fio

package module
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 23, 2024 License: GPL-2.0 Imports: 14 Imported by: 1

README

go-fio-

optimized file I/O routines - including reflink based copies/clones

Documentation

Index

Constants

View Source
const (
	OPT_OVERWRITE uint32 = 1 << iota
	OPT_COW
)

Variables

View Source
var (
	ErrTooSmall = errors.New("buffer is not big enough")
)

Functions

func ClearXattr added in v0.2.0

func ClearXattr(nm string) error

ClearXattr deletes all the extended attributes of a file.

func CloneFile

func CloneFile(dst, src string) error

CloneFile copies src to dst - including all copyable file attributes and xattr. CloneFile will use the best available CoW facilities provided by the OS and Filesystem. It will fall back to using copy via mmap(2) on systems that don't have CoW semantics.

func CloneMetadata added in v0.3.0

func CloneMetadata(dst, src string) error

CloneMetadata clones all the metadata from src to dst: the metadata is atime, mtime, uid, gid, mode/perm, xattr

func CopyFd

func CopyFd(dst, src *os.File) error

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

func CopyFile(dst, src string, perm fs.FileMode) error

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

func DelXattr(nm string, keys ...string) error

DelXattr deletes one or more extended attributes of a file.

func LclearXattr added in v0.2.0

func LclearXattr(nm string) error

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

func LdelXattr(nm string, keys ...string) error

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.

func LreplaceXattr added in v0.2.0

func LreplaceXattr(nm string, x Xattr) error

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

func LsetXattr(nm string, x Xattr) error

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.

func Lstatm added in v0.2.0

func Lstatm(nm string, fi *Info) error

Lstatm is like Lstat except it uses the caller's supplied memory.

func ReplaceXattr added in v0.2.0

func ReplaceXattr(nm string, x Xattr) error

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

func SetXattr(nm string, x Xattr) error

SetXattr sets/updates the xattr list for a given file.

func Statm added in v0.2.0

func Statm(nm string, fi *Info) error

Statm is like Stat above - except it uses caller supplied memory for the stat(2) info

func UpdateMetadata added in v0.3.0

func UpdateMetadata(dst string, fi *Info) error

UpdateMetadata writes new metadata of 'dst' from 'fi' The metadata that will be updated includes atime, mtime, uid/gid, mode/perm, xattr

Types

type Info added in v0.2.0

type Info struct {
	Ino  uint64
	Siz  int64
	Dev  uint64
	Rdev uint64

	Mod   fs.FileMode
	Uid   uint32
	Gid   uint32
	Nlink uint32

	Atim time.Time
	Mtim time.Time
	Ctim time.Time

	Nam   string
	Xattr Xattr
}

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)`). This type can also be safely marshaled and unmarshaled into a portable byte stream.

func Lstat added in v0.2.0

func Lstat(nm string) (*Info, error)

Lstat is like os.Lstat() but also returns xattr

func Stat added in v0.2.0

func Stat(nm string) (*Info, error)

Stat is like os.Stat() but also returns xattr

func (*Info) IsDir added in v0.2.0

func (ii *Info) IsDir() bool

IsDir returns true if this Info represents a directory entry

func (*Info) IsRegular added in v0.2.0

func (ii *Info) IsRegular() bool

IsRegular returns true if this Info represents a regular file

func (*Info) MarshalSize added in v0.2.0

func (ii *Info) MarshalSize() int

MarshalSize returns the marshaled size of _this_ instance of Info

func (*Info) MarshalTo added in v0.2.0

func (ii *Info) MarshalTo(b []byte) (int, error)

MarshalTo marshals 'ii' into the provided buffer 'b'. The buffer 'b' is expected to be sufficiently big to hold the marshaled data. It returns the number of marshaled bytes (ie exactly the value returned by the corresponding MarshalSize()).

func (*Info) ModTime added in v0.2.0

func (ii *Info) ModTime() time.Time

ModTime returns the file modification time

func (*Info) Mode added in v0.2.0

func (ii *Info) Mode() fs.FileMode

Mode returns the file mode bits

func (*Info) Name added in v0.2.0

func (ii *Info) Name() string

Name satisfies fs.FileInfo and returns the name of the fs entry.

func (*Info) Size added in v0.2.0

func (ii *Info) Size() int64

Size returns the fs entry's size

func (*Info) String added in v0.2.0

func (ii *Info) String() string

String is a string representation of Info

func (*Info) Sys added in v0.2.0

func (ii *Info) Sys() any

Sys returns the platform specific info - in our case it returns a pointer to the underlying Info instance.

func (*Info) Unmarshal added in v0.2.0

func (ii *Info) Unmarshal(b []byte) (int, error)

Unmarshal unmarshals the byte stream 'b' into a full rehydrated instance 'ii'. It returns the number of bytes consumed.

type SafeFile

type SafeFile struct {
	*os.File
	// contains filtered or unexported fields
}

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

func NewSafeFile(nm string, opts uint32, flag int, perm os.FileMode) (*SafeFile, error)

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

func (sf *SafeFile) Close() error

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.

func (*SafeFile) Write

func (sf *SafeFile) Write(b []byte) (int, error)

Attempt to write everything in 'b' and don't proceed if there was a previous error or the file was already closed.

func (*SafeFile) WriteAt

func (sf *SafeFile) WriteAt(b []byte, off int64) (int, error)

WriteAt writes 'b' at absolute offset 'off'

type Xattr

type Xattr map[string]string

Xattr is a collection of all the extended attributes of a given file

func GetXattr added in v0.2.0

func GetXattr(nm string) (Xattr, error)

GetXattr returns all the extended attributes of a file. This function will traverse symlinks.

func LgetXattr added in v0.2.0

func LgetXattr(nm string) (Xattr, error)

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.

func (Xattr) Equal added in v0.2.0

func (x Xattr) Equal(y Xattr) bool

Equal returns true if all xattr of 'x' is the same as all the xattr of 'y' and returns false otherwise.

func (Xattr) String

func (x Xattr) String() string

String returns the string representation of all the extended attributes

Directories

Path Synopsis
cmp
Package walk does a concurrent file system traversal and returns each entry.
Package walk does a concurrent file system traversal and returns each entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL