2015-11-06 21:18:21 +00:00
|
|
|
.\"This manpage is Copyright (C) 2015 Anna Schumaker <Anna.Schumaker@Netapp.com>
|
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(VERBATIM)
|
|
|
|
.\" Permission is granted to make and distribute verbatim copies of this
|
|
|
|
.\" manual provided the copyright notice and this permission notice are
|
|
|
|
.\" preserved on all copies.
|
|
|
|
.\"
|
|
|
|
.\" Permission is granted to copy and distribute modified versions of
|
|
|
|
.\" this manual under the conditions for verbatim copying, provided that
|
|
|
|
.\" the entire resulting derived work is distributed under the terms of
|
|
|
|
.\" a permission notice identical to this one.
|
|
|
|
.\"
|
|
|
|
.\" Since the Linux kernel and libraries are constantly changing, this
|
|
|
|
.\" manual page may be incorrect or out-of-date. The author(s) assume
|
|
|
|
.\" no responsibility for errors or omissions, or for damages resulting
|
|
|
|
.\" from the use of the information contained herein. The author(s) may
|
|
|
|
.\" not have taken the same level of care in the production of this
|
|
|
|
.\" manual, which is licensed free of charge, as they might when working
|
|
|
|
.\" professionally.
|
|
|
|
.\"
|
|
|
|
.\" Formatted or processed versions of this manual, if unaccompanied by
|
|
|
|
.\" the source, must acknowledge the copyright and authors of this work.
|
|
|
|
.\" %%%LICENSE_END
|
|
|
|
.\"
|
iconv.1, bpf.2, copy_file_range.2, fcntl.2, memfd_create.2, mlock.2, mount.2, mprotect.2, perf_event_open.2, pkey_alloc.2, prctl.2, read.2, recvmmsg.2, s390_sthyi.2, seccomp.2, sendmmsg.2, syscalls.2, unshare.2, write.2, errno.3, fgetpwent.3, fts.3, pthread_rwlockattr_setkind_np.3, fuse.4, veth.4, capabilities.7, cgroups.7, ip.7, man-pages.7, namespaces.7, network_namespaces.7, sched.7, socket.7, user_namespaces.7, iconvconfig.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2018-02-02 06:38:54 +00:00
|
|
|
.TH COPY_FILE_RANGE 2 2018-02-02 "Linux" "Linux Programmer's Manual"
|
2015-11-06 21:18:21 +00:00
|
|
|
.SH NAME
|
|
|
|
copy_file_range \- Copy a range of data from one file to another
|
|
|
|
.SH SYNOPSIS
|
|
|
|
.nf
|
2018-01-01 04:12:59 +00:00
|
|
|
.B #define _GNU_SOURCE
|
2015-11-06 21:18:21 +00:00
|
|
|
.B #include <unistd.h>
|
_syscall.2, clock_getres.2, clone.2, copy_file_range.2, create_module.2, delete_module.2, fallocate.2, futex.2, get_kernel_syms.2, get_robust_list.2, getcpu.2, getdents.2, gettid.2, gettimeofday.2, getunwind.2, init_module.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl_userfaultfd.2, ioprio_set.2, kcmp.2, kexec_load.2, keyctl.2, link.2, llseek.2, memfd_create.2, mmap.2, mq_getsetattr.2, msgctl.2, msgget.2, open_by_handle_at.2, outb.2, perf_event_open.2, pivot_root.2, process_vm_readv.2, query_module.2, readdir.2, recvmmsg.2, rename.2, request_key.2, restart_syscall.2, rt_sigqueueinfo.2, s390_pci_mmio_write.2, s390_runtime_instr.2, sched_setattr.2, seccomp.2, select.2, select_tut.2, send.2, sendmmsg.2, set_thread_area.2, set_tid_address.2, sgetmask.2, shmop.2, sigaction.2, sigprocmask.2, splice.2, spu_create.2, spu_run.2, statx.2, subpage_prot.2, sync_file_range.2, syscall.2, sysctl.2, sysfs.2, tee.2, timer_create.2, timer_delete.2, timer_getoverrun.2, timer_settime.2, tkill.2, uselib.2, utimensat.2, vmsplice.2, wait.2, aio_init.3, asinh.3, atan2.3, atanh.3, backtrace.3, basename.3, bswap.3, bzero.3, catgets.3, catopen.3, dladdr.3, dlsym.3, endian.3, envz_add.3, erf.3, erfc.3, error.3, ferror.3, ffs.3, fgetc.3, fmemopen.3, fopen.3, fopencookie.3, fseek.3, ftw.3, futimes.3, getdate.3, getenv.3, getline.3, getlogin.3, getrpcent.3, getsubopt.3, getutmp.3, getw.3, gnu_get_libc_version.3, inet_net_pton.3, isalpha.3, lio_listio.3, makedev.3, malloc_get_state.3, malloc_stats.3, malloc_trim.3, malloc_usable_size.3, matherr.3, memchr.3, nextup.3, ntp_gettime.3, posix_madvise.3, program_invocation_name.3, pthread_atfork.3, pthread_attr_setaffinity_np.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setscope.3, pthread_attr_setstack.3, pthread_attr_setstackaddr.3, pthread_attr_setstacksize.3, pthread_cleanup_push_defer_np.3, pthread_detach.3, pthread_equal.3, pthread_exit.3, pthread_join.3, pthread_kill.3, pthread_kill_other_threads_np.3, pthread_rwlockattr_setkind_np.3, pthread_self.3, pthread_setcancelstate.3, pthread_setconcurrency.3, pthread_setschedprio.3, pthread_testcancel.3, pthread_tryjoin_np.3, pthread_yield.3, puts.3, random.3, random_r.3, rpc.3, sched_getcpu.3, setnetgrent.3, sigwait.3, stdin.3, strerror.3, strfmon.3, timeradd.3, tmpnam.3, toupper.3, towlower.3, towupper.3, ttyname.3, uselocale.3, xdr.3, dsp56k.4, sigevent.7, vdso.7: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-15 17:26:11 +00:00
|
|
|
.PP
|
2016-01-26 09:32:01 +00:00
|
|
|
.BI "ssize_t copy_file_range(int " fd_in ", loff_t *" off_in ,
|
|
|
|
.BI " int " fd_out ", loff_t *" off_out ,
|
|
|
|
.BI " size_t " len ", unsigned int " flags );
|
2015-11-06 21:18:21 +00:00
|
|
|
.fi
|
|
|
|
.SH DESCRIPTION
|
|
|
|
The
|
|
|
|
.BR copy_file_range ()
|
|
|
|
system call performs an in-kernel copy between two file descriptors
|
2016-01-26 09:32:01 +00:00
|
|
|
without the additional cost of transferring data from the kernel to user space
|
2015-11-06 21:18:21 +00:00
|
|
|
and then back into the kernel.
|
|
|
|
It copies up to
|
|
|
|
.I len
|
|
|
|
bytes of data from file descriptor
|
|
|
|
.I fd_in
|
|
|
|
to file descriptor
|
|
|
|
.IR fd_out ,
|
|
|
|
overwriting any data that exists within the requested range of the target file.
|
_syscall.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, copy_file_range.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, execveat.2, fallocate.2, flock.2, fork.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_mempolicy.2, get_robust_list.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpriority.2, getrandom.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl_fat.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, ioctl_tty.2, ioctl_userfaultfd.2, ioperm.2, iopl.2, ioprio_set.2, kcmp.2, kexec_load.2, keyctl.2, kill.2, link.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, mbind.2, membarrier.2, memfd_create.2, migrate_pages.2, mincore.2, mkdir.2, mknod.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open_by_handle_at.2, outb.2, perf_event_open.2, perfmonctl.2, personality.2, pivot_root.2, pkey_alloc.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readv.2, reboot.2, recv.2, recvmmsg.2, remap_file_pages.2, rename.2, request_key.2, restart_syscall.2, rt_sigqueueinfo.2, s390_pci_mmio_write.2, s390_runtime_instr.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, seccomp.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, sendmmsg.2, set_mempolicy.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setns.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, spu_create.2, spu_run.2, stat.2, statfs.2, statx.2, subpage_prot.2, swapon.2, symlink.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysinfo.2, syslog.2, tee.2, time.2, timer_create.2, timer_getoverrun.2, timer_settime.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, unimplemented.2, unlink.2, unshare.2, uselib.2, userfaultfd.2, utime.2, utimensat.2, vfork.2, vmsplice.2, wait.2, wait4.2, write.2: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 07:30:51 +00:00
|
|
|
.PP
|
2015-11-06 21:18:21 +00:00
|
|
|
The following semantics apply for
|
|
|
|
.IR off_in ,
|
|
|
|
and similar statements apply to
|
|
|
|
.IR off_out :
|
|
|
|
.IP * 3
|
|
|
|
If
|
|
|
|
.I off_in
|
|
|
|
is NULL, then bytes are read from
|
|
|
|
.I fd_in
|
2016-01-26 09:32:01 +00:00
|
|
|
starting from the file offset, and the file offset is
|
2015-11-06 21:18:21 +00:00
|
|
|
adjusted by the number of bytes copied.
|
|
|
|
.IP *
|
|
|
|
If
|
|
|
|
.I off_in
|
|
|
|
is not NULL, then
|
|
|
|
.I off_in
|
|
|
|
must point to a buffer that specifies the starting
|
|
|
|
offset where bytes from
|
|
|
|
.I fd_in
|
2016-01-26 09:32:01 +00:00
|
|
|
will be read.
|
|
|
|
The file offset of
|
2015-11-06 21:18:21 +00:00
|
|
|
.I fd_in
|
|
|
|
is not changed, but
|
|
|
|
.I off_in
|
|
|
|
is adjusted appropriately.
|
|
|
|
.PP
|
_syscall.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, copy_file_range.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, execveat.2, fallocate.2, flock.2, fork.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_mempolicy.2, get_robust_list.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpriority.2, getrandom.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl_fat.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, ioctl_tty.2, ioctl_userfaultfd.2, ioperm.2, iopl.2, ioprio_set.2, kcmp.2, kexec_load.2, keyctl.2, kill.2, link.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, mbind.2, membarrier.2, memfd_create.2, migrate_pages.2, mincore.2, mkdir.2, mknod.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open_by_handle_at.2, outb.2, perf_event_open.2, perfmonctl.2, personality.2, pivot_root.2, pkey_alloc.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readv.2, reboot.2, recv.2, recvmmsg.2, remap_file_pages.2, rename.2, request_key.2, restart_syscall.2, rt_sigqueueinfo.2, s390_pci_mmio_write.2, s390_runtime_instr.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, seccomp.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, sendmmsg.2, set_mempolicy.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setns.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, spu_create.2, spu_run.2, stat.2, statfs.2, statx.2, subpage_prot.2, swapon.2, symlink.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysinfo.2, syslog.2, tee.2, time.2, timer_create.2, timer_getoverrun.2, timer_settime.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, unimplemented.2, unlink.2, unshare.2, uselib.2, userfaultfd.2, utime.2, utimensat.2, vfork.2, vmsplice.2, wait.2, wait4.2, write.2: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 07:30:51 +00:00
|
|
|
.PP
|
2015-11-06 21:18:21 +00:00
|
|
|
The
|
|
|
|
.I flags
|
2016-01-26 09:32:01 +00:00
|
|
|
argument is provided to allow for future extensions
|
|
|
|
and currently must be to 0.
|
2015-11-06 21:18:21 +00:00
|
|
|
.SH RETURN VALUE
|
|
|
|
Upon successful completion,
|
|
|
|
.BR copy_file_range ()
|
|
|
|
will return the number of bytes copied between files.
|
|
|
|
This could be less than the length originally requested.
|
_syscall.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, copy_file_range.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, execveat.2, fallocate.2, flock.2, fork.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_mempolicy.2, get_robust_list.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpriority.2, getrandom.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl_fat.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, ioctl_tty.2, ioctl_userfaultfd.2, ioperm.2, iopl.2, ioprio_set.2, kcmp.2, kexec_load.2, keyctl.2, kill.2, link.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, mbind.2, membarrier.2, memfd_create.2, migrate_pages.2, mincore.2, mkdir.2, mknod.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open_by_handle_at.2, outb.2, perf_event_open.2, perfmonctl.2, personality.2, pivot_root.2, pkey_alloc.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readv.2, reboot.2, recv.2, recvmmsg.2, remap_file_pages.2, rename.2, request_key.2, restart_syscall.2, rt_sigqueueinfo.2, s390_pci_mmio_write.2, s390_runtime_instr.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, seccomp.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, sendmmsg.2, set_mempolicy.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setns.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, spu_create.2, spu_run.2, stat.2, statfs.2, statx.2, subpage_prot.2, swapon.2, symlink.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysinfo.2, syslog.2, tee.2, time.2, timer_create.2, timer_getoverrun.2, timer_settime.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, unimplemented.2, unlink.2, unshare.2, uselib.2, userfaultfd.2, utime.2, utimensat.2, vfork.2, vmsplice.2, wait.2, wait4.2, write.2: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 07:30:51 +00:00
|
|
|
.PP
|
2015-11-06 21:18:21 +00:00
|
|
|
On error,
|
|
|
|
.BR copy_file_range ()
|
|
|
|
returns \-1 and
|
|
|
|
.I errno
|
|
|
|
is set to indicate the error.
|
|
|
|
.SH ERRORS
|
|
|
|
.TP
|
|
|
|
.B EBADF
|
|
|
|
One or more file descriptors are not valid; or
|
|
|
|
.I fd_in
|
|
|
|
is not open for reading; or
|
|
|
|
.I fd_out
|
|
|
|
is not open for writing; or
|
2016-01-26 09:36:54 +00:00
|
|
|
the
|
|
|
|
.B O_APPEND
|
2018-12-01 08:42:01 +00:00
|
|
|
flag is set for the open file description (see
|
|
|
|
.BR open (2))
|
|
|
|
referred to by the file descriptor
|
2016-01-26 09:36:54 +00:00
|
|
|
.IR fd_out .
|
2015-11-06 21:18:21 +00:00
|
|
|
.TP
|
2018-01-03 13:00:35 +00:00
|
|
|
.B EFBIG
|
|
|
|
An attempt was made to write a file that exceeds the implementation-defined
|
|
|
|
maximum file size or the process's file size limit,
|
|
|
|
or to write at a position past the maximum allowed offset.
|
|
|
|
.TP
|
2018-01-08 23:53:13 +00:00
|
|
|
.B EINVAL
|
|
|
|
Requested range extends beyond the end of the source file; or the
|
|
|
|
.I flags
|
|
|
|
argument is not 0.
|
|
|
|
.TP
|
2015-11-06 21:18:21 +00:00
|
|
|
.B EIO
|
2016-01-26 09:32:01 +00:00
|
|
|
A low-level I/O error occurred while copying.
|
2015-11-06 21:18:21 +00:00
|
|
|
.TP
|
2018-01-08 23:55:07 +00:00
|
|
|
.B EISDIR
|
|
|
|
.I fd_in
|
|
|
|
or
|
|
|
|
.I fd_out
|
|
|
|
refers to a directory.
|
|
|
|
.TP
|
2015-11-06 21:18:21 +00:00
|
|
|
.B ENOMEM
|
|
|
|
Out of memory.
|
|
|
|
.TP
|
|
|
|
.B ENOSPC
|
|
|
|
There is not enough space on the target filesystem to complete the copy.
|
|
|
|
.TP
|
|
|
|
.B EXDEV
|
2016-01-26 09:37:46 +00:00
|
|
|
The files referred to by
|
2015-11-06 21:18:21 +00:00
|
|
|
.IR file_in " and " file_out
|
|
|
|
are not on the same mounted filesystem.
|
|
|
|
.SH VERSIONS
|
|
|
|
The
|
|
|
|
.BR copy_file_range ()
|
2018-01-01 04:12:59 +00:00
|
|
|
system call first appeared in Linux 4.5, but glibc 2.27 provides a user-space
|
|
|
|
emulation when it is not available.
|
|
|
|
.\" https://sourceware.org/git/?p=glibc.git;a=commit;f=posix/unistd.h;h=bad7a0c81f501fbbcc79af9eaa4b8254441c4a1f
|
2015-11-06 21:18:21 +00:00
|
|
|
.SH CONFORMING TO
|
|
|
|
The
|
|
|
|
.BR copy_file_range ()
|
2018-01-01 04:12:59 +00:00
|
|
|
system call is a nonstandard Linux and GNU extension.
|
2015-11-06 21:18:21 +00:00
|
|
|
.SH NOTES
|
|
|
|
If
|
|
|
|
.I file_in
|
|
|
|
is a sparse file, then
|
|
|
|
.BR copy_file_range ()
|
|
|
|
may expand any holes existing in the requested range.
|
|
|
|
Users may benefit from calling
|
|
|
|
.BR copy_file_range ()
|
2016-01-26 09:39:28 +00:00
|
|
|
in a loop, and using the
|
2015-11-06 21:18:21 +00:00
|
|
|
.BR lseek (2)
|
2016-01-26 09:39:28 +00:00
|
|
|
.BR SEEK_DATA
|
|
|
|
and
|
|
|
|
.BR SEEK_HOLE
|
|
|
|
operations to find the locations of data segments.
|
_syscall.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres.2, clock_nanosleep.2, clone.2, close.2, connect.2, copy_file_range.2, create_module.2, delete_module.2, dup.2, epoll_create.2, epoll_ctl.2, epoll_wait.2, eventfd.2, execve.2, execveat.2, fallocate.2, flock.2, fork.2, fsync.2, futex.2, futimesat.2, get_kernel_syms.2, get_mempolicy.2, get_robust_list.2, getcpu.2, getdents.2, getdomainname.2, getgid.2, getgroups.2, gethostname.2, getitimer.2, getpagesize.2, getpeername.2, getpriority.2, getrandom.2, getresuid.2, getrlimit.2, getrusage.2, getsid.2, getsockname.2, getsockopt.2, gettid.2, gettimeofday.2, getuid.2, getunwind.2, init_module.2, inotify_add_watch.2, inotify_init.2, inotify_rm_watch.2, intro.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, ioctl_fat.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, ioctl_tty.2, ioctl_userfaultfd.2, ioperm.2, iopl.2, ioprio_set.2, kcmp.2, kexec_load.2, keyctl.2, kill.2, link.2, listen.2, listxattr.2, llseek.2, lookup_dcookie.2, lseek.2, madvise.2, mbind.2, membarrier.2, memfd_create.2, migrate_pages.2, mincore.2, mkdir.2, mknod.2, mlock.2, mmap.2, mmap2.2, modify_ldt.2, move_pages.2, mprotect.2, mq_getsetattr.2, mremap.2, msgctl.2, msgget.2, msgop.2, msync.2, nanosleep.2, nfsservctl.2, nice.2, open_by_handle_at.2, outb.2, perf_event_open.2, perfmonctl.2, personality.2, pivot_root.2, pkey_alloc.2, poll.2, posix_fadvise.2, prctl.2, pread.2, process_vm_readv.2, ptrace.2, query_module.2, quotactl.2, read.2, readahead.2, readdir.2, readv.2, reboot.2, recv.2, recvmmsg.2, remap_file_pages.2, rename.2, request_key.2, restart_syscall.2, rt_sigqueueinfo.2, s390_pci_mmio_write.2, s390_runtime_instr.2, sched_get_priority_max.2, sched_rr_get_interval.2, sched_setaffinity.2, sched_setattr.2, sched_setparam.2, sched_setscheduler.2, sched_yield.2, seccomp.2, select.2, select_tut.2, semctl.2, semget.2, semop.2, send.2, sendfile.2, sendmmsg.2, set_mempolicy.2, set_thread_area.2, set_tid_address.2, seteuid.2, setfsgid.2, setfsuid.2, setgid.2, setns.2, setpgid.2, setresuid.2, setreuid.2, setsid.2, setuid.2, sgetmask.2, shmctl.2, shmget.2, shmop.2, sigaction.2, sigaltstack.2, sigpending.2, sigprocmask.2, sigreturn.2, sigsuspend.2, sigwaitinfo.2, socket.2, socketcall.2, socketpair.2, splice.2, spu_create.2, spu_run.2, stat.2, statfs.2, statx.2, subpage_prot.2, swapon.2, symlink.2, sync.2, sync_file_range.2, syscalls.2, sysctl.2, sysinfo.2, syslog.2, tee.2, time.2, timer_create.2, timer_getoverrun.2, timer_settime.2, timerfd_create.2, times.2, tkill.2, truncate.2, umask.2, umount.2, unimplemented.2, unlink.2, unshare.2, uselib.2, userfaultfd.2, utime.2, utimensat.2, vfork.2, vmsplice.2, wait.2, wait4.2, write.2: Formatting fix: replace blank lines with .PP/.IP
Blank lines shouldn't generally appear in *roff source (other
than in code examples), since they create large vertical
spaces between text blocks.
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-16 07:30:51 +00:00
|
|
|
.PP
|
2016-01-27 08:10:32 +00:00
|
|
|
.BR copy_file_range ()
|
|
|
|
gives filesystems an opportunity to implement "copy acceleration" techniques,
|
2018-04-27 12:38:59 +00:00
|
|
|
such as the use of reflinks (i.e., two or more inodes that share
|
2016-01-27 08:10:32 +00:00
|
|
|
pointers to the same copy-on-write disk blocks)
|
|
|
|
or server-side-copy (in the case of NFS).
|
2015-11-06 21:18:21 +00:00
|
|
|
.SH EXAMPLE
|
locale.1, pldd.1, bpf.2, clone.2, copy_file_range.2, dup.2, execve.2, futex.2, get_kernel_syms.2, getdents.2, getrlimit.2, getunwind.2, init_module.2, ioctl_console.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, ioctl_ns.2, ioctl_tty.2, ioctl_userfaultfd.2: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 11:01:10 +00:00
|
|
|
.EX
|
2015-11-06 21:18:21 +00:00
|
|
|
#define _GNU_SOURCE
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/syscall.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2017-12-27 04:14:10 +00:00
|
|
|
/* On versions of glibc before 2.27, we must invoke copy_file_range()
|
|
|
|
using syscall(2) */
|
|
|
|
|
2016-01-26 09:32:01 +00:00
|
|
|
static loff_t
|
|
|
|
copy_file_range(int fd_in, loff_t *off_in, int fd_out,
|
|
|
|
loff_t *off_out, size_t len, unsigned int flags)
|
2015-11-06 21:18:21 +00:00
|
|
|
{
|
|
|
|
return syscall(__NR_copy_file_range, fd_in, off_in, fd_out,
|
|
|
|
off_out, len, flags);
|
|
|
|
}
|
|
|
|
|
2016-01-26 09:32:01 +00:00
|
|
|
int
|
|
|
|
main(int argc, char **argv)
|
2015-11-06 21:18:21 +00:00
|
|
|
{
|
|
|
|
int fd_in, fd_out;
|
|
|
|
struct stat stat;
|
|
|
|
loff_t len, ret;
|
|
|
|
|
|
|
|
if (argc != 3) {
|
|
|
|
fprintf(stderr, "Usage: %s <source> <destination>\\n", argv[0]);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
fd_in = open(argv[1], O_RDONLY);
|
|
|
|
if (fd_in == \-1) {
|
|
|
|
perror("open (argv[1])");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fstat(fd_in, &stat) == \-1) {
|
|
|
|
perror("fstat");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2016-01-26 09:32:01 +00:00
|
|
|
|
2015-11-06 21:18:21 +00:00
|
|
|
len = stat.st_size;
|
|
|
|
|
2016-01-26 09:32:01 +00:00
|
|
|
fd_out = open(argv[2], O_CREAT | O_WRONLY | O_TRUNC, 0644);
|
2015-11-06 21:18:21 +00:00
|
|
|
if (fd_out == \-1) {
|
|
|
|
perror("open (argv[2])");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
ret = copy_file_range(fd_in, NULL, fd_out, NULL, len, 0);
|
|
|
|
if (ret == \-1) {
|
|
|
|
perror("copy_file_range");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
len \-= ret;
|
|
|
|
} while (len > 0);
|
|
|
|
|
|
|
|
close(fd_in);
|
|
|
|
close(fd_out);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
locale.1, pldd.1, bpf.2, clone.2, copy_file_range.2, dup.2, execve.2, futex.2, get_kernel_syms.2, getdents.2, getrlimit.2, getunwind.2, init_module.2, ioctl_console.2, ioctl_ficlonerange.2, ioctl_fideduperange.2, ioctl_ns.2, ioctl_tty.2, ioctl_userfaultfd.2: ffix
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2017-08-18 11:01:10 +00:00
|
|
|
.EE
|
2015-11-06 21:18:21 +00:00
|
|
|
.SH SEE ALSO
|
2016-01-26 09:32:01 +00:00
|
|
|
.BR lseek (2),
|
|
|
|
.BR sendfile (2),
|
2015-11-06 21:18:21 +00:00
|
|
|
.BR splice (2)
|