Documentation ¶
Overview ¶
Package ramfs implements a 9P2000 file server keeping all files in memory.
A 9P2000 server is an agent that provides one or more hierarchical file systems -- file trees -- that may be accessed by processes. A server responds to requests by clients to navigate the hierarchy, and to create, remove, read, and write files.
References:
[intro] http://plan9.bell-labs.com/magic/man2html/5/0intro [attach] http://plan9.bell-labs.com/magic/man2html/5/attach [clunk] http://plan9.bell-labs.com/magic/man2html/5/clunk [error] http://plan9.bell-labs.com/magic/man2html/5/error [flush] http://plan9.bell-labs.com/magic/man2html/5/flush [open] http://plan9.bell-labs.com/magic/man2html/5/open [read] http://plan9.bell-labs.com/magic/man2html/5/read [remove] http://plan9.bell-labs.com/magic/man2html/5/remove [stat] http://plan9.bell-labs.com/magic/man2html/5/stat [version] http://plan9.bell-labs.com/magic/man2html/5/version [walk] http://plan9.bell-labs.com/magic/man2html/5/walk
Index ¶
- Constants
- type FS
- func (fs *FS) Attach(uname, aname string) (*Fid, error)
- func (fs *FS) Create(name string, mode uint8, perm Perm) (*Fid, error)
- func (fs *FS) Halt() error
- func (fs *FS) Listen(network, addr string) error
- func (fs *FS) Open(name string, mode uint8) (*Fid, error)
- func (fs *FS) Remove(name string) error
- type Fid
- func (f *Fid) Close() error
- func (f *Fid) Create(name string, mode uint8, perm Perm) error
- func (f *Fid) Open(mode uint8) error
- func (f *Fid) ReadAt(p []byte, offset int64) (int, error)
- func (f *Fid) Remove() error
- func (f *Fid) Stat() ([]byte, error)
- func (f *Fid) Walk(name []string, fn WalkFunc) error
- func (f *Fid) WriteAt(p []byte, offset int64) (int, error)
- func (f *Fid) Wstat(data []byte) error
- type LogFunc
- type Perm
- type WalkFunc
Constants ¶
const ( MSIZE = 128*1024 + plan9.IOHDRSZ // maximum message size // IOUNIT represents the maximum size that is guaranteed to be // transferred atomically. IOUNIT = 128 * 1024 BLOCKSIZE = 2 * 1024 * 1024 // maximum block size OREAD = plan9.OREAD // open for read OWRITE = plan9.OWRITE // open for write ORDWR = plan9.ORDWR // open for read/write OEXEC = plan9.OEXEC // read but check execute permission OTRUNC = plan9.OTRUNC // truncate file first ORCLOSE = plan9.ORCLOSE // remove on close OEXCL = plan9.OEXCL // exclusive use OAPPEND = plan9.OAPPEND // append only QTDIR = plan9.QTDIR // type bit for directories QTAPPEND = plan9.QTAPPEND // type bit for append only files QTEXCL = plan9.QTEXCL // type bit for exclusive use files QTAUTH = plan9.QTAUTH // type bit for authentication file QTTMP = plan9.QTTMP // type bit for non-backed-up file QTFILE = plan9.QTFILE // type bits for plain file DMDIR = plan9.DMDIR // mode bit for directories DMAPPEND = plan9.DMAPPEND // mode bit for append only files DMEXCL = plan9.DMEXCL // mode bit for exclusive use files DMAUTH = plan9.DMAUTH // mode bit for authentication file DMTMP = plan9.DMTMP // mode bit for non-backed-up file DMREAD = plan9.DMREAD // mode bit for read permission DMWRITE = plan9.DMWRITE // mode bit for write permission DMEXEC = plan9.DMEXEC // mode bit for execute permission )
RamFS constants and limits.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FS ¶
type FS struct { Log LogFunc // contains filtered or unexported fields }
FS represents a a 9P2000 file server.
func New ¶
New starts a 9P2000 file server keeping all files in memory. The filesystem is entirely maintained in memory, no external storage is used. File data is allocated in 128 * 1024 byte blocks.
The root of the filesystem is owned by the user who invoked ramfs and is created with Read, Write and Execute permissions for the owner and Read and Execute permissions for everyone else (0755). FS create the necessary directories and files in /adm/ctl, /adm/group and /<hostowner>.
func (*FS) Attach ¶
Attach identifies the user and may select the file tree to access. As a result of the attach transaction, the client will have a connection to the root directory of the desired file tree, represented by Fid.
func (*FS) Create ¶
Create asks the file server to create a new file with the name supplied, in the directory represented by fid, and requires write permission in the directory. The owner of the file is the implied user id of the request, the group of the file is the same as dir, and the permissions are the value of
perm = (perm &^ 0666) | (dir.Mode & 0666)
if a regular file is being created and
perm = (perm &^ 0777) | (dir.Mode & 0777)
if a directory is being created.
Finally, the newly created file is opened according to mode, and fid will represent the newly opened file. Directories are created by setting the DMDIR bit (0x80000000) in the perm.
The names . and .. are special; it is illegal to create files with these names.
func (*FS) Open ¶
Open asks the file server to check permissions and prepare a fid for I/O with subsequent read and write messages. The mode field determines the type of I/O: OREAD, OWRITE, ORDWR, and OEXEC mean read access, write access, read and write access, and execute access, to be checked against the permissions for the file.
In addition, if mode has the OTRUNC bit set, the file is to be truncated, which requires write permission (if the file is append–only, and permission is granted, the open succeeds but the file will not be truncated); if the mode has the ORCLOSE bit set, the file is to be removed when the fid is clunked, which requires permission to remove the file from its directory.
It is illegal to write a directory, truncate it, or attempt to remove it on close. If the file is marked for exclusive use, only one client can have the file open at any time.
type Fid ¶
type Fid struct { New *Fid // contains filtered or unexported fields }
The Fid type identifies a file on the file server. A new Fid is created when the user attaches to the file server, or when Walk-ing to a file. The Fid values are created automatically by the ramfs implementation.
func (*Fid) Close ¶
Close informs the file server that the current file represented by fid is no longer needed by the client.
func (*Fid) Create ¶
Create asks the file server to create a new file with the name supplied, in the directory represented by fid, and requires write permission in the directory. The owner of the file is the implied user id of the request, the group of the file is the same as dir, and the permissions are the value of
perm = (perm &^ 0666) | (dir.Mode & 0666)
if a regular file is being created and
perm = (perm &^ 0777) | (dir.Mode & 0777)
if a directory is being created.
Finally, the newly created file is opened according to mode, and fid will represent the newly opened file. Directories are created by setting the DMDIR bit (0x80000000) in the perm.
The names . and .. are special; it is illegal to create files with these names.
func (*Fid) Open ¶
Open asks the file server to check permissions and prepare a fid for I/O with subsequent read and write messages. The mode field determines the type of I/O: OREAD, OWRITE, ORDWR, and OEXEC mean read access, write access, read and write access, and execute access, to be checked against the permissions for the file.
In addition, if mode has the OTRUNC bit set, the file is to be truncated, which requires write permission (if the file is append–only, and permission is granted, the open succeeds but the file will not be truncated); if the mode has the ORCLOSE bit set, the file is to be removed when the fid is clunked, which requires permission to remove the file from its directory.
It is illegal to write a directory, truncate it, or attempt to remove it on close. If the file is marked for exclusive use, only one client can have the file open at any time.
func (*Fid) ReadAt ¶
ReadAt asks for len(p) bytes of data from the file identified by fid, which must be opened for reading, starting offset bytes after the beginning of the file.
For directories, ReadAt returns an integral number of directory entries exactly as in stat, one for each member of the directory.
func (*Fid) Remove ¶
Remove asks the file server both to remove the file represented by fid and to clunk the fid, even if the remove fails.
func (*Fid) Stat ¶
Stat inquires about the file identified by fid. The reply will contain a machine-independent directory entry
func (*Fid) WriteAt ¶
WriteAt asks that len(p) bytes of data be recorded in the file identified by fid, which must be opened for writing, starting offset bytes after the beginning of the file. If the file is append–only, the data will be placed at the end of the file regardless of offset. Directories may not be written.
WriteAt records the number of bytes actually written. It is usually an error if this is not the same as requested.
func (*Fid) Wstat ¶
Wstat can change some of the file status information. The name can be changed by anyone with write permission in the parent directory; it is an error to change the name to that of an existing file.
The mode can be changed by the owner of the file or the group leader of the file's current group. The directory bit cannot be changed by a wstat; the other defined permission and mode bits can. The gid can be changed: by the owner if also a member of the new group; or by the group leader of the file's current group if also leader of the new group.
Either all the changes in Wstat request happen, or none of them does: if the request succeeds, all changes were made; if it fails, none were.
type LogFunc ¶
type LogFunc func(format string, v ...interface{})
LogFunc can be used to enable a trace of general debugging messages.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
racon
Usage: racon [options] cmd [option] args...
|
Usage: racon [options] cmd [option] args... |
ramfs
Usage: ramfs [options] Ramfs starts a 9P2000 file server keeping all files in memory.
|
Usage: ramfs [options] Ramfs starts a 9P2000 file server keeping all files in memory. |