ManPageArchiveWriteDisk3.wiki 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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.
  91. Restore metadata using
  92. [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]].
  93. By default,
  94. [[copyfile(3)|http://www.freebsd.org/cgi/man.cgi?query=copyfile&sektion=3]]
  95. metadata is ignored.
  96. </dd><dt>'''ARCHIVE_EXTRACT_NO_OVERWRITE'''</dt><dd>
  97. Existing files on disk will not be overwritten.
  98. By default, existing regular files are truncated and overwritten;
  99. existing directories will have their permissions updated;
  100. other pre-existing objects are unlinked and recreated from scratch.
  101. </dd><dt>'''ARCHIVE_EXTRACT_OWNER'''</dt><dd>
  102. The user and group IDs should be set on the restored file.
  103. By default, the user and group IDs are not restored.
  104. </dd><dt>'''ARCHIVE_EXTRACT_PERM'''</dt><dd>
  105. Full permissions (including SGID, SUID, and sticky bits) should
  106. be restored exactly as specified, without obeying the
  107. current umask.
  108. Note that SUID and SGID bits can only be restored if the
  109. user and group ID of the object on disk are correct.
  110. If
  111. '''ARCHIVE_EXTRACT_OWNER'''
  112. is not specified, then SUID and SGID bits will only be restored
  113. if the default user and group IDs of newly-created objects on disk
  114. happen to match those specified in the archive entry.
  115. By default, only basic permissions are restored, and umask is obeyed.
  116. </dd><dt>'''ARCHIVE_EXTRACT_SAFE_WRITES'''</dt><dd>
  117. Extract files atomically, by first creating a unique temporary file and then
  118. renaming it to its required destination name.
  119. This avoids a race where an application might see a partial file (or no
  120. file) during extraction.
  121. </dd><dt>'''ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS'''</dt><dd>
  122. Refuse to extract an absolute path.
  123. The default is to not refuse such paths.
  124. </dd><dt>'''ARCHIVE_EXTRACT_SECURE_NODOTDOT'''</dt><dd>
  125. Refuse to extract a path that contains a
  126. ''..''
  127. element anywhere within it.
  128. The default is to not refuse such paths.
  129. Note that paths ending in
  130. ''..''
  131. always cause an error, regardless of this flag.
  132. </dd><dt>'''ARCHIVE_EXTRACT_SECURE_SYMLINKS'''</dt><dd>
  133. Refuse to extract any object whose final location would be altered
  134. by a symlink on disk.
  135. This is intended to help guard against a variety of mischief
  136. caused by archives that (deliberately or otherwise) extract
  137. files outside of the current directory.
  138. The default is not to perform this check.
  139. If
  140. '''ARCHIVE_EXTRACT_UNLINK'''
  141. is specified together with this option, the library will
  142. remove any intermediate symlinks it finds and return an
  143. error only if such symlink could not be removed.
  144. </dd><dt>'''ARCHIVE_EXTRACT_SPARSE'''</dt><dd>
  145. Scan data for blocks of NUL bytes and try to recreate them with holes.
  146. This results in sparse files, independent of whether the archive format
  147. supports or uses them.
  148. </dd><dt>'''ARCHIVE_EXTRACT_TIME'''</dt><dd>
  149. The timestamps (mtime, ctime, and atime) should be restored.
  150. By default, they are ignored.
  151. Note that restoring of atime is not currently supported.
  152. </dd><dt>'''ARCHIVE_EXTRACT_UNLINK'''</dt><dd>
  153. Existing files on disk will be unlinked before any attempt to
  154. create them.
  155. In some cases, this can prove to be a significant performance improvement.
  156. By default, existing files are truncated and rewritten, but
  157. the file is not recreated.
  158. In particular, the default behavior does not break existing hard links.
  159. </dd><dt>'''ARCHIVE_EXTRACT_XATTR'''</dt><dd>
  160. Attempt to restore extended file attributes.
  161. By default, they are ignored.
  162. See
  163. [[xattr(7)|http://www.freebsd.org/cgi/man.cgi?query=xattr&sektion=7]]
  164. (Linux,)
  165. [[xattr(2)|http://www.freebsd.org/cgi/man.cgi?query=xattr&sektion=2]]
  166. (Mac OS X,)
  167. or
  168. [[getextattr(8)|http://www.freebsd.org/cgi/man.cgi?query=getextattr&sektion=8]]
  169. (FreeBSD)
  170. for more information on extended file attributes.
  171. </dd></dl>
  172. </dd><dt>
  173. '''archive_write_disk_set_group_lookup'''(),
  174. '''archive_write_disk_set_user_lookup'''()
  175. </dt> <dd>
  176. The
  177. '''struct archive_entry'''
  178. objects contain both names and ids that can be used to identify users
  179. and groups.
  180. These names and ids describe the ownership of the file itself and
  181. also appear in ACL lists.
  182. By default, the library uses the ids and ignores the names, but
  183. this can be overridden by registering user and group lookup functions.
  184. To register, you must provide a lookup function which
  185. accepts both a name and id and returns a suitable id.
  186. You may also provide a
  187. '''void *'''
  188. pointer to a private data structure and a cleanup function for
  189. that data.
  190. The cleanup function will be invoked when the
  191. '''struct archive'''
  192. object is destroyed.
  193. </dd><dt>'''archive_write_disk_set_standard_lookup'''()</dt><dd>
  194. This convenience function installs a standard set of user
  195. and group lookup functions.
  196. These functions use
  197. [[getpwnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwnam&sektion=3]]
  198. and
  199. [[getgrnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrnam&sektion=3]]
  200. to convert names to ids, defaulting to the ids if the names cannot
  201. be looked up.
  202. These functions also implement a simple memory cache to reduce
  203. the number of calls to
  204. [[getpwnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwnam&sektion=3]]
  205. and
  206. [[getgrnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrnam&sektion=3]].
  207. </dd></dl>
  208. More information about the
  209. ''struct'' archive
  210. object and the overall design of the library can be found in the
  211. [[ManPageLibarchive3]]
  212. overview.
  213. Many of these functions are also documented under
  214. [[ManPageArchiveWrite3]].
  215. == RETURN VALUES ==
  216. Most functions return
  217. '''ARCHIVE_OK'''
  218. (zero) on success, or one of several non-zero
  219. error codes for errors.
  220. Specific error codes include:
  221. '''ARCHIVE_RETRY'''
  222. for operations that might succeed if retried,
  223. '''ARCHIVE_WARN'''
  224. for unusual conditions that do not prevent further operations, and
  225. '''ARCHIVE_FATAL'''
  226. for serious errors that make remaining operations impossible.
  227. '''archive_write_disk_new'''()
  228. returns a pointer to a newly-allocated
  229. '''struct archive'''
  230. object.
  231. '''archive_write_data'''()
  232. returns a count of the number of bytes actually written,
  233. or
  234. ```text
  235. -1
  236. ```
  237. on error.
  238. == ERRORS ==
  239. Detailed error codes and textual descriptions are available from the
  240. '''archive_errno'''()
  241. and
  242. '''archive_error_string'''()
  243. functions.
  244. == SEE ALSO ==
  245. [[ManPageBsdtar1]],
  246. [[ManPageArchiveRead3]],
  247. [[ManPageArchiveWrite3]],
  248. [[ManPageLibarchive3]]
  249. == HISTORY ==
  250. The
  251. '''libarchive'''
  252. library first appeared in
  253. FreeBSD 5.3.
  254. The
  255. '''archive_write_disk'''
  256. interface was added to
  257. '''libarchive''' 2.0
  258. and first appeared in
  259. FreeBSD 6.3.
  260. == AUTHORS ==
  261. The
  262. '''libarchive'''
  263. library was written by
  264. Tim Kientzle &lt;[email protected].&gt;
  265. == BUGS ==
  266. Directories are actually extracted in two distinct phases.
  267. Directories are created during
  268. '''archive_write_header'''(),
  269. but final permissions are not set until
  270. '''archive_write_close'''().
  271. This separation is necessary to correctly handle borderline
  272. cases such as a non-writable directory containing
  273. files, but can cause unexpected results.
  274. In particular, directory permissions are not fully
  275. restored until the archive is closed.
  276. If you use
  277. [[chdir(2)|http://www.freebsd.org/cgi/man.cgi?query=chdir&sektion=2]]
  278. to change the current directory between calls to
  279. '''archive_read_extract'''()
  280. or before calling
  281. '''archive_read_close'''(),
  282. you may confuse the permission-setting logic with
  283. the result that directory permissions are restored
  284. incorrectly.
  285. The library attempts to create objects with filenames longer than
  286. '''PATH_MAX'''
  287. by creating prefixes of the full path and changing the current directory.
  288. Currently, this logic is limited in scope; the fixup pass does
  289. not work correctly for such objects and the symlink security check
  290. option disables the support for very long pathnames.
  291. Restoring the path
  292. ''aa/../bb''
  293. does create each intermediate directory.
  294. In particular, the directory
  295. ''aa''
  296. is created as well as the final object
  297. ''bb''.
  298. In theory, this can be exploited to create an entire directory hierarchy
  299. with a single request.
  300. Of course, this does not work if the
  301. '''ARCHIVE_EXTRACT_NODOTDOT'''
  302. option is specified.
  303. Implicit directories are always created obeying the current umask.
  304. Explicit objects are created obeying the current umask unless
  305. '''ARCHIVE_EXTRACT_PERM'''
  306. is specified, in which case they current umask is ignored.
  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. The
  316. "standard"
  317. user-id and group-id lookup functions are not the defaults because
  318. [[getgrnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getgrnam&sektion=3]]
  319. and
  320. [[getpwnam(3)|http://www.freebsd.org/cgi/man.cgi?query=getpwnam&sektion=3]]
  321. are sometimes too large for particular applications.
  322. The current design allows the application author to use a more
  323. compact implementation when appropriate.
  324. There should be a corresponding
  325. '''archive_read_disk'''
  326. interface that walks a directory hierarchy and returns archive
  327. entry objects.