Commit 4898d792 authored by Ka-Hing Cheung's avatar Ka-Hing Cheung Committed by Michael Stapelberg

plumb through Fd in setattr (#67)

this allows us to distinguish between truncate vs ftruncate
parent e7bcad20
...@@ -93,6 +93,11 @@ func convertInMessage( ...@@ -93,6 +93,11 @@ func convertInMessage(
to.Mtime = &t to.Mtime = &t
} }
if valid.Handle() {
t := fuseops.HandleID(in.Fh)
to.Handle = &t
}
case fusekernel.OpForget: case fusekernel.OpForget:
type input fusekernel.ForgetIn type input fusekernel.ForgetIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{}))) in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))
......
...@@ -145,6 +145,9 @@ type SetInodeAttributesOp struct { ...@@ -145,6 +145,9 @@ type SetInodeAttributesOp struct {
// The inode of interest. // The inode of interest.
Inode InodeID Inode InodeID
// If set, this is ftruncate(2), otherwise it's truncate(2)
Handle *HandleID
// The attributes to modify, or nil for attributes that don't need a change. // The attributes to modify, or nil for attributes that don't need a change.
Size *uint64 Size *uint64
Mode *os.FileMode Mode *os.FileMode
......
...@@ -247,6 +247,12 @@ func (fs *memFS) SetInodeAttributes( ...@@ -247,6 +247,12 @@ func (fs *memFS) SetInodeAttributes(
fs.mu.Lock() fs.mu.Lock()
defer fs.mu.Unlock() defer fs.mu.Unlock()
if op.Size != nil && op.Handle == nil && *op.Size != 0 {
// require that truncate to non-zero has to be ftruncate()
// but allow open(O_TRUNC)
err = syscall.EBADF
}
// Grab the inode. // Grab the inode.
inode := fs.getInodeOrDie(op.Inode) inode := fs.getInodeOrDie(op.Inode)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment