From 8c94df5ce913877b3ba7f417aae0414bf78f7ddc Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 23 Jul 2015 16:16:42 +1000 Subject: [PATCH] Made package fuseshim build. --- internal/fusekernel/fuse_kernel.go | 46 +++++++------- internal/fusekernel/fuse_kernel_darwin.go | 8 +++ internal/fuseshim/fuse.go | 74 +++++++++++------------ internal/fuseshim/options.go | 4 +- 4 files changed, 70 insertions(+), 62 deletions(-) diff --git a/internal/fusekernel/fuse_kernel.go b/internal/fusekernel/fuse_kernel.go index fe25ee4..778f5fe 100644 --- a/internal/fusekernel/fuse_kernel.go +++ b/internal/fusekernel/fuse_kernel.go @@ -53,7 +53,7 @@ const ( RootID = 1 ) -type kstatfs struct { +type Kstatfs struct { Blocks uint64 Bfree uint64 Bavail uint64 @@ -387,7 +387,7 @@ const ( OpExchange = 63 ) -type entryOut struct { +type EntryOut struct { Nodeid uint64 // Inode ID Generation uint64 // Inode generation EntryValid uint64 // Cache timeout for the name @@ -400,9 +400,9 @@ type entryOut struct { func EntryOutSize(p Protocol) uintptr { switch { case p.LT(Protocol{7, 9}): - return unsafe.Offsetof(entryOut{}.Attr) + unsafe.Offsetof(entryOut{}.Attr.Blksize) + return unsafe.Offsetof(EntryOut{}.Attr) + unsafe.Offsetof(EntryOut{}.Attr.Blksize) default: - return unsafe.Sizeof(entryOut{}) + return unsafe.Sizeof(EntryOut{}) } } @@ -416,7 +416,7 @@ type GetattrIn struct { Fh uint64 } -type attrOut struct { +type AttrOut struct { AttrValid uint64 // Cache timeout for the attributes AttrValidNsec uint32 Dummy uint32 @@ -426,14 +426,14 @@ type attrOut struct { func AttrOutSize(p Protocol) uintptr { switch { case p.LT(Protocol{7, 9}): - return unsafe.Offsetof(attrOut{}.Attr) + unsafe.Offsetof(attrOut{}.Attr.Blksize) + return unsafe.Offsetof(AttrOut{}.Attr) + unsafe.Offsetof(AttrOut{}.Attr.Blksize) default: - return unsafe.Sizeof(attrOut{}) + return unsafe.Sizeof(AttrOut{}) } } // OS X -type getxtimesOut struct { +type GetxtimesOut struct { Bkuptime uint64 Crtime uint64 BkuptimeNsec uint32 @@ -512,7 +512,7 @@ type OpenIn struct { Unused uint32 } -type openOut struct { +type OpenOut struct { Fh uint64 OpenFlags uint32 Padding uint32 @@ -602,7 +602,7 @@ func WriteInSize(p Protocol) uintptr { } } -type writeOut struct { +type WriteOut struct { Size uint32 Padding uint32 } @@ -627,8 +627,8 @@ func (fl WriteFlags) String() string { const compatStatfsSize = 48 -type statfsOut struct { - St kstatfs +type StatfsOut struct { + St Kstatfs } type FsyncIn struct { @@ -642,7 +642,7 @@ type setxattrInCommon struct { Flags uint32 } -func (setxattrInCommon) position() uint32 { +func (setxattrInCommon) GetPosition() uint32 { return 0 } @@ -651,11 +651,11 @@ type getxattrInCommon struct { Padding uint32 } -func (getxattrInCommon) position() uint32 { +func (getxattrInCommon) GetPosition() uint32 { return 0 } -type getxattrOut struct { +type GetxattrOut struct { Size uint32 Padding uint32 } @@ -677,7 +677,7 @@ func LkInSize(p Protocol) uintptr { } } -type lkOut struct { +type LkOut struct { Lk fileLock } @@ -695,7 +695,7 @@ type InitIn struct { const InitInSize = int(unsafe.Sizeof(InitIn{})) -type initOut struct { +type InitOut struct { Major uint32 Minor uint32 MaxReadahead uint32 @@ -714,7 +714,7 @@ type BmapIn struct { Padding uint32 } -type bmapOut struct { +type BmapOut struct { Block uint64 } @@ -737,7 +737,7 @@ type OutHeader struct { Unique uint64 } -type dirent struct { +type Dirent struct { Ino uint64 Off uint64 Namelen uint32 @@ -745,12 +745,12 @@ type dirent struct { Name [0]byte } -const direntSize = 8 + 8 + 4 + 4 +const DirentSize = 8 + 8 + 4 + 4 const ( - notifyCodePoll int32 = 1 - notifyCodeInvalInode int32 = 2 - notifyCodeInvalEntry int32 = 3 + NotifyCodePoll int32 = 1 + NotifyCodeInvalInode int32 = 2 + NotifyCodeInvalEntry int32 = 3 ) type NotifyInvalInodeOut struct { diff --git a/internal/fusekernel/fuse_kernel_darwin.go b/internal/fusekernel/fuse_kernel_darwin.go index 2eb842d..fc02267 100644 --- a/internal/fusekernel/fuse_kernel_darwin.go +++ b/internal/fusekernel/fuse_kernel_darwin.go @@ -71,6 +71,10 @@ type GetxattrIn struct { Padding uint32 } +func (g *GetxattrIn) GetPosition() uint32 { + return g.Position +} + type SetxattrIn struct { setxattrInCommon @@ -78,3 +82,7 @@ type SetxattrIn struct { Position uint32 Padding uint32 } + +func (s *SetxattrIn) GetPosition() uint32 { + return s.Position +} diff --git a/internal/fuseshim/fuse.go b/internal/fuseshim/fuse.go index e1e98e3..56d1faf 100644 --- a/internal/fuseshim/fuse.go +++ b/internal/fuseshim/fuse.go @@ -868,7 +868,7 @@ loop: req = &SetxattrRequest{ Header: m.Header(), Flags: in.Flags, - Position: in.Position(), + Position: in.GetPosition(), Name: string(name[:i]), Xattr: xattr, } @@ -887,7 +887,7 @@ loop: Header: m.Header(), Name: string(name[:i]), Size: in.Size, - Position: in.Position, + Position: in.GetPosition(), } case fusekernel.OpListxattr: @@ -898,7 +898,7 @@ loop: req = &ListxattrRequest{ Header: m.Header(), Size: in.Size, - Position: in.Position, + Position: in.GetPosition(), } case fusekernel.OpRemovexattr: @@ -1049,7 +1049,7 @@ func (c *Conn) writeToKernel(msg []byte) error { c.wio.RLock() defer c.wio.RUnlock() - nn, err := syscall.Write(c.fd(), msg) + _, err := syscall.Write(c.fd(), msg) return err } @@ -1096,11 +1096,11 @@ func (c *Conn) sendInvalidate(msg []byte) error { // Returns ErrNotCached if the kernel is not currently caching the // node. func (c *Conn) InvalidateNode(nodeID NodeID, off int64, size int64) error { - buf := newBuffer(unsafe.Sizeof(notifyInvalInodeOut{})) + buf := newBuffer(unsafe.Sizeof(fusekernel.NotifyInvalInodeOut{})) h := (*fusekernel.OutHeader)(unsafe.Pointer(&buf[0])) // h.Unique is 0 - h.Error = notifyCodeInvalInode - out := (*notifyInvalInodeOut)(buf.alloc(unsafe.Sizeof(notifyInvalInodeOut{}))) + h.Error = fusekernel.NotifyCodeInvalInode + out := (*fusekernel.NotifyInvalInodeOut)(buf.alloc(unsafe.Sizeof(fusekernel.NotifyInvalInodeOut{}))) out.Ino = uint64(nodeID) out.Off = off out.Len = size @@ -1123,11 +1123,11 @@ func (c *Conn) InvalidateEntry(parent NodeID, name string) error { // very unlikely, but we don't want to silently truncate return syscall.ENAMETOOLONG } - buf := newBuffer(unsafe.Sizeof(notifyInvalEntryOut{}) + uintptr(len(name)) + 1) + buf := newBuffer(unsafe.Sizeof(fusekernel.NotifyInvalEntryOut{}) + uintptr(len(name)) + 1) h := (*fusekernel.OutHeader)(unsafe.Pointer(&buf[0])) // h.Unique is 0 - h.Error = notifyCodeInvalEntry - out := (*notifyInvalEntryOut)(buf.alloc(unsafe.Sizeof(notifyInvalEntryOut{}))) + h.Error = fusekernel.NotifyCodeInvalEntry + out := (*fusekernel.NotifyInvalEntryOut)(buf.alloc(unsafe.Sizeof(fusekernel.NotifyInvalEntryOut{}))) out.Parent = uint64(parent) out.Namelen = uint32(len(name)) buf = append(buf, name...) @@ -1168,8 +1168,8 @@ func (r *InitResponse) String() string { // Respond replies to the request with the given response. func (r *InitRequest) Respond(resp *InitResponse) { - buf := newBuffer(unsafe.Sizeof(initOut{})) - out := (*initOut)(buf.alloc(unsafe.Sizeof(initOut{}))) + buf := newBuffer(unsafe.Sizeof(fusekernel.InitOut{})) + out := (*fusekernel.InitOut)(buf.alloc(unsafe.Sizeof(fusekernel.InitOut{}))) out.Major = resp.Library.Major out.Minor = resp.Library.Minor out.MaxReadahead = resp.MaxReadahead @@ -1197,9 +1197,9 @@ func (r *StatfsRequest) String() string { // Respond replies to the request with the given response. func (r *StatfsRequest) Respond(resp *StatfsResponse) { - buf := newBuffer(unsafe.Sizeof(statfsOut{})) - out := (*statfsOut)(buf.alloc(unsafe.Sizeof(statfsOut{}))) - out.St = kstatfs{ + buf := newBuffer(unsafe.Sizeof(fusekernel.StatfsOut{})) + out := (*fusekernel.StatfsOut)(buf.alloc(unsafe.Sizeof(fusekernel.StatfsOut{}))) + out.St = fusekernel.Kstatfs{ Blocks: resp.Blocks, Bfree: resp.Bfree, Bavail: resp.Bavail, @@ -1336,7 +1336,7 @@ func (r *GetattrRequest) String() string { func (r *GetattrRequest) Respond(resp *GetattrResponse) { size := fusekernel.AttrOutSize(r.Header.Conn.proto) buf := newBuffer(size) - out := (*attrOut)(buf.alloc(size)) + out := (*fusekernel.AttrOut)(buf.alloc(size)) out.AttrValid = uint64(resp.Attr.Valid / time.Second) out.AttrValidNsec = uint32(resp.Attr.Valid % time.Second / time.Nanosecond) resp.Attr.attr(&out.Attr, r.Header.Conn.proto) @@ -1378,8 +1378,8 @@ func (r *GetxattrRequest) String() string { // Respond replies to the request with the given response. func (r *GetxattrRequest) Respond(resp *GetxattrResponse) { if r.Size == 0 { - buf := newBuffer(unsafe.Sizeof(getxattrOut{})) - out := (*getxattrOut)(buf.alloc(unsafe.Sizeof(getxattrOut{}))) + buf := newBuffer(unsafe.Sizeof(fusekernel.GetxattrOut{})) + out := (*fusekernel.GetxattrOut)(buf.alloc(unsafe.Sizeof(fusekernel.GetxattrOut{}))) out.Size = uint32(len(resp.Xattr)) r.respond(buf) } else { @@ -1414,8 +1414,8 @@ func (r *ListxattrRequest) String() string { // Respond replies to the request with the given response. func (r *ListxattrRequest) Respond(resp *ListxattrResponse) { if r.Size == 0 { - buf := newBuffer(unsafe.Sizeof(getxattrOut{})) - out := (*getxattrOut)(buf.alloc(unsafe.Sizeof(getxattrOut{}))) + buf := newBuffer(unsafe.Sizeof(fusekernel.GetxattrOut{})) + out := (*fusekernel.GetxattrOut)(buf.alloc(unsafe.Sizeof(fusekernel.GetxattrOut{}))) out.Size = uint32(len(resp.Xattr)) r.respond(buf) } else { @@ -1521,7 +1521,7 @@ func (r *LookupRequest) String() string { func (r *LookupRequest) Respond(resp *LookupResponse) { size := fusekernel.EntryOutSize(r.Header.Conn.proto) buf := newBuffer(size) - out := (*entryOut)(buf.alloc(size)) + out := (*fusekernel.EntryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation out.EntryValid = uint64(resp.EntryValid / time.Second) @@ -1559,8 +1559,8 @@ func (r *OpenRequest) String() string { // Respond replies to the request with the given response. func (r *OpenRequest) Respond(resp *OpenResponse) { - buf := newBuffer(unsafe.Sizeof(openOut{})) - out := (*openOut)(buf.alloc(unsafe.Sizeof(openOut{}))) + buf := newBuffer(unsafe.Sizeof(fusekernel.OpenOut{})) + out := (*fusekernel.OpenOut)(buf.alloc(unsafe.Sizeof(fusekernel.OpenOut{}))) out.Fh = uint64(resp.Handle) out.OpenFlags = uint32(resp.Flags) r.respond(buf) @@ -1594,9 +1594,9 @@ func (r *CreateRequest) String() string { // Respond replies to the request with the given response. func (r *CreateRequest) Respond(resp *CreateResponse) { eSize := fusekernel.EntryOutSize(r.Header.Conn.proto) - buf := newBuffer(eSize + unsafe.Sizeof(openOut{})) + buf := newBuffer(eSize + unsafe.Sizeof(fusekernel.OpenOut{})) - e := (*entryOut)(buf.alloc(eSize)) + e := (*fusekernel.EntryOut)(buf.alloc(eSize)) e.Nodeid = uint64(resp.Node) e.Generation = resp.Generation e.EntryValid = uint64(resp.EntryValid / time.Second) @@ -1605,7 +1605,7 @@ func (r *CreateRequest) Respond(resp *CreateResponse) { e.AttrValidNsec = uint32(resp.Attr.Valid % time.Second / time.Nanosecond) resp.Attr.attr(&e.Attr, r.Header.Conn.proto) - o := (*openOut)(buf.alloc(unsafe.Sizeof(openOut{}))) + o := (*fusekernel.OpenOut)(buf.alloc(unsafe.Sizeof(fusekernel.OpenOut{}))) o.Fh = uint64(resp.Handle) o.OpenFlags = uint32(resp.Flags) @@ -1641,7 +1641,7 @@ func (r *MkdirRequest) String() string { func (r *MkdirRequest) Respond(resp *MkdirResponse) { size := fusekernel.EntryOutSize(r.Header.Conn.proto) buf := newBuffer(size) - out := (*entryOut)(buf.alloc(size)) + out := (*fusekernel.EntryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation out.EntryValid = uint64(resp.EntryValid / time.Second) @@ -1831,15 +1831,15 @@ func (t DirentType) String() string { // AppendDirent appends the encoded form of a directory entry to data // and returns the resulting slice. func AppendDirent(data []byte, dir Dirent) []byte { - de := dirent{ + de := fusekernel.Dirent{ Ino: dir.Inode, Namelen: uint32(len(dir.Name)), Type: uint32(dir.Type), } - de.Off = uint64(len(data) + direntSize + (len(dir.Name)+7)&^7) - data = append(data, (*[direntSize]byte)(unsafe.Pointer(&de))[:]...) + de.Off = uint64(len(data) + fusekernel.DirentSize + (len(dir.Name)+7)&^7) + data = append(data, (*[fusekernel.DirentSize]byte)(unsafe.Pointer(&de))[:]...) data = append(data, dir.Name...) - n := direntSize + uintptr(len(dir.Name)) + n := fusekernel.DirentSize + uintptr(len(dir.Name)) if n%8 != 0 { var pad [8]byte data = append(data, pad[:8-n%8]...) @@ -1883,8 +1883,8 @@ func (r *WriteRequest) MarshalJSON() ([]byte, error) { // Respond replies to the request with the given response. func (r *WriteRequest) Respond(resp *WriteResponse) { - buf := newBuffer(unsafe.Sizeof(writeOut{})) - out := (*writeOut)(buf.alloc(unsafe.Sizeof(writeOut{}))) + buf := newBuffer(unsafe.Sizeof(fusekernel.WriteOut{})) + out := (*fusekernel.WriteOut)(buf.alloc(unsafe.Sizeof(fusekernel.WriteOut{}))) out.Size = uint32(resp.Size) r.respond(buf) } @@ -1975,7 +1975,7 @@ func (r *SetattrRequest) String() string { func (r *SetattrRequest) Respond(resp *SetattrResponse) { size := fusekernel.AttrOutSize(r.Header.Conn.proto) buf := newBuffer(size) - out := (*attrOut)(buf.alloc(size)) + out := (*fusekernel.AttrOut)(buf.alloc(size)) out.AttrValid = uint64(resp.Attr.Valid / time.Second) out.AttrValidNsec = uint32(resp.Attr.Valid % time.Second / time.Nanosecond) resp.Attr.attr(&out.Attr, r.Header.Conn.proto) @@ -2049,7 +2049,7 @@ func (r *SymlinkRequest) String() string { func (r *SymlinkRequest) Respond(resp *SymlinkResponse) { size := fusekernel.EntryOutSize(r.Header.Conn.proto) buf := newBuffer(size) - out := (*entryOut)(buf.alloc(size)) + out := (*fusekernel.EntryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation out.EntryValid = uint64(resp.EntryValid / time.Second) @@ -2098,7 +2098,7 @@ func (r *LinkRequest) String() string { func (r *LinkRequest) Respond(resp *LookupResponse) { size := fusekernel.EntryOutSize(r.Header.Conn.proto) buf := newBuffer(size) - out := (*entryOut)(buf.alloc(size)) + out := (*fusekernel.EntryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation out.EntryValid = uint64(resp.EntryValid / time.Second) @@ -2144,7 +2144,7 @@ func (r *MknodRequest) String() string { func (r *MknodRequest) Respond(resp *LookupResponse) { size := fusekernel.EntryOutSize(r.Header.Conn.proto) buf := newBuffer(size) - out := (*entryOut)(buf.alloc(size)) + out := (*fusekernel.EntryOut)(buf.alloc(size)) out.Nodeid = uint64(resp.Node) out.Generation = resp.Generation out.EntryValid = uint64(resp.EntryValid / time.Second) diff --git a/internal/fuseshim/options.go b/internal/fuseshim/options.go index 7e89207..2630ad0 100644 --- a/internal/fuseshim/options.go +++ b/internal/fuseshim/options.go @@ -166,7 +166,7 @@ func MaxReadahead(n uint32) MountOption { // time. func AsyncRead() MountOption { return func(conf *mountConfig) error { - conf.initFlags |= InitAsyncRead + conf.initFlags |= fusekernel.InitAsyncRead return nil } } @@ -176,7 +176,7 @@ func AsyncRead() MountOption { // used. func WritebackCache() MountOption { return func(conf *mountConfig) error { - conf.initFlags |= InitWritebackCache + conf.initFlags |= fusekernel.InitWritebackCache return nil } }