1ARCHIVE_WRITE_DISK(3)    BSD Library Functions Manual    ARCHIVE_WRITE_DISK(3)
2

NAME

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

LIBRARY

11     Streaming Archive Library (libarchive, -larchive)
12

SYNOPSIS

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

DESCRIPTION

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 ARCHIVE_EXTRACT_UNLINK is speci‐
118                     fied together with this option, the library will remove
119                     any intermediate symlinks it finds and return an error
120                     only if such symlink could not be removed.
121             ARCHIVE_EXTRACT_SPARSE
122                     Scan data for blocks of NUL bytes and try to recreate
123                     them with holes.  This results in sparse files, indepen‐
124                     dent of whether the archive format supports or uses them.
125             ARCHIVE_EXTRACT_TIME
126                     The timestamps (mtime, ctime, and atime) should be re‐
127                     stored.  By default, they are ignored.  Note that restor‐
128                     ing of atime is not currently supported.
129             ARCHIVE_EXTRACT_UNLINK
130                     Existing files on disk will be unlinked before any at‐
131                     tempt to create them.  In some cases, this can prove to
132                     be a significant performance improvement.  By default,
133                     existing files are truncated and rewritten, but the file
134                     is not recreated.  In particular, the default behavior
135                     does not break existing hard links.
136             ARCHIVE_EXTRACT_XATTR
137                     Attempt to restore extended file attributes.  By default,
138                     they are ignored.  See xattr(7) (Linux), xattr(2) (Mac OS
139                     X), or getextattr(8) (FreeBSD) for more information on
140                     extended file attributes.
141
142     archive_write_disk_set_group_lookup(),
143             archive_write_disk_set_user_lookup()
144             The struct archive_entry objects contain both names and ids that
145             can be used to identify users and groups.  These names and ids
146             describe the ownership of the file itself and also appear in ACL
147             lists.  By default, the library uses the ids and ignores the
148             names, but this can be overridden by registering user and group
149             lookup functions.  To register, you must provide a lookup func‐
150             tion which accepts both a name and id and returns a suitable id.
151             You may also provide a void * pointer to a private data structure
152             and a cleanup function for that data.  The cleanup function will
153             be invoked when the struct archive object is destroyed.
154
155     archive_write_disk_set_standard_lookup()
156             This convenience function installs a standard set of user and
157             group lookup functions.  These functions use getpwnam(3) and
158             getgrnam(3) to convert names to ids, defaulting to the ids if the
159             names cannot be looked up.  These functions also implement a sim‐
160             ple memory cache to reduce the number of calls to getpwnam(3) and
161             getgrnam(3).
162     More information about the struct archive object and the overall design
163     of the library can be found in the libarchive(3) overview.  Many of these
164     functions are also documented under archive_write(3).
165

RETURN VALUES

167     Most functions return ARCHIVE_OK (zero) on success, or one of several
168     non-zero error codes for errors.  Specific error codes include:
169     ARCHIVE_RETRY for operations that might succeed if retried, ARCHIVE_WARN
170     for unusual conditions that do not prevent further operations, and
171     ARCHIVE_FATAL for serious errors that make remaining operations impossi‐
172     ble.
173
174     archive_write_disk_new() returns a pointer to a newly-allocated struct
175     archive object.
176
177     archive_write_data() returns a count of the number of bytes actually
178     written, or -1 on error.
179

ERRORS

181     Detailed error codes and textual descriptions are available from the
182     archive_errno() and archive_error_string() functions.
183

SEE ALSO

185     tar(1), archive_read(3), archive_write(3), libarchive(3)
186

HISTORY

188     The libarchive library first appeared in FreeBSD 5.3.  The
189     archive_write_disk interface was added to libarchive 2.0 and first ap‐
190     peared in FreeBSD 6.3.
191

AUTHORS

193     The libarchive library was written by Tim Kientzle <kientzle@acm.org>.
194

BUGS

196     Directories are actually extracted in two distinct phases.  Directories
197     are created during archive_write_header(), but final permissions are not
198     set until archive_write_close().  This separation is necessary to cor‐
199     rectly handle borderline cases such as a non-writable directory contain‐
200     ing files, but can cause unexpected results.  In particular, directory
201     permissions are not fully restored until the archive is closed.  If you
202     use chdir(2) to change the current directory between calls to
203     archive_read_extract() or before calling archive_read_close(), you may
204     confuse the permission-setting logic with the result that directory per‐
205     missions are restored incorrectly.
206
207     The library attempts to create objects with filenames longer than
208     PATH_MAX by creating prefixes of the full path and changing the current
209     directory.  Currently, this logic is limited in scope; the fixup pass
210     does not work correctly for such objects and the symlink security check
211     option disables the support for very long pathnames.
212
213     Restoring the path aa/../bb does create each intermediate directory.  In
214     particular, the directory aa is created as well as the final object bb.
215     In theory, this can be exploited to create an entire directory hierarchy
216     with a single request.  Of course, this does not work if the
217     ARCHIVE_EXTRACT_NODOTDOT option is specified.
218
219     Implicit directories are always created obeying the current umask.  Ex‐
220     plicit objects are created obeying the current umask unless
221     ARCHIVE_EXTRACT_PERM is specified, in which case they current umask is
222     ignored.
223
224     SGID and SUID bits are restored only if the correct user and group could
225     be set.  If ARCHIVE_EXTRACT_OWNER is not specified, then no attempt is
226     made to set the ownership.  In this case, SGID and SUID bits are restored
227     only if the user and group of the final object happen to match those
228     specified in the entry.
229
230     The “standard” user-id and group-id lookup functions are not the defaults
231     because getgrnam(3) and getpwnam(3) are sometimes too large for particu‐
232     lar applications.  The current design allows the application author to
233     use a more compact implementation when appropriate.
234
235     There should be a corresponding archive_read_disk interface that walks a
236     directory hierarchy and returns archive entry objects.
237
238BSD                            January 19, 2020                            BSD
Impressum