plan9

package
v0.0.0-...-278237d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2015 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Tversion = 100 + iota
	Rversion
	Tauth
	Rauth
	Tattach
	Rattach
	Terror
	Rerror
	Tflush
	Rflush
	Twalk
	Rwalk
	Topen
	Ropen
	Tcreate
	Rcreate
	Tread
	Rread
	Twrite
	Rwrite
	Tclunk
	Rclunk
	Tremove
	Rremove
	Tstat
	Rstat
	Twstat
	Rwstat
	Tlast
)

9P2000 message types

View Source
const (
	MSIZE   = 8192 + IOHDRSZ // default message size (8192+IOHdrSz)
	IOHDRSZ = 24             // the non-data size of the Twrite messages
	PORT    = 564            // default port for 9P file servers
)
View Source
const (
	QTDIR     = 0x80 // directories
	QTAPPEND  = 0x40 // append only files
	QTEXCL    = 0x20 // exclusive use files
	QTMOUNT   = 0x10 // mounted channel
	QTAUTH    = 0x08 // authentication file
	QTTMP     = 0x04 // non-backed-up file
	QTSYMLINK = 0x02 // symbolic link (Unix, 9P2000.u)
	QTLINK    = 0x01 // hard link (Unix, 9P2000.u)
	QTFILE    = 0x00
)

Qid types

View Source
const (
	OREAD   = 0  // open read-only
	OWRITE  = 1  // open write-only
	ORDWR   = 2  // open read-write
	OEXEC   = 3  // execute (== read but check execute permission)
	OTRUNC  = 16 // or'ed in (except for exec), truncate file first
	OCEXEC  = 32 // or'ed in, close on exec
	ORCLOSE = 64 // or'ed in, remove on close
)

Flags for the mode field in Topen and Tcreate messages

View Source
const (
	DMDIR       = 0x80000000 // mode bit for directories
	DMAPPEND    = 0x40000000 // mode bit for append only files
	DMEXCL      = 0x20000000 // mode bit for exclusive use files
	DMMOUNT     = 0x10000000 // mode bit for mounted channel
	DMAUTH      = 0x08000000 // mode bit for authentication file
	DMTMP       = 0x04000000 // mode bit for non-backed-up file
	DMSYMLINK   = 0x02000000 // mode bit for symbolic link (Unix, 9P2000.u)
	DMLINK      = 0x01000000 // mode bit for hard link (Unix, 9P2000.u)
	DMDEVICE    = 0x00800000 // mode bit for device file (Unix, 9P2000.u)
	DMNAMEDPIPE = 0x00200000 // mode bit for named pipe (Unix, 9P2000.u)
	DMSOCKET    = 0x00100000 // mode bit for socket (Unix, 9P2000.u)
	DMSETUID    = 0x00080000 // mode bit for setuid (Unix, 9P2000.u)
	DMSETGID    = 0x00040000 // mode bit for setgid (Unix, 9P2000.u)
	DMREAD      = 0x4        // mode bit for read permission
	DMWRITE     = 0x2        // mode bit for write permission
	DMEXEC      = 0x1        // mode bit for execute permission
)

File modes

View Source
const (
	NOTAG uint16 = 0xFFFF     // no tag specified
	NOFID uint32 = 0xFFFFFFFF // no fid specified
	NOUID uint32 = 0xFFFFFFFF // no uid specified
)
View Source
const (
	EPERM   = 1
	ENOENT  = 2
	EIO     = 5
	EEXIST  = 17
	ENOTDIR = 20
	EINVAL  = 22
)

Error values

Variables

View Source
var BufferInsufficient = errors.New("insufficient buffer?")

Global errors.

View Source
var Ebadoffset error = &Error{"bad offset in directory read", EINVAL}
View Source
var Ebaduse error = &Error{"bad use of fid", EINVAL}
View Source
var Edirchange error = &Error{"cannot convert between files and directories", EINVAL}
View Source
var Eexist = &Error{"file already exists", EEXIST}
View Source
var Einuse error = &Error{"fid already in use", EINVAL}
View Source
var Enoauth error = &Error{"no authentication required", EINVAL}
View Source
var Enoent = &Error{"file not found", ENOENT}
View Source
var Enotdir error = &Error{"not a directory", ENOTDIR}
View Source
var Enotempty = &Error{"directory not empty", EPERM}
View Source
var Enotimpl error = &Error{"not implemented", EINVAL}
View Source
var Enouser error = &Error{"unknown user", EINVAL}
View Source
var Eopen error = &Error{"fid already opened", EINVAL}
View Source
var Eperm error = &Error{"permission denied", EPERM}
View Source
var Etoolarge error = &Error{"i/o count too large", EINVAL}
View Source
var Eunknownfid error = &Error{"unknown fid", EINVAL}

