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
41     extracting objects from an archive using the archive_read() interface.
42     The general process is to read struct archive_entry objects from an ar‐
43     chive, then write those objects to a struct archive object created using
44     the archive_write_disk() family functions.  This interface is deliber‐
45     ately very similar to the archive_write() interface used to write objects
46     to a 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
56             being read.  This capability is technically unnecessary but can
57             be 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,
64                     extended 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
71                     default, 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
79                     default, existing regular files are truncated and over‐
80                     written; existing directories will have their permissions
81                     updated; other pre-existing objects are unlinked and
82                     recreated 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
86                     restored.
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_SECURE_NOABSOLUTEPATHS
99                     Refuse to extract an absolute path.  The default is to
100                     not refuse such paths.
101             ARCHIVE_EXTRACT_SECURE_NODOTDOT
102                     Refuse to extract a path that contains a .. element any‐
103                     where within it.  The default is to not refuse such
104                     paths.  Note that paths ending in .. always cause an
105                     error, regardless of this flag.
106             ARCHIVE_EXTRACT_SECURE_SYMLINKS
107                     Refuse to extract any object whose final location would
108                     be altered by a symlink on disk.  This is intended to
109                     help guard against a variety of mischief caused by ar‐
110                     chives that (deliberately or otherwise) extract files
111                     outside of the current directory.  The default is not to
112                     perform this check.  If
113             ARCHIVE_EXTRACT_SPARSE
114                     Scan data for blocks of NUL bytes and try to recreate
115                     them with holes.  This results in sparse files, indepen‐
116                     dent of whether the archive format supports or uses them.
117                     ARCHIVE_EXTRACT_UNLINK is specified together with this
118                     option, the library will remove any intermediate symlinks
119                     it finds and return an error only if such symlink could
120                     not be removed.
121             ARCHIVE_EXTRACT_TIME
122                     The timestamps (mtime, ctime, and atime) should be
123                     restored.  By default, they are ignored.  Note that
124                     restoring of atime is not currently supported.
125             ARCHIVE_EXTRACT_UNLINK
126                     Existing files on disk will be unlinked before any
127                     attempt to create them.  In some cases, this can prove to
128                     be a significant performance improvement.  By default,
129                     existing files are truncated and rewritten, but the file
130                     is not recreated.  In particular, the default behavior
131                     does not break existing hard links.
132             ARCHIVE_EXTRACT_XATTR
133                     Attempt to restore extended file attributes.  By default,
134                     they are ignored.  See xattr(7) (Linux), xattr(2) (Mac OS
135                     X), or getextattr(8) (FreeBSD) for more information on
136                     extended file attributes.
137
138     archive_write_disk_set_group_lookup(),
139             archive_write_disk_set_user_lookup()
140             The struct archive_entry objects contain both names and ids that
141             can be used to identify users and groups.  These names and ids
142             describe the ownership of the file itself and also appear in ACL
143             lists.  By default, the library uses the ids and ignores the
144             names, but this can be overridden by registering user and group
145             lookup functions.  To register, you must provide a lookup func‐
146             tion which accepts both a name and id and returns a suitable id.
147             You may also provide a void * pointer to a private data structure
148             and a cleanup function for that data.  The cleanup function will
149             be invoked when the struct archive object is destroyed.
150
151     archive_write_disk_set_standard_lookup()
152             This convenience function installs a standard set of user and
153             group lookup functions.  These functions use getpwnam(3) and
154             getgrnam(3) to convert names to ids, defaulting to the ids if the
155             names cannot be looked up.  These functions also implement a sim‐
156             ple memory cache to reduce the number of calls to getpwnam(3) and
157             getgrnam(3).
158     More information about the struct archive object and the overall design
159     of the library can be found in the libarchive(3) overview.  Many of these
160     functions are also documented under archive_write(3).
161

RETURN VALUES

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

ERRORS

177     Detailed error codes and textual descriptions are available from the
178     archive_errno() and archive_error_string() functions.
179

SEE ALSO

181     archive_read(3), archive_write(3), tar(1), libarchive(3)
182

HISTORY

184     The libarchive library first appeared in FreeBSD 5.3.  The
185     archive_write_disk interface was added to libarchive 2.0 and first
186     appeared in FreeBSD 6.3.
187

AUTHORS

189     The libarchive library was written by Tim Kientzle <kientzle@acm.org>.
190

BUGS

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