Documentation ¶
Overview ¶
Package reflink provides a simple library allowing to create reflinks (shallow copies) of files enabling copy-on-write behavior.
This library currently only supports creating reflinks on Linux and requires a compatible filesystem (e.g. btrfs)
A small command line utility is also provided.
Index ¶
Examples ¶
Constants ¶
const ErrUnsupported = internalError("reflinks are not supported on this platform")
ErrUnsupported indicated that the operation is not supported
Variables ¶
This section is empty.
Functions ¶
func Clone ¶
func Clone(src, dst string, flags CloneFlags, mode os.FileMode) error
Clone creates a reflink (clone) of the src file to the dst file. flags can be used to control how the clone will be created. Unless the PreserveMode flag is set, the target file mode is set to mode.
Example ¶
// Clone /source to /target err := Clone("/source", "/target", 0, 0644) if err != nil { panic(err) } // Clone /source to /target2, preserving source mode & owner if possible err = Clone("/source", "/target2", PreserveMode|PreserveOwner|FailSafe, 0644) if err != nil { panic(err) }
Output:
func CloneRange ¶
CloneRange creates a reflink (clone) of a sub-range of the src file to the dst file. ofs define offsets of the source and target file. flags can be used to control how the clone will be created. Unless the PreserveMode flag is set, the target file mode is set to mode.
Example ¶
// Clone the first 512 bytes of /source to /target err := CloneRange("/source", "/target", 0, 0644, Offsets{ SrcOffset: 0, SrcLength: 512, DestOffset: 0, }) if err != nil { panic(err) }
Output:
Types ¶
type CloneFlags ¶
type CloneFlags int
CloneFlags are the flags
const ( // Preserve file permissions PreserveMode CloneFlags = 1 // Preserve file owner PreserveOwner CloneFlags = 1 << 1 // Preserve file times PreserveTimes CloneFlags = 1 << 2 // Don't return an error if mode / owner / times cannot be set on target file FailSafe CloneFlags = 1 << 6 // Delete the target file if the operation fails UnlinkOnFailure CloneFlags = 1 << 7 )
Available clone flags
func (CloneFlags) IsSet ¶
func (cf CloneFlags) IsSet(f CloneFlags) bool
IsSet returns whether f is set on cf
func (CloneFlags) Set ¶
func (cf CloneFlags) Set(f CloneFlags) CloneFlags
Set returns a copy of cf with f set
func (CloneFlags) UnSet ¶
func (cf CloneFlags) UnSet(f CloneFlags) CloneFlags
UnSet returns a copy of cf with f unset