@@ -115,6 +115,25 @@ func isNameRestricted(name string) bool {
115115 return disallowedRexp .FindStringIndex (name ) != nil
116116}
117117
118+ // makeattr is a convenience function to create a set of filesystem attrs for
119+ // use with syscalls that use or modify attrs.
120+ func (f * Filesystem ) makeAttr (i * Inode ) fuse.Attr {
121+ mtime := i .ModTime ()
122+ return fuse.Attr {
123+ Ino : i .NodeID (),
124+ Size : i .Size (),
125+ Nlink : i .NLink (),
126+ Ctime : mtime ,
127+ Mtime : mtime ,
128+ Atime : mtime ,
129+ Mode : i .Mode (),
130+ Owner : fuse.Owner {
131+ Uid : f .uid ,
132+ Gid : f .gid ,
133+ },
134+ }
135+ }
136+
118137// Statfs returns information about the filesystem. Mainly useful for checking
119138// quotas and storage limits.
120139func (f * Filesystem ) StatFs (cancel <- chan struct {}, in * fuse.InHeader , out * fuse.StatfsOut ) fuse.Status {
@@ -180,7 +199,7 @@ func (f *Filesystem) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string
180199 newInode .mode = in .Mode | fuse .S_IFDIR
181200
182201 out .NodeId = f .InsertChild (id , newInode )
183- out .Attr = newInode .makeAttr ()
202+ out .Attr = f .makeAttr (newInode )
184203 out .SetAttrTimeout (timeout )
185204 out .SetEntryTimeout (timeout )
186205 return fuse .OK
@@ -305,7 +324,7 @@ func (f *Filesystem) ReadDirPlus(cancel <-chan struct{}, in *fuse.ReadIn, out *f
305324 return fuse .EIO
306325 }
307326 entryOut .NodeId = entry .Ino
308- entryOut .Attr = inode .makeAttr ()
327+ entryOut .Attr = f .makeAttr (inode )
309328 entryOut .SetAttrTimeout (timeout )
310329 entryOut .SetEntryTimeout (timeout )
311330 return fuse .OK
@@ -369,7 +388,7 @@ func (f *Filesystem) Lookup(cancel <-chan struct{}, in *fuse.InHeader, name stri
369388 }
370389
371390 out .NodeId = child .NodeID ()
372- out .Attr = child .makeAttr ()
391+ out .Attr = f .makeAttr (child )
373392 out .SetAttrTimeout (timeout )
374393 out .SetEntryTimeout (timeout )
375394 return fuse .OK
@@ -412,7 +431,7 @@ func (f *Filesystem) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string
412431 Str ("mode" , Octal (in .Mode )).
413432 Msg ("Creating inode." )
414433 out .NodeId = f .InsertChild (parentID , inode )
415- out .Attr = inode .makeAttr ()
434+ out .Attr = f .makeAttr (inode )
416435 out .SetAttrTimeout (timeout )
417436 out .SetEntryTimeout (timeout )
418437 return fuse .OK
@@ -721,7 +740,7 @@ func (f *Filesystem) GetAttr(cancel <-chan struct{}, in *fuse.GetAttrIn, out *fu
721740 Str ("path" , inode .Path ()).
722741 Msg ("" )
723742
724- out .Attr = inode .makeAttr ()
743+ out .Attr = f .makeAttr (inode )
725744 out .SetTimeout (timeout )
726745 return fuse .OK
727746}
@@ -784,7 +803,7 @@ func (f *Filesystem) SetAttr(cancel <-chan struct{}, in *fuse.SetAttrIn, out *fu
784803 }
785804
786805 i .Unlock ()
787- out .Attr = i .makeAttr ()
806+ out .Attr = f .makeAttr (i )
788807 out .SetTimeout (timeout )
789808 return fuse .OK
790809}
0 commit comments