Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | .\" Copyright (c) 2015 Apple Computer, Inc. All rights reserved. .\" .\" The contents of this file constitute Original Code as defined in and .\" are subject to the Apple Public Source License Version 1.1 (the .\" "License"). You may not use this file except in compliance with the .\" License. Please obtain a copy of the License at .\" http://www.apple.com/publicsource and read it before using this file. .\" .\" This Original Code and all software distributed under the License are .\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the .\" License for the specific language governing rights and limitations .\" under the License. .\" .\" @(#)clonefile.2 . .Dd June 3, 2021 .Dt CLONEFILE 2 .Os Darwin .Sh NAME .Nm clonefile .Nd create copy on write clones of files .Sh SYNOPSIS .Fd #include <sys/attr.h> .Fd #include <sys/clonefile.h> .Pp .Ft int .Fn clonefile "const char * src" "const char * dst" "int flags" . .Fn clonefileat "int src_dirfd" "const char * src" "int dst_dirfd" "const char * dst" "int flags" . .Fn fclonefileat "int srcfd" "int dst_dirfd" "const char * dst" "int flags" . .Sh DESCRIPTION The .Fn clonefile function causes the named file .Fa src to be cloned to the named file .Fa dst . The cloned file .Fa dst shares its data blocks with the .Fa src file but has its own copy of attributes and extended attributes which are identical to those of the named file .Fa src with the exceptions listed below .Pp . .Bl -enum . .It ownership information is set as it would be if .Fa dst was created by .Xr openat 2 or .Xr mkdirat 2 or .Xr symlinkat 2 if the current user does not have privileges to change ownership. If the optional flag CLONE_NOOWNERCOPY is passed, the ownership information is the same as if the the current user does not have privileges to change ownership . .It setuid and setgid bits are turned off in the mode bits for regular files. .El .Pp Subsequent writes to either the original or cloned file are private to the file being modified (copy-on-write). The named file .Fa 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 .Fa src names a directory, the directory hierarchy is cloned as if each item was cloned individually. However, the use of .Xr copyfile 3 is more appropriate for copying large directory hierarchies instead of .Xr clonefile 2 .Pp The .Fn clonefileat function is equivalent to .Fn clonefile except in the case where either .Fa src or .Fa 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 .Fa src_dirfd instead of the current working directory. If .Fa dst is a relative path, the same happens only relative to the directory associated with .Fa dst_dirfd . If .Fn clonefileat is passed the special value .Dv AT_FDCWD in either the .Fa src_dirfd or .Fa dst_dirfd parameters, the current working directory is used in the determination of the file for the respective path parameter. .Pp The .Fn fclonefileat function is similar to .Fn clonefileat except that the source is identified by file descriptor .Fa srcfd rather than a path (as in .Fn clonefile or .Fn clonefileat ) .Pp The .Fa flags parameter specifies the options that can be passed. Options are specified in the .Fa flags argument by or'ing the following values: . .Bl -tag -width CLONE_NOFOLLOW . .It CLONE_NOFOLLOW Don't follow the src file if it is a symbolic link (applicable only if the source is not a directory). The symbolic link is itself cloned if .Fa src names a symbolic link. . .El .Pp .Bl -tag -width CLONE_NOOWNERCOPY . .It CLONE_NOOWNERCOPY Don't copy ownership information from the source when run called with superuser privileges. The symbolic link is itself cloned if .Fa src names a symbolic link. . .El .Pp The The .Fn clonefile , .Fn clonefileat and .Fn 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 .Fn clonefile . . .Sh RETURN VALUES Upon successful completion, .Fn clonefile returns 0. Otherwise, a value of -1 is returned and errno is set to indicate the error. .Pp .Sh COMPATIBILITY Not all volumes support .Fn clonefile . A volume can be tested for .Fn clonefile support by using .Xr getattrlist 2 to get the volume capabilities attribute ATTR_VOL_CAPABILITIES, and then testing the VOL_CAP_INT_CLONE flag. .Pp .Sh ERRORS The .Fn clonefile function will fail if: .Bl -tag -width Er . .It Bq Er EACCES Read permissions are denied on the source or write permissions are on the destination parent. . .It Bq Er ENOTSUP The underlying filesystem does not support this call. . .It Bq Er EEXIST The named file .Fa dst exists. . .It Bq Er EXDEV .Fa src and .Fa dst are not on the same filesystem. . .It Bq Er EINVAL The value of the .Fa flags parameter is invalid. . .It Bq Er ENOSPC There is no free space remaining on the file system containing the file. . .It Bq Er EIO An I/O error occurred while reading from or writing to the file system. . .It Bq Er EPERM The calling process does not have appropriate privileges. . .It Bq Er EPERM .Fa src is the root of the Filesystem. . .It Bq Er ELOOP A loop exists in symbolic links encountered during in resolution of the .Fa src or .Fa dst path arguments. . .It Bq Er EROFS The requested operation requires writing in a directory on a read-only file system. . .It Bq Er ENAMETOOLONG The length of a component of a pathname is longer than {NAME_MAX}. . .It Bq Er ENOENT A component of path .Fa src or the path .Fa dst does not name an existing file or path is an empty string. . .It Bq Er ENOTDIR A component of path prefix of either .Fa src or .Fa dst names an existing file that is neither a directory nor a symbolic link to a directory, or the path argument contains at least one non <slash> character and ends with one or more trailing <slash> characters and the last pathname component names an existing file that is neither a directory nor a symbolic link to a directory. . .It Bq Er EDEADLK A component of either pathname refers to a .Dq dataless directory that requires materialization and the I/O policy of the current thread or process disallows dataless directory materialization .Po see .Xr getiopolicy_np 3 .Pc . . .It Bq Er EDEADLK The .Fa src pathname refers to a .Dq dataless file that must be materialized before being cloned and the I/O policy of the current thread or process disallows file materialization .Po see .Xr getiopolicy_np 3 .Pc . .El .Pp In addition, the .Fn clonefileat or .Fn fclonefileat functions may fail with the following errors .Bl -tag -width Er .It Bq Er EBADF The .Fa src or .Fa dst argument does not specify an absolute path and the .Fa src_dirfd or .Fa dst_dirfd argument is neither .Dv AT_FDCWD nor a valid file descriptor open for searching. . .It Bq Er ENOTDIR The .Fa src or .Fa dst argument is not an absolute path and .Fa src_dirfd or .Fa dst_dirfd is neither .Dv AT_FDCWD nor a file descriptor associated with a directory. . .El . .Pp . .Sh SEE ALSO . .Xr copyfile 3 .Xr chown 2 . .Sh HISTORY The .Fn clonefile , .Fn clonefileat and .Fn fclonefileat function calls appeared in OS X version 10.12 . |