Ejemplo n.º 1
0
func (fs *memFS) MkDir(
	op *fuseops.MkDirOp) (err error) {
	fs.mu.Lock()
	defer fs.mu.Unlock()

	// Grab the parent, which we will update shortly.
	parent := fs.getInodeOrDie(op.Parent)

	// Ensure that the name doesn't already exist, so we don't wind up with a
	// duplicate.
	_, _, exists := parent.LookUpChild(op.Name)
	if exists {
		err = fuse.EEXIST
		return
	}

	// Set up attributes from the child, using the credentials of the calling
	// process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8).
	childAttrs := fuseops.InodeAttributes{
		Nlink: 1,
		Mode:  op.Mode,
		Uid:   op.Header().Uid,
		Gid:   op.Header().Gid,
	}

	// Allocate a child.
	childID, child := fs.allocateInode(childAttrs)

	// Add an entry in the parent.
	parent.AddChild(childID, op.Name, fuseutil.DT_Directory)

	// Fill in the response.
	op.Entry.Child = childID
	op.Entry.Attributes = child.attrs

	// We don't spontaneously mutate, so the kernel can cache as long as it wants
	// (since it also handles invalidation).
	op.Entry.AttributesExpiration = fs.clock.Now().Add(365 * 24 * time.Hour)
	op.Entry.EntryExpiration = op.Entry.EntryExpiration

	return
}