Commit d4e694da authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Pass destination attribute to File.GetAttr.

parent 83e93502
......@@ -170,7 +170,7 @@ type File interface {
// The methods below may be called on closed files, due to
// concurrency. In that case, you should return EBADF.
Truncate(size uint64) Status
GetAttr() (*Attr, Status)
GetAttr(out *Attr) (Status)
Chown(uid uint32, gid uint32) Status
Chmod(perms uint32) Status
Utimens(atimeNs int64, mtimeNs int64) Status
......
......@@ -35,8 +35,8 @@ func (f *DefaultFile) Release() {
}
func (f *DefaultFile) GetAttr() (*Attr, Status) {
return nil, ENOSYS
func (f *DefaultFile) GetAttr(*Attr) Status {
return ENOSYS
}
func (f *DefaultFile) Fsync(flags int) (code Status) {
......
......@@ -26,8 +26,10 @@ func (f *DataFile) String() string {
return fmt.Sprintf("DataFile(%x)", f.data[:l])
}
func (f *DataFile) GetAttr() (*Attr, Status) {
return &Attr{Mode: S_IFREG | 0644, Size: uint64(len(f.data))}, OK
func (f *DataFile) GetAttr(out *Attr) Status {
out.Mode = S_IFREG | 0644
out.Size = uint64(len(f.data))
return OK
}
func NewDataFile(data []byte) *DataFile {
......@@ -52,6 +54,8 @@ type DevNullFile struct {
DefaultFile
}
var _ = (File)((*DevNullFile)(nil))
func NewDevNullFile() *DevNullFile {
return new(DevNullFile)
}
......@@ -134,15 +138,14 @@ func (f *LoopbackFile) Chown(uid uint32, gid uint32) Status {
return ToStatus(f.File.Chown(int(uid), int(gid)))
}
func (f *LoopbackFile) GetAttr() (*Attr, Status) {
func (f *LoopbackFile) GetAttr(a *Attr) Status {
st := syscall.Stat_t{}
err := syscall.Fstat(int(f.File.Fd()), &st)
if err != nil {
return nil, ToStatus(err)
return ToStatus(err)
}
a := &Attr{}
a.FromStat(&st)
return a, OK
return OK
}
////////////////////////////////////////////////////////////////
......
......@@ -147,9 +147,10 @@ func (n *memNodeFile) InnerFile() File {
func (n *memNodeFile) Flush() Status {
code := n.LoopbackFile.Flush()
fi, _ := n.LoopbackFile.GetAttr()
n.node.info.Size = fi.Size
n.node.info.Blocks = fi.Blocks
var a Attr
n.LoopbackFile.GetAttr(&a)
n.node.info.Size = a.Size
n.node.info.Blocks = a.Blocks
return code
}
......
......@@ -527,8 +527,7 @@ func (n *pathInode) GetAttr(out *Attr, file File, context *Context) (code Status
}
if file != nil {
fi, code = file.GetAttr()
*out = *fi
code = file.GetAttr(out)
}
if file == nil || code == ENOSYS || code == EBADF {
......
......@@ -1007,12 +1007,10 @@ func (fs *unionFsFile) SetInode(node *fuse.Inode) {
fs.node = node
}
func (fs *unionFsFile) GetAttr() (*fuse.Attr, fuse.Status) {
fi, code := fs.File.GetAttr()
if fi != nil {
f := *fi
fi = &f
fi.Mode |= 0200
}
return fi, code
func (fs *unionFsFile) GetAttr(out *fuse.Attr) fuse.Status {
code := fs.File.GetAttr(out)
if code.Ok() {
out.Mode |= 0200
}
return code
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment