func TestMemUnionResetDelete(t *testing.T) { wd, ufs, clean := setupMemUfs(t) defer clean() ioutil.WriteFile(wd+"/ro/todelete", []byte{42}, 0644) var before, after, afterReset syscall.Stat_t syscall.Lstat(wd+"/mnt/todelete", &before) before.Ino = 0 os.Remove(wd + "/mnt/todelete") syscall.Lstat(wd+"/mnt/todelete", &after) testEq(t, after, before, false) ufs.Reset() syscall.Lstat(wd+"/mnt/todelete", &afterReset) afterReset.Ino = 0 testEq(t, afterReset, before, true) }
func (constor *Constor) LstatInode(path string, stat *syscall.Stat_t, inode *Inode) error { li := inode.layer if li == -1 { li = constor.getLayer(path) if li == -1 { return syscall.ENOENT } inode.layer = li } pathl := Path.Join(constor.layers[li], path) err := syscall.Lstat(pathl, stat) if err != nil { return err } if li != 0 { // INOXATTR valid only for layer-0 return nil } // var inobyte []byte // inobyte = make([]byte, 100, 100) // size, err := syscall.Getxattr(pathl, INOXATTR, inobyte) inobyte, err := Lgetxattr(pathl, INOXATTR) if err != nil { return nil } if len(inobyte) == 0 { return nil } inostr := string(inobyte) ino, err := strconv.Atoi(inostr) if err != nil { return err } stat.Ino = uint64(ino) if inode.ino == 1 { stat.Ino = 1 } return nil }
// GetAttr - FUSE call func (f *virtualFile) GetAttr(a *fuse.Attr) fuse.Status { var st syscall.Stat_t err := syscall.Lstat(f.parentFile, &st) if err != nil { fmt.Printf("Lstat %q: %v\n", f.parentFile, err) return fuse.ToStatus(err) } st.Ino = f.ino st.Size = int64(len(f.content)) st.Mode = syscall.S_IFREG | 0400 st.Nlink = 1 a.FromStat(&st) return fuse.OK }
func (constor *Constor) Lstat(li int, id string, stat *syscall.Stat_t) error { path := constor.getPath(li, id) if err := syscall.Lstat(path, stat); err != nil { return err } count := 1 linksbyte, err := Lgetxattr(path, LINKSXATTR) if err == nil && len(linksbyte) != 0 { linksstr := string(linksbyte) linksint, err := strconv.Atoi(linksstr) if err != nil { constor.error("%s : %s", id, err) return err } count = linksint } stat.Nlink = uint64(count) stat.Ino = idtoino(id) return nil }
func (constor *Constor) GetAttr(input *fuse.GetAttrIn, out *fuse.AttrOut) (code fuse.Status) { stat := syscall.Stat_t{} inode := constor.inodemap.findInodePtr(input.NodeId) if inode == nil { constor.error("%d not in inodemap", input.NodeId) return fuse.ENOENT } if inode.id == ROOTID && inode.layer == -1 { inode.layer = constor.getLayer(inode.id) if inode.layer == -1 { constor.error("Unable to find root inode") return fuse.ENOENT } } F := constor.fdlookup(inode.id, input.Pid) var err error // FIXME check to see if F.layer needs to be changed if F == nil { if inode.layer == -1 { constor.error("layer is -1 for %s", inode.id) return fuse.ENOENT } constor.log("Lstat on %s", inode.id) err = constor.Lstat(inode.layer, inode.id, &stat) } else { constor.log("Fstat on %s", inode.id) err = syscall.Fstat(F.fd, &stat) stat.Ino = idtoino(F.id) // FIXME take care of hard links too } if err != nil { constor.error("%s: %s", inode.id, err) return fuse.ToStatus(err) } attr := (*fuse.Attr)(&out.Attr) attr.FromStat(&stat) out.AttrValid = 1000 constor.log("%s", inode.id) return fuse.OK }