gvisor: gvisor.dev/gvisor/pkg/fd Index | Files

package fd

import "gvisor.dev/gvisor/pkg/fd"

Package fd provides types for working with file descriptors.


Package Files


type FD Uses

type FD struct {

FD owns a host file descriptor.

It is similar to os.File, with a few important distinctions:

FD provies a Release() method which relinquishes ownership. Like os.File, FD adds a finalizer to close the backing FD. However, the finalizer cannot be removed from os.File, forever pinning the lifetime of an FD to its os.File.

FD supports both blocking and non-blocking operation. os.File only supports blocking operation.

func New Uses

func New(fd int) *FD

New creates a new FD.

New takes ownership of fd.

func NewFromFile Uses

func NewFromFile(file *os.File) (*FD, error)

NewFromFile creates a new FD from an os.File.

NewFromFile does not transfer ownership of the file descriptor (it will be duplicated, so both the os.File and FD will eventually need to be closed and some (but not all) changes made to the FD will be applied to the os.File as well).

The returned FD is always blocking (Go 1.9+).

func NewFromFiles Uses

func NewFromFiles(files []*os.File) ([]*FD, error)

NewFromFiles creates new FDs for each file in the slice.

func Open Uses

func Open(path string, openmode int, perm uint32) (*FD, error)

Open is equivalent to open(2).

func OpenAt Uses

func OpenAt(dir *FD, path string, flags int, mode uint32) (*FD, error)

OpenAt is equivalent to openat(2).

func (*FD) Close Uses

func (f *FD) Close() error

Close closes the file descriptor contained in the FD.

Close is safe to call multiple times, but will return an error after the first call.

Concurrently calling Close and any other method is undefined.

func (*FD) File Uses

func (f *FD) File() (*os.File, error)

File converts the FD to an os.File.

FD does not transfer ownership of the file descriptor (it will be duplicated, so both the FD and os.File will eventually need to be closed and some (but not all) changes made to the os.File will be applied to the FD as well).

This operation is somewhat expensive, so care should be taken to minimize its use.

func (*FD) Release Uses

func (f *FD) Release() int

Release relinquishes ownership of the contained file descriptor.

Concurrently calling Release and any other method is undefined.

func (*FD) ReleaseToFile Uses

func (f *FD) ReleaseToFile(name string) *os.File

ReleaseToFile returns an os.File that takes ownership of the FD.

name is passed to os.NewFile.

type ReadWriter Uses

type ReadWriter struct {
    // contains filtered or unexported fields

ReadWriter implements io.ReadWriter, io.ReaderAt, and io.WriterAt for fd. It does not take ownership of fd.

func NewReadWriter Uses

func NewReadWriter(fd int) *ReadWriter

NewReadWriter creates a ReadWriter for fd.

func (*ReadWriter) FD Uses

func (r *ReadWriter) FD() int

FD returns the owned file descriptor. Ownership remains unchanged.

func (*ReadWriter) Read Uses

func (r *ReadWriter) Read(b []byte) (int, error)

Read implements io.Reader.

func (*ReadWriter) ReadAt Uses

func (r *ReadWriter) ReadAt(b []byte, off int64) (c int, err error)

ReadAt implements io.ReaderAt.

ReadAt always returns a non-nil error when c < len(b).

func (*ReadWriter) String Uses

func (r *ReadWriter) String() string

String implements Stringer.String().

func (*ReadWriter) Write Uses

func (r *ReadWriter) Write(b []byte) (int, error)

Write implements io.Writer.

func (*ReadWriter) WriteAt Uses

func (r *ReadWriter) WriteAt(b []byte, off int64) (c int, err error)

WriteAt implements io.WriterAt.

Package fd imports 6 packages (graph) and is imported by 32 packages. Updated 2020-09-27. Refresh now. Tools for package owners.