1 ARCHIVE_WRITE_DISK(3) manual page
3 '''archive_write_disk_new''',
4 '''archive_write_disk_set_options''',
5 '''archive_write_disk_set_skip_file''',
6 '''archive_write_disk_set_group_lookup''',
7 '''archive_write_disk_set_standard_lookup''',
8 '''archive_write_disk_set_user_lookup'''
9 - functions for creating objects on disk
11 Streaming Archive Library (libarchive, -larchive)
13 '''<nowiki>#include <archive.h></nowiki>'''
17 '''archive_write_disk_new'''(''void'');
21 '''archive_write_disk_set_options'''(''struct archive *'', ''int flags'');
25 '''archive_write_disk_set_skip_file'''(''struct archive *'', ''dev_t'', ''ino_t'');
29 '''archive_write_disk_set_group_lookup'''(''struct archive *'', ''void *'', ''gid_t (*)(void *, const char *gname, gid_t gid)'', ''void (*cleanup)(void *)'');
33 '''archive_write_disk_set_standard_lookup'''(''struct archive *'');
37 '''archive_write_disk_set_user_lookup'''(''struct archive *'', ''void *'', ''uid_t (*)(void *, const char *uname, uid_t uid)'', ''void (*cleanup)(void *)'');
39 These functions provide a complete API for creating objects on
41 '''struct archive_entry'''
43 They are most naturally used when extracting objects from an archive
47 The general process is to read
48 '''struct archive_entry'''
49 objects from an archive, then write those objects to a
51 object created using the
52 '''archive_write_disk'''()
54 This interface is deliberately very similar to the
56 interface used to write objects to a streaming archive.
58 <dt>'''archive_write_disk_new'''()</dt><dd>
59 Allocates and initializes a
61 object suitable for writing objects to disk.
62 </dd><dt>'''archive_write_disk_set_skip_file'''()</dt><dd>
63 Records the device and inode numbers of a file that should not be
65 This is typically used to ensure that an extraction process does not
66 overwrite the archive from which objects are being read.
67 This capability is technically unnecessary but can be a significant
68 performance optimization in practice.
69 </dd><dt>'''archive_write_disk_set_options'''()</dt><dd>
70 The options field consists of a bitwise OR of one or more of the
73 <dt>'''ARCHIVE_EXTRACT_ACL'''</dt><dd>
74 Attempt to restore Access Control Lists.
75 By default, extended ACLs are ignored.
76 </dd><dt>'''ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS'''</dt><dd>
77 Before removing a file system object prior to replacing it, clear
78 platform-specific file flags which might prevent its removal.
79 </dd><dt>'''ARCHIVE_EXTRACT_FFLAGS'''</dt><dd>
80 Attempt to restore file attributes (file flags).
81 By default, file attributes are ignored.
83 [[chattr(1)|http://www.freebsd.org/cgi/man.cgi?query=chattr&sektion=1]]
86 [[chflags(1)|http://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=1]]
88 for more information on file attributes.
89 </dd><dt>'''ARCHIVE_EXTRACT_MAC_METADATA'''</dt><dd>
90 Mac OS X specific. Restore metadata using
91 [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]].
93 [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]]
95 </dd><dt>'''ARCHIVE_EXTRACT_NO_OVERWRITE'''</dt><dd>
96 Existing files on disk will not be overwritten.
97 By default, existing regular files are truncated and overwritten;
98 existing directories will have their permissions updated;
99 other pre-existing objects are unlinked and recreated from scratch.
100 </dd><dt>'''ARCHIVE_EXTRACT_OWNER'''</dt><dd>
101 The user and group IDs should be set on the restored file.
102 By default, the user and group IDs are not restored.
103 </dd><dt>'''ARCHIVE_EXTRACT_PERM'''</dt><dd>
104 Full permissions (including SGID, SUID, and sticky bits) should
105 be restored exactly as specified, without obeying the
107 Note that SUID and SGID bits can only be restored if the
108 user and group ID of the object on disk are correct.
110 '''ARCHIVE_EXTRACT_OWNER'''
111 is not specified, then SUID and SGID bits will only be restored
112 if the default user and group IDs of newly-created objects on disk
113 happen to match those specified in the archive entry.
114 By default, only basic permissions are restored, and umask is obeyed.
115 </dd><dt>'''ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS'''</dt><dd>
116 Refuse to extract an absolute path.
117 The default is to not refuse such paths.
118 </dd><dt>'''ARCHIVE_EXTRACT_SECURE_NODOTDOT'''</dt><dd>
119 Refuse to extract a path that contains a
121 element anywhere within it.
122 The default is to not refuse such paths.
123 Note that paths ending in
125 always cause an error, regardless of this flag.
126 </dd><dt>'''ARCHIVE_EXTRACT_SECURE_SYMLINKS'''</dt><dd>
127 Refuse to extract any object whose final location would be altered
128 by a symlink on disk.
129 This is intended to help guard against a variety of mischief
130 caused by archives that (deliberately or otherwise) extract
131 files outside of the current directory.
132 The default is not to perform this check.
134 </dd><dt>'''ARCHIVE_EXTRACT_SPARSE'''</dt><dd>
135 Scan data for blocks of NUL bytes and try to recreate them with holes.
136 This results in sparse files, independent of whether the archive format
137 supports or uses them.
138 '''ARCHIVE_EXTRACT_UNLINK'''
139 is specified together with this option, the library will
140 remove any intermediate symlinks it finds and return an
141 error only if such symlink could not be removed.
142 </dd><dt>'''ARCHIVE_EXTRACT_TIME'''</dt><dd>
143 The timestamps (mtime, ctime, and atime) should be restored.
144 By default, they are ignored.
145 Note that restoring of atime is not currently supported.
146 </dd><dt>'''ARCHIVE_EXTRACT_UNLINK'''</dt><dd>
147 Existing files on disk will be unlinked before any attempt to
149 In some cases, this can prove to be a significant performance improvement.
150 By default, existing files are truncated and rewritten, but
151 the file is not recreated.
152 In particular, the default behavior does not break existing hard links.
153 </dd><dt>'''ARCHIVE_EXTRACT_XATTR'''</dt><dd>
154 Attempt to restore extended file attributes.
155 By default, they are ignored.
157 [[xattr(7)|http://www.freebsd.org/cgi/man.cgi?query=xattr&sektion=7]]
159 [[xattr(2)|http://www.freebsd.org/cgi/man.cgi?query=xattr&sektion=2]]
162 [[getextattr(8)|http://www.freebsd.org/cgi/man.cgi?query=getextattr&sektion=8]]
164 for more information on extended file attributes.
167 '''archive_write_disk_set_group_lookup'''(),
168 '''archive_write_disk_set_user_lookup'''()
171 '''struct archive_entry'''
172 objects contain both names and ids that can be used to identify users
174 These names and ids describe the ownership of the file itself and
175 also appear in ACL lists.
176 By default, the library uses the ids and ignores the names, but
177 this can be overridden by registering user and group lookup functions.
178 To register, you must provide a lookup function which
179 accepts both a name and id and returns a suitable id.
180 You may also provide a
182 pointer to a private data structure and a cleanup function for
184 The cleanup function will be invoked when the
187 </dd><dt>'''archive_write_disk_set_standard_lookup'''()</dt><dd>
188 This convenience function installs a standard set of user
189 and group lookup functions.
191 [[getpwnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwnam&sektion=3]]
193 [[getgrnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrnam&sektion=3]]
194 to convert names to ids, defaulting to the ids if the names cannot
196 These functions also implement a simple memory cache to reduce
197 the number of calls to
198 [[getpwnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwnam&sektion=3]]
200 [[getgrnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrnam&sektion=3]].
202 More information about the
204 object and the overall design of the library can be found in the
205 [[ManPageLibarchive3]]
207 Many of these functions are also documented under
208 [[ManPageArchiveWrite3]].
210 Most functions return
212 (zero) on success, or one of several non-zero
213 error codes for errors.
214 Specific error codes include:
216 for operations that might succeed if retried,
218 for unusual conditions that do not prevent further operations, and
220 for serious errors that make remaining operations impossible.
222 '''archive_write_disk_new'''()
223 returns a pointer to a newly-allocated
227 '''archive_write_data'''()
228 returns a count of the number of bytes actually written,
235 Detailed error codes and textual descriptions are available from the
236 '''archive_errno'''()
238 '''archive_error_string'''()
241 [[ManPageArchiveRead3]],
242 [[ManPageArchiveWrite3]],
244 [[ManPageLibarchive3]]
248 library first appeared in
251 '''archive_write_disk'''
252 interface was added to
254 and first appeared in
259 library was written by
260 Tim Kientzle <kientzle@acm.org.>
262 Directories are actually extracted in two distinct phases.
263 Directories are created during
264 '''archive_write_header'''(),
265 but final permissions are not set until
266 '''archive_write_close'''().
267 This separation is necessary to correctly handle borderline
268 cases such as a non-writable directory containing
269 files, but can cause unexpected results.
270 In particular, directory permissions are not fully
271 restored until the archive is closed.
273 [[chdir(2)|http://www.freebsd.org/cgi/man.cgi?query=chdir&sektion=2]]
274 to change the current directory between calls to
275 '''archive_read_extract'''()
277 '''archive_read_close'''(),
278 you may confuse the permission-setting logic with
279 the result that directory permissions are restored
282 The library attempts to create objects with filenames longer than
284 by creating prefixes of the full path and changing the current directory.
285 Currently, this logic is limited in scope; the fixup pass does
286 not work correctly for such objects and the symlink security check
287 option disables the support for very long pathnames.
291 does create each intermediate directory.
292 In particular, the directory
294 is created as well as the final object
296 In theory, this can be exploited to create an entire directory hierarchy
297 with a single request.
298 Of course, this does not work if the
299 '''ARCHIVE_EXTRACT_NODOTDOT'''
302 Implicit directories are always created obeying the current umask.
303 Explicit objects are created obeying the current umask unless
304 '''ARCHIVE_EXTRACT_PERM'''
305 is specified, in which case they current umask is ignored.
307 SGID and SUID bits are restored only if the correct user and
310 '''ARCHIVE_EXTRACT_OWNER'''
311 is not specified, then no attempt is made to set the ownership.
312 In this case, SGID and SUID bits are restored only if the
313 user and group of the final object happen to match those specified
318 user-id and group-id lookup functions are not the defaults because
319 [[getgrnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrnam&sektion=3]]
321 [[getpwnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwnam&sektion=3]]
322 are sometimes too large for particular applications.
323 The current design allows the application author to use a more
324 compact implementation when appropriate.
326 There should be a corresponding
327 '''archive_read_disk'''
328 interface that walks a directory hierarchy and returns archive