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