ramfs

package
v0.0.0-...-23e6066 Latest Latest
Warning

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

Go to latest
Published: May 3, 2018 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package ramfs implements an in-memory file system that can be associated with any device.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidOp indicates the operation is not valid.
	ErrInvalidOp = errors.New("invalid operation")

	// ErrDenied indicates the operation was denid.
	ErrDenied = errors.New("operation denied")

	// ErrNotFound indicates that a node was not found on a walk.
	ErrNotFound = errors.New("node not found")

	// ErrCrossDevice indicates a cross-device link or rename.
	ErrCrossDevice = errors.New("can't link across filesystems")

	// ErrIsDirectory indicates that the operation failed because
	// the node is a directory.
	ErrIsDirectory = errors.New("is a directory")

	// ErrNotDirectory indicates that the operation failed because
	// the node is a not directory.
	ErrNotDirectory = errors.New("not a directory")

	// ErrNotEmpty indicates that the operation failed because the
	// directory is not empty.
	ErrNotEmpty = errors.New("directory not empty")
)

Functions

func MakeDirectoryTree

func MakeDirectoryTree(ctx context.Context, msrc *fs.MountSource, subdirs []string) (*fs.Inode, error)

MakeDirectoryTree constructs a ramfs tree of all directories containing subdirs. Each element of subdir must be a clean path, and cannot be empty or "/".

func Rename

func Rename(ctx context.Context, oldParent fs.InodeOperations, oldName string, newParent fs.InodeOperations, newName string) error

Rename renames from a *ramfs.Dir to another *ramfs.Dir.

Types

type CreateOps

type CreateOps struct {
	// NewDir creates a new directory.
	NewDir func(ctx context.Context, dir *fs.Inode, perms fs.FilePermissions) (*fs.Inode, error)

	// NewFile creates a new file.
	NewFile func(ctx context.Context, dir *fs.Inode, perms fs.FilePermissions) (*fs.Inode, error)

	// NewSymlink creates a new symlink with permissions 0777.
	NewSymlink func(ctx context.Context, dir *fs.Inode, target string) (*fs.Inode, error)

	// NewBoundEndpoint creates a new socket.
	NewBoundEndpoint func(ctx context.Context, dir *fs.Inode, ep unix.BoundEndpoint, perms fs.FilePermissions) (*fs.Inode, error)

	// NewFifo creates a new fifo.
	NewFifo func(ctx context.Context, dir *fs.Inode, perm fs.FilePermissions) (*fs.Inode, error)
}

CreateOps represents operations to create different file types.

type Dir

type Dir struct {
	Entry

	// CreateOps may be provided.
	//
	// These may only be modified during initialization (while the application
	// is not running). No sychronization is performed when accessing these
	// operations during syscalls.
	*CreateOps `state:"nosave"`
	// contains filtered or unexported fields
}

Dir represents a single directory in the filesystem.

func (*Dir) AddChild

func (d *Dir) AddChild(ctx context.Context, name string, inode *fs.Inode)

AddChild adds a child to this dir.

func (*Dir) Bind

func (d *Dir) Bind(ctx context.Context, dir *fs.Inode, name string, ep unix.BoundEndpoint, perms fs.FilePermissions) error

Bind implements fs.InodeOperations.Bind.

func (*Dir) Create

func (d *Dir) Create(ctx context.Context, dir *fs.Inode, name string, flags fs.FileFlags, perms fs.FilePermissions) (*fs.File, error)

Create creates a new Inode with the given name and returns its File.

func (*Dir) CreateDirectory

func (d *Dir) CreateDirectory(ctx context.Context, dir *fs.Inode, name string, perms fs.FilePermissions) error

CreateDirectory returns a new subdirectory.

func (*Dir) CreateFifo

func (d *Dir) CreateFifo(ctx context.Context, dir *fs.Inode, name string, perms fs.FilePermissions) error

CreateFifo implements fs.InodeOperations.CreateFifo.

func (d *Dir) CreateHardLink(ctx context.Context, dir *fs.Inode, target *fs.Inode, name string) error

CreateHardLink creates a new hard link.