Internal errors.

View Source
var InvalidMessage = errors.New("invalid 9pfs message?")
View Source
var P9ModeToMode = map[uint32]uint32{
	DMDIR:          syscall.S_IFDIR,
	DMSYMLINK:      syscall.S_IFLNK,
	DMSOCKET:       syscall.S_IFSOCK,
	DMDEVICE:       syscall.S_IFCHR,
	DMSETUID:       syscall.S_ISUID,
	DMSETGID:       syscall.S_ISGID,
	(DMREAD << 6):  syscall.S_IRUSR,
	(DMWRITE << 6): syscall.S_IWUSR,
	(DMEXEC << 6):  syscall.S_IXUSR,
	(DMREAD << 3):  syscall.S_IRGRP,
	(DMWRITE << 3): syscall.S_IWGRP,
	(DMEXEC << 3):  syscall.S_IXGRP,
	DMREAD:         syscall.S_IROTH,
	DMWRITE:        syscall.S_IWOTH,
	DMEXEC:         syscall.S_IXOTH,
}
View Source
var P9TypeToMode = map[uint8]uint32{
	QTDIR:     syscall.S_IFDIR,
	QTSYMLINK: syscall.S_IFLNK,
}
View Source
var XattrError = errors.New("unable to fetch xattr?")

Functions

func PackRattach

func PackRattach(
	buf Buffer,
	tag uint16,
	aqid *Qid) error

func PackRauth

func PackRauth(
	buf Buffer,
	tag uint16,
	aqid *Qid) error

func PackRclunk

func PackRclunk(
	buf Buffer,
	tag uint16) error

func PackRcreate

func PackRcreate(
	buf Buffer,
	tag uint16,
	qid *Qid,
	iounit uint32) error

func PackRerror

func PackRerror(
	buf Buffer,
	tag uint16,
	error string,
	errornum uint32,
	dotu bool) error

func PackRflush

func PackRflush(
	buf Buffer,
	tag uint16) error

func PackRopen

func PackRopen(
	buf Buffer,
	tag uint16,
	qid *Qid,
	iounit uint32) error

func PackRread

func PackRread(
	buf Buffer,
	tag uint16,
	count uint32) error

func PackRremove

func PackRremove(
	buf Buffer,
	tag uint16) error

func PackRstat

func PackRstat(
	buf Buffer,
	tag uint16,
	d *Dir,
	dotu bool) error

func PackRversion

func PackRversion(
	buf Buffer,
	tag uint16,
	msize uint32,
	version string) error

func PackRwalk

func PackRwalk(
	buf Buffer,
	tag uint16,
	wqids []Qid) error

func PackRwrite

func PackRwrite(
	buf Buffer,
	tag uint16,
	count uint32) error

func PackRwstat

func PackRwstat(
	buf Buffer,
	tag uint16) error

Types

type Buffer

type Buffer interface {
	ReadLeft() int
	WriteLeft() int

	ReadRewind()
	WriteRewind()

	Read8() uint8
	Read16() uint16
	Read32() uint32
	Read64() uint64
	ReadBytes(length int) []byte
	ReadString() string

	Write8(value uint8)
	Write16(value uint16)
	Write32(value uint32)
	Write64(value uint64)
	WriteBytes(value []byte)
	WriteString(value string)

	ReadFromFd(fd int, offset int64, length int) (int, error)
	WriteToFd(fd int, offset int64, length int) (int, error)
}

type Dir

type Dir struct {
	Type   uint16
	Dev    uint32
	Qid           // file's Qid
	Mode   uint32 // permissions and flags
	Atime  uint32 // last access time in seconds
	Mtime  uint32 // last modified time in seconds
	Length uint64 // file length in bytes
	Name   string // file name
	Uid    string // owner name
	Gid    string // group name
	Muid   string // name of the last user that modified the file

	// 9P2000.u extension
	Ext     string // special file's descriptor
	Uidnum  uint32 // owner ID
	Gidnum  uint32 // group ID
	Muidnum uint32 // ID of the last user that modified the file
}

Dir describes a file.

func (*Dir) String

func (d *Dir) String() string

type Error

type Error struct {
	Err      string // textual representation of the error
	Errornum uint32 // numeric representation of the error (9P2000.u)
}

Error represents a 9P2000 (and 9P2000.u) error.

func (*Error) Error

func (err *Error) Error() string

type Fcall

