lib9p

Go 9P library.
Log | Files | Refs | LICENSE

fs.go (2760B)


      1 package lib9p
      2 
      3 import (
      4 	"io/fs"
      5 	"os"
      6 )
      7 
      8 // An FS is an file system to be exported by 9P server.
      9 type FS interface {
     10 	// OpenFile opens file named name with specified flag (O_RDONLY etc.).
     11 	// The separator of name is slash in all platforms.
     12 	//
     13 	// When OpenFile returns an error, it should be of type *fs.PathError
     14 	// with the Op field set to "openfile", the Path field set to name,
     15 	// and the Err field describing the problem.
     16 	//
     17 	// Open should reject attempts to open names that do not satisfy
     18 	// fs.ValidPath(name), returning a *fs.PathError with Err set to
     19 	// fs.ErrInvalid or fs.ErrNotExist.
     20 	OpenFile(name string, flag int) (File, error)
     21 }
     22 
     23 const (
     24 	// Exactly one of O_RDONLY, O_WRONLY, or O_RDWR must be specified.
     25 	O_RDONLY int = os.O_RDONLY // open the file read-only.
     26 	O_WRONLY int = os.O_WRONLY // open the file write-only.
     27 	O_RDWR   int = os.O_RDWR   // open the file read-write.
     28 	// The remaining values may be or'ed in to control behavior.
     29 	O_APPEND int = os.O_APPEND // append data to the file when writing.
     30 	O_CREATE int = os.O_CREATE // create a new file if none exists.
     31 	O_EXCL   int = os.O_EXCL   // used with O_CREATE, file must not exist.
     32 	O_SYNC   int = os.O_SYNC   // open for synchronous I/O.
     33 	O_TRUNC  int = os.O_TRUNC  // truncate regular writable file when opened.
     34 )
     35 
     36 // A GroupFS is an file system with the notion of group.
     37 // If an FS does not implement this interface, then the Server assumes that
     38 // that every group is consists of only one member with the same name as the
     39 // group itself and he is the leader of that group.
     40 type GroupFS interface {
     41 	FS
     42 	// IsGroupLeader reports whether uid is the leader of group.
     43 	IsGroupLeader(group, uid string) bool
     44 	// IsGroupMember reports whether uid is a member of group.
     45 	IsGroupMember(group, uid string) bool
     46 }
     47 
     48 type CreatorFS interface {
     49 	FS
     50 	// Create creates a file named name.
     51 	// It sets the owner of newly created file to the specified uid,
     52 	// and file mode to the specified perm.
     53 	//
     54 	// Create should reject attempts to create names that do not satisfy
     55 	// fs.ValidPath(name), returning a *fs.PathError with Err set to
     56 	// fs.ErrInvalid.
     57 	Create(name string, uid string, mode OpenMode, perm FileMode) (File, error)
     58 }
     59 
     60 type RemoverFS interface {
     61 	FS
     62 	Remove(name string) error
     63 }
     64 
     65 func FSModeToQidType(fm fs.FileMode) QidType {
     66 	var qt QidType
     67 	if fm&fs.ModeDir != 0 {
     68 		qt |= QTDIR
     69 	}
     70 	if fm&fs.ModeAppend != 0 {
     71 		qt |= QTAPPEND
     72 	}
     73 	if fm&fs.ModeExclusive != 0 {
     74 		qt |= QTEXCL
     75 	}
     76 	if fm&fs.ModeTemporary != 0 {
     77 		qt |= QTTMP
     78 	}
     79 	if fm&fs.ModeSymlink != 0 {
     80 		qt |= QTSYMLINK
     81 	}
     82 	// QTMOUNT is not in fs.FileMode.
     83 	// ModeDevice, ModeNamedPope, ModeSocket, ModeSetuid,
     84 	// ModeSetgid, ModeCharDevice, ModeSticky, ModeIrregular
     85 	// are not in QidType.
     86 	return qt
     87 }