ManPageArchiveReadDisk3.wiki 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. ARCHIVE_READ_DISK(3) manual page
  2. == NAME ==
  3. '''archive_read_disk_new''',
  4. '''archive_read_disk_open''',
  5. '''archive_read_disk_open_w''',
  6. '''archive_read_disk_set_behavior''',
  7. '''archive_read_disk_set_symlink_logical''',
  8. '''archive_read_disk_set_symlink_physical''',
  9. '''archive_read_disk_set_symlink_hybrid''',
  10. '''archive_read_disk_entry_from_file''',
  11. '''archive_read_disk_gname''',
  12. '''archive_read_disk_uname''',
  13. '''archive_read_disk_set_uname_lookup''',
  14. '''archive_read_disk_set_gname_lookup''',
  15. '''archive_read_disk_set_standard_lookup''',
  16. '''archive_read_disk_descend''',
  17. '''archive_read_disk_can_descend''',
  18. '''archive_read_disk_current_filesystem''',
  19. '''archive_read_disk_current_filesystem_is_synthetic''',
  20. '''archive_read_disk_current_filesystem_is_remote''',
  21. '''archive_read_disk_set_matching''',
  22. '''archive_read_disk_set_metadata_filter_callback''',
  23. - functions for reading objects from disk
  24. == LIBRARY ==
  25. Streaming Archive Library (libarchive, -larchive)
  26. == SYNOPSIS ==
  27. '''<nowiki>#include <archive.h></nowiki>'''
  28. <br>
  29. ''struct archive *''
  30. <br>
  31. '''archive_read_disk_new'''(''void'');
  32. <br>
  33. ''int''
  34. <br>
  35. '''archive_read_disk_open'''(''struct archive *'', ''const char *'');
  36. <br>
  37. ''int''
  38. <br>
  39. '''archive_read_disk_open_w'''(''struct archive *'', ''const wchar_t *'', '''');
  40. <br>
  41. ''int''
  42. <br>
  43. '''archive_read_disk_set_behavior'''(''struct archive *'', ''int'');
  44. <br>
  45. ''int''
  46. <br>
  47. '''archive_read_disk_set_symlink_logical'''(''struct archive *'');
  48. <br>
  49. ''int''
  50. <br>
  51. '''archive_read_disk_set_symlink_physical'''(''struct archive *'');
  52. <br>
  53. ''int''
  54. <br>
  55. '''archive_read_disk_set_symlink_hybrid'''(''struct archive *'');
  56. <br>
  57. ''const char *''
  58. <br>
  59. '''archive_read_disk_gname'''(''struct archive *'', ''gid_t'');
  60. <br>
  61. ''const char *''
  62. <br>
  63. '''archive_read_disk_uname'''(''struct archive *'', ''uid_t'');
  64. <br>
  65. ''int''
  66. <br>
  67. '''archive_read_disk_set_gname_lookup'''(''struct archive *'', ''void *'', ''const char *(*lookup)(void *, gid_t)'', ''void (*cleanup)(void *)'');
  68. <br>
  69. ''int''
  70. <br>
  71. '''archive_read_disk_set_uname_lookup'''(''struct archive *'', ''void *'', ''const char *(*lookup)(void *, uid_t)'', ''void (*cleanup)(void *)'');
  72. <br>
  73. ''int''
  74. <br>
  75. '''archive_read_disk_set_standard_lookup'''(''struct archive *'');
  76. <br>
  77. ''int''
  78. <br>
  79. '''archive_read_disk_entry_from_file'''(''struct archive *'', ''struct archive_entry *'', ''int fd'', ''const struct stat *'');
  80. <br>
  81. ''int''
  82. <br>
  83. '''archive_read_disk_descend'''(''struct archive *'');
  84. <br>
  85. ''int''
  86. <br>
  87. '''archive_read_disk_can_descend'''(''struct archive *'');
  88. <br>
  89. ''int''
  90. <br>
  91. '''archive_read_disk_current_filesystem'''(''struct archive *'');
  92. <br>
  93. ''int''
  94. <br>
  95. '''archive_read_disk_current_filesystem_is_synthetic'''(''struct archive *'');
  96. <br>
  97. ''int''
  98. <br>
  99. '''archive_read_disk_current_filesystem_is_remote'''(''struct archive *'');
  100. <br>
  101. ''int''
  102. <br>
  103. '''archive_read_disk_set_matching'''(''struct archive *'', ''struct archive *'', ''void (*excluded_func)(struct archive *, void *, struct archive entry *)'', ''void *'');
  104. <br>
  105. ''int''
  106. <br>
  107. '''archive_read_disk_set_metadata_filter_callback'''(''struct archive *'', ''int (*metadata_filter_func)(struct archive *, void*, struct archive_entry *)'', ''void *'');
  108. == DESCRIPTION ==
  109. These functions provide an API for reading information about
  110. objects on disk.
  111. In particular, they provide an interface for populating
  112. '''struct archive_entry'''
  113. objects.
  114. <dl>
  115. <dt>'''archive_read_disk_new'''()</dt><dd>
  116. Allocates and initializes a
  117. '''struct archive'''
  118. object suitable for reading object information from disk.
  119. </dd><dt>'''archive_read_disk_open'''()</dt><dd>
  120. Opens the file or directory from the given path and prepares the
  121. '''struct archive'''
  122. to read it from disk.
  123. </dd><dt>'''archive_read_disk_open_w'''()</dt><dd>
  124. Opens the file or directory from the given path as a wide character string and prepares the
  125. '''struct archive'''
  126. to read it from disk.
  127. </dd><dt>'''archive_read_disk_set_behavior'''()</dt><dd>
  128. Configures various behavior options when reading entries from disk.
  129. The flags field consists of a bitwise OR of one or more of the
  130. following values:
  131. <dl>
  132. <dt>'''ARCHIVE_READDISK_HONOR_NODUMP'''</dt><dd>
  133. Skip files and directories with the nodump file attribute (file flag) set.
  134. By default, the nodump file attribute is ignored.
  135. </dd><dt>'''ARCHIVE_READDISK_MAC_COPYFILE'''</dt><dd>
  136. Mac OS X specific.
  137. Read metadata (ACLs and extended attributes) with
  138. [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]].
  139. By default, metadata is read using
  140. [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]].
  141. </dd><dt>'''ARCHIVE_READDISK_NO_ACL'''</dt><dd>
  142. Do not read Access Control Lists.
  143. By default, ACLs are read from disk.
  144. </dd><dt>'''ARCHIVE_READDISK_NO_FFLAGS'''</dt><dd>
  145. Do not read file attributes (file flags).
  146. By default, file attributes are read from disk.
  147. See
  148. [[chattr(1)|http://www.freebsd.org/cgi/man.cgi?query=chattr&sektion=1]]
  149. (Linux)
  150. or
  151. [[chflags(1)|http://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=1]]
  152. (FreeBSD, Mac OS X)
  153. for more information on file attributes.
  154. </dd><dt>'''ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS'''</dt><dd>
  155. Do not traverse mount points.
  156. By default, mount points are traversed.
  157. </dd><dt>'''ARCHIVE_READDISK_NO_XATTR'''</dt><dd>
  158. Do not read extended file attributes (xattrs).
  159. By default, extended file attributes are read from disk.
  160. See
  161. [[xattr(7)|http://www.freebsd.org/cgi/man.cgi?query=xattr&sektion=7]]
  162. (Linux,)
  163. [[xattr(2)|http://www.freebsd.org/cgi/man.cgi?query=xattr&sektion=2]]
  164. (Mac OS X,)
  165. or
  166. [[getextattr(8)|http://www.freebsd.org/cgi/man.cgi?query=getextattr&sektion=8]]
  167. (FreeBSD)
  168. for more information on extended file attributes.
  169. </dd><dt>'''ARCHIVE_READDISK_RESTORE_ATIME'''</dt><dd>
  170. Restore access time of traversed files.
  171. By default, access time of traversed files is not restored.
  172. </dd><dt>'''ARCHIVE_READDISK_NO_SPARSE'''</dt><dd>
  173. Do not read sparse file information.
  174. By default, sparse file information is read from disk.
  175. </dd></dl>
  176. </dd><dt>
  177. '''archive_read_disk_set_symlink_logical'''(),
  178. '''archive_read_disk_set_symlink_physical'''(),
  179. '''archive_read_disk_set_symlink_hybrid'''()
  180. </dt> <dd>
  181. This sets the mode used for handling symbolic links.
  182. The
  183. "logical"
  184. mode follows all symbolic links.
  185. The
  186. "physical"
  187. mode does not follow any symbolic links.
  188. The
  189. "hybrid"
  190. mode currently behaves identically to the
  191. "logical"
  192. mode.
  193. </dd><dt>
  194. '''archive_read_disk_gname'''(),
  195. '''archive_read_disk_uname'''()
  196. </dt> <dd>
  197. Returns a user or group name given a gid or uid value.
  198. By default, these always return a NULL string.
  199. </dd><dt>
  200. '''archive_read_disk_set_gname_lookup'''(),
  201. '''archive_read_disk_set_uname_lookup'''()
  202. </dt> <dd>
  203. These allow you to override the functions used for
  204. user and group name lookups.
  205. You may also provide a
  206. '''void *'''
  207. pointer to a private data structure and a cleanup function for
  208. that data.
  209. The cleanup function will be invoked when the
  210. '''struct archive'''
  211. object is destroyed or when new lookup functions are registered.
  212. </dd><dt>'''archive_read_disk_set_standard_lookup'''()</dt><dd>
  213. This convenience function installs a standard set of user
  214. and group name lookup functions.
  215. These functions use
  216. [[getpwuid(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwuid&sektion=3]]
  217. and
  218. [[getgrgid(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrgid&sektion=3]]
  219. to convert ids to names, defaulting to NULL if the names cannot
  220. be looked up.
  221. These functions also implement a simple memory cache to reduce
  222. the number of calls to
  223. [[getpwuid(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwuid&sektion=3]]
  224. and
  225. [[getgrgid(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrgid&sektion=3]].
  226. </dd><dt>'''archive_read_disk_entry_from_file'''()</dt><dd>
  227. Populates a
  228. '''struct archive_entry'''
  229. object with information about a particular file.
  230. The
  231. '''archive_entry'''
  232. object must have already been created with
  233. [[ManPageArchiveEntryNew3]]
  234. and at least one of the source path or path fields must already be set.
  235. (If both are set, the source path will be used.)
  236. Information is read from disk using the path name from the
  237. '''struct archive_entry'''
  238. object.
  239. If a file descriptor is provided, some information will be obtained using
  240. that file descriptor, on platforms that support the appropriate
  241. system calls.
  242. If a pointer to a
  243. '''struct stat'''
  244. is provided, information from that structure will be used instead
  245. of reading from the disk where appropriate.
  246. This can provide performance benefits in scenarios where
  247. '''struct stat'''
  248. information has already been read from the disk as a side effect
  249. of some other operation.
  250. (For example, directory traversal libraries often provide this information.)
  251. Where necessary, user and group ids are converted to user and group names
  252. using the currently-registered lookup functions above.
  253. This affects the file ownership fields and ACL values in the
  254. '''struct archive_entry'''
  255. object.
  256. </dd><dt>'''archive_read_disk_descend'''()</dt><dd>
  257. If the current entry can be descended, this function will mark the directory as the next entry for
  258. [[ManPageArchiveReadHeader3]]
  259. to visit.
  260. </dd><dt>'''archive_read_disk_can_descend'''()</dt><dd>
  261. Returns 1 if the current entry is an unvisited directory and 0 otherwise.
  262. </dd><dt>'''archive_read_disk_current_filesystem'''()</dt><dd>
  263. Returns the index of the most recent filesystem entry that has been visited through archive_read_disk
  264. </dd><dt>'''archive_read_disk_current_filesystem_is_synthetic'''()</dt><dd>
  265. 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.
  266. </dd><dt>'''archive_read_disk_current_filesystem_is_remote'''()</dt><dd>
  267. 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.
  268. </dd><dt>'''archive_read_disk_set_matching'''()</dt><dd>
  269. Allows the caller to set
  270. '''struct archive'''
  271. *_ma to compare each entry during
  272. [[ManPageArchiveReadHeader3]]
  273. calls. If matched based on calls to
  274. '''archive_match_path_excluded ,'''
  275. '''archive_match_time_excluded ,'''
  276. or
  277. '''archive_match_owner_excluded ,'''
  278. 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.
  279. </dd><dt>'''archive_read_disk_set_metadata_filter_callback'''()</dt><dd>
  280. Allows the caller to set a callback function during calls to
  281. [[ManPageArchiveReadHeader3]]
  282. to filter out metadata for each entry. The callback function recieves the
  283. '''struct archive'''
  284. object, void* custom filter data, and the
  285. '''struct archive_entry .'''
  286. If the callback function returns an error, ARCHIVE_RETRY will be returned and the entry will not be further processed.
  287. </dd></dl>
  288. More information about the
  289. ''struct'' archive
  290. object and the overall design of the library can be found in the
  291. [[ManPageLibarchive3]]
  292. overview.
  293. == EXAMPLES ==
  294. The following illustrates basic usage of the library by
  295. showing how to use it to copy an item on disk into an archive.
  296. ```text
  297. void
  298. file_to_archive(struct archive *a, const char *name)
  299. {
  300. char buff[8192];
  301. size_t bytes_read;
  302. struct archive *ard;
  303. struct archive_entry *entry;
  304. int fd;
  305. ard = archive_read_disk_new();
  306. archive_read_disk_set_standard_lookup(ard);
  307. entry = archive_entry_new();
  308. fd = open(name, O_RDONLY);
  309. if (fd < 0)
  310. return;
  311. archive_entry_copy_pathname(entry, name);
  312. archive_read_disk_entry_from_file(ard, entry, fd, NULL);
  313. archive_write_header(a, entry);
  314. while ((bytes_read = read(fd, buff, sizeof(buff))) > 0)
  315. archive_write_data(a, buff, bytes_read);
  316. archive_write_finish_entry(a);
  317. archive_read_free(ard);
  318. archive_entry_free(entry);
  319. }
  320. ```
  321. == RETURN VALUES ==
  322. Most functions return
  323. '''ARCHIVE_OK'''
  324. (zero) on success, or one of several negative
  325. error codes for errors.
  326. Specific error codes include:
  327. '''ARCHIVE_RETRY'''
  328. for operations that might succeed if retried,
  329. '''ARCHIVE_WARN'''
  330. for unusual conditions that do not prevent further operations, and
  331. '''ARCHIVE_FATAL'''
  332. for serious errors that make remaining operations impossible.
  333. '''archive_read_disk_new'''()
  334. returns a pointer to a newly-allocated
  335. '''struct archive'''
  336. object or NULL if the allocation failed for any reason.
  337. '''archive_read_disk_gname'''()
  338. and
  339. '''archive_read_disk_uname'''()
  340. return
  341. '''const char *'''
  342. pointers to the textual name or NULL if the lookup failed for any reason.
  343. The returned pointer points to internal storage that
  344. may be reused on the next call to either of these functions;
  345. callers should copy the string if they need to continue accessing it.
  346. == ERRORS ==
  347. Detailed error codes and textual descriptions are available from the
  348. '''archive_errno'''()
  349. and
  350. '''archive_error_string'''()
  351. functions.
  352. == SEE ALSO ==
  353. [[ManPageBsdtar1]],
  354. [[ManPageArchiveRead3]],
  355. [[ManPageArchiveUtil3]],
  356. [[ManPageArchiveWrite3]],
  357. [[ManPageArchiveWriteDisk3]],
  358. [[ManPageLibarchive3]]
  359. == HISTORY ==
  360. The
  361. '''libarchive'''
  362. library first appeared in
  363. FreeBSD 5.3.
  364. The
  365. '''archive_read_disk'''
  366. interface was added to
  367. '''libarchive''' 2.6
  368. and first appeared in
  369. FreeBSD 8.0.
  370. == AUTHORS ==
  371. The
  372. '''libarchive'''
  373. library was written by
  374. Tim Kientzle &lt;[email protected].&gt;
  375. == BUGS ==
  376. The
  377. "standard"
  378. user name and group name lookup functions are not the defaults because
  379. [[getgrgid(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrgid&sektion=3]]
  380. and
  381. [[getpwuid(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwuid&sektion=3]]
  382. are sometimes too large for particular applications.
  383. The current design allows the application author to use a more
  384. compact implementation when appropriate.
  385. The full list of metadata read from disk by
  386. '''archive_read_disk_entry_from_file'''()
  387. is necessarily system-dependent.
  388. The
  389. '''archive_read_disk_entry_from_file'''()
  390. function reads as much information as it can from disk.
  391. Some method should be provided to limit this so that clients who
  392. do not need ACLs, for instance, can avoid the extra work needed
  393. to look up such information.
  394. This API should provide a set of methods for walking a directory tree.
  395. That would make it a direct parallel of the
  396. [[ManPageArchiveRead3]]
  397. API.
  398. When such methods are implemented, the
  399. "hybrid"
  400. symbolic link mode will make sense.