Documentation ¶
Overview ¶
Package fs implements a virtual filesystem layer.
Specific filesystem implementations must implement the InodeOperations interface (inode.go).
The MountNamespace (mounts.go) is used to create a collection of mounts in a filesystem rooted at a given Inode.
MountSources (mount.go) form a tree, with each mount holding pointers to its parent and children.
Dirents (dirents.go) wrap Inodes in a caching layer.
When multiple locks are to be held at the same time, they should be acquired in the following order.
Either:
File.mu Locks in FileOperations implementations goto Dirent-Locks
Or:
MountNamespace.mu goto Dirent-Locks
Dirent-Locks:
renameMu Dirent.dirMu Dirent.mu DirentCache.mu Locks in InodeOperations implementations or overlayEntry Inode.Watches.mu (see `Inotify` for other lock ordering) MountSource.mu
If multiple Dirent or MountSource locks must be taken, locks in the parent must be taken before locks in their children.
If locks must be taken on multiple unrelated Dirents, renameMu must be taken first. See lockForRename.
Index ¶
- Constants
- Variables
- func Async(f func())
- func AsyncBarrier()
- func ContextCanAccessFile(ctx context.Context, inode *Inode, reqPerms PermMask) bool
- func DirentReaddir(ctx context.Context, d *Dirent, it DirIterator, root *Dirent, dirCtx *DirCtx, ...) (int64, error)
- func GenericMountSourceOptions(data string) map[string]string
- func GenericReaddir(ctx *DirCtx, s *SortedDentryMap) (int, error)
- func IsCharDevice(s StableAttr) bool
- func IsDir(s StableAttr) bool
- func IsFile(s StableAttr) bool
- func IsPipe(s StableAttr) bool
- func IsRegular(s StableAttr) bool
- func IsSocket(s StableAttr) bool
- func IsSymlink(s StableAttr) bool
- func MayDelete(ctx context.Context, root, dir *Dirent, name string) error
- func OffsetPageEnd(offset int64) uint64
- func ReadEndOffset(offset int64, length int64, size int64) int64
- func RegisterFilesystem(f Filesystem)
- func Rename(ctx context.Context, root *Dirent, oldParent *Dirent, oldName string, ...) error
- func SaveFileFsyncError(err error) error
- func SaveInodeMappings()
- func SetRestoreEnvironment(r RestoreEnvironment)
- func SplitFirst(path string) (current, remainder string)
- func SplitLast(path string) (dir, file string)
- func TrimTrailingSlashes(dir string) (trimmed string, changed bool)
- func UnregisterFilesystem(name string)
- func WriteEndOffset(offset int64, length int64) int64
- func XattrOverlayWhiteout(name string) string
- type AttrMask
- type CollectEntriesSerializer
- type DentAttr
- type DentrySerializer
- type DirCtx
- type DirIterator
- type Dirent
- func (d *Dirent) Bind(ctx context.Context, root *Dirent, name string, socket unix.BoundEndpoint, ...) error
- func (d *Dirent) Busy() bool
- func (d *Dirent) Create(ctx context.Context, root *Dirent, name string, flags FileFlags, ...) (*File, error)
- func (d *Dirent) CreateDirectory(ctx context.Context, root *Dirent, name string, perms FilePermissions) error
- func (d *Dirent) CreateFifo(ctx context.Context, root *Dirent, name string, perms FilePermissions) error
- func (d *Dirent) CreateHardLink(ctx context.Context, root *Dirent, target *Dirent, name string) error
- func (d *Dirent) CreateLink(ctx context.Context, root *Dirent, oldname, newname string) error
- func (d *Dirent) DecRef()
- func (d *Dirent) Freeze()
- func (d *Dirent) FullName(root *Dirent) (string, bool)
- func (d *Dirent) IncRef()
- func (d *Dirent) InotifyEvent(events, cookie uint32)
- func (d *Dirent) IsNegative() bool
- func (d *Dirent) IsRoot() bool
- func (d *Dirent) Remove(ctx context.Context, root *Dirent, name string) error
- func (d *Dirent) RemoveDirectory(ctx context.Context, root *Dirent, name string) error
- func (d *Dirent) SyncAll(ctx context.Context)
- func (d *Dirent) TryIncRef() bool
- func (d *Dirent) Walk(ctx context.Context, root *Dirent, name string) (*Dirent, error)
- type DirentCache
- type DirentOperations
- type ErrSaveRejection
- type Event
- type File
- func (f *File) ConfigureMMap(ctx context.Context, opts *memmap.MMapOpts) error
- func (f *File) DecRef()
- func (f *File) DeviceID() uint64
- func (f *File) EventRegister(e *waiter.Entry, mask waiter.EventMask)
- func (f *File) EventUnregister(e *waiter.Entry)
- func (f *File) Flags() FileFlags
- func (f *File) Flush(ctx context.Context) error
- func (f *File) Fsync(ctx context.Context, start int64, end int64, syncType SyncType) error
- func (f *File) InodeID() uint64
- func (f *File) MappedName(ctx context.Context) string
- func (f *File) Msync(ctx context.Context, mr memmap.MappableRange) error
- func (f *File) Offset() int64
- func (f *File) Preadv(ctx context.Context, dst usermem.IOSequence, offset int64) (int64, error)
- func (f *File) Pwritev(ctx context.Context, src usermem.IOSequence, offset int64) (int64, error)
- func (f *File) Readdir(ctx context.Context, serializer DentrySerializer) error
- func (f *File) Readiness(mask waiter.EventMask) waiter.EventMask
- func (f *File) Readv(ctx context.Context, dst usermem.IOSequence) (int64, error)
- func (f *File) Seek(ctx context.Context, whence SeekWhence, offset int64) (int64, error)
- func (f *File) SetFlags(newFlags SettableFileFlags)
- func (f *File) Writev(ctx context.Context, src usermem.IOSequence) (int64, error)
- type FileFlags
- type FileOperations
- type FileOwner
- type FilePermissions
- type FileReader
- type FileWriter
- type Filesystem
- type FilesystemFlags
- type HandleOperations
- type Info
- type Inode
- func NewInode(iops InodeOperations, msrc *MountSource, sattr StableAttr) *Inode
- func NewMockInode(ctx context.Context, msrc *MountSource, sattr StableAttr) *Inode
- func NewOverlayRoot(ctx context.Context, upper *Inode, lower *Inode, flags MountSourceFlags) (*Inode, error)
- func NewTestOverlayDir(ctx context.Context, upper *Inode, lower *Inode) *Inode
- func (i *Inode) AddLink()
- func (i *Inode) Bind(ctx context.Context, name string, data unix.BoundEndpoint, ...) error
- func (i *Inode) BoundEndpoint(path string) unix.BoundEndpoint
- func (i *Inode) CheckCapability(ctx context.Context, cp linux.Capability) bool
- func (i *Inode) CheckOwnership(ctx context.Context) bool
- func (i *Inode) CheckPermission(ctx context.Context, p PermMask) error
- func (i *Inode) Create(ctx context.Context, d *Dirent, name string, flags FileFlags, ...) (*File, error)
- func (i *Inode) CreateDirectory(ctx context.Context, d *Dirent, name string, perm FilePermissions) error
- func (i *Inode) CreateFifo(ctx context.Context, d *Dirent, name string, perm FilePermissions) error
- func (i *Inode) CreateHardLink(ctx context.Context, d *Dirent, target *Dirent, name string) error
- func (i *Inode) CreateLink(ctx context.Context, d *Dirent, oldname string, newname string) error
- func (i *Inode) DecRef()
- func (i *Inode) DropLink()
- func (i *Inode) GetFile(ctx context.Context, d *Dirent, flags FileFlags) (*File, error)
- func (i *Inode) Getlink(ctx context.Context) (*Dirent, error)
- func (i *Inode) Getxattr(name string) ([]byte, error)
- func (i *Inode) HandleOps() HandleOperations
- func (i *Inode) IsVirtual() bool
- func (i *Inode) Listxattr() (map[string]struct{}, error)
- func (i *Inode) Lookup(ctx context.Context, name string) (*Dirent, error)
- func (i *Inode) Mappable() memmap.Mappable
- func (i *Inode) NotifyStatusChange(ctx context.Context)
- func (i *Inode) Readlink(ctx context.Context) (string, error)
- func (i *Inode) Remove(ctx context.Context, d *Dirent, remove *Dirent) error
- func (i *Inode) Rename(ctx context.Context, oldParent *Dirent, renamed *Dirent, newParent *Dirent, ...) error
- func (i *Inode) SetOwner(ctx context.Context, d *Dirent, o FileOwner) error
- func (i *Inode) SetPermissions(ctx context.Context, d *Dirent, f FilePermissions) bool
- func (i *Inode) SetTimestamps(ctx context.Context, d *Dirent, ts TimeSpec) error
- func (i *Inode) StatFS(ctx context.Context) (Info, error)
- func (i *Inode) TestHasLowerFS() bool
- func (i *Inode) TestHasUpperFS() bool
- func (i *Inode) Truncate(ctx context.Context, d *Dirent, size int64) error
- func (i *Inode) UnstableAttr(ctx context.Context) (UnstableAttr, error)
- func (i *Inode) WriteOut(ctx context.Context) error
- type InodeMappings
- type InodeOperations
- type InodeType
- type Inotify
- func (i *Inotify) AddWatch(target *Dirent, mask uint32) int32
- func (*Inotify) ConfigureMMap(context.Context, *File, *memmap.MMapOpts) error
- func (*Inotify) Flush(context.Context, *File) error
- func (*Inotify) Fsync(context.Context, *File, int64, int64, SyncType) error
- func (i *Inotify) Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallArguments) (uintptr, error)
- func (i *Inotify) Read(ctx context.Context, _ *File, dst usermem.IOSequence, _ int64) (int64, error)
- func (*Inotify) Readdir(context.Context, *File, DentrySerializer) (int64, error)
- func (i *Inotify) Readiness(mask waiter.EventMask) waiter.EventMask
- func (i *Inotify) Release()
- func (i *Inotify) RmWatch(wd int32) error
- func (*Inotify) Seek(context.Context, *File, SeekWhence, int64) (int64, error)
- func (*Inotify) Write(context.Context, *File, usermem.IOSequence, int64) (int64, error)
- type LockCtx
- type MockInodeOperations
- func (n *MockInodeOperations) Check(ctx context.Context, inode *Inode, p PermMask) bool
- func (n *MockInodeOperations) Create(ctx context.Context, dir *Inode, p string, flags FileFlags, ...) (*File, error)
- func (n *MockInodeOperations) CreateDirectory(context.Context, *Inode, string, FilePermissions) error
- func (n *MockInodeOperations) CreateLink(_ context.Context, dir *Inode, oldname string, newname string) error
- func (n *MockInodeOperations) DeprecatedPwritev(context.Context, usermem.IOSequence, int64) (int64, error)
- func (n *MockInodeOperations) DeprecatedReaddir(context.Context, *DirCtx, int) (int, error)
- func (n *MockInodeOperations) Getlink(context.Context, *Inode) (*Dirent, error)
- func (n *MockInodeOperations) IsVirtual() bool
- func (n *MockInodeOperations) Lookup(ctx context.Context, dir *Inode, p string) (*Dirent, error)
- func (n *MockInodeOperations) Release(context.Context)
- func (n *MockInodeOperations) Remove(context.Context, *Inode, string) error
- func (n *MockInodeOperations) RemoveDirectory(context.Context, *Inode, string) error
- func (n *MockInodeOperations) Rename(ctx context.Context, oldParent *Inode, oldName string, newParent *Inode, ...) error
- func (*MockInodeOperations) SetOwner(context.Context, *Inode, FileOwner) error
- func (n *MockInodeOperations) SetPermissions(context.Context, *Inode, FilePermissions) bool
- func (n *MockInodeOperations) SetTimestamps(context.Context, *Inode, TimeSpec) error
- func (n *MockInodeOperations) Truncate(ctx context.Context, inode *Inode, size int64) error
- func (n *MockInodeOperations) UnstableAttr(context.Context, *Inode) (UnstableAttr, error)
- func (n *MockInodeOperations) WriteOut(context.Context, *Inode) error
- type MockMountSourceOps
- type MountArgs
- type MountNamespace
- func (mns *MountNamespace) DecRef()
- func (mns *MountNamespace) FindInode(ctx context.Context, root, wd *Dirent, path string, maxTraversals uint) (*Dirent, error)
- func (mns *MountNamespace) FindLink(ctx context.Context, root, wd *Dirent, path string, maxTraversals uint) (*Dirent, error)
- func (mns *MountNamespace) FlushMountSourceRefs()
- func (mns *MountNamespace) Freeze()
- func (mns *MountNamespace) Mount(ctx context.Context, node *Dirent, inode *Inode) error
- func (mns *MountNamespace) Root() *Dirent
- func (mns *MountNamespace) SyncAll(ctx context.Context)
- func (mns *MountNamespace) Unmount(ctx context.Context, node *Dirent, detachOnly bool) error
- func (mns *MountNamespace) UserNamespace() *auth.UserNamespace
- type MountSource
- func NewCachingMountSource(filesystem Filesystem, flags MountSourceFlags) *MountSource
- func NewMockMountSource(cache *DirentCache) *MountSource
- func NewMountSource(mops MountSourceOperations, filesystem Filesystem, flags MountSourceFlags) *MountSource
- func NewNonCachingMountSource(filesystem Filesystem, flags MountSourceFlags) *MountSource
- func (msrc *MountSource) Children() []*MountSource
- func (msrc *MountSource) DecDirentRefs()
- func (msrc *MountSource) DecRef()
- func (msrc *MountSource) DirentRefs() uint64
- func (msrc *MountSource) FlushDirentRefs()
- func (msrc *MountSource) ID() uint64
- func (msrc *MountSource) IncDirentRefs()
- func (msrc *MountSource) Parent() *MountSource
- func (msrc *MountSource) Root() *Dirent
- func (msrc *MountSource) Submounts() []*MountSource
- type MountSourceFlags
- type MountSourceOperations
- type PermMask
- type RestoreEnvironment
- type SeekWhence
- type SettableFileFlags
- type SimpleMountSourceOperations
- type SortedDentryMap
- func (s *SortedDentryMap) Add(name string, entry DentAttr)
- func (s *SortedDentryMap) Contains(name string) bool
- func (s *SortedDentryMap) GetAll() ([]string, map[string]DentAttr)
- func (s *SortedDentryMap) GetNext(cursor string) ([]string, map[string]DentAttr)
- func (s *SortedDentryMap) Remove(name string)
- type StableAttr
- type SyncType
- type TimeSpec
- type UnstableAttr
- type Watch
- type Watches
Constants ¶
const ( // XattrOverlayPrefix is the prefix for extended attributes that affect // the behavior of an overlay. XattrOverlayPrefix = "trusted.overlay." // XattrOverlayWhiteoutPrefix is the prefix for extended attributes // that indicate that a whiteout exists. XattrOverlayWhiteoutPrefix = XattrOverlayPrefix + "whiteout." )
const ( // CtxRoot is a Context.Value key for a Dirent. CtxRoot contextID = iota )
const DefaultTraversalLimit = 10
DefaultTraversalLimit provides a sensible default traversal limit that may be passed to FindInode and FindLink. You may want to provide other options in individual syscall implementations, but for internal functions this will be sane.
const FileMaxOffset = math.MaxInt64
FileMaxOffset is the maximum possible file offset.
Variables ¶
var ( // ErrResolveViaReadlink is a special error value returned by // InodeOperations.Getlink() to indicate that a link should be // resolved automatically by walking to the path returned by // InodeOperations.Readlink(). ErrResolveViaReadlink = errors.New("link should be resolved via Readlink()") )
RootOwner corresponds to KUID/KGID 0/0.
Functions ¶
func AsyncBarrier ¶
func AsyncBarrier()
AsyncBarrier waits for all outstanding asynchronous work to complete.
func ContextCanAccessFile ¶
ContextCanAccessFile determines whether `file` can be accessed in the requested way (for reading, writing, or execution) using the caller's credentials and user namespace, as does Linux's fs/namei.c:generic_permission.
func DirentReaddir ¶
func DirentReaddir(ctx context.Context, d *Dirent, it DirIterator, root *Dirent, dirCtx *DirCtx, offset int64) (int64, error)
DirentReaddir serializes the directory entries of d including "." and "..".
Arguments:
* d: the Dirent of the directory being read; required to provide "." and "..". * it: the directory iterator; which represents an open directory handle. * root: fs root; if d is equal to the root, then '..' will refer to d. * ctx: context provided to file systems in order to select and serialize entries. * offset: the current directory offset.
Returns the offset of the *next* element which was not serialized.
func GenericMountSourceOptions ¶
GenericMountSourceOptions splits a string containing comma separated tokens of the format 'key=value' or 'key' into a map of keys and values. For example:
data = "key0=value0,key1,key2=value2" -> map{'key0':'value0','key1':”,'key2':'value2'}
If data contains duplicate keys, then the last token wins.
func GenericReaddir ¶
func GenericReaddir(ctx *DirCtx, s *SortedDentryMap) (int, error)
GenericReaddir serializes DentAttrs based on a SortedDentryMap that must contain _all_ up-to-date DentAttrs under a directory. If ctx.DirCursor is not nil, it is updated to the name of the last DentAttr that was successfully serialized.
Returns the number of entries serialized.
func IsCharDevice ¶
func IsCharDevice(s StableAttr) bool
IsCharDevice returns true if StableAttr.Type matches a character device.
func IsDir ¶
func IsDir(s StableAttr) bool
IsDir returns true if StableAttr.Type matches any type of directory.
func IsFile ¶
func IsFile(s StableAttr) bool
IsFile returns true if StableAttr.Type matches any type of file.
func IsPipe ¶
func IsPipe(s StableAttr) bool
IsPipe returns true if StableAttr.Type matches any type of pipe.
func IsRegular ¶
func IsRegular(s StableAttr) bool
IsRegular returns true if StableAttr.Type matches a regular file.
func IsSocket ¶
func IsSocket(s StableAttr) bool
IsSocket returns true if StableAttr.Type matches any type of socket.
func IsSymlink ¶
func IsSymlink(s StableAttr) bool
IsSymlink returns true if StableAttr.Type matches a symlink.
func MayDelete ¶
MayDelete determines whether `name`, a child of `dir`, can be deleted or renamed by `ctx`.
Compare Linux kernel fs/namei.c:may_delete.
func OffsetPageEnd ¶
OffsetPageEnd returns the file offset rounded up to the nearest page boundary. OffsetPageEnd panics if rounding up causes overflow, which shouldn't be possible given that offset is an int64.
func ReadEndOffset ¶
ReadEndOffset returns an exclusive end offset for a read operation so that the read does not overflow an int64 nor size.
Parameters: - offset: the starting offset of the read. - length: the number of bytes to read. - size: the size of the file.
Postconditions: The returned offset is >= offset.
func RegisterFilesystem ¶
func RegisterFilesystem(f Filesystem)
RegisterFilesystem registers a new file system that is visible to mount and the /proc/filesystems list. Packages implementing Filesystem should call RegisterFilesystem in init().
func Rename ¶
func Rename(ctx context.Context, root *Dirent, oldParent *Dirent, oldName string, newParent *Dirent, newName string) error
Rename atomically converts the child of oldParent named oldName to a child of newParent named newName.
func SaveFileFsyncError ¶
SaveFileFsyncError converts an fs.File.Fsync error to an error that indicates that the fs.File was not synced sufficiently to be saved.
func SaveInodeMappings ¶
func SaveInodeMappings()
SaveInodeMappings saves a mapping of path -> inode ID for every user-reachable Dirent.
The entire kernel must be frozen to call this, and filesystem state must not change between SaveInodeMappings and state.Save, otherwise the saved state of any MountSource may be incoherent.
func SetRestoreEnvironment ¶
func SetRestoreEnvironment(r RestoreEnvironment)
SetRestoreEnvironment sets the RestoreEnvironment. Must be called before state.Load and only once.
func SplitFirst ¶
SplitFirst splits the given path into a first directory and the remainder.
If remainder is empty, then the path is a single element.
func SplitLast ¶
SplitLast splits the given path into a directory and a file.
The "absoluteness" of the path is preserved, but dir is always stripped of trailing slashes.
func TrimTrailingSlashes ¶
TrimTrailingSlashes trims any trailing slashes.
The returned boolean indicates whether any changes were made.
func UnregisterFilesystem ¶
func UnregisterFilesystem(name string)
UnregisterFilesystem removes a file system from the global set. To keep the file system set compatible with save/restore, UnregisterFilesystem must be called before save/restore methods.
For instance, packages may unregister their file system after it is mounted. This makes sense for pseudo file systems that should not be visible or mountable. See whitelistfs in fs/host/fs.go for one example.
func WriteEndOffset ¶
WriteEndOffset returns an exclusive end offset for a write operation so that the write does not overflow an int64.
Parameters: - offset: the starting offset of the write. - length: the number of bytes to write.
Postconditions: The returned offset is >= offset.
func XattrOverlayWhiteout ¶
XattrOverlayWhiteout returns an extended attribute that indicates a whiteout exists for name. It is supported by directories that wish to mask the existence of name.
Types ¶
type AttrMask ¶
type AttrMask struct { Type bool DeviceID bool InodeID bool BlockSize bool Size bool Usage bool Perms bool UID bool GID bool AccessTime bool ModificationTime bool StatusChangeTime bool Links bool }
AttrMask contains fields to mask StableAttr and UnstableAttr.
type CollectEntriesSerializer ¶
CollectEntriesSerializer copies DentAttrs to Entries. The order in which entries are encountered is preserved in Order.
func (*CollectEntriesSerializer) CopyOut ¶
func (c *CollectEntriesSerializer) CopyOut(name string, attr DentAttr) error
CopyOut implements DentrySerializer.CopyOut.
func (*CollectEntriesSerializer) Written ¶
func (c *CollectEntriesSerializer) Written() int
Written implements DentrySerializer.Written.
type DentAttr ¶
type DentAttr struct { // Type is the InodeType of an Inode. Type InodeType // InodeID uniquely identifies an Inode on a device. InodeID uint64 }
DentAttr is the metadata of a directory entry. It is a subset of StableAttr.
type DentrySerializer ¶
type DentrySerializer interface { // CopyOut serializes a directory entry based on its name and attributes. CopyOut(name string, attributes DentAttr) error // Written returns the number of bytes written. Written() int }
DentrySerializer serializes a directory entry.
type DirCtx ¶
type DirCtx struct { // Serializer is used to serialize the node attributes. Serializer DentrySerializer // DirCursor is the directory cursor. // TODO: Once Handles are removed this can just live in the // respective FileOperations implementations and not need to get // plumbed everywhere. DirCursor *string // contains filtered or unexported fields }
DirCtx is used by node.Readdir to emit directory entries. It is not thread-safe.
type DirIterator ¶
type DirIterator interface { // IterateDir emits directory entries by calling dirCtx.EmitDir, beginning // with the entry at offset and returning the next directory offset. // // Entries for "." and ".." must *not* be included. // // If the offset returned is the same as the argument offset, then // nothing has been serialized. This is equivalent to reaching EOF. // In this case serializer.Written() should return 0. // // The order of entries to emit must be consistent between Readdir // calls, and must start with the given offset. // // The caller must ensure that this operation is permitted. IterateDir(ctx context.Context, dirCtx *DirCtx, offset int) (int, error) }
DirIterator is an open directory containing directory entries that can be read.
type Dirent ¶
type Dirent struct { // AtomicRefCount is our reference count. refs.AtomicRefCount // Inode is the underlying file object. // // Inode is exported currently to assist in implementing overlay Inodes (where a // Inode.InodeOperations.Lookup may need to merge the Inode contained in a positive Dirent with // another Inode). This is normally done before the Dirent is parented (there are // no external references to it). // // Other objects in the VFS may take a reference to this Inode but only while holding // a reference to this Dirent. Inode *Inode // contains filtered or unexported fields }
Dirent holds an Inode in memory.
A Dirent may be negative or positive:
A negative Dirent contains a nil Inode and indicates that a path does not exist. This is a convention taken from the Linux dcache, see fs/dcache.c. A negative Dirent remains cached until a create operation replaces it with a positive Dirent. A negative Dirent always has one reference owned by its parent and takes _no_ reference on its parent. This ensures that its parent can be unhashed regardless of negative children.
A positive Dirent contains a non-nil Inode. It remains cached for as long as there remain references to it. A positive Dirent always takes a reference on its parent.
A Dirent may be a root Dirent (parent is nil) or be parented (non-nil parent).
Dirents currently do not attempt to free entries that lack application references under memory pressure.
func NewDirent ¶
NewDirent returns a new root Dirent, taking the caller's reference on inode. The caller holds the only reference to the Dirent. Parents may call hashChild to parent this Dirent.
func NewNegativeDirent ¶
NewNegativeDirent returns a new root negative Dirent. Otherwise same as NewDirent.
func NewTransientDirent ¶
NewTransientDirent creates a transient Dirent that shouldn't actually be visible to users.
func RootFromContext ¶
RootFromContext returns the root of the virtual filesystem observed by ctx, or nil if ctx is not associated with a virtual filesystem. If RootFromContext returns a non-nil fs.Dirent, a reference is taken on it.
func (*Dirent) Bind ¶
func (d *Dirent) Bind(ctx context.Context, root *Dirent, name string, socket unix.BoundEndpoint, perms FilePermissions) error
Bind satisfies the InodeOperations interface; otherwise same as GetFile.
func (*Dirent) Busy ¶
Busy indicates whether this Dirent is a mount point or root dirent, or has active positive children.
This is expensive, since it flushes the children cache.
TODO: Fix this busy-ness check.
func (*Dirent) Create ¶
func (d *Dirent) Create(ctx context.Context, root *Dirent, name string, flags FileFlags, perms FilePermissions) (*File, error)
Create creates a new regular file in this directory.
func (*Dirent) CreateDirectory ¶
func (d *Dirent) CreateDirectory(ctx context.Context, root *Dirent, name string, perms FilePermissions) error
CreateDirectory creates a new directory under this dirent.
func (*Dirent) CreateFifo ¶
func (d *Dirent) CreateFifo(ctx context.Context, root *Dirent, name string, perms FilePermissions) error
CreateFifo creates a new named pipe under this dirent.
func (*Dirent) CreateHardLink ¶
func (d *Dirent) CreateHardLink(ctx context.Context, root *Dirent, target *Dirent, name string) error
CreateHardLink creates a new hard link in this directory.
func (*Dirent) CreateLink ¶
CreateLink creates a new link in this directory.
func (*Dirent) DecRef ¶
func (d *Dirent) DecRef()
DecRef decreases the Dirent's refcount and drops its reference on its mount.
DecRef implements RefCounter.DecRef with destructor d.destroy.
func (*Dirent) Freeze ¶
func (d *Dirent) Freeze()
Freeze prevents this dirent from walking to more nodes. Freeze is applied recursively to all children.
If this particular Dirent represents a Virtual node, then Walks and Creates may proceed as before.
Freeze can only be called before the application starts running, otherwise the root it might be out of sync with the application root if modified by sys_chroot.
func (*Dirent) FullName ¶
FullName returns the fully-qualified name and a boolean value representing whether this Dirent was a descendant of root. If the root argument is nil it is assumed to be the root of the Dirent tree.
func (*Dirent) IncRef ¶
func (d *Dirent) IncRef()
IncRef increases the Dirent's refcount as well as its mount's refcount.
IncRef implements RefCounter.IncRef.
func (*Dirent) InotifyEvent ¶
InotifyEvent notifies all watches on the inode for this dirent and its parent of potential events. The events may not actually propagate up to the user, depending on the event masks. InotifyEvent automatically provides the name of the current dirent as the subject of the event as required, and adds the IN_ISDIR flag for dirents that refer to directories.
func (*Dirent) IsNegative ¶
IsNegative returns true if d represents a path that does not exist.
func (*Dirent) Remove ¶
Remove removes the given file or symlink. The root dirent is used to resolve name, and must not be nil.
func (*Dirent) RemoveDirectory ¶
RemoveDirectory removes the given directory. The root dirent is used to resolve name, and must not be nil.
func (*Dirent) SyncAll ¶
SyncAll iterates through mount points under d and writes back their buffered modifications to filesystems.
type DirentCache ¶
type DirentCache struct {
// contains filtered or unexported fields
}
DirentCache is an LRU cache of Dirents. The Dirent's refCount is incremented when it is added to the cache, and decremented when it is removed.
A nil DirentCache corresponds to a cache with size 0. All methods can be called, but nothing is actually cached.
func NewDirentCache ¶
func NewDirentCache(maxSize uint64) *DirentCache
NewDirentCache returns a new DirentCache with the given maxSize. If maxSize is 0, nil is returned.
func (*DirentCache) Add ¶
func (c *DirentCache) Add(d *Dirent)
Add adds the element to the cache and increments the refCount. If the argument is already in the cache, it is moved to the front. An element is removed from the back if the cache is over capacity.
func (*DirentCache) Invalidate ¶
func (c *DirentCache) Invalidate()
Invalidate removes all Dirents from the cache, caling DecRef on each.
func (*DirentCache) Remove ¶
func (c *DirentCache) Remove(d *Dirent)
Remove removes the element from the cache and decrements its refCount. It also sets the previous and next elements to nil, which allows us to determine if a given element is in the cache.
func (*DirentCache) Size ¶
func (c *DirentCache) Size() uint64
Size returns the number of elements in the cache.
type DirentOperations ¶
type DirentOperations interface { // Revalidate returns true if the Dirent is stale and its InodeOperations needs to be reloaded. Revalidate // will never be called on a Dirent that is mounted. Revalidate(dirent *Dirent) bool // Keep returns true if the Dirent should be kept in memory for as long as possible // beyond any active references. Keep(dirent *Dirent) bool }
DirentOperations provide file systems greater control over how long a Dirent stays pinned in core. Implementations must not take Dirent.mu.
type ErrSaveRejection ¶
type ErrSaveRejection struct { // Err is the wrapped error. Err error }
ErrSaveRejection indicates a failed save due to unsupported file system state such as dangling open fd, etc.
func (ErrSaveRejection) Error ¶
func (e ErrSaveRejection) Error() string
Error returns a sensible description of the save rejection error.
type Event ¶
Event represents a struct inotify_event from linux.
type File ¶
type File struct { refs.AtomicRefCount // UniqueID is the globally unique identifier of the File. UniqueID uint64 // Dirent is the Dirent backing this File. This encodes the name // of the File via Dirent.FullName() as well as its identity via the // Dirent's Inode. The Dirent is non-nil. // // A File holds a reference to this Dirent. Using the returned Dirent is // only safe as long as a reference on the File is held. The association // between a File and a Dirent is immutable. // // Files that are not parented in a filesystem return a root Dirent // that holds a reference to their Inode. // // The name of the Dirent may reflect parentage if the Dirent is not a // root Dirent or the identity of the File on a pseudo filesystem (pipefs, // sockfs, etc). // // Multiple Files may hold a reference to the same Dirent. This is the // common case for Files that are parented and maintain consistency with // other files via the Dirent cache. Dirent *Dirent // FileOperations implements file system specific behavior for this File. FileOperations FileOperations // contains filtered or unexported fields }
File is an open file handle. It is thread-safe.
File provides stronger synchronization guarantees than Linux. Linux synchronizes lseek(2), read(2), and write(2) with respect to the file offset for regular files and only for those interfaces. See fs/read_write.c:fdget_pos, fs.read_write.c:fdput_pos and FMODE_ATOMIC_POS.
In contrast, File synchronizes any operation that could take a long time under a single abortable mutex which also synchronizes lseek(2), read(2), and write(2).
FIXME: Split synchronization from cancellation.
func NewFile ¶
NewFile returns a File. It takes a reference on the Dirent and owns the lifetime of the FileOperations. Files that do not support reading and writing at an arbitrary offset should set flags.Pread and flags.Pwrite to false respectively.
func (*File) ConfigureMMap ¶
ConfigureMMap calls f.FileOperations.ConfigureMMap with f as the File.
Returns syserror.ErrInterrupted if interrupted.
func (*File) DecRef ¶
func (f *File) DecRef()
DecRef destroys the File when it is no longer referenced.
func (*File) EventRegister ¶
EventRegister implements waiter.Waitable.EventRegister.
func (*File) EventUnregister ¶
EventUnregister implements waiter.Waitable.EventUnregister.
func (*File) Flush ¶
Flush calls f.FileOperations.Flush with f as the File.
Returns syserror.ErrInterrupted if syncing was interrupted.
func (*File) Fsync ¶
Fsync calls f.FileOperations.Fsync with f as the File.
Returns syserror.ErrInterrupted if syncing was interrupted.
func (*File) MappedName ¶
MappedName implements memmap.MappingIdentity.MappedName.
func (*File) Preadv ¶
Preadv calls f.FileOperations.Read with f as the File. It does not advance the file offset. If !f.Flags().Pread, Preadv should not be called.
Otherwise same as Readv.
func (*File) Pwritev ¶
Pwritev calls f.FileOperations.Write with f as the File. It does not advance the file offset. If !f.Flags().Pwritev, Pwritev should not be called.
Otherwise same as Writev.
func (*File) Readdir ¶
func (f *File) Readdir(ctx context.Context, serializer DentrySerializer) error
Readdir reads the directory entries of this File and writes them out to the DentrySerializer until entries can no longer be written. If even a single directory entry is written then Readdir returns a nil error and the directory offset is advanced.
Readdir unconditionally updates the access time on the File's Inode, see fs/readdir.c:iterate_dir.
Returns syserror.ErrInterrupted if reading was interrupted.
func (*File) Readv ¶
Readv calls f.FileOperations.Read with f as the File, advancing the file offset if f.FileOperations.Read returns bytes read > 0.
Returns syserror.ErrInterrupted if reading was interrupted.
func (*File) Seek ¶
Seek calls f.FileOperations.Seek with f as the File, updating the file offset to the value returned by f.FileOperations.Seek if the operation is successful.
Returns syserror.ErrInterrupted if seeking was interrupted.
func (*File) SetFlags ¶
func (f *File) SetFlags(newFlags SettableFileFlags)
SetFlags atomically changes the File's flags to the values contained in newFlags. See SettableFileFlags for values that can be set.
func (*File) Writev ¶
Writev calls f.FileOperations.Write with f as the File, advancing the file offset if f.FileOperations.Write returns bytes written > 0.
Writev positions the write offset at EOF if f.Flags().Append. This is unavoidably racy for network file systems. Writev also truncates src to avoid overrunning the current file size limit if necessary.
Returns syserror.ErrInterrupted if writing was interrupted.
type FileFlags ¶
type FileFlags struct { // Direct indicates that I/O should be done directly. Direct bool // NonBlocking indicates that I/O should not block. NonBlocking bool // Sync indicates that any writes should be synchronous. Sync bool // Append indicates this file is append only. Append bool // Read indicates this file is readable. Read bool // Write indicates this file is writeable. Write bool // Pread indicates this file is readable at an arbitrary offset. Pread bool // Pwrite indicates this file is writable at an arbitrary offset. Pwrite bool // Directory indicates that this file must be a directory. Directory bool }
FileFlags encodes file flags.
func (FileFlags) Settable ¶
func (f FileFlags) Settable() SettableFileFlags
Settable returns the subset of f that are settable.
type FileOperations ¶
type FileOperations interface { // Release release resources held by FileOperations. Release() // Waitable defines how this File can be waited on for read and // write readiness. waiter.Waitable // Seek seeks to offset based on SeekWhence. Returns the new // offset or no change in the offset and an error. Seek(ctx context.Context, file *File, whence SeekWhence, offset int64) (int64, error) // Readdir reads the directory entries of file and serializes them // using serializer. // // Returns the new directory offset or no change in the offset and // an error. The offset returned must not be less than file.Offset(). // // Serialization of directory entries must not happen asynchronously. Readdir(ctx context.Context, file *File, serializer DentrySerializer) (int64, error) // Read reads from file into dst at offset and returns the number // of bytes read which must be greater than or equal to 0. File // systems that do not support reading at an offset, (i.e. pipefs, // sockfs) may ignore the offset. These file systems are expected // to construct Files with !FileFlags.Pread. // // Read may return a nil error and only partially fill dst (at or // before EOF). If the file represents a symlink, Read reads the target // value of the symlink. // // Read does not check permissions nor flags. // // Read must not be called if !FileFlags.Read. Read(ctx context.Context, file *File, dst usermem.IOSequence, offset int64) (int64, error) // Write writes src to file at offset and returns the number of bytes // written which must be greater than or equal to 0. Like Read, file // systems that do not support writing at an offset (i.e. pipefs, sockfs) // may ignore the offset. These file systems are expected to construct // Files with !FileFlags.Pwrite. // // If only part of src could be written, Write must return an error // indicating why (e.g. syserror.ErrWouldBlock). // // Write does not check permissions nor flags. // // Write must not be called if !FileFlags.Write. Write(ctx context.Context, file *File, src usermem.IOSequence, offset int64) (int64, error) // Fsync writes buffered modifications of file and/or flushes in-flight // operations to backing storage based on syncType. The range to sync is // [start, end]. The end is inclusive so that the last byte of a maximally // sized file can be synced. Fsync(ctx context.Context, file *File, start, end int64, syncType SyncType) error // Flush this file's buffers/state (on close(2)). Flush(ctx context.Context, file *File) error // ConfigureMMap mutates opts to implement mmap(2) for the file. Most // implementations can either embed fsutil.NoMMap (if they don't support // memory mapping) or call fsutil.GenericConfigureMMap with the appropriate // memmap.Mappable. ConfigureMMap(ctx context.Context, file *File, opts *memmap.MMapOpts) error // Ioctl implements the ioctl(2) linux syscall. // // io provides access to the virtual memory space to which pointers in args // refer. // // Preconditions: The AddressSpace (if any) that io refers to is activated. Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallArguments) (uintptr, error) }
FileOperations are operations on a File that diverge per file system.
Operations that take a *File may use only the following interfaces:
- File.UniqueID: Operations may only read this value.
- File.Dirent: Operations must not take or drop a reference.
- File.Offset(): This value is guaranteed to not change for the duration of the operation.
- File.Flags(): This value may change during the operation.
type FileOwner ¶
FileOwner represents ownership of a file.
func FileOwnerFromContext ¶
FileOwnerFromContext returns a FileOwner using the effective user and group IDs used by ctx.
type FilePermissions ¶
type FilePermissions struct { User PermMask Group PermMask Other PermMask // Sticky, if set on directories, restricts renaming and deletion of // files in those directories to the directory owner, file owner, or // CAP_FOWNER. The sticky bit is ignored when set on other files. Sticky bool // SetUID executables can call UID-setting syscalls without CAP_SETUID. SetUID bool // SetGID executables can call GID-setting syscalls without CAP_SETGID. SetGID bool }
FilePermissions represents the permissions of a file, with Read/Write/Execute bits for user, group, and other.
func FilePermsFromMode ¶
func FilePermsFromMode(mode linux.FileMode) (fp FilePermissions)
FilePermsFromMode converts a system file mode to a FilePermissions struct.
func FilePermsFromP9 ¶
func FilePermsFromP9(mode p9.FileMode) FilePermissions
FilePermsFromP9 converts a p9.FileMode to a FilePermissions struct.
func (FilePermissions) AnyExecute ¶
func (f FilePermissions) AnyExecute() bool
AnyExecute returns true if any of U/G/O have the execute bit set.
func (FilePermissions) AnyRead ¶
func (f FilePermissions) AnyRead() bool
AnyRead returns true if any of U/G/O have the read bit set.
func (FilePermissions) AnyWrite ¶
func (f FilePermissions) AnyWrite() bool
AnyWrite returns true if any of U/G/O have the write bit set.
func (FilePermissions) LinuxMode ¶
func (f FilePermissions) LinuxMode() linux.FileMode
LinuxMode returns the linux mode_t representation of these permissions.
func (FilePermissions) OSMode ¶
func (f FilePermissions) OSMode() os.FileMode
OSMode returns the Go runtime's OS independent os.FileMode representation of these permissions.
type FileReader ¶
type FileReader struct { // Ctx is the context for the file reader. Ctx context.Context // File is the file to read from. File *File }
FileReader implements io.Reader and io.ReaderAt.
type FileWriter ¶
type FileWriter struct { // Ctx is the context for the file writer. Ctx context.Context // File is the file to write to. File *File }
FileWriter implements io.Writer and io.WriterAt.
type Filesystem ¶
type Filesystem interface { // Name is the unique identifier of the file system. It corresponds to the // filesystemtype argument of sys_mount and will appear in the output of // /proc/filesystems. Name() string // Flags indicate common properties of the file system. Flags() FilesystemFlags // Mount generates a mountable Inode backed by device and configured // using file system independent flags and file system dependent // data options. Mount(ctx context.Context, device string, flags MountSourceFlags, data string) (*Inode, error) // AllowUserMount determines whether mount(2) is allowed to mount a // file system of this type. AllowUserMount() bool }
Filesystem is a mountable file system.
func FindFilesystem ¶
func FindFilesystem(name string) (Filesystem, bool)
FindFilesystem returns a Filesystem registered at name or (nil, false) if name is not a file system type that can be found in /proc/filesystems.
func GetFilesystems ¶
func GetFilesystems() []Filesystem
GetFilesystems returns the set of registered filesystems in a consistent order.
type FilesystemFlags ¶
type FilesystemFlags int
FilesystemFlags matches include/linux/fs.h:file_system_type.fs_flags.
const ( // FilesystemRequiresDev indicates that the file system requires a device name // on mount. It is used to construct the output of /proc/filesystems. FilesystemRequiresDev FilesystemFlags = 1 )
type HandleOperations ¶
type HandleOperations interface { waiter.Waitable // DeprecatedPreadv is deprecated in favor of filesystems // implementing File.Preadv directly. // // DeprecatedPreadv reads up to dst.NumBytes() bytes into dst, starting at // the given offset, and returns the number of bytes read. // // Preadv may return a partial read result before EOF is reached. // // If a symlink, Preadv reads the target value of the symlink. // // Preadv should not check for readable permissions. DeprecatedPreadv(ctx context.Context, dst usermem.IOSequence, offset int64) (int64, error) // DeprecatedPwritev is deprecated in favor of filesystems // implementing File.Pwritev directly. // // DeprecatedPwritev writes up to src.NumBytes() bytes from src to the // Inode, starting at the given offset and returns the number of bytes // written. // // Pwritev should not check that the Inode has writable permissions. DeprecatedPwritev(ctx context.Context, src usermem.IOSequence, offset int64) (int64, error) // DeprecatedReaddir is deprecated in favor of filesystems // implementing File.Readdir directly. // // DeprecatedReaddir emits directory entries by calling dirCtx.EmitDir, // beginning with the entry at offset. // // Entries for "." and ".." must *not* be included. // // If the offset returned is the same as the argument offset, then // nothing has been serialized. This is equivalent to reaching EOF. // In this case serializer.Written() should return 0. // // The order of entries to emit must be consistent between Readdir // calls, and must start with the given offset. // // The caller must ensure that this operation is permitted. DeprecatedReaddir(ctx context.Context, dirCtx *DirCtx, offset int) (int, error) // DeprecatedFsync is deprecated in favor of filesystems implementing // File.Fsync directly. // // DeprecatedFsync syncs a file. DeprecatedFsync() error // DeprecatedMappable is deprecated in favor of filesystems implementing // File.Mappable directly. // // DeprecatedMappable returns a Mappable if the Inode can be mapped. DeprecatedMappable(ctx context.Context, inode *Inode) (memmap.Mappable, bool) // DeprecatedFlush is deprecated in favor of filesystems implementing // File.Flush directly. // // DeprecatedFlush flushes a file. // // Implementations may choose to free up memory or complete pending I/O // but also may implement Flush as a no-op. DeprecatedFlush() error }
HandleOperations are extended InodeOperations that are only implemented for file systems that use fs/handle.go:Handle to generate open Files.
Handle is deprecated; these methods are deprecated as well.
Filesystems are encouraged to implement the File interface directly instead of using Handle. To indicate that the below methods should never be called, embed DeprecatedFileOperations to satisfy this interface.
type Info ¶
type Info struct { // Type is the filesystem type magic value. Type uint64 // TotalBlocks is the total data blocks in the filesystem. TotalBlocks uint64 // FreeBlocks is the number of free blocks available. FreeBlocks uint64 // TotalFiles is the total file nodes in the filesystem. TotalFiles uint64 // FreeFiles is the number of free file nodes. FreeFiles uint64 }
Info defines attributes of a filesystem.
type Inode ¶
type Inode struct { // AtomicRefCount is our reference count. refs.AtomicRefCount // InodeOperations is the file system specific behavior of the Inode. InodeOperations InodeOperations // StableAttr are stable cached attributes of the Inode. StableAttr StableAttr // LockCtx is the file lock context. It manages its own sychronization and tracks // regions of the Inode that have locks held. LockCtx LockCtx // Watches is the set of inotify watches for this inode. Watches *Watches // MountSource is the mount source this Inode is a part of. MountSource *MountSource // contains filtered or unexported fields }
Inode is a file system object that can be simulatenously referenced by different components of the VFS (Dirent, fs.File, etc).
func NewInode ¶
func NewInode(iops InodeOperations, msrc *MountSource, sattr StableAttr) *Inode
NewInode constructs an Inode from InodeOperations, a MountSource, and stable attributes.
NewInode takes a reference on msrc.
func NewMockInode ¶
func NewMockInode(ctx context.Context, msrc *MountSource, sattr StableAttr) *Inode
NewMockInode returns a mock *Inode using MockInodeOperations.
func NewOverlayRoot ¶
func NewOverlayRoot(ctx context.Context, upper *Inode, lower *Inode, flags MountSourceFlags) (*Inode, error)
NewOverlayRoot produces the root of an overlay.
Preconditions:
- upper and lower must be non-nil.
- lower should not expose character devices, pipes, or sockets, because copying up these types of files is not supported.
- upper and lower must not require that file objects be revalidated.
- upper and lower must not have dynamic file/directory content.
func NewTestOverlayDir ¶
NewTestOverlayDir returns an overlay Inode for tests.
func (*Inode) Bind ¶
func (i *Inode) Bind(ctx context.Context, name string, data unix.BoundEndpoint, perm FilePermissions) error
Bind calls i.InodeOperations.Bind with i as the directory.
func (*Inode) BoundEndpoint ¶
func (i *Inode) BoundEndpoint(path string) unix.BoundEndpoint
BoundEndpoint calls i.InodeOperations.BoundEndpoint with i as the Inode.
func (*Inode) CheckCapability ¶
CheckCapability checks whether `ctx` has capability `cp` with respect to operations on this Inode.
Compare Linux's kernel/capability.c:capable_wrt_inode_uidgid(). Note that this function didn't exist in Linux 3.11.10, but was added by upstream 23adbe12ef7d "fs,userns: Change inode_capable to capable_wrt_inode_uidgid" to fix local privilege escalation CVE-2014-4014.
func (*Inode) CheckOwnership ¶
CheckOwnership checks whether `ctx` owns this Inode or may act as its owner. Compare Linux's fs/inode.c:inode_owner_or_capable().
func (*Inode) CheckPermission ¶
CheckPermission will check if the caller may access this file in the requested way for reading, writing, or executing.
CheckPermission is like Linux's fs/namei.c:inode_permission. It - checks file system mount flags, - and utilizes InodeOperations.Check to check capabilities and modes.
func (*Inode) Create ¶
func (i *Inode) Create(ctx context.Context, d *Dirent, name string, flags FileFlags, perm FilePermissions) (*File, error)
Create calls i.InodeOperations.Create with i as the directory.
func (*Inode) CreateDirectory ¶
func (i *Inode) CreateDirectory(ctx context.Context, d *Dirent, name string, perm FilePermissions) error
CreateDirectory calls i.InodeOperations.CreateDirectory with i as the directory.
func (*Inode) CreateFifo ¶
CreateFifo calls i.InodeOperations.CreateFifo with i as the directory.
func (*Inode) CreateHardLink ¶
CreateHardLink calls i.InodeOperations.CreateHardLink with i as the directory.
func (*Inode) CreateLink ¶
CreateLink calls i.InodeOperations.CreateLink with i as the directory.
func (*Inode) HandleOps ¶
func (i *Inode) HandleOps() HandleOperations
HandleOps extracts HandleOperations from i.
func (*Inode) NotifyStatusChange ¶
NotifyStatusChange calls i.InodeOperations.NotifyStatusChange.
func (*Inode) Remove ¶
Remove calls i.InodeOperations.Remove/RemoveDirectory with i as the directory.
func (*Inode) Rename ¶
func (i *Inode) Rename(ctx context.Context, oldParent *Dirent, renamed *Dirent, newParent *Dirent, newName string) error
Rename calls i.InodeOperations.Rename with the given arguments.
func (*Inode) SetPermissions ¶
SetPermissions calls i.InodeOperations.SetPermissions with i as the Inode.
func (*Inode) SetTimestamps ¶
SetTimestamps calls i.InodeOperations.SetTimestamps with i as the Inode.
func (*Inode) TestHasLowerFS ¶
TestHasLowerFS returns true if i is an overlay Inode and it has a pointer to an Inode on a lower filesystem.
func (*Inode) TestHasUpperFS ¶
TestHasUpperFS returns true if i is an overlay Inode and it has a pointer to an Inode on an upper filesystem.
func (*Inode) UnstableAttr ¶
func (i *Inode) UnstableAttr(ctx context.Context) (UnstableAttr, error)
UnstableAttr calls i.InodeOperations.UnstableAttr with i as the Inode.
type InodeMappings ¶
InodeMappings defines a fmt.Stringer MountSource Inode mappings.
func (InodeMappings) String ¶
func (i InodeMappings) String() string
String implements fmt.Stringer.String.
type InodeOperations ¶
type InodeOperations interface { // Release releases all private file system data held by this object. // Once Release is called, this object is dead (no other methods will // ever be called). Release(context.Context) // Lookup loads an Inode at name under dir into a Dirent. The name // is a valid component path: it contains no "/"s nor is the empty // string. // // Lookup may return one of: // // * A nil Dirent and a non-nil error. If the reason that Lookup failed // was because the name does not exist under Inode, then must return // syserror.ENOENT. // // * If name does not exist under dir and the file system wishes this // fact to be cached, a non-nil Dirent containing a nil Inode and a // nil error. This is a negative Dirent and must have exactly one // reference (at-construction reference). // // * If name does exist under this dir, a non-nil Dirent containing a // non-nil Inode, and a nil error. File systems that take extra // references on this Dirent should implement DirentOperations. Lookup(ctx context.Context, dir *Inode, name string) (*Dirent, error) // Create creates an Inode at name under dir and returns a new File // whose Dirent backs the new Inode. Implementations must ensure that // name does not already exist. Create may return one of: // // * A nil File and a non-nil error. // // * A non-nil File and a nil error. File.Dirent will be a new Dirent, // with a single reference held by File. File systems that take extra // references on this Dirent should implement DirentOperations. // // The caller must ensure that this operation is permitted. Create(ctx context.Context, dir *Inode, name string, flags FileFlags, perm FilePermissions) (*File, error) // CreateDirectory creates a new directory under this dir. // CreateDirectory should otherwise do the same as Create. // // The caller must ensure that this operation is permitted. CreateDirectory(ctx context.Context, dir *Inode, name string, perm FilePermissions) error // CreateLink creates a symbolic link under dir between newname // and oldname. CreateLink should otherwise do the same as Create. // // The caller must ensure that this operation is permitted. CreateLink(ctx context.Context, dir *Inode, oldname string, newname string) error // CreateHardLink creates a hard link under dir between the target // Inode and name. Implementations must ensure that name does not // already exist. // // The caller must ensure this operation is permitted. CreateHardLink(ctx context.Context, dir *Inode, target *Inode, name string) error // CreateFifo creates a new named pipe under dir at name. // Implementations must ensure that an Inode at name does not // already exist. // // The caller must ensure that this operation is permitted. CreateFifo(ctx context.Context, dir *Inode, name string, perm FilePermissions) error // Remove removes the given named non-directory under dir. // // The caller must ensure that this operation is permitted. // // TODO: merge Remove and RemoveDirectory, Remove // just needs a type flag. Remove(ctx context.Context, dir *Inode, name string) error // RemoveDirectory removes the given named directory under dir. // // The caller must ensure that this operation is permitted. // // RemoveDirectory should check that the directory to be // removed is empty. RemoveDirectory(ctx context.Context, dir *Inode, name string) error // Rename atomically renames oldName under oldParent to newName // under newParent where oldParent and newParent are directories. // // Implementations are responsible for rejecting renames that // replace non-empty directories. Rename(ctx context.Context, oldParent *Inode, oldName string, newParent *Inode, newName string) error // Bind binds a new socket under dir at the given name. // Implementations must ensure that name does not already exist. // // The caller must ensure that this operation is permitted. Bind(ctx context.Context, dir *Inode, name string, data unix.BoundEndpoint, perm FilePermissions) error // BoundEndpoint returns the socket endpoint at path stored in // or generated by an Inode. // // The path is only relevant for generated endpoint because stored // endpoints already know their path. It is ok for the endpoint to // hold onto their path because the only way to change a bind // address is to rebind the socket. // // This is valid iff the type of the Inode is a Socket, which // generally implies that this Inode was created via CreateSocket. // // If there is no socket endpoint available, nil will be returned. BoundEndpoint(inode *Inode, path string) unix.BoundEndpoint // GetFile returns a new open File backed by a Dirent and FileFlags. // It may block as long as it is done with ctx. // // The returned File will uniquely back an application fd. GetFile(ctx context.Context, d *Dirent, flags FileFlags) (*File, error) // UnstableAttr returns the most up-to-date "unstable" attributes of // an Inode, where "unstable" means that they change in response to // file system events. UnstableAttr(ctx context.Context, inode *Inode) (UnstableAttr, error) // Getxattr retrieves the value of extended attribute name. Inodes that // do not support extended attributes return EOPNOTSUPP. Inodes that // support extended attributes but don't have a value at name return // ENODATA. Getxattr(inode *Inode, name string) ([]byte, error) // Setxattr sets the value of extended attribute name. Inodes that // do not support extended attributes return EOPNOTSUPP. Setxattr(inode *Inode, name string, value []byte) error // Listxattr returns the set of all extended attributes names that // have values. Inodes that do not support extended attributes return // EOPNOTSUPP. Listxattr(inode *Inode) (map[string]struct{}, error) // Check determines whether an Inode can be accessed with the // requested permission mask using the context (which gives access // to Credentials and UserNamespace). Check(ctx context.Context, inode *Inode, p PermMask) bool // SetPermissions sets new permissions for an Inode. Returns false // if it was not possible to set the new permissions. // // The caller must ensure that this operation is permitted. SetPermissions(ctx context.Context, inode *Inode, f FilePermissions) bool // SetOwner sets the ownership for this file. // // If either UID or GID are set to auth.NoID, its value will not be // changed. // // The caller must ensure that this operation is permitted. SetOwner(ctx context.Context, inode *Inode, owner FileOwner) error // SetTimestamps sets the access and modification timestamps of an // Inode according to the access and modification times in the TimeSpec. // // If either ATimeOmit or MTimeOmit is set, then the corresponding // timestamp is not updated. // // If either ATimeSetSystemTime or MTimeSetSystemTime is true, that // timestamp is set to the current time instead. // // The caller must ensure that this operation is permitted. SetTimestamps(ctx context.Context, inode *Inode, ts TimeSpec) error // Truncate changes the size of an Inode. Truncate should not check // permissions internally, as it is used for both sys_truncate and // sys_ftruncate. // // Implementations need not check that length >= 0. Truncate(ctx context.Context, inode *Inode, size int64) error // WriteOut writes cached Inode state to a backing filesystem in a // synchronous manner. // // File systems that do not cache metadata or data via an Inode // implement WriteOut as a no-op. File systems that are entirely in // memory also implement WriteOut as a no-op. Otherwise file systems // call Inode.Sync to write back page cached data and cached metadata // followed by syncing writeback handles. // // It derives from include/linux/fs.h:super_operations->write_inode. WriteOut(ctx context.Context, inode *Inode) error // Readlink reads the symlink path of an Inode. // // Readlink is permitted to return a different path depending on ctx, // the request originator. // // The caller must ensure that this operation is permitted. // // Readlink should check that Inode is a symlink and its content is // at least readable. Readlink(ctx context.Context, inode *Inode) (string, error) // Getlink resolves a symlink to a target *Dirent. // // Filesystems that can resolve the link by walking to the path returned // by Readlink should return (nil, ErrResolveViaReadlink), which // triggers link resolution via Realink and Lookup. // // Some links cannot be followed by Lookup. In this case, Getlink can // return the Dirent of the link target. The caller holds a reference // to the Dirent. Filesystems that return a non-nil *Dirent from Getlink // cannot participate in an overlay because it is impossible for the // overlay to ascertain whether or not the *Dirent should contain an // overlayEntry. // // Any error returned from Getlink other than ErrResolveViaReadlink // indicates the caller's inability to traverse this Inode as a link // (e.g. syserror.ENOLINK indicates that the Inode is not a link, // syscall.EPERM indicates that traversing the link is not allowed, etc). Getlink(context.Context, *Inode) (*Dirent, error) // Mappable returns a memmap.Mappable that provides memory mappings of the // Inode's data. Mappable may return nil if this is not supported. The // returned Mappable must remain valid until InodeOperations.Release is // called. Mappable(*Inode) memmap.Mappable // AddLink increments the hard link count of an Inode. // // Remove in favor of Inode.IncLink. AddLink() // DropLink decrements the hard link count of an Inode. // // Remove in favor of Inode.DecLink. DropLink() // NotifyStatusChange sets the status change time to the current time. // // Remove in favor of updating the Inode's cached status change time. NotifyStatusChange(ctx context.Context) // IsVirtual indicates whether or not this corresponds to a virtual // resource. // // If IsVirtual returns true, then caching will be disabled for this // node, and fs.Dirent.Freeze() will not stop operations on the node. // // Remove in favor of freezing specific mounts. IsVirtual() bool // StatFS returns a filesystem Info implementation or an error. If // the filesystem does not support this operation (maybe in the future // it will), then ENOSYS should be returned. // // Move to MountSourceOperations. StatFS(context.Context) (Info, error) HandleOperations }
InodeOperations are operations on an Inode that diverge per file system.
Objects that implement InodeOperations may cache file system "private" data that is useful for implementing these methods. In contrast, Inode contains state that is common to all Inodes; this state may be optionally used by InodeOperations. An object that implements InodeOperations may not take a reference on an Inode.
type InodeType ¶
type InodeType int
InodeType enumerates types of Inodes.
const ( // RegularFile is a regular file. RegularFile InodeType = iota // SpecialFile is a file that doesn't support SeekEnd. It is used for // things like proc files. SpecialFile // Directory is a directory. Directory // SpecialDirectory is a directory that *does* support SeekEnd. It's // the opposite of the SpecialFile scenario above. It similarly // supports proc files. SpecialDirectory // Symlink is a symbolic link. Symlink // Pipe is a pipe (named or regular). Pipe // Socket is a socket. Socket // CharacterDevice is a character device. CharacterDevice // BlockDevice is a block device. BlockDevice // Anonymous is an anonymous type when none of the above apply. // Epoll fds and event-driven fds fit this category. Anonymous )
type Inotify ¶
Inotify represents an inotify instance created by inotify_init(2) or inotify_init1(2). Inotify implements the FileOperations interface.
Lock ordering:
Inotify.mu -> Inode.Watches.mu -> Watch.mu -> Inotify.evMu
func NewInotify ¶
NewInotify constructs a new Inotify instance.
func (*Inotify) AddWatch ¶
AddWatch constructs a new inotify watch and adds it to the target dirent. It returns the watch descriptor returned by inotify_add_watch(2).
func (*Inotify) ConfigureMMap ¶
ConfigureMMap implements FileOperations.ConfigureMMap.
func (*Inotify) Ioctl ¶
func (i *Inotify) Ioctl(ctx context.Context, io usermem.IO, args arch.SyscallArguments) (uintptr, error)
Ioctl implements fs.FileOperations.Ioctl.
func (*Inotify) Read ¶
func (i *Inotify) Read(ctx context.Context, _ *File, dst usermem.IOSequence, _ int64) (int64, error)
Read implements FileOperations.Read.
func (*Inotify) Readiness ¶
Readiness implements waiter.Waitable.Readiness.
Readiness indicates whether there are pending events for an inotify instance.
func (*Inotify) Release ¶
func (i *Inotify) Release()
Release implements FileOperations.Release. Release removes all watches and frees all resources for an inotify instance.
func (*Inotify) RmWatch ¶
RmWatch implements watcher.Watchable.RmWatch.
RmWatch looks up an inotify watch for the given 'wd' and configures the target dirent to stop sending events to this inotify instance.
type LockCtx ¶
type LockCtx struct { // Posix is a set of POSIX-style regional advisory locks, see fcntl(2). Posix lock.Locks // BSD is a set of BSD-style advisory file wide locks, see flock(2). BSD lock.Locks }
LockCtx is an Inode's lock context and contains different personalities of locks; both Posix and BSD style locks are supported.
Note that in Linux fcntl(2) and flock(2) locks are _not_ cooperative, because race and deadlock conditions make merging them prohibitive. We do the same and keep them oblivious to each other but provide a "context" as a convenient container.
type MockInodeOperations ¶
type MockInodeOperations struct { InodeOperations UAttr UnstableAttr // contains filtered or unexported fields }
MockInodeOperations implements InodeOperations for testing Inodes.
func NewMockInodeOperations ¶
func NewMockInodeOperations(ctx context.Context) *MockInodeOperations
NewMockInodeOperations returns a *MockInodeOperations.
func (*MockInodeOperations) Create ¶
func (n *MockInodeOperations) Create(ctx context.Context, dir *Inode, p string, flags FileFlags, perms FilePermissions) (*File, error)
Create implements fs.InodeOperations.Create.
func (*MockInodeOperations) CreateDirectory ¶
func (n *MockInodeOperations) CreateDirectory(context.Context, *Inode, string, FilePermissions) error
CreateDirectory implements fs.InodeOperations.CreateDirectory.
func (*MockInodeOperations) CreateLink ¶
func (n *MockInodeOperations) CreateLink(_ context.Context, dir *Inode, oldname string, newname string) error
CreateLink implements fs.InodeOperations.CreateLink.
func (*MockInodeOperations) DeprecatedPwritev ¶
func (n *MockInodeOperations) DeprecatedPwritev(context.Context, usermem.IOSequence, int64) (int64, error)
DeprecatedPwritev implements fs.InodeOperations.DeprecatedPwritev.
func (*MockInodeOperations) DeprecatedReaddir ¶
DeprecatedReaddir implements fs.InodeOperations.DeprecatedReaddir.
func (*MockInodeOperations) IsVirtual ¶
func (n *MockInodeOperations) IsVirtual() bool
IsVirtual implements fs.InodeOperations.IsVirtual.
func (*MockInodeOperations) Release ¶
func (n *MockInodeOperations) Release(context.Context)
Release implements fs.InodeOperations.Release.
func (*MockInodeOperations) RemoveDirectory ¶
RemoveDirectory implements fs.InodeOperations.RemoveDirectory.
func (*MockInodeOperations) Rename ¶
func (n *MockInodeOperations) Rename(ctx context.Context, oldParent *Inode, oldName string, newParent *Inode, newName string) error
Rename implements fs.InodeOperations.Rename.
func (*MockInodeOperations) SetPermissions ¶
func (n *MockInodeOperations) SetPermissions(context.Context, *Inode, FilePermissions) bool
SetPermissions implements fs.InodeOperations.SetPermissions.
func (*MockInodeOperations) SetTimestamps ¶
SetTimestamps implements fs.InodeOperations.SetTimestamps.
func (*MockInodeOperations) UnstableAttr ¶
func (n *MockInodeOperations) UnstableAttr(context.Context, *Inode) (UnstableAttr, error)
UnstableAttr implements fs.InodeOperations.UnstableAttr.
type MockMountSourceOps ¶
type MockMountSourceOps struct { MountSourceOperations // contains filtered or unexported fields }
MockMountSourceOps implements fs.MountSourceOperations.
func (*MockMountSourceOps) Keep ¶
func (n *MockMountSourceOps) Keep(dirent *Dirent) bool
Keep implements fs.MountSourceOperations.Keep.
func (*MockMountSourceOps) Revalidate ¶
func (n *MockMountSourceOps) Revalidate(*Dirent) bool
Revalidate implements fs.MountSourceOperations.Revalidate.
type MountArgs ¶
type MountArgs struct { // Dev corresponds to the devname argumnent of Mount. Dev string // Flags corresponds to the flags argument of Mount. Flags MountSourceFlags // Data corresponds to the data argument of Mount. Data string }
MountArgs holds arguments to Mount.
type MountNamespace ¶
type MountNamespace struct { refs.AtomicRefCount // contains filtered or unexported fields }
MountNamespace defines a collection of mounts.
func NewMountNamespace ¶
func NewMountNamespace(ctx context.Context, root *Inode) (*MountNamespace, error)
NewMountNamespace returns a new MountNamespace, with the provided node at the root, and the given cache size. A root must always be provided.
func (*MountNamespace) DecRef ¶
func (mns *MountNamespace) DecRef()
DecRef implements RefCounter.DecRef with destructor mns.destroy.
func (*MountNamespace) FindInode ¶
func (mns *MountNamespace) FindInode(ctx context.Context, root, wd *Dirent, path string, maxTraversals uint) (*Dirent, error)
FindInode is identical to FindLink except the return value is resolved.
func (*MountNamespace) FindLink ¶
func (mns *MountNamespace) FindLink(ctx context.Context, root, wd *Dirent, path string, maxTraversals uint) (*Dirent, error)
FindLink returns an Dirent from a given node, which may be a symlink.
The root argument is treated as the root directory, and FindLink will not return anything above that. The wd dirent provides the starting directory, and may be nil which indicates the root should be used. You must call DecRef on the resulting Dirent when you are no longer using the object.
If wd is nil, then the root will be used as the working directory. If the path is absolute, this has no functional impact.
Precondition: root must be non-nil. Precondition: the path must be non-empty.
func (*MountNamespace) FlushMountSourceRefs ¶
func (mns *MountNamespace) FlushMountSourceRefs()
FlushMountSourceRefs flushes extra references held by MountSources for all active mount points; see fs/mount.go:MountSource.FlushDirentRefs.
func (*MountNamespace) Freeze ¶
func (mns *MountNamespace) Freeze()
Freeze freezes the entire mount tree.
func (*MountNamespace) Root ¶
func (mns *MountNamespace) Root() *Dirent
Root returns the MountNamespace's root Dirent and increments its reference count. The caller must call DecRef when finished.
func (*MountNamespace) SyncAll ¶
func (mns *MountNamespace) SyncAll(ctx context.Context)
SyncAll calls Dirent.SyncAll on the root.
func (*MountNamespace) Unmount ¶
Unmount ensures no references to the MountSource remain and removes `node` from this subtree. The subtree formerly mounted in `node`'s place will be restored. node's MountSource will be destroyed as soon as the last reference to `node` is dropped, as no references to Dirents within will remain.
If detachOnly is set, Unmount merely removes `node` from the subtree, but allows existing references to the MountSource remain. E.g. if an open file still refers to Dirents in MountSource, the Unmount will succeed anyway and MountSource will be destroyed at a later time when all references to Dirents within are dropped.
The caller must hold a reference to node from walking to it.
func (*MountNamespace) UserNamespace ¶
func (mns *MountNamespace) UserNamespace() *auth.UserNamespace
UserNamespace returns the user namespace associated with this mount manager.
type MountSource ¶
type MountSource struct { refs.AtomicRefCount // MountSourceOperations defines filesystem specific behavior. MountSourceOperations // Filesystem is the filesystem backing the mount. Can be nil if there // is no filesystem backing the mount. Filesystem Filesystem // Flags are the flags that this filesystem was mounted with. Flags MountSourceFlags // contains filtered or unexported fields }
MountSource represents a source of file objects.
MountSource corresponds to struct super_block in Linux.
A mount source may represent a physical device (or a partition of a physical device) or a virtual source of files such as procfs for a specific PID namespace. There should be only one mount source per logical device. E.g. there should be only procfs mount source for a given PID namespace.
A mount source represents files as inodes. Every inode belongs to exactly one mount source. Each file object may only be represented using one inode object in a sentry instance.
This is an amalgamation of structs super_block, vfsmount, and mount, while MountSourceOperations is akin to struct super_operations.
Hence, mount source also contains common mounted file system state, such as mount flags, the root Dirent, and children mounts. For now, this amalgamation implies that a mount source cannot be shared by multiple mounts (e.g. cannot be mounted at different locations).
TODO: Move mount-specific information out of MountSource.
func NewCachingMountSource ¶
func NewCachingMountSource(filesystem Filesystem, flags MountSourceFlags) *MountSource
NewCachingMountSource returns a generic mount that will cache dirents aggressively. Filesystem may be nil if there is no backing filesystem.
func NewMockMountSource ¶
func NewMockMountSource(cache *DirentCache) *MountSource
NewMockMountSource returns a new *MountSource using MockMountSourceOps.
func NewMountSource ¶
func NewMountSource(mops MountSourceOperations, filesystem Filesystem, flags MountSourceFlags) *MountSource
NewMountSource returns a new MountSource. Filesystem may be nil if there is no filesystem backing the mount.
func NewNonCachingMountSource ¶
func NewNonCachingMountSource(filesystem Filesystem, flags MountSourceFlags) *MountSource
NewNonCachingMountSource returns a generic mount that will never cache dirents. Filesystem may be nil if there is no backing filesystem.
func (*MountSource) Children ¶
func (msrc *MountSource) Children() []*MountSource
Children returns the (immediate) children of this MountSource.
func (*MountSource) DecDirentRefs ¶
func (msrc *MountSource) DecDirentRefs()
DecDirentRefs decrements direntRefs.
func (*MountSource) DecRef ¶
func (msrc *MountSource) DecRef()
DecRef drops a reference on the MountSource.
func (*MountSource) DirentRefs ¶
func (msrc *MountSource) DirentRefs() uint64
DirentRefs returns the current mount direntRefs.
func (*MountSource) FlushDirentRefs ¶
func (msrc *MountSource) FlushDirentRefs()
FlushDirentRefs drops all references held by the MountSource on Dirents.
func (*MountSource) IncDirentRefs ¶
func (msrc *MountSource) IncDirentRefs()
IncDirentRefs increases direntRefs.
func (*MountSource) Parent ¶
func (msrc *MountSource) Parent() *MountSource
Parent returns the parent mount, or nil if this mount is the root.
func (*MountSource) Root ¶
func (msrc *MountSource) Root() *Dirent
Root returns the root dirent of this mount.
func (*MountSource) Submounts ¶
func (msrc *MountSource) Submounts() []*MountSource
Submounts returns all mounts that are descendants of this mount.
type MountSourceFlags ¶
type MountSourceFlags struct { // ReadOnly corresponds to mount(2)'s "MS_RDONLY" and indicates that // the filesystem should be mounted read-only. ReadOnly bool // NoAtime corresponds to mount(2)'s "MS_NOATIME" and indicates that // the filesystem should not update access time in-place. NoAtime bool // ForcePageCache causes all filesystem I/O operations to use the page // cache, even when the platform supports direct mapped I/O. This // doesn't correspond to any Linux mount options. ForcePageCache bool }
MountSourceFlags represents all mount option flags as a struct.
type MountSourceOperations ¶
type MountSourceOperations interface { // DirentOperations provide optional extra management of Dirents. DirentOperations // Destroy destroys the MountSource. Destroy() // ResetInodeMappings clears all mappings of Inodes before SaveInodeMapping // is called. ResetInodeMappings() // SaveInodeMappings is called during saving to store, for each reachable // Inode in the mounted filesystem, a mapping of Inode.StableAttr.InodeID // to the Inode's path relative to its mount point. If an Inode is // reachable at more than one path due to hard links, it is unspecified // which path is mapped. Filesystems that do not use this information to // restore inodes can make SaveInodeMappings a no-op. SaveInodeMapping(inode *Inode, path string) }
MountSourceOperations contains filesystem specific operations.
type PermMask ¶
type PermMask struct { // Read indicates reading is permitted. Read bool // Write indicates writing is permitted. Write bool // Execute indicates execution is permitted. Execute bool }
PermMask are file access permissions.
func PermsFromMode ¶
PermsFromMode takes the Other permissions (last 3 bits) of a FileMode and returns a set of PermMask.
func (PermMask) Mode ¶
Mode returns the system mode (syscall.S_IXOTH, etc.) for these permissions in the "other" bits.
func (PermMask) SupersetOf ¶
SupersetOf returns true iff the permissions in p are a superset of the permissions in other.
type RestoreEnvironment ¶
type RestoreEnvironment struct { // MountSources maps Filesystem.Name() to mount arguments. MountSources map[string][]MountArgs // ValidateFileSize indicates file size should not change across S/R. ValidateFileSize bool // ValidateFileTimestamp indicates file modification timestamp should // not change across S/R. ValidateFileTimestamp bool }
RestoreEnvironment is the restore environment for file systems. It consists of things that change across save and restore and therefore cannot be saved in the object graph.
func CurrentRestoreEnvironment ¶
func CurrentRestoreEnvironment() (RestoreEnvironment, bool)
CurrentRestoreEnvironment returns the current, read-only RestoreEnvironment. If no RestoreEnvironment was ever set, returns (_, false).
type SeekWhence ¶
type SeekWhence int
SeekWhence determines seek direction.
const ( // SeekSet sets the absolute offset. SeekSet SeekWhence = iota // SeekCurrent sets relative to the current position. SeekCurrent // SeekEnd sets relative to the end of the file. SeekEnd )
func (SeekWhence) String ¶
func (s SeekWhence) String() string
String returns a human readable string for whence.
type SettableFileFlags ¶
type SettableFileFlags struct { // Direct indicates that I/O should be done directly. Direct bool // NonBlocking indicates that I/O should not block. NonBlocking bool // Append indicates this file is append only. Append bool }
SettableFileFlags is a subset of FileFlags above that can be changed via fcntl(2) using the F_SETFL command.
type SimpleMountSourceOperations ¶
type SimpleMountSourceOperations struct {
// contains filtered or unexported fields
}
SimpleMountSourceOperations implements MountSourceOperations.
func (*SimpleMountSourceOperations) Destroy ¶
func (*SimpleMountSourceOperations) Destroy()
Destroy implements MountSourceOperations.Destroy.
func (*SimpleMountSourceOperations) Keep ¶
func (smo *SimpleMountSourceOperations) Keep(*Dirent) bool
Keep implements MountSourceOperations.Keep.
func (*SimpleMountSourceOperations) ResetInodeMappings ¶
func (*SimpleMountSourceOperations) ResetInodeMappings()
ResetInodeMappings implements MountSourceOperations.ResetInodeMappings.
func (*SimpleMountSourceOperations) Revalidate ¶
func (*SimpleMountSourceOperations) Revalidate(*Dirent) bool
Revalidate implements MountSourceOperations.Revalidate.
func (*SimpleMountSourceOperations) SaveInodeMapping ¶
func (*SimpleMountSourceOperations) SaveInodeMapping(*Inode, string)
SaveInodeMapping implements MountSourceOperations.SaveInodeMapping.
type SortedDentryMap ¶
type SortedDentryMap struct {
// contains filtered or unexported fields
}
SortedDentryMap is a sorted map of names and fs.DentAttr entries.
func NewSortedDentryMap ¶
func NewSortedDentryMap(entries map[string]DentAttr) *SortedDentryMap
NewSortedDentryMap maintains entries in name sorted order.
func (*SortedDentryMap) Add ¶
func (s *SortedDentryMap) Add(name string, entry DentAttr)
Add adds an entry with the given name to the map, preserving sort order. If name already exists in the map, its entry will be overwritten.
func (*SortedDentryMap) Contains ¶
func (s *SortedDentryMap) Contains(name string) bool
Contains reports whether the map contains an entry with the given name.
func (*SortedDentryMap) GetAll ¶
func (s *SortedDentryMap) GetAll() ([]string, map[string]DentAttr)
GetAll returns all names and entries in s.
func (*SortedDentryMap) GetNext ¶
func (s *SortedDentryMap) GetNext(cursor string) ([]string, map[string]DentAttr)
GetNext returns names after cursor in s and all entries.
func (*SortedDentryMap) Remove ¶
func (s *SortedDentryMap) Remove(name string)
Remove removes an entry with the given name from the map, preserving sort order.
type StableAttr ¶
type StableAttr struct { // Type is the InodeType of a InodeOperations. Type InodeType // DeviceID is the device on which a InodeOperations resides. DeviceID uint64 // InodeID uniquely identifies InodeOperations on its device. InodeID uint64 // BlockSize is the block size of data backing this InodeOperations. BlockSize int64 // DeviceFileMajor is the major device number of this Node, if it is a // device file. DeviceFileMajor uint16 // DeviceFileMinor is the minor device number of this Node, if it is a // device file. DeviceFileMinor uint32 }
StableAttr contains Inode attributes that will be stable throughout the lifetime of the Inode.
type SyncType ¶
type SyncType int
SyncType enumerates ways in which a File can be synced.
const ( // SyncAll indicates that modified in-memory metadata and data should // be written to backing storage. SyncAll implies SyncBackingStorage. SyncAll SyncType = iota // SyncData indicates that along with modified in-memory data, only // metadata needed to access that data needs to be written. // // For example, changes to access time or modification time do not // need to be written because they are not necessary for a data read // to be handled correctly, unlike the file size. // // The aim of SyncData is to reduce disk activity for applications // that do not require all metadata to be synchronized with the disk, // see fdatasync(2). File systems that implement SyncData as SyncAll // do not support this optimization. // // SyncData implies SyncBackingStorage. SyncData // SyncBackingStorage indicates that in-flight write operations to // backing storage should be flushed. SyncBackingStorage )
type TimeSpec ¶
type TimeSpec struct { ATime ktime.Time ATimeOmit bool ATimeSetSystemTime bool MTime ktime.Time MTimeOmit bool MTimeSetSystemTime bool }
TimeSpec contains access and modification timestamps. If either ATimeOmit or MTimeOmit is true, then the corresponding timestamp should not be updated. If either ATimeSetSystemTime or MTimeSetSystemTime are set then the corresponding timestamp should be ignored and the time will be set to the current system time.
type UnstableAttr ¶
type UnstableAttr struct { // Size is the file size in bytes. Size int64 // Usage is the actual data usage in bytes. Usage int64 // Perms is the protection (read/write/execute for user/group/other). Perms FilePermissions // Owner describes the ownership of this file. Owner FileOwner // AccessTime is the time of last access AccessTime ktime.Time // ModificationTime is the time of last modification. ModificationTime ktime.Time // StatusChangeTime is the time of last attribute modification. StatusChangeTime ktime.Time // Links is the number of hard links. Links uint64 }
UnstableAttr contains Inode attributes that may change over the lifetime of the Inode.
func WithCurrentTime ¶
func WithCurrentTime(ctx context.Context, u UnstableAttr) UnstableAttr
WithCurrentTime returns u with AccessTime == ModificationTime == current time.
type Watch ¶
type Watch struct {
// contains filtered or unexported fields
}
Watch represent a particular inotify watch created by inotify_add_watch.
While a watch is active, it ensures the target inode is pinned in memory by holding an extra ref on each dirent known (by inotify) to point to the inode. These are known as pins. For a full discussion, see fs/g3doc/inotify.md.
func (*Watch) NotifyParentAfterUnlink ¶
NotifyParentAfterUnlink indicates whether the parent of the watched object should continue to be be notified of events after the target has been unlinked.
func (*Watch) Pin ¶
Pin acquires a new ref on dirent, which pins the dirent in memory while the watch is active. Calling Pin for a second time on the same dirent for the same watch is a no-op.
func (*Watch) TargetDestroyed ¶
func (w *Watch) TargetDestroyed()
TargetDestroyed notifies the owner of the watch that the watch target is gone. The owner should release its own references to the watcher upon receiving this notification.
type Watches ¶
type Watches struct {
// contains filtered or unexported fields
}
Watches is the collection of inotify watches on an inode.
func (*Watches) Add ¶
Add adds watch into this set of watches. The watch being added must be unique - its ID() should not collide with any existing watches.
func (*Watches) Lookup ¶
Lookup returns a matching watch with the given id. Returns nil if no such watch exists. Note that the result returned by this method only remains valid if the inotify instance owning the watch is locked, preventing modification of the returned watch and preventing the replacement of the watch by another one from the same instance (since there may be at most one watch per instance, per target).
func (*Watches) MarkUnlinked ¶
func (w *Watches) MarkUnlinked()
MarkUnlinked indicates the target for this set of watches to be unlinked. This has implications for the IN_EXCL_UNLINK flag.
Source Files ¶
- attr.go
- context.go
- copy_up.go
- dentry.go
- dirent.go
- dirent_cache.go
- dirent_state.go
- file.go
- file_operations.go
- file_overlay.go
- file_state.go
- filesystems.go
- flags.go
- fs.go
- inode.go
- inode_inotify.go
- inode_operations.go
- inode_overlay.go
- inotify.go
- inotify_event.go
- inotify_watch.go
- mock.go
- mount.go
- mount_overlay.go
- mount_state.go
- mounts.go
- offset.go
- overlay.go
- path.go
- restore.go
- save.go
- seek.go
- sync.go
Directories ¶
Path | Synopsis |
---|---|
Package anon implements an anonymous inode, useful for implementing inodes for pseudo filesystems.
|
Package anon implements an anonymous inode, useful for implementing inodes for pseudo filesystems. |
Package ashmem implements Android ashmem module (Anonymus Shared Memory).
|
Package ashmem implements Android ashmem module (Anonymus Shared Memory). |
Package binder implements Android Binder IPC module.
|
Package binder implements Android Binder IPC module. |
Package dev provides a filesystem with simple devices.
|
Package dev provides a filesystem with simple devices. |
Package fdpipe implements common namedpipe opening and accessing logic.
|
Package fdpipe implements common namedpipe opening and accessing logic. |
Package filetest provides a test implementation of an fs.File.
|
Package filetest provides a test implementation of an fs.File. |
Package fsutil provides utilities for implementing fs.InodeOperations and fs.FileOperations:
|
Package fsutil provides utilities for implementing fs.InodeOperations and fs.FileOperations: |
Package gofer implements a remote 9p filesystem.
|
Package gofer implements a remote 9p filesystem. |
Package host implements an fs.Filesystem for files backed by host file descriptors.
|
Package host implements an fs.Filesystem for files backed by host file descriptors. |
Package lock is the API for POSIX-style advisory regional file locks and BSD-style full file locks.
|
Package lock is the API for POSIX-style advisory regional file locks and BSD-style full file locks. |
Package proc implements a partial in-memory file system for profs.
|
Package proc implements a partial in-memory file system for profs. |
device
Package device contains the proc device to avoid dependency loops.
|
Package device contains the proc device to avoid dependency loops. |
Package ramfs implements an in-memory file system that can be associated with any device.
|
Package ramfs implements an in-memory file system that can be associated with any device. |
test
Package test provides a simple ramfs-based filesystem for use in testing.
|
Package test provides a simple ramfs-based filesystem for use in testing. |
Package sys implements a sysfs filesystem.
|
Package sys implements a sysfs filesystem. |
Package timerfd implements the semantics of Linux timerfd objects as described by timerfd_create(2).
|
Package timerfd implements the semantics of Linux timerfd objects as described by timerfd_create(2). |
Package tmpfs is a filesystem implementation backed by memory.
|
Package tmpfs is a filesystem implementation backed by memory. |
Package tty provide pseudoterminals via a devpts filesystem.
|
Package tty provide pseudoterminals via a devpts filesystem. |