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, locale.1, memusage.1, memusagestat.1, pldd.1, sprof.1, _syscall.2, add_key.2, adjtimex.2, bind.2, bpf.2, chown.2, clone.2, close.2, copy_file_range.2, eventfd.2, fanotify_init.2, fanotify_mark.2, fork.2, fsync.2, futex.2, getdents.2, getrlimit.2, getxattr.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, ioctl_fat.2, ioctl_getfsmap.2, ioctl_ns.2, ioctl_tty.2, ioctl_userfaultfd.2, kcmp.2, keyctl.2, listen.2, listxattr.2, mbind.2, membarrier.2, memfd_create.2, mkdir.2, move_pages.2, mremap.2, msync.2, nfsservctl.2, open.2, perf_event_open.2, pidfd_send_signal.2, pipe.2, pivot_root.2, pkey_alloc.2, process_vm_readv.2, ptrace.2, readlink.2, readv.2, recv.2, recvmmsg.2, rename.2, request_key.2, s390_runtime_instr.2, sched_setaffinity.2, seccomp.2, send.2, sendmmsg.2, sigaltstack.2, signalfd.2, socket.2, socketpair.2, splice.2, spu_create.2, spu_run.2, statfs.2, syscall.2, sysctl.2, sysfs.2, tee.2, timer_getoverrun.2, timer_settime.2, umount.2, userfaultfd.2, utimensat.2, wait4.2, INFINITY.3, __ppc_get_timebase.3, __setfpucw.3, abort.3, aio_cancel.3, aio_error.3, aio_read.3, aio_return.3, atexit.3, backtrace.3, basename.3, bsearch.3, bswap.3, cacos.3, cacosh.3, catan.3, catanh.3, cexp2.3, clock_getcpuclockid.3, clog2.3, cmsg.3, confstr.3, div.3, dl_iterate_phdr.3, dlerror.3, dlinfo.3, dlopen.3, dlsym.3, duplocale.3, encrypt.3, end.3, endian.3, envz_add.3, err.3, expm1.3, fdim.3, flockfile.3, fmtmsg.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo_a.3, getauxval.3, getdate.3, getdtablesize.3, getgrent_r.3, getgrouplist.3, gethostbyname.3, getline.3, getnameinfo.3, getopt.3, getprotoent_r.3, getpwent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, getutent.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, inet.3, inet_net_pton.3, inet_ntop.3, inet_pton.3, insque.3, killpg.3, makecontext.3, mallinfo.3, malloc.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbsnrtowcs.3, mbstowcs.3, mcheck.3, mempcpy.3, mq_getattr.3, mq_notify.3, mtrace.3, newlocale.3, nextafter.3, ntp_gettime.3, offsetof.3, open_memstream.3, pow.3, printf.3, pthread_attr_init.3, pthread_attr_setdetachstate.3, pthread_attr_setguardsize.3, pthread_attr_setinheritsched.3, pthread_attr_setschedparam.3, pthread_attr_setschedpolicy.3, pthread_attr_setstack.3, pthread_attr_setstacksize.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_detach.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_join.3, pthread_mutex_consistent.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setcancelstate.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, pthread_spin_init.3, pthread_testcancel.3, pthread_tryjoin_np.3, ptsname.3, qsort.3, rand.3, random.3, remainder.3, rpmatch.3, rtime.3, rtnetlink.3, scalb.3, scalbln.3, scandir.3, sem_getvalue.3, sem_wait.3, setaliasent.3, setlogmask.3, sigwait.3, sincos.3, sockatmark.3, stdarg.3, stpcpy.3, strcat.3, strfmon.3, strptime.3, strtod.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, tsearch.3, uselocale.3, wcstok.3, wcstombs.3, wordexp.3, y0.3, loop.4, vcs.4, veth.4, charmap.5, core.5, filesystems.5, gai.conf.5, hosts.5, hosts.equiv.5, locale.5, nss.5, repertoiremap.5, securetty.5, shells.5, ttytype.5, ascii.7, complex.7, cpuset.7, credentials.7, fanotify.7, hier.7, inotify.7, ip.7, mount_namespaces.7, mq_overview.7, netlink.7, network_namespaces.7, pid_namespaces.7, pkeys.7, rtld-audit.7, rtnetlink.7, sem_overview.7, signal-safety.7, sock_diag.7, spufs.7, standards.7, symlink.7, tcp.7, time_namespaces.7, unix.7, user_namespaces.7, xattr.7, ldconfig.8: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-06-09 12:43:54 +00:00
|
|
|
.TH COPY_FILE_RANGE 2 2020-06-09 "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
|
2019-09-26 17:01:19 +00:00
|
|
|
bytes of data from the source file descriptor
|
2015-11-06 21:18:21 +00:00
|
|
|
.I fd_in
|
2019-09-26 17:01:19 +00:00
|
|
|
to the target file descriptor
|
2015-11-06 21:18:21 +00:00
|
|
|
.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
|
2019-09-26 17:01:19 +00:00
|
|
|
.I fd_in
|
|
|
|
and
|
|
|
|
.I fd_out
|
|
|
|
can refer to the same file.
|
|
|
|
If they refer to the same file, then the source and target ranges are not
|
|
|
|
allowed to overlap.
|
_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
|
2019-12-09 10:56:41 +00:00
|
|
|
and currently must be set 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.
|
2019-09-26 17:01:19 +00:00
|
|
|
If the file offset of
|
|
|
|
.I fd_in
|
|
|
|
is at or past the end of file, no bytes are copied, and
|
|
|
|
.BR copy_file_range ()
|
|
|
|
returns zero.
|
_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
|
2019-09-26 17:01:19 +00:00
|
|
|
One or more file descriptors are not valid.
|
|
|
|
.TP
|
|
|
|
.B EBADF
|
2015-11-06 21:18:21 +00:00
|
|
|
.I fd_in
|
|
|
|
is not open for reading; or
|
|
|
|
.I fd_out
|
2019-09-26 17:01:19 +00:00
|
|
|
is not open for writing.
|
|
|
|
.TP
|
|
|
|
.B EBADF
|
|
|
|
The
|
2016-01-26 09:36:54 +00:00
|
|
|
.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
|
2019-09-26 17:01:19 +00:00
|
|
|
An attempt was made to write at a position past the maximum file offset the
|
|
|
|
kernel supports.
|
|
|
|
.TP
|
|
|
|
.B EFBIG
|
|
|
|
An attempt was made to write a range that exceeds the allowed maximum file size.
|
|
|
|
The maximum file size differs between filesystem implementations and can be
|
|
|
|
different from the maximum allowed file offset.
|
|
|
|
.TP
|
|
|
|
.B EFBIG
|
|
|
|
An attempt was made to write beyond the process's file size resource limit.
|
|
|
|
This may also result in the process receiving a
|
|
|
|
.I SIGXFSZ
|
|
|
|
signal.
|
2018-01-03 13:00:35 +00:00
|
|
|
.TP
|
2018-01-08 23:53:13 +00:00
|
|
|
.B EINVAL
|
2019-09-26 17:01:19 +00:00
|
|
|
The
|
2018-01-08 23:53:13 +00:00
|
|
|
.I flags
|
|
|
|
argument is not 0.
|
|
|
|
.TP
|
2019-09-26 17:01:19 +00:00
|
|
|
.B EINVAL
|
|
|
|
.I fd_in
|
|
|
|
and
|
|
|
|
.I fd_out
|
|
|
|
refer to the same file and the source and target ranges overlap.
|
|
|
|
.TP
|
|
|
|
.B EINVAL
|
|
|
|
Either
|
|
|
|
.I fd_in
|
|
|
|
or
|
|
|
|
.I fd_out
|
|
|
|
is not a regular file.
|
2015-11-06 21:18:21 +00:00
|
|
|
.TP
|
2019-09-27 11:28:50 +00:00
|
|
|
.B EIO
|
|
|
|
A low-level I/O error occurred while copying.
|
|
|
|
.TP
|
2018-01-08 23:55:07 +00:00
|
|
|
.B EISDIR
|
2019-09-26 17:01:19 +00:00
|
|
|
Either
|
2018-01-08 23:55:07 +00:00
|
|
|
.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
|
2019-09-27 11:28:50 +00:00
|
|
|
.B EOVERFLOW
|
|
|
|
The requested source or destination range is too large to represent in the
|
|
|
|
specified data types.
|
|
|
|
.TP
|
|
|
|
.B EPERM
|
|
|
|
.I fd_out
|
|
|
|
refers to an immutable file.
|
2019-09-26 17:01:19 +00:00
|
|
|
.TP
|
2019-10-22 03:20:23 +00:00
|
|
|
.B ETXTBSY
|
2019-09-26 17:01:19 +00:00
|
|
|
Either
|
|
|
|
.I fd_in
|
|
|
|
or
|
|
|
|
.I fd_out
|
|
|
|
refers to an active swap file.
|
|
|
|
.TP
|
2019-09-27 11:28:50 +00:00
|
|
|
.B EXDEV
|
|
|
|
The files referred to by
|
2020-05-04 08:29:01 +00:00
|
|
|
.IR fd_in " and " fd_out
|
2019-09-27 11:28:50 +00:00
|
|
|
are not on the same mounted filesystem (pre Linux 5.3).
|
2015-11-06 21:18:21 +00:00
|
|
|
.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
|
2019-09-26 17:01:19 +00:00
|
|
|
.PP
|
|
|
|
A major rework of the kernel implementation occurred in 5.3.
|
|
|
|
Areas of the API that weren't clearly defined were clarified and the API bounds
|
|
|
|
are much more strictly checked than on earlier kernels.
|
|
|
|
Applications should target the behaviour and requirements of 5.3 kernels.
|
|
|
|
.PP
|
|
|
|
First support for cross-filesystem copies was introduced in Linux 5.3.
|
|
|
|
Older kernels will return -EXDEV when cross-filesystem copies are attempted.
|
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
|
2020-05-04 08:29:01 +00:00
|
|
|
.I fd_in
|
2015-11-06 21:18:21 +00:00
|
|
|
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).
|
2020-05-21 08:00:37 +00:00
|
|
|
.SH EXAMPLES
|
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) {
|
locale.1, memusage.1, pldd.1, _syscall.2, add_key.2, bind.2, bpf.2, chown.2, clone.2, copy_file_range.2, eventfd.2, execve.2, futex.2, getdents.2, getrlimit.2, ioctl_fat.2, ioctl_ns.2, kcmp.2, kexec_load.2, keyctl.2, listxattr.2, lseek.2, membarrier.2, memfd_create.2, mmap.2, mprotect.2, msgop.2, open_by_handle_at.2, perf_event_open.2, pipe.2, readdir.2, readlink.2, readv.2, recvmmsg.2, request_key.2, sched_setaffinity.2, seccomp.2, select.2, select_tut.2, sendmmsg.2, setns.2, signalfd.2, spu_run.2, stat.2, sysctl.2, tee.2, timer_create.2, timerfd_create.2, truncate.2, uname.2, unshare.2, userfaultfd.2, ustat.2, wait.2, CPU_SET.3, __ppc_get_timebase.3, argz_add.3, asprintf.3, backtrace.3, basename.3, bswap.3, bzero.3, cacos.3, cacosh.3, catan.3, catanh.3, catgets.3, clock_getcpuclockid.3, confstr.3, ctime.3, dl_iterate_phdr.3, dlinfo.3, duplocale.3, encrypt.3, end.3, endian.3, fgetws.3, fmemopen.3, fopencookie.3, fputws.3, frexp.3, ftw.3, get_nprocs_conf.3, get_phys_pages.3, getaddrinfo.3, getaddrinfo_a.3, getdate.3, getgrouplist.3, getifaddrs.3, getline.3, getlogin.3, getopt.3, getpass.3, getprotoent_r.3, getpwnam.3, getservent_r.3, getsubopt.3, glob.3, gnu_get_libc_version.3, hsearch.3, if_nameindex.3, index.3, inet.3, inet_net_pton.3, inet_pton.3, insque.3, iswblank.3, iswspace.3, makecontext.3, mallinfo.3, malloc_hook.3, malloc_info.3, mallopt.3, matherr.3, mbrtowc.3, mbsnrtowcs.3, mbsrtowcs.3, mbstowcs.3, mbtowc.3, mcheck.3, memchr.3, mq_getattr.3, mq_notify.3, newlocale.3, nl_langinfo.3, offsetof.3, perror.3, posix_spawn.3, printf.3, pthread_attr_init.3, pthread_cancel.3, pthread_cleanup_push.3, pthread_create.3, pthread_getattr_default_np.3, pthread_getattr_np.3, pthread_getcpuclockid.3, pthread_mutexattr_setrobust.3, pthread_setaffinity_np.3, pthread_setname_np.3, pthread_setschedparam.3, pthread_sigmask.3, qsort.3, rand.3, readdir.3, regex.3, rpmatch.3, rtime.3, scanf.3, sem_wait.3, setaliasent.3, setbuf.3, stpcpy.3, stpncpy.3, strcat.3, strchr.3, strcpy.3, strdup.3, strerror.3, strfromd.3, strftime.3, strlen.3, strnlen.3, strsep.3, strstr.3, strtok.3, strtol.3, strtoul.3, strverscmp.3, strxfrm.3, termios.3, tsearch.3, wcpcpy.3, wcpncpy.3, wcrtomb.3, wcscat.3, wcscpy.3, wcslen.3, wcsncat.3, wcsncmp.3, wcsncpy.3, wcsnlen.3, wcsnrtombs.3, wcsrtombs.3, wcsstr.3, wcstok.3, wcstombs.3, wcwidth.3, wprintf.3, console_codes.4, dsp56k.4, full.4, initrd.4, loop.4, vcs.4, charmap.5, core.5, elf.5, locale.5, proc.5, repertoiremap.5, sysfs.5, termcap.5, aio.7, bpf-helpers.7, cgroups.7, charsets.7, complex.7, fanotify.7, feature_test_macros.7, inotify.7, locale.7, man-pages.7, man.7, pkeys.7, pthreads.7, rtld-audit.7, sock_diag.7, unix.7, user_namespaces.7, utf-8.7: Use '\e' rather than '\\' to get a backslash
Quoting Branden:
*roff escape sequences may sometimes look like C escapes, but that
is misleading. *roff is in part a macro language and that means
recursive expansion to arbitrary depths.
You can get away with "\\" in a context where no macro expansion
is taking place, but try to spell a literal backslash this way in
the argument to a macro and you will likely be unhappy with
results.
Try viewing the attached file with "man -l".
"\e" is the preferred and portable way to get a portable "escape
literal" going back to CSTR #54, the original Bell Labs troff
paper.
groff(7) discusses the issue:
\\ reduces to a single backslash; useful to delay its
interpretation as escape character in copy mode. For a
printable backslash, use \e, or even better \[rs], to be
independent from the current escape character.
As of groff 1.22.4, groff_man(7) does as well:
\e Widely used in man pages to represent a backslash output
glyph. It works reliably as long as the .ec request is
not used, which should never happen in man pages, and it
is slightly more portable than the more exact ‘\(rs’
(“reverse solidus”) escape sequence.
People not concerned with portability to extremely old troffs should
probably just use \(rs (or \[rs]), as it means "the backslash
glyph", not "the glyph corresponding to whatever the current escape
character is".
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2019-02-27 11:57:17 +00:00
|
|
|
fprintf(stderr, "Usage: %s <source> <destination>\en", argv[0]);
|
2015-11-06 21:18:21 +00:00
|
|
|
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;
|
2019-09-26 17:01:19 +00:00
|
|
|
} while (len > 0 && ret > 0);
|
2015-11-06 21:18:21 +00:00
|
|
|
|
|
|
|
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)
|