func (d *Dir) CreateLink(ctx context.Context, dir *fs.Inode, oldname, newname string) error

CreateLink returns a new link.

func (*Dir) DeprecatedPreadv

func (*Dir) DeprecatedPreadv(context.Context, usermem.IOSequence, int64) (int64, error)

DeprecatedPreadv always returns ErrIsDirectory

func (*Dir) DeprecatedPwritev

func (*Dir) DeprecatedPwritev(context.Context, usermem.IOSequence, int64) (int64, error)

DeprecatedPwritev always returns ErrIsDirectory

func (*Dir) DeprecatedReaddir

func (d *Dir) DeprecatedReaddir(ctx context.Context, dirCtx *fs.DirCtx, offset int) (int, error)

DeprecatedReaddir emits the entries contained in this directory.

func (*Dir) FindChild

func (d *Dir) FindChild(name string) (*fs.Inode, bool)

FindChild returns (child, true) if the directory contains name.

func (*Dir) InitDir

func (d *Dir) InitDir(ctx context.Context, contents map[string]*fs.Inode, owner fs.FileOwner, perms fs.FilePermissions)

InitDir initializes a directory.

func (*Dir) Lookup

func (d *Dir) Lookup(ctx context.Context, dir *fs.Inode, p string) (*fs.Dirent, error)

Lookup loads an inode at p into a Dirent.

func (*Dir) Remove

func (d *Dir) Remove(ctx context.Context, dir *fs.Inode, name string) error

Remove removes the named non-directory.

func (*Dir) RemoveDirectory

func (d *Dir) RemoveDirectory(ctx context.Context, dir *fs.Inode, name string) error

RemoveDirectory removes the named directory.

func (*Dir) RemoveEntry

func (d *Dir) RemoveEntry(ctx context.Context, name string) error

RemoveEntry attempts to remove an entry from this directory.

type Entry

type Entry struct {
	waiter.AlwaysReady    `state:"nosave"`
	fsutil.NoMappable     `state:"nosave"`
	fsutil.NoopWriteOut   `state:"nosave"`
	fsutil.InodeNotSocket `state:"nosave"`
	// contains filtered or unexported fields
}

Entry represents common internal state for file and directory nodes. This may be used by other packages to easily create ramfs files.

func (*Entry) AccessTime

func (e *Entry) AccessTime() ktime.Time

AccessTime returns the last access time for this node.

func (e *Entry) AddLink()

AddLink implements InodeOperationss.AddLink.

func (*Entry) Bind

Bind is not supported by default.

func (*Entry) Check

func (*Entry) Check(ctx context.Context, inode *fs.Inode, p fs.PermMask) bool

Check implements fs.InodeOperations.Check.

func (*Entry) Create

Create is not supported by default.

func (*Entry) CreateDirectory

func (*Entry) CreateDirectory(context.Context, *fs.Inode, string, fs.FilePermissions) error

CreateDirectory is not supported by default.

func (*Entry) CreateFifo

CreateFifo implements fs.InodeOperations.CreateFifo. CreateFifo is not supported by default.

func (*Entry) CreateHardLink(context.Context, *fs.Inode, *fs.Inode, string) error

CreateHardLink is not supported by default.

func (*Entry) CreateLink(context.Context, *fs.Inode, string, string) error

CreateLink is not supported by default.

func (*Entry) DeprecatedFlush

func (*Entry) DeprecatedFlush() error

DeprecatedFlush always returns nil.

func (*Entry) DeprecatedFsync

func (*Entry) DeprecatedFsync() error

DeprecatedFsync is a noop.

func (*Entry) DeprecatedMappable

func (*Entry) DeprecatedMappable(context.Context, *fs.Inode) (memmap.Mappable, bool)

DeprecatedMappable implements fs.InodeOperations.DeprecatedMappable.

func (*Entry) DeprecatedPreadv

func (*Entry) DeprecatedPreadv(context.Context, usermem.IOSequence, int64) (int64, error)

DeprecatedPreadv always returns ErrInvalidOp.

func (*Entry) DeprecatedPwritev

