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 ¶
- func Append(f File, data []byte)
- func AtomicCreate(dir, fname string, data []byte)
- func Close(f File)
- func Delete(dir, fname string)
- func Link(oldDir, oldName, newDir, newName string) bool
- func List(dir string) []string
- func ReadAt(f File, offset uint64, length uint64) []byte
- type DirFs
- func (fs DirFs) Append(f File, data []byte)
- func (fs DirFs) AtomicCreate(dir, fname string, data []byte)
- func (fs DirFs) Close(f File)
- func (fs DirFs) CloseFs()
- func (fs DirFs) Create(dir, fname string) (f File, ok bool)
- func (fs DirFs) Delete(dir, fname string)
- func (fs DirFs) Link(oldDir, oldName, newDir, newName string) bool
- func (fs DirFs) List(dir string) []string
- func (fs DirFs) Mkdir(p string)
- func (fs DirFs) Open(dir, fname string) File
- func (fs DirFs) ReadAt(f File, offset uint64, length uint64) []byte
- type File
- type Filesys
- type MemFs
- func (fs *MemFs) Append(f File, data []byte)
- func (fs *MemFs) AtomicCreate(dir, fname string, data []byte)
- func (fs *MemFs) Close(f File)
- func (fs *MemFs) Create(dir, fname string) (f File, ok bool)
- func (fs *MemFs) Delete(dir, fname string)
- func (fs *MemFs) Link(oldDir, oldName, newDir, newName string) bool
- func (fs *MemFs) List(dir string) (names []string)
- func (fs *MemFs) Mkdir(dir string)
- func (fs *MemFs) Open(dir, fname string) File
- func (fs *MemFs) ReadAt(f File, offset uint64, length uint64) []byte
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AtomicCreate ¶
AtomicCreate calls AtomicCreate 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 (DirFs) AtomicCreate ¶
type File ¶
type File int
A File is a file descriptor (either a real OS fd or an in-memory "inode number")
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).
type MemFs ¶
type MemFs struct {
// contains filtered or unexported fields
}
MemFs is an in-memory, thread-safe implementation of filesys.Filesys.