Exemplo n.º 1
0
func (m *MaggieFuse) Rmdir(header *raw.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
}
Exemplo n.º 2
0
func (m *MaggieFuse) Link(out *raw.EntryOut, header *raw.InHeader, input *raw.LinkIn, name string) (code fuse.Status) {
	// new parent is header.NodeId
	// existing node is input.Oldnodeid

	// add link to new parent
	err := m.names.Link(header.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
}
Exemplo n.º 3
0
func (m *MaggieFuse) Unlink(header *raw.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
}
Exemplo n.º 4
0
func (m *MaggieFuse) Mkdir(out *raw.EntryOut, header *raw.InHeader, input *raw.MkdirIn, name string) (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,
		header.Uid,
		header.Gid,
		"",
		make([]maggiefs.Block, 0, 0),
		make(map[string]maggiefs.Dentry),
		make(map[string][]byte),
	}

	// save
	id, err := m.names.AddInode(&i)
	if err != nil {
		return fuse.EROFS
	}
	i.Inodeid = id
	// link parent
	err = m.names.Link(header.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
}
Exemplo n.º 5
0
func (m *MaggieFuse) Mknod(out *raw.EntryOut, header *raw.InHeader, input *raw.MknodIn, name string) (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,
		header.Uid,
		header.Gid,
		"",
		make([]maggiefs.Block, 0, 0),
		make(map[string]maggiefs.Dentry),
		make(map[string][]byte),
	}

	// save new node
	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, 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

}
Exemplo n.º 6
0
func (m *MaggieFuse) Symlink(out *raw.EntryOut, header *raw.InHeader, pointedTo string, linkName string) (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),
		make(map[string][]byte),
	}
	// 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
}