clnt

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2017 License: Apache-2.0, BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

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

Index

Constants

View Source
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

View Source
var DefaultDebuglevel int
View Source
var DefaultLogger *p.Logger
View Source
var Eisdir = &p.Error{"file is a directory", p.EIO}
View Source
var Enegoff = &p.Error{"negative i/o offset", p.EIO}

Functions

This section is empty.

Types

type Clnt

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        *p.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

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

func Mount(ntype, addr, aname string, user p.User) (*Clnt, error)

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

func MountConn

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

func NewClnt

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

func (clnt *Clnt) Attach(afid *Fid, user p.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

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

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

func (*Clnt) Clunk

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

Clunks a fid. Returns nil if successful.

func (*Clnt) Create

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

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

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

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

func (*Clnt) FRemove

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

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

func (*Clnt) FStat

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

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

func (*Clnt) FWalk

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

func (clnt *Clnt) FidAlloc() *Fid

Creates a new Fid object for the client

func (*Clnt) FreeFcall

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

func (*Clnt) NewFcall

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

func (*Clnt) Open

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

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

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

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

func (*Clnt) ReqAlloc

func (clnt *Clnt) ReqAlloc() *Req

func (*Clnt) ReqFree

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

func (*Clnt) Rpc

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

func (*Clnt) Rpcnb

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

func (*Clnt) Stat

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

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

func (*Clnt) TagAlloc

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

func (*Clnt) TagFree

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

func (*Clnt) Unmount

func (clnt *Clnt) Unmount()

Closes the connection to the file sever.

func (*Clnt) Walk

func (clnt *Clnt) Walk(fid *Fid, newfid *Fid, wnames []string) ([]p.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

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

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

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

type ClntList

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

type Fid

type Fid struct {
	sync.Mutex
	Clnt   *Clnt // Client the fid belongs to
	Iounit uint32
	p.Qid         // The Qid description for the file
	Mode   uint8  // Open mode (one of p.O* values) (if file is open)
	Fid    uint32 // Fid number
	p.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

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

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

func (*File) Close

func (file *File) Close() error

Closes a file. Returns nil if successful.

func (*File) Fid

func (f *File) Fid() *Fid

func (*File) Read

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

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

func (file *File) Readdir(num int) ([]*p.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

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

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

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

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

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

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

type StatsOps

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

type Tag

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

func (*Tag) Attach

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

func (*Tag) Auth

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

func (*Tag) Clunk

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

func (*Tag) Create

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

func (*Tag) Open

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

func (*Tag) Read

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

func (*Tag) Remove

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

func (*Tag) ReqFree

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

func (*Tag) Stat

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

func (*Tag) Walk

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

func (*Tag) Write

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

func (*Tag) Wstat

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

Directories

Path Synopsis
examples
cl
ls
tag
tls
Connects to a server over TLS and lists the specified directory
Connects to a server over TLS and lists the specified directory

Jump to

Keyboard shortcuts

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