fs

package
v0.0.0-...-b1bb66f Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2026 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Overview

9p File System Implementations.

Various implementations of servers that conform to the ninep.FileSystem interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Env

func Env() ninep.FileSystem

Env implements a basic file system to the process environment variables.

func FS

FS wraps a FileSystem to provide a ninep.FileSystem interface This provides an interface using io/fs when possible.

func NewDelayFS

func NewDelayFS(underlying ninep.FileSystem, delay time.Duration) ninep.FileSystem

func Populate

func Populate(fs ninep.FileSystem, files map[string]string) error

func ReadOnly

func ReadOnly(fsys ninep.FileSystem) ninep.FileSystem

ReadOnly wraps a FileSystem and returns a read-only version of it.

func ReadOnlyFS

func ReadOnlyFS(f fs.FS) ninep.FileSystem

ReadOnlyFS wraps an fs.FS and returns a read-only version of it for use with ninep.

func Restrict

func Restrict(fs ninep.FileSystem, disallow Disallow) ninep.FileSystem

Restrict returns a new FileSystem that disallows certain operations.

func Sub

func Sub(fs ninep.FileSystem, subdir string) ninep.FileSystem

Sub returns a new FileSystem that operates on a subdirectory of the given FileSystem.

func TraceFs

func TraceFs(fs ninep.FileSystem, l *slog.Logger) ninep.FileSystem

Returns a trace file system the wraps a given file system.

The trace file system simply logs all file system operations are logged to the loggable.

Supports also walkable file systems.

func WithClose

func WithClose(f ninep.FileSystem, closers ...context.CancelFunc) ninep.FileSystem

WithClose returns a wrapped file system that attaches the given closers to the Close() method of the filesystem. These methods are call prior to calling Close() on the underlying filesystem.

Types

type Dir

type Dir string

Dir implements a basic file system to the local file system with a given root dir. The type represents the root directory for this file system

func (Dir) CreateFile

func (d Dir) CreateFile(ctx context.Context, path string, flag ninep.OpenMode, mode ninep.Mode) (ninep.FileHandle, error)

CreateFile creates a new file as a descendent of the root directory of Dir

func (Dir) Delete

func (d Dir) Delete(ctx context.Context, path string) error

Delete a file or directory. Deleting the root directory will be an error.

func (Dir) ListDir

func (d Dir) ListDir(ctx context.Context, path string) iter.Seq2[fs.FileInfo, error]

ListDir lists all files and directories in a given subdirectory

func (Dir) MakeDir

func (d Dir) MakeDir(ctx context.Context, path string, mode ninep.Mode) error

MakeDir creates a local directory as subdirectory of the root directory of Dir

func (Dir) OpenFile

func (d Dir) OpenFile(ctx context.Context, path string, flag ninep.OpenMode) (ninep.FileHandle, error)

OpenFile opens an existing file that is a descendent of the root directory of Dir for reading/writing

func (Dir) Stat

func (d Dir) Stat(ctx context.Context, path string) (fs.FileInfo, error)

Stat returns information about a given file or directory

func (Dir) Traverse

func (d Dir) Traverse(ctx context.Context, path string) (ninep.TraversableFile, error)

func (Dir) Walk

func (d Dir) Walk(ctx context.Context, parts []string) ([]os.FileInfo, error)

func (Dir) WriteStat

func (d Dir) WriteStat(ctx context.Context, path string, s ninep.Stat) error

WriteStat updates file or directory metadata.

type Disallow

type Disallow uint64
const (
	DisallowMakeDirectory Disallow = 1 << iota
	DisallowCreateFile
	DisallowOpenFile
	DisallowListDir
	DisallowStat
	DisallowWriteStat
	DisallowDelete
	DisallowOpenFileTruncate
	DisallowRemoveOnClose

	DisallowCreation = DisallowMakeDirectory | DisallowCreateFile
	DisallowMutation = DisallowWriteStat | DisallowDelete | DisallowOpenFileTruncate | DisallowRemoveOnClose
)

