@@ -115,6 +115,26 @@ 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+ // whatever user is running the filesystem is the owner
131+ Owner : fuse.Owner {
132+ Uid : f .uid ,
133+ Gid : f .gid ,
134+ },
135+ }
136+ }
137+
118138// Statfs returns information about the filesystem. Mainly useful for checking
119139// quotas and storage limits.
120140func (f * Filesystem ) StatFs (cancel <- chan struct {}, in * fuse.InHeader , out * fuse.StatfsOut ) fuse.Status {
@@ -180,7 +200,7 @@ func (f *Filesystem) Mkdir(cancel <-chan struct{}, in *fuse.MkdirIn, name string
180200 newInode .mode = in .Mode | fuse .S_IFDIR
181201
182202 out .NodeId = f .InsertChild (id , newInode )
183- out .Attr = newInode .makeAttr ()
203+ out .Attr = f .makeAttr (newInode )
184204 out .SetAttrTimeout (timeout )
185205 out .SetEntryTimeout (timeout )
186206 return fuse .OK
@@ -305,7 +325,7 @@ func (f *Filesystem) ReadDirPlus(cancel <-chan struct{}, in *fuse.ReadIn, out *f
305325 return fuse .EIO
306326 }
307327 entryOut .NodeId = entry .Ino
308- entryOut .Attr = inode .makeAttr ()
328+ entryOut .Attr = f .makeAttr (inode )
309329 entryOut .SetAttrTimeout (timeout )
310330 entryOut .SetEntryTimeout (timeout )
311331 return fuse .OK
@@ -369,7 +389,7 @@ func (f *Filesystem) Lookup(cancel <-chan struct{}, in *fuse.InHeader, name stri
369389 }
370390
371391 out .NodeId = child .NodeID ()
372- out .Attr = child .makeAttr ()
392+ out .Attr = f .makeAttr (child )
373393 out .SetAttrTimeout (timeout )
374394 out .SetEntryTimeout (timeout )
375395 return fuse .OK
@@ -412,7 +432,7 @@ func (f *Filesystem) Mknod(cancel <-chan struct{}, in *fuse.MknodIn, name string
412432 Str ("mode" , Octal (in .Mode )).
413433 Msg ("Creating inode." )
414434 out .NodeId = f .InsertChild (parentID , inode )
415- out .Attr = inode .makeAttr ()
435+ out .Attr = f .makeAttr (inode )
416436 out .SetAttrTimeout (timeout )
417437 out .SetEntryTimeout (timeout )
418438 return fuse .OK
@@ -721,7 +741,7 @@ func (f *Filesystem) GetAttr(cancel <-chan struct{}, in *fuse.GetAttrIn, out *fu
721741 Str ("path" , inode .Path ()).
722742 Msg ("" )
723743
724- out .Attr = inode .makeAttr ()
744+ out .Attr = f .makeAttr (inode )
725745 out .SetTimeout (timeout )
726746 return fuse .OK
727747}
@@ -784,7 +804,7 @@ func (f *Filesystem) SetAttr(cancel <-chan struct{}, in *fuse.SetAttrIn, out *fu
784804 }
785805
786806 i .Unlock ()
787- out .Attr = i .makeAttr ()
807+ out .Attr = f .makeAttr (i )
788808 out .SetTimeout (timeout )
789809 return fuse .OK
790810}
0 commit comments