package fd
import "github.com/cyphar/filepath-securejoin/pathrs-lite/internal/fd"
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
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 Dup ¶
Dup creates a new file description referencing the same underlying file.
func DupWithName ¶
DupWithName creates a new file descriptor referencing the same underlying file, but with the provided name instead of fd.Name().
func Faccessat ¶
Faccessat is an Fd-based wrapper around unix.Faccessat.
func Fsmount ¶
Fsmount is an Fd-based wrapper around unix.Fsmount.
func Fsopen ¶
Fsopen is an Fd-based wrapper around unix.Fsopen.
func Fstat ¶
Fstat is an Fd-based wrapper around unix.Fstat.
func Fstatat ¶
Fstatat is an Fd-based wrapper around unix.Fstatat.
func Fstatfs ¶
Fstatfs is an Fd-based wrapper around unix.Fstatfs.
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.
func OpenTree ¶
OpenTree is an Fd-based wrapper around unix.OpenTree.
func Openat ¶
Openat is an Fd-based wrapper around unix.Openat.
func Readlinkat ¶
Readlinkat is an Fd-based wrapper around unix.Readlinkat.
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).
Source Files ¶
at_linux.go fd.go fd_linux.go mount_linux.go openat2_linux.go
- Version
- v0.6.1 (latest)
- Published
- Nov 19, 2025
- Platform
- linux/amd64
- Imports
- 9 packages
- Last checked
- 48 minutes ago –
Tools for package owners.