func (m *MaggieFuse) Rmdir(header *fuse.InHeader, name string) (code fuse.Status) { // sanity checks on parent, child // pull parent parent, err := m.names.GetInode(header.NodeId) if err != nil { return fuse.EROFS } // check if name doesn't exist childEntry, exists := parent.Children[name] if !exists { return fuse.ENOENT } // look up node for name child, err := m.names.GetInode(childEntry.Inodeid) if err != nil { return fuse.EROFS } // if child is not dir, err if !child.IsDir() { return fuse.Status(syscall.ENOTDIR) } fmt.Printf("removing directory %d with children %+v", child.Inodeid, child.Children) if len(child.Children) != 0 { return fuse.Status(syscall.ENOTEMPTY) } // actually unlink err = m.names.Unlink(parent.Inodeid, name) if err != nil { return fuse.EROFS } return fuse.OK }
func (m *MaggieFuse) Link(input *fuse.LinkIn, name string, out *fuse.EntryOut) (code fuse.Status) { // new parent is header.NodeId // existing node is input.Oldnodeid // add link to new parent err := m.names.Link(input.InHeader.NodeId, input.Oldnodeid, name, false) if err == maggiefs.E_EXISTS { return fuse.Status(syscall.EEXIST) } else if err != nil { return fuse.EROFS } return fuse.OK }
func (m *MaggieFuse) Unlink(header *fuse.InHeader, name string) (code fuse.Status) { // finally unlink err := m.names.Unlink(header.NodeId, name) if err != nil { if err == maggiefs.E_NOENT { return fuse.ENOENT } else if err == maggiefs.E_ISDIR { return fuse.Status(syscall.EISDIR) } return fuse.EROFS } return fuse.OK }
func (m *MaggieFuse) Mkdir(input *fuse.MkdirIn, name string, out *fuse.EntryOut) (code fuse.Status) { // make new child currTime := time.Now().Unix() i := maggiefs.Inode{ 0, // id 0 to start, we get id when inserting 0, maggiefs.FTYPE_DIR, 0, 07777 & input.Mode, currTime, currTime, 0, input.InHeader.Uid, input.InHeader.Gid, "", make([]maggiefs.Block, 0, 0), make(map[string]maggiefs.Dentry), } // save id, err := m.names.AddInode(&i) if err != nil { return fuse.EROFS } i.Inodeid = id // link parent err = m.names.Link(input.InHeader.NodeId, id, name, false) if err != nil { // garbage collector will clean up our 0 reference node if err == maggiefs.E_EXISTS { return fuse.Status(syscall.EEXIST) } if err == maggiefs.E_NOTDIR { return fuse.ENOTDIR } return fuse.EROFS } // send entry back to child fillEntryOut(out, &i) return fuse.OK }
func (m *MaggieFuse) Mknod(input *fuse.MknodIn, name string, out *fuse.EntryOut) (code fuse.Status) { //build node currTime := time.Now().Unix() i := maggiefs.Inode{ 0, // id 0 to start 0, // gen 0 maggiefs.FTYPE_REG, 0, input.Mode & 07777, currTime, currTime, 1, input.InHeader.Uid, input.InHeader.Gid, "", make([]maggiefs.Block, 0, 0), make(map[string]maggiefs.Dentry), } // save new node id, err := m.names.AddInode(&i) if err != nil { return fuse.EROFS } i.Inodeid = id // link parent err = m.names.Link(input.InHeader.NodeId, i.Inodeid, name, false) if err != nil { if err == maggiefs.E_EXISTS { return fuse.Status(syscall.EEXIST) } else { return fuse.EROFS } } // output fillEntryOut(out, &i) return fuse.OK }
func (m *MaggieFuse) Symlink(header *fuse.InHeader, pointedTo string, linkName string, out *fuse.EntryOut) (code fuse.Status) { // new inode type symlink currTime := time.Now().Unix() i := maggiefs.Inode{ 0, // id 0 to start, we get id when inserting 0, maggiefs.FTYPE_LNK, 0, 0777, currTime, currTime, 0, header.Uid, header.Gid, pointedTo, make([]maggiefs.Block, 0, 0), make(map[string]maggiefs.Dentry), } // save id, err := m.names.AddInode(&i) if err != nil { return fuse.EROFS } i.Inodeid = id // link parent err = m.names.Link(header.NodeId, i.Inodeid, linkName, false) if err != nil { if err == maggiefs.E_EXISTS { return fuse.Status(syscall.EEXIST) } else if err == maggiefs.E_NOTDIR { return fuse.ENOTDIR } return fuse.EROFS } // send entry back to child fillEntryOut(out, &i) return fuse.OK }