From 4898d79241b8d92d15e326b0f267ecd54c133e0c Mon Sep 17 00:00:00 2001 From: Ka-Hing Cheung Date: Wed, 11 Dec 2019 00:49:03 -0800 Subject: [PATCH] plumb through Fd in setattr (#67) this allows us to distinguish between truncate vs ftruncate --- conversions.go | 5 +++++ fuseops/ops.go | 3 +++ samples/memfs/memfs.go | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/conversions.go b/conversions.go index fb034e9..6502767 100644 --- a/conversions.go +++ b/conversions.go @@ -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{}))) diff --git a/fuseops/ops.go b/fuseops/ops.go index d09c690..03ab376 100644 --- a/fuseops/ops.go +++ b/fuseops/ops.go @@ -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 diff --git a/samples/memfs/memfs.go b/samples/memfs/memfs.go index 6cbb6bc..e0f2a5b 100644 --- a/samples/memfs/memfs.go +++ b/samples/memfs/memfs.go @@ -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)