p9

package
v0.0.0-...-604993b Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2023 License: ISC Imports: 27 Imported by: 0

Documentation

Overview

Package p9 implements file systems for the Plan 9 File Protocol.

Index

Constants

View Source
const (
	ExecuteOther p9.FileMode = p9.Exec << iota
	WriteOther
	ReadOther

	ExecuteGroup
	WriteGroup
	ReadGroup

	ExecuteUser
	WriteUser
	ReadUser
)

Permission mode bits.

Variables

This section is empty.

Functions

func GetListeners

func GetListeners(listener p9.File) ([]multiaddr.Multiaddr, error)

GetListeners returns a slice of maddrs that correspond to active listeners contained within the `listener` file.

func Listen

func Listen(listener p9.File, maddr multiaddr.Multiaddr, permissions p9.FileMode) error

TODO: [Ame] English. Listen tries to listen on the provided [Multiaddr]. If successful, the [Multiaddr] is mapped as a directory, inheriting permissions from parent directories all the way down. The passed permissions are used for the final API file.

func MkdirAll

func MkdirAll(root p9.File, names []string,
	permissions p9.FileMode, uid p9.UID, gid p9.GID,
) (p9.File, error)

func NewDirectory

func NewDirectory(options ...DirectoryOption) (p9.QID, p9.File, error)

func ReadAll

func ReadAll(file p9.File) ([]byte, error)

ReadAll performs the following sequence on file: clone, stat(size), open(read-only), read, close.

func ReadDir

func ReadDir(dir p9.File) (p9.Dirents, error)

func UnlinkEmptyChildren

func UnlinkEmptyChildren[
	OT generic.OptionFunc[T],
	T any,
	I directorySetter[T],
](b bool,
) OT

UnlinkEmptyChildren sets UnlinkWhenEmpty on files created by this file.

func UnlinkWhenEmpty

func UnlinkWhenEmpty[
	OT generic.OptionFunc[T],
	T any,
	I directorySetter[T],
](b bool,
) OT

UnlinkWhenEmpty causes files to unlink from their parent after they are considered empty and the last reference held by a Walk has been closed.

func UnmountAll

func UnmountAll(mounts p9.File) error

func UnmountTargets

func UnmountTargets(mounts p9.File,
	mountPoints []string, decodeTargetFn DecodeTargetFunc,
) error

func WithBuffer

func WithBuffer[
	OT generic.OptionFunc[T],
	T any,
	I channelSetter[T],
](size int,
) OT

func WithGID

func WithGID[
	OT generic.OptionFunc[T],
	T any,
	I metadataSetter[T],
](gid p9.GID,
) OT

WithGID specifies a GID value for a file's status information.

func WithParent

func WithParent[
	OT generic.OptionFunc[T],
	T any,
	I linkSetter[T],
](parent p9.File, child string,
) OT

func WithPath

func WithPath[
	OT generic.OptionFunc[T],
	T any,
	I metadataSetter[T],
](path *atomic.Uint64,
) OT

WithPath specifies the path to be used by this file.

func WithPermissions

func WithPermissions[
	OT generic.OptionFunc[T],
	T any,
	I metadataSetter[T],
](permissions p9.FileMode,
) OT

WithPermissions specifies the permission bits for a file's mode status.

func WithRenamedFunc

func WithRenamedFunc[
	OT generic.OptionFunc[T],
	T any,
	I linkSetter[T],
](fn RenamedFunc,
) OT

WithRenamedFunc provides a callback which is called after a successful rename operation.

func WithUID

func WithUID[
	OT generic.OptionFunc[T],
	T any,
	I metadataSetter[T],
](uid p9.UID,
) OT

WithUID specifies a UID value for a file's status information.

func WithoutRename

func WithoutRename[
	OT generic.OptionFunc[T],
	T any,
	I linkSetter[T],
](disabled bool,
) OT

WithoutRename causes rename operations to return an error when called.

Types

type ChannelFile

type ChannelFile struct {
	templatefs.NoopFile
	// contains filtered or unexported fields
}

func NewChannelFile

func NewChannelFile(ctx context.Context,
	options ...ChannelOption,
) (p9.QID, *ChannelFile, <-chan []byte, error)

func (*ChannelFile) Close

func (cf *ChannelFile) Close() error

func (*ChannelFile) GetAttr

func (cf *ChannelFile) GetAttr(req p9.AttrMask) (p9.QID, p9.AttrMask, p9.Attr, error)

func (ChannelFile) Mode

func (of ChannelFile) Mode() p9.OpenFlags

func (*ChannelFile) Open

func (cf *ChannelFile) Open(mode p9.OpenFlags) (p9.QID, ioUnit, error)

func (*ChannelFile) Rename

func (cf *ChannelFile) Rename(newDir p9.File, newName string) error

func (*ChannelFile) Renamed

func (cf *ChannelFile) Renamed(newDir p9.File, newName string)

func (*ChannelFile) SetAttr

func (cf *ChannelFile) SetAttr(valid p9.SetAttrMask, attr p9.SetAttr) error