func (*Entry) DeprecatedPwritev(context.Context, usermem.IOSequence, int64) (int64, error)

DeprecatedPwritev always returns ErrInvalidOp.

func (*Entry) DeprecatedReaddir

func (*Entry) DeprecatedReaddir(context.Context, *fs.DirCtx, int) (int, error)

DeprecatedReaddir is not supported by default.

func (e *Entry) DropLink()

DropLink implements InodeOperationss.DropLink.

func (*Entry) GetFile

func (*Entry) GetFile(ctx context.Context, d *fs.Dirent, flags fs.FileFlags) (*fs.File, error)

GetFile returns a fs.File backed by the dirent argument and flags.

func (*Entry) Getlink(context.Context, *fs.Inode) (*fs.Dirent, error)

Getlink always returns ENOLINK.

func (*Entry) Getxattr

func (e *Entry) Getxattr(inode *fs.Inode, name string) ([]byte, error)

Getxattr implements fs.InodeOperations.Getxattr.

func (*Entry) InitEntry

func (e *Entry) InitEntry(ctx context.Context, owner fs.FileOwner, p fs.FilePermissions)

InitEntry initializes an entry.

func (*Entry) InitEntryWithAttr

func (e *Entry) InitEntryWithAttr(ctx context.Context, uattr fs.UnstableAttr)

InitEntryWithAttr initializes an entry with a complete set of attributes.

func (*Entry) IsVirtual

func (*Entry) IsVirtual() bool

IsVirtual returns true.

func (*Entry) Listxattr

func (e *Entry) Listxattr(inode *fs.Inode) (map[string]struct{}, error)

Listxattr implements fs.InodeOperations.Listxattr.

func (*Entry) Lookup

func (*Entry) Lookup(context.Context, *fs.Inode, string) (*fs.Dirent, error)

Lookup is not supported by default.

func (*Entry) ModificationTime

func (e *Entry) ModificationTime() ktime.Time

ModificationTime returns the last modification time for this node.

func (*Entry) NotifyAccess

func (e *Entry) NotifyAccess(ctx context.Context)

NotifyAccess updates the access time.

func (*Entry) NotifyModification

func (e *Entry) NotifyModification(ctx context.Context)

NotifyModification updates the modification time and the status change time.

func (*Entry) NotifyStatusChange

func (e *Entry) NotifyStatusChange(ctx context.Context)

NotifyStatusChange updates the status change time (ctime).

func (*Entry) Permissions

func (e *Entry) Permissions() fs.FilePermissions

Permissions returns permissions on this entry.

func (*Entry) Readlink(context.Context, *fs.Inode) (string, error)

Readlink always returns ENOLINK.

func (*Entry) Release

func (e *Entry) Release(context.Context)

Release is a no-op.

func (*Entry) Remove

func (*Entry) Remove(context.Context, *fs.Inode, string) error

Remove is not supported by default.

func (*Entry) RemoveDirectory

func (*Entry) RemoveDirectory(context.Context, *fs.Inode, string) error

RemoveDirectory is not supported by default.

func (*Entry) Rename

func (e *Entry) Rename(ctx context.Context, oldParent *fs.Inode, oldName string, newParent *fs.Inode, newName string) error

Rename implements fs.InodeOperations.Rename.

func (*Entry) SetOwner

func (e *Entry) SetOwner(ctx context.Context, inode *fs.Inode, owner fs.FileOwner) error

SetOwner always sets ownership.

func (*Entry) SetPermissions

func (e *Entry) SetPermissions(ctx context.Context, inode *fs.Inode, p fs.FilePermissions) bool

SetPermissions always sets the permissions.

func (*Entry) SetTimestamps

func (e *Entry) SetTimestamps(ctx context.Context, inode *fs.Inode, ts fs.TimeSpec) error

SetTimestamps sets the timestamps.

func (*Entry) Setxattr

func (e *Entry) Setxattr(inode *fs.Inode, name string, value []byte) error

Setxattr implements fs.InodeOperations.Setxattr.

func (*Entry) StatFS

func (*Entry) StatFS(context.Context) (fs.Info, error)

