Documentation
¶
Overview ¶
Package fd provides a drop-in interface-based replacement of *os.File that allows for things like noop-Close wrappers to be used.
Index ¶
- Variables
- func Dup(fd Fd) (*os.File, error)
- func DupWithName(fd Fd, name string) (*os.File, error)
- func Faccessat(dir Fd, path string, mode uint32, flags int) error
- func Fsmount(ctx Fd, flags, mountAttrs int) (*os.File, error)
- func Fsopen(fsName string, flags int) (*os.File, error)
- func Fstat(fd Fd) (unix.Stat_t, error)
- func Fstatat(dir Fd, path string, flags int) (unix.Stat_t, error)
- func Fstatfs(fd Fd) (unix.Statfs_t, error)
- func GetMountID(dir Fd, path string) (uint64, error)
- func IsDeadInode(file Fd) error
- func OpenTree(dir Fd, path string, flags uint) (*os.File, error)
- func Openat(dir Fd, path string, flags int, mode int) (*os.File, error)
- func Readlinkat(dir Fd, path string) (string, error)
- type Fd
Constants ¶
This section is empty.
Variables ¶
var Openat2 = func(dir Fd, path string, how *unix.OpenHow) (*os.File, error) { dirFd, fullPath := prepareAt(dir, path) how.Flags |= unix.O_CLOEXEC var tries int for { fd, err := unix.Openat2(dirFd, path, how) if err != nil { if scopedLookupShouldRetry(how, err) && tries < scopedLookupMaxRetries { tries++ continue } return nil, &os.PathError{Op: "openat2", Path: fullPath, Err: err} } runtime.KeepAlive(dir) return os.NewFile(uintptr(fd), fullPath), nil } }
Openat2 is an Fd-based wrapper around unix.Openat2, but with some retry logic in case of EAGAIN errors.
NOTE: This is a variable so that the lookup tests can force openat2 to fail.
Functions ¶
func DupWithName ¶
DupWithName creates a new file descriptor referencing the same underlying file, but with the provided name instead of fd.Name().
func GetMountID ¶
GetMountID gets the mount identifier associated with the fd and path combination. It is effectively a wrapper around fetching STATX_MNT_ID{,_UNIQUE} with unix.Statx, but with a fallback to 0 if the kernel doesn't support the feature.
func IsDeadInode ¶
IsDeadInode detects whether the file has been unlinked from a filesystem and is thus a "dead inode" from the kernel's perspective.
Types ¶
type Fd ¶
Fd is an interface that mirrors most of the API of *os.File, allowing you to create wrappers that can be used in place of *os.File.
func NopCloser ¶
NopCloser returns an *os.File-like object where the Close method is now a no-op.
Note that for *os.File and similar objects, the Go garbage collector will still call Close on the underlying file unless you use runtime.SetFinalizer to disable this behaviour. This is up to the caller to do (if necessary).