Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrReflinkUnsupported indicates that reflink operations are not supported on the current OS ErrReflinkUnsupported = errors.New("reflink is not supported on this OS") // ErrReflinkFailed indicates that the reflink operation failed because the specific // filesystem or files don't support it. This can happen if the files are on different // filesystems or if the filesystem doesn't support reflinks (e.g., ext4). ErrReflinkFailed = errors.New("reflink is not supported on this OS or file") )
ErrReflinkUnsupported is returned by Always() if the reflink operation is not supported on the current operating system. This happens on non-Linux systems or when the necessary system calls aren't available.
Auto() will never return this error since it falls back to regular copy methods.
Functions ¶
func Always ¶
Always will perform a reflink operation and fail on error if reflink is not supported. It creates a copy of the source file at the destination using the filesystem's copy-on-write mechanism, which is extremely fast and space-efficient.
This is equivalent to command `cp --reflink=always` on Linux systems. Both files must be on the same filesystem that supports reflinks (btrfs, xfs).
Returns ErrReflinkUnsupported if the OS doesn't support reflinks, or ErrReflinkFailed if the specific filesystem doesn't support reflinks.
func Auto ¶
Auto will attempt to perform a reflink operation and fallback to normal data copy if reflink is not supported. This is the safer option for general use.
The fallback mechanism follows this priority: 1. Try reflink (FICLONE ioctl) 2. Try copy_file_range syscall (more efficient than userspace copy) 3. Fallback to regular io.Copy
This is equivalent to `cp --reflink=auto` on Linux systems.
func Partial ¶
Partial performs a range reflink operation on the passed files, replacing part of dst's contents with data from src. This allows for more fine-grained control over which parts of the file are copied.
Parameters:
- dst: Destination file handle
- src: Source file handle
- dstOffset: Offset in the destination file where data should be written
- srcOffset: Offset in the source file where data should be read from
- n: Number of bytes to copy
- fallback: Whether to fall back to regular copy methods if reflink fails
If fallback is true and reflink fails, copy_file_range will be tried first, and if that fails too, io.CopyN with appropriate readers/writers will be used.
This function is useful for selectively copying parts of large files without having to read and write the entire file contents.
func Reflink ¶
Reflink performs the reflink operation on the passed files, replacing dst's contents with src. This function works with already-open file handles.
If fallback is true and reflink fails (on unsupported filesystems), copy_file_range will be tried first, and if that fails too, io.Copy will be used to copy the data. When using io.Copy, the destination file will be truncated first.
Note: Unlike Always() and Auto(), this function requires you to open and close the file handles yourself, which gives more control but requires more careful handling.
Types ¶
This section is empty.