plumb through Fd in setattr (#67)

this allows us to distinguish between truncate vs ftruncate
geesefs-0-30-9
Ka-Hing Cheung 2019-12-11 00:49:03 -08:00 committed by Michael Stapelberg
parent e7bcad2083
commit 4898d79241
3 changed files with 14 additions and 0 deletions

View File

@ -93,6 +93,11 @@ func convertInMessage(
to.Mtime = &t
}
if valid.Handle() {
t := fuseops.HandleID(in.Fh)
to.Handle = &t
}
case fusekernel.OpForget:
type input fusekernel.ForgetIn
in := (*input)(inMsg.Consume(unsafe.Sizeof(input{})))

View File

@ -145,6 +145,9 @@ type SetInodeAttributesOp struct {
// The inode of interest.
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.
Size *uint64
Mode *os.FileMode

View File

@ -247,6 +247,12 @@ func (fs *memFS) SetInodeAttributes(
fs.mu.Lock()
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.
inode := fs.getInodeOrDie(op.Inode)