diff --git a/samples/memfs/fs.go b/samples/memfs/fs.go index eceed2b..07e3885 100644 --- a/samples/memfs/fs.go +++ b/samples/memfs/fs.go @@ -279,7 +279,7 @@ func (fs *memFS) MkDir( parent := fs.getInodeForModifyingOrDie(req.Parent) defer parent.mu.Unlock() - // Set up attributes from the child, using the credientials of the calling + // Set up attributes from the child, using the credentials of the calling // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). now := fs.clock.Now() childAttrs := fuse.InodeAttributes{ @@ -311,6 +311,52 @@ func (fs *memFS) MkDir( return } +func (fs *memFS) CreateFile( + ctx context.Context, + req *fuse.CreateFileRequest) (resp *fuse.CreateFileResponse, err error) { + resp = &fuse.CreateFileResponse{} + + fs.mu.Lock() + defer fs.mu.Unlock() + + // Grab the parent, which we will update shortly. + parent := fs.getInodeForModifyingOrDie(req.Parent) + defer parent.mu.Unlock() + + // Set up attributes from the child, using the credentials of the calling + // process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8). + now := fs.clock.Now() + childAttrs := fuse.InodeAttributes{ + Mode: req.Mode, + Atime: now, + Mtime: now, + Ctime: now, + Crtime: now, + Uid: req.Header.Uid, + Gid: req.Header.Gid, + } + + // Allocate a child. + childID, child := fs.allocateInode(childAttrs) + defer child.mu.Unlock() + + // Add an entry in the parent. + parent.AddChild(childID, req.Name, fuseutil.DT_File) + + // Fill in the response entry. + resp.Entry.Child = childID + resp.Entry.Attributes = child.attributes + + // We don't spontaneously mutate, so the kernel can cache as long as it wants + // (since it also handles invalidation). + resp.Entry.AttributesExpiration = fs.clock.Now().Add(365 * 24 * time.Hour) + resp.Entry.EntryExpiration = resp.Entry.EntryExpiration + + // We have nothing interesting to put in the Handle field. + + return +} + func (fs *memFS) RmDir( ctx context.Context, req *fuse.RmDirRequest) (resp *fuse.RmDirResponse, err error) {