type Fcall struct {
	Size    uint32   // size of the message
	Type    uint8    // message type
	Fid     uint32   // file identifier
	Tag     uint16   // message tag
	Msize   uint32   // maximum message size (used by Tversion, Rversion)
	Version string   // protocol version (used by Tversion, Rversion)
	Oldtag  uint16   // tag of the message to flush (used by Tflush)
	Error   string   // error (used by Rerror)
	Qid              // file Qid (used by Rauth, Rattach, Ropen, Rcreate)
	Iounit  uint32   // maximum bytes read without breaking in multiple messages (used by Ropen, Rcreate)
	Afid    uint32   // authentication fid (used by Tauth, Tattach)
	Uname   string   // user name (used by Tauth, Tattach)
	Aname   string   // attach name (used by Tauth, Tattach)
	Perm    uint32   // file permission (mode) (used by Tcreate)
	Name    string   // file name (used by Tcreate)
	Mode    uint8    // open mode (used by Topen, Tcreate)
	Newfid  uint32   // the fid that represents the file walked to (used by Twalk)
	Wname   []string // list of names to walk (used by Twalk)
	Wqid    []Qid    // list of Qids for the walked files (used by Rwalk)
	Offset  uint64   // offset in the file to read/write from/to (used by Tread, Twrite)
	Count   uint32   // number of bytes read/written (used by Tread, Rread, Twrite, Rwrite)
	Dir              // file description (used by Rstat, Twstat)

	/* 9P2000.u extensions */
	Errornum uint32 // error code, 9P2000.u only (used by Rerror)
	Ext      string // special file description, 9P2000.u only (used by Tcreate)
	Unamenum uint32 // user ID, 9P2000.u only (used by Tauth, Tattach)
}

Fcall represents a 9P2000 message.

func Unpack

func Unpack(
	buf Buffer,
	dotu bool) (*Fcall, error)

Creates a Fcall value from the on-the-wire representation. If dotu is true, reads 9P2000.u messages. Returns the unpacked message, error and how many bytes from the buffer were used by the message.

func (*Fcall) String

func (fc *Fcall) String() string

type Fid

type Fid struct {
	// The associated Fid.
	Fid uint32 `json:"fid"`

	// The associated path.
	Path string `json:"path"`

	// True if the Fid is opened.
	Opened bool `json:"opened"`

	// Open mode (O* flags).
	Omode uint8 `json:"omode"`

	// If directory, next valid read position.
	Diroffset uint64 `json:"diroffset"`

	// If directory, list of children (reset by read(offset=0).
	Direntries []*Dir `json:"direntries"`
	// contains filtered or unexported fields
}

func (*Fid) DecRef

func (fid *Fid) DecRef(fs *Fs)

type Fidpool

type Fidpool map[uint32]*Fid

Our collection of Fids.

This is a special type to handle marshal/unmarshal.

func (*Fidpool) MarshalJSON

func (fidpool *Fidpool) MarshalJSON() ([]byte, error)

func (*Fidpool) UnmarshalJSON

func (fidpool *Fidpool) UnmarshalJSON(data []byte) error

type File

type File struct {

	// File identifier.
	Qid

	// Our RWMutex (protects r=>w transition).
	sync.RWMutex
	// contains filtered or unexported fields
}

func (*File) DecRef

func (file *File) DecRef(fs *Fs, path string)

func (*File) IncRef

func (file *File) IncRef(fs *Fs)

type Fs

type Fs struct {

	// The read mappings.
	Read map[string][]string `json:"read"`

	// The write mappings.
	Write map[string]string `json:"write"`

	// are we speaking 9P2000.u?
	Dotu bool `json:"dotu"`

	// open FiDs.
	Pool Fidpool `json:"pool"`

	// requests outstanding.
	Reqs Reqlist `json"reqs"`

	// Our next fileid.
	Fileid uint64 `json:"fileid"`

	// Our file descriptor limits.
	Fdlimit uint `json:"fdlimit"`
	// contains filtered or unexported fields
}

Filesystem state.

func (*Fs) Attach

func (fs *Fs) Attach() error

func (*Fs) GetFid

func (fs *Fs) GetFid(fidno uint32) *Fid

func (*Fs) Handle

func (fs *Fs) Handle(req Buffer, resp Buffer, debug bool) error

func (*Fs) Init

func (fs *Fs) Init() error

func (*Fs) NewFid

func (fs *Fs) NewFid(
	fidno uint32,
	path string,
	file *File) (*Fid, error)

func (*Fs) NewFile

func (fs *Fs) NewFile(path string) (*File, error)

type Qid

type Qid struct {
	Type    uint8  // type of the file (high 8 bits of the mode)
	Version uint32 // version number for the path
	Path    uint64 // server's unique identification of the file
}

File identifier.

func (*Qid) String

func (qid *Qid) String() string

type Reqlist

type Reqlist map[uint16]bool

Outstanding request list.

func (*Reqlist) MarshalJSON

func (reqs *Reqlist) MarshalJSON() ([]byte, error)

func (*Reqlist) UnmarshalJSON

func (reqs *Reqlist) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL