1ARCHIVE_WRITE_DISK(3)	 BSD Library Functions Manual	 ARCHIVE_WRITE_DISK(3)
2
3NAME
4     archive_write_disk_new, archive_write_disk_set_options,
5     archive_write_disk_set_skip_file, archive_write_disk_set_group_lookup,
6     archive_write_disk_set_standard_lookup,
7     archive_write_disk_set_user_lookup — functions for creating objects on
8     disk
9
10LIBRARY
11     Streaming Archive Library (libarchive, -larchive)
12
13SYNOPSIS
14     #include <archive.h>
15
16     struct archive *
17     archive_write_disk_new(void);
18
19     int
20     archive_write_disk_set_options(struct archive *, int flags);
21
22     int
23     archive_write_disk_set_skip_file(struct archive *, dev_t, ino_t);
24
25     int
26     archive_write_disk_set_group_lookup(struct archive *, void *,
27	 gid_t (*)(void *, const char *gname, gid_t gid),
28	 void (*cleanup)(void *));
29
30     int
31     archive_write_disk_set_standard_lookup(struct archive *);
32
33     int
34     archive_write_disk_set_user_lookup(struct archive *, void *,
35	 uid_t (*)(void *, const char *uname, uid_t uid),
36	 void (*cleanup)(void *));
37
38DESCRIPTION
39     These functions provide a complete API for creating objects on disk from
40     struct archive_entry descriptions.  They are most naturally used when ex‐
41     tracting objects from an archive using the archive_read() interface.  The
42     general process is to read struct archive_entry objects from an archive,
43     then write those objects to a struct archive object created using the
44     archive_write_disk() family functions.  This interface is deliberately
45     very similar to the archive_write() interface used to write objects to a
46     streaming archive.
47
48     archive_write_disk_new()
49	     Allocates and initializes a struct archive object suitable for
50	     writing objects to disk.
51
52     archive_write_disk_set_skip_file()
53	     Records the device and inode numbers of a file that should not be
54	     overwritten.  This is typically used to ensure that an extraction
55	     process does not overwrite the archive from which objects are be‐
56	     ing read.	This capability is technically unnecessary but can be
57	     a significant performance optimization in practice.
58
59     archive_write_disk_set_options()
60	     The options field consists of a bitwise OR of one or more of the
61	     following values:
62	     ARCHIVE_EXTRACT_ACL
63		     Attempt to restore Access Control Lists.  By default, ex‐
64		     tended ACLs are ignored.
65	     ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS
66		     Before removing a file system object prior to replacing
67		     it, clear platform-specific file flags which might pre‐
68		     vent its removal.
69	     ARCHIVE_EXTRACT_FFLAGS
70		     Attempt to restore file attributes (file flags).  By de‐
71		     fault, file attributes are ignored.  See chattr(1)
72		     (Linux) or chflags(1) (FreeBSD, Mac OS X) for more infor‐
73		     mation on file attributes.
74	     ARCHIVE_EXTRACT_MAC_METADATA
75		     Mac OS X specific.  Restore metadata using copyfile(3).
76		     By default, copyfile(3) metadata is ignored.
77	     ARCHIVE_EXTRACT_NO_OVERWRITE
78		     Existing files on disk will not be overwritten.  By de‐
79		     fault, existing regular files are truncated and overwrit‐
80		     ten; existing directories will have their permissions up‐
81		     dated; other pre-existing objects are unlinked and recre‐
82		     ated from scratch.
83	     ARCHIVE_EXTRACT_OWNER
84		     The user and group IDs should be set on the restored
85		     file.  By default, the user and group IDs are not re‐
86		     stored.
87	     ARCHIVE_EXTRACT_PERM
88		     Full permissions (including SGID, SUID, and sticky bits)
89		     should be restored exactly as specified, without obeying
90		     the current umask.  Note that SUID and SGID bits can only
91		     be restored if the user and group ID of the object on
92		     disk are correct.	If ARCHIVE_EXTRACT_OWNER is not speci‐
93		     fied, then SUID and SGID bits will only be restored if
94		     the default user and group IDs of newly-created objects
95		     on disk happen to match those specified in the archive
96		     entry.  By default, only basic permissions are restored,
97		     and umask is obeyed.
98	     ARCHIVE_EXTRACT_SAFE_WRITES
99		     Extract files atomically, by first creating a unique tem‐
100		     porary file and then renaming it to its required destina‐
101		     tion name.  This avoids a race where an application might
102		     see a partial file (or no file) during extraction.
103	     ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS
104		     Refuse to extract an absolute path.  The default is to
105		     not refuse such paths.
106	     ARCHIVE_EXTRACT_SECURE_NODOTDOT
107		     Refuse to extract a path that contains a .. element any‐
108		     where within it.  The default is to not refuse such
109		     paths.  Note that paths ending in .. always cause an er‐
110		     ror, regardless of this flag.
111	     ARCHIVE_EXTRACT_SECURE_SYMLINKS
112		     Refuse to extract any object whose final location would
113		     be altered by a symlink on disk.  This is intended to
114		     help guard against a variety of mischief caused by ar‐
115		     chives that (deliberately or otherwise) extract files
116		     outside of the current directory.	The default is not to
117		     perform this check.  If
118	     ARCHIVE_EXTRACT_SPARSE
119		     Scan data for blocks of NUL bytes and try to recreate
120		     them with holes.  This results in sparse files, indepen‐
121		     dent of whether the archive format supports or uses them.
122		     ARCHIVE_EXTRACT_UNLINK is specified together with this
123		     option, the library will remove any intermediate symlinks
124		     it finds and return an error only if such symlink could
125		     not be removed.
126	     ARCHIVE_EXTRACT_TIME
127		     The timestamps (mtime, ctime, and atime) should be re‐
128		     stored.  By default, they are ignored.  Note that restor‐
129		     ing of atime is not currently supported.
130	     ARCHIVE_EXTRACT_UNLINK
131		     Existing files on disk will be unlinked before any at‐
132		     tempt to create them.  In some cases, this can prove to
133		     be a significant performance improvement.	By default,
134		     existing files are truncated and rewritten, but the file
135		     is not recreated.	In particular, the default behavior
136		     does not break existing hard links.
137	     ARCHIVE_EXTRACT_XATTR
138		     Attempt to restore extended file attributes.  By default,
139		     they are ignored.	See xattr(7) (Linux), xattr(2) (Mac OS
140		     X), or getextattr(8) (FreeBSD) for more information on
141		     extended file attributes.
142
143     archive_write_disk_set_group_lookup(),
144	     archive_write_disk_set_user_lookup()
145	     The struct archive_entry objects contain both names and ids that
146	     can be used to identify users and groups.	These names and ids
147	     describe the ownership of the file itself and also appear in ACL
148	     lists.  By default, the library uses the ids and ignores the
149	     names, but this can be overridden by registering user and group
150	     lookup functions.	To register, you must provide a lookup func‐
151	     tion which accepts both a name and id and returns a suitable id.
152	     You may also provide a void * pointer to a private data structure
153	     and a cleanup function for that data.  The cleanup function will
154	     be invoked when the struct archive object is destroyed.
155
156     archive_write_disk_set_standard_lookup()
157	     This convenience function installs a standard set of user and
158	     group lookup functions.  These functions use getpwnam(3) and
159	     getgrnam(3) to convert names to ids, defaulting to the ids if the
160	     names cannot be looked up.  These functions also implement a sim‐
161	     ple memory cache to reduce the number of calls to getpwnam(3) and
162	     getgrnam(3).
163     More information about the struct archive object and the overall design
164     of the library can be found in the libarchive(3) overview.  Many of these
165     functions are also documented under archive_write(3).
166
167RETURN VALUES
168     Most functions return ARCHIVE_OK (zero) on success, or one of several
169     non-zero error codes for errors.  Specific error codes include:
170     ARCHIVE_RETRY for operations that might succeed if retried, ARCHIVE_WARN
171     for unusual conditions that do not prevent further operations, and
172     ARCHIVE_FATAL for serious errors that make remaining operations impossi‐
173     ble.
174
175     archive_write_disk_new() returns a pointer to a newly-allocated struct
176     archive object.
177
178     archive_write_data() returns a count of the number of bytes actually
179     written, or -1 on error.
180
181ERRORS
182     Detailed error codes and textual descriptions are available from the
183     archive_errno() and archive_error_string() functions.
184
185SEE ALSO
186     tar(1), archive_read(3), archive_write(3), libarchive(3)
187
188HISTORY
189     The libarchive library first appeared in FreeBSD 5.3.  The
190     archive_write_disk interface was added to libarchive 2.0 and first ap‐
191     peared in FreeBSD 6.3.
192
193AUTHORS
194     The libarchive library was written by Tim Kientzle <kientzle@acm.org>.
195
196BUGS
197     Directories are actually extracted in two distinct phases.  Directories
198     are created during archive_write_header(), but final permissions are not
199     set until archive_write_close().  This separation is necessary to cor‐
200     rectly handle borderline cases such as a non-writable directory contain‐
201     ing files, but can cause unexpected results.  In particular, directory
202     permissions are not fully restored until the archive is closed.  If you
203     use chdir(2) to change the current directory between calls to
204     archive_read_extract() or before calling archive_read_close(), you may
205     confuse the permission-setting logic with the result that directory per‐
206     missions are restored incorrectly.
207
208     The library attempts to create objects with filenames longer than
209     PATH_MAX by creating prefixes of the full path and changing the current
210     directory.  Currently, this logic is limited in scope; the fixup pass
211     does not work correctly for such objects and the symlink security check
212     option disables the support for very long pathnames.
213
214     Restoring the path aa/../bb does create each intermediate directory.  In
215     particular, the directory aa is created as well as the final object bb.
216     In theory, this can be exploited to create an entire directory hierarchy
217     with a single request.  Of course, this does not work if the
218     ARCHIVE_EXTRACT_NODOTDOT option is specified.
219
220     Implicit directories are always created obeying the current umask.  Ex‐
221     plicit objects are created obeying the current umask unless
222     ARCHIVE_EXTRACT_PERM is specified, in which case they current umask is
223     ignored.
224
225     SGID and SUID bits are restored only if the correct user and group could
226     be set.  If ARCHIVE_EXTRACT_OWNER is not specified, then no attempt is
227     made to set the ownership.  In this case, SGID and SUID bits are restored
228     only if the user and group of the final object happen to match those
229     specified in the entry.
230
231     The “standard” user-id and group-id lookup functions are not the defaults
232     because getgrnam(3) and getpwnam(3) are sometimes too large for particu‐
233     lar applications.	The current design allows the application author to
234     use a more compact implementation when appropriate.
235
236     There should be a corresponding archive_read_disk interface that walks a
237     directory hierarchy and returns archive entry objects.
238
239BSD			       January 19, 2020 			   BSD
240