func (*ChannelFile) Walk

func (cf *ChannelFile) Walk(names []string) ([]p9.QID, p9.File, error)

func (*ChannelFile) WriteAt

func (cf *ChannelFile) WriteAt(p []byte, _ int64) (int, error)

type ChannelOption

type ChannelOption func(*channelFileSettings) error

type ConnInfo

type ConnInfo struct {
	LastRead  time.Time           `json:"lastRead"`
	LastWrite time.Time           `json:"lastWrite"`
	Local     multiaddr.Multiaddr `json:"local"`
	Remote    multiaddr.Multiaddr `json:"remote"`
	ID        uintptr             `json:"#"`
}

func GetConnections

func GetConnections(listener p9.File) ([]ConnInfo, error)

GetConnections returns a slice of info that corresponds to active connections contained within the `listener` file.

func (*ConnInfo) UnmarshalJSON

func (ci *ConnInfo) UnmarshalJSON(data []byte) error

type DecodeTargetFunc

type DecodeTargetFunc func(filesystem.Host, filesystem.ID, []byte) (string, error)

DecodeTargetFunc will be called with bytes representing an encoded mount point, and should decode then return the mount point's target. Under typical operation, the encoded data should have the same format as the argument passed to [Client.Mount]. However, this is not guaranteed; as different clients with different formats may call `Mount` and `Unmount` independently.

type Directory

type Directory struct {
	templatefs.NoopFile
	// contains filtered or unexported fields
}

func (Directory) GetAttr

func (dir Directory) GetAttr(req p9.AttrMask) (p9.QID, p9.AttrMask, p9.Attr, error)
func (dir *Directory) Link(file p9.File, name string) error

func (*Directory) Mkdir

func (dir *Directory) Mkdir(name string, permissions p9.FileMode, uid p9.UID, gid p9.GID) (p9.QID, error)

func (*Directory) Open

func (dir *Directory) Open(mode p9.OpenFlags) (p9.QID, ioUnit, error)

func (*Directory) Readdir

func (dir *Directory) Readdir(offset uint64, count uint32) (p9.Dirents, error)

func (*Directory) Rename

func (dir *Directory) Rename(newDir p9.File, newName string) error

func (*Directory) RenameAt

func (dir *Directory) RenameAt(oldName string, newDir p9.File, newName string) error

func (*Directory) Renamed

func (dir *Directory) Renamed(newDir p9.File, newName string)

func (Directory) SetAttr

func (dir Directory) SetAttr(valid p9.SetAttrMask, attr p9.SetAttr) error

func (*Directory) UnlinkAt

func (dir *Directory) UnlinkAt(name string, _ uint32) error

func (*Directory) Walk

func (dir *Directory) Walk(names []string) ([]p9.QID, p9.File, error)

type DirectoryOption

type DirectoryOption func(*directorySettings) error

type FieldError

type FieldError struct {
	Key   string
	Tried []string
}

FieldError describes which key was searched for and the available fields which were tried. Useful for chaining [FieldParser.ParseField] calls with errors.As.

func (FieldError) Error

func (fe FieldError) Error() string

type FieldParser

type FieldParser interface {
	ParseField(key, value string) error
}

FieldParser should parse and assign its inputs. Returning either a FieldError if the key is not applicable, or any other error if the value is invalid.

type GuestFile

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

func NewGuestFile

func NewGuestFile(makeMountPointFn MakeMountPointFunc,
	options ...GuestOption,
) (p9.QID, *GuestFile, error)

func (*GuestFile) Create

func (gf *GuestFile) Create(name string, flags p9.OpenFlags, permissions p9.FileMode,
	uid p9.UID, gid p9.GID,
) (p9.File, p9.QID, uint32, error)

func (*GuestFile) Mkdir

func (gf *GuestFile) Mkdir(name string, permissions p9.FileMode, uid p9.UID, gid p9.GID) (p9.QID, error)

TODO: stub out [Link] too?

func (*GuestFile) Mknod

func (gf *GuestFile) Mknod(name string, mode p9.FileMode,
	_, _ uint32, uid p9.UID, gid p9.GID,
) (p9.QID, error)

func (*GuestFile) UnlinkAt

func (gf *GuestFile) UnlinkAt(name string, flags uint32) error

func (*GuestFile) Walk

func (gf *GuestFile) Walk(names []string) ([]p9.QID, p9.File, error)

type GuestIdentifier

type GuestIdentifier interface {
	GuestID() filesystem.ID
}

type GuestOption

type GuestOption func(*guestSettings) error

type HostFile

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

func NewHostFile

func NewHostFile(makeGuestFn MakeGuestFunc,
	options ...HosterOption,
) (p9.QID, *HostFile, error)

func (*HostFile) Create

func (hf *HostFile) Create(name string, flags p9.OpenFlags, permissions p9.FileMode,
	uid p9.UID, gid p9.GID,
) (p9.File, p9.QID, uint32, error)

func (*HostFile) Mkdir

