go9p

package module
v1.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2021 License: MIT Imports: 13 Imported by: 12

README

go9p

This is an implementation of the 9p2000 protocol in Go.

There are a couple of packages here.

github.com/knusbaum/go9p just contains an interface definition for a 9p2000 server, Srv. along with a few functions that will serve the 9p2000 protocol using a Srv.

github.com/knusbaum/go9p/proto is the protocol implementation. It is used by the other packages to send and receive 9p2000 messages. It may be useful to someone who wants to investigate 9p2000 at the protocol level.

github.com/knusbaum/go9p/fs is an package that implements a hierarchical filesystem as a struct, FS. An FS contains a hierarchy of Dirs and Files. The package also contains other types and functions useful for building 9p filesystems.

Examples are available in examples/

This library has been tested on Plan 9 and Linux.

Programs serving 9p2000 can be mounted on Unix with plan9port's 9pfuse (or some equivalent) https://github.com/9fans/plan9port

This repository now also offers the mount9p and export9p programs. mount9p replaces plan9port's 9pfuse and export9p will export part of a local namespace via 9p.

For example, you would mount the ramfs example with the following command:

9pfuse localhost:9999 /mnt/myramfs

Then you can copy files to/from the ramfs and do all the other stuff that you'd expect.

This is distributed under the MIT license

    Copyright (c) 2016-Present Kyle Nusbaum


    Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is furnished
    to do so, subject to the following conditions:

    The above copyright notice and this permission notice shall be included in all
    copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
    FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
    COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
    AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Overview

Package go9p contains contains an interface definition for a 9p2000 server, `Srv`. along with a few functions that will serve the 9p2000 protocol using a `Srv`.

Most people wanting to implement a 9p filesystem should start in the subpackage github.com/knusbaum/go9p/fs, which contains tools for constructing a file system which can be served using the functions in this package.

The subpackage github.com/knusbaum/go9p/proto contains the protocol implementation. It is used by the other packages to send and receive 9p2000 messages. It may be useful to someone who wants to investigate 9p2000 at the protocol level.

Index

Constants

This section is empty.

Variables

View Source
var Verbose bool

If Verbose is true, incoming and outgoing 9p messages will be printed to stderr.

Functions

func PostSrv added in v0.19.0

func PostSrv(name string, srv Srv) error

PostSrv serves srv, from a file descriptor named name. The fd is posted and can subsequently be mounted. On Unix, the descriptor is posted under in the current namespace, which is determined by 9fans.net/go/plan9/client Namespace. On Plan9 it is posted in the usual place, /srv.

func Serve added in v0.19.0

func Serve(addr string, srv Srv) error

Serve serves srv on the given address, addr.

func ServeReadWriter added in v0.19.0

func ServeReadWriter(r io.Reader, w io.Writer, srv Srv) error

ServeReadWriter accepts an io.Reader an io.Writer, and an Srv. It reads 9p2000 messages from r, handles them with srv, and writes the responses to w.

Types

type Conn added in v0.19.0

type Conn interface {
	TagContext(uint16) context.Context
	DropContext(uint16)
}

Conn represents an individual connection to a 9p server. In the case of a server listening on a network, there may be many clients connected to a given server at once.

type Srv added in v0.19.0

type Srv interface {
	NewConn() Conn
	Version(Conn, *proto.TRVersion) (proto.FCall, error)
	Auth(Conn, *proto.TAuth) (proto.FCall, error)
	Attach(Conn, *proto.TAttach) (proto.FCall, error)
	Walk(Conn, *proto.TWalk) (proto.FCall, error)
	Open(Conn, *proto.TOpen) (proto.FCall, error)
	Create(Conn, *proto.TCreate) (proto.FCall, error)
	Read(Conn, *proto.TRead) (proto.FCall, error)
	Write(Conn, *proto.TWrite) (proto.FCall, error)
	Clunk(Conn, *proto.TClunk) (proto.FCall, error)
	Remove(Conn, *proto.TRemove) (proto.FCall, error)
	Stat(Conn, *proto.TStat) (proto.FCall, error)
	Wstat(Conn, *proto.TWstat) (proto.FCall, error)
}

The Srv interface is used to handle 9p2000 messages. Each function handles a specific type of message, and should return a response. If some expected error occurs, for example a TOpen message for a file with the wrong permissions, a proto.TError message should be returned rather than a go error. Returning a go error indicates that something has gone wrong with the server, and when used with Serve and PostSrv, will cause the connection to be terminated or the file descriptor to be closed.

Directories

Path Synopsis
cmd
examples
utilfs
This is a sample filesystem that serves a couple "utilities" There's /time, which when read, will return a human-readable string of the current time.
This is a sample filesystem that serves a couple "utilities" There's /time, which when read, will return a human-readable string of the current time.
fs
Package fs is an package that implements a hierarchical filesystem as a struct, FS.
Package fs is an package that implements a hierarchical filesystem as a struct, FS.
Package proto implements the 9p2000 protocol messages and the code required to marshal the messages.
Package proto implements the 9p2000 protocol messages and the code required to marshal the messages.

Jump to

Keyboard shortcuts

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