d3e1a4e16248264c2ab1a8d3c35100eab3c66efc
[platform/upstream/libarchive.git] / doc / wiki / ManPageArchiveWriteDisk3.wiki
1 ARCHIVE_WRITE_DISK(3) manual page 
2 == NAME == 
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 
10 == LIBRARY == 
11 Streaming Archive Library (libarchive, -larchive) 
12 == SYNOPSIS == 
13 '''<nowiki>#include <archive.h></nowiki>''' 
14 <br> 
15 ''struct archive *'' 
16 <br> 
17 '''archive_write_disk_new'''(''void''); 
18 <br> 
19 ''int'' 
20 <br> 
21 '''archive_write_disk_set_options'''(''struct archive *'', ''int flags''); 
22 <br> 
23 ''int'' 
24 <br> 
25 '''archive_write_disk_set_skip_file'''(''struct archive *'', ''dev_t'', ''ino_t''); 
26 <br> 
27 ''int'' 
28 <br> 
29 '''archive_write_disk_set_group_lookup'''(''struct archive *'', ''void *'', ''gid_t (*)(void *, const char *gname, gid_t gid)'', ''void (*cleanup)(void *)''); 
30 <br> 
31 ''int'' 
32 <br> 
33 '''archive_write_disk_set_standard_lookup'''(''struct archive *''); 
34 <br> 
35 ''int'' 
36 <br> 
37 '''archive_write_disk_set_user_lookup'''(''struct archive *'', ''void *'', ''uid_t (*)(void *, const char *uname, uid_t uid)'', ''void (*cleanup)(void *)''); 
38 == DESCRIPTION == 
39 These functions provide a complete API for creating objects on 
40 disk from 
41 '''struct archive_entry''' 
42 descriptions. 
43 They are most naturally used when extracting objects from an archive 
44 using the 
45 '''archive_read'''() 
46 interface. 
47 The general process is to read 
48 '''struct archive_entry''' 
49 objects from an archive, then write those objects to a 
50 '''struct archive''' 
51 object created using the 
52 '''archive_write_disk'''() 
53 family functions. 
54 This interface is deliberately very similar to the 
55 '''archive_write'''() 
56 interface used to write objects to a streaming archive. 
57 <dl> 
58 <dt>'''archive_write_disk_new'''()</dt><dd> 
59 Allocates and initializes a 
60 '''struct archive''' 
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 
64 overwritten. 
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 
71 following values: 
72 <dl> 
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. 
82 See 
83 [[chattr(1)|http://www.freebsd.org/cgi/man.cgi?query=chattr&sektion=1]] 
84 (Linux) 
85 or 
86 [[chflags(1)|http://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=1]] 
87 (FreeBSD, Mac OS X) 
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]]. 
92 By default, 
93 [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]] 
94 metadata is ignored. 
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 
106 current umask. 
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. 
109 If 
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 
120 ''..'' 
121 element anywhere within it. 
122 The default is to not refuse such paths. 
123 Note that paths ending in 
124 ''..'' 
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. 
133 If 
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 
148 create them. 
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. 
156 See 
157 [[xattr(7)|http://www.freebsd.org/cgi/man.cgi?query=xattr&sektion=7]] 
158 (Linux,) 
159 [[xattr(2)|http://www.freebsd.org/cgi/man.cgi?query=xattr&sektion=2]] 
160 (Mac OS X,) 
161 or 
162 [[getextattr(8)|http://www.freebsd.org/cgi/man.cgi?query=getextattr&sektion=8]] 
163 (FreeBSD) 
164 for more information on extended file attributes. 
165 </dd></dl> 
166 </dd><dt> 
167 '''archive_write_disk_set_group_lookup'''(), 
168 '''archive_write_disk_set_user_lookup'''() 
169 </dt> <dd> 
170 The 
171 '''struct archive_entry''' 
172 objects contain both names and ids that can be used to identify users 
173 and groups. 
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 
181 '''void *''' 
182 pointer to a private data structure and a cleanup function for 
183 that data. 
184 The cleanup function will be invoked when the 
185 '''struct archive''' 
186 object is destroyed. 
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. 
190 These functions use 
191 [[getpwnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwnam&sektion=3]] 
192 and 
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 
195 be looked up. 
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]] 
199 and 
200 [[getgrnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrnam&sektion=3]]. 
201 </dd></dl> 
202 More information about the 
203 ''struct'' archive 
204 object and the overall design of the library can be found in the 
205 [[ManPageLibarchive3]] 
206 overview. 
207 Many of these functions are also documented under 
208 [[ManPageArchiveWrite3]]. 
209 == RETURN VALUES == 
210 Most functions return 
211 '''ARCHIVE_OK''' 
212 (zero) on success, or one of several non-zero 
213 error codes for errors. 
214 Specific error codes include: 
215 '''ARCHIVE_RETRY''' 
216 for operations that might succeed if retried, 
217 '''ARCHIVE_WARN''' 
218 for unusual conditions that do not prevent further operations, and 
219 '''ARCHIVE_FATAL''' 
220 for serious errors that make remaining operations impossible. 
221
222 '''archive_write_disk_new'''() 
223 returns a pointer to a newly-allocated 
224 '''struct archive''' 
225 object. 
226
227 '''archive_write_data'''() 
228 returns a count of the number of bytes actually written, 
229 or 
230 ```text
231 -1 
232 ```
233 on error. 
234 == ERRORS == 
235 Detailed error codes and textual descriptions are available from the 
236 '''archive_errno'''() 
237 and 
238 '''archive_error_string'''() 
239 functions. 
240 == SEE ALSO == 
241 [[ManPageArchiveRead3]], 
242 [[ManPageArchiveWrite3]], 
243 [[ManPageBsdtar1]], 
244 [[ManPageLibarchive3]] 
245 == HISTORY == 
246 The 
247 '''libarchive''' 
248 library first appeared in 
249 FreeBSD 5.3. 
250 The 
251 '''archive_write_disk''' 
252 interface was added to 
253 '''libarchive''' 2.0 
254 and first appeared in 
255 FreeBSD 6.3. 
256 == AUTHORS == 
257 The 
258 '''libarchive''' 
259 library was written by 
260 Tim Kientzle  &lt;kientzle@acm.org.&gt; 
261 == BUGS == 
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. 
272 If you use 
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'''() 
276 or before calling 
277 '''archive_read_close'''(), 
278 you may confuse the permission-setting logic with 
279 the result that directory permissions are restored 
280 incorrectly. 
281
282 The library attempts to create objects with filenames longer than 
283 '''PATH_MAX''' 
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. 
288
289 Restoring the path 
290 ''aa/../bb'' 
291 does create each intermediate directory. 
292 In particular, the directory 
293 ''aa'' 
294 is created as well as the final object 
295 ''bb''. 
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''' 
300 option is specified. 
301
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. 
306
307 SGID and SUID bits are restored only if the correct user and 
308 group could be set. 
309 If 
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 
314 in the entry. 
315
316 The 
317 "standard" 
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]] 
320 and 
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. 
325
326 There should be a corresponding 
327 '''archive_read_disk''' 
328 interface that walks a directory hierarchy and returns archive 
329 entry objects.