1 .\" Copyright (c) 2003-2007 Tim Kientzle
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 .Dt ARCHIVE_WRITE_DISK 3
31 .Nm archive_write_disk_new ,
32 .Nm archive_write_disk_set_options ,
33 .Nm archive_write_disk_set_skip_file ,
34 .Nm archive_write_disk_set_group_lookup ,
35 .Nm archive_write_disk_set_standard_lookup ,
36 .Nm archive_write_disk_set_user_lookup
37 .Nd functions for creating objects on disk
39 Streaming Archive Library (libarchive, -larchive)
43 .Fn archive_write_disk_new "void"
45 .Fn archive_write_disk_set_options "struct archive *" "int flags"
47 .Fn archive_write_disk_set_skip_file "struct archive *" "dev_t" "ino_t"
49 .Fo archive_write_disk_set_group_lookup
50 .Fa "struct archive *"
52 .Fa "gid_t (*)(void *, const char *gname, gid_t gid)"
53 .Fa "void (*cleanup)(void *)"
56 .Fn archive_write_disk_set_standard_lookup "struct archive *"
58 .Fo archive_write_disk_set_user_lookup
59 .Fa "struct archive *"
61 .Fa "uid_t (*)(void *, const char *uname, uid_t uid)"
62 .Fa "void (*cleanup)(void *)"
65 These functions provide a complete API for creating objects on
67 .Tn struct archive_entry
69 They are most naturally used when extracting objects from an archive
73 The general process is to read
74 .Tn struct archive_entry
75 objects from an archive, then write those objects to a
77 object created using the
78 .Fn archive_write_disk
80 This interface is deliberately very similar to the
82 interface used to write objects to a streaming archive.
83 .Bl -tag -width indent
84 .It Fn archive_write_disk_new
85 Allocates and initializes a
87 object suitable for writing objects to disk.
88 .It Fn archive_write_disk_set_skip_file
89 Records the device and inode numbers of a file that should not be
91 This is typically used to ensure that an extraction process does not
92 overwrite the archive from which objects are being read.
93 This capability is technically unnecessary but can be a significant
94 performance optimization in practice.
95 .It Fn archive_write_disk_set_options
96 The options field consists of a bitwise OR of one or more of the
98 .Bl -tag -compact -width "indent"
99 .It Cm ARCHIVE_EXTRACT_ACL
100 Attempt to restore Access Control Lists.
101 By default, extended ACLs are ignored.
102 .It Cm ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS
103 Before removing a file system object prior to replacing it, clear
104 platform-specific file flags which might prevent its removal.
105 .It Cm ARCHIVE_EXTRACT_FFLAGS
106 Attempt to restore file attributes (file flags).
107 By default, file attributes are ignored.
113 .Pq FreeBSD, Mac OS X
114 for more information on file attributes.
115 .It Cm ARCHIVE_EXTRACT_MAC_METADATA
117 Restore metadata using
122 .It Cm ARCHIVE_EXTRACT_NO_OVERWRITE
123 Existing files on disk will not be overwritten.
124 By default, existing regular files are truncated and overwritten;
125 existing directories will have their permissions updated;
126 other pre-existing objects are unlinked and recreated from scratch.
127 .It Cm ARCHIVE_EXTRACT_OWNER
128 The user and group IDs should be set on the restored file.
129 By default, the user and group IDs are not restored.
130 .It Cm ARCHIVE_EXTRACT_PERM
131 Full permissions (including SGID, SUID, and sticky bits) should
132 be restored exactly as specified, without obeying the
134 Note that SUID and SGID bits can only be restored if the
135 user and group ID of the object on disk are correct.
137 .Cm ARCHIVE_EXTRACT_OWNER
138 is not specified, then SUID and SGID bits will only be restored
139 if the default user and group IDs of newly-created objects on disk
140 happen to match those specified in the archive entry.
141 By default, only basic permissions are restored, and umask is obeyed.
142 .It Cm ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
143 Refuse to extract an absolute path.
144 The default is to not refuse such paths.
145 .It Cm ARCHIVE_EXTRACT_SECURE_NODOTDOT
146 Refuse to extract a path that contains a
148 element anywhere within it.
149 The default is to not refuse such paths.
150 Note that paths ending in
152 always cause an error, regardless of this flag.
153 .It Cm ARCHIVE_EXTRACT_SECURE_SYMLINKS
154 Refuse to extract any object whose final location would be altered
155 by a symlink on disk.
156 This is intended to help guard against a variety of mischief
157 caused by archives that (deliberately or otherwise) extract
158 files outside of the current directory.
159 The default is not to perform this check.
161 .It Cm ARCHIVE_EXTRACT_SPARSE
162 Scan data for blocks of NUL bytes and try to recreate them with holes.
163 This results in sparse files, independent of whether the archive format
164 supports or uses them.
165 .Cm ARCHIVE_EXTRACT_UNLINK
166 is specified together with this option, the library will
167 remove any intermediate symlinks it finds and return an
168 error only if such symlink could not be removed.
169 .It Cm ARCHIVE_EXTRACT_TIME
170 The timestamps (mtime, ctime, and atime) should be restored.
171 By default, they are ignored.
172 Note that restoring of atime is not currently supported.
173 .It Cm ARCHIVE_EXTRACT_UNLINK
174 Existing files on disk will be unlinked before any attempt to
176 In some cases, this can prove to be a significant performance improvement.
177 By default, existing files are truncated and rewritten, but
178 the file is not recreated.
179 In particular, the default behavior does not break existing hard links.
180 .It Cm ARCHIVE_EXTRACT_XATTR
181 Attempt to restore extended file attributes.
182 By default, they are ignored.
191 for more information on extended file attributes.
194 .Fn archive_write_disk_set_group_lookup ,
195 .Fn archive_write_disk_set_user_lookup
198 .Tn struct archive_entry
199 objects contain both names and ids that can be used to identify users
201 These names and ids describe the ownership of the file itself and
202 also appear in ACL lists.
203 By default, the library uses the ids and ignores the names, but
204 this can be overridden by registering user and group lookup functions.
205 To register, you must provide a lookup function which
206 accepts both a name and id and returns a suitable id.
207 You may also provide a
209 pointer to a private data structure and a cleanup function for
211 The cleanup function will be invoked when the
214 .It Fn archive_write_disk_set_standard_lookup
215 This convenience function installs a standard set of user
216 and group lookup functions.
221 to convert names to ids, defaulting to the ids if the names cannot
223 These functions also implement a simple memory cache to reduce
224 the number of calls to
229 More information about the
231 object and the overall design of the library can be found in the
234 Many of these functions are also documented under
235 .Xr archive_write 3 .
237 Most functions return
239 (zero) on success, or one of several non-zero
240 error codes for errors.
241 Specific error codes include:
243 for operations that might succeed if retried,
245 for unusual conditions that do not prevent further operations, and
247 for serious errors that make remaining operations impossible.
249 .Fn archive_write_disk_new
250 returns a pointer to a newly-allocated
254 .Fn archive_write_data
255 returns a count of the number of bytes actually written,
261 Detailed error codes and textual descriptions are available from the
264 .Fn archive_error_string
270 .Xr archive_write 3 ,
275 library first appeared in
278 .Nm archive_write_disk
279 interface was added to
281 and first appeared in
287 library was written by
288 .An Tim Kientzle Aq kientzle@acm.org .
290 Directories are actually extracted in two distinct phases.
291 Directories are created during
292 .Fn archive_write_header ,
293 but final permissions are not set until
294 .Fn archive_write_close .
295 This separation is necessary to correctly handle borderline
296 cases such as a non-writable directory containing
297 files, but can cause unexpected results.
298 In particular, directory permissions are not fully
299 restored until the archive is closed.
302 to change the current directory between calls to
303 .Fn archive_read_extract
305 .Fn archive_read_close ,
306 you may confuse the permission-setting logic with
307 the result that directory permissions are restored
310 The library attempts to create objects with filenames longer than
312 by creating prefixes of the full path and changing the current directory.
313 Currently, this logic is limited in scope; the fixup pass does
314 not work correctly for such objects and the symlink security check
315 option disables the support for very long pathnames.
319 does create each intermediate directory.
320 In particular, the directory
322 is created as well as the final object
324 In theory, this can be exploited to create an entire directory hierarchy
325 with a single request.
326 Of course, this does not work if the
327 .Cm ARCHIVE_EXTRACT_NODOTDOT
330 Implicit directories are always created obeying the current umask.
331 Explicit objects are created obeying the current umask unless
332 .Cm ARCHIVE_EXTRACT_PERM
333 is specified, in which case they current umask is ignored.
335 SGID and SUID bits are restored only if the correct user and
338 .Cm ARCHIVE_EXTRACT_OWNER
339 is not specified, then no attempt is made to set the ownership.
340 In this case, SGID and SUID bits are restored only if the
341 user and group of the final object happen to match those specified
346 user-id and group-id lookup functions are not the defaults because
350 are sometimes too large for particular applications.
351 The current design allows the application author to use a more
352 compact implementation when appropriate.
354 There should be a corresponding
355 .Nm archive_read_disk
356 interface that walks a directory hierarchy and returns archive