type FileInfoChangeRequest

type FileInfoChangeRequest struct {
	Name             *string
	Owner            *string
	Group            *string
	LastModifiedUser *string
	Mode             *fs.FileMode
	ModTime          *time.Time
	AccessTime       *time.Time
	Length           *int64
}

FileInfoChangeRequest is used to change the stat of a file or directory. If a value is nil, the caller does not want that part of the stat to be changed.

type FileSystem

type FileSystem interface {
	// Creates a directory. Implementions should recursively make directories
	// whenever possible.
	MakeDir(ctx context.Context, path string, mode fs.FileMode) error
	// Creates a file and opens it for reading/writing
	CreateFile(ctx context.Context, path string, flag int, mode fs.FileMode) (ninep.FileHandle, error)
	// Opens an existing file for reading/writing
	OpenFile(ctx context.Context, path string, flag int) (ninep.FileHandle, error)
	// Lists directories and files in a given path. Does not include '.' or '..'
	// fs.FileInfo may optionally implement Statable. Iterations are allowed to
	// return a nil FileInfo if they have an error.
	ListDir(ctx context.Context, path string) iter.Seq2[fs.FileInfo, error]
	// Lists stats about a given file or directory. Implementations may return
	// fs.ErrNotExist for directories that do not exist.
	Stat(ctx context.Context, path string) (fs.FileInfo, error)
	// Writes stats about a given file or directory.
	// The req contains all desired changes. If a value is nil, the caller
	// does not want that part of the stat to be changed.
	WriteStat(ctx context.Context, path string, info FileInfoChangeRequest) error
	// Deletes a file or directory. Implementations may reject directories that aren't empty
	Delete(ctx context.Context, path string) error
}

FileSystem is a bridging interface to provide a ninep.FileSystem interface. This allows implementing using familiar fs types without knowing about the 9p protocol. Note that various fs.FileMode values cannot be translated to 9p.

type Mem

type Mem struct {
	Root memNode
}

Implements a basic file system in memory only. Also, not a particularly efficient implementation.

func NewMemFSWithFiles

func NewMemFSWithFiles(files map[string]string) *Mem

NewMemFS creates a new in-memory file system with a given set of files.

func (*Mem) CreateFile

func (m *Mem) CreateFile(ctx context.Context, path string, flag ninep.OpenMode, mode ninep.Mode) (ninep.FileHandle, error)

func (*Mem) Delete

func (m *Mem) Delete(ctx context.Context, path string) error

func (*Mem) ListDir

func (m *Mem) ListDir(ctx context.Context, path string) iter.Seq2[os.FileInfo, error]

func (*Mem) MakeDir

func (m *Mem) MakeDir(ctx context.Context, path string, mode ninep.Mode) error

func (*Mem) OpenFile

func (m *Mem) OpenFile(ctx context.Context, path string, flag ninep.OpenMode) (ninep.FileHandle, error)

func (*Mem) Stat

func (m *Mem) Stat(ctx context.Context, path string) (os.FileInfo, error)

func (*Mem) Traverse

func (m *Mem) Traverse(ctx context.Context, path string) (ninep.TraversableFile, error)

func (*Mem) WriteStat

func (m *Mem) WriteStat(ctx context.Context, path string, s ninep.Stat) error

Directories

Path Synopsis
Implements a 9p file system that talks to a docker daemon.
Implements a 9p file system that talks to a docker daemon.
Implements a 9p file system encrypts its data on another 9p file server
Implements a 9p file system encrypts its data on another 9p file server
muxfs provides a file system based on a mux.
muxfs provides a file system based on a mux.
Implements a 9p file server that behaves similar to /proc on some unix systems
Implements a 9p file server that behaves similar to /proc on some unix systems
Implements a 9p file system that talks to Amazon's S3 Object Storage Service.
Implements a 9p file system that talks to Amazon's S3 Object Storage Service.
Implements a 9p file system that talks to a given server via SFTP
Implements a 9p file system that talks to a given server via SFTP

Jump to

Keyboard shortcuts

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