ninep: github.com/lionkov/ninep/clnt Index | Files

package clnt

import "github.com/lionkov/ninep/clnt"

The clnt package provides definitions and functions used to implement a 9P2000 file client.

Index

Package Files

clnt.go close.go mount.go open.go pool.go read.go remove.go seek.go stat.go tag.go walk.go write.go

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 DefaultDebuglevel int
var DefaultLogger *ninep.Logger
var Eisdir = &ninep.Error{"file is a directory", ninep.EIO}
var Enegoff = &ninep.Error{"negative i/o offset", ninep.EIO}

type Clnt Uses

type Clnt struct {
    sync.Mutex
    Debuglevel int    // =0 don't print anything, >0 print Fcalls, >1 print raw packets
    Msize      uint32 // Maximum size of the 9P messages
    Dotu       bool   // If true, 9P2000.u protocol is spoken
    Root       *Fid   // Fid that points to the rood directory
    Id         string // Used when printing debug messages
    Log        *ninep.Logger
    // contains filtered or unexported fields
}

The Clnt type represents a 9P2000 client. The client is connected to a 9P2000 file server and its methods can be used to access and manipulate the files exported by the server.

func Connect Uses

func Connect(c net.Conn, msize uint32, dotu bool) (*Clnt, error)

Establishes a new socket connection to the 9P server and creates a client object for it. Negotiates the dialect and msize for the connection. Returns a Clnt object, or Error.

func Mount Uses

func Mount(ntype, addr, aname string, msize uint32, user ninep.User) (*Clnt, error)

Connects to a file server and attaches to it as the specified user.

func MountConn Uses

func MountConn(c net.Conn, aname string, msize uint32, user ninep.User) (*Clnt, error)

func NewClnt Uses

func NewClnt(c net.Conn, msize uint32, dotu bool) *Clnt

Creates and initializes a new Clnt object. Doesn't send any data on the wire.

func (*Clnt) Attach Uses

func (clnt *Clnt) Attach(afid *Fid, user ninep.User, aname string) (*Fid, error)

Creates a fid for the specified user that points to the root of the file server's file tree. Returns a Fid pointing to the root, if successful, or an Error.

func (*Clnt) Auth Uses

func (clnt *Clnt) Auth(user ninep.User, aname string) (*Fid, error)

Creates an authentication fid for the specified user. Returns the fid, if successful, or an Error.

func (*Clnt) Clunk Uses

func (clnt *Clnt) Clunk(fid *Fid) (err error)

Clunks a fid. Returns nil if successful.

func (*Clnt) Create Uses

func (clnt *Clnt) Create(fid *Fid, name string, perm uint32, mode uint8, ext string) error

Creates a file in the directory associated with the fid. Returns nil if the operation is successful.

func (*Clnt) FCreate Uses

func (clnt *Clnt) FCreate(path string, perm uint32, mode uint8) (*File, error)

Creates and opens a named file. Returns the file if the operation is successful, or an Error.

func (*Clnt) FOpen Uses

func (clnt *Clnt) FOpen(path string, mode uint8) (*File, error)

Opens a named file. Returns the opened file, or an Error.

func (*Clnt) FRemove Uses

func (clnt *Clnt) FRemove(path string) error

Removes the named file. Returns nil if the operation is successful.

func (*Clnt) FStat Uses

func (clnt *Clnt) FStat(path string) (*ninep.Dir, error)

Returns the metadata for a named file, or an Error.

func (*Clnt) FSync Uses

func (clnt *Clnt) FSync(fid *Fid) error

FSync syncs the file for a fid. It does this by sending a NewWstatDir, i.e. a Dir with all fields set to 'not set'.

func (*Clnt) FWalk Uses

func (clnt *Clnt) FWalk(path string) (*Fid, error)

Walks to a named file. Returns a Fid associated with the file, or an Error.

func (*Clnt) FidAlloc Uses

func (clnt *Clnt) FidAlloc() *Fid

Creates a new Fid object for the client

func (*Clnt) FreeFcall Uses

func (clnt *Clnt) FreeFcall(fc *ninep.Fcall)

func (*Clnt) NewFcall Uses

func (clnt *Clnt) NewFcall() *ninep.Fcall

func (*Clnt) Open Uses

func (clnt *Clnt) Open(fid *Fid, mode uint8) error

Opens the file associated with the fid. Returns nil if the operation is successful.

func (*Clnt) Read Uses

func (clnt *Clnt) Read(fid *Fid, offset uint64, count uint32) ([]byte, error)

Reads count bytes starting from offset from the file associated with the fid. Returns a slice with the data read, if the operation was successful, or an Error.

func (*Clnt) Remove Uses

func (clnt *Clnt) Remove(fid *Fid) error

Removes the file associated with the Fid. Returns nil if the operation is successful.

func (*Clnt) Rename Uses

func (clnt *Clnt) Rename(fid *Fid, name string) error

Rename renames the file for a fid.

func (*Clnt) ReqAlloc Uses

func (clnt *Clnt) ReqAlloc() *Req

func (*Clnt) ReqFree Uses

func (clnt *Clnt) ReqFree(req *Req)

func (*Clnt) Rpc Uses

func (clnt *Clnt) Rpc(tc *ninep.Fcall) (rc *ninep.Fcall, err error)

func (*Clnt) Rpcnb Uses

func (clnt *Clnt) Rpcnb(r *Req) error

func (*Clnt) Stat Uses

func (clnt *Clnt) Stat(fid *Fid) (*ninep.Dir, error)

Returns the metadata for the file associated with the Fid, or an Error.

func (*Clnt) TagAlloc Uses

func (clnt *Clnt) TagAlloc(reqchan chan *Req) *Tag

func (*Clnt) TagFree Uses