StatFS always returns ENOSYS.

func (*Entry) StatusChangeTime

func (e *Entry) StatusChangeTime() ktime.Time

StatusChangeTime returns the last status change time for this node.

func (*Entry) Truncate

func (*Entry) Truncate(context.Context, *fs.Inode, int64) error

Truncate is not supported by default.

func (*Entry) UnstableAttr

func (e *Entry) UnstableAttr(ctx context.Context, inode *fs.Inode) (fs.UnstableAttr, error)

UnstableAttr implements fs.InodeOperations.UnstableAttr.

type File

type File struct {
	Entry
	// contains filtered or unexported fields
}

File represents a unique file. It uses a simple byte slice as storage, and thus should only be used for small files.

A File is not mappable.

func (*File) Append

func (f *File) Append(data []byte)

Append appends the given data. This is for internal use.

func (*File) DeprecatedPreadv

func (f *File) DeprecatedPreadv(ctx context.Context, dst usermem.IOSequence, offset int64) (int64, error)

DeprecatedPreadv reads into a collection of slices from a given offset.

func (*File) DeprecatedPwritev

func (f *File) DeprecatedPwritev(ctx context.Context, src usermem.IOSequence, offset int64) (int64, error)

DeprecatedPwritev writes from a collection of slices at a given offset.

func (*File) InitFile

func (f *File) InitFile(ctx context.Context, owner fs.FileOwner, perms fs.FilePermissions)

InitFile initializes a file.

func (*File) ReadAt

func (f *File) ReadAt(data []byte, offset int64) (int, error)

ReadAt implements io.ReaderAt.

func (*File) Truncate

func (f *File) Truncate(ctx context.Context, inode *fs.Inode, l int64) error

Truncate truncates this node.

func (*File) UnstableAttr

func (f *File) UnstableAttr(ctx context.Context, inode *fs.Inode) (fs.UnstableAttr, error)

UnstableAttr returns unstable attributes of this ramfs file.

func (*File) WriteAt

func (f *File) WriteAt(data []byte, offset int64) (int, error)

WriteAt implements io.WriterAt.

type Socket

type Socket struct {
	Entry
	// contains filtered or unexported fields
}

Socket represents a socket.

func (*Socket) BoundEndpoint

func (s *Socket) BoundEndpoint(*fs.Inode, string) unix.BoundEndpoint

BoundEndpoint returns the socket data.

func (*Socket) InitSocket

func (s *Socket) InitSocket(ctx context.Context, ep unix.BoundEndpoint, owner fs.FileOwner, perms fs.FilePermissions)

InitSocket initializes a socket.

type Symlink struct {
	Entry

	// Target is the symlink target.
	Target string
	// contains filtered or unexported fields
}

Symlink represents a symlink.

func (*Symlink) Check

func (s *Symlink) Check(ctx context.Context, inode *fs.Inode, p fs.PermMask) bool

Check implements InodeOperations.Check.

func (*Symlink) Getlink(context.Context, *fs.Inode) (*fs.Dirent, error)

Getlink returns ErrResolveViaReadlink, falling back to walking to the result of Readlink().

func (s *Symlink) InitSymlink(ctx context.Context, owner fs.FileOwner, target string)

InitSymlink initializes a symlink, pointing to the given target. A symlink is assumed to always have permissions 0777.

func (s *Symlink) Readlink(ctx context.Context, _ *fs.Inode) (string, error)

Readlink reads the symlink value.

func (*Symlink) SetPermissions

func (s *Symlink) SetPermissions(context.Context, *fs.Inode, fs.FilePermissions) bool

SetPermissions on a symlink is always rejected.

func (*Symlink) UnstableAttr

func (s *Symlink) UnstableAttr(ctx context.Context, inode *fs.Inode) (fs.UnstableAttr, error)

UnstableAttr returns all attributes of this ramfs symlink.

Directories

Path Synopsis
Package test provides a simple ramfs-based filesystem for use in testing.
Package test provides a simple ramfs-based filesystem for use in testing.

Jump to

Keyboard shortcuts

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