CLONEFILE(2) | System Calls Manual | CLONEFILE(2) |
clonefile
— create
copy on write clones of files
#include
<sys/attr.h>
#include <sys/clonefile.h>
int
clonefile
(const
char * src, const char *
dst, int
flags);
clonefileat
(int
src_dirfd, const char *
src, int dst_dirfd,
const char * dst,
int flags);
fclonefileat
(int
srcfd, int
dst_dirfd, const char *
dst, int
flags);
Cloning directories with these functions is strongly discouraged. Use copyfile(3) to clone directories instead.
The
clonefile
()
function causes the named file src to be cloned to the
named file dst. The cloned file
dst shares its data blocks with the
src file but has its own copy of attributes and
extended attributes which are identical to those of the named file
src with the exceptions listed below:
Subsequent writes to either the original or cloned file are private to the file being modified (copy-on-write). The named file dst must not exist for the call to be successful. Since the clonefile() system call might not allocate new storage for data blocks, it is possible for a subsequent overwrite of an existing data block to return ENOSPC. If src names a directory, the directory hierarchy is cloned as if each item was cloned individually. However, the use of clonefile(2) to clone directory hierarchies is strongly discouraged. Use copyfile(3) instead for copying directories.
The
clonefileat
()
function is equivalent to clonefile
() except in the
case where either src or dst
specifies a relative path. If src is a relative path, the file to be cloned
is located relative to the directory associated with the file descriptor
src_dirfd instead of the current working directory. If
dst is a relative path, the same happens only relative
to the directory associated with dst_dirfd. If
clonefileat
() is passed the special value
AT_FDCWD
in either the
src_dirfd or dst_dirfd
parameters, the current working directory is used in the determination of
the file for the respective path parameter.
The
fclonefileat
()
function is similar to clonefileat
() except that the
source is identified by file descriptor srcfd rather
than a path (as in clonefile
() or
clonefileat
() ).
The flags parameter specifies the options that can be passed. Options are specified in the flags argument by or'ing the following values:
The
clonefile
(),
clonefileat
() and
fclonefileat
() functions are expected to be atomic
i.e. the system call will result all new objects being created successfully
or no new objects will be created. POSIX conforming applications cannot use
clonefile
().
Upon successful completion, clonefile
()
returns 0. Otherwise, a value of -1 is returned and errno is set to indicate
the error.
Not all volumes support clonefile
(). A
volume can be tested for clonefile
() support by
using getattrlist(2) to get the volume capabilities
attribute ATTR_VOL_CAPABILITIES, and then testing the VOL_CAP_INT_CLONE
flag.
The clonefile
() function will fail if:
EACCES
]ENOTSUP
]EEXIST
]EXDEV
]EINVAL
]ENOSPC
]EIO
]EPERM
]EPERM
]ELOOP
]EROFS
]ENAMETOOLONG
]ENOENT
]ENOTDIR
]EDEADLK
]EDEADLK
]In addition, the clonefileat
() or
fclonefileat
() functions may fail with the following
errors:
EBADF
]AT_FDCWD
nor a valid file descriptor open for
searching.ENOTDIR
]AT_FDCWD
nor a file descriptor associated with a
directory.The clonefile
(),
clonefileat
() and
fclonefileat
() function calls appeared in OS X
version 10.12
June 3, 2021 | Darwin |