Compare commits
47 Commits
geesefs-0.
...
master
Author | SHA1 | Date |
---|---|---|
Vitaliy Filippov | 7a12c251bb | |
Vitaliy Filippov | e64d1db179 | |
Vitaliy Filippov | f403be49ac | |
Vitaliy Filippov | d9f86f936a | |
Vitaliy Filippov | e03805b2b5 | |
Vitaliy Filippov | 4a8b61d056 | |
Vitaliy Filippov | e37465aa67 | |
Vitaliy Filippov | 3f512fd68f | |
Vitaliy Filippov | 299578a3b3 | |
Vitaliy Filippov | 5231edee52 | |
Vitaliy Filippov | 9afe460f00 | |
Michael Stapelberg | a1c7c8268f | |
Коренберг Марк | 80d6127f10 | |
labulakalia | bc4b1b58bb | |
Michael Stapelberg | faebccf4c6 | |
Aaron Jacobs | dd426a02d6 | |
Aaron Jacobs | 5559e12766 | |
Prince Kumar | 8a36813dc0 | |
pat-vish | 7285af0d05 | |
Prince Kumar | a2f23eec70 | |
Alex Fishman | 39f95ce809 | |
Alex Fishman | a385e05f09 | |
dependabot[bot] | edf18a690d | |
Ayush Sethi | 84480b28de | |
Alex Fishman | 2b0495a1d5 | |
Alex Fishman | 6031ecfb44 | |
Alex Fishman | 8e7cb84040 | |
Alex Fishman | 729d9bae15 | |
Alex Fishman | d873f3245d | |
Alex Fishman | 3b4e7be609 | |
Alex Fishman | 08e4247097 | |
Alex Fishman | 81500b6e41 | |
Alex Fishman | 8d8cb12b5b | |
Scott Bauersfeld | cefeec4a40 | |
dependabot[bot] | 40a7e03ed1 | |
Prince Kumar | d0f3daf365 | |
Tulsi Shah | ab21db1af8 | |
Vaishali Kumanan | b8484ee15d | |
Prince Kumar | 7263f3a2b4 | |
Tulsishah | b7182e0d0b | |
Vitaliy Filippov | 28052ba41f | |
Vitaliy Filippov | 043fbd1f54 | |
dependabot[bot] | 86031ac261 | |
Doug Schaapveld | 702f658418 | |
Doug Schaapveld | bb43c71d6f | |
Ayush Sethi | 5e0f2e6b43 | |
Lars Gohr | c2e09611e9 |
|
@ -39,17 +39,19 @@ var contextKey interface{} = contextKeyType(0)
|
||||||
//
|
//
|
||||||
// As of 2015-03-26, the behavior in the kernel is:
|
// As of 2015-03-26, the behavior in the kernel is:
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/bQ1f1i, http://goo.gl/HwBrR6) Set the local variable
|
// - (https://tinyurl.com/2eakn5e9, https://tinyurl.com/mry9e33d) Set the
|
||||||
// ra_pages to be init_response->max_readahead divided by the page size.
|
// local variable ra_pages to be init_response->max_readahead divided by
|
||||||
|
// the page size.
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/gcIsSh, http://goo.gl/LKV2vA) Set
|
// - (https://tinyurl.com/2eakn5e9, https://tinyurl.com/mbpshk8h) Set
|
||||||
// backing_dev_info::ra_pages to the min of that value and what was sent
|
// backing_dev_info::ra_pages to the min of that value and what was sent in
|
||||||
// in the request's max_readahead field.
|
// the request's max_readahead field.
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/u2SqzH) Use backing_dev_info::ra_pages when deciding
|
// - (https://tinyurl.com/57hpfu4x) Use backing_dev_info::ra_pages when
|
||||||
// how much to read ahead.
|
// deciding how much to read ahead.
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/JnhbdL) Don't read ahead at all if that field is zero.
|
// - (https://tinyurl.com/ywhfcfte) Don't read ahead at all if that field is
|
||||||
|
// zero.
|
||||||
//
|
//
|
||||||
// Reading a page at a time is a drag. Ask for a larger size.
|
// Reading a page at a time is a drag. Ask for a larger size.
|
||||||
const maxReadahead = 1 << 20
|
const maxReadahead = 1 << 20
|
||||||
|
@ -194,13 +196,17 @@ func (c *Connection) Init() error {
|
||||||
initOp.Flags |= fusekernel.InitNoOpendirSupport
|
initOp.Flags |= fusekernel.InitNoOpendirSupport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tell the Kernel to allow sending parallel lookup and readdir operations.
|
||||||
|
if c.cfg.EnableParallelDirOps {
|
||||||
|
initOp.Flags |= fusekernel.InitParallelDirOps
|
||||||
|
}
|
||||||
|
|
||||||
// Tell the kernel to do readdirplus (readdir+lookup in one call)
|
// Tell the kernel to do readdirplus (readdir+lookup in one call)
|
||||||
if c.cfg.UseReadDirPlus && readdirplusSupport {
|
if c.cfg.UseReadDirPlus && readdirplusSupport {
|
||||||
initOp.Flags |= fusekernel.InitDoReaddirplus
|
initOp.Flags |= fusekernel.InitDoReaddirplus
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Reply(ctx, nil)
|
return c.Reply(ctx, nil)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log information for an operation with the given ID. calldepth is the depth
|
// Log information for an operation with the given ID. calldepth is the depth
|
||||||
|
@ -315,13 +321,13 @@ func (c *Connection) handleInterrupt(fuseID uint64) {
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
||||||
// NOTE(jacobsa): fuse.txt in the Linux kernel documentation
|
// NOTE(jacobsa): fuse.txt in the Linux kernel documentation
|
||||||
// (https://goo.gl/H55Dnr) defines the kernel <-> userspace protocol for
|
// (https://tinyurl.com/2r4ajuwd) defines the kernel <-> userspace protocol
|
||||||
// interrupts.
|
// for interrupts.
|
||||||
//
|
//
|
||||||
// In particular, my reading of it is that an interrupt request cannot be
|
// In particular, my reading of it is that an interrupt request cannot be
|
||||||
// delivered to userspace before the original request. The part about the
|
// delivered to userspace before the original request. The part about the
|
||||||
// race and EAGAIN appears to be aimed at userspace programs that
|
// race and EAGAIN appears to be aimed at userspace programs that
|
||||||
// concurrently process requests (cf. http://goo.gl/BES2rs).
|
// concurrently process requests (https://tinyurl.com/3euehwfb).
|
||||||
//
|
//
|
||||||
// So in this method if we can't find the ID to be interrupted, it means that
|
// So in this method if we can't find the ID to be interrupted, it means that
|
||||||
// the request has already been replied to.
|
// the request has already been replied to.
|
||||||
|
@ -380,6 +386,11 @@ func (c *Connection) writeMessage(outMsg *buffer.OutMessage) error {
|
||||||
var n int
|
var n int
|
||||||
expectedLen := outMsg.Len()
|
expectedLen := outMsg.Len()
|
||||||
if outMsg.Sglist != nil {
|
if outMsg.Sglist != nil {
|
||||||
|
if fusekernel.IsPlatformFuseT {
|
||||||
|
// writev is not atomic on macos, restrict to fuse-t platform
|
||||||
|
writeLock.Lock()
|
||||||
|
defer writeLock.Unlock()
|
||||||
|
}
|
||||||
n, err = writev(int(c.dev.Fd()), outMsg.Sglist)
|
n, err = writev(int(c.dev.Fd()), outMsg.Sglist)
|
||||||
} else {
|
} else {
|
||||||
// Avoid the retry loop in os.File.Write.
|
// Avoid the retry loop in os.File.Write.
|
||||||
|
@ -388,8 +399,12 @@ func (c *Connection) writeMessage(outMsg *buffer.OutMessage) error {
|
||||||
if err == nil && n != expectedLen {
|
if err == nil && n != expectedLen {
|
||||||
err = fmt.Errorf("Wrote %d bytes; expected %d", n, expectedLen)
|
err = fmt.Errorf("Wrote %d bytes; expected %d", n, expectedLen)
|
||||||
}
|
}
|
||||||
if err != nil && c.errorLogger != nil {
|
if err != nil {
|
||||||
c.errorLogger.Printf("writeMessage: %v %v", err, outMsg.OutHeaderBytes())
|
writeErrMsg := fmt.Sprintf("writeMessage: %v %v", err, outMsg.OutHeaderBytes())
|
||||||
|
if c.errorLogger != nil {
|
||||||
|
c.errorLogger.Print(writeErrMsg)
|
||||||
|
}
|
||||||
|
return fmt.Errorf(writeErrMsg)
|
||||||
}
|
}
|
||||||
outMsg.Sglist = nil
|
outMsg.Sglist = nil
|
||||||
return err
|
return err
|
||||||
|
@ -466,7 +481,7 @@ func (c *Connection) shouldLogError(
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case *fuseops.GetXattrOp, *fuseops.ListXattrOp:
|
case *fuseops.GetXattrOp, *fuseops.ListXattrOp:
|
||||||
if err == syscall.ENODATA || err == syscall.ERANGE {
|
if err == syscall.ENOSYS || err == syscall.ENODATA || err == syscall.ERANGE {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
case *unknownOp:
|
case *unknownOp:
|
||||||
|
@ -479,11 +494,13 @@ func (c *Connection) shouldLogError(
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var writeLock sync.Mutex
|
||||||
|
|
||||||
// Reply replies to an op previously read using ReadOp, with the supplied error
|
// Reply replies to an op previously read using ReadOp, with the supplied error
|
||||||
// (or nil if successful). The context must be the context returned by ReadOp.
|
// (or nil if successful). The context must be the context returned by ReadOp.
|
||||||
//
|
//
|
||||||
// LOCKS_EXCLUDED(c.mu)
|
// LOCKS_EXCLUDED(c.mu)
|
||||||
func (c *Connection) Reply(ctx context.Context, opErr error) {
|
func (c *Connection) Reply(ctx context.Context, opErr error) error {
|
||||||
// Extract the state we stuffed in earlier.
|
// Extract the state we stuffed in earlier.
|
||||||
var key interface{} = contextKey
|
var key interface{} = contextKey
|
||||||
foo := ctx.Value(key)
|
foo := ctx.Value(key)
|
||||||
|
@ -497,16 +514,25 @@ func (c *Connection) Reply(ctx context.Context, opErr error) {
|
||||||
outMsg := state.outMsg
|
outMsg := state.outMsg
|
||||||
fuseID := inMsg.Header().Unique
|
fuseID := inMsg.Header().Unique
|
||||||
|
|
||||||
|
defer func() {
|
||||||
|
// Invoke any callbacks set by the FUSE server after the response to the kernel is
|
||||||
|
// complete and before the inMessage and outMessage memory buffers have been freed.
|
||||||
|
callback := c.callbackForOp(op)
|
||||||
|
if callback != nil {
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we destroy the messages when we're done.
|
||||||
suppressReuse := false
|
suppressReuse := false
|
||||||
if wr, ok := op.(*fuseops.WriteFileOp); ok {
|
if wr, ok := op.(*fuseops.WriteFileOp); ok {
|
||||||
suppressReuse = wr.SuppressReuse
|
suppressReuse = wr.SuppressReuse
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we destroy the messages when we're done.
|
|
||||||
if !suppressReuse {
|
if !suppressReuse {
|
||||||
defer c.putInMessage(inMsg)
|
c.putInMessage(inMsg)
|
||||||
}
|
}
|
||||||
defer c.putOutMessage(outMsg)
|
c.putOutMessage(outMsg)
|
||||||
|
}()
|
||||||
|
|
||||||
// Clean up state for this op.
|
// Clean up state for this op.
|
||||||
c.finishOp(inMsg.Header().Opcode, inMsg.Header().Unique)
|
c.finishOp(inMsg.Header().Opcode, inMsg.Header().Unique)
|
||||||
|
@ -514,7 +540,7 @@ func (c *Connection) Reply(ctx context.Context, opErr error) {
|
||||||
// Debug logging
|
// Debug logging
|
||||||
if c.debugLogger != nil {
|
if c.debugLogger != nil {
|
||||||
if opErr == nil {
|
if opErr == nil {
|
||||||
c.debugLog(fuseID, 1, "-> OK (%s)", describeResponse(op))
|
c.debugLog(fuseID, 1, "-> %s", describeResponse(op))
|
||||||
} else {
|
} else {
|
||||||
c.debugLog(fuseID, 1, "-> Error: %q", opErr.Error())
|
c.debugLog(fuseID, 1, "-> Error: %q", opErr.Error())
|
||||||
}
|
}
|
||||||
|
@ -531,6 +557,18 @@ func (c *Connection) Reply(ctx context.Context, opErr error) {
|
||||||
if !noResponse {
|
if !noResponse {
|
||||||
c.writeMessage(outMsg)
|
c.writeMessage(outMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Connection) callbackForOp(op interface{}) func() {
|
||||||
|
switch o := op.(type) {
|
||||||
|
case *fuseops.ReadFileOp:
|
||||||
|
return o.Callback
|
||||||
|
case *fuseops.WriteFileOp:
|
||||||
|
return o.Callback
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send a notification to the kernel
|
// Send a notification to the kernel
|
||||||
|
|
233
conversions.go
233
conversions.go
|
@ -53,13 +53,23 @@ func convertInMessage(
|
||||||
o = &fuseops.LookUpInodeOp{
|
o = &fuseops.LookUpInodeOp{
|
||||||
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(buf[:n-1]),
|
Name: string(buf[:n-1]),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpGetattr:
|
case fusekernel.OpGetattr:
|
||||||
o = &fuseops.GetInodeAttributesOp{
|
o = &fuseops.GetInodeAttributesOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpSetattr:
|
case fusekernel.OpSetattr:
|
||||||
|
@ -71,7 +81,12 @@ func convertInMessage(
|
||||||
|
|
||||||
to := &fuseops.SetInodeAttributesOp{
|
to := &fuseops.SetInodeAttributesOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
o = to
|
o = to
|
||||||
|
|
||||||
|
@ -118,7 +133,12 @@ func convertInMessage(
|
||||||
o = &fuseops.ForgetInodeOp{
|
o = &fuseops.ForgetInodeOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
N: in.Nlookup,
|
N: in.Nlookup,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpBatchForget:
|
case fusekernel.OpBatchForget:
|
||||||
|
@ -144,7 +164,12 @@ func convertInMessage(
|
||||||
|
|
||||||
o = &fuseops.BatchForgetOp{
|
o = &fuseops.BatchForgetOp{
|
||||||
Entries: entries,
|
Entries: entries,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpMkdir:
|
case fusekernel.OpMkdir:
|
||||||
|
@ -165,13 +190,18 @@ func convertInMessage(
|
||||||
Name: string(name),
|
Name: string(name),
|
||||||
|
|
||||||
// On Linux, vfs_mkdir calls through to the inode with at most
|
// On Linux, vfs_mkdir calls through to the inode with at most
|
||||||
// permissions and sticky bits set (cf. https://goo.gl/WxgQXk), and fuse
|
// permissions and sticky bits set (https://tinyurl.com/3djx8498), and
|
||||||
// passes that on directly (cf. https://goo.gl/f31aMo). In other words,
|
// fuse passes that on directly (https://tinyurl.com/exezw647). In other
|
||||||
// the fact that this is a directory is implicit in the fact that the
|
// words, the fact that this is a directory is implicit in the fact that
|
||||||
// opcode is mkdir. But we want the correct mode to go through, so ensure
|
// the opcode is mkdir. But we want the correct mode to go through, so
|
||||||
// that os.ModeDir is set.
|
// ensure that os.ModeDir is set.
|
||||||
Mode: fuseops.ConvertFileMode(in.Mode) | os.ModeDir,
|
Mode: fuseops.ConvertFileMode(in.Mode) | os.ModeDir,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpMknod:
|
case fusekernel.OpMknod:
|
||||||
|
@ -192,7 +222,12 @@ func convertInMessage(
|
||||||
Name: string(name),
|
Name: string(name),
|
||||||
Mode: fuseops.ConvertFileMode(in.Mode),
|
Mode: fuseops.ConvertFileMode(in.Mode),
|
||||||
Rdev: in.Rdev,
|
Rdev: in.Rdev,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpCreate:
|
case fusekernel.OpCreate:
|
||||||
|
@ -212,7 +247,12 @@ func convertInMessage(
|
||||||
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(name),
|
Name: string(name),
|
||||||
Mode: fuseops.ConvertFileMode(in.Mode),
|
Mode: fuseops.ConvertFileMode(in.Mode),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpSymlink:
|
case fusekernel.OpSymlink:
|
||||||
|
@ -231,7 +271,12 @@ func convertInMessage(
|
||||||
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(newName),
|
Name: string(newName),
|
||||||
Target: string(target),
|
Target: string(target),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpRename:
|
case fusekernel.OpRename:
|
||||||
|
@ -273,7 +318,12 @@ func convertInMessage(
|
||||||
OldName: string(oldName),
|
OldName: string(oldName),
|
||||||
NewParent: fuseops.InodeID(in.Newdir),
|
NewParent: fuseops.InodeID(in.Newdir),
|
||||||
NewName: string(newName),
|
NewName: string(newName),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpUnlink:
|
case fusekernel.OpUnlink:
|
||||||
|
@ -286,7 +336,12 @@ func convertInMessage(
|
||||||
o = &fuseops.UnlinkOp{
|
o = &fuseops.UnlinkOp{
|
||||||
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(buf[:n-1]),
|
Name: string(buf[:n-1]),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpRmdir:
|
case fusekernel.OpRmdir:
|
||||||
|
@ -299,7 +354,12 @@ func convertInMessage(
|
||||||
o = &fuseops.RmDirOp{
|
o = &fuseops.RmDirOp{
|
||||||
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(buf[:n-1]),
|
Name: string(buf[:n-1]),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpOpen:
|
case fusekernel.OpOpen:
|
||||||
|
@ -312,13 +372,23 @@ func convertInMessage(
|
||||||
o = &fuseops.OpenFileOp{
|
o = &fuseops.OpenFileOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
OpenFlags: fusekernel.OpenFlags(in.Flags),
|
OpenFlags: fusekernel.OpenFlags(in.Flags),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpOpendir:
|
case fusekernel.OpOpendir:
|
||||||
o = &fuseops.OpenDirOp{
|
o = &fuseops.OpenDirOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpRead:
|
case fusekernel.OpRead:
|
||||||
|
@ -332,7 +402,12 @@ func convertInMessage(
|
||||||
Handle: fuseops.HandleID(in.Fh),
|
Handle: fuseops.HandleID(in.Fh),
|
||||||
Offset: int64(in.Offset),
|
Offset: int64(in.Offset),
|
||||||
Size: int64(in.Size),
|
Size: int64(in.Size),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
if !config.UseVectoredRead {
|
if !config.UseVectoredRead {
|
||||||
// Use part of the incoming message storage as the read buffer
|
// Use part of the incoming message storage as the read buffer
|
||||||
|
@ -354,7 +429,12 @@ func convertInMessage(
|
||||||
Handle: fuseops.HandleID(in.Fh),
|
Handle: fuseops.HandleID(in.Fh),
|
||||||
Offset: fuseops.DirOffset(in.Offset),
|
Offset: fuseops.DirOffset(in.Offset),
|
||||||
Plus: inMsg.Header().Opcode == fusekernel.OpReaddirplus,
|
Plus: inMsg.Header().Opcode == fusekernel.OpReaddirplus,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
o = to
|
o = to
|
||||||
|
|
||||||
|
@ -378,7 +458,12 @@ func convertInMessage(
|
||||||
|
|
||||||
o = &fuseops.ReleaseFileHandleOp{
|
o = &fuseops.ReleaseFileHandleOp{
|
||||||
Handle: fuseops.HandleID(in.Fh),
|
Handle: fuseops.HandleID(in.Fh),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpReleasedir:
|
case fusekernel.OpReleasedir:
|
||||||
|
@ -390,7 +475,12 @@ func convertInMessage(
|
||||||
|
|
||||||
o = &fuseops.ReleaseDirHandleOp{
|
o = &fuseops.ReleaseDirHandleOp{
|
||||||
Handle: fuseops.HandleID(in.Fh),
|
Handle: fuseops.HandleID(in.Fh),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpWrite:
|
case fusekernel.OpWrite:
|
||||||
|
@ -409,19 +499,41 @@ func convertInMessage(
|
||||||
Handle: fuseops.HandleID(in.Fh),
|
Handle: fuseops.HandleID(in.Fh),
|
||||||
Data: buf,
|
Data: buf,
|
||||||
Offset: int64(in.Offset),
|
Offset: int64(in.Offset),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpFsync, fusekernel.OpFsyncdir:
|
case fusekernel.OpFsync, fusekernel.OpFsyncdir:
|
||||||
type input fusekernel.FsyncIn
|
type input fusekernel.FsyncIn
|
||||||
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
|
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
|
||||||
if in == nil {
|
if in == nil {
|
||||||
return nil, errors.New("Corrupt OpFsync")
|
return nil, errors.New("Corrupt OpFsync/OpFsyncdir")
|
||||||
}
|
}
|
||||||
|
|
||||||
o = &fuseops.SyncFileOp{
|
o = &fuseops.SyncFileOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Handle: fuseops.HandleID(in.Fh),
|
Handle: fuseops.HandleID(in.Fh),
|
||||||
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
case fusekernel.OpSyncFS:
|
||||||
|
type input fusekernel.SyncFSIn
|
||||||
|
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
|
||||||
|
if in == nil {
|
||||||
|
return nil, errors.New("Corrupt OpSyncFS")
|
||||||
|
}
|
||||||
|
|
||||||
|
o = &fuseops.SyncFSOp{
|
||||||
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,13 +547,23 @@ func convertInMessage(
|
||||||
o = &fuseops.FlushFileOp{
|
o = &fuseops.FlushFileOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Handle: fuseops.HandleID(in.Fh),
|
Handle: fuseops.HandleID(in.Fh),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpReadlink:
|
case fusekernel.OpReadlink:
|
||||||
o = &fuseops.ReadSymlinkOp{
|
o = &fuseops.ReadSymlinkOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpStatfs:
|
case fusekernel.OpStatfs:
|
||||||
|
@ -492,7 +614,12 @@ func convertInMessage(
|
||||||
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
Parent: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(name),
|
Name: string(name),
|
||||||
Target: fuseops.InodeID(in.Oldnodeid),
|
Target: fuseops.InodeID(in.Oldnodeid),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpRemovexattr:
|
case fusekernel.OpRemovexattr:
|
||||||
|
@ -505,7 +632,12 @@ func convertInMessage(
|
||||||
o = &fuseops.RemoveXattrOp{
|
o = &fuseops.RemoveXattrOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(buf[:n-1]),
|
Name: string(buf[:n-1]),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpGetxattr:
|
case fusekernel.OpGetxattr:
|
||||||
|
@ -525,7 +657,12 @@ func convertInMessage(
|
||||||
to := &fuseops.GetXattrOp{
|
to := &fuseops.GetXattrOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
Name: string(name),
|
Name: string(name),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
o = to
|
o = to
|
||||||
|
|
||||||
|
@ -553,7 +690,12 @@ func convertInMessage(
|
||||||
|
|
||||||
to := &fuseops.ListXattrOp{
|
to := &fuseops.ListXattrOp{
|
||||||
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
Inode: fuseops.InodeID(inMsg.Header().Nodeid),
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
o = to
|
o = to
|
||||||
|
|
||||||
|
@ -592,7 +734,12 @@ func convertInMessage(
|
||||||
Name: string(name),
|
Name: string(name),
|
||||||
Value: value,
|
Value: value,
|
||||||
Flags: in.Flags,
|
Flags: in.Flags,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
case fusekernel.OpFallocate:
|
case fusekernel.OpFallocate:
|
||||||
type input fusekernel.FallocateIn
|
type input fusekernel.FallocateIn
|
||||||
|
@ -607,7 +754,12 @@ func convertInMessage(
|
||||||
Offset: in.Offset,
|
Offset: in.Offset,
|
||||||
Length: in.Length,
|
Length: in.Length,
|
||||||
Mode: in.Mode,
|
Mode: in.Mode,
|
||||||
OpContext: fuseops.OpContext{Pid: inMsg.Header().Pid},
|
OpContext: fuseops.OpContext{
|
||||||
|
FuseID: inMsg.Header().Unique,
|
||||||
|
Pid: inMsg.Header().Pid,
|
||||||
|
Uid: inMsg.Header().Uid,
|
||||||
|
Gid: inMsg.Header().Gid,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
case fusekernel.OpPoll:
|
case fusekernel.OpPoll:
|
||||||
|
@ -783,6 +935,14 @@ func (c *Connection) kernelResponseForOp(
|
||||||
out := (*fusekernel.OpenOut)(m.Grow(int(unsafe.Sizeof(fusekernel.OpenOut{}))))
|
out := (*fusekernel.OpenOut)(m.Grow(int(unsafe.Sizeof(fusekernel.OpenOut{}))))
|
||||||
out.Fh = uint64(o.Handle)
|
out.Fh = uint64(o.Handle)
|
||||||
|
|
||||||
|
if o.CacheDir {
|
||||||
|
out.OpenFlags |= uint32(fusekernel.OpenCacheDir)
|
||||||
|
}
|
||||||
|
|
||||||
|
if o.KeepCache {
|
||||||
|
out.OpenFlags |= uint32(fusekernel.OpenKeepCache)
|
||||||
|
}
|
||||||
|
|
||||||
case *fuseops.ReadDirOp:
|
case *fuseops.ReadDirOp:
|
||||||
// convertInMessage already set up the destination buffer to be at the end
|
// convertInMessage already set up the destination buffer to be at the end
|
||||||
// of the out message. We need only shrink to the right size based on how
|
// of the out message. We need only shrink to the right size based on how
|
||||||
|
@ -837,7 +997,7 @@ func (c *Connection) kernelResponseForOp(
|
||||||
out.St.Ffree = o.InodesFree
|
out.St.Ffree = o.InodesFree
|
||||||
out.St.Namelen = 255
|
out.St.Namelen = 255
|
||||||
|
|
||||||
// The posix spec for sys/statvfs.h (http://goo.gl/LktgrF) defines the
|
// The posix spec for sys/statvfs.h (https://tinyurl.com/2juj6ah6) defines the
|
||||||
// following fields of statvfs, among others:
|
// following fields of statvfs, among others:
|
||||||
//
|
//
|
||||||
// f_bsize File system block size.
|
// f_bsize File system block size.
|
||||||
|
@ -847,7 +1007,7 @@ func (c *Connection) kernelResponseForOp(
|
||||||
// It appears as though f_bsize was the only thing supported by most unixes
|
// It appears as though f_bsize was the only thing supported by most unixes
|
||||||
// originally, but then f_frsize was added when new sorts of file systems
|
// originally, but then f_frsize was added when new sorts of file systems
|
||||||
// came about. Quoth The Linux Programming Interface by Michael Kerrisk
|
// came about. Quoth The Linux Programming Interface by Michael Kerrisk
|
||||||
// (https://goo.gl/5LZMxQ):
|
// (https://tinyurl.com/5n8mjtws):
|
||||||
//
|
//
|
||||||
// For most Linux file systems, the values of f_bsize and f_frsize are
|
// For most Linux file systems, the values of f_bsize and f_frsize are
|
||||||
// the same. However, some file systems support the notion of block
|
// the same. However, some file systems support the notion of block
|
||||||
|
@ -891,6 +1051,9 @@ func (c *Connection) kernelResponseForOp(
|
||||||
case *fuseops.FallocateOp:
|
case *fuseops.FallocateOp:
|
||||||
// Empty response
|
// Empty response
|
||||||
|
|
||||||
|
case *fuseops.SyncFSOp:
|
||||||
|
// Empty response
|
||||||
|
|
||||||
case *initOp:
|
case *initOp:
|
||||||
out := (*fusekernel.InitOut)(m.Grow(int(unsafe.Sizeof(fusekernel.InitOut{}))))
|
out := (*fusekernel.InitOut)(m.Grow(int(unsafe.Sizeof(fusekernel.InitOut{}))))
|
||||||
|
|
||||||
|
|
9
debug.go
9
debug.go
|
@ -115,6 +115,9 @@ func describeRequest(op interface{}) (s string) {
|
||||||
addComponent("offset %d", typed.Offset)
|
addComponent("offset %d", typed.Offset)
|
||||||
addComponent("length %d", typed.Length)
|
addComponent("length %d", typed.Length)
|
||||||
addComponent("mode %d", typed.Mode)
|
addComponent("mode %d", typed.Mode)
|
||||||
|
|
||||||
|
case *fuseops.ReleaseFileHandleOp:
|
||||||
|
addComponent("handle %d", typed.Handle)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use just the name if there is no extra info.
|
// Use just the name if there is no extra info.
|
||||||
|
@ -141,6 +144,10 @@ func describeResponse(op interface{}) string {
|
||||||
addComponent("inode %v", entry.Child)
|
addComponent("inode %v", entry.Child)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch typed := op.(type) {
|
||||||
|
case *fuseops.OpenFileOp:
|
||||||
|
addComponent("handle %d", typed.Handle)
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s", strings.Join(components, ", "))
|
return fmt.Sprintf("%s (%s)", opName(op), strings.Join(components, ", "))
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ func ConvertAttributes(
|
||||||
out.Blocks = (in.Size + 512 - 1) / 512
|
out.Blocks = (in.Size + 512 - 1) / 512
|
||||||
|
|
||||||
// Set the mode.
|
// Set the mode.
|
||||||
out.Mode = ConvertGolangMode(in.Mode)
|
out.Mode = ConvertGoMode(in.Mode)
|
||||||
|
|
||||||
if out.Mode & (syscall.S_IFCHR | syscall.S_IFBLK) != 0 {
|
if out.Mode & (syscall.S_IFCHR | syscall.S_IFBLK) != 0 {
|
||||||
out.Rdev = in.Rdev
|
out.Rdev = in.Rdev
|
||||||
|
@ -60,9 +60,10 @@ func ConvertAttributes(
|
||||||
// consumption by the fuse kernel module.
|
// consumption by the fuse kernel module.
|
||||||
func ConvertExpirationTime(t time.Time) (secs uint64, nsecs uint32) {
|
func ConvertExpirationTime(t time.Time) (secs uint64, nsecs uint32) {
|
||||||
// Fuse represents durations as unsigned 64-bit counts of seconds and 32-bit
|
// Fuse represents durations as unsigned 64-bit counts of seconds and 32-bit
|
||||||
// counts of nanoseconds (cf. http://goo.gl/EJupJV). So negative durations
|
// counts of nanoseconds (https://tinyurl.com/4muvkr6k). So negative
|
||||||
// are right out. There is no need to cap the positive magnitude, because
|
// durations are right out. There is no need to cap the positive magnitude,
|
||||||
// 2^64 seconds is well longer than the 2^63 ns range of time.Duration.
|
// because 2^64 seconds is well longer than the 2^63 ns range of
|
||||||
|
// time.Duration.
|
||||||
d := t.Sub(time.Now())
|
d := t.Sub(time.Now())
|
||||||
if d > 0 {
|
if d > 0 {
|
||||||
secs = uint64(d / time.Second)
|
secs = uint64(d / time.Second)
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ConvertFileMode returns an os.FileMode with the Go mode and permission bits
|
||||||
|
// set according to the Linux mode and permission bits.
|
||||||
func ConvertFileMode(unixMode uint32) os.FileMode {
|
func ConvertFileMode(unixMode uint32) os.FileMode {
|
||||||
mode := os.FileMode(unixMode & 0777)
|
mode := os.FileMode(unixMode & 0777)
|
||||||
switch unixMode & syscall.S_IFMT {
|
switch unixMode & syscall.S_IFMT {
|
||||||
|
@ -37,7 +39,9 @@ func ConvertFileMode(unixMode uint32) os.FileMode {
|
||||||
return mode
|
return mode
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertGolangMode(inMode os.FileMode) uint32 {
|
// ConvertGoMode returns an integer with the Linux mode and permission bits
|
||||||
|
// set according to the Go mode and permission bits.
|
||||||
|
func ConvertGoMode(inMode os.FileMode) uint32 {
|
||||||
outMode := uint32(inMode) & 0777
|
outMode := uint32(inMode) & 0777
|
||||||
switch {
|
switch {
|
||||||
default:
|
default:
|
||||||
|
|
292
fuseops/ops.go
292
fuseops/ops.go
|
@ -28,25 +28,35 @@ import (
|
||||||
// OpContext contains extra context that may be needed by some file systems.
|
// OpContext contains extra context that may be needed by some file systems.
|
||||||
// See https://libfuse.github.io/doxygen/structfuse__context.html as a reference.
|
// See https://libfuse.github.io/doxygen/structfuse__context.html as a reference.
|
||||||
type OpContext struct {
|
type OpContext struct {
|
||||||
|
// FuseID is the Unique identifier for each operation from the kernel.
|
||||||
|
FuseID uint64
|
||||||
|
|
||||||
// PID of the process that is invoking the operation.
|
// PID of the process that is invoking the operation.
|
||||||
// Not filled in case of a writepage operation.
|
// Not filled in case of a writepage operation.
|
||||||
Pid uint32
|
Pid uint32
|
||||||
|
|
||||||
|
// UID of the process that is invoking the operation.
|
||||||
|
// Not filled in case of a writepage operation.
|
||||||
|
Uid uint32
|
||||||
|
|
||||||
|
// GID of the process that is invoking the operation.
|
||||||
|
// Not filled in case of a writepage operation.
|
||||||
|
Gid uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return statistics about the file system's capacity and available resources.
|
// Return statistics about the file system's capacity and available resources.
|
||||||
//
|
//
|
||||||
// Called by statfs(2) and friends:
|
// Called by statfs(2) and friends:
|
||||||
//
|
//
|
||||||
// - (https://goo.gl/Xi1lDr) sys_statfs called user_statfs, which calls
|
// - (https://tinyurl.com/234ppacj) sys_statfs called user_statfs, which calls
|
||||||
// vfs_statfs, which calls statfs_by_dentry.
|
// vfs_statfs, which calls statfs_by_dentry.
|
||||||
//
|
//
|
||||||
// - (https://goo.gl/VAIOwU) statfs_by_dentry calls the superblock
|
// - (https://tinyurl.com/u6keadjz) statfs_by_dentry calls the superblock
|
||||||
// operation statfs, which in our case points at
|
// operation statfs, which in our case points at
|
||||||
// fuse_statfs (cf. https://goo.gl/L7BTM3)
|
// fuse_statfs (https://tinyurl.com/mr45wd28)
|
||||||
//
|
//
|
||||||
// - (https://goo.gl/Zn7Sgl) fuse_statfs sends a statfs op, then uses
|
// - (https://tinyurl.com/3wt3dw3c) fuse_statfs sends a statfs op, then uses
|
||||||
// convert_fuse_statfs to convert the response in a straightforward
|
// convert_fuse_statfs to convert the response in a straightforward manner.
|
||||||
// manner.
|
|
||||||
//
|
//
|
||||||
// This op is particularly important on OS X: if you don't implement it, the
|
// This op is particularly important on OS X: if you don't implement it, the
|
||||||
// file system will not successfully mount. If you don't model a sane amount of
|
// file system will not successfully mount. If you don't model a sane amount of
|
||||||
|
@ -57,15 +67,15 @@ type StatFSOp struct {
|
||||||
// system's capacity and space availability.
|
// system's capacity and space availability.
|
||||||
//
|
//
|
||||||
// On Linux this is surfaced as statfs::f_frsize, matching the posix standard
|
// On Linux this is surfaced as statfs::f_frsize, matching the posix standard
|
||||||
// (http://goo.gl/LktgrF), which says that f_blocks and friends are in units
|
// (https://tinyurl.com/2juj6ah6), which says that f_blocks and friends are
|
||||||
// of f_frsize. On OS X this is surfaced as statfs::f_bsize, which plays the
|
// in units of f_frsize. On OS X this is surfaced as statfs::f_bsize, which
|
||||||
// same roll.
|
// plays the same roll.
|
||||||
//
|
//
|
||||||
// It appears as though the original intent of statvfs::f_frsize in the posix
|
// It appears as though the original intent of statvfs::f_frsize in the posix
|
||||||
// standard was to support a smaller addressable unit than statvfs::f_bsize
|
// standard was to support a smaller addressable unit than statvfs::f_bsize
|
||||||
// (cf. The Linux Programming Interface by Michael Kerrisk,
|
// (cf. The Linux Programming Interface by Michael Kerrisk,
|
||||||
// https://goo.gl/5LZMxQ). Therefore users should probably arrange for this
|
// https://tinyurl.com/5n8mjtws). Therefore users should probably arrange for
|
||||||
// to be no larger than IoSize.
|
// this to be no larger than IoSize.
|
||||||
//
|
//
|
||||||
// On Linux this can be any value, and will be faithfully returned to the
|
// On Linux this can be any value, and will be faithfully returned to the
|
||||||
// caller of statfs(2) (see the code walk above). On OS X it appears that
|
// caller of statfs(2) (see the code walk above). On OS X it appears that
|
||||||
|
@ -183,20 +193,22 @@ type SetInodeAttributesOp struct {
|
||||||
// contain a note of this (but see also the note about the root inode below).
|
// contain a note of this (but see also the note about the root inode below).
|
||||||
// For example, LookUpInodeOp and MkDirOp. The authoritative source is the
|
// For example, LookUpInodeOp and MkDirOp. The authoritative source is the
|
||||||
// libfuse documentation, which states that any op that returns
|
// libfuse documentation, which states that any op that returns
|
||||||
// fuse_reply_entry fuse_reply_create implicitly increments (cf.
|
// fuse_reply_entry fuse_reply_create implicitly increments
|
||||||
// http://goo.gl/o5C7Dx).
|
// (https://tinyurl.com/2xd5zssm).
|
||||||
//
|
//
|
||||||
// If the reference count hits zero, the file system can forget about that ID
|
// If the reference count hits zero, the file system can forget about that ID
|
||||||
// entirely, and even re-use it in future responses. The kernel guarantees that
|
// entirely, and even re-use it in future responses. The kernel guarantees that
|
||||||
// it will not otherwise use it again.
|
// it will not otherwise use it again.
|
||||||
//
|
//
|
||||||
// The reference count corresponds to fuse_inode::nlookup
|
// The reference count corresponds to fuse_inode::nlookup
|
||||||
// (http://goo.gl/ut48S4). Some examples of where the kernel manipulates it:
|
// (https://tinyurl.com/ycka69ck). Some examples of where the kernel
|
||||||
|
// manipulates it:
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/vPD9Oh) Any caller to fuse_iget increases the count.
|
// - (https://tinyurl.com/s8dz2ays) Any caller to fuse_iget increases the
|
||||||
// - (http://goo.gl/B6tTTC) fuse_lookup_name calls fuse_iget.
|
// count.
|
||||||
// - (http://goo.gl/IlcxWv) fuse_create_open calls fuse_iget.
|
// - (https://tinyurl.com/mu37ceua) fuse_lookup_name calls fuse_iget.
|
||||||
// - (http://goo.gl/VQMQul) fuse_dentry_revalidate increments after
|
// - (https://tinyurl.com/2nyhhnsh) fuse_create_open calls fuse_iget.
|
||||||
|
// - (https://tinyurl.com/mnjpu3a9) fuse_dentry_revalidate increments after
|
||||||
// revalidating.
|
// revalidating.
|
||||||
//
|
//
|
||||||
// In contrast to all other inodes, RootInodeID begins with an implicit
|
// In contrast to all other inodes, RootInodeID begins with an implicit
|
||||||
|
@ -204,12 +216,13 @@ type SetInodeAttributesOp struct {
|
||||||
// could be no such op, because the root cannot be referred to by name.) Code
|
// could be no such op, because the root cannot be referred to by name.) Code
|
||||||
// walk:
|
// walk:
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/gWAheU) fuse_fill_super calls fuse_get_root_inode.
|
// - (https://tinyurl.com/yf8m2drx) fuse_fill_super calls
|
||||||
|
// fuse_get_root_inode.
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/AoLsbb) fuse_get_root_inode calls fuse_iget without
|
// - (https://tinyurl.com/35f86asu) fuse_get_root_inode calls fuse_iget
|
||||||
// sending any particular request.
|
// without sending any particular request.
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/vPD9Oh) fuse_iget increments nlookup.
|
// - (https://tinyurl.com/s8dz2ays) fuse_iget increments nlookup.
|
||||||
//
|
//
|
||||||
// File systems should tolerate but not rely on receiving forget ops for
|
// File systems should tolerate but not rely on receiving forget ops for
|
||||||
// remaining inodes when the file system unmounts, including the root inode.
|
// remaining inodes when the file system unmounts, including the root inode.
|
||||||
|
@ -259,10 +272,11 @@ type BatchForgetOp struct {
|
||||||
//
|
//
|
||||||
// The Linux kernel appears to verify the name doesn't already exist (mkdir
|
// The Linux kernel appears to verify the name doesn't already exist (mkdir
|
||||||
// calls mkdirat calls user_path_create calls filename_create, which verifies:
|
// calls mkdirat calls user_path_create calls filename_create, which verifies:
|
||||||
// http://goo.gl/FZpLu5). Indeed, the tests in samples/memfs that call in
|
// https://tinyurl.com/24yw46mf). Indeed, the tests in samples/memfs that call
|
||||||
// parallel appear to bear this out. But osxfuse does not appear to guarantee
|
// in parallel appear to bear this out. But osxfuse does not appear to
|
||||||
// this (cf. https://goo.gl/PqzZDv). And if names may be created outside of the
|
// guarantee this (https://tinyurl.com/22587hcf). And if names may be created
|
||||||
// kernel's control, it doesn't matter what the kernel does anyway.
|
// outside of the kernel's control, it doesn't matter what the kernel does
|
||||||
|
// anyway.
|
||||||
//
|
//
|
||||||
// Therefore the file system should return EEXIST if the name already exists.
|
// Therefore the file system should return EEXIST if the name already exists.
|
||||||
type MkDirOp struct {
|
type MkDirOp struct {
|
||||||
|
@ -283,14 +297,14 @@ type MkDirOp struct {
|
||||||
|
|
||||||
// Create a file inode as a child of an existing directory inode. The kernel
|
// Create a file inode as a child of an existing directory inode. The kernel
|
||||||
// sends this in response to a mknod(2) call. It may also send it in special
|
// sends this in response to a mknod(2) call. It may also send it in special
|
||||||
// cases such as an NFS export (cf. https://goo.gl/HiLfnK). It is more typical
|
// cases such as an NFS export (https://tinyurl.com/5dwxr7c9). It is more typical
|
||||||
// to see CreateFileOp, which is received for an open(2) that creates a file.
|
// to see CreateFileOp, which is received for an open(2) that creates a file.
|
||||||
//
|
//
|
||||||
// The Linux kernel appears to verify the name doesn't already exist (mknod
|
// The Linux kernel appears to verify the name doesn't already exist (mknod
|
||||||
// calls sys_mknodat calls user_path_create calls filename_create, which
|
// calls sys_mknodat calls user_path_create calls filename_create, which
|
||||||
// verifies: http://goo.gl/FZpLu5). But osxfuse may not guarantee this, as with
|
// verifies: https://tinyurl.com/24yw46mf). But osxfuse may not guarantee this,
|
||||||
// mkdir(2). And if names may be created outside of the kernel's control, it
|
// as with mkdir(2). And if names may be created outside of the kernel's
|
||||||
// doesn't matter what the kernel does anyway.
|
// control, it doesn't matter what the kernel does anyway.
|
||||||
//
|
//
|
||||||
// Therefore the file system should return EEXIST if the name already exists.
|
// Therefore the file system should return EEXIST if the name already exists.
|
||||||
type MkNodeOp struct {
|
type MkNodeOp struct {
|
||||||
|
@ -316,10 +330,10 @@ type MkNodeOp struct {
|
||||||
//
|
//
|
||||||
// The kernel sends this when the user asks to open a file with the O_CREAT
|
// The kernel sends this when the user asks to open a file with the O_CREAT
|
||||||
// flag and the kernel has observed that the file doesn't exist. (See for
|
// flag and the kernel has observed that the file doesn't exist. (See for
|
||||||
// example lookup_open, http://goo.gl/PlqE9d). However, osxfuse doesn't appear
|
// example lookup_open, https://tinyurl.com/49899mvb). However, osxfuse doesn't
|
||||||
// to make this check atomically (cf. https://goo.gl/PqzZDv). And if names may
|
// appear to make this check atomically (https://tinyurl.com/22587hcf). And if
|
||||||
// be created outside of the kernel's control, it doesn't matter what the
|
// names may be created outside of the kernel's control, it doesn't matter what
|
||||||
// kernel does anyway.
|
// the kernel does anyway.
|
||||||
//
|
//
|
||||||
// Therefore the file system should return EEXIST if the name already exists.
|
// Therefore the file system should return EEXIST if the name already exists.
|
||||||
type CreateFileOp struct {
|
type CreateFileOp struct {
|
||||||
|
@ -397,8 +411,8 @@ type CreateLinkOp struct {
|
||||||
// Rename a file or directory, given the IDs of the original parent directory
|
// Rename a file or directory, given the IDs of the original parent directory
|
||||||
// and the new one (which may be the same).
|
// and the new one (which may be the same).
|
||||||
//
|
//
|
||||||
// In Linux, this is called by vfs_rename (https://goo.gl/eERItT), which is
|
// In Linux, this is called by vfs_rename (https://tinyurl.com/2xbx9kr2), which
|
||||||
// called by sys_renameat2 (https://goo.gl/fCC9qC).
|
// is called by sys_renameat2 (https://tinyurl.com/4zyak2kt).
|
||||||
//
|
//
|
||||||
// The kernel takes care of ensuring that the source and destination are not
|
// The kernel takes care of ensuring that the source and destination are not
|
||||||
// identical (in which case it does nothing), that the rename is not across
|
// identical (in which case it does nothing), that the rename is not across
|
||||||
|
@ -407,7 +421,7 @@ type CreateLinkOp struct {
|
||||||
//
|
//
|
||||||
// - If the new name is an existing directory, the file system must ensure it
|
// - If the new name is an existing directory, the file system must ensure it
|
||||||
// is empty before replacing it, returning ENOTEMPTY otherwise. (This is
|
// is empty before replacing it, returning ENOTEMPTY otherwise. (This is
|
||||||
// per the posix spec: http://goo.gl/4XtT79)
|
// per the posix spec: https://tinyurl.com/5n865nx9)
|
||||||
//
|
//
|
||||||
// - The rename must be atomic from the point of view of an observer of the
|
// - The rename must be atomic from the point of view of an observer of the
|
||||||
// new name. That is, if the new name already exists, there must be no
|
// new name. That is, if the new name already exists, there must be no
|
||||||
|
@ -415,9 +429,9 @@ type CreateLinkOp struct {
|
||||||
//
|
//
|
||||||
// - It is okay for the new name to be modified before the old name is
|
// - It is okay for the new name to be modified before the old name is
|
||||||
// removed; these need not be atomic. In fact, the Linux man page
|
// removed; these need not be atomic. In fact, the Linux man page
|
||||||
// explicitly says this is likely (cf. https://goo.gl/Y1wVZc).
|
// explicitly says this is likely (https://tinyurl.com/mdpbpjmr).
|
||||||
//
|
//
|
||||||
// - Linux bends over backwards (https://goo.gl/pLDn3r) to ensure that
|
// - Linux bends over backwards (https://tinyurl.com/3hmt7puy) to ensure that
|
||||||
// neither the old nor the new parent can be concurrently modified. But
|
// neither the old nor the new parent can be concurrently modified. But
|
||||||
// it's not clear whether OS X does this, and in any case it doesn't matter
|
// it's not clear whether OS X does this, and in any case it doesn't matter
|
||||||
// for file systems that may be modified remotely. Therefore a careful file
|
// for file systems that may be modified remotely. Therefore a careful file
|
||||||
|
@ -446,7 +460,7 @@ type RenameOp struct {
|
||||||
//
|
//
|
||||||
// The file system is responsible for checking that the directory is empty.
|
// The file system is responsible for checking that the directory is empty.
|
||||||
//
|
//
|
||||||
// Sample implementation in ext2: ext2_rmdir (http://goo.gl/B9QmFf)
|
// Sample implementation in ext2: ext2_rmdir (https://tinyurl.com/bajkpcf9)
|
||||||
type RmDirOp struct {
|
type RmDirOp struct {
|
||||||
// The ID of parent directory inode, and the name of the directory being
|
// The ID of parent directory inode, and the name of the directory being
|
||||||
// removed within it.
|
// removed within it.
|
||||||
|
@ -460,7 +474,7 @@ type RmDirOp struct {
|
||||||
// ForgetInodeOp. It may still be referenced before then if a user still has
|
// ForgetInodeOp. It may still be referenced before then if a user still has
|
||||||
// the file open.
|
// the file open.
|
||||||
//
|
//
|
||||||
// Sample implementation in ext2: ext2_unlink (http://goo.gl/hY6r6C)
|
// Sample implementation in ext2: ext2_unlink (https://tinyurl.com/3wpwedcp)
|
||||||
type UnlinkOp struct {
|
type UnlinkOp struct {
|
||||||
// The ID of parent directory inode, and the name of the entry being removed
|
// The ID of parent directory inode, and the name of the entry being removed
|
||||||
// within it.
|
// within it.
|
||||||
|
@ -493,6 +507,14 @@ type OpenDirOp struct {
|
||||||
// a later call to ReleaseDirHandle.
|
// a later call to ReleaseDirHandle.
|
||||||
Handle HandleID
|
Handle HandleID
|
||||||
OpContext OpContext
|
OpContext OpContext
|
||||||
|
|
||||||
|
// CacheDir conveys to the kernel to cache the response of next
|
||||||
|
// ReadDirOp as page cache. Once cached, listing on that directory will be
|
||||||
|
// served from the kernel until invalidated.
|
||||||
|
CacheDir bool
|
||||||
|
|
||||||
|
// KeepCache instructs the kernel to not invalidate the data cache on open calls.
|
||||||
|
KeepCache bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read entries from a directory previously opened with OpenDir.
|
// Read entries from a directory previously opened with OpenDir.
|
||||||
|
@ -512,47 +534,51 @@ type ReadDirOp struct {
|
||||||
// at zero and is set by llseek and by the final consumed result returned by
|
// at zero and is set by llseek and by the final consumed result returned by
|
||||||
// each call to ReadDir:
|
// each call to ReadDir:
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/2nWJPL) iterate_dir, which is called by getdents(2) and
|
// * (https://tinyurl.com/3ueykmaj) iterate_dir, which is called by
|
||||||
// readdir(2), sets dir_context::pos to file::f_pos before calling
|
// getdents(2) and readdir(2), sets dir_context::pos to file::f_pos
|
||||||
// f_op->iterate, and then does the opposite assignment afterward.
|
// before calling f_op->iterate, and then does the opposite assignment
|
||||||
|
// afterward.
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/rTQVSL) fuse_readdir, which implements iterate for fuse
|
// * (https://tinyurl.com/a8urhfy9) fuse_readdir, which implements iterate
|
||||||
// directories, passes dir_context::pos as the offset to fuse_read_fill,
|
// for fuse directories, passes dir_context::pos as the offset to
|
||||||
// which passes it on to user-space. fuse_readdir later calls
|
// fuse_read_fill, which passes it on to user-space. fuse_readdir later
|
||||||
// parse_dirfile with the same context.
|
// calls parse_dirfile with the same context.
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/vU5ukv) For each returned result (except perhaps the
|
// * (https://tinyurl.com/5cev5fn4) For each returned result (except
|
||||||
// last, which may be truncated by the page boundary), parse_dirfile
|
// perhaps the last, which may be truncated by the page boundary),
|
||||||
// updates dir_context::pos with fuse_dirent::off.
|
// parse_dirfile updates dir_context::pos with fuse_dirent::off.
|
||||||
//
|
//
|
||||||
// It is affected by the Posix directory stream interfaces in the following
|
// It is affected by the Posix directory stream interfaces in the following
|
||||||
// manner:
|
// manner:
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/fQhbyn, http://goo.gl/ns1kDF) opendir initially causes
|
// * (https://tinyurl.com/2pjv5jvz, https://tinyurl.com/2r6h4mkj) opendir
|
||||||
// filepos to be set to zero.
|
// initially causes filepos to be set to zero.
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/ezNKyR, http://goo.gl/xOmDv0) readdir allows the user
|
// * (https://tinyurl.com/2yvcbcpv, https://tinyurl.com/bddezwp4) readdir
|
||||||
// to iterate through the directory one entry at a time. As each entry is
|
// allows the user to iterate through the directory one entry at a time.
|
||||||
// consumed, its d_off field is stored in __dirstream::filepos.
|
// As each entry is consumed, its d_off field is stored in
|
||||||
|
// __dirstream::filepos.
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/WEOXG8, http://goo.gl/rjSXl3) telldir allows the user
|
// * (https://tinyurl.com/2pfbfe9v, https://tinyurl.com/4wtat58a) telldir
|
||||||
// to obtain the d_off field from the most recently returned entry.
|
// allows the user to obtain the d_off field from the most recently
|
||||||
|
// returned entry.
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/WG3nDZ, http://goo.gl/Lp0U6W) seekdir allows the user
|
// * (https://tinyurl.com/bdynryef, https://tinyurl.com/4hysrnb8) seekdir
|
||||||
// to seek backward to an offset previously returned by telldir. It
|
// allows the user to seek backward to an offset previously returned by
|
||||||
// stores the new offset in filepos, and calls llseek to update the
|
// telldir. It stores the new offset in filepos, and calls llseek to
|
||||||
// kernel's struct file.
|
// update the kernel's struct file.
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/gONQhz, http://goo.gl/VlrQkc) rewinddir allows the user
|
// * (https://tinyurl.com/5n8dkb44, https://tinyurl.com/3jnn5nnn) rewinddir
|
||||||
// to go back to the beginning of the directory, obtaining a fresh view.
|
// allows the user to go back to the beginning of the directory,
|
||||||
// It updates filepos and calls llseek to update the kernel's struct
|
// obtaining a fresh view. It updates filepos and calls llseek to update
|
||||||
// file.
|
// the kernel's struct file.
|
||||||
//
|
//
|
||||||
// Unfortunately, FUSE offers no way to intercept seeks
|
// Unfortunately, FUSE offers no way to intercept seeks
|
||||||
// (http://goo.gl/H6gEXa), so there is no way to cause seekdir or rewinddir
|
// (https://tinyurl.com/4bm2sfjd), so there is no way to cause seekdir or
|
||||||
// to fail. Additionally, there is no way to distinguish an explicit
|
// rewinddir to fail. Additionally, there is no way to distinguish an
|
||||||
// rewinddir followed by readdir from the initial readdir, or a rewinddir
|
// explicit rewinddir followed by readdir from the initial readdir, or a
|
||||||
// from a seekdir to the value returned by telldir just after opendir.
|
// rewinddir from a seekdir to the value returned by telldir just after
|
||||||
|
// opendir.
|
||||||
//
|
//
|
||||||
// Luckily, Posix is vague about what the user will see if they seek
|
// Luckily, Posix is vague about what the user will see if they seek
|
||||||
// backwards, and requires the user not to seek to an old offset after a
|
// backwards, and requires the user not to seek to an old offset after a
|
||||||
|
@ -571,9 +597,9 @@ type ReadDirOp struct {
|
||||||
// The destination buffer, whose length gives the size of the read.
|
// The destination buffer, whose length gives the size of the read.
|
||||||
//
|
//
|
||||||
// The output data should consist of a sequence of FUSE directory entries in
|
// The output data should consist of a sequence of FUSE directory entries in
|
||||||
// the format generated by fuse_add_direntry (http://goo.gl/qCcHCV), which is
|
// the format generated by fuse_add_direntry (https://tinyurl.com/3r9t7d2p),
|
||||||
// consumed by parse_dirfile (http://goo.gl/2WUmD2). Use fuseutil.WriteDirent
|
// which is consumed by parse_dirfile (https://tinyurl.com/bevwty74). Use
|
||||||
// or fuseutil.WriteDirentPlus to generate this data.
|
// fuseutil.WriteDirent or fuseutil.WriteDirentPlus to generate this data.
|
||||||
//
|
//
|
||||||
// Each entry returned exposes a directory offset to the user that may later
|
// Each entry returned exposes a directory offset to the user that may later
|
||||||
// show up in ReadDirRequest.Offset. See notes on that field for more
|
// show up in ReadDirRequest.Offset. See notes on that field for more
|
||||||
|
@ -586,10 +612,10 @@ type ReadDirOp struct {
|
||||||
// entries available or the final entry would not fit.
|
// entries available or the final entry would not fit.
|
||||||
//
|
//
|
||||||
// Zero means that the end of the directory has been reached. This is
|
// Zero means that the end of the directory has been reached. This is
|
||||||
// unambiguous because NAME_MAX (https://goo.gl/ZxzKaE) plus the size of
|
// unambiguous because NAME_MAX (https://tinyurl.com/4r2b68jp) plus the size
|
||||||
// fuse_dirent (https://goo.gl/WO8s3F) plus the 8-byte alignment of
|
// of fuse_dirent (https://tinyurl.com/mp43bu8) plus the 8-byte alignment of
|
||||||
// FUSE_DIRENT_ALIGN (http://goo.gl/UziWvH) is less than the read size of
|
// FUSE_DIRENT_ALIGN (https://tinyurl.com/3m3ewu7h) is less than the read
|
||||||
// PAGE_SIZE used by fuse_readdir (cf. https://goo.gl/VajtS2).
|
// size of PAGE_SIZE used by fuse_readdir (https://tinyurl.com/mrwxsfxw).
|
||||||
BytesRead int
|
BytesRead int
|
||||||
OpContext OpContext
|
OpContext OpContext
|
||||||
}
|
}
|
||||||
|
@ -601,7 +627,8 @@ type ReadDirOp struct {
|
||||||
// The kernel guarantees that the handle ID will not be used in further ops
|
// The kernel guarantees that the handle ID will not be used in further ops
|
||||||
// sent to the file system (unless it is reissued by the file system).
|
// sent to the file system (unless it is reissued by the file system).
|
||||||
//
|
//
|
||||||
// Errors from this op are ignored by the kernel (cf. http://goo.gl/RL38Do).
|
// Errors from this op are ignored by the kernel
|
||||||
|
// (https://tinyurl.com/2aaccyzk).
|
||||||
type ReleaseDirHandleOp struct {
|
type ReleaseDirHandleOp struct {
|
||||||
// The handle ID to be released. The kernel guarantees that this ID will not
|
// The handle ID to be released. The kernel guarantees that this ID will not
|
||||||
// be used in further calls to the file system (unless it is reissued by the
|
// be used in further calls to the file system (unless it is reissued by the
|
||||||
|
@ -634,15 +661,15 @@ type OpenFileOp struct {
|
||||||
Handle HandleID
|
Handle HandleID
|
||||||
|
|
||||||
// By default, fuse invalidates the kernel's page cache for an inode when a
|
// By default, fuse invalidates the kernel's page cache for an inode when a
|
||||||
// new file handle is opened for that inode (cf. https://goo.gl/2rZ9uk). The
|
// new file handle is opened for that inode (https://tinyurl.com/yyb497zy).
|
||||||
// intent appears to be to allow users to "see" content that has changed
|
// The intent appears to be to allow users to "see" content that has changed
|
||||||
// remotely on a networked file system by re-opening the file.
|
// remotely on a networked file system by re-opening the file.
|
||||||
//
|
//
|
||||||
// For file systems where this is not a concern because all modifications for
|
// For file systems where this is not a concern because all modifications for
|
||||||
// a particular inode go through the kernel, set this field to true to
|
// a particular inode go through the kernel, set this field to true to
|
||||||
// disable this behavior.
|
// disable this behavior.
|
||||||
//
|
//
|
||||||
// (More discussion: http://goo.gl/cafzWF)
|
// (More discussion: https://tinyurl.com/4znxvzwh)
|
||||||
//
|
//
|
||||||
// Note that on OS X it appears that the behavior is always as if this field
|
// Note that on OS X it appears that the behavior is always as if this field
|
||||||
// is set to true, regardless of its value, at least for files opened in the
|
// is set to true, regardless of its value, at least for files opened in the
|
||||||
|
@ -691,15 +718,21 @@ type ReadFileOp struct {
|
||||||
// Set by the file system: the number of bytes read.
|
// Set by the file system: the number of bytes read.
|
||||||
//
|
//
|
||||||
// The FUSE documentation requires that exactly the requested number of bytes
|
// The FUSE documentation requires that exactly the requested number of bytes
|
||||||
// be returned, except in the case of EOF or error (http://goo.gl/ZgfBkF).
|
// be returned, except in the case of EOF or error
|
||||||
// This appears to be because it uses file mmapping machinery
|
// (https://tinyurl.com/2mzewn35). This appears to be because it uses file
|
||||||
// (http://goo.gl/SGxnaN) to read a page at a time. It appears to understand
|
// mmapping machinery (https://tinyurl.com/avxy3dvm) to read a page at a
|
||||||
// where EOF is by checking the inode size (http://goo.gl/0BkqKD), returned
|
// time. It appears to understand where EOF is by checking the inode size
|
||||||
// by a previous call to LookUpInode, GetInodeAttributes, etc.
|
// (https://tinyurl.com/2eteerzt), returned by a previous call to
|
||||||
|
// LookUpInode, GetInodeAttributes, etc.
|
||||||
//
|
//
|
||||||
// If direct IO is enabled, semantics should match those of read(2).
|
// If direct IO is enabled, semantics should match those of read(2).
|
||||||
BytesRead int
|
BytesRead int
|
||||||
OpContext OpContext
|
OpContext OpContext
|
||||||
|
|
||||||
|
// If set, this function will be invoked after the operation response has been
|
||||||
|
// sent to the kernel and before the buffers containing the response data are
|
||||||
|
// freed.
|
||||||
|
Callback func()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write data to a file previously opened with CreateFile or OpenFile.
|
// Write data to a file previously opened with CreateFile or OpenFile.
|
||||||
|
@ -709,21 +742,22 @@ type ReadFileOp struct {
|
||||||
// page via the FUSE VFS layer, causing this op to be sent:
|
// page via the FUSE VFS layer, causing this op to be sent:
|
||||||
//
|
//
|
||||||
// - The kernel calls address_space_operations::writepage when a dirty page
|
// - The kernel calls address_space_operations::writepage when a dirty page
|
||||||
// needs to be written to backing store (cf. http://goo.gl/Ezbewg). Fuse
|
// needs to be written to backing store (https://tinyurl.com/yck2sf5u).
|
||||||
// sets this to fuse_writepage (cf. http://goo.gl/IeNvLT).
|
// Fuse sets this to fuse_writepage (https://tinyurl.com/5n989f8p).
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/Eestuy) fuse_writepage calls fuse_writepage_locked.
|
// - (https://tinyurl.com/mvn6zv3j) fuse_writepage calls
|
||||||
|
// fuse_writepage_locked.
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/RqYIxY) fuse_writepage_locked makes a write request to
|
// - (https://tinyurl.com/2wn8scwb) fuse_writepage_locked makes a write
|
||||||
// the userspace server.
|
// request to the userspace server.
|
||||||
//
|
//
|
||||||
// Note that the kernel *will* ensure that writes are received and acknowledged
|
// Note that the kernel *will* ensure that writes are received and acknowledged
|
||||||
// by the file system before sending a FlushFileOp when closing the file
|
// by the file system before sending a FlushFileOp when closing the file
|
||||||
// descriptor to which they were written. Cf. the notes on
|
// descriptor to which they were written. Cf. the notes on
|
||||||
// fuse.MountConfig.DisableWritebackCaching.
|
// fuse.MountConfig.DisableWritebackCaching.
|
||||||
//
|
//
|
||||||
// (See also http://goo.gl/ocdTdM, fuse-devel thread "Fuse guarantees on
|
// (See also https://tinyurl.com/5dchkdtx, fuse-devel thread "Fuse guarantees
|
||||||
// concurrent requests".)
|
// on concurrent requests".)
|
||||||
type WriteFileOp struct {
|
type WriteFileOp struct {
|
||||||
// The file inode that we are modifying, and the handle previously returned
|
// The file inode that we are modifying, and the handle previously returned
|
||||||
// by CreateFile or OpenFile when opening that inode.
|
// by CreateFile or OpenFile when opening that inode.
|
||||||
|
@ -755,9 +789,9 @@ type WriteFileOp struct {
|
||||||
// The data to write.
|
// The data to write.
|
||||||
//
|
//
|
||||||
// The FUSE documentation requires that exactly the number of bytes supplied
|
// The FUSE documentation requires that exactly the number of bytes supplied
|
||||||
// be written, except on error (http://goo.gl/KUpwwn). This appears to be
|
// be written, except on error (https://tinyurl.com/yuruk5tx). This appears
|
||||||
// because it uses file mmapping machinery (http://goo.gl/SGxnaN) to write a
|
// to be because it uses file mmapping machinery
|
||||||
// page at a time.
|
// (https://tinyurl.com/avxy3dvm) to write a page at a time.
|
||||||
Data []byte
|
Data []byte
|
||||||
|
|
||||||
// Set by the file system: "no reuse" flag.
|
// Set by the file system: "no reuse" flag.
|
||||||
|
@ -771,20 +805,25 @@ type WriteFileOp struct {
|
||||||
SuppressReuse bool
|
SuppressReuse bool
|
||||||
|
|
||||||
OpContext OpContext
|
OpContext OpContext
|
||||||
|
|
||||||
|
// If set, this function will be invoked after the operation response has been
|
||||||
|
// sent to the kernel and before the buffers containing the response data are
|
||||||
|
// freed.
|
||||||
|
Callback func()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Synchronize the current contents of an open file to storage.
|
// Synchronize the current contents of an open file to storage.
|
||||||
//
|
//
|
||||||
// vfs.txt documents this as being called for by the fsync(2) system call
|
// vfs.txt documents this as being called for by the fsync(2) system call
|
||||||
// (cf. http://goo.gl/j9X8nB). Code walk for that case:
|
// (https://tinyurl.com/y2kdrfzw). Code walk for that case:
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/IQkWZa) sys_fsync calls do_fsync, calls vfs_fsync, calls
|
// - (https://tinyurl.com/2s44cefz) sys_fsync calls do_fsync, calls
|
||||||
// vfs_fsync_range.
|
// vfs_fsync, calls vfs_fsync_range.
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/5L2SMy) vfs_fsync_range calls f_op->fsync.
|
// - (https://tinyurl.com/bdhhfam5) vfs_fsync_range calls f_op->fsync.
|
||||||
//
|
//
|
||||||
// Note that this is also sent by fdatasync(2) (cf. http://goo.gl/01R7rF), and
|
// Note that this is also sent by fdatasync(2) (https://tinyurl.com/ja5wtszf),
|
||||||
// may be sent for msync(2) with the MS_SYNC flag (see the notes on
|
// and may be sent for msync(2) with the MS_SYNC flag (see the notes on
|
||||||
// FlushFileOp).
|
// FlushFileOp).
|
||||||
//
|
//
|
||||||
// See also: FlushFileOp, which may perform a similar function when closing a
|
// See also: FlushFileOp, which may perform a similar function when closing a
|
||||||
|
@ -799,39 +838,42 @@ type SyncFileOp struct {
|
||||||
// Flush the current state of an open file to storage upon closing a file
|
// Flush the current state of an open file to storage upon closing a file
|
||||||
// descriptor.
|
// descriptor.
|
||||||
//
|
//
|
||||||
// vfs.txt documents this as being sent for each close(2) system call (cf.
|
// vfs.txt documents this as being sent for each close(2) system call
|
||||||
// http://goo.gl/FSkbrq). Code walk for that case:
|
// (https://tinyurl.com/r4ujfxkc). Code walk for that case:
|
||||||
//
|
//
|
||||||
// - (http://goo.gl/e3lv0e) sys_close calls __close_fd, calls filp_close.
|
// - (https://tinyurl.com/2kzyyjcu) sys_close calls __close_fd, calls
|
||||||
// - (http://goo.gl/nI8fxD) filp_close calls f_op->flush (fuse_flush).
|
// filp_close.
|
||||||
|
|
||||||
|
// - (https://tinyurl.com/4zdxrz52) filp_close calls f_op->flush
|
||||||
|
// (fuse_flush).
|
||||||
//
|
//
|
||||||
// But note that this is also sent in other contexts where a file descriptor is
|
// But note that this is also sent in other contexts where a file descriptor is
|
||||||
// closed, such as dup2(2) (cf. http://goo.gl/NQDvFS). In the case of close(2),
|
// closed, such as dup2(2) (https://tinyurl.com/5bj3z3f5). In the case of
|
||||||
// a flush error is returned to the user. For dup2(2), it is not.
|
// close(2), a flush error is returned to the user. For dup2(2), it is not.
|
||||||
//
|
//
|
||||||
// One potentially significant case where this may not be sent is mmap'd files,
|
// One potentially significant case where this may not be sent is mmap'd files,
|
||||||
// where the behavior is complicated:
|
// where the behavior is complicated:
|
||||||
//
|
//
|
||||||
// - munmap(2) does not cause flushes (cf. http://goo.gl/j8B9g0).
|
// - munmap(2) does not cause flushes (https://tinyurl.com/ycy9z2jb).
|
||||||
//
|
//
|
||||||
// - On OS X, if a user modifies a mapped file via the mapping before
|
// - On OS X, if a user modifies a mapped file via the mapping before closing
|
||||||
// closing the file with close(2), the WriteFileOps for the modifications
|
// the file with close(2), the WriteFileOps for the modifications may not
|
||||||
// may not be received before the FlushFileOp for the close(2) (cf.
|
// be received before the FlushFileOp for the close(2) (cf.
|
||||||
// https://github.com/osxfuse/osxfuse/issues/202). It appears that this may
|
// https://github.com/osxfuse/osxfuse/issues/202). It appears that this may
|
||||||
// be fixed in osxfuse 3 (cf. https://goo.gl/rtvbko).
|
// be fixed in osxfuse 3 (https://tinyurl.com/2ne2jv8u).
|
||||||
//
|
//
|
||||||
// - However, you safely can arrange for writes via a mapping to be
|
// - However, you safely can arrange for writes via a mapping to be flushed
|
||||||
// flushed by calling msync(2) followed by close(2). On OS X msync(2)
|
// by calling msync(2) followed by close(2). On OS X msync(2) will cause a
|
||||||
// will cause a WriteFileOps to go through and close(2) will cause a
|
// WriteFileOps to go through and close(2) will cause a FlushFile as usual
|
||||||
// FlushFile as usual (cf. http://goo.gl/kVmNcx). On Linux, msync(2) does
|
// (https://tinyurl.com/2p9b4axf). On Linux, msync(2) does nothing unless
|
||||||
// nothing unless you set the MS_SYNC flag, in which case it causes a
|
// you set the MS_SYNC flag, in which case it causes a SyncFileOp to be
|
||||||
// SyncFileOp to be sent (cf. http://goo.gl/P3mErk).
|
// sent (https://tinyurl.com/2y3d9hhj).
|
||||||
//
|
//
|
||||||
// In summary: if you make data durable in both FlushFile and SyncFile, then
|
// In summary: if you make data durable in both FlushFile and SyncFile, then
|
||||||
// your users can get safe behavior from mapped files on both operating systems
|
// your users can get safe behavior from mapped files on both operating systems
|
||||||
// by calling msync(2) with MS_SYNC, followed by munmap(2), followed by
|
// by calling msync(2) with MS_SYNC, followed by munmap(2), followed by
|
||||||
// close(2). On Linux, the msync(2) is optional (cf. http://goo.gl/EIhAxv and
|
// close(2). On Linux, the msync(2) is optional (cf.
|
||||||
// the notes on WriteFileOp).
|
// https://tinyurl.com/unesszdp and the notes on WriteFileOp).
|
||||||
//
|
//
|
||||||
// Because of cases like dup2(2), FlushFileOps are not necessarily one to one
|
// Because of cases like dup2(2), FlushFileOps are not necessarily one to one
|
||||||
// with OpenFileOps. They should not be used for reference counting, and the
|
// with OpenFileOps. They should not be used for reference counting, and the
|
||||||
|
@ -858,7 +900,8 @@ type FlushFileOp struct {
|
||||||
// The kernel guarantees that the handle ID will not be used in further calls
|
// The kernel guarantees that the handle ID will not be used in further calls
|
||||||
// to the file system (unless it is reissued by the file system).
|
// to the file system (unless it is reissued by the file system).
|
||||||
//
|
//
|
||||||
// Errors from this op are ignored by the kernel (cf. http://goo.gl/RL38Do).
|
// Errors from this op are ignored by the kernel
|
||||||
|
// (https://tinyurl.com/2aaccyzk).
|
||||||
type ReleaseFileHandleOp struct {
|
type ReleaseFileHandleOp struct {
|
||||||
// The handle ID to be released. The kernel guarantees that this ID will not
|
// The handle ID to be released. The kernel guarantees that this ID will not
|
||||||
// be used in further calls to the file system (unless it is reissued by the
|
// be used in further calls to the file system (unless it is reissued by the
|
||||||
|
@ -983,6 +1026,11 @@ type FallocateOp struct {
|
||||||
OpContext OpContext
|
OpContext OpContext
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SyncFSOp struct {
|
||||||
|
Inode InodeID
|
||||||
|
OpContext OpContext
|
||||||
|
}
|
||||||
|
|
||||||
// Request notifications when the file system user calls poll/select or
|
// Request notifications when the file system user calls poll/select or
|
||||||
// similar operations on a file.
|
// similar operations on a file.
|
||||||
type PollOp struct {
|
type PollOp struct {
|
||||||
|
|
|
@ -27,7 +27,7 @@ import (
|
||||||
// RootInodeID.
|
// RootInodeID.
|
||||||
//
|
//
|
||||||
// This corresponds to struct inode::i_no in the VFS layer.
|
// This corresponds to struct inode::i_no in the VFS layer.
|
||||||
// (Cf. http://goo.gl/tvYyQt)
|
// (https://tinyurl.com/23sr9svd)
|
||||||
type InodeID uint64
|
type InodeID uint64
|
||||||
|
|
||||||
// RootInodeID is a distinguished inode ID that identifies the root of the file
|
// RootInodeID is a distinguished inode ID that identifies the root of the file
|
||||||
|
@ -57,7 +57,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// InodeAttributes contains attributes for a file or directory inode. It
|
// InodeAttributes contains attributes for a file or directory inode. It
|
||||||
// corresponds to struct inode (cf. http://goo.gl/tvYyQt).
|
// corresponds to struct inode (https://tinyurl.com/23sr9svd).
|
||||||
type InodeAttributes struct {
|
type InodeAttributes struct {
|
||||||
Size uint64
|
Size uint64
|
||||||
|
|
||||||
|
@ -70,20 +70,20 @@ type InodeAttributes struct {
|
||||||
// Note that in contrast to the defaults for FUSE, this package mounts file
|
// Note that in contrast to the defaults for FUSE, this package mounts file
|
||||||
// systems in a manner such that the kernel checks inode permissions in the
|
// systems in a manner such that the kernel checks inode permissions in the
|
||||||
// standard posix way. This is implemented by setting the default_permissions
|
// standard posix way. This is implemented by setting the default_permissions
|
||||||
// mount option (cf. http://goo.gl/1LxOop and http://goo.gl/1pTjuk).
|
// mount option (https://tinyurl.com/ytun2zsn, https://tinyurl.com/52hz9vya).
|
||||||
//
|
//
|
||||||
// For example, in the case of mkdir:
|
// For example, in the case of mkdir:
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/JkdxDI) sys_mkdirat calls inode_permission.
|
// * (https://tinyurl.com/4yp9bu3h) sys_mkdirat calls inode_permission.
|
||||||
//
|
//
|
||||||
// * (...) inode_permission eventually calls do_inode_permission.
|
// * (...) inode_permission eventually calls do_inode_permission.
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/aGCsmZ) calls i_op->permission, which is
|
// * (https://tinyurl.com/5f9k2eya) calls i_op->permission, which is
|
||||||
// fuse_permission (cf. http://goo.gl/VZ9beH).
|
// fuse_permission (https://tinyurl.com/4kevbw27).
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/5kqUKO) fuse_permission doesn't do anything at all for
|
// * (https://tinyurl.com/nfea3pwj) fuse_permission doesn't do anything at
|
||||||
// several code paths if FUSE_DEFAULT_PERMISSIONS is unset. In contrast,
|
// all for several code paths if FUSE_DEFAULT_PERMISSIONS is unset. In
|
||||||
// if that flag *is* set, then it calls generic_permission.
|
// contrast, if that flag *is* set, then it calls generic_permission.
|
||||||
//
|
//
|
||||||
Mode os.FileMode
|
Mode os.FileMode
|
||||||
|
|
||||||
|
@ -117,15 +117,15 @@ func (a *InodeAttributes) DebugString() string {
|
||||||
// when an ID is reused.
|
// when an ID is reused.
|
||||||
//
|
//
|
||||||
// This corresponds to struct inode::i_generation in the VFS layer.
|
// This corresponds to struct inode::i_generation in the VFS layer.
|
||||||
// (Cf. http://goo.gl/tvYyQt)
|
// (https://tinyurl.com/23sr9svd)
|
||||||
//
|
//
|
||||||
// Some related reading:
|
// Some related reading:
|
||||||
//
|
//
|
||||||
// http://fuse.sourceforge.net/doxygen/structfuse__entry__param.html
|
// http://fuse.sourceforge.net/doxygen/structfuse__entry__param.html
|
||||||
// http://stackoverflow.com/q/11071996/1505451
|
// http://stackoverflow.com/q/11071996/1505451
|
||||||
// http://goo.gl/CqvwyX
|
// https://tinyurl.com/yn7wmcmy
|
||||||
// http://julipedia.meroh.net/2005/09/nfs-file-handles.html
|
// http://julipedia.meroh.net/2005/09/nfs-file-handles.html
|
||||||
// http://goo.gl/wvo3MB
|
// https://tinyurl.com/2c8vsfrs
|
||||||
type GenerationNumber uint64
|
type GenerationNumber uint64
|
||||||
|
|
||||||
// HandleID is an opaque 64-bit number used to identify a particular open
|
// HandleID is an opaque 64-bit number used to identify a particular open
|
||||||
|
@ -160,7 +160,7 @@ type ChildInodeEntry struct {
|
||||||
// Ownership information in particular must be set to something reasonable or
|
// Ownership information in particular must be set to something reasonable or
|
||||||
// by default root will own everything and unprivileged users won't be able
|
// by default root will own everything and unprivileged users won't be able
|
||||||
// to do anything useful. In traditional file systems in the kernel, the
|
// to do anything useful. In traditional file systems in the kernel, the
|
||||||
// function inode_init_owner (http://goo.gl/5qavg8) contains the
|
// function inode_init_owner (https://tinyurl.com/5yfdrfdf) contains the
|
||||||
// standards-compliant logic for this.
|
// standards-compliant logic for this.
|
||||||
Attributes InodeAttributes
|
Attributes InodeAttributes
|
||||||
|
|
||||||
|
@ -169,16 +169,19 @@ type ChildInodeEntry struct {
|
||||||
//
|
//
|
||||||
// For example, this is the abridged call chain for fstat(2):
|
// For example, this is the abridged call chain for fstat(2):
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/tKBH1p) fstat calls vfs_fstat.
|
// * (https://tinyurl.com/bdd6ek3c) fstat calls vfs_fstat.
|
||||||
// * (http://goo.gl/3HeITq) vfs_fstat eventuall calls vfs_getattr_nosec.
|
// * (https://tinyurl.com/3enne935) vfs_fstat eventuall calls
|
||||||
// * (http://goo.gl/DccFQr) vfs_getattr_nosec calls i_op->getattr.
|
// vfs_getattr_nosec.
|
||||||
// * (http://goo.gl/dpKkst) fuse_getattr calls fuse_update_attributes.
|
// * (https://tinyurl.com/y5rkhzx4) vfs_getattr_nosec calls i_op->getattr.
|
||||||
// * (http://goo.gl/yNlqPw) fuse_update_attributes uses the values in the
|
// * (https://tinyurl.com/33hawubc) fuse_getattr calls
|
||||||
// struct inode if allowed, otherwise calling out to the user-space code.
|
// fuse_update_attributes.
|
||||||
|
// * (https://tinyurl.com/ywhhshxt) fuse_update_attributes uses the values
|
||||||
|
// in the struct inode if allowed, otherwise calling out to the
|
||||||
|
// user-space code.
|
||||||
//
|
//
|
||||||
// In addition to obvious cases like fstat, this is also used in more subtle
|
// In addition to obvious cases like fstat, this is also used in more subtle
|
||||||
// cases like updating size information before seeking (http://goo.gl/2nnMFa)
|
// cases like updating size information before seeking
|
||||||
// or reading (http://goo.gl/FQSWs8).
|
// (https://tinyurl.com/hv2jabnh) or reading (https://tinyurl.com/bdkpz96v).
|
||||||
//
|
//
|
||||||
// Most 'real' file systems do not set inode_operations::getattr, and
|
// Most 'real' file systems do not set inode_operations::getattr, and
|
||||||
// therefore vfs_getattr_nosec calls generic_fillattr which simply grabs the
|
// therefore vfs_getattr_nosec calls generic_fillattr which simply grabs the
|
||||||
|
@ -205,16 +208,18 @@ type ChildInodeEntry struct {
|
||||||
// As in the discussion of attribute caching above, unlike real file systems,
|
// As in the discussion of attribute caching above, unlike real file systems,
|
||||||
// FUSE file systems may spontaneously change their name -> inode mapping.
|
// FUSE file systems may spontaneously change their name -> inode mapping.
|
||||||
// Therefore the FUSE VFS layer uses dentry_operations::d_revalidate
|
// Therefore the FUSE VFS layer uses dentry_operations::d_revalidate
|
||||||
// (http://goo.gl/dVea0h) to intercept lookups and revalidate by calling the
|
// (https://tinyurl.com/ydb8ncrk) to intercept lookups and revalidate by
|
||||||
// user-space LookUpInode method. However the latter may be slow, so it
|
// calling the user-space LookUpInode method. However the latter may be slow,
|
||||||
// caches the entries until the time defined by this field.
|
// so it caches the entries until the time defined by this field.
|
||||||
//
|
//
|
||||||
// Example code walk:
|
// Example code walk:
|
||||||
//
|
//
|
||||||
// * (http://goo.gl/M2G3tO) lookup_dcache calls d_revalidate if enabled.
|
// * (https://tinyurl.com/crddueft) lookup_dcache calls d_revalidate if
|
||||||
// * (http://goo.gl/ef0Elu) fuse_dentry_revalidate just uses the dentry's
|
// enabled.
|
||||||
// inode if fuse_dentry_time(entry) hasn't passed. Otherwise it sends a
|
//
|
||||||
// lookup request.
|
// * (https://tinyurl.com/bdsxacjy) fuse_dentry_revalidate just uses the
|
||||||
|
// dentry's inode if fuse_dentry_time(entry) hasn't passed. Otherwise
|
||||||
|
// it sends a lookup request.
|
||||||
//
|
//
|
||||||
// Leave at the zero value to disable caching.
|
// Leave at the zero value to disable caching.
|
||||||
//
|
//
|
||||||
|
|
|
@ -30,7 +30,7 @@ func (f sortedEntries) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
|
||||||
// Read the directory with the given name and return a list of directory
|
// Read the directory with the given name and return a list of directory
|
||||||
// entries, sorted by name.
|
// entries, sorted by name.
|
||||||
//
|
//
|
||||||
// Unlike ioutil.ReadDir (cf. http://goo.gl/i0nNP4), this function does not
|
// Unlike ioutil.ReadDir (https://tinyurl.com/yft8kkxb), this function does not
|
||||||
// silently ignore "file not found" errors when stat'ing the names read from
|
// silently ignore "file not found" errors when stat'ing the names read from
|
||||||
// the directory.
|
// the directory.
|
||||||
func ReadDirPicky(dirname string) (entries []os.FileInfo, err error) {
|
func ReadDirPicky(dirname string) (entries []os.FileInfo, err error) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ func extractBirthtime(sys interface{}) (birthtime time.Time, ok bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractNlink(sys interface{}) (nlink uint64, ok bool) {
|
func extractNlink(sys interface{}) (nlink uint64, ok bool) {
|
||||||
return sys.(*syscall.Stat_t).Nlink, true
|
return uint64(sys.(*syscall.Stat_t).Nlink), true
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTimes(stat *syscall.Stat_t) (atime, ctime, mtime time.Time) {
|
func getTimes(stat *syscall.Stat_t) (atime, ctime, mtime time.Time) {
|
||||||
|
|
|
@ -64,9 +64,9 @@ func WriteDirent(buf []byte, d Dirent) (n int) {
|
||||||
// Returns zero if the entry would not fit.
|
// Returns zero if the entry would not fit.
|
||||||
func WriteDirentPlus(buf []byte, e *fuseops.ChildInodeEntry, d Dirent) (n int) {
|
func WriteDirentPlus(buf []byte, e *fuseops.ChildInodeEntry, d Dirent) (n int) {
|
||||||
// We want to write bytes with the layout of fuse_dirent
|
// We want to write bytes with the layout of fuse_dirent
|
||||||
// (http://goo.gl/BmFxob) in host order. The struct must be aligned according
|
// (https://tinyurl.com/4k7y2h9r) in host order. The struct must be aligned
|
||||||
// to FUSE_DIRENT_ALIGN (http://goo.gl/UziWvH), which dictates 8-byte
|
// according to FUSE_DIRENT_ALIGN (https://tinyurl.com/3m3ewu7h), which
|
||||||
// alignment.
|
// dictates 8-byte alignment.
|
||||||
type fuse_dirent struct {
|
type fuse_dirent struct {
|
||||||
ino uint64
|
ino uint64
|
||||||
off uint64
|
off uint64
|
||||||
|
|
|
@ -63,6 +63,7 @@ type FileSystem interface {
|
||||||
ListXattr(context.Context, *fuseops.ListXattrOp) error
|
ListXattr(context.Context, *fuseops.ListXattrOp) error
|
||||||
SetXattr(context.Context, *fuseops.SetXattrOp) error
|
SetXattr(context.Context, *fuseops.SetXattrOp) error
|
||||||
Fallocate(context.Context, *fuseops.FallocateOp) error
|
Fallocate(context.Context, *fuseops.FallocateOp) error
|
||||||
|
SyncFS(context.Context, *fuseops.SyncFSOp) error
|
||||||
Poll(context.Context, *fuseops.PollOp) error
|
Poll(context.Context, *fuseops.PollOp) error
|
||||||
|
|
||||||
SetConnection(*fuse.Connection)
|
SetConnection(*fuse.Connection)
|
||||||
|
@ -84,8 +85,8 @@ type FileSystem interface {
|
||||||
//
|
//
|
||||||
// (It is safe to naively process ops concurrently because the kernel
|
// (It is safe to naively process ops concurrently because the kernel
|
||||||
// guarantees to serialize operations that the user expects to happen in order,
|
// guarantees to serialize operations that the user expects to happen in order,
|
||||||
// cf. http://goo.gl/jnkHPO, fuse-devel thread "Fuse guarantees on concurrent
|
// cf. https://tinyurl.com/bddm85v5, fuse-devel thread "Fuse guarantees on
|
||||||
// requests").
|
// concurrent requests").
|
||||||
func NewFileSystemServer(fs FileSystem) fuse.Server {
|
func NewFileSystemServer(fs FileSystem) fuse.Server {
|
||||||
return &fileSystemServer{
|
return &fileSystemServer{
|
||||||
fs: fs,
|
fs: fs,
|
||||||
|
@ -242,6 +243,9 @@ func (s *fileSystemServer) handleOp(
|
||||||
case *fuseops.FallocateOp:
|
case *fuseops.FallocateOp:
|
||||||
err = s.fs.Fallocate(ctx, typed)
|
err = s.fs.Fallocate(ctx, typed)
|
||||||
|
|
||||||
|
case *fuseops.SyncFSOp:
|
||||||
|
err = s.fs.SyncFS(ctx, typed)
|
||||||
|
|
||||||
case *fuseops.PollOp:
|
case *fuseops.PollOp:
|
||||||
err = s.fs.Poll(ctx, typed)
|
err = s.fs.Poll(ctx, typed)
|
||||||
}
|
}
|
||||||
|
|
|
@ -204,6 +204,12 @@ func (fs *NotImplementedFileSystem) Fallocate(
|
||||||
return fuse.ENOSYS
|
return fuse.ENOSYS
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *NotImplementedFileSystem) SyncFS(
|
||||||
|
ctx context.Context,
|
||||||
|
op *fuseops.SyncFSOp) error {
|
||||||
|
return fuse.ENOSYS
|
||||||
|
}
|
||||||
|
|
||||||
func (fs *NotImplementedFileSystem) Poll(
|
func (fs *NotImplementedFileSystem) Poll(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
op *fuseops.PollOp) error {
|
op *fuseops.PollOp) error {
|
||||||
|
|
14
go.mod
14
go.mod
|
@ -1,17 +1,19 @@
|
||||||
module github.com/jacobsa/fuse
|
module github.com/jacobsa/fuse
|
||||||
|
|
||||||
go 1.18
|
go 1.20
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e
|
github.com/detailyang/go-fallocate v0.0.0-20180908115635-432fa640bd2e
|
||||||
github.com/jacobsa/oglematchers v0.0.0-20150720000706-141901ea67cd
|
github.com/jacobsa/oglematchers v0.0.0-20150720000706-141901ea67cd
|
||||||
github.com/jacobsa/oglemock v0.0.0-20150831005832-e94d794d06ff // indirect
|
|
||||||
github.com/jacobsa/ogletest v0.0.0-20170503003838-80d50a735a11
|
github.com/jacobsa/ogletest v0.0.0-20170503003838-80d50a735a11
|
||||||
github.com/jacobsa/reqtrace v0.0.0-20150505043853-245c9e0234cb // indirect
|
|
||||||
github.com/jacobsa/syncutil v0.0.0-20180201203307-228ac8e5a6c3
|
github.com/jacobsa/syncutil v0.0.0-20180201203307-228ac8e5a6c3
|
||||||
github.com/jacobsa/timeutil v0.0.0-20170205232429-577e5acbbcf6
|
github.com/jacobsa/timeutil v0.0.0-20170205232429-577e5acbbcf6
|
||||||
github.com/kylelemons/godebug v1.1.0
|
github.com/kylelemons/godebug v1.1.0
|
||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
|
golang.org/x/net v0.23.0
|
||||||
golang.org/x/net v0.0.0-20220526153639-5463443f8c37
|
golang.org/x/sys v0.18.0
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/jacobsa/oglemock v0.0.0-20150831005832-e94d794d06ff // indirect
|
||||||
|
github.com/jacobsa/reqtrace v0.0.0-20150505043853-245c9e0234cb // indirect
|
||||||
)
|
)
|
||||||
|
|
26
go.sum
26
go.sum
|
@ -14,25 +14,7 @@ github.com/jacobsa/timeutil v0.0.0-20170205232429-577e5acbbcf6 h1:XKHJmHcgU9glxk
|
||||||
github.com/jacobsa/timeutil v0.0.0-20170205232429-577e5acbbcf6/go.mod h1:JEWKD6V8xETMW+DEv+IQVz++f8Cn8O/X0HPeDY3qNis=
|
github.com/jacobsa/timeutil v0.0.0-20170205232429-577e5acbbcf6/go.mod h1:JEWKD6V8xETMW+DEv+IQVz++f8Cn8O/X0HPeDY3qNis=
|
||||||
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
|
||||||
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
|
||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e h1:T8NU3HyQ8ClP4SEE+KbFlg6n0NhuTsN4MyznaarGsZM=
|
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
|
||||||
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
|
||||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a h1:GuSPYbZzB5/dcLNCwLQLsg3obCJtX9IJhpXkvY7kzk0=
|
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
|
||||||
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 h1:lUkvobShwKsOesNfWWlCS5q7fnbG1MEliIzwu886fn8=
|
|
||||||
golang.org/x/net v0.0.0-20220526153639-5463443f8c37/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
|
|
||||||
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ package buffer
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
@ -52,11 +53,38 @@ func NewInMessage() *InMessage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var readLock sync.Mutex
|
||||||
|
|
||||||
|
func (m *InMessage) ReadSingle(r io.Reader) (int, error) {
|
||||||
|
readLock.Lock()
|
||||||
|
defer readLock.Unlock()
|
||||||
|
|
||||||
|
// read request length
|
||||||
|
if _, err := io.ReadFull(r, m.storage[0:4]); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
l := m.Header().Len
|
||||||
|
// read remaining request
|
||||||
|
if n, err := io.ReadFull(r, m.storage[4:l]); err != nil {
|
||||||
|
return n, err
|
||||||
|
}
|
||||||
|
return int(l), nil
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize with the data read by a single call to r.Read. The first call to
|
// Initialize with the data read by a single call to r.Read. The first call to
|
||||||
// Consume will consume the bytes directly after the fusekernel.InHeader
|
// Consume will consume the bytes directly after the fusekernel.InHeader
|
||||||
// struct.
|
// struct.
|
||||||
func (m *InMessage) Init(r io.Reader) error {
|
func (m *InMessage) Init(r io.Reader) error {
|
||||||
n, err := r.Read(m.storage[:])
|
|
||||||
|
var n int
|
||||||
|
var err error
|
||||||
|
if fusekernel.IsPlatformFuseT {
|
||||||
|
n, err = m.ReadSingle(r)
|
||||||
|
} else {
|
||||||
|
n, err = r.Read(m.storage[:])
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,12 +41,14 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var IsPlatformFuseT bool
|
||||||
|
|
||||||
// The FUSE version implemented by the package.
|
// The FUSE version implemented by the package.
|
||||||
const (
|
const (
|
||||||
ProtoVersionMinMajor = 7
|
ProtoVersionMinMajor = 7
|
||||||
ProtoVersionMinMinor = 19
|
ProtoVersionMinMinor = 18
|
||||||
ProtoVersionMaxMajor = 7
|
ProtoVersionMaxMajor = 7
|
||||||
ProtoVersionMaxMinor = 31
|
ProtoVersionMaxMinor = 34
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -227,6 +229,7 @@ const (
|
||||||
OpenDirectIO OpenResponseFlags = 1 << 0 // bypass page cache for this open file
|
OpenDirectIO OpenResponseFlags = 1 << 0 // bypass page cache for this open file
|
||||||
OpenKeepCache OpenResponseFlags = 1 << 1 // don't invalidate the data cache on open
|
OpenKeepCache OpenResponseFlags = 1 << 1 // don't invalidate the data cache on open
|
||||||
OpenNonSeekable OpenResponseFlags = 1 << 2 // mark the file as non-seekable (not supported on OS X)
|
OpenNonSeekable OpenResponseFlags = 1 << 2 // mark the file as non-seekable (not supported on OS X)
|
||||||
|
OpenCacheDir OpenResponseFlags = 1 << 3 // allow caching this directory
|
||||||
|
|
||||||
OpenPurgeAttr OpenResponseFlags = 1 << 30 // OS X
|
OpenPurgeAttr OpenResponseFlags = 1 << 30 // OS X
|
||||||
OpenPurgeUBC OpenResponseFlags = 1 << 31 // OS X
|
OpenPurgeUBC OpenResponseFlags = 1 << 31 // OS X
|
||||||
|
@ -240,6 +243,7 @@ var openResponseFlagNames = []flagName{
|
||||||
{uint32(OpenDirectIO), "OpenDirectIO"},
|
{uint32(OpenDirectIO), "OpenDirectIO"},
|
||||||
{uint32(OpenKeepCache), "OpenKeepCache"},
|
{uint32(OpenKeepCache), "OpenKeepCache"},
|
||||||
{uint32(OpenNonSeekable), "OpenNonSeekable"},
|
{uint32(OpenNonSeekable), "OpenNonSeekable"},
|
||||||
|
{uint32(OpenCacheDir), "OpenCacheDir"},
|
||||||
{uint32(OpenPurgeAttr), "OpenPurgeAttr"},
|
{uint32(OpenPurgeAttr), "OpenPurgeAttr"},
|
||||||
{uint32(OpenPurgeUBC), "OpenPurgeUBC"},
|
{uint32(OpenPurgeUBC), "OpenPurgeUBC"},
|
||||||
}
|
}
|
||||||
|
@ -266,6 +270,7 @@ const (
|
||||||
InitAsyncDIO InitFlags = 1 << 15
|
InitAsyncDIO InitFlags = 1 << 15
|
||||||
InitWritebackCache InitFlags = 1 << 16
|
InitWritebackCache InitFlags = 1 << 16
|
||||||
InitNoOpenSupport InitFlags = 1 << 17
|
InitNoOpenSupport InitFlags = 1 << 17
|
||||||
|
InitParallelDirOps InitFlags = 1 << 18
|
||||||
InitMaxPages InitFlags = 1 << 22
|
InitMaxPages InitFlags = 1 << 22
|
||||||
InitCacheSymlinks InitFlags = 1 << 23
|
InitCacheSymlinks InitFlags = 1 << 23
|
||||||
InitNoOpendirSupport InitFlags = 1 << 24
|
InitNoOpendirSupport InitFlags = 1 << 24
|
||||||
|
@ -418,6 +423,13 @@ const (
|
||||||
OpBatchForget = 42
|
OpBatchForget = 42
|
||||||
OpFallocate = 43
|
OpFallocate = 43
|
||||||
OpReaddirplus = 44
|
OpReaddirplus = 44
|
||||||
|
//
|
||||||
|
OpRename2 = 45
|
||||||
|
OpLseek = 46
|
||||||
|
OpCopyFileRange = 47
|
||||||
|
OpSetupMapping = 48
|
||||||
|
OpRemoveMapping = 49
|
||||||
|
OpSyncFS = 50
|
||||||
|
|
||||||
// OS X
|
// OS X
|
||||||
OpSetvolname = 61
|
OpSetvolname = 61
|
||||||
|
@ -850,6 +862,10 @@ type NotifyInvalEntryOut struct {
|
||||||
padding uint32
|
padding uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SyncFSIn struct {
|
||||||
|
Padding uint64
|
||||||
|
}
|
||||||
|
|
||||||
type NotifyDeleteOut struct {
|
type NotifyDeleteOut struct {
|
||||||
Parent uint64
|
Parent uint64
|
||||||
Child uint64
|
Child uint64
|
||||||
|
|
|
@ -50,7 +50,7 @@ type MountConfig struct {
|
||||||
// Linux only. OS X always behaves as if writeback caching is disabled.
|
// Linux only. OS X always behaves as if writeback caching is disabled.
|
||||||
//
|
//
|
||||||
// By default on Linux we allow the kernel to perform writeback caching
|
// By default on Linux we allow the kernel to perform writeback caching
|
||||||
// (cf. http://goo.gl/LdZzo1):
|
// (https://tinyurl.com/3ma8ypeu):
|
||||||
//
|
//
|
||||||
// * When the user calls write(2), the kernel sticks the user's data into
|
// * When the user calls write(2), the kernel sticks the user's data into
|
||||||
// its page cache. Only later does it call through to the file system,
|
// its page cache. Only later does it call through to the file system,
|
||||||
|
@ -65,7 +65,7 @@ type MountConfig struct {
|
||||||
//
|
//
|
||||||
// * close(2) (and anything else calling f_op->flush) causes all dirty
|
// * close(2) (and anything else calling f_op->flush) causes all dirty
|
||||||
// pages to be written out before it proceeds to send a FlushFileOp
|
// pages to be written out before it proceeds to send a FlushFileOp
|
||||||
// (cf. https://goo.gl/TMrY6X).
|
// (https://tinyurl.com/3ur6vmsv).
|
||||||
//
|
//
|
||||||
// * Similarly, close(2) causes the kernel to send a setattr request
|
// * Similarly, close(2) causes the kernel to send a setattr request
|
||||||
// filling in the mtime if any dirty pages were flushed, since the time
|
// filling in the mtime if any dirty pages were flushed, since the time
|
||||||
|
@ -78,22 +78,23 @@ type MountConfig struct {
|
||||||
//
|
//
|
||||||
// Code walk:
|
// Code walk:
|
||||||
//
|
//
|
||||||
// * (https://goo.gl/zTIZQ9) fuse_flush calls write_inode_now before
|
// * (https://tinyurl.com/3ur6vmsv) fuse_flush calls write_inode_now
|
||||||
// calling the file system. The latter eventually calls into
|
// before calling the file system. The latter eventually calls into
|
||||||
// __writeback_single_inode.
|
// __writeback_single_inode.
|
||||||
//
|
//
|
||||||
// * (https://goo.gl/L7Z2w5) __writeback_single_inode calls
|
// * (https://tinyurl.com/35vtmtsz) __writeback_single_inode calls
|
||||||
// do_writepages, which writes out any dirty pages.
|
// do_writepages, which writes out any dirty pages.
|
||||||
//
|
//
|
||||||
// * (https://goo.gl/DOPgla) __writeback_single_inode later calls
|
// * (https://tinyurl.com/3wv4paaf) __writeback_single_inode later
|
||||||
// write_inode, which calls into the superblock op struct's write_inode
|
// calls write_inode, which calls into the superblock op struct's
|
||||||
// member. For fuse, this is fuse_write_inode
|
// write_inode member. For fuse, this is fuse_write_inode
|
||||||
// (cf. https://goo.gl/eDSKOX).
|
// (https://tinyurl.com/mrxupe98).
|
||||||
//
|
//
|
||||||
// * (https://goo.gl/PbkGA1) fuse_write_inode calls fuse_flush_times.
|
// * (https://tinyurl.com/mrxt9bta) fuse_write_inode calls
|
||||||
|
// fuse_flush_times.
|
||||||
//
|
//
|
||||||
// * (https://goo.gl/ig8x9V) fuse_flush_times sends a setttr request
|
// * (https://tinyurl.com/mr49cjdf) fuse_flush_times sends a setttr
|
||||||
// for setting the inode's mtime.
|
// request for setting the inode's mtime.
|
||||||
//
|
//
|
||||||
// However, this brings along some caveats:
|
// However, this brings along some caveats:
|
||||||
//
|
//
|
||||||
|
@ -102,11 +103,11 @@ type MountConfig struct {
|
||||||
//
|
//
|
||||||
// * The kernel caches mtime and ctime regardless of whether the file
|
// * The kernel caches mtime and ctime regardless of whether the file
|
||||||
// system tells it to do so, disregarding the result of further getattr
|
// system tells it to do so, disregarding the result of further getattr
|
||||||
// requests (cf. https://goo.gl/3ZZMUw, https://goo.gl/7WtQUp). It
|
// requests (https://tinyurl.com/mrxnfatv, https://tinyurl.com/27jju8n4).
|
||||||
// appears this may be true of the file size, too. Writeback caching may
|
// It appears this may be true of the file size, too. Writeback caching
|
||||||
// therefore not be suitable for file systems where these attributes can
|
// may therefore not be suitable for file systems where these attributes
|
||||||
// spontaneously change for reasons the kernel doesn't observe. See
|
// can spontaneously change for reasons the kernel doesn't observe. See
|
||||||
// http://goo.gl/V5WQCN for more discussion.
|
// https://tinyurl.com/yyprvjvs for more discussion.
|
||||||
//
|
//
|
||||||
// Setting DisableWritebackCaching disables this behavior. Instead the file
|
// Setting DisableWritebackCaching disables this behavior. Instead the file
|
||||||
// system is called one or more times for each write(2), and the user's
|
// system is called one or more times for each write(2), and the user's
|
||||||
|
@ -116,12 +117,12 @@ type MountConfig struct {
|
||||||
// OS X only.
|
// OS X only.
|
||||||
//
|
//
|
||||||
// Normally on OS X we mount with the novncache option
|
// Normally on OS X we mount with the novncache option
|
||||||
// (cf. http://goo.gl/1pTjuk), which disables entry caching in the kernel.
|
// (https://tinyurl.com/52hz9vya), which disables entry caching in the
|
||||||
// This is because osxfuse does not honor the entry expiration values we
|
// kernel. This is because macFUSE (osxfuse) does not honor the entry
|
||||||
// return to it, instead caching potentially forever (cf.
|
// expiration values we return to it, instead caching potentially forever
|
||||||
// http://goo.gl/8yR0Ie), and it is probably better to fail to cache than to
|
// (https://tinyurl.com/2rr6cd3m), and it is probably better to fail to cache
|
||||||
// cache for too long, since the latter is more likely to hide consistency
|
// than to cache for too long, since the latter is more likely to hide
|
||||||
// bugs that are difficult to detect and diagnose.
|
// consistency bugs that are difficult to detect and diagnose.
|
||||||
//
|
//
|
||||||
// This field disables the use of novncache, restoring entry caching. Beware:
|
// This field disables the use of novncache, restoring entry caching. Beware:
|
||||||
// the value of ChildInodeEntry.EntryExpiration is ignored by the kernel, and
|
// the value of ChildInodeEntry.EntryExpiration is ignored by the kernel, and
|
||||||
|
@ -171,9 +172,16 @@ type MountConfig struct {
|
||||||
// OS X only.
|
// OS X only.
|
||||||
//
|
//
|
||||||
// The name of the mounted volume, as displayed in the Finder. If empty, a
|
// The name of the mounted volume, as displayed in the Finder. If empty, a
|
||||||
// default name involving the string 'osxfuse' is used.
|
// default name involving the string 'osxfuse' (the old name of macFUSE)
|
||||||
|
// is used.
|
||||||
VolumeName string
|
VolumeName string
|
||||||
|
|
||||||
|
// OS X only.
|
||||||
|
//
|
||||||
|
// The FUSE implementation to use. One of FUSEImplFuseT (default) or
|
||||||
|
// FUSEImplMacFUSE.
|
||||||
|
FuseImpl FUSEImpl
|
||||||
|
|
||||||
// Additional key=value options to pass unadulterated to the underlying mount
|
// Additional key=value options to pass unadulterated to the underlying mount
|
||||||
// command. See `man 8 mount`, the fuse documentation, etc. for
|
// command. See `man 8 mount`, the fuse documentation, etc. for
|
||||||
// system-specific information.
|
// system-specific information.
|
||||||
|
@ -190,8 +198,20 @@ type MountConfig struct {
|
||||||
// Flag to enable async reads that are received from
|
// Flag to enable async reads that are received from
|
||||||
// the kernel
|
// the kernel
|
||||||
EnableAsyncReads bool
|
EnableAsyncReads bool
|
||||||
|
|
||||||
|
// Flag to enable parallel lookup and readdir operations from the
|
||||||
|
// kernel
|
||||||
|
// Ref: https://github.com/torvalds/linux/commit/5c672ab3f0ee0f78f7acad183f34db0f8781a200
|
||||||
|
EnableParallelDirOps bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type FUSEImpl uint8
|
||||||
|
|
||||||
|
const (
|
||||||
|
FUSEImplFuseT = iota
|
||||||
|
FUSEImplMacFUSE
|
||||||
|
)
|
||||||
|
|
||||||
// Create a map containing all of the key=value mount options to be given to
|
// Create a map containing all of the key=value mount options to be given to
|
||||||
// the mount helper.
|
// the mount helper.
|
||||||
func (c *MountConfig) toMap() (opts map[string]string) {
|
func (c *MountConfig) toMap() (opts map[string]string) {
|
||||||
|
|
164
mount_darwin.go
164
mount_darwin.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
@ -11,6 +12,7 @@ import (
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/jacobsa/fuse/internal/buffer"
|
"github.com/jacobsa/fuse/internal/buffer"
|
||||||
|
"github.com/jacobsa/fuse/internal/fusekernel"
|
||||||
)
|
)
|
||||||
|
|
||||||
var errNoAvail = errors.New("no available fuse devices")
|
var errNoAvail = errors.New("no available fuse devices")
|
||||||
|
@ -78,6 +80,8 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const FUSET_SRV_PATH = "/usr/local/bin/go-nfsv4"
|
||||||
|
|
||||||
func loadOSXFUSE(bin string) error {
|
func loadOSXFUSE(bin string) error {
|
||||||
cmd := exec.Command(bin)
|
cmd := exec.Command(bin)
|
||||||
cmd.Dir = "/"
|
cmd.Dir = "/"
|
||||||
|
@ -212,7 +216,7 @@ func callMountCommFD(
|
||||||
// to the kernel. Mounting continues in the background, and is complete when an
|
// to the kernel. Mounting continues in the background, and is complete when an
|
||||||
// error is written to the supplied channel. The file system may need to
|
// error is written to the supplied channel. The file system may need to
|
||||||
// service the connection in order for mounting to complete.
|
// service the connection in order for mounting to complete.
|
||||||
func mount(
|
func mountOsxFuse(
|
||||||
dir string,
|
dir string,
|
||||||
cfg *MountConfig,
|
cfg *MountConfig,
|
||||||
ready chan<- error) (dev *os.File, err error) {
|
ready chan<- error) (dev *os.File, err error) {
|
||||||
|
@ -263,3 +267,161 @@ func mount(
|
||||||
|
|
||||||
return nil, errOSXFUSENotFound
|
return nil, errOSXFUSENotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fusetBinary() (string, error) {
|
||||||
|
srv_path := os.Getenv("FUSE_NFSSRV_PATH")
|
||||||
|
if srv_path == "" {
|
||||||
|
srv_path = FUSET_SRV_PATH
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := os.Stat(srv_path); err == nil {
|
||||||
|
return srv_path, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", fmt.Errorf("FUSE-T not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func unixgramSocketpair() (l, r *os.File, err error) {
|
||||||
|
fd, err := syscall.Socketpair(syscall.AF_UNIX, syscall.SOCK_STREAM, 0)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, os.NewSyscallError("socketpair",
|
||||||
|
err.(syscall.Errno))
|
||||||
|
}
|
||||||
|
l = os.NewFile(uintptr(fd[0]), fmt.Sprintf("socketpair-half%d", fd[0]))
|
||||||
|
r = os.NewFile(uintptr(fd[1]), fmt.Sprintf("socketpair-half%d", fd[1]))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var local, local_mon, remote, remote_mon *os.File
|
||||||
|
|
||||||
|
func startFuseTServer(binary string, argv []string,
|
||||||
|
additionalEnv []string,
|
||||||
|
wait bool,
|
||||||
|
debugLogger *log.Logger,
|
||||||
|
ready chan<- error) (*os.File, error) {
|
||||||
|
if debugLogger != nil {
|
||||||
|
debugLogger.Println("Creating a socket pair")
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
local, remote, err = unixgramSocketpair()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer remote.Close()
|
||||||
|
|
||||||
|
local_mon, remote_mon, err = unixgramSocketpair()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer remote_mon.Close()
|
||||||
|
|
||||||
|
syscall.CloseOnExec(int(local.Fd()))
|
||||||
|
syscall.CloseOnExec(int(local_mon.Fd()))
|
||||||
|
|
||||||
|
if debugLogger != nil {
|
||||||
|
debugLogger.Println("Creating files to wrap the sockets")
|
||||||
|
}
|
||||||
|
|
||||||
|
if debugLogger != nil {
|
||||||
|
debugLogger.Println("Starting fusermount/os mount")
|
||||||
|
}
|
||||||
|
// Start fusermount/mount_macfuse/mount_osxfuse.
|
||||||
|
cmd := exec.Command(binary, argv...)
|
||||||
|
cmd.Env = append(os.Environ(), "_FUSE_COMMFD=3")
|
||||||
|
cmd.Env = append(cmd.Env, "_FUSE_MONFD=4")
|
||||||
|
cmd.Env = append(cmd.Env, additionalEnv...)
|
||||||
|
cmd.ExtraFiles = []*os.File{remote, remote_mon}
|
||||||
|
cmd.Stderr = nil
|
||||||
|
cmd.Stdout = nil
|
||||||
|
// daemonize
|
||||||
|
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||||
|
Setsid: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run the command.
|
||||||
|
err = cmd.Start()
|
||||||
|
cmd.Process.Release()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("running %v: %v", binary, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if debugLogger != nil {
|
||||||
|
debugLogger.Println("Wrapping socket pair in a connection")
|
||||||
|
}
|
||||||
|
|
||||||
|
if debugLogger != nil {
|
||||||
|
debugLogger.Println("Checking that we have a unix domain socket")
|
||||||
|
}
|
||||||
|
|
||||||
|
if debugLogger != nil {
|
||||||
|
debugLogger.Println("Read a message from socket")
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
if _, err = local_mon.Write([]byte("mount")); err != nil {
|
||||||
|
err = fmt.Errorf("fuse-t failed: %v", err)
|
||||||
|
} else {
|
||||||
|
reply := make([]byte, 4)
|
||||||
|
if _, err = local_mon.Read(reply); err != nil {
|
||||||
|
fmt.Printf("mount read %v\n", err)
|
||||||
|
err = fmt.Errorf("fuse-t failed: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ready <- err
|
||||||
|
close(ready)
|
||||||
|
}()
|
||||||
|
|
||||||
|
if debugLogger != nil {
|
||||||
|
debugLogger.Println("Successfully read the socket message.")
|
||||||
|
}
|
||||||
|
|
||||||
|
return local, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func mountFuset(
|
||||||
|
dir string,
|
||||||
|
cfg *MountConfig,
|
||||||
|
ready chan<- error) (dev *os.File, err error) {
|
||||||
|
fuseTBin, err := fusetBinary()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fusekernel.IsPlatformFuseT = true
|
||||||
|
env := []string{}
|
||||||
|
argv := []string{
|
||||||
|
fmt.Sprintf("--rwsize=%d", buffer.MaxWriteSize),
|
||||||
|
}
|
||||||
|
|
||||||
|
if cfg.VolumeName != "" {
|
||||||
|
argv = append(argv, "--volname")
|
||||||
|
argv = append(argv, cfg.VolumeName)
|
||||||
|
}
|
||||||
|
if cfg.ReadOnly {
|
||||||
|
argv = append(argv, "-r")
|
||||||
|
}
|
||||||
|
|
||||||
|
env = append(env, "_FUSE_COMMVERS=2")
|
||||||
|
argv = append(argv, dir)
|
||||||
|
|
||||||
|
return startFuseTServer(fuseTBin, argv, env, false, cfg.DebugLogger, ready)
|
||||||
|
}
|
||||||
|
|
||||||
|
func mount(
|
||||||
|
dir string,
|
||||||
|
cfg *MountConfig,
|
||||||
|
ready chan<- error) (dev *os.File, err error) {
|
||||||
|
|
||||||
|
fusekernel.IsPlatformFuseT = false
|
||||||
|
switch cfg.FuseImpl {
|
||||||
|
case FUSEImplMacFUSE:
|
||||||
|
dev, err = mountOsxFuse(dir, cfg, ready)
|
||||||
|
case FUSEImplFuseT:
|
||||||
|
fallthrough
|
||||||
|
default:
|
||||||
|
dev, err = mountFuset(dir, cfg, ready)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
@ -84,6 +84,7 @@ func directmount(dir string, cfg *MountConfig) (*os.File, error) {
|
||||||
mountflag = fn(mountflag)
|
mountflag = fn(mountflag)
|
||||||
delete(opts, k)
|
delete(opts, k)
|
||||||
}
|
}
|
||||||
|
fsname := opts["fsname"]
|
||||||
delete(opts, "fsname") // handled via fstype mount(2) parameter
|
delete(opts, "fsname") // handled via fstype mount(2) parameter
|
||||||
fstype := "fuse"
|
fstype := "fuse"
|
||||||
if subtype, ok := opts["subtype"]; ok {
|
if subtype, ok := opts["subtype"]; ok {
|
||||||
|
@ -96,7 +97,7 @@ func directmount(dir string, cfg *MountConfig) (*os.File, error) {
|
||||||
cfg.DebugLogger.Println("Starting the unix mounting")
|
cfg.DebugLogger.Println("Starting the unix mounting")
|
||||||
}
|
}
|
||||||
if err := unix.Mount(
|
if err := unix.Mount(
|
||||||
cfg.FSName, // source
|
fsname, // source
|
||||||
dir, // target
|
dir, // target
|
||||||
fstype, // fstype
|
fstype, // fstype
|
||||||
mountflag, // mountflag
|
mountflag, // mountflag
|
||||||
|
|
|
@ -48,6 +48,11 @@ const (
|
||||||
// Each file responds to reads with random contents. SetKeepCache can be used
|
// Each file responds to reads with random contents. SetKeepCache can be used
|
||||||
// to control whether the response to OpenFileOp tells the kernel to keep the
|
// to control whether the response to OpenFileOp tells the kernel to keep the
|
||||||
// file's data in the page cache or not.
|
// file's data in the page cache or not.
|
||||||
|
//
|
||||||
|
// Each directory responds to readdir with random entries (different names).
|
||||||
|
// SetCacheDir and SetKeepDirCache can be used to control whether the response
|
||||||
|
// to OpenDirOp tells the kernel to cache the next response of ReadDirOp
|
||||||
|
// in cache, or invalidate the existing cached entry in page cache.
|
||||||
type CachingFS interface {
|
type CachingFS interface {
|
||||||
fuseutil.FileSystem
|
fuseutil.FileSystem
|
||||||
|
|
||||||
|
@ -66,6 +71,14 @@ type CachingFS interface {
|
||||||
// Instruct the file system whether or not to reply to OpenFileOp with
|
// Instruct the file system whether or not to reply to OpenFileOp with
|
||||||
// FOPEN_KEEP_CACHE set.
|
// FOPEN_KEEP_CACHE set.
|
||||||
SetKeepCache(keep bool)
|
SetKeepCache(keep bool)
|
||||||
|
|
||||||
|
// Instruct the file system whether or not to reply to OpenDirOp with
|
||||||
|
// FOPEN_KEEP_CACHE set.
|
||||||
|
SetKeepDirCache(keep bool)
|
||||||
|
|
||||||
|
// Instruct the file system whether or not to reply to OpenDirOp with
|
||||||
|
// FOPEN_CACHE_DIR set.
|
||||||
|
SetCacheDir(cacheDir bool)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a file system that issues cacheable responses according to the
|
// Create a file system that issues cacheable responses according to the
|
||||||
|
@ -126,6 +139,10 @@ type cachingFS struct {
|
||||||
// GUARDED_BY(mu)
|
// GUARDED_BY(mu)
|
||||||
keepPageCache bool
|
keepPageCache bool
|
||||||
|
|
||||||
|
// GUARDED_BY(mu)
|
||||||
|
keepDirCache bool
|
||||||
|
cacheDir bool
|
||||||
|
|
||||||
// The current ID of the lowest numbered non-root inode.
|
// The current ID of the lowest numbered non-root inode.
|
||||||
//
|
//
|
||||||
// INVARIANT: baseID > fuseops.RootInodeID
|
// INVARIANT: baseID > fuseops.RootInodeID
|
||||||
|
@ -202,6 +219,17 @@ func (fs *cachingFS) barAttrs() fuseops.InodeAttributes {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func randomString(len int) string {
|
||||||
|
bytes := make([]byte, len)
|
||||||
|
nn, err := rand.Read(bytes)
|
||||||
|
|
||||||
|
if err != nil || len != nn {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
return string(bytes)
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// Public interface
|
// Public interface
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -254,6 +282,22 @@ func (fs *cachingFS) SetKeepCache(keep bool) {
|
||||||
fs.keepPageCache = keep
|
fs.keepPageCache = keep
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
|
func (fs *cachingFS) SetKeepDirCache(keep bool) {
|
||||||
|
fs.mu.Lock()
|
||||||
|
defer fs.mu.Unlock()
|
||||||
|
|
||||||
|
fs.keepDirCache = keep
|
||||||
|
}
|
||||||
|
|
||||||
|
// LOCKS_EXCLUDED(fs.mu)
|
||||||
|
func (fs *cachingFS) SetCacheDir(cacheDir bool) {
|
||||||
|
fs.mu.Lock()
|
||||||
|
defer fs.mu.Unlock()
|
||||||
|
|
||||||
|
fs.cacheDir = cacheDir
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// FileSystem methods
|
// FileSystem methods
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -349,6 +393,51 @@ func (fs *cachingFS) GetInodeAttributes(
|
||||||
func (fs *cachingFS) OpenDir(
|
func (fs *cachingFS) OpenDir(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
op *fuseops.OpenDirOp) error {
|
op *fuseops.OpenDirOp) error {
|
||||||
|
fs.mu.Lock()
|
||||||
|
defer fs.mu.Unlock()
|
||||||
|
|
||||||
|
op.CacheDir = fs.cacheDir
|
||||||
|
op.KeepCache = fs.keepDirCache
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs *cachingFS) ReadDir(
|
||||||
|
ctx context.Context,
|
||||||
|
op *fuseops.ReadDirOp) error {
|
||||||
|
|
||||||
|
entries := []fuseutil.Dirent{
|
||||||
|
{
|
||||||
|
Offset: 1,
|
||||||
|
Inode: 101,
|
||||||
|
Name: "rdir" + randomString(4),
|
||||||
|
Type: fuseutil.DT_Directory,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Offset: 2,
|
||||||
|
Inode: 102,
|
||||||
|
Name: "rfoo" + randomString(4),
|
||||||
|
Type: fuseutil.DT_File,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Grab the range of interest.
|
||||||
|
if op.Offset > fuseops.DirOffset(len(entries)) {
|
||||||
|
return fuse.EIO
|
||||||
|
}
|
||||||
|
|
||||||
|
entries = entries[op.Offset:]
|
||||||
|
|
||||||
|
// Resume at the specified offset into the array.
|
||||||
|
for _, e := range entries {
|
||||||
|
n := fuseutil.WriteDirent(op.Dst[op.BytesRead:], e)
|
||||||
|
if n == 0 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
op.BytesRead += n
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -723,3 +723,253 @@ func (t *PageCacheTest) TwoFileHandles_KeepCache() {
|
||||||
|
|
||||||
ExpectTrue(bytes.Equal(c1, c3))
|
ExpectTrue(bytes.Equal(c1, c3))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
// Dir cache
|
||||||
|
////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
type DirCacheTest struct {
|
||||||
|
cachingFSTest
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ SetUpInterface = &DirCacheTest{}
|
||||||
|
|
||||||
|
func init() { RegisterTestSuite(&DirCacheTest{}) }
|
||||||
|
|
||||||
|
func (t *DirCacheTest) SetUp(ti *TestInfo) {
|
||||||
|
const (
|
||||||
|
lookupEntryTimeout = 0
|
||||||
|
getattrTimeout = 0
|
||||||
|
)
|
||||||
|
|
||||||
|
t.cachingFSTest.setUp(ti, lookupEntryTimeout, getattrTimeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DirCacheTest) CacheDirAndKeepDirCache() {
|
||||||
|
t.fs.SetCacheDir(true)
|
||||||
|
t.fs.SetKeepDirCache(true)
|
||||||
|
|
||||||
|
// First read, kernel will cache the dir response.
|
||||||
|
f, err := os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
defer f.Close() // Make sure to close specially required in failure scenario.
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names1, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names1))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Second read, will be served from cache.
|
||||||
|
f, err = os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names2, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names2))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
AssertEq(names1[0], names2[0])
|
||||||
|
AssertEq(names1[1], names2[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DirCacheTest) NoCacheDirAndKeepDirCache() {
|
||||||
|
t.fs.SetCacheDir(false)
|
||||||
|
t.fs.SetKeepDirCache(true)
|
||||||
|
|
||||||
|
// First read, no caching since NoCacheDir.
|
||||||
|
f, err := os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
defer f.Close() // Make sure to close specially required in failure scenario.
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names1, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names1))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Second read, will be served from filesystem, hence different name.
|
||||||
|
f, err = os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names2, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names2))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
AssertNe(names1[0], names2[0])
|
||||||
|
AssertNe(names1[1], names2[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DirCacheTest) CacheDirAndNoKeepDirCache() {
|
||||||
|
t.fs.SetCacheDir(true)
|
||||||
|
t.fs.SetKeepDirCache(false)
|
||||||
|
|
||||||
|
// First read, kernel will cache the dir response.
|
||||||
|
f, err := os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
defer f.Close() // Make sure to close specially required in failure scenario.
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names1, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names1))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Second read, cached response will be invalidated since NoKeepDirCache.
|
||||||
|
// Hence, different names.
|
||||||
|
f, err = os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names2, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names2))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
AssertNe(names1[0], names2[0])
|
||||||
|
AssertNe(names1[1], names2[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DirCacheTest) NoCacheDirAndNoKeepDirCache() {
|
||||||
|
t.fs.SetCacheDir(false)
|
||||||
|
t.fs.SetKeepDirCache(false)
|
||||||
|
|
||||||
|
// First read, no caching since NoCacheDir.
|
||||||
|
f, err := os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
defer f.Close() // Make sure to close specially required in failure scenario.
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names1, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names1))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Second read, will be served from filesystem.
|
||||||
|
// Since NoCacheDir also NoKeepDirCache. Hence, different names.
|
||||||
|
f, err = os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names2, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names2))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
AssertNe(names1[0], names2[0])
|
||||||
|
AssertNe(names1[1], names2[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DirCacheTest) CacheDirWithChangingKeepDirCache() {
|
||||||
|
t.fs.SetCacheDir(true)
|
||||||
|
t.fs.SetKeepDirCache(false)
|
||||||
|
|
||||||
|
// First read, kernel will cache the dir response.
|
||||||
|
f, err := os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
defer f.Close() // Make sure to close specially required in failure scenario.
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names1, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names1))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Cached response will not be invalidated. Hence, served from kernel cache.
|
||||||
|
t.fs.SetKeepDirCache(true)
|
||||||
|
// Second read, will be served from cache
|
||||||
|
f, err = os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names2, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names2))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
AssertEq(names1[0], names2[0])
|
||||||
|
AssertEq(names1[1], names2[1])
|
||||||
|
|
||||||
|
// Kernel has cached but invalidated due to NoKeepDirCache.
|
||||||
|
// Hence, third read will be served from filesystem.
|
||||||
|
t.fs.SetKeepDirCache(false)
|
||||||
|
|
||||||
|
// Third read, will be served from filesystem. So, names will be different.
|
||||||
|
f, err = os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names3, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names3))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
AssertNe(names2[0], names3[0])
|
||||||
|
AssertNe(names2[1], names3[1])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *DirCacheTest) ChangingCacheDirWithKeepDirCache() {
|
||||||
|
t.fs.SetCacheDir(true)
|
||||||
|
t.fs.SetKeepDirCache(true)
|
||||||
|
|
||||||
|
// First read, kernel will cache the dir response.
|
||||||
|
f, err := os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
defer f.Close() // Make sure to close specially required in failure scenario.
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names1, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names1))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Cached response will not be invalidated, but also not be served from cache.
|
||||||
|
// Since NoCacheDir so names will be different.
|
||||||
|
t.fs.SetCacheDir(false)
|
||||||
|
// Second read, will be served from filesystem.
|
||||||
|
f, err = os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names2, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names2))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
AssertNe(names1[0], names2[0])
|
||||||
|
AssertNe(names1[1], names2[1])
|
||||||
|
|
||||||
|
// Third read will be served from cache.
|
||||||
|
// But first read response is cached, since KeepDirCache.
|
||||||
|
t.fs.SetCacheDir(true)
|
||||||
|
|
||||||
|
// Third read, will be served from filesystem. So, names will be different.
|
||||||
|
f, err = os.Open(path.Join(t.Dir, "dir"))
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
names3, err := f.Readdirnames(-1)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
AssertEq(2, len(names3))
|
||||||
|
|
||||||
|
err = f.Close()
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
AssertEq(names1[0], names3[0])
|
||||||
|
AssertEq(names1[1], names3[1])
|
||||||
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ func (fs *helloFS) ReadDir(
|
||||||
|
|
||||||
// Grab the range of interest.
|
// Grab the range of interest.
|
||||||
if op.Offset > fuseops.DirOffset(len(entries)) {
|
if op.Offset > fuseops.DirOffset(len(entries)) {
|
||||||
return fuse.EIO
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
entries = entries[op.Offset:]
|
entries = entries[op.Offset:]
|
||||||
|
|
|
@ -0,0 +1,81 @@
|
||||||
|
package memfs_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jacobsa/fuse/samples"
|
||||||
|
"github.com/jacobsa/fuse/samples/memfs"
|
||||||
|
. "github.com/jacobsa/ogletest"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestFuseServerCallbacks(t *testing.T) { RunTests(t) }
|
||||||
|
|
||||||
|
type CallbackTest struct {
|
||||||
|
samples.SampleTest
|
||||||
|
readFileCallbackInvoked bool
|
||||||
|
writeFileCallbackInvoked bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() { RegisterTestSuite(&CallbackTest{}) }
|
||||||
|
|
||||||
|
func (t *CallbackTest) SetUp(ti *TestInfo) {
|
||||||
|
t.MountConfig.DisableWritebackCaching = true
|
||||||
|
t.readFileCallbackInvoked = false
|
||||||
|
t.writeFileCallbackInvoked = false
|
||||||
|
|
||||||
|
t.Server = memfs.NewMemFSWithCallbacks(
|
||||||
|
currentUid(),
|
||||||
|
currentGid(),
|
||||||
|
func() { t.readFileCallbackInvoked = true },
|
||||||
|
func() { t.writeFileCallbackInvoked = true },
|
||||||
|
)
|
||||||
|
t.SampleTest.SetUp(ti)
|
||||||
|
}
|
||||||
|
|
||||||
|
// The test suite is torn down during the test to ensure
|
||||||
|
// that all FUSE operations are complete before checking
|
||||||
|
// the invocations on the callbacks.
|
||||||
|
func (t *CallbackTest) TearDown() {}
|
||||||
|
|
||||||
|
func (t *CallbackTest) TestCallbacksInvokedForWriteFile() {
|
||||||
|
AssertEq(t.writeFileCallbackInvoked, false)
|
||||||
|
AssertEq(t.readFileCallbackInvoked, false)
|
||||||
|
|
||||||
|
// Write a file.
|
||||||
|
fileName := path.Join(t.Dir, memfs.CheckFileOpenFlagsFileName)
|
||||||
|
const contents = "Hello world"
|
||||||
|
err := os.WriteFile(fileName, []byte(contents), 0400)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Tear down the FUSE mount. This ensures that all FUSE operations are complete.
|
||||||
|
t.SampleTest.TearDown()
|
||||||
|
|
||||||
|
// Check that our callback was invoked as expected.
|
||||||
|
AssertEq(t.writeFileCallbackInvoked, true)
|
||||||
|
AssertEq(t.readFileCallbackInvoked, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *CallbackTest) TestCallbacksInvokedForWriteFileAndReadFile() {
|
||||||
|
AssertEq(t.writeFileCallbackInvoked, false)
|
||||||
|
AssertEq(t.readFileCallbackInvoked, false)
|
||||||
|
|
||||||
|
// Write a file.
|
||||||
|
fileName := path.Join(t.Dir, memfs.CheckFileOpenFlagsFileName)
|
||||||
|
const contents = "Hello world"
|
||||||
|
err := os.WriteFile(fileName, []byte(contents), 0400)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
|
||||||
|
// Read it back.
|
||||||
|
slice, err := os.ReadFile(fileName)
|
||||||
|
AssertEq(nil, err)
|
||||||
|
ExpectEq(contents, string(slice))
|
||||||
|
|
||||||
|
// Tear down the FUSE mount. This ensures that all FUSE operations are complete.
|
||||||
|
t.SampleTest.TearDown()
|
||||||
|
|
||||||
|
// Check that our callback was invoked as expected.
|
||||||
|
AssertEq(t.writeFileCallbackInvoked, true)
|
||||||
|
AssertEq(t.readFileCallbackInvoked, true)
|
||||||
|
}
|
|
@ -17,6 +17,7 @@ package memfs
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -377,7 +378,8 @@ func (in *inode) SetAttributes(
|
||||||
|
|
||||||
// Change mode?
|
// Change mode?
|
||||||
if mode != nil {
|
if mode != nil {
|
||||||
in.attrs.Mode = *mode
|
in.attrs.Mode &= ^fs.ModePerm
|
||||||
|
in.attrs.Mode |= *mode & fs.ModePerm
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change mtime?
|
// Change mtime?
|
||||||
|
|
|
@ -67,6 +67,9 @@ type memFS struct {
|
||||||
// INVARIANT: This is all and only indices i of 'inodes' such that i >
|
// INVARIANT: This is all and only indices i of 'inodes' such that i >
|
||||||
// fuseops.RootInodeID and inodes[i] == nil
|
// fuseops.RootInodeID and inodes[i] == nil
|
||||||
freeInodes []fuseops.InodeID // GUARDED_BY(mu)
|
freeInodes []fuseops.InodeID // GUARDED_BY(mu)
|
||||||
|
|
||||||
|
readFileCallback func()
|
||||||
|
writeFileCallback func()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a file system that stores data and metadata in memory.
|
// Create a file system that stores data and metadata in memory.
|
||||||
|
@ -77,11 +80,21 @@ type memFS struct {
|
||||||
func NewMemFS(
|
func NewMemFS(
|
||||||
uid uint32,
|
uid uint32,
|
||||||
gid uint32) fuse.Server {
|
gid uint32) fuse.Server {
|
||||||
|
return NewMemFSWithCallbacks(uid, gid, nil, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewMemFSWithCallbacks(
|
||||||
|
uid uint32,
|
||||||
|
gid uint32,
|
||||||
|
readFileCallback func(),
|
||||||
|
writeFileCallback func()) fuse.Server {
|
||||||
// Set up the basic struct.
|
// Set up the basic struct.
|
||||||
fs := &memFS{
|
fs := &memFS{
|
||||||
inodes: make([]*inode, fuseops.RootInodeID+1),
|
inodes: make([]*inode, fuseops.RootInodeID+1),
|
||||||
uid: uid,
|
uid: uid,
|
||||||
gid: gid,
|
gid: gid,
|
||||||
|
readFileCallback: readFileCallback,
|
||||||
|
writeFileCallback: writeFileCallback,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up the root inode.
|
// Set up the root inode.
|
||||||
|
@ -627,7 +640,7 @@ func (fs *memFS) OpenFile(
|
||||||
// Set attribute (name=fileOpenFlagsXattr, value=OpenFlags) to test whether
|
// Set attribute (name=fileOpenFlagsXattr, value=OpenFlags) to test whether
|
||||||
// we set OpenFlags correctly. The value is checked in test with getXattr.
|
// we set OpenFlags correctly. The value is checked in test with getXattr.
|
||||||
value := make([]byte, 4)
|
value := make([]byte, 4)
|
||||||
binary.LittleEndian.PutUint32(value, uint32(op.OpenFlags))
|
binary.LittleEndian.PutUint32(value, uint32(op.OpenFlags)&syscall.O_ACCMODE)
|
||||||
err := fs.setXattrHelper(inode, &fuseops.SetXattrOp{
|
err := fs.setXattrHelper(inode, &fuseops.SetXattrOp{
|
||||||
Name: FileOpenFlagsXattrName,
|
Name: FileOpenFlagsXattrName,
|
||||||
Value: value,
|
Value: value,
|
||||||
|
@ -653,6 +666,8 @@ func (fs *memFS) ReadFile(
|
||||||
var err error
|
var err error
|
||||||
op.BytesRead, err = inode.ReadAt(op.Dst, op.Offset)
|
op.BytesRead, err = inode.ReadAt(op.Dst, op.Offset)
|
||||||
|
|
||||||
|
op.Callback = fs.readFileCallback
|
||||||
|
|
||||||
// Don't return EOF errors; we just indicate EOF to fuse using a short read.
|
// Don't return EOF errors; we just indicate EOF to fuse using a short read.
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
return nil
|
return nil
|
||||||
|
@ -673,6 +688,8 @@ func (fs *memFS) WriteFile(
|
||||||
// Serve the request.
|
// Serve the request.
|
||||||
_, err := inode.WriteAt(op.Data, op.Offset)
|
_, err := inode.WriteAt(op.Data, op.Offset)
|
||||||
|
|
||||||
|
op.Callback = fs.writeFileCallback
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ func main() {
|
||||||
|
|
||||||
cfg := &fuse.MountConfig{
|
cfg := &fuse.MountConfig{
|
||||||
ReadOnly: *fReadOnly,
|
ReadOnly: *fReadOnly,
|
||||||
|
FuseImpl: fuse.FUSEImplMacFUSE,
|
||||||
}
|
}
|
||||||
|
|
||||||
if *fDebug {
|
if *fDebug {
|
||||||
|
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"syscall"
|
||||||
|
|
||||||
"github.com/jacobsa/fuse/fuseops"
|
"github.com/jacobsa/fuse/fuseops"
|
||||||
"github.com/jacobsa/fuse/fuseutil"
|
"github.com/jacobsa/fuse/fuseutil"
|
||||||
|
@ -53,21 +53,20 @@ func getOrCreateInode(inodes *sync.Map, parentId fuseops.InodeID, name string) (
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
parentPath := parent.(Inode).Path()
|
parentPath := parent.(Inode).Path()
|
||||||
entries, err := ioutil.ReadDir(parentPath)
|
|
||||||
|
path := filepath.Join(parentPath, name)
|
||||||
|
fileInfo, err := os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, nil
|
||||||
}
|
}
|
||||||
for _, entry := range entries {
|
stat, _ := fileInfo.Sys().(*syscall.Stat_t)
|
||||||
if entry.Name() == name {
|
|
||||||
inodeEntry := &inodeEntry{
|
inodeEntry := &inodeEntry{
|
||||||
id: nextInodeID(),
|
id: fuseops.InodeID(stat.Ino),
|
||||||
path: filepath.Join(parentPath, name),
|
path: path,
|
||||||
}
|
}
|
||||||
storedEntry, _ := inodes.LoadOrStore(inodeEntry.id, inodeEntry)
|
storedEntry, _ := inodes.LoadOrStore(inodeEntry.id, inodeEntry)
|
||||||
return storedEntry.(Inode), nil
|
return storedEntry.(Inode), nil
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type inodeEntry struct {
|
type inodeEntry struct {
|
||||||
|
@ -101,14 +100,12 @@ func (in *inodeEntry) Attributes() (*fuseops.InodeAttributes, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &fuseops.InodeAttributes{}, err
|
return &fuseops.InodeAttributes{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &fuseops.InodeAttributes{
|
return &fuseops.InodeAttributes{
|
||||||
Size: uint64(fileInfo.Size()),
|
Size: uint64(fileInfo.Size()),
|
||||||
Nlink: 1,
|
Nlink: 1,
|
||||||
Mode: fileInfo.Mode(),
|
Mode: fileInfo.Mode(),
|
||||||
Atime: fileInfo.ModTime(),
|
|
||||||
Mtime: fileInfo.ModTime(),
|
Mtime: fileInfo.ModTime(),
|
||||||
Ctime: time.Now(),
|
|
||||||
Crtime: time.Now(),
|
|
||||||
Uid: uid,
|
Uid: uid,
|
||||||
Gid: gid,
|
Gid: gid,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -119,12 +116,12 @@ func (in *inodeEntry) ListChildren(inodes *sync.Map) ([]*fuseutil.Dirent, error)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dirents := make([]*fuseutil.Dirent, len(children))
|
dirents := []*fuseutil.Dirent{}
|
||||||
for i, child := range children {
|
for i, child := range children {
|
||||||
|
|
||||||
childInode, err := getOrCreateInode(inodes, in.id, child.Name())
|
childInode, err := getOrCreateInode(inodes, in.id, child.Name())
|
||||||
if err != nil || childInode == nil {
|
if err != nil || childInode == nil {
|
||||||
return nil, nil
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var childType fuseutil.DirentType
|
var childType fuseutil.DirentType
|
||||||
|
@ -136,12 +133,12 @@ func (in *inodeEntry) ListChildren(inodes *sync.Map) ([]*fuseutil.Dirent, error)
|
||||||
childType = fuseutil.DT_File
|
childType = fuseutil.DT_File
|
||||||
}
|
}
|
||||||
|
|
||||||
dirents[i] = &fuseutil.Dirent{
|
dirents = append(dirents, &fuseutil.Dirent{
|
||||||
Offset: fuseops.DirOffset(i + 1),
|
Offset: fuseops.DirOffset(i + 1),
|
||||||
Inode: childInode.Id(),
|
Inode: childInode.Id(),
|
||||||
Name: child.Name(),
|
Name: child.Name(),
|
||||||
Type: childType,
|
Type: childType,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
return dirents, nil
|
return dirents, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,7 +121,7 @@ func (fs *readonlyLoopbackFs) ReadDir(
|
||||||
}
|
}
|
||||||
|
|
||||||
if op.Offset > fuseops.DirOffset(len(children)) {
|
if op.Offset > fuseops.DirOffset(len(children)) {
|
||||||
return fuse.EIO
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
children = children[op.Offset:]
|
children = children[op.Offset:]
|
||||||
|
@ -139,8 +139,13 @@ func (fs *readonlyLoopbackFs) ReadDir(
|
||||||
func (fs *readonlyLoopbackFs) OpenFile(
|
func (fs *readonlyLoopbackFs) OpenFile(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
op *fuseops.OpenFileOp) error {
|
op *fuseops.OpenFileOp) error {
|
||||||
// Allow opening any file.
|
|
||||||
|
var _, found = fs.inodes.Load(op.Inode)
|
||||||
|
if !found {
|
||||||
|
return fuse.ENOENT
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *readonlyLoopbackFs) ReadFile(
|
func (fs *readonlyLoopbackFs) ReadFile(
|
||||||
|
|
|
@ -16,6 +16,7 @@ package statfs_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/jacobsa/oglematchers"
|
||||||
"math"
|
"math"
|
||||||
"regexp"
|
"regexp"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -68,7 +69,7 @@ func (t *StatFSTest) Syscall_ZeroValues() {
|
||||||
ExpectEq(0, stat.Bavail)
|
ExpectEq(0, stat.Bavail)
|
||||||
ExpectEq(0, stat.Files)
|
ExpectEq(0, stat.Files)
|
||||||
ExpectEq(0, stat.Ffree)
|
ExpectEq(0, stat.Ffree)
|
||||||
ExpectEq("osxfuse", convertName(stat.Fstypename[:]))
|
ExpectThat(convertName(stat.Fstypename[:]), oglematchers.AnyOf(oglematchers.Equals("osxfuse"), oglematchers.Equals("macfuse")))
|
||||||
ExpectEq(t.canonicalDir, convertName(stat.Mntonname[:]))
|
ExpectEq(t.canonicalDir, convertName(stat.Mntonname[:]))
|
||||||
ExpectEq(fsName, convertName(stat.Mntfromname[:]))
|
ExpectEq(fsName, convertName(stat.Mntfromname[:]))
|
||||||
}
|
}
|
||||||
|
@ -103,7 +104,7 @@ func (t *StatFSTest) Syscall_NonZeroValues() {
|
||||||
ExpectEq(canned.BlocksAvailable, stat.Bavail)
|
ExpectEq(canned.BlocksAvailable, stat.Bavail)
|
||||||
ExpectEq(canned.Inodes, stat.Files)
|
ExpectEq(canned.Inodes, stat.Files)
|
||||||
ExpectEq(canned.InodesFree, stat.Ffree)
|
ExpectEq(canned.InodesFree, stat.Ffree)
|
||||||
ExpectEq("osxfuse", convertName(stat.Fstypename[:]))
|
ExpectThat(convertName(stat.Fstypename[:]), oglematchers.AnyOf(oglematchers.Equals("osxfuse"), oglematchers.Equals("macfuse")))
|
||||||
ExpectEq(t.canonicalDir, convertName(stat.Mntonname[:]))
|
ExpectEq(t.canonicalDir, convertName(stat.Mntonname[:]))
|
||||||
ExpectEq(fsName, convertName(stat.Mntfromname[:]))
|
ExpectEq(fsName, convertName(stat.Mntfromname[:]))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue