Ejemplo n.º 1
0
func (f *File) Attr(c context.Context, a *fuse.Attr) error {
	defer log.Debugln("file_attr:", f.dir.path, f.name, a)

	f.mu.Lock()
	defer f.mu.Unlock()

	return f.dir.fs.backend.View(c, func(ctx Context) error {
		b, err := ctx.Dir(f.dir.path)
		if err != nil {
			return err
		}
		meta, err := b.Meta(f.name)
		if err != nil {
			return err
		}
		a.Uid = meta.Uid
		a.Gid = meta.Gid
		a.Mode = meta.Perm
		a.Nlink = f.links
		if f.link {
			a.Mode = a.Mode | os.ModeSymlink
		}
		a.Size = uint64(len(f.data))
		if f.writers == 0 {
			// not in memory, fetch correct size.
			// Attr can't fail, so ignore errors
			_ = f.load(c, func(buff []byte) { a.Size = uint64(len(buff)) })
		}
		return nil
	})
}
Ejemplo n.º 2
0
// Attr sets the fuse attribute for the file
func (f *File) Attr(ctx context.Context, attr *fuse.Attr) (err error) {
	// Set attributes from resource metadata
	attr.Mode = f.resource.Mode()
	attr.Uid = f.uid
	attr.Gid = f.gid

	if rf, ok := f.resource.(continuity.RegularFile); ok {
		attr.Nlink = uint32(len(rf.Paths()))
		attr.Size = uint64(rf.Size())
	} else {
		attr.Nlink = 1
	}

	attr.Inode = f.inode

	return nil
}
Ejemplo n.º 3
0
// Attr implements the Node interface. It is called when fetching the inode attribute for
// this directory (e.g., to service stat(2)).
func (dir *consulDir) Attr(ctx context.Context, attr *fuse.Attr) error {
	attr.Mode = dir.mode()
	// Nlink should technically include all the files in the directory, but VFS seems fine
	// with the constant "2".
	attr.Nlink = 2
	attr.Uid = dir.ConsulFS.UID
	attr.Gid = dir.ConsulFS.GID
	return nil
}
Ejemplo n.º 4
0
func nodeAttr(ctx context.Context, n Node, attr *fuse.Attr) error {
	attr.Valid = attrValidTime
	attr.Nlink = 1
	attr.Atime = startTime
	attr.Mtime = startTime
	attr.Ctime = startTime
	attr.Crtime = startTime
	if err := n.Attr(ctx, attr); err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 5
0
// lockedAttr fills in an Attr struct for this file. Call when the file's mutex is locked.
func (file *consulFile) lockedAttr(attr *fuse.Attr) {
	attr.Mode = file.ConsulFS.mode()
	if !file.Deleted {
		attr.Nlink = 1
	}
	// Timestamps aren't reflected in Consul, but it doesn't hurt to fake them
	attr.Ctime = file.Ctime
	attr.Mtime = file.Mtime
	attr.Atime = file.Atime
	attr.Uid = file.ConsulFS.UID
	attr.Gid = file.ConsulFS.GID
	if file.IsOpen {
		// Some applications like seeking...
		attr.Size = file.Size
	}
}
Ejemplo n.º 6
0
func (t *Node) Attr(ctx context.Context, a *fuse.Attr) error {
	fi, err := os.Stat(t.getTargetPath(""))
	if err != nil {
		return err
	}
	st := fi.Sys().(*syscall.Stat_t)
	a.Nlink = uint32(st.Nlink)
	a.Size = uint64(st.Size)
	a.Gid = st.Gid
	a.Uid = st.Uid
	a.Ctime = time.Unix(st.Ctimespec.Unix())
	a.Blocks = uint64(st.Blocks)
	a.BlockSize = uint32(st.Blksize)
	a.Inode = st.Ino
	a.Mode = fi.Mode()
	logex.Struct(a)
	return nil
}
Ejemplo n.º 7
0
func (n FileNode) Attr(ctx context.Context, a *bfuse.Attr) error {
	attr, err := n.fs.Attr(n.id)
	if err != nil {
		panic("fs.Attr failed for FileNode")
	}

	a.Valid = 1 * time.Minute
	a.Nlink = 1
	a.Inode = uint64(n.id)
	a.Mode = os.FileMode(attr.PermMode) & os.ModePerm
	a.Atime = attr.ModifiedT
	a.Mtime = attr.ModifiedT
	a.Ctime = attr.ModifiedT
	a.Crtime = attr.ModifiedT
	a.Size = uint64(attr.Size)
	a.Uid = attr.Uid
	a.Gid = attr.Gid
	return nil
}
Ejemplo n.º 8
0
func GoFileInfoToFuseAttr(fi os.FileInfo) fuse.Attr {
	a := fuse.Attr{
		// Valid: cachable,
		Size:  uint64(fi.Size()),
		Mode:  fi.Mode(),
		Mtime: fi.ModTime(),
	}

	switch sp := fi.Sys().(type) {
	case *sys.Stat_t:
		AssertEq(StatModeToGoMode(uint64(sp.Mode)), a.Mode)
		// System specific attributes
		SetSysAttributes(sp, &a)
		a.Blocks = uint64(sp.Blocks)
		a.Gid = sp.Gid
		a.Inode = uint64(sp.Ino)
		a.Nlink = uint32(sp.Nlink)
		a.Rdev = uint32(sp.Rdev)
		a.Uid = sp.Uid
	}

	return a
}