Commit 67e4fbbc authored by Aaron Jacobs's avatar Aaron Jacobs

Added memFS.MkNode.

parent 47638fa8
...@@ -305,28 +305,37 @@ func (fs *memFS) MkDir( ...@@ -305,28 +305,37 @@ func (fs *memFS) MkDir(
return return
} }
func (fs *memFS) CreateFile( func (fs *memFS) MkNode(
ctx context.Context, ctx context.Context,
op *fuseops.CreateFileOp) (err error) { op *fuseops.MkNodeOp) (err error) {
fs.mu.Lock() fs.mu.Lock()
defer fs.mu.Unlock() defer fs.mu.Unlock()
op.Entry, err = fs.createFile(op.Parent, op.Name, op.Mode)
return
}
// LOCKS_REQUIRED(fs.mu)
func (fs *memFS) createFile(
parentID fuseops.InodeID,
name string,
mode os.FileMode) (entry fuseops.ChildInodeEntry, err error) {
// Grab the parent, which we will update shortly. // Grab the parent, which we will update shortly.
parent := fs.getInodeOrDie(op.Parent) parent := fs.getInodeOrDie(parentID)
// Ensure that the name doesn't already exist, so we don't wind up with a // Ensure that the name doesn't already exist, so we don't wind up with a
// duplicate. // duplicate.
_, _, exists := parent.LookUpChild(op.Name) _, _, exists := parent.LookUpChild(name)
if exists { if exists {
err = fuse.EEXIST err = fuse.EEXIST
return return
} }
// Set up attributes from the child. // Set up attributes for the child.
now := time.Now() now := time.Now()
childAttrs := fuseops.InodeAttributes{ childAttrs := fuseops.InodeAttributes{
Nlink: 1, Nlink: 1,
Mode: op.Mode, Mode: mode,
Atime: now, Atime: now,
Mtime: now, Mtime: now,
Ctime: now, Ctime: now,
...@@ -339,19 +348,27 @@ func (fs *memFS) CreateFile( ...@@ -339,19 +348,27 @@ func (fs *memFS) CreateFile(
childID, child := fs.allocateInode(childAttrs) childID, child := fs.allocateInode(childAttrs)
// Add an entry in the parent. // Add an entry in the parent.
parent.AddChild(childID, op.Name, fuseutil.DT_File) parent.AddChild(childID, name, fuseutil.DT_File)
// Fill in the response entry. // Fill in the response entry.
op.Entry.Child = childID entry.Child = childID
op.Entry.Attributes = child.attrs entry.Attributes = child.attrs
// We don't spontaneously mutate, so the kernel can cache as long as it wants // We don't spontaneously mutate, so the kernel can cache as long as it wants
// (since it also handles invalidation). // (since it also handles invalidation).
op.Entry.AttributesExpiration = time.Now().Add(365 * 24 * time.Hour) entry.AttributesExpiration = time.Now().Add(365 * 24 * time.Hour)
op.Entry.EntryExpiration = op.Entry.EntryExpiration entry.EntryExpiration = entry.AttributesExpiration
return
}
// We have nothing interesting to put in the Handle field. func (fs *memFS) CreateFile(
ctx context.Context,
op *fuseops.CreateFileOp) (err error) {
fs.mu.Lock()
defer fs.mu.Unlock()
op.Entry, err = fs.createFile(op.Parent, op.Name, op.Mode)
return return
} }
......
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