func (clnt *Clnt) TagFree(tag *Tag)

func (*Clnt) Unmount Uses

func (clnt *Clnt) Unmount()

Closes the connection to the file sever.

func (*Clnt) Walk Uses

func (clnt *Clnt) Walk(fid *Fid, newfid *Fid, wnames []string) ([]ninep.Qid, error)

Starting from the file associated with fid, walks all wnames in sequence and associates the resulting file with newfid. If no wnames were walked successfully, an Error is returned. Otherwise a slice with a Qid for each walked name is returned.

func (*Clnt) Write Uses

func (clnt *Clnt) Write(fid *Fid, data []byte, offset uint64) (int, error)

Write up to len(data) bytes starting from offset. Returns the number of bytes written, or an Error.

func (*Clnt) Wstat Uses

func (clnt *Clnt) Wstat(fid *Fid, dir *ninep.Dir) error

Modifies the data of the file associated with the Fid, or an Error.

type ClntList Uses

type ClntList struct {
    sync.Mutex
    // contains filtered or unexported fields
}

type Fid Uses

type Fid struct {
    sync.Mutex
    Clnt       *Clnt // Client the fid belongs to
    Iounit     uint32
    ninep.Qid         // The Qid description for the file
    Mode       uint8  // Open mode (one of ninep.O* values) (if file is open)
    Fid        uint32 // Fid number
    ninep.User        // The user the fid belongs to
    // contains filtered or unexported fields
}

A Fid type represents a file on the server. Fids are used for the low level methods that correspond directly to the 9P2000 message requests

type File Uses

type File struct {
    // contains filtered or unexported fields
}

The file is similar to the Fid, but is used in the high-level client interface.

func NewFile Uses

func NewFile(f *Fid, offset uint64) *File

func (*File) Close Uses

func (file *File) Close() error

Closes a file. Returns nil if successful.

func (*File) Fid Uses

func (f *File) Fid() *Fid

func (*File) Read Uses

func (file *File) Read(buf []byte) (int, error)

Reads up to len(buf) bytes from the File. Returns the number of bytes read, or an Error.

func (*File) ReadAt Uses

func (file *File) ReadAt(buf []byte, offset int64) (int, error)

Reads up to len(buf) bytes from the file starting from offset. Returns the number of bytes read, or an Error.

func (*File) Readdir Uses

func (file *File) Readdir(num int) ([]*ninep.Dir, error)

Reads the content of the directory associated with the File. Returns an array of maximum num entries (if num is 0, returns all entries from the directory). If the operation fails, returns an Error.

func (*File) Readn Uses

func (file *File) Readn(buf []byte, offset uint64) (int, error)

Reads exactly len(buf) bytes from the File starting from offset. Returns the number of bytes read (could be less than len(buf) if end-of-file is reached), or an Error.

func (*File) Seek Uses

func (f *File) Seek(offset int64, whence int) (int64, error)

Seek sets the offset for the next Read or Write to offset, interpreted according to whence: 0 means relative to the origin of the file, 1 means relative to the current offset, and 2 means relative to the end. Seek returns the new offset and an error, if any.

Seeking to a negative offset is an error, and results in Enegoff. Seeking to 0 in a directory is only valid if whence is 0. Seek returns Eisdir otherwise.

func (*File) Write Uses

func (file *File) Write(buf []byte) (int, error)

Writes up to len(buf) bytes to a file. Returns the number of bytes written, or an Error.

func (*File) WriteAt Uses

func (file *File) WriteAt(buf []byte, offset int64) (int, error)

Writes up to len(buf) bytes starting from offset. Returns the number of bytes written, or an Error.

func (*File) Writen Uses

func (file *File) Writen(buf []byte, offset uint64) (int, error)

Writes exactly len(buf) bytes starting from offset. Returns the number of bytes written. If Error is returned the number of bytes can be less than len(buf).

type Req Uses

type Req struct {
    sync.Mutex
    Clnt *Clnt
    Tc   *ninep.Fcall
    Rc   *ninep.Fcall
    Err  error
    Done chan *Req
    Sent chan bool
    // contains filtered or unexported fields
}

type StatsOps Uses

type StatsOps interface {
    // contains filtered or unexported methods
}

type Tag Uses

type Tag struct {
    // contains filtered or unexported fields
}

func (*Tag) Attach Uses

func (tag *Tag) Attach(fid, afid *Fid, user ninep.User, aname string) error

func (*Tag) Auth Uses

func (tag *Tag) Auth(afid *Fid, user ninep.User, aname string) error

func (*Tag) Clunk Uses

func (tag *Tag) Clunk(fid *Fid) error

func (*Tag) Create Uses

func (tag *Tag) Create(fid *Fid, name string, perm uint32, mode uint8, ext string) error

func (*Tag) Open Uses

func (tag *Tag) Open(fid *Fid, mode uint8) error

func (*Tag) Read Uses

func (tag *Tag) Read(fid *Fid, offset uint64, count uint32) error

func (*Tag) Remove Uses

func (tag *Tag) Remove(fid *Fid) error

func (*Tag) ReqFree Uses

func (tag *Tag) ReqFree(r *Req)

func (*Tag) Stat Uses

func (tag *Tag) Stat(fid *Fid) error

func (*Tag) Walk Uses

func (tag *Tag) Walk(fid *Fid, newfid *Fid, wnames []string) error

func (*Tag) Write Uses

func (tag *Tag) Write(fid *Fid, data []byte, offset uint64) error

func (*Tag) Wstat Uses

func (tag *Tag) Wstat(fid *Fid, dir *ninep.Dir) error

Package clnt imports 8 packages (graph). Updated 2016-07-24. Refresh now. Tools for package owners. This is an inactive package (no imports and no commits in at least two years).