package host
import "gvisor.dev/gvisor/pkg/sentry/fsimpl/host"
Package host provides a filesystem implementation for host files imported as file descriptors.
Index ¶
- func MakeRestoreID(containerName string, fd int) vfs.RestoreID
- func NewFD(ctx context.Context, mnt *vfs.Mount, hostFD int, opts *NewFDOptions) (*vfs.FileDescription, error)
- func NewFilesystem(vfsObj *vfs.VirtualFilesystem) (*vfs.Filesystem, error)
- type NewFDOptions
- type TTYFileDescription
- func (f *TTYFileDescription) Allocate(ctx context.Context, mode, offset, length uint64) error
- func (f *TTYFileDescription) ConfigureMMap(_ context.Context, opts *memmap.MMapOpts) error
- func (f *TTYFileDescription) Epollable() bool
- func (f *TTYFileDescription) EventRegister(e *waiter.Entry) error
- func (f *TTYFileDescription) EventUnregister(e *waiter.Entry)
- func (t *TTYFileDescription) Ioctl(ctx context.Context, io usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error)
- func (t *TTYFileDescription) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error)
- func (t *TTYFileDescription) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error)
- func (t *TTYFileDescription) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error)
- func (f *TTYFileDescription) Readiness(mask waiter.EventMask) waiter.EventMask
- func (f *TTYFileDescription) Release(context.Context)
- func (f *TTYFileDescription) Seek(_ context.Context, offset int64, whence int32) (int64, error)
- func (f *TTYFileDescription) SetStat(ctx context.Context, opts vfs.SetStatOptions) error
- func (f *TTYFileDescription) Stat(ctx context.Context, opts vfs.StatOptions) (linux.Statx, error)
- func (f *TTYFileDescription) Sync(ctx context.Context) error
- func (t *TTYFileDescription) TTY() *kernel.TTY
- func (t *TTYFileDescription) ThreadGroup() *kernel.ThreadGroup
- func (t *TTYFileDescription) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error)
Functions ¶
func MakeRestoreID ¶
MakeRestoreID creates a RestoreID for a given application FD. The application FD remains the same between restores, e.g. stdout=2 before and after restore, but the host FD that is maps to can change between restores. This ID is used to map application FDs to their respective FD after a restore happens.
func NewFD ¶
func NewFD(ctx context.Context, mnt *vfs.Mount, hostFD int, opts *NewFDOptions) (*vfs.FileDescription, error)
NewFD returns a vfs.FileDescription representing the given host file descriptor. mnt must be Kernel.HostMount().
func NewFilesystem ¶
func NewFilesystem(vfsObj *vfs.VirtualFilesystem) (*vfs.Filesystem, error)
NewFilesystem sets up and returns a new hostfs filesystem.
Note that there should only ever be one instance of host.filesystem, a global mount for host fds.
Types ¶
type NewFDOptions ¶
type NewFDOptions struct { // If Savable is true, the host file descriptor may be saved/restored by // numeric value. RestoreKey is used to map the FD after restore. Savable bool // RestoreKey is only used when Savable==true. It uniquely identifies the // host FD so that a mapping to the corresponding FD can be provided during // restore. RestoreKey vfs.RestoreID // Restorable is true if hostFD may be restored. This can be set to false // for host FDs that are not going to be present after restore. Restorable bool // If IsTTY is true, the file descriptor is a TTY. IsTTY bool // If HaveFlags is true, use Flags for the new file description. Otherwise, // the new file description will inherit flags from hostFD. HaveFlags bool Flags uint32 // VirtualOwner allow the host file to have owner and permissions different // than the underlying host file. VirtualOwner bool UID auth.KUID GID auth.KGID // If Readonly is true, we disallow operations that can potentially change // the host file associated with the file descriptor. Readonly bool }
NewFDOptions contains options to NewFD.
type TTYFileDescription ¶
type TTYFileDescription struct {
// contains filtered or unexported fields
}
TTYFileDescription implements vfs.FileDescriptionImpl for a host file descriptor that wraps a TTY FD.
It implements kernel.TTYOperations.
+stateify savable
func (*TTYFileDescription) Allocate ¶
Allocate implements vfs.FileDescriptionImpl.Allocate.
func (*TTYFileDescription) ConfigureMMap ¶
ConfigureMMap implements vfs.FileDescriptionImpl.ConfigureMMap.
func (*TTYFileDescription) Epollable ¶
func (f *TTYFileDescription) Epollable() bool
Epollable implements FileDescriptionImpl.Epollable.
func (*TTYFileDescription) EventRegister ¶
EventRegister implements waiter.Waitable.EventRegister.
func (*TTYFileDescription) EventUnregister ¶
EventUnregister implements waiter.Waitable.EventUnregister.
func (*TTYFileDescription) Ioctl ¶
func (t *TTYFileDescription) Ioctl(ctx context.Context, io usermem.IO, sysno uintptr, args arch.SyscallArguments) (uintptr, error)
Ioctl implements vfs.FileDescriptionImpl.Ioctl.
func (*TTYFileDescription) PRead ¶
func (t *TTYFileDescription) PRead(ctx context.Context, dst usermem.IOSequence, offset int64, opts vfs.ReadOptions) (int64, error)
PRead implements vfs.FileDescriptionImpl.PRead.
Reading from a TTY is only allowed for foreground process groups. Background process groups will either get EIO or a SIGTTIN.
func (*TTYFileDescription) PWrite ¶
func (t *TTYFileDescription) PWrite(ctx context.Context, src usermem.IOSequence, offset int64, opts vfs.WriteOptions) (int64, error)
PWrite implements vfs.FileDescriptionImpl.PWrite.
func (*TTYFileDescription) Read ¶
func (t *TTYFileDescription) Read(ctx context.Context, dst usermem.IOSequence, opts vfs.ReadOptions) (int64, error)
Read implements vfs.FileDescriptionImpl.Read.
Reading from a TTY is only allowed for foreground process groups. Background process groups will either get EIO or a SIGTTIN.
func (*TTYFileDescription) Readiness ¶
Readiness uses the poll() syscall to check the status of the underlying FD.
func (*TTYFileDescription) Release ¶
Release implements vfs.FileDescriptionImpl.Release.
func (*TTYFileDescription) Seek ¶
Seek implements vfs.FileDescriptionImpl.Seek.
Note that we do not support seeking on directories, since we do not even allow directory fds to be imported at all.
func (*TTYFileDescription) SetStat ¶
func (f *TTYFileDescription) SetStat(ctx context.Context, opts vfs.SetStatOptions) error
SetStat implements vfs.FileDescriptionImpl.SetStat.
func (*TTYFileDescription) Stat ¶
Stat implements vfs.FileDescriptionImpl.Stat.
func (*TTYFileDescription) Sync ¶
Sync implements vfs.FileDescriptionImpl.Sync.
func (*TTYFileDescription) TTY ¶
func (t *TTYFileDescription) TTY() *kernel.TTY
TTY returns the kernel.TTY.
func (*TTYFileDescription) ThreadGroup ¶
func (t *TTYFileDescription) ThreadGroup() *kernel.ThreadGroup
ThreadGroup returns the kernel.ThreadGroup associated with this tty.
func (*TTYFileDescription) Write ¶
func (t *TTYFileDescription) Write(ctx context.Context, src usermem.IOSequence, opts vfs.WriteOptions) (int64, error)
Write implements vfs.FileDescriptionImpl.Write.
Source Files ¶
host.go host_unsafe.go ioctl_unsafe.go save_restore.go tty.go util.go util_unsafe.go
- Version
- v0.0.0-20250605235530-a6711d1e1dc6 (latest)
- Published
- Jun 5, 2025
- Platform
- linux/amd64
- Imports
- 31 packages
- Last checked
- 4 hours ago –
Tools for package owners.