Documentation ¶
Overview ¶
The srv package provides definitions and functions used to implement a 9P2000 file server.
Index ¶
- Constants
- Variables
- type AuthOps
- type Conn
- type ConnOps
- type FClunkOp
- type FCreateOp
- type FDestroyOp
- type FFid
- type FFlags
- type FOpenOp
- type FReadOp
- type FRemoveOp
- type FStatOp
- type FWriteOp
- type FWstatOp
- type Fid
- type FidOps
- type File
- type FlushOp
- type Fsrv
- func (s *Fsrv) Attach(req *Req)
- func (*Fsrv) Clunk(req *Req)
- func (*Fsrv) Create(req *Req)
- func (*Fsrv) FidDestroy(ffid *Fid)
- func (*Fsrv) Open(req *Req)
- func (*Fsrv) Read(req *Req)
- func (*Fsrv) Remove(req *Req)
- func (*Fsrv) Stat(req *Req)
- func (*Fsrv) Walk(req *Req)
- func (*Fsrv) Write(req *Req)
- func (*Fsrv) Wstat(req *Req)
- type Req
- func (req *Req) Flush()
- func (req *Req) PostProcess()
- func (req *Req) Process()
- func (req *Req) Respond()
- func (req *Req) RespondError(err interface{})
- func (req *Req) RespondRattach(aqid *p.Qid)
- func (req *Req) RespondRauth(aqid *p.Qid)
- func (req *Req) RespondRclunk()
- func (req *Req) RespondRcreate(qid *p.Qid, iounit uint32)
- func (req *Req) RespondRflush()
- func (req *Req) RespondRopen(qid *p.Qid, iounit uint32)
- func (req *Req) RespondRread(data []byte)
- func (req *Req) RespondRremove()
- func (req *Req) RespondRstat(st *p.Dir)
- func (req *Req) RespondRversion(msize uint32, version string)
- func (req *Req) RespondRwalk(wqids []p.Qid)
- func (req *Req) RespondRwrite(count uint32)
- func (req *Req) RespondRwstat()
- type ReqOps
- type ReqProcessOps
- type Srv
- type StatsOps
Constants ¶
const ( DbgPrintFcalls = (1 << iota) // print all 9P messages on stderr DbgPrintPackets // print the raw packets on stderr DbgLogFcalls // keep the last N 9P messages (can be accessed over http) DbgLogPackets // keep the last N 9P messages (can be accessed over http) )
Debug flags
Variables ¶
var Edirchange error = &p.Error{"cannot convert between files and directories", p.EINVAL}
var Eexist = &p.Error{"file already exists", p.EEXIST}
var Enoent = &p.Error{"file not found", p.ENOENT}
var Enotempty = &p.Error{"directory not empty", p.EPERM}
Functions ¶
This section is empty.
Types ¶
type AuthOps ¶
type AuthOps interface { // AuthInit is called when the user starts the authentication // process on Fid afid. The user that is being authenticated // is referred by afid.User. The function should return the Qid // for the authentication file, or an Error if the user can't be // authenticated AuthInit(afid *Fid, aname string) (*p.Qid, error) // AuthDestroy is called when an authentication fid is destroyed. AuthDestroy(afid *Fid) // AuthCheck is called after the authentication process is finished // when the user tries to attach to the file server. If the function // returns nil, the authentication was successful and the user has // permission to access the files. AuthCheck(fid *Fid, afid *Fid, aname string) error // AuthRead is called when the user attempts to read data from an // authentication fid. AuthRead(afid *Fid, offset uint64, data []byte) (count int, err error) // AuthWrite is called when the user attempts to write data to an // authentication fid. AuthWrite(afid *Fid, offset uint64, data []byte) (count int, err error) }
Authentication operations. The file server should implement them if it requires user authentication. The authentication in 9P2000 is done by creating special authentication fids and performing I/O operations on them. Once the authentication is done, the authentication fid can be used by the user to get access to the actual files.
type Conn ¶
type Conn struct { sync.Mutex Srv *Srv Msize uint32 // maximum size of 9P2000 messages for the connection Dotu bool // if true, both the client and the server speak 9P2000.u Id string // used for debugging and stats Debuglevel int // contains filtered or unexported fields }
The Conn type represents a connection from a client to the file server
func (*Conn) FidGet ¶
Lookup a Fid struct based on the 32-bit identifier sent over the wire. Returns nil if the fid is not found. Increases the reference count of the returned fid. The user is responsible to call DecRef once it no longer needs it.
func (*Conn) FidNew ¶
Creates a new Fid struct for the fidno integer. Returns nil if the Fid for that number already exists. The returned fid has reference count set to 1.
func (*Conn) RemoteAddr ¶
type ConnOps ¶
Connection operations. These should be implemented if the file server needs to be called when a connection is opened or closed.
type FCreateOp ¶
If the FCreateOp interface is implemented, the Create operation will be called when the client attempts to create a file in the File implementing the interface. If not implemented, "permission denied" error will be send back. If successful, the operation should call (*File)Add() to add the created file to the directory. The operation returns the created file, or the error occured while creating it.
type FDestroyOp ¶
type FDestroyOp interface {
FidDestroy(fid *FFid)
}
type FReadOp ¶
If the FReadOp interface is implemented, the Read operation will be called to read from the file. If not implemented, "permission denied" error will be send back. The operation returns the number of bytes read, or the error occured while reading.
type FRemoveOp ¶
If the FRemoveOp interface is implemented, the Remove operation will be called when the client attempts to create a file in the File implementing the interface. If not implemented, "permission denied" error will be send back. The operation returns nil if successful, or the error that occured while removing the file.
type FStatOp ¶
The FStatOp interface provides a single operation (Stat) that will be called before a file stat is sent back to the client. If implemented, the operation should update the data in the File struct.
type FWriteOp ¶
If the FWriteOp interface is implemented, the Write operation will be called to write to the file. If not implemented, "permission denied" error will be send back. The operation returns the number of bytes written, or the error occured while writing.
type FWstatOp ¶
The FWstatOp interface provides a single operation (Wstat) that will be called when the client requests the File metadata to be modified. If implemented, the operation will be called when Twstat message is received. If not implemented, "permission denied" error will be sent back. If the operation returns an Error, the error is send back to the client.
type Fid ¶
type Fid struct { sync.Mutex Fconn *Conn // Connection the Fid belongs to Omode uint8 // Open mode (p.O* flags), if the fid is opened Type uint8 // Fid type (p.QT* flags) Diroffset uint64 // If directory, the next valid read position User p.User // The Fid's user Aux interface{} // Can be used by the file server implementation for per-Fid data // 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 (the Attach operation), or when Walk-ing to a file. The Fid values are created automatically by the srv implementation. The FidDestroy operation is called when a Fid is destroyed.
type FidOps ¶
type FidOps interface {
FidDestroy(*Fid)
}
Fid operations. This interface should be implemented if the file server needs to be called when a Fid is destroyed.
type File ¶
type File struct { sync.Mutex p.Dir Parent *File // parent Ops interface{} // contains filtered or unexported fields }
The File type represents a file (or directory) served by the file server.
func (*File) Add ¶
func (f *File) Add(dir *File, name string, uid p.User, gid p.Group, mode uint32, ops interface{}) error
Initializes the fields of a file and add it to a directory. Returns nil if successful, or an error.
func (*File) CheckPerm ¶
Checks if the specified user has permission to perform certain operation on a file. Perm contains one or more of p.DMREAD, p.DMWRITE, and p.DMEXEC.
type FlushOp ¶
type FlushOp interface {
Flush(*Req)
}
Flush operation. This interface should be implemented if the file server can flush pending requests. If the interface is not implemented, requests that were passed to the file server implementation won't be flushed. The flush method should call the (req *Req) srv.Flush() method if the flush was successful so the request can be marked appropriately.
type Fsrv ¶
The Fsrv can be used to create file servers that serve simple trees of synthetic files.
func NewFileSrv ¶
Creates a file server with root as root directory
func (*Fsrv) FidDestroy ¶
type Req ¶
type Req struct { sync.Mutex Tc *p.Fcall // Incoming 9P2000 message Rc *p.Fcall // Outgoing 9P2000 response Fid *Fid // The Fid value for all messages that contain fid[4] Afid *Fid // The Fid value for the messages that contain afid[4] (Tauth and Tattach) Newfid *Fid // The Fid value for the messages that contain newfid[4] (Twalk) Conn *Conn // Connection that the request belongs to // contains filtered or unexported fields }
The Req type represents a 9P2000 request. Each request has a T-message (Tc) and a R-message (Rc). If the ReqProcessOps don't override the default behavior, the implementation initializes Fid, Afid and Newfid values and automatically keeps track on when the Fids should be destroyed.
func (*Req) Flush ¶
func (req *Req) Flush()
Should be called to cancel a request. Should only be called from the Flush operation if the FlushOp is implemented.
func (*Req) PostProcess ¶
func (req *Req) PostProcess()
Performs the post processing required if the (*Req) Process() method is called for a request. The file server implementer should call it only if the file server implements the ReqProcessOps within the ReqRespond operation.
func (*Req) Process ¶
func (req *Req) Process()
Performs the default processing of a request. Initializes the Fid, Afid and Newfid fields and calls the appropriate ReqOps operation for the message. The file server implementer should call it only if the file server implements the ReqProcessOps within the ReqProcess operation.
func (*Req) Respond ¶
func (req *Req) Respond()
The Respond method sends response back to the client. The req.Rc value should be initialized and contain valid 9P2000 message. In most cases the file server implementer shouldn't call this method directly. Instead one of the RespondR* methods should be used.
func (*Req) RespondError ¶
func (req *Req) RespondError(err interface{})
Respond to the request with Rerror message
func (*Req) RespondRattach ¶
Respond to the request with Rattach message
func (*Req) RespondRauth ¶
Respond to the request with Rauth message
func (*Req) RespondRclunk ¶
func (req *Req) RespondRclunk()
Respond to the request with Rclunk message
func (*Req) RespondRcreate ¶
Respond to the request with Rcreate message
func (*Req) RespondRflush ¶
func (req *Req) RespondRflush()
Respond to the request with Rflush message
func (*Req) RespondRopen ¶
Respond to the request with Ropen message
func (*Req) RespondRread ¶
Respond to the request with Rread message
func (*Req) RespondRremove ¶
func (req *Req) RespondRremove()
Respond to the request with Rremove message
func (*Req) RespondRstat ¶
Respond to the request with Rstat message
func (*Req) RespondRversion ¶
Respond to the request with Rversion message
func (*Req) RespondRwalk ¶
Respond to the request with Rwalk message
func (*Req) RespondRwrite ¶
Respond to the request with Rwrite message
func (*Req) RespondRwstat ¶
func (req *Req) RespondRwstat()
Respond to the request with Rwstat message
type ReqOps ¶
type ReqOps interface { Attach(*Req) Walk(*Req) Open(*Req) Create(*Req) Read(*Req) Write(*Req) Clunk(*Req) Remove(*Req) Stat(*Req) Wstat(*Req) }
Request operations. This interface should be implemented by all file servers. The operations correspond directly to most of the 9P2000 message types.
type ReqProcessOps ¶
type ReqProcessOps interface { // Called when a new request is received from the client. If the // interface is not implemented, (req *Req) srv.Process() method is // called. If the interface is implemented, it is the user's // responsibility to call srv.Process. If srv.Process isn't called, // Fid, Afid and Newfid fields in Req are not set, and the ReqOps // methods are not called. ReqProcess(*Req) // Called when a request is responded, i.e. when (req *Req)srv.Respond() // is called and before the response is sent. If the interface is not // implemented, (req *Req) srv.PostProcess() method is called to finalize // the request. If the interface is implemented and ReqProcess calls // the srv.Process method, ReqRespond should call the srv.PostProcess // method. ReqRespond(*Req) }
Request operations. This interface should be implemented if the file server needs to bypass the default request process, or needs to perform certain operations before the (any) request is processed, or before (any) response sent back to the client.
type Srv ¶
type Srv struct { sync.Mutex Id string // Used for debugging and stats Msize uint32 // Maximum size of the 9P2000 messages supported by the server Dotu bool // If true, the server supports the 9P2000.u extension Debuglevel int // debug level Upool p.Users // Interface for finding users and groups known to the file server Maxpend int // Maximum pending outgoing requests Log *p.Logger // contains filtered or unexported fields }
The Srv type contains the basic fields used to control the 9P2000 file server. Each file server implementation should create a value of Srv type, initialize the values it cares about and pass the struct to the (Srv *) srv.Start(ops) method together with the object that implements the file server operations.
func (*Srv) Start ¶
The Start method should be called once the file server implementor initializes the Srv struct with the preferred values. It sets default values to the fields that are not initialized and creates the goroutines required for the server's operation. The method receives an empty interface value, ops, that should implement the interfaces the file server is interested in. Ops must implement the ReqOps interface.
func (*Srv) StartListener ¶
Start listening on the specified network and address for incoming connections. Once a connection is established, create a new Conn value, read messages from the socket, send them to the specified server, and send back responses received from the server.
func (*Srv) StartNetListener ¶
Directories ¶
Path | Synopsis |
---|---|
examples
|
|
tlsramfs
Listen on SSL connection, can be used as an example with p/clnt/examples/tls.go Sample certificate was copied from the Go source code
|
Listen on SSL connection, can be used as an example with p/clnt/examples/tls.go Sample certificate was copied from the Go source code |