GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
COPY_FILE_RANGE(2) FreeBSD System Calls Manual COPY_FILE_RANGE(2)

copy_file_range
kernel copy of a byte range from one file to another or within one file

Standard C Library (libc, -lc)

#include <sys/types.h>
#include <unistd.h>

ssize_t
copy_file_range(int infd, off_t *inoffp, int outfd, off_t *outoffp, size_t len, unsigned int flags);

The copy_file_range() system call copies up to len bytes from infd to outfd in the kernel. It may do this using a file system specific technique if infd and outfd are on the same file system. If infd and outfd refer to the same file, the byte ranges defined by the input file offset, output file offset and len cannot overlap. The infd argument must be opened for reading and the outfd argument must be opened for writing, but not O_APPEND. If inoffp or outoffp is NULL, the file offset for infd or outfd respectively will be used and updated by the number of bytes copied. If inoffp or outoffp is not NULL, the byte offset pointed to by inoffp or outoffp respectively will be used/updated and the file offset for infd or outfd respectively will not be affected. The flags argument must be 0.

This system call attempts to maintain holes in the output file for the byte range being copied. However, this does not always work well. It is recommended that sparse files be copied in a loop using lseek(2) with SEEK_HOLE, SEEK_DATA arguments and this system call for the data ranges found.

For best performance, call copy_file_range() with the largest len value possible. It is interruptible on most file systems, so there is no penalty for using very large len values, even SSIZE_MAX.

If it succeeds, the call returns the number of bytes copied, which can be fewer than len. Returning fewer bytes than len does not necessarily indicate that EOF was reached. However, a return of zero for a non-zero len argument indicates that the offset for infd is at or beyond EOF. copy_file_range() should be used in a loop until copying of the desired byte range has been completed. If an error has occurred, a -1 is returned and the error code is placed in the global variable errno.

The copy_file_range() system call will fail if:
[]
If infd is not open for reading or outfd is not open for writing, or opened for writing with O_APPEND, or if infd and outfd refer to the same file.
[]
If the copy exceeds the process's file size limit or the maximum file size for the file system outfd resides on.
[]
A signal interrupted the system call before it could be completed. This may happen for files on some NFS mounts. When this happens, the values pointed to by inoffp and outoffp are reset to the initial values for the system call.
[]
infd and outfd refer to the same file and the byte ranges overlap or flags is not zero.
[]
An I/O error occurred while reading/writing the files.
[]
Corrupted data was detected while reading from a file system.
[]
If either infd or outfd refers to a directory.
[]
File system that stores outfd is full.

lseek(2)

The copy_file_range() system call is expected to be compatible with the Linux system call of the same name.

The copy_file_range() function appeared in FreeBSD 13.0.
January 2, 2021 FreeBSD 13.1-RELEASE

Search for    or go to Top of page |  Section 2 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.