func (hd *HostFile) Mkdir(name string, permissions p9.FileMode, uid p9.UID, gid p9.GID) (p9.QID, error)

func (*HostFile) Mknod

func (hf *HostFile) Mknod(name string, mode p9.FileMode,
	_, _ uint32, uid p9.UID, gid p9.GID,
) (p9.QID, error)

func (*HostFile) Walk

func (hd *HostFile) Walk(names []string) ([]p9.QID, p9.File, error)

type HostIdentifier

type HostIdentifier interface {
	HostID() filesystem.Host
}

type HosterOption

type HosterOption func(*hosterSettings) error

type Listener

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

func NewListener

func NewListener(ctx context.Context, options ...ListenerOption) (p9.QID, *Listener, <-chan manet.Listener, error)
func (ld *Listener) Link(file p9.File, name string) error

func (*Listener) Mkdir

func (ld *Listener) Mkdir(name string, permissions p9.FileMode, uid p9.UID, gid p9.GID) (p9.QID, error)

func (*Listener) Walk

func (ld *Listener) Walk(names []string) ([]p9.QID, p9.File, error)

type ListenerOption

type ListenerOption func(*listenerSettings) error

type MakeGuestFunc

type MakeGuestFunc func(parent p9.File, guest filesystem.ID,
	mode p9.FileMode,
	uid p9.UID, gid p9.GID) (p9.QID, p9.File, error)

MakeGuestFunc should handle file creation operations for files representing a filesystem.ID. The file `mode` will contain file type bits.

type MakeHostFunc

type MakeHostFunc func(parent p9.File, host filesystem.Host,
	mode p9.FileMode,
	uid p9.UID, gid p9.GID) (p9.QID, p9.File, error)

MakeHostFunc should handle file creation operations for files representing a filesystem.Host. The file `mode` will contain file type bits.

type MakeMountPointFunc

type MakeMountPointFunc func(parent p9.File, name string,
	mode p9.FileMode, uid p9.UID, gid p9.GID,
) (p9.QID, p9.File, error)

MakeMountPointFunc should handle file creation operations for files representing mount points. The file `mode` will contain file type bits.

type MountFile

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

func NewMounter

func NewMounter(makeHostFn MakeHostFunc, options ...MounterOption) (p9.QID, *MountFile, error)

func (*MountFile) Create

func (mf *MountFile) Create(name string, flags p9.OpenFlags, permissions p9.FileMode,
	uid p9.UID, gid p9.GID,
) (p9.File, p9.QID, uint32, error)

func (*MountFile) Mkdir

func (mf *MountFile) Mkdir(name string, permissions p9.FileMode, uid p9.UID, gid p9.GID) (p9.QID, error)

func (*MountFile) Mknod

func (mf *MountFile) Mknod(name string, mode p9.FileMode,
	_, _ uint32, uid p9.UID, gid p9.GID,
) (p9.QID, error)

func (*MountFile) Walk

func (mf *MountFile) Walk(names []string) ([]p9.QID, p9.File, error)

type MountPoint

type MountPoint interface {
	SystemMaker
	Mounter
	HostIdentifier
	GuestIdentifier
}

type MountPointFile

type MountPointFile[MP MountPoint] struct {
	// contains filtered or unexported fields
}

func NewMountPoint

func NewMountPoint[
	MP interface {
		*T
		MountPoint
	},
	T any,
](options ...MountPointOption,
) (p9.QID, *MountPointFile[MP], error)

func (*MountPointFile[MP]) Close

func (mf *MountPointFile[MP]) Close() error

func (*MountPointFile[MP]) FSync

func (mf *MountPointFile[MP]) FSync() error

func (*MountPointFile[MP]) GetAttr

func (mf *MountPointFile[MP]) GetAttr(req p9.AttrMask) (p9.QID, p9.AttrMask, p9.Attr, error)

func (*MountPointFile[MP]) Open

func (mf *MountPointFile[MP]) Open(mode p9.OpenFlags) (p9.QID, ioUnit, error)

func (*MountPointFile[MP]) ReadAt

func (mf *MountPointFile[MP]) ReadAt(p []byte, offset int64) (int, error)

func (*MountPointFile[MP]) SetAttr

func (mf *MountPointFile[MP]) SetAttr(valid p9.SetAttrMask, attr p9.SetAttr) error

func (*MountPointFile[MP]) Walk

func (mf *MountPointFile[MP]) Walk(names []string) ([]p9.QID, p9.File, error)

func (*MountPointFile[MP]) WriteAt

func (mf *MountPointFile[MP]) WriteAt(p []byte, offset int64) (int, error)

type MountPointOption

type MountPointOption func(*fileSettings) error

type Mounter

type Mounter interface {
	Mount(fs.FS) (io.Closer, error)
}

type MounterOption

type MounterOption func(*mounterSettings) error

type RenamedFunc

type RenamedFunc func(old, new string)

type SystemMaker

type SystemMaker interface {
	MakeFS() (fs.FS, error)
}

Jump to

Keyboard shortcuts

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