1 .\" Copyright (c) 2017-2018 Apple Computer, Inc. All rights reserved.
3 .\" The contents of this file constitute Original Code as defined in and
4 .\" are subject to the Apple Public Source License Version 1.1 (the
5 .\" "License"). You may not use this file except in compliance with the
6 .\" License. Please obtain a copy of the License at
7 .\" http://www.apple.com/publicsource and read it before using this file.
9 .\" This Original Code and all software distributed under the License are
10 .\" distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
11 .\" EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
12 .\" INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
13 .\" FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
14 .\" License for the specific language governing rights and limitations
15 .\" under the License.
17 .\" @(#)fs_snapshot_create.2
20 .Dt FS_SNAPSHOT_CREATE 2
23 .Nm fs_snapshot_create
24 .Nd create read only snapshot of a mounted filesystem
26 .Fd #include <sys/attr.h>
27 .Fd #include <sys/snapshot.h>
30 .Fn fs_snapshot_create "int dirfd" "const char * name" "uint32_t flags"
33 .Fn fs_snapshot_delete "int dirfd" "const char * name" "uint32_t flags"
36 .Fn fs_snapshot_list "int dirfd" "struct attrlist * name" "void * attrbuf" "size_t bufsize" "uint32_t flags"
39 .Fn fs_snapshot_rename "int dirfd" "const char * old" "const char * new" "uint32_t flags"
42 .Fn fs_snapshot_mount "int dirfd" "const char * dir" "const char * snapshot" "uint32_t flags"
45 .Fn fs_snapshot_revert "int dirfd" "const char * name" "uint32_t flags"
49 .Fn fs_snapshot_create
50 function, for supported Filesystems, causes a snapshot of the Filesystem to be created. A snapshot is a read only copy
51 of the filesystem frozen at a point in time. The Filesystem is identified by the
53 parameter which should be a file descriptor associated with the root directory of the filesystem for which the snapshot is to be created.
55 can be any valid name for a component name (except . and ..).
58 .Fn fs_snapshot_delete
59 function causes the named snapshot
62 .Fn fs_snapshot_rename
63 function causes the named snapshot
65 to be renamed to the name
67 Available snapshots along with their attributes can be listed by calling
69 which is to be used in exactly the same way as
70 .Xr getattrlistbulk 2 .
74 parameter specifies the options that can be passed. No options are currently defined.
76 Snapshots may be useful for backing up the Filesystem and to restore the Filesystem to a previous state.
77 Snapshots are expected to consume no additional storage on creation but might consume additional storage as the active
78 Filesystem is modified. Similarly deletion of files on the active filesystem may not result in the storage being available
79 if the snapshot contains the file. Additionally, the underlying Filesystem may impose a limit on the number
80 of snapshots that can be taken. For supporting Filesystems, a snapshot may be used as a source for a mount. This can be done
83 function. The snapshot will be mounted read only. When a snapshot is mounted, it cannot be deleted but it can be renamed.
84 To revert the filesystem to a previous snapshot, the
85 .Fn fs_snapshot_revert
86 can be used. It should be noted that reverting a filesystem to a snapshot is a destructive operation and causes all
87 changes made to the filesystem (including snapshots created after the snapshot being reverted to) to be lost.
90 All snapshot functions require superuser privileges and also require an additional entitlement.
93 Upon successful completion,
94 .Fn fs_snapshot_create
96 .Fn fs_snapshot_delete
98 .Fn fs_snapshot_rename
99 returns 0. Otherwise, a value of -1 is returned and errno is set to indicate the error.
101 returns the number of entries successfully read. A return value of 0 indicates there are no more entries.
102 Otherwise, a value of -1 is returned and errno is set to indicate the error. Return values are the same as
103 .Xr getattrlistbulk 2 .
106 Not all volumes support snapshots. A volume can be tested for snapshot support
109 to get the volume capabilities attribute ATTR_VOL_CAPABILITIES, and then testing the VOL_CAP_INT_SNAPSHOT flag.
113 .Fn fs_snapshot_create
115 .Fn fs_snapshot_delete
117 .Fn fs_snapshot_rename
120 function will fail if:
124 Read permissions are denied for the caller on the filesystem
127 The underlying filesystem does not support this call.
132 parameter is invalid.
135 There is no free space remaining on the file system containing the file.
138 The limit for the maximum number of snapshots for a filesystem has been reached.
141 An I/O error occurred while reading from or writing to the file system.
144 The calling process does not have appropriate privileges.
147 The requested operation requires modifications in a read-only file system.
149 .It Bq Er ENAMETOOLONG
150 The length of a component of a pathname is longer than {NAME_MAX}.
153 dirfd is not a valid file descriptor.
156 dirfd is a file descriptor associated with a non-directory file.
160 .Fn fs_snapshot_create
162 .Fn fs_snapshot_rename
163 functions may fail with the following errors
166 The The named snapshot to be created already exists or the new name already
167 exists for the snapshot being renamed.
171 .Fn fs_snapshot_create
173 .Fn fs_snapshot_rename
174 functions may fail with the following errors
177 The named snapshot does not exist.
181 .Fn fs_snapshot_delete
182 function may fail with
185 The named snapshot is currently mounted.
191 .Xr getattrlistbulk 2
195 .Fn fs_snapshot_create
197 .Fn fs_snapshot_delete
199 .Fn fs_snapshot_delete
202 function calls appeared in macOS version 10.13