1 .\" Copyright (c) 2003-2009 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_READ_DISK 3
31 .Nm archive_read_disk_new ,
32 .Nm archive_read_disk_open ,
33 .Nm archive_read_disk_open_w ,
34 .Nm archive_read_disk_set_behavior ,
35 .Nm archive_read_disk_set_symlink_logical ,
36 .Nm archive_read_disk_set_symlink_physical ,
37 .Nm archive_read_disk_set_symlink_hybrid ,
38 .Nm archive_read_disk_entry_from_file ,
39 .Nm archive_read_disk_gname ,
40 .Nm archive_read_disk_uname ,
41 .Nm archive_read_disk_set_uname_lookup ,
42 .Nm archive_read_disk_set_gname_lookup ,
43 .Nm archive_read_disk_set_standard_lookup ,
44 .Nm archive_read_disk_descend ,
45 .Nm archive_read_disk_can_descend ,
46 .Nm archive_read_disk_current_filesystem ,
47 .Nm archive_read_disk_current_filesystem_is_synthetic ,
48 .Nm archive_read_disk_current_filesystem_is_remote ,
49 .Nm archive_read_disk_set_matching ,
50 .Nm archive_read_disk_set_metadata_filter_callback ,
51 .Nd functions for reading objects from disk
53 Streaming Archive Library (libarchive, -larchive)
57 .Fn archive_read_disk_new "void"
59 .Fn archive_read_disk_open "struct archive *" "const char *"
61 .Fn archive_read_disk_open_w "struct archive *" "const wchar_t *"
63 .Fn archive_read_disk_set_behavior "struct archive *" "int"
65 .Fn archive_read_disk_set_symlink_logical "struct archive *"
67 .Fn archive_read_disk_set_symlink_physical "struct archive *"
69 .Fn archive_read_disk_set_symlink_hybrid "struct archive *"
71 .Fn archive_read_disk_gname "struct archive *" "gid_t"
73 .Fn archive_read_disk_uname "struct archive *" "uid_t"
75 .Fo archive_read_disk_set_gname_lookup
76 .Fa "struct archive *"
78 .Fa "const char *(*lookup)(void *, gid_t)"
79 .Fa "void (*cleanup)(void *)"
82 .Fo archive_read_disk_set_uname_lookup
83 .Fa "struct archive *"
85 .Fa "const char *(*lookup)(void *, uid_t)"
86 .Fa "void (*cleanup)(void *)"
89 .Fn archive_read_disk_set_standard_lookup "struct archive *"
91 .Fo archive_read_disk_entry_from_file
92 .Fa "struct archive *"
93 .Fa "struct archive_entry *"
95 .Fa "const struct stat *"
98 .Fn archive_read_disk_descend "struct archive *"
100 .Fn archive_read_disk_can_descend "struct archive *"
102 .Fn archive_read_disk_current_filesystem "struct archive *"
104 .Fn archive_read_disk_current_filesystem_is_synthetic "struct archive *"
106 .Fn archive_read_disk_current_filesystem_is_remote "struct archive *"
108 .Fo archive_read_disk_set_matching
109 .Fa "struct archive *"
110 .Fa "struct archive *"
111 .Fa "void (*excluded_func)(struct archive *, void *, struct archive entry *)"
115 .Fo archive_read_disk_set_metadata_filter_callback
116 .Fa "struct archive *"
117 .Fa "int (*metadata_filter_func)(struct archive *, void*, struct archive_entry *)"
121 These functions provide an API for reading information about
123 In particular, they provide an interface for populating
124 .Tn struct archive_entry
126 .Bl -tag -width indent
127 .It Fn archive_read_disk_new
128 Allocates and initializes a
130 object suitable for reading object information from disk.
131 .It Fn archive_read_disk_open
132 Opens the file or directory from the given path and prepares the
134 to read it from disk.
135 .It Fn archive_read_disk_open_w
136 Opens the file or directory from the given path as a wide character string and prepares the
138 to read it from disk.
139 .It Fn archive_read_disk_set_behavior
140 Configures various behavior options when reading entries from disk.
141 The flags field consists of a bitwise OR of one or more of the
143 .Bl -tag -compact -width "indent"
144 .It Cm ARCHIVE_READDISK_HONOR_NODUMP
145 Skip files and directories with the nodump file attribute (file flag) set.
146 By default, the nodump file attribute is ignored.
147 .It Cm ARCHIVE_READDISK_MAC_COPYFILE
149 Read metadata (ACLs and extended attributes) with
151 By default, metadata is read using
153 .It Cm ARCHIVE_READDISK_NO_ACL
154 Do not read Access Control Lists.
155 By default, ACLs are read from disk.
156 .It Cm ARCHIVE_READDISK_NO_FFLAGS
157 Do not read file attributes (file flags).
158 By default, file attributes are read from disk.
164 .Pq FreeBSD, Mac OS X
165 for more information on file attributes.
166 .It Cm ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS
167 Do not traverse mount points.
168 By default, mount points are traversed.
169 .It Cm ARCHIVE_READDISK_NO_XATTR
170 Do not read extended file attributes (xattrs).
171 By default, extended file attributes are read from disk.
180 for more information on extended file attributes.
181 .It Cm ARCHIVE_READDISK_RESTORE_ATIME
182 Restore access time of traversed files.
183 By default, access time of traversed files is not restored.
184 .It Cm ARCHIVE_READDISK_NO_SPARSE
185 Do not read sparse file information.
186 By default, sparse file information is read from disk.
189 .Fn archive_read_disk_set_symlink_logical ,
190 .Fn archive_read_disk_set_symlink_physical ,
191 .Fn archive_read_disk_set_symlink_hybrid
193 This sets the mode used for handling symbolic links.
196 mode follows all symbolic links.
199 mode does not follow any symbolic links.
202 mode currently behaves identically to the
206 .Fn archive_read_disk_gname ,
207 .Fn archive_read_disk_uname
209 Returns a user or group name given a gid or uid value.
210 By default, these always return a NULL string.
212 .Fn archive_read_disk_set_gname_lookup ,
213 .Fn archive_read_disk_set_uname_lookup
215 These allow you to override the functions used for
216 user and group name lookups.
217 You may also provide a
219 pointer to a private data structure and a cleanup function for
221 The cleanup function will be invoked when the
223 object is destroyed or when new lookup functions are registered.
224 .It Fn archive_read_disk_set_standard_lookup
225 This convenience function installs a standard set of user
226 and group name lookup functions.
231 to convert ids to names, defaulting to NULL if the names cannot
233 These functions also implement a simple memory cache to reduce
234 the number of calls to
238 .It Fn archive_read_disk_entry_from_file
240 .Tn struct archive_entry
241 object with information about a particular file.
244 object must have already been created with
245 .Xr archive_entry_new 3
246 and at least one of the source path or path fields must already be set.
247 (If both are set, the source path will be used.)
249 Information is read from disk using the path name from the
250 .Tn struct archive_entry
252 If a file descriptor is provided, some information will be obtained using
253 that file descriptor, on platforms that support the appropriate
258 is provided, information from that structure will be used instead
259 of reading from the disk where appropriate.
260 This can provide performance benefits in scenarios where
262 information has already been read from the disk as a side effect
263 of some other operation.
264 (For example, directory traversal libraries often provide this information.)
266 Where necessary, user and group ids are converted to user and group names
267 using the currently-registered lookup functions above.
268 This affects the file ownership fields and ACL values in the
269 .Tn struct archive_entry
271 .It Fn archive_read_disk_descend
272 If the current entry can be descended, this function will mark the directory as the next entry for
273 .Xr archive_read_header 3
275 .It Fn archive_read_disk_can_descend
276 Returns 1 if the current entry is an unvisited directory and 0 otherwise.
277 .It Fn archive_read_disk_current_filesystem
278 Returns the index of the most recent filesystem entry that has been visited through archive_read_disk
279 .It Fn archive_read_disk_current_filesystem_is_synthetic
280 Returns 1 if the current filesystem is a virtual filesystem. Returns 0 if the current filesystem is not a virtual filesystem. Returns -1 if it is unknown.
281 .It Fn archive_read_disk_current_filesystem_is_remote
282 Returns 1 if the current filesystem is a remote filesystem. Returns 0 if the current filesystem is not a remote filesystem. Returns -1 if it is unknown.
283 .It Fn archive_read_disk_set_matching
284 Allows the caller to set
286 *_ma to compare each entry during
287 .Xr archive_read_header 3
288 calls. If matched based on calls to
289 .Tn archive_match_path_excluded ,
290 .Tn archive_match_time_excluded ,
292 .Tn archive_match_owner_excluded ,
293 then the callback function specified by the _excluded_func parameter will execute. This function will recieve data provided to the fourth parameter, void *_client_data.
294 .It Fn archive_read_disk_set_metadata_filter_callback
295 Allows the caller to set a callback function during calls to
296 .Xr archive_read_header 3
297 to filter out metadata for each entry. The callback function recieves the
299 object, void* custom filter data, and the
300 .Tn struct archive_entry .
301 If the callback function returns an error, ARCHIVE_RETRY will be returned and the entry will not be further processed.
303 More information about the
305 object and the overall design of the library can be found in the
309 The following illustrates basic usage of the library by
310 showing how to use it to copy an item on disk into an archive.
311 .Bd -literal -offset indent
313 file_to_archive(struct archive *a, const char *name)
318 struct archive_entry *entry;
321 ard = archive_read_disk_new();
322 archive_read_disk_set_standard_lookup(ard);
323 entry = archive_entry_new();
324 fd = open(name, O_RDONLY);
327 archive_entry_copy_pathname(entry, name);
328 archive_read_disk_entry_from_file(ard, entry, fd, NULL);
329 archive_write_header(a, entry);
330 while ((bytes_read = read(fd, buff, sizeof(buff))) > 0)
331 archive_write_data(a, buff, bytes_read);
332 archive_write_finish_entry(a);
333 archive_read_free(ard);
334 archive_entry_free(entry);
338 Most functions return
340 (zero) on success, or one of several negative
341 error codes for errors.
342 Specific error codes include:
344 for operations that might succeed if retried,
346 for unusual conditions that do not prevent further operations, and
348 for serious errors that make remaining operations impossible.
350 .Fn archive_read_disk_new
351 returns a pointer to a newly-allocated
353 object or NULL if the allocation failed for any reason.
355 .Fn archive_read_disk_gname
357 .Fn archive_read_disk_uname
360 pointers to the textual name or NULL if the lookup failed for any reason.
361 The returned pointer points to internal storage that
362 may be reused on the next call to either of these functions;
363 callers should copy the string if they need to continue accessing it.
366 Detailed error codes and textual descriptions are available from the
369 .Fn archive_error_string
376 .Xr archive_write 3 ,
377 .Xr archive_write_disk 3 ,
382 library first appeared in
385 .Nm archive_read_disk
386 interface was added to
388 and first appeared in
394 library was written by
395 .An Tim Kientzle Aq kientzle@FreeBSD.org .
399 user name and group name lookup functions are not the defaults because
403 are sometimes too large for particular applications.
404 The current design allows the application author to use a more
405 compact implementation when appropriate.
407 The full list of metadata read from disk by
408 .Fn archive_read_disk_entry_from_file
409 is necessarily system-dependent.
412 .Fn archive_read_disk_entry_from_file
413 function reads as much information as it can from disk.
414 Some method should be provided to limit this so that clients who
415 do not need ACLs, for instance, can avoid the extra work needed
416 to look up such information.
418 This API should provide a set of methods for walking a directory tree.
419 That would make it a direct parallel of the
422 When such methods are implemented, the
424 symbolic link mode will make sense.