fs.go (1149B)
1 // Package iofs provides a glue layer between fs.FS and lib9p.FS 2 // The resulting file system is readonly. 3 package iofs 4 5 import ( 6 "errors" 7 "io/fs" 8 9 "git.mtkn.jp/lib9p" 10 ) 11 12 type FS struct { 13 fs fs.FS 14 qidPool *QidPool 15 } 16 17 // NewFS converts the fs.FS to FS 18 // It can then be used as the lib9p.FS argument for lib9p.NewServer. 19 func NewFS(fsys fs.FS) *FS { 20 fs := &FS{ 21 fs: fsys, 22 qidPool: allocQidPool(), 23 } 24 return fs 25 } 26 27 func (fsys *FS) OpenFile(name string, flag int) (lib9p.File, error) { 28 if flag != lib9p.O_RDONLY { 29 return nil, errors.New("read only file system") 30 } 31 if name == "" { 32 name = "." 33 } 34 f, err := fsys.fs.Open(name) 35 if err != nil { 36 return nil, err 37 } 38 return &File{ 39 fs: fsys, 40 file: f, 41 path: name, 42 }, nil 43 } 44 45 // This function assumes that group and uid both exist and 46 // the leader of group has the same name as group itself. 47 func (fsys *FS) IsGroupLeader(group, uid string) bool { 48 return group == uid 49 } 50 51 // This function assumes that group and uid both exists and 52 // only the member of group has the same name as group itself. 53 func (fsys *FS) IsGroupMember(group, uid string) bool { 54 return group == uid 55 }