filesys

package
v0.0.0-...-cd2353e Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package filesys is a support library providing access to a single directory in the filesystem.

These operations have corresponding operations in Perennial in `Goose/Filesys.v` and are exported as functions in the `FS` module.

The interface is a subset of the filesystem API specific to the needs of the key-value store. That said, each method (with the notable exceptions of AtomicCreate and List) is a straightforward wrapper around a system call.

AtomicCreate provides the temp file + rename pattern for convenience to create files atomically.

List is a wrapper around readdir, which is not a system call but a library function that reads a directory entry in chunks and returns parsed entries from it. As a result the List operation is not atomic with respect to concurrent filesystem operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(f File, data []byte)

Append calls Append on the global Filesys

func AtomicCreate

func AtomicCreate(dir, fname string, data []byte)

AtomicCreate calls AtomicCreate on the global Filesys

func Close

func Close(f File)

Close calls Close on the global Filesys

func Delete

func Delete(dir, fname string)

Delete calls Delete on the global Filesys

func Link(oldDir, oldName, newDir, newName string) bool

Link calls Link on the global Filesys

func List

func List(dir string) []string

List calls List on the global Filesys

func ReadAt

func ReadAt(f File, offset uint64, length uint64) []byte

ReadAt calls ReadAt on the global Filesys

Types

type DirFs

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

DirFs is a Filesys backed by a directory on some host filesystem.

func NewDirFs

func NewDirFs(root string) DirFs

NewDirFs creates a DirFs using root as the root directory for all operations.

func (DirFs) Append

func (fs DirFs) Append(f File, data []byte)

func (DirFs) AtomicCreate

func (fs DirFs) AtomicCreate(dir, fname string, data []byte)

func (DirFs) Close

func (fs DirFs) Close(f File)

func (DirFs) CloseFs

func (fs DirFs) CloseFs()

func (DirFs) Create

func (fs DirFs) Create(dir, fname string) (f File, ok bool)

func (DirFs) Delete

func (fs DirFs) Delete(dir, fname string)
func (fs DirFs) Link(oldDir, oldName, newDir, newName string) bool

func (DirFs) List

func (fs DirFs) List(dir string) []string

func (DirFs) Mkdir

func (fs DirFs) Mkdir(p string)

func (DirFs) Open

func (fs DirFs) Open(dir, fname string) File

func (DirFs) ReadAt

func (fs DirFs) ReadAt(f File, offset uint64, length uint64) []byte

type File

type File int

A File is a file descriptor (either a real OS fd or an in-memory "inode number")

func Create

func Create(dir, fname string) (File, bool)

Create calls Create on the global Filesys

func Open

func Open(dir, fname string) File

Open calls Open on the global Filesys

type Filesys

type Filesys interface {
	// Create creates an empty file at fname in write-only mode.
	// Returns ok=false and does nothing if fname exists.
	Create(dir, fname string) (f File, ok bool)
	// Append to an open file
	Append(f File, data []byte)
	// Close closes a file, invalidating the file descriptor
	Close(f File)
	// Open opens a file for reading
	//
	// Read-only files do not use the read offset managed by the kernel since
	// all reads are absolute.
	Open(dir, fname string) File
	// ReadAt reads from an offset in the file (using pread)
	ReadAt(f File, offset uint64, length uint64) []byte
	// Delete deletes a file (which must exist).
	Delete(dir, fname string)
	// AtomicCreate creates a file with data atomically using a temp file and
	// rename.
	AtomicCreate(dir, fname string, data []byte)
	// Link creates a hard link from newName to oldName
	Link(oldDir, oldName, newDir, newName string) bool
	// List lists the directory using readdir().
	//
	// This is a non-atomic operation since multiple system calls might be
	// needed to read the entire directory entry.
	List(dir string) []string
	// Mkdir creates a root directory.
	//
	// Used only for initialization outside of verified code
	// (Perennial's Go model does not model this operation).
	Mkdir(dir string)
}

Filesys provides access a directory with one layer of nested directories.

var Fs Filesys

Fs is a global instance of Filesys.

Before using the filesystem this must be initialized (use DefaultFs, MemFs, or DirFs).

func DefaultFs

func DefaultFs() Filesys

DefaultFs returns a directory filesystem using the global flag configuration.

type MemFs

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

MemFs is an in-memory, thread-safe implementation of filesys.Filesys.

func NewMemFs

func NewMemFs() *MemFs

NewMemFs creates an empty MemFs

func (*MemFs) Append

func (fs *MemFs) Append(f File, data []byte)

func (*MemFs) AtomicCreate

func (fs *MemFs) AtomicCreate(dir, fname string, data []byte)

func (*MemFs) Close

func (fs *MemFs) Close(f File)

func (*MemFs) Create

func (fs *MemFs) Create(dir, fname string) (f File, ok bool)

func (*MemFs) Delete

func (fs *MemFs) Delete(dir, fname string)
func (fs *MemFs) Link(oldDir, oldName, newDir, newName string) bool

func (*MemFs) List

func (fs *MemFs) List(dir string) (names []string)

func (*MemFs) Mkdir

func (fs *MemFs) Mkdir(dir string)

func (*MemFs) Open

func (fs *MemFs) Open(dir, fname string) File

func (*MemFs) ReadAt

func (fs *MemFs) ReadAt(f File, offset uint64, length uint64) []byte

Jump to

Keyboard shortcuts

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