Documentation
¶
Index ¶
- Constants
- Variables
- func ClearXattr(nm string) error
- func CopyFd(dst, src *os.File) error
- func CopyFile(dst, src string, perm fs.FileMode) error
- func DelXattr(nm string, keys ...string) error
- func Fstatm(fd *os.File, fi *Info) error
- func LclearXattr(nm string) error
- func LdelXattr(nm string, keys ...string) error
- func LreplaceXattr(nm string, x Xattr) error
- func LsetXattr(nm string, x Xattr) error
- func Lstatm(nm string, fi *Info) error
- func ReplaceXattr(nm string, x Xattr) error
- func SetXattr(nm string, x Xattr) error
- func Statm(nm string, fi *Info) error
- type CopyError
- type Info
- func (ii *Info) Clone() *Info
- func (ii *Info) CopyTo(dest *Info)
- func (ii *Info) DiskBytes() int64
- func (ii *Info) IsDir() bool
- func (ii *Info) IsRegular() bool
- func (ii *Info) IsSameFS(b *Info) bool
- func (ii *Info) Marshal(flag MarshalFlag) ([]byte, error)
- func (ii *Info) MarshalJSON() ([]byte, error)
- func (ii *Info) MarshalSize(flag MarshalFlag) int
- func (ii *Info) MarshalTo(b []byte, flag MarshalFlag) (int, error)
- func (ii *Info) ModTime() time.Time
- func (ii *Info) Mode() fs.FileMode
- func (ii *Info) Name() string
- func (ii *Info) Path() string
- func (ii *Info) SetPath(p string)
- func (ii *Info) Size() int64
- func (ii *Info) String() string
- func (ii *Info) Sys() any
- func (ii *Info) Unmarshal(b []byte) (int, error)
- type Map
- type MarshalFlag
- type Pair
- type PairMap
- type SafeFile
- type Xattr
Constants ¶
const (
OptOverwrite uint32 = 1 << iota
)
Variables ¶
var (
ErrAborted = errors.New("safefile: aborted; file not committed")
)
var ErrTooSmall = errors.New("buffer is not big enough")
ErrTooSmall is returned when a caller-supplied buffer cannot hold the encoded form of a value. Detect with errors.Is.
var ErrXattrCapabilityMissing = errors.New("xattr: required capability not held")
ErrXattrCapabilityMissing is returned (wrapped) when a caller attempts to write an xattr whose namespace requires a Linux capability the process does not hold:
- trusted.* requires CAP_SYS_ADMIN
- security.* requires CAP_MAC_ADMIN (or CAP_SYS_ADMIN depending on LSM)
Surfacing this as a typed error lets callers emit a clear diagnostic ("needs CAP_SYS_ADMIN to restore trusted.xattr") instead of the raw EPERM that getxattr/setxattr would otherwise return. clone.WithIgnoreUnsupported also treats this error as skippable since the clone cannot succeed with the current privileges.
var ErrXattrUnsupported = errors.New("xattr: filesystem does not support extended attributes")
ErrXattrUnsupported is returned (wrapped) from xattr operations when the target filesystem does not support extended attributes (the kernel reports ENOTSUP / EOPNOTSUPP). Callers that want to treat this as a non-fatal condition use errors.Is to detect it and downgrade to a skip - see clone.WithIgnoreUnsupported.
Functions ¶
func ClearXattr ¶ added in v0.2.0
ClearXattr deletes all the extended attributes of a file.
func CopyFd ¶
CopyFd copies open files 'src' to 'dst' using the most efficient OS primitive available on the runtime platform. CopyFile will use copy-on-write facailities if the underlying file-system implements it. It will fallback to copying via memory mapping 'src' and writing the blocks to 'dst'.
func CopyFile ¶
CopyFile copies files 'src' to 'dst' using the most efficient OS primitive available on the runtime platform. CopyFile will use copy-on-write facilities if the underlying file-system implements it. It will fallback to copying via memory mapping 'src' and writing the blocks to 'dst'.
func DelXattr ¶ added in v0.2.0
DelXattr deletes one or more extended attributes of a file. Errors from an xattr-less filesystem are wrapped as ErrXattrUnsupported.
func LclearXattr ¶ added in v0.2.0
ClearXattr deletes all the extended attributes of a file. If 'nm' points to a symlink, LSetXattr will delete the extended attributes of the symlink and *not* the target.
func LdelXattr ¶ added in v0.2.0
LDelXattr deletes one or more extended attributes of a file. If 'nm' points to a symlink, LSetXattr will delete the extended attributes of the symlink and *not* the target. Errors from an xattr-less filesystem are wrapped as ErrXattrUnsupported.
func LreplaceXattr ¶ added in v0.2.0
LReplaceXattr replaces all the extended attributes of 'nm' with new attributes in 'x'. This function is a combination of LclearXattr() and LsetXattr(). If 'nm' points to a symlink, LReplaceXattr will set/update the extended attributes of the symlink and *not* the target.
func LsetXattr ¶ added in v0.2.0
LSetXattr sets/updates the xattr list for a given file. If 'nm' points to a symlink, LSetXattr will set/update the extended attributes of the symlink and *not* the target. Errors caused by a filesystem that does not support extended attributes are wrapped as ErrXattrUnsupported; missing Linux capabilities surface as ErrXattrCapabilityMissing. Platform- reserved keys (darwin's com.apple.system.Security) are skipped.
func ReplaceXattr ¶ added in v0.2.0
ReplaceXattr replaces all the extended attributes of 'nm' with new attributes in 'x'. This function is a combination of ClearXattr() and SetXattr().
func SetXattr ¶ added in v0.2.0
SetXattr sets/updates the xattr list for a given file. Errors caused by a filesystem that does not support extended attributes are wrapped as ErrXattrUnsupported. On Linux, a preflight checks whether the calling process has the capability required to write any privileged-namespace keys (trusted.*, security.*); a missing capability surfaces as ErrXattrCapabilityMissing before we hit the kernel's EPERM.
Platform-reserved keys that cannot round-trip via setxattr (currently darwin's com.apple.system.Security) are silently skipped - use acl_*(3) for those.
Types ¶
type CopyError ¶ added in v0.4.0
CopyError represents the errors returned by CopyFile and CopyFd
type Info ¶ added in v0.2.0
type Info struct {
Ino uint64
Siz int64
Dev uint64
Rdev uint64
// POSIX st_blocks: count of 512-byte allocation units. The
// 512-byte unit is fixed by POSIX across every Unix kernel,
// independent of the filesystem's actual block size. Use
// DiskBytes() to recover bytes-on-disk.
Blocks int64
Mod fs.FileMode
Uid uint32
Gid uint32
Nlink uint32
Atim time.Time
Mtim time.Time
Ctim time.Time
Xattr Xattr
// contains filtered or unexported fields
}
Info represents a file/dir metadata in a normalized form. It satisfies the fs.FileInfo interface and notably supports extended file system attributes (`xattr(7)`). It can also be marshaled and unmarshaled into a portable byte stream.
Callers construct an Info either by passing a *Info to Statm / Lstatm / Fstatm, or by struct literal (`&fio.Info{Mod: m}`). The wire encoding is handled via a local pb.Info inside the Marshal path; none of that surfaces to callers.
func (*Info) DiskBytes ¶ added in v0.7.2
DiskBytes returns the actually-allocated bytes-on-disk for this entry. Differs from Size() for sparse files (where DiskBytes can be far smaller than Size) and for tiny files (where DiskBytes is rounded up to a filesystem block, so DiskBytes can exceed Size).
func (*Info) IsRegular ¶ added in v0.2.0
IsRegular returns true if this Info represents a regular file
func (*Info) IsSameFS ¶ added in v0.3.2
IsSameFs returns true if ii and b represent file entries on the same file system
func (*Info) Marshal ¶ added in v0.5.4
func (ii *Info) Marshal(flag MarshalFlag) ([]byte, error)
Marshal allocates a correctly-sized buffer, marshals ii into it, and returns it.
func (*Info) MarshalJSON ¶ added in v0.7.6
MarshalJSON implements encoding/json.Marshaler so an *Info can be passed directly to json.Marshal / json.Encoder.Encode.
The full relative path (ii.Path()) is always emitted; the JunkPath MarshalFlag governs only the protobuf wire format and does not apply to JSON.
func (*Info) MarshalSize ¶ added in v0.2.0
func (ii *Info) MarshalSize(flag MarshalFlag) int
MarshalSize returns the number of bytes Marshal / MarshalTo will write for this Info under the given flag.
func (*Info) MarshalTo ¶ added in v0.2.0
func (ii *Info) MarshalTo(b []byte, flag MarshalFlag) (int, error)
MarshalTo marshals ii into the caller-supplied buffer, returning the number of bytes written. The buffer must be at least MarshalSize bytes.
func (*Info) Name ¶ added in v0.2.0
Name satisfies fs.FileInfo and returns the basename of the fs entry.
func (*Info) Path ¶ added in v0.5.8
Path returns the relative path of this file ("relative" to current working dir of the calling process).
type Map ¶ added in v0.5.13
Map is a concurrency safe map of path name and the corresponding Stat/Lstat info.
type MarshalFlag ¶ added in v0.5.8
type MarshalFlag uint32
MarshalFlag tunes the marshaling of an Info.
const ( // JunkPath strips Path() to its basename before marshaling. // Useful when the caller wants to serialize metadata without // leaking the full directory hierarchy. JunkPath MarshalFlag = 1 << iota )
type Pair ¶ added in v0.5.3
type Pair struct {
Src, Dst *Info
}
Pair represents the Stat/Lstat info of a pair of related file system entries in the source and destination
type PairMap ¶ added in v0.5.13
PairMap is a concurrency safe map of path name and the corresponding Stat/Lstat info of both the source and destination.
func NewPairMap ¶ added in v0.5.13
func NewPairMap() *PairMap
NewPairMap makes a new concurrent map of name to a Pair
type SafeFile ¶
SafeFile is an io.WriteCloser which uses a temporary file that will be atomically renamed when there are no errors and caller invokes Close(). The recommended usage is:
sf, err := NewSafeFile(...) ... error handling defer sf.Abort() ... write to sf .. sf.Close()
It is safe to call Abort on a closed SafeFile; the first call to Close() or Abort() seals the outcome. Similarly, it is safe to call Close() after Abort() - the first call to either takes precedence.
func NewSafeFile ¶
NewSafeFile creates a new temporary file that would either be aborted or safely renamed to the correct name. 'nm' is the name of the final file; if 'ovwrite' is true, then the file is overwritten if it exists.
func (*SafeFile) Abort ¶
func (sf *SafeFile) Abort()
Abort the file write and remove any temporary artifacts; it is safe to call Close() on a different code path; the first call to Abort() or Close() takes precedence.
func (*SafeFile) Close ¶
Close flushes all file data & metadata to disk, closes the file and atomically renames the temp file to the actual file - ONLY if there were no intervening errors.
type Xattr ¶
Xattr is a collection of all the extended attributes of a given file
func GetXattr ¶ added in v0.2.0
GetXattr returns all the extended attributes of a file. This function will traverse symlinks.
func LgetXattr ¶ added in v0.2.0
LGetXattr returns all the extended attributes of a file. If 'nm' points to a symlink, LGetXattr will return the extended attributes of the symlink and *not* the target.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
testutil
Package testutil provides tiny helpers for go-fio's privileged tests.
|
Package testutil provides tiny helpers for go-fio's privileged tests. |
|
Package walk does a concurrent file system traversal and returns each entry.
|
Package walk does a concurrent file system traversal and returns each entry. |