]> wimlib.net Git - wimlib/blob - include/wimlib.h
Replace WIMLIB_OPEN_FLAG_SPLIT_OK with WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT
[wimlib] / include / wimlib.h
1 /*
2  * wimlib.h
3  *
4  * External header for wimlib.
5  *
6  * This file contains extensive comments for generating documentation with
7  * Doxygen.  The built HTML documentation can be viewed at
8  * http://wimlib.sourceforge.net.
9  */
10
11 /*
12  * Copyright (C) 2012, 2013 Eric Biggers
13  *
14  * This file is part of wimlib, a library for working with WIM files.
15  *
16  * wimlib is free software; you can redistribute it and/or modify it under the
17  * terms of the GNU General Public License as published by the Free
18  * Software Foundation; either version 3 of the License, or (at your option)
19  * any later version.
20  *
21  * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
22  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
23  * A PARTICULAR PURPOSE. See the GNU General Public License for more
24  * details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with wimlib; if not, see http://www.gnu.org/licenses/.
28  */
29
30 /** \mainpage
31  *
32  * \section intro Introduction
33  *
34  * This is the documentation for the library interface of wimlib 1.5.0, a C
35  * library for creating, modifying, extracting, and mounting files in the
36  * Windows Imaging Format.  This documentation is intended for developers only.
37  * If you have installed wimlib and want to know how to use the @b wimlib-imagex
38  * program, please see the README file or manual pages.
39  *
40  * \section installing_and_compiling Installing and Compiling
41  *
42  * wimlib uses the GNU autotools, so, on UNIX-like systems, it should be easy to
43  * install with <code>configure && make && sudo make install</code>; however,
44  * please see the README for more information about installing it.
45  *
46  * To use wimlib in your program after installing it, include wimlib.h and link
47  * your program with @c -lwim.
48  *
49  * As of wimlib 1.5.0, wimlib.h is also compatible with C++.
50  *
51  * Note: before calling any other function declared in wimlib.h,
52  * wimlib_global_init() can (and in some cases, must) be called.  See its
53  * documentation for more details.
54  *
55  * \section basic_wim_handling_concepts Basic WIM handling concepts
56  *
57  * wimlib wraps up a WIM file in an opaque ::WIMStruct structure.   There are
58  * two ways to create such a structure: wimlib_open_wim(), which opens a WIM
59  * file and creates a ::WIMStruct representing it, and wimlib_create_new_wim(),
60  * which creates a new ::WIMStruct that initially contains no images and does
61  * not yet have a backing on-disk file.
62  *
63  * A WIM file, represented by a ::WIMStruct, contains zero or more images.
64  * Images can be extracted (or "applied") using wimlib_extract_image(), added
65  * (or "captured" or "appended") using wimlib_add_image(), deleted using
66  * wimlib_delete_image(), exported using wimlib_export_image(), and updated or
67  * modified using wimlib_update_image().  However, changes made to a WIM
68  * represented by a ::WIMStruct have no persistent effect until the WIM is
69  * actually written to an on-disk file.  This can be done using wimlib_write(),
70  * but if the WIM was originally opened using wimlib_open_wim(), then
71  * wimlib_overwrite() can be used instead.
72  *
73  * Note that with this ::WIMStruct abstraction, performing many tasks on WIM
74  * files is a multi-step process.  For example, to add, or "append" an image to
75  * an existing stand-alone WIM file in a way similar to <b>wimlib-imagex
76  * append</b>, you must call the following functions:
77  *
78  * 1. wimlib_open_wim()
79  * 2. wimlib_add_image()
80  * 3. wimlib_overwrite()
81  *
82  * This design is very much on purpose as it makes the library more useful in
83  * general by allowing functions to be composed in different ways.  For example,
84  * you can make multiple changes to a WIM and commit them all to the underlying
85  * file in only one overwrite operation, which is more efficient.
86  *
87  * \section cleaning_up Cleaning up
88  *
89  * After you are done with any ::WIMStruct, you can call wimlib_free() to free
90  * all resources associated with it.  Also, when you are completely done with
91  * using wimlib in your program, you can call wimlib_global_cleanup() to free
92  * any other resources allocated by the library.
93  *
94  * \section error_handling Error Handling
95  *
96  * Most functions in wimlib return 0 on success and a positive error code on
97  * failure.  Use wimlib_get_error_string() to get a string that describes an
98  * error code.  wimlib also can print error messages to standard error itself
99  * when an error happens, and these may be more informative than the error code;
100  * to enable this, call wimlib_set_print_errors().  Please note that this is for
101  * convenience only, and some errors can occur without a message being printed.
102  * Currently, error messages and strings (as well as all documentation, for that
103  * matter) are only available in English.
104  *
105  * \section encodings Locales and character encodings
106  *
107  * To support Windows as well as UNIX-like systems, wimlib's API typically takes
108  * and returns strings of ::wimlib_tchar, which are in a platform-dependent
109  * encoding.
110  *
111  * On Windows, each ::wimlib_tchar is 2 bytes and is the same as a "wchar_t",
112  * and the encoding is UTF-16LE.
113  *
114  * On UNIX-like systems, each ::wimlib_tchar is 1 byte and is simply a "char",
115  * and the encoding is the locale-dependent multibyte encoding.  I recommend you
116  * set your locale to a UTF-8 capable locale to avoid any issues.  Also, by
117  * default, wimlib on UNIX will assume the locale is UTF-8 capable unless you
118  * call wimlib_global_init() after having set your desired locale.
119  *
120  * \section advanced Additional information and features
121  *
122  * \subsection image_addition Image addition/capture
123  *
124  * As described in \ref basic_wim_handling_concepts, capturing a new WIM or
125  * appending an image to an existing WIM is a multi-step process, but at its
126  * core is wimlib_add_image() or an equivalent function.  Normally,
127  * wimlib_add_image() takes an on-disk directory tree and logically adds it to a
128  * ::WIMStruct as a new image.  However, when supported by the build of the
129  * library, there is also a special NTFS volume capture mode (entered when
130  * ::WIMLIB_ADD_FLAG_NTFS is specified) that allows adding the image directly
131  * from an unmounted NTFS volume.
132  *
133  * Another function, wimlib_add_image_multisource() is also provided.  It
134  * generalizes wimlib_add_image() to allow combining multiple files or directory
135  * trees into a single WIM image in a configurable way.
136  *
137  * For maximum customization of WIM image creation, it is also possible to add a
138  * completely empty WIM image with wimlib_add_empty_image(), then update it with
139  * wimlib_update_image().  (This is in fact what wimlib_add_image() and
140  * wimlib_add_image_multisource() do internally.)
141  *
142  * Note that some details of how image addition/capture works are documented
143  * more fully in the manual page for <b>wimlib-imagex capture</b>.
144  *
145  * \subsection extraction Image extraction/application
146  *
147  * wimlib_extract_image() extracts, or "applies", an image from a WIM
148  * (represented, as usual, by a ::WIMStruct).  This normally extracts the image
149  * to a directory, but when supported by the build of the library there is also
150  * a special NTFS volume extraction mode (entered when
151  * ::WIMLIB_EXTRACT_FLAG_NTFS is specified) that allows extracting a WIM image
152  * directly to an unmounted NTFS volume.  Various other flags allow further
153  * customization of image extraction.
154  *
155  * Another function, wimlib_extract_files(), is also provided.  It can extract
156  * certain files or directories from a WIM image, instead of a full image.
157  *
158  * A third function, wimlib_extract_image_from_pipe(), allows an image to be
159  * extracted from a pipable WIM sent over a pipe; see \ref pipable_wims.
160  *
161  * Note that some details of how image extraction/application works are
162  * documented more fully in the manual pages for <b>wimlib-imagex apply</b> and
163  * <b>wimlib-imagex extract</b>.
164  *
165  * \subsection non_standalone_wims Non-standalone WIMs
166  *
167  * Earlier it was stated that a ::WIMStruct represents a WIM file, but there's a
168  * bit more to it than that.  Normally, WIM files are "standalone".  However,
169  * WIM files can also be arranged in non-standalone ways, such as a set of
170  * on-disk files that together form a single "split WIM" or "delta WIM".  Such
171  * arrangements are fully supported by wimlib.  However, as a result, in such
172  * cases a ::WIMStruct created from one of these on-disk files initially only
173  * partially represents the full WIM and needs to, in effect, be logically
174  * combined with other ::WIMStruct's before performing certain operations, such
175  * as extracting files with wimlib_extract_image() or wimlib_extract_files().
176  * This is done by calling wimlib_reference_resource_files() or
177  * wimlib_reference_resources().
178  *
179  * wimlib_write() can create delta WIMs as well as standalone WIMs, but a
180  * specialized function (wimlib_split()) is needed to create a split WIM.
181  *
182  * \subsection mounting_wim_images Mounting WIM images
183  *
184  * On UNIX-like systems supporting FUSE (such as Linux), wimlib supports
185  * mounting images from WIM files either read-only or read-write.  To mount an
186  * image, call wimlib_mount_image().  To unmount an image, call
187  * wimlib_unmount_image().  Mounting can be done without root privileges because
188  * it is implemented using FUSE (Filesystem in Userspace).  If wimlib is
189  * compiled with the <code>--without-fuse</code> flag, these functions will be
190  * available but will fail with ::WIMLIB_ERR_UNSUPPORTED.  Note that mounting an
191  * image read-write is an alternative to calling wimlib_update_image().
192  *
193  * \subsection progress_functions Progress Functions
194  *
195  * When operating on large archives, operations such as extraction will
196  * naturally take a while to complete.  Because of this and to improve the
197  * potential user-friendliness of library clients, a number of functions take a
198  * pointer to a progress function of type ::wimlib_progress_func_t.  This
199  * function will be called periodically during the WIM operation(s) to report on
200  * the progress of the operation (for example, how many bytes have been written
201  * so far).
202  *
203  * \subsection pipable_wims Pipable WIMs
204  *
205  * wimlib supports a special "pipable" WIM format which unfortunately is @b not
206  * compatible with Microsoft's software.  To create a pipable WIM, call
207  * wimlib_write(), wimlib_write_to_fd(), or wimlib_overwrite() with
208  * ::WIMLIB_WRITE_FLAG_PIPABLE specified.  Pipable WIMs are pipable in both
209  * directions, so wimlib_write_to_fd() can be used to write a pipable WIM to a
210  * pipe, and wimlib_extract_image_from_pipe() can be used to apply an image from
211  * a pipable WIM.  wimlib can also transparently open and operate on pipable WIM
212  * s using a seekable file descriptor using the regular function calls (e.g.
213  * wimlib_open_wim(), wimlib_extract_image()).
214  *
215  * See the documentation for the <b>--pipable</b> flag of <b>wimlib-imagex
216  * capture</b> for more information about pipable WIMs.
217  *
218  * \subsection thread_safety Thread Safety
219  *
220  * wimlib is thread-safe, with the following exceptions:
221  * - Different threads cannot operate on the same ::WIMStruct at the same time;
222  *   they must use different ::WIMStruct's.
223  * - You must call wimlib_global_init() in one thread before calling any other
224  *   functions.
225  * - wimlib_set_print_errors() and wimlib_set_memory_allocator() both apply globally.
226  * - wimlib_mount_image(), while it can be used to mount multiple WIMs
227  *   concurrently in the same process, will daemonize the entire process when it
228  *   does so for the first time.  This includes changing the working directory
229  *   to the root directory.
230  *
231  * \subsection limitations Limitations
232  *
233  * This section documents some technical limitations of wimlib not already
234  * documented in the man page for @b wimlib-imagex.
235  *
236  * - The old WIM format from Vista pre-releases is not supported.
237  * - Compressed resource chunk sizes other than 32768 are not supported.  This
238  *   doesn't seem to be a real problem because the chunk size always seems to be
239  *   this value.
240  * - wimlib does not provide a clone of the @b PEImg tool, or the @b Dism
241  *   functionality other than that already present in @b ImageX, that allows you
242  *   to make certain Windows-specific modifications to a Windows PE image, such
243  *   as adding a driver or Windows component.  Such a tool could be implemented
244  *   on top of wimlib.
245  *
246  * \subsection more_info More information
247  *
248  * You are advised to read the README as well as the manual pages for
249  * <b>wimlib-imagex</b>, since not all relevant information is repeated here in
250  * the API documentation.
251  */
252
253 #ifndef _WIMLIB_H
254 #define _WIMLIB_H
255
256 #include <stdio.h>
257 #include <stddef.h>
258 #include <stdbool.h>
259 #include <inttypes.h>
260 #include <time.h>
261
262 /** Major version of the library (for example, the 1 in 1.2.5). */
263 #define WIMLIB_MAJOR_VERSION 1
264
265 /** Minor version of the library (for example, the 2 in 1.2.5). */
266 #define WIMLIB_MINOR_VERSION 5
267
268 /** Patch version of the library (for example, the 5 in 1.2.5). */
269 #define WIMLIB_PATCH_VERSION 0
270
271 #ifdef __cplusplus
272 extern "C" {
273 #endif
274
275 /**
276  * Opaque structure that represents a WIM file.  This is an in-memory structure
277  * and need not correspond to a specific on-disk file.  However, a ::WIMStruct
278  * obtained from wimlib_open_wim() depends on the underlying on-disk WIM file
279  * continuing to exist so that data can be read from it as needed.
280  *
281  * Most functions in this library will work the same way regardless of whether a
282  * given ::WIMStruct was obtained through wimlib_open_wim() or
283  * wimlib_create_new_wim().  Exceptions are documented.
284  *
285  * Use wimlib_write() or wimlib_overwrite() to actually write an on-disk WIM
286  * file from a ::WIMStruct.
287  */
288 #ifndef WIMLIB_WIMSTRUCT_DECLARED
289 typedef struct WIMStruct WIMStruct;
290 #define WIMLIB_WIMSTRUCT_DECLARED
291 #endif
292
293 #ifdef __WIN32__
294 typedef wchar_t wimlib_tchar;
295 #else
296 /** See \ref encodings */
297 typedef char wimlib_tchar;
298 #endif
299
300 #ifdef __WIN32__
301 /** Path separator for WIM paths passed back to progress callbacks. */
302 #  define WIMLIB_WIM_PATH_SEPARATOR '\\'
303 #  define WIMLIB_WIM_PATH_SEPARATOR_STRING L"\\"
304 #else
305 /** Path separator for WIM paths passed back to progress callbacks. */
306 #  define WIMLIB_WIM_PATH_SEPARATOR '/'
307 #  define WIMLIB_WIM_PATH_SEPARATOR_STRING "/"
308 #endif
309
310 #ifdef __GNUC__
311 #  define _wimlib_deprecated __attribute__((deprecated))
312 #else
313 #  define _wimlib_deprecated
314 #endif
315
316 #define WIMLIB_GUID_LEN 16
317
318 /**
319  * Specifies the compression type of a WIM file.
320  */
321 enum wimlib_compression_type {
322         /** An invalid compression type. */
323         WIMLIB_COMPRESSION_TYPE_INVALID = -1,
324
325         /** The WIM does not include any compressed resources. */
326         WIMLIB_COMPRESSION_TYPE_NONE = 0,
327
328         /** Compressed resources in the WIM use LZX compression. */
329         WIMLIB_COMPRESSION_TYPE_LZX = 1,
330
331         /** Compressed resources in the WIM use XPRESS compression. */
332         WIMLIB_COMPRESSION_TYPE_XPRESS = 2,
333 };
334
335 /** Possible values of the first parameter to the user-supplied
336  * ::wimlib_progress_func_t progress function */
337 enum wimlib_progress_msg {
338
339         /** A WIM image is about to be extracted.  @p info will point to
340          * ::wimlib_progress_info.extract. */
341         WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN = 0,
342
343         /** A file or directory tree within a WIM image (not the full image) is
344          * about to be extracted.  @p info will point to
345          * ::wimlib_progress_info.extract. */
346         WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN,
347
348         /** The directory structure of the WIM image is about to be extracted.
349          * @p info will point to ::wimlib_progress_info.extract. */
350         WIMLIB_PROGRESS_MSG_EXTRACT_DIR_STRUCTURE_BEGIN,
351
352         /** The directory structure of the WIM image has been successfully
353          * extracted.  @p info will point to ::wimlib_progress_info.extract. */
354         WIMLIB_PROGRESS_MSG_EXTRACT_DIR_STRUCTURE_END,
355
356         /** The WIM image's files resources are currently being extracted.  @p
357          * info will point to ::wimlib_progress_info.extract. */
358         WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS,
359
360         /** Starting to read a new part of a split pipable WIM over the pipe.
361          * @p info will point to ::wimlib_progress_info.extract.  */
362         WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN,
363
364         /** All the WIM files and directories have been extracted, and
365          * timestamps are about to be applied.  @p info will point to
366          * ::wimlib_progress_info.extract. */
367         WIMLIB_PROGRESS_MSG_APPLY_TIMESTAMPS,
368
369         /** A WIM image has been successfully extracted.  @p info will point to
370          * ::wimlib_progress_info.extract. */
371         WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END,
372
373         /** A file or directory tree within a WIM image (not the full image) has
374          * been successfully extracted.  @p info will point to
375          * ::wimlib_progress_info.extract. */
376         WIMLIB_PROGRESS_MSG_EXTRACT_TREE_END,
377
378         /** The directory or NTFS volume is about to be scanned to build a tree
379          * of WIM dentries in-memory.  @p info will point to
380          * ::wimlib_progress_info.scan. */
381         WIMLIB_PROGRESS_MSG_SCAN_BEGIN,
382
383         /** A directory or file is being scanned.  @p info will point to
384          * ::wimlib_progress_info.scan, and its @p cur_path member will be
385          * valid.  This message is only sent if ::WIMLIB_ADD_FLAG_VERBOSE
386          * is passed to wimlib_add_image(). */
387         WIMLIB_PROGRESS_MSG_SCAN_DENTRY,
388
389         /** The directory or NTFS volume has been successfully scanned, and a
390          * tree of WIM dentries has been built in-memory. @p info will point to
391          * ::wimlib_progress_info.scan. */
392         WIMLIB_PROGRESS_MSG_SCAN_END,
393
394         /**
395          * File resources are currently being written to the WIM.
396          * @p info will point to ::wimlib_progress_info.write_streams. */
397         WIMLIB_PROGRESS_MSG_WRITE_STREAMS,
398
399         /**
400          * The metadata resource for each image is about to be written to the
401          * WIM. @p info will not be valid. */
402         WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN,
403
404         /**
405          * The metadata resource for each image has successfully been writen to
406          * the WIM.  @p info will not be valid. */
407         WIMLIB_PROGRESS_MSG_WRITE_METADATA_END,
408
409         /**
410          * The temporary file has successfully been renamed to the original WIM
411          * file.  Only happens when wimlib_overwrite() is called and the
412          * overwrite is not done in-place.
413          * @p info will point to ::wimlib_progress_info.rename. */
414         WIMLIB_PROGRESS_MSG_RENAME,
415
416         /** The contents of the WIM are being checked against the integrity
417          * table.  Only happens when wimlib_open_wim() is called with the
418          * ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY flag.  @p info will point to
419          * ::wimlib_progress_info.integrity. */
420         WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY,
421
422         /** An integrity table is being calculated for the WIM being written.
423          * Only happens when wimlib_write() or wimlib_overwrite() is called with
424          * the ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY flag.  @p info will point to
425          * ::wimlib_progress_info.integrity. */
426         WIMLIB_PROGRESS_MSG_CALC_INTEGRITY,
427
428         /** Reserved.  (Previously used for WIMLIB_PROGRESS_MSG_JOIN_STREAMS,
429          * but in wimlib v1.5.0 this was removed to simplify the code and now
430          * you'll get ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS messages instead.)  */
431         WIMLIB_PROGRESS_MSG_RESERVED,
432
433         /** A wimlib_split() operation is in progress, and a new split part is
434          * about to be started.  @p info will point to
435          * ::wimlib_progress_info.split. */
436         WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART,
437
438         /** A wimlib_split() operation is in progress, and a split part has been
439          * finished. @p info will point to ::wimlib_progress_info.split. */
440         WIMLIB_PROGRESS_MSG_SPLIT_END_PART,
441
442         /**
443          * A WIM update command is just about to be executed; @p info will point
444          * to ::wimlib_progress_info.update.
445          */
446         WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND,
447
448         /**
449          * A WIM update command has just been executed; @p info will point to
450          * ::wimlib_progress_info.update.
451          */
452         WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND,
453
454 };
455
456 /** A pointer to this union is passed to the user-supplied
457  * ::wimlib_progress_func_t progress function.  One (or none) of the structures
458  * contained in this union will be applicable for the operation
459  * (::wimlib_progress_msg) indicated in the first argument to the progress
460  * function. */
461 union wimlib_progress_info {
462
463         /* N.B. I wanted these to be anonymous structs, but Doxygen won't
464          * document them if they aren't given a name... */
465
466         /** Valid on messages ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS. */
467         struct wimlib_progress_info_write_streams {
468                 /** Number of bytes that are going to be written for all the
469                  * streams combined.  This is the amount in uncompressed data.
470                  * (The actual number of bytes will be less if the data is being
471                  * written compressed.) */
472                 uint64_t total_bytes;
473
474                 /** Number of streams that are going to be written. */
475                 uint64_t total_streams;
476
477                 /** Number of uncompressed bytes that have been written so far.
478                  * Will be 0 initially, and equal to @p total_bytes at the end.
479                  * */
480                 uint64_t completed_bytes;
481
482                 /** Number of streams that have been written.  Will be 0
483                  * initially, and equal to @p total_streams at the end. */
484                 uint64_t completed_streams;
485
486                 /** Number of threads that are being used to compress resources
487                  * (if applicable).  */
488                 unsigned num_threads;
489
490                 /** The compression type being used to write the streams; either
491                  * ::WIMLIB_COMPRESSION_TYPE_NONE,
492                  * ::WIMLIB_COMPRESSION_TYPE_XPRESS, or
493                  * ::WIMLIB_COMPRESSION_TYPE_LZX. */
494                 int      compression_type;
495
496                 /** Number of split WIM parts from which streams are being
497                  * written (may be 0 if irrelevant).  */
498                 unsigned total_parts;
499
500                 /** Number of split WIM parts from which streams have been
501                  * written (may be 0 if irrelevant).  */
502                 unsigned completed_parts;
503         } write_streams;
504
505         /** Valid on messages ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN and
506          * ::WIMLIB_PROGRESS_MSG_SCAN_END. */
507         struct wimlib_progress_info_scan {
508                 /** Directory or NTFS volume that is being scanned. */
509                 const wimlib_tchar *source;
510
511                 /** Path to the file or directory that is about to be scanned,
512                  * relative to the root of the image capture or the NTFS volume.
513                  * */
514                 const wimlib_tchar *cur_path;
515
516                 enum {
517                         /** File or directory looks okay and will be captured.  */
518                         WIMLIB_SCAN_DENTRY_OK = 0,
519
520                         /** File or directory is being excluded from capture due
521                          * to the capture configuration file.  */
522                         WIMLIB_SCAN_DENTRY_EXCLUDED,
523
524                         /** File or directory is being excluded from capture due
525                          * to being unsupported (e.g. an encrypted or device
526                          * file).  */
527                         WIMLIB_SCAN_DENTRY_UNSUPPORTED,
528                 } status;
529
530                 /** Target path in the WIM.  Only valid on messages
531                  * ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN and
532                  * ::WIMLIB_PROGRESS_MSG_SCAN_END. */
533                 const wimlib_tchar *wim_target_path;
534         } scan;
535
536         /** Valid on messages ::WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN,
537          * ::WIMLIB_PROGRESS_MSG_EXTRACT_DIR_STRUCTURE_BEGIN,
538          * ::WIMLIB_PROGRESS_MSG_EXTRACT_DIR_STRUCTURE_END,
539          * ::WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS, and
540          * ::WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END. */
541         struct wimlib_progress_info_extract {
542                 /** Number of the image being extracted (1-based). */
543                 int image;
544
545                 /** Flags passed to to wimlib_extract_image() */
546                 int extract_flags;
547
548                 /** Full path to the WIM file being extracted. */
549                 const wimlib_tchar *wimfile_name;
550
551                 /** Name of the image being extracted. */
552                 const wimlib_tchar *image_name;
553
554                 /** Directory or NTFS volume to which the image is being
555                  * extracted. */
556                 const wimlib_tchar *target;
557
558                 /** Reserved.  */
559                 const wimlib_tchar *cur_path;
560
561                 /** Number of bytes of uncompressed data that will be extracted.
562                  * Takes into account hard links (they are not counted for each
563                  * link.)  */
564                 uint64_t total_bytes;
565
566                 /** Number of bytes that have been written so far.  Will be 0
567                  * initially, and equal to @p total_bytes at the end. */
568                 uint64_t completed_bytes;
569
570                 /** Number of streams that will be extracted.  This may more or
571                  * less than the number of "files" to be extracted due to
572                  * special cases (hard links, symbolic links, and alternate data
573                  * streams.) */
574                 uint64_t num_streams;
575
576                 /** Path to the root dentry within the WIM for the tree that is
577                  * being extracted.  Will be the empty string when extracting a
578                  * full image. */
579                 const wimlib_tchar *extract_root_wim_source_path;
580
581                 /** Currently only used for
582                  * ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN.  */
583
584                 unsigned part_number;
585
586                 /** Currently only used for
587                  * ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN.  */
588                 unsigned total_parts;
589
590                 /** Currently only used for
591                  * ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN.  */
592                 uint8_t guid[WIMLIB_GUID_LEN];
593         } extract;
594
595         /** Valid on messages ::WIMLIB_PROGRESS_MSG_RENAME. */
596         struct wimlib_progress_info_rename {
597                 /** Name of the temporary file that the WIM was written to. */
598                 const wimlib_tchar *from;
599
600                 /** Name of the original WIM file to which the temporary file is
601                  * being renamed. */
602                 const wimlib_tchar *to;
603         } rename;
604
605         /** Valid on messages ::WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND and
606          * ::WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND. */
607         struct wimlib_progress_info_update {
608                 /** Pointer to the update command that will be executed or has
609                  * just been executed. */
610                 const struct wimlib_update_command *command;
611
612                 /** Number of update commands that have been completed so far.
613                  */
614                 size_t completed_commands;
615
616                 /** Number of update commands that are being executed as part of
617                  * this call to wimlib_update_image(). */
618                 size_t total_commands;
619         } update;
620
621         /** Valid on messages ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY and
622          * ::WIMLIB_PROGRESS_MSG_CALC_INTEGRITY. */
623         struct wimlib_progress_info_integrity {
624                 /** Number of bytes from the end of the WIM header to the end of
625                  * the lookup table (the area that is covered by the SHA1
626                  * integrity checks.) */
627                 uint64_t total_bytes;
628
629                 /** Number of bytes that have been SHA1-summed so far.  Will be
630                  * 0 initially, and equal @p total_bytes at the end. */
631                 uint64_t completed_bytes;
632
633                 /** Number of chunks that the checksummed region is divided
634                  * into. */
635                 uint32_t total_chunks;
636
637                 /** Number of chunks that have been SHA1-summed so far.   Will
638                  * be 0 initially, and equal to @p total_chunks at the end. */
639                 uint32_t completed_chunks;
640
641                 /** Size of the chunks used for the integrity calculation. */
642                 uint32_t chunk_size;
643
644                 /** Filename of the WIM (only valid if the message is
645                  * ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY). */
646                 const wimlib_tchar *filename;
647         } integrity;
648
649         /** Valid on messages ::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART and
650          * ::WIMLIB_PROGRESS_MSG_SPLIT_END_PART. */
651         struct wimlib_progress_info_split {
652                 /** Total size of the original WIM's file and metadata resources
653                  * (compressed). */
654                 uint64_t total_bytes;
655
656                 /** Number of bytes of file and metadata resources that have
657                  * been copied out of the original WIM so far.  Will be 0
658                  * initially, and equal to @p total_bytes at the end. */
659                 uint64_t completed_bytes;
660
661                 /** Number of the split WIM part that is about to be started
662                  * (::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART) or has just been
663                  * finished (::WIMLIB_PROGRESS_MSG_SPLIT_END_PART). */
664                 unsigned cur_part_number;
665
666                 /** Total number of split WIM parts that are being written.  */
667                 unsigned total_parts;
668
669                 /** Name of the split WIM part that is about to be started
670                  * (::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART) or has just been
671                  * finished (::WIMLIB_PROGRESS_MSG_SPLIT_END_PART). */
672                 const wimlib_tchar *part_name;
673         } split;
674 };
675
676 /** A user-supplied function that will be called periodically during certain WIM
677  * operations.  The first argument will be the type of operation that is being
678  * performed or is about to be started or has been completed.  The second
679  * argument will be a pointer to one of a number of structures depending on the
680  * first argument.  It may be @c NULL for some message types.
681  *
682  * The return value of the progress function is currently ignored, but it may do
683  * something in the future.  (Set it to 0 for now.)
684  */
685 typedef int (*wimlib_progress_func_t)(enum wimlib_progress_msg msg_type,
686                                       const union wimlib_progress_info *info);
687
688 /** An array of these structures is passed to wimlib_add_image_multisource() to
689  * specify the sources from which to create a WIM image. */
690 struct wimlib_capture_source {
691         /** Absolute or relative path to a file or directory on the external
692          * filesystem to be included in the WIM image. */
693         wimlib_tchar *fs_source_path;
694
695         /** Destination path in the WIM image.  Leading and trailing slashes are
696          * ignored.  The empty string or @c NULL means the root directory of the
697          * WIM image. */
698         wimlib_tchar *wim_target_path;
699
700         /** Reserved; set to 0. */
701         long reserved;
702 };
703
704 /** Structure that specifies a list of path patterns. */
705 struct wimlib_pattern_list {
706         /** Array of patterns.  The patterns may be modified by library code,
707          * but the @p pats pointer itself will not.  See the man page for
708          * <b>wimlib-imagex capture</b> for more information about allowed
709          * patterns. */
710         wimlib_tchar **pats;
711
712         /** Number of patterns in the @p pats array. */
713         size_t num_pats;
714
715         /** Ignored; may be used by the calling code. */
716         size_t num_allocated_pats;
717 };
718
719 /** A structure that contains lists of wildcards that match paths to treat
720  * specially when capturing a WIM image. */
721 struct wimlib_capture_config {
722         /** Paths matching any pattern this list are excluded from being
723          * captured, except if the same path appears in @p
724          * exclusion_exception_pats. */
725         struct wimlib_pattern_list exclusion_pats;
726
727         /** Paths matching any pattern in this list are never excluded from
728          * being captured. */
729         struct wimlib_pattern_list exclusion_exception_pats;
730
731         /** Reserved for future capture configuration options. */
732         struct wimlib_pattern_list reserved1;
733
734         /** Reserved for future capture configuration options. */
735         struct wimlib_pattern_list reserved2;
736
737         /** Library internal use only. */
738         wimlib_tchar *_prefix;
739
740         /** Library internal use only. */
741         size_t _prefix_num_tchars;
742 };
743
744 /** Set or unset the WIM header flag that marks it read-only
745  * (WIM_HDR_FLAG_READONLY in Microsoft's documentation), based on the
746  * ::wimlib_wim_info.is_marked_readonly member of the @p info parameter.  This
747  * is distinct from basic file permissions; this flag can be set on a WIM file
748  * that is physically writable.  If this flag is set, all further operations to
749  * modify the WIM will fail, except calling wimlib_overwrite() with
750  * ::WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG specified, which is a loophole that
751  * allows you to set this flag persistently on the underlying WIM file.
752  */
753 #define WIMLIB_CHANGE_READONLY_FLAG             0x00000001
754
755 /** Set the GUID (globally unique identifier) of the WIM file to the value
756  * specified in ::wimlib_wim_info.guid of the @p info parameter. */
757 #define WIMLIB_CHANGE_GUID                      0x00000002
758
759 /** Change the bootable image of the WIM to the value specified in
760  * ::wimlib_wim_info.boot_index of the @p info parameter.  */
761 #define WIMLIB_CHANGE_BOOT_INDEX                0x00000004
762
763 /** Change the WIM_HDR_FLAG_RP_FIX flag of the WIM file to the value specified
764  * in ::wimlib_wim_info.has_rpfix of the @p info parameter.  This flag generally
765  * indicates whether an image in the WIM has been captured with reparse-point
766  * fixups enabled.  wimlib also treats this flag as specifying whether to do
767  * reparse-point fixups by default when capturing or applying WIM images.  */
768 #define WIMLIB_CHANGE_RPFIX_FLAG                0x00000008
769
770 /** General information about a WIM file. */
771 struct wimlib_wim_info {
772
773         /** Globally unique identifier for the WIM file.  Note: all parts of a
774          * split WIM should have an identical value in this field.  */
775         uint8_t  guid[WIMLIB_GUID_LEN];
776
777         /** Number of images in the WIM.  */
778         uint32_t image_count;
779
780         /** 1-based index of the bootable image in the WIM, or 0 if no image is
781          * bootable.  */
782         uint32_t boot_index;
783
784         /** Version of the WIM file.  */
785         uint32_t wim_version;
786
787         /** Chunk size used for compression.  */
788         uint32_t chunk_size;
789
790         /** For split WIMs, the 1-based index of this part within the split WIM;
791          * otherwise 1.  */
792         uint16_t part_number;
793
794         /** For split WIMs, the total number of parts in the split WIM;
795          * otherwise 1.  */
796         uint16_t total_parts;
797
798         /** One of the ::wimlib_compression_type values that specifies the
799          * method used to compress resources in the WIM.  */
800         int32_t  compression_type;
801
802         /** Size of the WIM file in bytes, excluding the XML data and integrity
803          * table.  */
804         uint64_t total_bytes;
805
806         /** 1 if the WIM has an integrity table.  Note: if the ::WIMStruct was
807          * created via wimlib_create_new_wim() rather than wimlib_open_wim(),
808          * this will always be 0, even if the ::WIMStruct was written to
809          * somewhere by calling wimlib_write() with the
810          * ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY flag specified. */
811         uint32_t has_integrity_table : 1;
812
813         /** 1 if the ::WIMStruct was created via wimlib_open_wim() rather than
814          * wimlib_create_new_wim(). */
815         uint32_t opened_from_file : 1;
816
817         /** 1 if the WIM is considered readonly for any reason. */
818         uint32_t is_readonly : 1;
819
820         /** 1 if reparse-point fixups are supposedly enabled for one or more
821          * images in the WIM.  */
822         uint32_t has_rpfix : 1;
823
824         /** 1 if the WIM is marked as read-only.  */
825         uint32_t is_marked_readonly : 1;
826
827         /** 1 if the WIM is part of a spanned set.  */
828         uint32_t spanned : 1;
829
830         uint32_t write_in_progress : 1;
831         uint32_t metadata_only : 1;
832         uint32_t resource_only : 1;
833
834         /** 1 if the WIM is pipable (see ::WIMLIB_WRITE_FLAG_PIPABLE).  */
835         uint32_t pipable : 1;
836         uint32_t reserved_flags : 22;
837         uint32_t reserved[9];
838 };
839
840 /** Information about a unique resource in the WIM file.
841  */
842 struct wimlib_resource_entry {
843         /** Uncompressed size of the resource in bytes. */
844         uint64_t uncompressed_size;
845
846         /** Compressed size of the resource in bytes.  This will be the same as
847          * @p uncompressed_size if the resource is uncompressed.  */
848         uint64_t compressed_size;
849
850         /** Offset, in bytes, of this resource from the start of the WIM file.
851          */
852         uint64_t offset;
853
854         /** SHA1 message digest of the resource's uncompressed contents.  */
855         uint8_t sha1_hash[20];
856
857         /** Which part number of the split WIM this resource is in.  This should
858          * be the same as the part number provided by wimlib_get_wim_info().  */
859         uint32_t part_number;
860
861         /** Number of times this resource is referenced over all WIM images.  */
862         uint32_t reference_count;
863
864         /** 1 if this resource is compressed.  */
865         uint32_t is_compressed : 1;
866
867         /** 1 if this resource is a metadata resource rather than a file
868          * resource.  */
869         uint32_t is_metadata : 1;
870
871         uint32_t is_free : 1;
872         uint32_t is_spanned : 1;
873         uint32_t reserved_flags : 28;
874         uint64_t reserved[4];
875 };
876
877 /** A stream of a file in the WIM.  */
878 struct wimlib_stream_entry {
879         /** Name of the stream, or NULL if the stream is unnamed. */
880         const wimlib_tchar *stream_name;
881         /** Location, size, etc. of the stream within the WIM file.  */
882         struct wimlib_resource_entry resource;
883         uint64_t reserved[4];
884 };
885
886 /** Structure passed to the wimlib_iterate_dir_tree() callback function.
887  * Roughly, the information about a "file" in the WIM--- but really a directory
888  * entry ("dentry") because hard links are allowed.  The hard_link_group_id
889  * field can be used to distinguish actual file inodes.  */
890 struct wimlib_dir_entry {
891         /** Name of the file, or NULL if this file is unnamed (only possible for
892          * the root directory) */
893         const wimlib_tchar *filename;
894
895         /** 8.3 DOS name of this file, or NULL if this file has no such name.
896          * */
897         const wimlib_tchar *dos_name;
898
899         /** Full path to this file within the WIM image.  */
900         const wimlib_tchar *full_path;
901
902         /** Depth of this directory entry, where 0 is the root, 1 is the root's
903          * children, ..., etc. */
904         size_t depth;
905
906         /** Pointer to the security descriptor for this file, in Windows
907          * SECURITY_DESCRIPTOR_RELATIVE format, or NULL if this file has no
908          * security descriptor.  */
909         const char *security_descriptor;
910
911         /** Length of the above security descriptor.  */
912         size_t security_descriptor_size;
913
914 #define WIMLIB_FILE_ATTRIBUTE_READONLY            0x00000001
915 #define WIMLIB_FILE_ATTRIBUTE_HIDDEN              0x00000002
916 #define WIMLIB_FILE_ATTRIBUTE_SYSTEM              0x00000004
917 #define WIMLIB_FILE_ATTRIBUTE_DIRECTORY           0x00000010
918 #define WIMLIB_FILE_ATTRIBUTE_ARCHIVE             0x00000020
919 #define WIMLIB_FILE_ATTRIBUTE_DEVICE              0x00000040
920 #define WIMLIB_FILE_ATTRIBUTE_NORMAL              0x00000080
921 #define WIMLIB_FILE_ATTRIBUTE_TEMPORARY           0x00000100
922 #define WIMLIB_FILE_ATTRIBUTE_SPARSE_FILE         0x00000200
923 #define WIMLIB_FILE_ATTRIBUTE_REPARSE_POINT       0x00000400
924 #define WIMLIB_FILE_ATTRIBUTE_COMPRESSED          0x00000800
925 #define WIMLIB_FILE_ATTRIBUTE_OFFLINE             0x00001000
926 #define WIMLIB_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
927 #define WIMLIB_FILE_ATTRIBUTE_ENCRYPTED           0x00004000
928 #define WIMLIB_FILE_ATTRIBUTE_VIRTUAL             0x00010000
929         /** File attributes, such as whether the file is a directory or not.
930          * These are the "standard" Windows FILE_ATTRIBUTE_* values, although in
931          * wimlib.h they are defined as WIMLIB_FILE_ATTRIBUTE_* for convenience
932          * on other platforms.  */
933         uint32_t attributes;
934
935 #define WIMLIB_REPARSE_TAG_RESERVED_ZERO        0x00000000
936 #define WIMLIB_REPARSE_TAG_RESERVED_ONE         0x00000001
937 #define WIMLIB_REPARSE_TAG_MOUNT_POINT          0xA0000003
938 #define WIMLIB_REPARSE_TAG_HSM                  0xC0000004
939 #define WIMLIB_REPARSE_TAG_HSM2                 0x80000006
940 #define WIMLIB_REPARSE_TAG_DRIVER_EXTENDER      0x80000005
941 #define WIMLIB_REPARSE_TAG_SIS                  0x80000007
942 #define WIMLIB_REPARSE_TAG_DFS                  0x8000000A
943 #define WIMLIB_REPARSE_TAG_DFSR                 0x80000012
944 #define WIMLIB_REPARSE_TAG_FILTER_MANAGER       0x8000000B
945 #define WIMLIB_REPARSE_TAG_SYMLINK              0xA000000C
946         /** If the file is a reparse point (FILE_ATTRIBUTE_DIRECTORY set in the
947          * attributes), this will give the reparse tag.  This tells you whether
948          * the reparse point is a symbolic link, junction point, or some other,
949          * more unusual kind of reparse point.  */
950         uint32_t reparse_tag;
951
952         /*  Number of (hard) links to this file.  */
953         uint32_t num_links;
954
955         /** Number of named data streams that this file has.  Normally 0.  */
956         uint32_t num_named_streams;
957
958         /** Roughly, the inode number of this file.  However, it may be 0 if
959          * @p num_links == 1.  */
960         uint64_t hard_link_group_id;
961
962         /** Time this file was created.  */
963         struct timespec creation_time;
964
965         /** Time this file was last written to.  */
966         struct timespec last_write_time;
967
968         /** Time this file was last accessed.  */
969         struct timespec last_access_time;
970         uint64_t reserved[16];
971
972         /** Array of streams that make up this file.  The first entry will
973          * always exist and will correspond to the unnamed data stream (default
974          * file contents), so it will have @p stream_name == @c NULL.  There
975          * will then be @p num_named_streams additional entries that specify the
976          * named data streams, if any, each of which will have @p stream_name !=
977          * @c NULL.  */
978         struct wimlib_stream_entry streams[];
979 };
980
981 /**
982  * Type of a callback function to wimlib_iterate_dir_tree().  Must return 0 on
983  * success.
984  */
985 typedef int (*wimlib_iterate_dir_tree_callback_t)(const struct wimlib_dir_entry *dentry,
986                                                   void *user_ctx);
987
988 /**
989  * Type of a callback function to wimlib_iterate_lookup_table().  Must return 0
990  * on success.
991  */
992 typedef int (*wimlib_iterate_lookup_table_callback_t)(const struct wimlib_resource_entry *resource,
993                                                       void *user_ctx);
994
995 /**
996  * @name Directory tree iteration flags
997  *
998  * The following flags can be passed to wimlib_iterate_dir_tree().
999  *
1000  * @{
1001  */
1002
1003 /** For wimlib_iterate_dir_tree(): Iterate recursively on children rather than
1004  * just on the specified path. */
1005 #define WIMLIB_ITERATE_DIR_TREE_FLAG_RECURSIVE 0x00000001
1006
1007 /** For wimlib_iterate_dir_tree(): Don't iterate on the file or directory
1008  * itself; only its children (in the case of a non-empty directory) */
1009 #define WIMLIB_ITERATE_DIR_TREE_FLAG_CHILDREN  0x00000002
1010
1011
1012
1013 /**
1014  * @name Add flags
1015  *
1016  * The following flags can be passed to wimlib_add_image(),
1017  * wimlib_add_image_multisource(), and add commands passed to
1018  * wimlib_update_image().
1019  *
1020  * @{
1021  */
1022
1023 /** Directly capture a NTFS volume rather than a generic directory.  This flag
1024  * cannot be combined with ::WIMLIB_ADD_FLAG_DEREFERENCE or
1025  * ::WIMLIB_ADD_FLAG_UNIX_DATA.   */
1026 #define WIMLIB_ADD_FLAG_NTFS                    0x00000001
1027
1028 /** Follow symlinks; archive and dump the files they point to.  Cannot be used
1029  * with ::WIMLIB_ADD_FLAG_NTFS. */
1030 #define WIMLIB_ADD_FLAG_DEREFERENCE             0x00000002
1031
1032 /** Call the progress function with the message
1033  * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY when each directory or file is starting to
1034  * be scanned, or when a directory or file is being excluded from capture.  */
1035 #define WIMLIB_ADD_FLAG_VERBOSE                 0x00000004
1036
1037 /** Mark the image being added as the bootable image of the WIM. */
1038 #define WIMLIB_ADD_FLAG_BOOT                    0x00000008
1039
1040 /** Store the UNIX owner, group, and mode.  This is done by adding a special
1041  * alternate data stream to each regular file, symbolic link, and directory to
1042  * contain this information.  Please note that this flag is for convenience
1043  * only; Microsoft's @a imagex.exe will not understand this special information.
1044  * This flag cannot be combined with ::WIMLIB_ADD_FLAG_NTFS.  */
1045 #define WIMLIB_ADD_FLAG_UNIX_DATA               0x00000010
1046
1047 /** Do not capture security descriptors.  Only has an effect in NTFS capture
1048  * mode, or in Win32 native builds. */
1049 #define WIMLIB_ADD_FLAG_NO_ACLS                 0x00000020
1050
1051 /** Fail immediately if the full security descriptor of any file or directory
1052  * cannot be accessed.  Only has an effect in Win32 native builds.  The default
1053  * behavior without this flag is to first try omitting the SACL from the
1054  * security descriptor, then to try omitting the security descriptor entirely.
1055  * */
1056 #define WIMLIB_ADD_FLAG_STRICT_ACLS             0x00000040
1057
1058 /** Call the progress function with the message
1059  * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY when a directory or file is excluded from
1060  * capture.  This is a subset of the messages provided by
1061  * ::WIMLIB_ADD_FLAG_VERBOSE. */
1062 #define WIMLIB_ADD_FLAG_EXCLUDE_VERBOSE         0x00000080
1063
1064 /** Reparse-point fixups:  Modify absolute symbolic links (or junction points,
1065  * in the case of Windows) that point inside the directory being captured to
1066  * instead be absolute relative to the directory being captured, rather than the
1067  * current root; also exclude absolute symbolic links that point outside the
1068  * directory tree being captured.
1069  *
1070  * Without this flag, the default is to do this if WIM_HDR_FLAG_RP_FIX is set in
1071  * the WIM header or if this is the first image being added.
1072  * WIM_HDR_FLAG_RP_FIX is set if the first image in a WIM is captured with
1073  * reparse point fixups enabled and currently cannot be unset. */
1074 #define WIMLIB_ADD_FLAG_RPFIX                   0x00000100
1075
1076 /** Don't do reparse point fixups.  The default behavior is described in the
1077  * documentation for ::WIMLIB_ADD_FLAG_RPFIX. */
1078 #define WIMLIB_ADD_FLAG_NORPFIX                 0x00000200
1079
1080 /** Do not automatically exclude unsupported files or directories from capture;
1081  * e.g. encrypted directories in NTFS-3g capture mode, or device files and FIFOs
1082  * on UNIX-like systems.  Instead, fail with ::WIMLIB_ERR_UNSUPPORTED_FILE when
1083  * such a file is encountered.  */
1084 #define WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE  0x00000400
1085
1086 /** Automatically select a capture configuration appropriate for capturing
1087  * filesystems containing Windows operating systems.  When this flag is
1088  * specified, the corresponding @p config parameter or member must be @c NULL.
1089  *
1090  * Currently, selecting this capture configuration will cause the following
1091  * files and directories to be excluded from capture:
1092  *
1093  * - "\$ntfs.log"
1094  * - "\hiberfil.sys"
1095  * - "\pagefile.sys"
1096  * - "\System Volume Information"
1097  * - "\RECYCLER"
1098  * - "\Windows\CSC"
1099  *
1100  * Note that the default behavior--- that is, when this flag is not specified
1101  * and @p config is @c NULL--- is to use no capture configuration, meaning that
1102  * no files are excluded from capture.
1103  */
1104 #define WIMLIB_ADD_FLAG_WINCONFIG               0x00000800
1105
1106 #define WIMLIB_ADD_IMAGE_FLAG_NTFS              WIMLIB_ADD_FLAG_NTFS
1107 #define WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE       WIMLIB_ADD_FLAG_DEREFERENCE
1108 #define WIMLIB_ADD_IMAGE_FLAG_VERBOSE           WIMLIB_ADD_FLAG_VERBOSE
1109 #define WIMLIB_ADD_IMAGE_FLAG_BOOT              WIMLIB_ADD_FLAG_BOOT
1110 #define WIMLIB_ADD_IMAGE_FLAG_UNIX_DATA         WIMLIB_ADD_FLAG_UNIX_DATA
1111 #define WIMLIB_ADD_IMAGE_FLAG_NO_ACLS           WIMLIB_ADD_FLAG_NO_ACLS
1112 #define WIMLIB_ADD_IMAGE_FLAG_STRICT_ACLS       WIMLIB_ADD_FLAG_STRICT_ACLS
1113 #define WIMLIB_ADD_IMAGE_FLAG_EXCLUDE_VERBOSE   WIMLIB_ADD_FLAG_EXCLUDE_VERBOSE
1114 #define WIMLIB_ADD_IMAGE_FLAG_RPFIX             WIMLIB_ADD_FLAG_RPFIX
1115 #define WIMLIB_ADD_IMAGE_FLAG_NORPFIX           WIMLIB_ADD_FLAG_NORPFIX
1116 #define WIMLIB_ADD_IMAGE_FLAG_NO_UNSUPPORTED_EXCLUDE \
1117                                                 WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE
1118 #define WIMLIB_ADD_IMAGE_FLAG_WINCONFIG         WIMLIB_ADD_FLAG_WINCONFIG
1119
1120 /**
1121  * @name Delete flags
1122  *
1123  * The following flags can be specified in delete commands passed to
1124  * wimlib_update_image().
1125  *
1126  * @{
1127  */
1128
1129 /** Do not issue an error if the path to delete does not exist. */
1130 #define WIMLIB_DELETE_FLAG_FORCE                        0x00000001
1131
1132 /** Delete the file or directory tree recursively; if not specified, an error is
1133  * issued if the path to delete is a directory. */
1134 #define WIMLIB_DELETE_FLAG_RECURSIVE                    0x00000002
1135
1136 /**
1137  * @name Export flags
1138  *
1139  * The following flags can be passed to wimlib_export_image().
1140  *
1141  * @{
1142  */
1143
1144 /**
1145  * If a single image is being exported, mark it bootable in the destination WIM.
1146  * Alternatively, if ::WIMLIB_ALL_IMAGES is specified as the image to export,
1147  * the image in the source WIM (if any) that is marked as bootable is also
1148  * marked as bootable in the destination WIM.
1149  */
1150 #define WIMLIB_EXPORT_FLAG_BOOT                         0x00000001
1151
1152 /** Give the exported image(s) no names.  Avoids problems with image name
1153  * collisions.
1154  */
1155 #define WIMLIB_EXPORT_FLAG_NO_NAMES                     0x00000002
1156
1157 /** Give the exported image(s) no descriptions.  */
1158 #define WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS              0x00000004
1159
1160 /**
1161  * @name Extract flags
1162  *
1163  * The following flags can be passed to wimlib_extract_image(),
1164  * wimlib_extract_files(), and wimlib_extract_image_from_pipe().
1165  *
1166  * @{
1167  */
1168
1169 /** Extract the image directly to a NTFS volume rather than a generic directory.
1170  * This mode is only available if wimlib was compiled with libntfs-3g support;
1171  * if not, ::WIMLIB_ERR_UNSUPPORTED will be returned.  In this mode, the
1172  * extraction target will be interpreted as the path to a NTFS volume image (as
1173  * a regular file or block device) rather than a directory.  It will be opened
1174  * using libntfs-3g, and the image will be extracted to the NTFS filesystem's
1175  * root directory.  Note: this flag cannot be used when wimlib_extract_image()
1176  * is called with ::WIMLIB_ALL_IMAGES as the @p image.  */
1177 #define WIMLIB_EXTRACT_FLAG_NTFS                        0x00000001
1178
1179 /** When identical files are extracted from the WIM, always hard link them
1180  * together.  */
1181 #define WIMLIB_EXTRACT_FLAG_HARDLINK                    0x00000002
1182
1183 /** When identical files are extracted from the WIM, always symlink them
1184  * together.  */
1185 #define WIMLIB_EXTRACT_FLAG_SYMLINK                     0x00000004
1186
1187 /** This flag no longer does anything but is reserved for future use.  */
1188 #define WIMLIB_EXTRACT_FLAG_VERBOSE                     0x00000008
1189
1190 /** Read the WIM file sequentially while extracting the image.  */
1191 #define WIMLIB_EXTRACT_FLAG_SEQUENTIAL                  0x00000010
1192
1193 /** Extract special UNIX data captured with ::WIMLIB_ADD_FLAG_UNIX_DATA.  Only
1194  * valid on UNIX-like platforms, and when ::WIMLIB_EXTRACT_FLAG_NTFS was not
1195  * specified.  */
1196 #define WIMLIB_EXTRACT_FLAG_UNIX_DATA                   0x00000020
1197
1198 /** Do not extract security descriptors.  */
1199 #define WIMLIB_EXTRACT_FLAG_NO_ACLS                     0x00000040
1200
1201 /** Fail immediately if the full security descriptor of any file or directory
1202  * cannot be set exactly as specified in the WIM file.  On Windows, the default
1203  * behavior without this flag is to fall back to setting the security descriptor
1204  * with the SACL omitted, then only the default inherited security descriptor,
1205  * if we do not have permission to set the desired one.  */
1206 #define WIMLIB_EXTRACT_FLAG_STRICT_ACLS                 0x00000080
1207
1208 /** This is the extraction equivalent to ::WIMLIB_ADD_FLAG_RPFIX.  This forces
1209  * reparse-point fixups on, so absolute symbolic links or junction points will
1210  * be fixed to be absolute relative to the actual extraction root.  Reparse
1211  * point fixups are done by default if WIM_HDR_FLAG_RP_FIX is set in the WIM
1212  * header.  This flag may only be specified when extracting a full image (not a
1213  * file or directory tree within one).  */
1214 #define WIMLIB_EXTRACT_FLAG_RPFIX                       0x00000100
1215
1216 /** Force reparse-point fixups on extraction off, regardless of the state of the
1217  * WIM_HDR_FLAG_RP_FIX flag in the WIM header.  */
1218 #define WIMLIB_EXTRACT_FLAG_NORPFIX                     0x00000200
1219
1220 /** Extract the specified file to standard output.  This is only valid in an
1221  * extraction command that specifies the extraction of a regular file in the WIM
1222  * image.  */
1223 #define WIMLIB_EXTRACT_FLAG_TO_STDOUT                   0x00000400
1224
1225 /** Instead of ignoring files and directories with names that cannot be
1226  * represented on the current platform (note: Windows has more restrictions on
1227  * filenames than POSIX-compliant systems), try to replace characters or append
1228  * junk to the names so that they can be extracted in some form.  */
1229 #define WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES   0x00000800
1230
1231 /** On Windows, when there exist two or more files with the same case
1232  * insensitive name but different case sensitive names, try to extract them all
1233  * by appending junk to the end of them, rather than arbitrarily extracting only
1234  * one.  */
1235 #define WIMLIB_EXTRACT_FLAG_ALL_CASE_CONFLICTS          0x00001000
1236
1237 /** Do not ignore failure to set timestamps on extracted files.  */
1238 #define WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS           0x00002000
1239
1240 /** Do not ignore failure to set short names on extracted files.  */
1241 #define WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES          0x00004000
1242
1243 /** Do not ignore failure to extract symbolic links (and junction points, on
1244  * Windows) due to permissions problems.  By default, such failures are ignored
1245  * since the default configuration of Windows only allows the Administrator to
1246  * create symbolic links.  */
1247 #define WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS             0x00008000
1248
1249 /** TODO: this flag is intended to allow resuming an aborted extraction, but the
1250  * behavior is currently less than satisfactory.  Do not use (yet).  */
1251 #define WIMLIB_EXTRACT_FLAG_RESUME                      0x00010000
1252
1253 /**
1254  * @name Mount flags
1255  *
1256  * The following flags can be passed to wimlib_mount_image().
1257  *
1258  * @{
1259  */
1260
1261 /** Mount the WIM image read-write rather than the default of read-only. */
1262 #define WIMLIB_MOUNT_FLAG_READWRITE                     0x00000001
1263
1264 /** Enable FUSE debugging by passing the @c -d flag to @c fuse_main().*/
1265 #define WIMLIB_MOUNT_FLAG_DEBUG                         0x00000002
1266
1267 /** Do not allow accessing alternate data streams in the mounted WIM image. */
1268 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE         0x00000004
1269
1270 /** Access alternate data streams in the mounted WIM image through extended file
1271  * attributes.  This is the default mode. */
1272 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR        0x00000008
1273
1274 /** Access alternate data streams in the mounted WIM image by specifying the
1275  * file name, a colon, then the alternate file stream name. */
1276 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS      0x00000010
1277
1278 /** Use UNIX file owners, groups, and modes if available in the WIM (see
1279  * ::WIMLIB_ADD_FLAG_UNIX_DATA). */
1280 #define WIMLIB_MOUNT_FLAG_UNIX_DATA                     0x00000020
1281
1282 /** Allow other users to see the mounted filesystem.  (this passes the @c
1283  * allow_other option to FUSE mount) */
1284 #define WIMLIB_MOUNT_FLAG_ALLOW_OTHER                   0x00000040
1285
1286 /**
1287  * @name Open flags
1288  *
1289  * The following flags can be passed to wimlib_open_wim() and several other
1290  * functions such as wimlib_join().
1291  * @{
1292  */
1293
1294 /** Verify the WIM contents against the WIM's integrity table, if present.  This
1295  * causes the raw data of the WIM file, divided into 10 MB chunks, to be
1296  * checksummed and checked against the SHA1 message digests specified in the
1297  * integrity table.  ::WIMLIB_ERR_INTEGRITY is returned if there are any
1298  * mismatches (or, ::WIMLIB_ERR_INVALID_INTEGRITY_TABLE is returned if the
1299  * integrity table is invalid).  */
1300 #define WIMLIB_OPEN_FLAG_CHECK_INTEGRITY                0x00000001
1301
1302 /** Issue an error if the WIM is part of a split WIM.  */
1303 #define WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT                 0x00000002
1304
1305 /** Check if the WIM is writable and return ::WIMLIB_ERR_WIM_IS_READONLY if it
1306  * is not.  A WIM is considered writable only if it is writable at the
1307  * filesystem level, does not have the WIM_HDR_FLAG_READONLY flag set in its
1308  * header, and is not part of a spanned set.  It is not required to provide this
1309  * flag before attempting to make changes to the WIM, but with this flag you get
1310  * an error sooner rather than later. */
1311 #define WIMLIB_OPEN_FLAG_WRITE_ACCESS                   0x00000004
1312
1313 /**
1314  * @name Unmount flags
1315  *
1316  * The following flags can be passed to wimlib_unmount_image().
1317  * @{
1318  */
1319
1320 /** See ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY.  */
1321 #define WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY             0x00000001
1322
1323 /** Unless this flag is given, changes to a read-write mounted WIM are
1324  * discarded.  Ignored for read-only mounts.  */
1325 #define WIMLIB_UNMOUNT_FLAG_COMMIT                      0x00000002
1326
1327 /** See ::WIMLIB_WRITE_FLAG_REBUILD.  */
1328 #define WIMLIB_UNMOUNT_FLAG_REBUILD                     0x00000004
1329
1330 /** See ::WIMLIB_WRITE_FLAG_RECOMPRESS */
1331 #define WIMLIB_UNMOUNT_FLAG_RECOMPRESS                  0x00000008
1332
1333 /** Do a "lazy" unmount (detach filesystem immediately, even if busy).  */
1334 #define WIMLIB_UNMOUNT_FLAG_LAZY                        0x00000010
1335
1336 /**
1337  * @name Update flags
1338  *
1339  * The following flags can be passed to wimlib_update_image().
1340  * @{
1341  */
1342
1343 /** Send ::WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND and
1344  * ::WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND messages.  */
1345 #define WIMLIB_UPDATE_FLAG_SEND_PROGRESS                0x00000001
1346
1347 /**
1348  * @name Write flags
1349  *
1350  * The following flags can be passed to wimlib_write(), wimlib_overwrite(),
1351  * wimlib_write_to_fd(), and several other functions such as wimlib_join().
1352  * @{
1353  */
1354
1355 /** Include an integrity table in the WIM.
1356  *
1357  * For WIMs created with wimlib_open_wim(), the default behavior is to include
1358  * an integrity table if and only if one was present before.  For WIMs created
1359  * with wimlib_create_new_wim(), the default behavior is to not include an
1360  * integrity table.  */
1361 #define WIMLIB_WRITE_FLAG_CHECK_INTEGRITY               0x00000001
1362
1363 /** Do not include an integrity table in the new WIM file.  This is the default
1364  * behavior, unless the WIM already included an integrity table.  */
1365 #define WIMLIB_WRITE_FLAG_NO_CHECK_INTEGRITY            0x00000002
1366
1367 /** Write the WIM as "pipable".  After writing a WIM with this flag specified,
1368  * images from it can be applied directly from a pipe using
1369  * wimlib_extract_image_from_pipe().  See the documentation for the --pipable
1370  * flag of `wimlib-imagex capture' for more information.  Beware: WIMs written
1371  * with this flag will not be compatible with Microsoft's software.
1372  *
1373  * For WIMs created with wimlib_open_wim(), the default behavior is to write the
1374  * WIM as pipable if and only if it was pipable before.  For WIMs created with
1375  * wimlib_create_new_wim(), the default behavior is to write the WIM as
1376  * non-pipable.  */
1377 #define WIMLIB_WRITE_FLAG_PIPABLE                       0x00000004
1378
1379 /** Do not write the WIM as "pipable".  This is the default behavior, unless the
1380  * WIM was pipable already.  */
1381 #define WIMLIB_WRITE_FLAG_NOT_PIPABLE                   0x00000008
1382
1383 /** Recompress all resources, even if they could otherwise be copied from a
1384  * different WIM with the same compression type (in the case of
1385  * wimlib_export_image() being called previously).  This flag is also valid in
1386  * the @p wim_write_flags of wimlib_join(), in which case all resources included
1387  * in the joined WIM file will be recompressed.  */
1388 #define WIMLIB_WRITE_FLAG_RECOMPRESS                    0x00000010
1389
1390 /** Call fsync() just before the WIM file is closed.  */
1391 #define WIMLIB_WRITE_FLAG_FSYNC                         0x00000020
1392
1393 /** wimlib_overwrite() only:  Re-build the entire WIM file rather than appending
1394  * data to it if possible.  */
1395 #define WIMLIB_WRITE_FLAG_REBUILD                       0x00000040
1396
1397 /** wimlib_overwrite() only:  Specifying this flag overrides the default
1398  * behavior of wimlib_overwrite() after one or more calls to
1399  * wimlib_delete_image(), which is to rebuild the entire WIM.  With this flag,
1400  * only minimal changes to correctly remove the image from the WIM will be
1401  * taken.  In particular, all streams will be left alone, even if they are no
1402  * longer referenced.  This is probably not what you want, because almost no
1403  * space will be saved by deleting an image in this way.  */
1404 #define WIMLIB_WRITE_FLAG_SOFT_DELETE                   0x00000080
1405
1406 /** wimlib_overwrite() only:  Allow overwriting the WIM even if the readonly
1407  * flag is set in the WIM header.  This can be used in combination with
1408  * wimlib_set_wim_info() with the ::WIMLIB_CHANGE_READONLY_FLAG flag to actually
1409  * set the readonly flag on the on-disk WIM file.  */
1410 #define WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG          0x00000100
1411
1412 /** Do not include non-metadata resources already present in other WIMs.  This
1413  * flag can be used to write a "delta" WIM after resources from the WIM on which
1414  * the delta is to be based were referenced with
1415  * wimlib_reference_resource_files() or wimlib_reference_resources().  */
1416 #define WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIMS            0x00000200
1417
1418 /** Asserts that for writes of all WIM images, all streams needed for the WIM
1419  * are already present (not in external resource WIMs) and their reference
1420  * counts are correct, so the code does not need to recalculate which streams
1421  * are referenced.  This is for optimization purposes only, since with this flag
1422  * specified, the metadata resources may not need to be decompressed and parsed.
1423  *
1424  * This flag can be passed to wimlib_write() and wimlib_write_to_fd(), but is
1425  * already implied for wimlib_overwrite().  */
1426 #define WIMLIB_WRITE_FLAG_STREAMS_OK                    0x00000400
1427
1428 /**
1429  * @name Init flags
1430  *
1431  * The following flags can be passed to wimlib_global_init().
1432  * @{
1433  */
1434
1435 /** Assume that strings are represented in UTF-8, even if this is not the
1436  * locale's character encoding.  This flag is ignored on Windows, where wimlib
1437  * always uses UTF-16LE.  */
1438 #define WIMLIB_INIT_FLAG_ASSUME_UTF8                    0x00000001
1439
1440 /** Windows-only: do not attempt to acquire additional privileges (currently
1441  * SeBackupPrivilege, SeRestorePrivilege, SeSecurityPrivilege, and
1442  * SeTakeOwnershipPrivilege) when initializing the library.  This is intended
1443  * for the case where the calling program manages these privileges itself.
1444  * Note: no error is issued if privileges cannot be acquired, although related
1445  * errors may be reported later, depending on if the operations performed
1446  * actually require additional privileges or not.  */
1447 #define WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES        0x00000002
1448
1449 /** Windows only:  If ::WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES not specified,
1450  * return ::WIMLIB_ERR_INSUFFICIENT_PRIVILEGES if privileges that may be needed
1451  * to read all possible data and metadata for a capture operation could not be
1452  * acquired.  Can be combined with ::WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES.
1453  */
1454 #define WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES      0x00000004
1455
1456 /** Windows only:  If ::WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES not specified,
1457  * return ::WIMLIB_ERR_INSUFFICIENT_PRIVILEGES if privileges that may be needed
1458  * to restore all possible data and metadata for an apply operation could not be
1459  * acquired.  Can be combined with ::WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES.
1460  */
1461 #define WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES        0x00000008
1462
1463 /**
1464  * @name Resource reference flags
1465  *
1466  * The following flags can be passed to wimlib_reference_resource_files() and
1467  * wimlib_reference_resources().
1468  * @{
1469  */
1470
1471 /** wimlib_reference_resource_files() only:  Enable shell-style filename
1472  * globbing.  */
1473 #define WIMLIB_REF_FLAG_GLOB_ENABLE             0x00000001
1474
1475 /** wimlib_reference_resource_files() only:  Issue an error
1476  * (::WIMLIB_ERR_GLOB_HAD_NO_MATCHES) if a glob did not match any files.  The
1477  * default behavior without this flag is to issue no error at that point, but
1478  * then attempt to open the glob as a literal path, which of course will fail
1479  * anyway if no file exists at that path.  No effect if
1480  * ::WIMLIB_REF_FLAG_GLOB_ENABLE is not also specified.  */
1481 #define WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH     0x00000002
1482
1483 /**
1484  * @}
1485  */
1486
1487 /** The specific type of update to perform. */
1488 enum wimlib_update_op {
1489         /** Add a new file or directory tree to the WIM image in a
1490          * certain location. */
1491         WIMLIB_UPDATE_OP_ADD = 0,
1492
1493         /** Delete a file or directory tree from the WIM image. */
1494         WIMLIB_UPDATE_OP_DELETE,
1495
1496         /** Rename a file or directory tree in the WIM image. */
1497         WIMLIB_UPDATE_OP_RENAME,
1498 };
1499
1500 /** Data for a ::WIMLIB_UPDATE_OP_ADD operation. */
1501 struct wimlib_add_command {
1502         /** Filesystem path to the file or directory tree to
1503          * add. */
1504         wimlib_tchar *fs_source_path;
1505         /** Path, specified from the root of the WIM image, at
1506          * which to add the file or directory tree within the
1507          * WIM image. */
1508         wimlib_tchar *wim_target_path;
1509
1510         /** Configuration for excluded files.  @c NULL means
1511          * exclude no files (use no configuration), unless
1512          * ::WIMLIB_ADD_FLAG_WINCONFIG is specified in @p
1513          * add_flags.  */
1514         struct wimlib_capture_config *config;
1515
1516         /** Bitwise OR of WIMLIB_ADD_FLAG_* flags. */
1517         int add_flags;
1518 };
1519
1520 /** Data for a ::WIMLIB_UPDATE_OP_DELETE operation. */
1521 struct wimlib_delete_command {
1522         /** Path, specified from the root of the WIM image, for
1523          * the file or directory tree within the WIM image to be
1524          * deleted. */
1525         wimlib_tchar *wim_path;
1526         /** Bitwise OR of WIMLIB_DELETE_FLAG_* flags. */
1527         int delete_flags;
1528 };
1529
1530 /** Data for a ::WIMLIB_UPDATE_OP_RENAME operation. */
1531 struct wimlib_rename_command {
1532         /** Path, specified from the root of the WIM image, for
1533          * the source file or directory tree within the WIM
1534          * image. */
1535         wimlib_tchar *wim_source_path;
1536         /** Path, specified from the root of the WIM image, for
1537          * the destination file or directory tree within the WIM
1538          * image. */
1539         wimlib_tchar *wim_target_path;
1540         /** Reserved; set to 0. */
1541         int rename_flags;
1542 };
1543
1544 /** Specification of an update to perform on a WIM image. */
1545 struct wimlib_update_command {
1546
1547         enum wimlib_update_op op;
1548
1549         union {
1550                 struct wimlib_add_command add;
1551                 struct wimlib_delete_command delete_; /* Underscore is for C++
1552                                                          compatibility.  */
1553                 struct wimlib_rename_command rename;
1554         };
1555 };
1556
1557 /** Specification of a file or directory tree to extract from a WIM image. */
1558 struct wimlib_extract_command {
1559         /** Path to file or directory tree within the WIM image to extract.  It
1560          * must be provided as an absolute path from the root of the WIM image.
1561          * The path separators may be either forward slashes or backslashes. */
1562         wimlib_tchar *wim_source_path;
1563
1564         /** Filesystem path to extract the file or directory tree to. */
1565         wimlib_tchar *fs_dest_path;
1566
1567         /** Bitwise or of zero or more of the WIMLIB_EXTRACT_FLAG_* flags. */
1568         int extract_flags;
1569 };
1570
1571 /**
1572  * Possible values of the error code returned by many functions in wimlib.
1573  *
1574  * See the documentation for each wimlib function to see specifically what error
1575  * codes can be returned by a given function, and what they mean.
1576  */
1577 enum wimlib_error_code {
1578         WIMLIB_ERR_SUCCESS = 0,
1579         WIMLIB_ERR_ALREADY_LOCKED,
1580         WIMLIB_ERR_DECOMPRESSION,
1581         WIMLIB_ERR_DELETE_STAGING_DIR,
1582         WIMLIB_ERR_FILESYSTEM_DAEMON_CRASHED,
1583         WIMLIB_ERR_FORK,
1584         WIMLIB_ERR_FUSE,
1585         WIMLIB_ERR_FUSERMOUNT,
1586         WIMLIB_ERR_GLOB_HAD_NO_MATCHES,
1587         WIMLIB_ERR_ICONV_NOT_AVAILABLE,
1588         WIMLIB_ERR_IMAGE_COUNT,
1589         WIMLIB_ERR_IMAGE_NAME_COLLISION,
1590         WIMLIB_ERR_INSUFFICIENT_PRIVILEGES,
1591         WIMLIB_ERR_INTEGRITY,
1592         WIMLIB_ERR_INVALID_CAPTURE_CONFIG,
1593         WIMLIB_ERR_INVALID_CHUNK_SIZE,
1594         WIMLIB_ERR_INVALID_COMPRESSION_TYPE,
1595         WIMLIB_ERR_INVALID_HEADER,
1596         WIMLIB_ERR_INVALID_IMAGE,
1597         WIMLIB_ERR_INVALID_INTEGRITY_TABLE,
1598         WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY,
1599         WIMLIB_ERR_INVALID_METADATA_RESOURCE,
1600         WIMLIB_ERR_INVALID_MULTIBYTE_STRING,
1601         WIMLIB_ERR_INVALID_OVERLAY,
1602         WIMLIB_ERR_INVALID_PARAM,
1603         WIMLIB_ERR_INVALID_PART_NUMBER,
1604         WIMLIB_ERR_INVALID_PIPABLE_WIM,
1605         WIMLIB_ERR_INVALID_REPARSE_DATA,
1606         WIMLIB_ERR_INVALID_RESOURCE_HASH,
1607         WIMLIB_ERR_INVALID_UNMOUNT_MESSAGE,
1608         WIMLIB_ERR_INVALID_UTF16_STRING,
1609         WIMLIB_ERR_INVALID_UTF8_STRING,
1610         WIMLIB_ERR_IS_DIRECTORY,
1611         WIMLIB_ERR_IS_SPLIT_WIM,
1612         WIMLIB_ERR_LIBXML_UTF16_HANDLER_NOT_AVAILABLE,
1613         WIMLIB_ERR_LINK,
1614         WIMLIB_ERR_METADATA_NOT_FOUND,
1615         WIMLIB_ERR_MKDIR,
1616         WIMLIB_ERR_MQUEUE,
1617         WIMLIB_ERR_NOMEM,
1618         WIMLIB_ERR_NOTDIR,
1619         WIMLIB_ERR_NOTEMPTY,
1620         WIMLIB_ERR_NOT_A_REGULAR_FILE,
1621         WIMLIB_ERR_NOT_A_WIM_FILE,
1622         WIMLIB_ERR_NOT_PIPABLE,
1623         WIMLIB_ERR_NO_FILENAME,
1624         WIMLIB_ERR_NTFS_3G,
1625         WIMLIB_ERR_OPEN,
1626         WIMLIB_ERR_OPENDIR,
1627         WIMLIB_ERR_PATH_DOES_NOT_EXIST,
1628         WIMLIB_ERR_READ,
1629         WIMLIB_ERR_READLINK,
1630         WIMLIB_ERR_RENAME,
1631         WIMLIB_ERR_REOPEN,
1632         WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED,
1633         WIMLIB_ERR_RESOURCE_NOT_FOUND,
1634         WIMLIB_ERR_RESOURCE_ORDER,
1635         WIMLIB_ERR_SET_ATTRIBUTES,
1636         WIMLIB_ERR_SET_REPARSE_DATA,
1637         WIMLIB_ERR_SET_SECURITY,
1638         WIMLIB_ERR_SET_SHORT_NAME,
1639         WIMLIB_ERR_SET_TIMESTAMPS,
1640         WIMLIB_ERR_SPLIT_INVALID,
1641         WIMLIB_ERR_STAT,
1642         WIMLIB_ERR_TIMEOUT,
1643         WIMLIB_ERR_UNEXPECTED_END_OF_FILE,
1644         WIMLIB_ERR_UNICODE_STRING_NOT_REPRESENTABLE,
1645         WIMLIB_ERR_UNKNOWN_VERSION,
1646         WIMLIB_ERR_UNSUPPORTED,
1647         WIMLIB_ERR_UNSUPPORTED_FILE,
1648         WIMLIB_ERR_VOLUME_LACKS_FEATURES,
1649         WIMLIB_ERR_WIM_IS_READONLY,
1650         WIMLIB_ERR_WRITE,
1651         WIMLIB_ERR_XML,
1652 };
1653
1654
1655 /** Used to indicate no WIM image or an invalid WIM image. */
1656 #define WIMLIB_NO_IMAGE         0
1657
1658 /** Used to specify all images in the WIM. */
1659 #define WIMLIB_ALL_IMAGES       (-1)
1660
1661 /**
1662  * Appends an empty image to a WIM file.  This empty image will initially
1663  * contain no files or directories, although if written without further
1664  * modifications, a root directory will be created automatically for it.  After
1665  * calling this function, you can use wimlib_update_image() to add files to the
1666  * new WIM image.  This gives you slightly more control over making the new
1667  * image compared to calling wimlib_add_image() or
1668  * wimlib_add_image_multisource() directly.
1669  *
1670  * @param wim
1671  *      Pointer to the ::WIMStruct for the WIM file to which the image is to be
1672  *      added.
1673  * @param name
1674  *      Name to give the new image.  If @c NULL or empty, the new image is given
1675  *      no name.  If nonempty, it must specify a name that does not already
1676  *      exist in @p wim.
1677  * @param new_idx_ret
1678  *      If non-<code>NULL</code>, the index of the newly added image is returned
1679  *      in this location.
1680  *
1681  * @return 0 on success; nonzero on failure.  The possible error codes are:
1682  *
1683  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
1684  *      There is already an image in @p wim named @p name.
1685  * @retval ::WIMLIB_ERR_NOMEM
1686  *      Failed to allocate the memory needed to add the new image.
1687  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
1688  *      The WIM file is considered read-only because of any of the reasons
1689  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
1690  *      flag.
1691  */
1692 extern int
1693 wimlib_add_empty_image(WIMStruct *wim,
1694                        const wimlib_tchar *name,
1695                        int *new_idx_ret);
1696
1697 /**
1698  * Adds an image to a WIM file from an on-disk directory tree or NTFS volume.
1699  *
1700  * The directory tree or NTFS volume is scanned immediately to load the dentry
1701  * tree into memory, and file attributes and symbolic links are read.  However,
1702  * actual file data is not read until wimlib_write() or wimlib_overwrite() is
1703  * called.
1704  *
1705  * See the manual page for the @b wimlib-imagex program for more information
1706  * about the "normal" capture mode versus the NTFS capture mode (entered by
1707  * providing the flag ::WIMLIB_ADD_FLAG_NTFS).
1708  *
1709  * Note that @b no changes are committed to the underlying WIM file (if
1710  * any) until wimlib_write() or wimlib_overwrite() is called.
1711  *
1712  * @param wim
1713  *      Pointer to the ::WIMStruct for a WIM file to which the image will be
1714  *      added.
1715  * @param source
1716  *      A path to a directory or unmounted NTFS volume that will be captured as
1717  *      a WIM image.
1718  * @param name
1719  *      Name to give the new image.  If @c NULL or empty, the new image is given
1720  *      no name.  If nonempty, it must specify a name that does not already
1721  *      exist in @p wim.
1722  * @param config
1723  *      Capture configuration that specifies files, directories, or path globs
1724  *      to exclude from being captured.  If @c NULL, a dummy configuration where
1725  *      no paths are treated specially is used.
1726  * @param add_flags
1727  *      Bitwise OR of flags prefixed with WIMLIB_ADD_FLAG.
1728  * @param progress_func
1729  *      If non-NULL, a function that will be called periodically with the
1730  *      progress of the current operation.  The progress messages that will be
1731  *      received are ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN,
1732  *      ::WIMLIB_PROGRESS_MSG_SCAN_END, and, if ::WIMLIB_ADD_FLAG_VERBOSE was
1733  *      included in @p add_flags, also ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY.
1734  *
1735  * @return 0 on success; nonzero on error.  On error, changes to @p wim are
1736  * discarded so that it appears to be in the same state as when this function
1737  * was called.
1738  *
1739  * This function is implemented by calling wimlib_add_empty_image(), then
1740  * calling wimlib_update_image() with a single "add" command, so any error code
1741  * returned by wimlib_add_empty_image() may be returned, as well as any error
1742  * codes returned by wimlib_update_image() other than ones documented as only
1743  * being returned specifically by an update involving delete or rename commands.
1744  */
1745 extern int
1746 wimlib_add_image(WIMStruct *wim,
1747                  const wimlib_tchar *source,
1748                  const wimlib_tchar *name,
1749                  const struct wimlib_capture_config *config,
1750                  int add_flags,
1751                  wimlib_progress_func_t progress_func);
1752
1753 /** This function is equivalent to wimlib_add_image() except it allows for
1754  * multiple sources to be combined into a single WIM image.  This is done by
1755  * specifying the @p sources and @p num_sources parameters instead of the @p
1756  * source parameter of wimlib_add_image().  The rest of the parameters are the
1757  * same as wimlib_add_image().  See the documentation for <b>wimlib-imagex
1758  * capture</b> for full details on how this mode works.
1759  *
1760  * In addition to the error codes that wimlib_add_image() can return,
1761  * wimlib_add_image_multisource() can return ::WIMLIB_ERR_INVALID_OVERLAY
1762  * when trying to overlay a non-directory on a directory or when otherwise
1763  * trying to overlay multiple conflicting files to the same location in the WIM
1764  * image.  It will also return ::WIMLIB_ERR_INVALID_PARAM if
1765  * ::WIMLIB_ADD_FLAG_NTFS was specified in @p add_flags but there
1766  * was not exactly one capture source with the target being the root directory.
1767  * (In this respect, there is no advantage to using
1768  * wimlib_add_image_multisource() instead of wimlib_add_image() when requesting
1769  * NTFS mode.) */
1770 extern int
1771 wimlib_add_image_multisource(WIMStruct *wim,
1772                              const struct wimlib_capture_source *sources,
1773                              size_t num_sources,
1774                              const wimlib_tchar *name,
1775                              const struct wimlib_capture_config *config,
1776                              int add_flags,
1777                              wimlib_progress_func_t progress_func);
1778
1779 /**
1780  * Creates a ::WIMStruct for a new WIM file.
1781  *
1782  * This only creates an in-memory structure for a WIM that initially contains no
1783  * images.  No on-disk file is created until wimlib_write() is called.
1784  *
1785  * @param ctype
1786  *      The type of compression to be used in the new WIM file.  Must be
1787  *      ::WIMLIB_COMPRESSION_TYPE_NONE, ::WIMLIB_COMPRESSION_TYPE_LZX, or
1788  *      ::WIMLIB_COMPRESSION_TYPE_XPRESS.
1789  * @param wim_ret
1790  *      On success, a pointer to an opaque ::WIMStruct for the new WIM file is
1791  *      written to the memory location pointed to by this paramater.  The
1792  *      ::WIMStruct must be freed using using wimlib_free() when finished with
1793  *      it.
1794  * @return 0 on success; nonzero on error.
1795  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
1796  *      @p ctype was not ::WIMLIB_COMPRESSION_TYPE_NONE,
1797  *      ::WIMLIB_COMPRESSION_TYPE_LZX, or ::WIMLIB_COMPRESSION_TYPE_XPRESS.
1798  * @retval ::WIMLIB_ERR_NOMEM
1799  *      Failed to allocate needed memory.
1800  */
1801 extern int
1802 wimlib_create_new_wim(int ctype, WIMStruct **wim_ret);
1803
1804 /**
1805  * Deletes an image, or all images, from a WIM file.
1806  *
1807  * All streams referenced by the image(s) being deleted are removed from the
1808  * lookup table of the WIM if they are not referenced by any other images in the
1809  * WIM.
1810  *
1811  * Please note that @b no changes are committed to the underlying WIM file (if
1812  * any) until wimlib_write() or wimlib_overwrite() is called.
1813  *
1814  * @param wim
1815  *      Pointer to the ::WIMStruct for the WIM file that contains the image(s)
1816  *      being deleted.
1817  * @param image
1818  *      The number of the image to delete, or ::WIMLIB_ALL_IMAGES to delete all
1819  *      images.
1820  * @return 0 on success; nonzero on failure.  On failure, @p wim is guaranteed
1821  * to be left unmodified only if @p image specified a single image.  If instead
1822  * @p image was ::WIMLIB_ALL_IMAGES and @p wim contained more than one image, it's
1823  * possible for some but not all of the images to have been deleted when a
1824  * failure status is returned.
1825  *
1826  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1827  *      @p image does not exist in the WIM and is not ::WIMLIB_ALL_IMAGES.
1828  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
1829  *      The WIM file is considered read-only because of any of the reasons
1830  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
1831  *      flag.
1832  *
1833  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
1834  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
1835  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
1836  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
1837  * different reasons) to read the metadata resource for an image that needed to
1838  * be deleted.
1839  */
1840 extern int
1841 wimlib_delete_image(WIMStruct *wim, int image);
1842
1843 /**
1844  * Exports an image, or all the images, from a WIM file, into another WIM file.
1845  *
1846  * The destination image is made to share the same dentry tree and security data
1847  * structure as the source image.  This places some restrictions on additional
1848  * functions that may be called.  wimlib_mount_image() may not be called on
1849  * either the source image or the destination image without an intervening call
1850  * to a function that un-shares the images, such as wimlib_free() on @p
1851  * dest_wim, or wimlib_delete_image() on either the source or destination image.
1852  * Furthermore, you may not call wimlib_free() on @p src_wim before calling
1853  * wimlib_write() or wimlib_overwrite() on @p dest_wim because @p dest_wim will
1854  * have references back to @p src_wim.
1855  *
1856  * If this function fails, all changes to @p dest_wim are rolled back.
1857  *
1858  * Please note that no changes are committed to the underlying WIM file of @p
1859  * dest_wim (if any) until wimlib_write() or wimlib_overwrite() is called.
1860  *
1861  * @param src_wim
1862  *      The WIM from which to export the images, specified as a pointer to the
1863  *      ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1 of a
1864  *      split WIM.  In the case of a WIM file that is not standalone, this
1865  *      ::WIMStruct must have had any needed external resources previously
1866  *      referenced using wimlib_reference_resources() or
1867  *      wimlib_reference_resource_files().
1868  * @param src_image
1869  *      The image to export from @p src_wim, as either a 1-based image index to
1870  *      export a single image, or ::WIMLIB_ALL_IMAGES to export all images.
1871  * @param dest_wim
1872  *      Pointer to the ::WIMStruct for a WIM that will receive the images being
1873  *      exported.
1874  * @param dest_name
1875  *      For single-image exports, the name to give the exported image in @p
1876  *      dest_wim.  If left @c NULL, the name from @p src_wim is used.  For
1877  *      ::WIMLIB_ALL_IMAGES exports, this parameter must be left @c NULL; in
1878  *      that case, the names are all taken from @p src_wim.  This parameter is
1879  *      overridden by ::WIMLIB_EXPORT_FLAG_NO_NAMES.
1880  * @param dest_description
1881  *      For single-image exports, the description to give the exported image in
1882  *      the new WIM file.  If left @c NULL, the description from @p src_wim is
1883  *      used.  For ::WIMLIB_ALL_IMAGES exports, this parameter must be left @c
1884  *      NULL; in that case, the description are all taken from @p src_wim.  This
1885  *      parameter is overridden by ::WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS.
1886  * @param export_flags
1887  *      Bitwise OR of flags prefixed with WIMLIB_EXPORT_FLAG.
1888  * @param progress_func
1889  *      Currently ignored, but reserved for a function that will be called with
1890  *      information about the operation.  Use NULL if no additional information
1891  *      is desired.
1892  *
1893  * @return 0 on success; nonzero on error.
1894  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
1895  *      One or more of the names being given to an exported image was already in
1896  *      use in the destination WIM.
1897  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1898  *      @p src_image does not exist in @p src_wim and was not
1899  *      ::WIMLIB_ALL_IMAGES.
1900  * @retval ::WIMLIB_ERR_INVALID_PARAM
1901  *      @p src_wim and/or @p dest_wim were @c NULL; or @p src_image was
1902  *      ::WIMLIB_ALL_IMAGES but @p dest_name and/or @p dest_description were not
1903  *      @c NULL.
1904  * @retval ::WIMLIB_ERR_METADATA_NOT_FOUND
1905  *      Either @p src_wim or @p dest_wim did not contain metadata resources; for
1906  *      example, one of them was a non-first part of a split WIM.
1907  * @retval ::WIMLIB_ERR_NOMEM
1908  *      Failed to allocate needed memory.
1909  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
1910  *      A resource that needed to be exported could not be found in either the
1911  *      source or destination WIMs.  This error can occur if, for example, @p
1912  *      src_wim is part of a split WIM but needed resources from the other split
1913  *      WIM parts were not referenced with wimlib_reference_resources() or
1914  *      wimlib_reference_resource_files() before the call to
1915  *      wimlib_export_image().
1916  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
1917  *      @p dest_wim is considered read-only because of any of the reasons
1918  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
1919  *      flag.
1920  *
1921  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
1922  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
1923  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
1924  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
1925  * different reasons) to read the metadata resource for an image in @p src_wim
1926  * that needed to be exported.
1927  */
1928 extern int
1929 wimlib_export_image(WIMStruct *src_wim, int src_image,
1930                     WIMStruct *dest_wim,
1931                     const wimlib_tchar *dest_name,
1932                     const wimlib_tchar *dest_description,
1933                     int export_flags,
1934                     wimlib_progress_func_t progress_func);
1935
1936 /**
1937  * Extract zero or more files or directory trees from a WIM image.
1938  *
1939  * This generalizes the single-image extraction functionality of
1940  * wimlib_extract_image() to allow extracting only the specified subsets of the
1941  * image.
1942  *
1943  * @param wim
1944  *      The WIM from which to extract the files, specified as a pointer to the
1945  *      ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1 of a
1946  *      split WIM.  In the case of a WIM file that is not standalone, this
1947  *      ::WIMStruct must have had any needed external resources previously
1948  *      referenced using wimlib_reference_resources() or
1949  *      wimlib_reference_resource_files().
1950  *
1951  * @param image
1952  *      The 1-based number of the image in @p wim from which the files or
1953  *      directory trees are to be extracted.  It cannot be ::WIMLIB_ALL_IMAGES.
1954  *
1955  * @param cmds
1956  *      An array of ::wimlib_extract_command structures that specifies the
1957  *      extractions to perform.
1958  *
1959  * @param num_cmds
1960  *      Number of commands in the @p cmds array.
1961  *
1962  * @param default_extract_flags
1963  *      Default extraction flags; the behavior shall be as if these flags had
1964  *      been specified in the ::wimlib_extract_command.extract_flags member in
1965  *      each extraction command, in combination with any flags already present.
1966  *
1967  * @param progress_func
1968  *      If non-NULL, a function that will be called periodically with the
1969  *      progress of the current operation.
1970  *
1971  * @return 0 on success; nonzero on error.  The possible error codes include
1972  * most of those documented as returned by wimlib_extract_image() as well as the
1973  * following additional error codes:
1974  *
1975  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1976  *      @p image was ::WIMLIB_ALL_IMAGES (or was not otherwise a valid image in
1977  *      the WIM file).
1978  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
1979  *      The ::wimlib_extract_command.wim_source_path member in one of the
1980  *      extract commands did not exist in the WIM.
1981  * @retval ::WIMLIB_ERR_NOT_A_REGULAR_FILE
1982  *      ::WIMLIB_EXTRACT_FLAG_TO_STDOUT was specified for an extraction command
1983  *      in which ::wimlib_extract_command.wim_source_path existed but was not a
1984  *      regular file or directory.
1985  * @retval ::WIMLIB_ERR_INVALID_PARAM
1986  *      ::WIMLIB_EXTRACT_FLAG_HARDLINK or ::WIMLIB_EXTRACT_FLAG_SYMLINK was
1987  *      specified for some commands but not all; or
1988  *      ::wimlib_extract_command.fs_dest_path was @c NULL or the empty string
1989  *      for one or more commands; or ::WIMLIB_EXTRACT_FLAG_RPFIX was specified
1990  *      for a command in which ::wimlib_extract_command.wim_source_path did not
1991  *      specify the root directory of the WIM image.
1992  */
1993 extern int
1994 wimlib_extract_files(WIMStruct *wim,
1995                      int image,
1996                      const struct wimlib_extract_command *cmds,
1997                      size_t num_cmds,
1998                      int default_extract_flags,
1999                      wimlib_progress_func_t progress_func);
2000
2001 /**
2002  * Extracts an image, or all images, from a WIM to a directory or directly to a
2003  * NTFS volume image.
2004  *
2005  * The exact behavior of how wimlib extracts files from a WIM image is
2006  * controllable by the @p extract_flags parameter, but there also are
2007  * differences depending on the platform (UNIX-like vs Windows).  See the manual
2008  * page for <b>wimlib-imagex apply</b> for more information, including about the
2009  * special "NTFS volume extraction mode" entered by providing
2010  * ::WIMLIB_EXTRACT_FLAG_NTFS.
2011  *
2012  * All extracted data is SHA1-summed, and ::WIMLIB_ERR_INVALID_RESOURCE_HASH is
2013  * returned if any resulting SHA1 message digests do not match the values
2014  * provided in the WIM file.  Therefore, if this function is successful, you can
2015  * be fairly sure that any compressed data in the WIM was uncompressed
2016  * correctly.
2017  *
2018  * @param wim
2019  *      The WIM from which to extract the image(s), specified as a pointer to
2020  *      the ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1
2021  *      of a split WIM.  In the case of a WIM file that is not standalone, this
2022  *      ::WIMStruct must have had any needed external resources previously
2023  *      referenced using wimlib_reference_resources() or
2024  *      wimlib_reference_resource_files().
2025  * @param image
2026  *      The image to extract.  Can be the number of an image, or ::WIMLIB_ALL_IMAGES
2027  *      to specify that all images are to be extracted.  ::WIMLIB_ALL_IMAGES cannot
2028  *      be used if ::WIMLIB_EXTRACT_FLAG_NTFS is specified in @p extract_flags.
2029  * @param target
2030  *      Directory to extract the WIM image(s) to (created if it does not already
2031  *      exist); or, with ::WIMLIB_EXTRACT_FLAG_NTFS in @p extract_flags, the
2032  *      path to the unmounted NTFS volume to extract the image to.
2033  * @param extract_flags
2034  *      Bitwise OR of the flags prefixed with WIMLIB_EXTRACT_FLAG.
2035  * @param progress_func
2036  *      If non-NULL, a function that will be called periodically with the
2037  *      progress of the current operation.
2038  *
2039  * @return 0 on success; nonzero on error.
2040  * @retval ::WIMLIB_ERR_DECOMPRESSION
2041  *      Failed to decompress a resource to be extracted.
2042  * @retval ::WIMLIB_ERR_INVALID_PARAM
2043  *      Both ::WIMLIB_EXTRACT_FLAG_HARDLINK and ::WIMLIB_EXTRACT_FLAG_SYMLINK
2044  *      were specified in @p extract_flags; or both
2045  *      ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS and ::WIMLIB_EXTRACT_FLAG_NO_ACLS were
2046  *      specified in @p extract_flags; or both ::WIMLIB_EXTRACT_FLAG_RPFIX and
2047  *      ::WIMLIB_EXTRACT_FLAG_NORPFIX were specified in @p extract_flags; or
2048  *      ::WIMLIB_EXTRACT_FLAG_RESUME was specified in @p extract_flags; or if
2049  *      ::WIMLIB_EXTRACT_FLAG_NTFS was specified in @p extract_flags and
2050  *      @p image was ::WIMLIB_ALL_IMAGES.
2051  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
2052  *      The SHA1 message digest of an extracted stream did not match the SHA1
2053  *      message digest given in the WIM file.
2054  * @retval ::WIMLIB_ERR_LINK
2055  *      Failed to create a symbolic link or a hard link.
2056  * @retval ::WIMLIB_ERR_MKDIR
2057  *      Failed create a directory.
2058  * @retval ::WIMLIB_ERR_NOMEM
2059  *      Failed to allocate needed memory.
2060  * @retval ::WIMLIB_ERR_OPEN
2061  *      Could not create a file, or failed to open an already-extracted file.
2062  * @retval ::WIMLIB_ERR_READ
2063  *      Failed to read data from the WIM file associated with @p wim.
2064  * @retval ::WIMLIB_ERR_READLINK
2065  *      Failed to determine the target of a symbolic link in the WIM.
2066  * @retval ::WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED
2067  *      Failed to fix the target of an absolute symbolic link (e.g. if the
2068  *      target would have exceeded the maximum allowed length).  (Only if
2069  *      reparse data was supported by the extraction mode and
2070  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS was specified in @p extract_flags.)
2071  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
2072  *      One of the files or directories that needed to be extracted referenced a
2073  *      stream not present in the WIM's lookup table (or in any of the lookup
2074  *      tables of the split WIM parts).
2075  * @retval ::WIMLIB_ERR_SET_ATTRIBUTES
2076  *      Failed to set attributes on a file.
2077  * @retval ::WIMLIB_ERR_SET_REPARSE_DATA
2078  *      Failed to set reparse data on a file (only if reparse data was supported
2079  *      by the extraction mode).
2080  * @retval ::WIMLIB_ERR_SET_SECURITY
2081  *      Failed to set security descriptor on a file
2082  *      (only if ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS was specified in @p
2083  *      extract_flags).
2084  * @retval ::WIMLIB_ERR_SET_SHORT_NAME
2085  *      Failed to set the short name of a file (only if
2086  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES was specified in @p extract_flags).
2087  * @retval ::WIMLIB_ERR_SET_TIMESTAMPS
2088  *      Failed to set timestamps on a file (only if
2089  *      ::WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS was specified in @p extract_flags).
2090  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
2091  *      Unexpected end-of-file occurred when reading data from the WIM file
2092  *      associated with @p wim.
2093  * @retval ::WIMLIB_ERR_UNSUPPORTED
2094  *      A requested extraction flag, or the data or metadata that must be
2095  *      extracted to support it, is unsupported in the build and configuration
2096  *      of wimlib, or on the current platform or extraction mode or target
2097  *      volume.  Flags affected by this include ::WIMLIB_EXTRACT_FLAG_NTFS,
2098  *      ::WIMLIB_EXTRACT_FLAG_UNIX_DATA, ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS,
2099  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES,
2100  *      ::WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS,
2101  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS, ::WIMLIB_EXTRACT_FLAG_SYMLINK,
2102  *      and ::WIMLIB_EXTRACT_FLAG_HARDLINK.  For example, if
2103  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES is specified in @p
2104  *      extract_flags,
2105  *      ::WIMLIB_ERR_UNSUPPORTED will be returned if the WIM image contains one
2106  *      or more files with short names, but extracting short names is not
2107  *      supported --- on Windows, this occurs if the target volume does not
2108  *      support short names, while on non-Windows, this occurs if
2109  *      ::WIMLIB_EXTRACT_FLAG_NTFS was not specified in @p extract_flags.
2110  * @retval ::WIMLIB_ERR_WRITE
2111  *      Failed to write data to a file being extracted.
2112  *
2113  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2114  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2115  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2116  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2117  * different reasons) to read the metadata resource for an image that needed to
2118  * be extracted.
2119  */
2120 extern int
2121 wimlib_extract_image(WIMStruct *wim, int image,
2122                      const wimlib_tchar *target,
2123                      int extract_flags,
2124                      wimlib_progress_func_t progress_func);
2125
2126 /**
2127  * Since wimlib v1.5.0:  Extract one or more images from a pipe on which a
2128  * pipable WIM is being sent.
2129  *
2130  * See the documentation for ::WIMLIB_WRITE_FLAG_PIPABLE for more information
2131  * about pipable WIMs.
2132  *
2133  * This function operates in a special way to read the WIM fully sequentially.
2134  * As a result, there is no ::WIMStruct is made visible to library users, and
2135  * you cannot call wimlib_open_wim() on the pipe.  (You can, however, use
2136  * wimlib_open_wim() to transparently open a pipable WIM if it's available as a
2137  * seekable file, not a pipe.)
2138  *
2139  * @param pipe_fd
2140  *      File descriptor, which may be a pipe, opened for reading and positioned
2141  *      at the start of the pipable WIM.
2142  * @param image_num_or_name
2143  *      String that specifies the 1-based index or name of the image to extract.
2144  *      It is translated to an image index using the same rules that
2145  *      wimlib_resolve_image() uses.  However, unlike wimlib_extract_image(),
2146  *      only a single image (not all images) can be specified.  Alternatively,
2147  *      specify @p NULL here to use the first image in the WIM if it contains
2148  *      exactly one image but otherwise return ::WIMLIB_ERR_INVALID_IMAGE.
2149  * @param target
2150  *      Same as the corresponding parameter to wimlib_extract_image().
2151  * @param extract_flags
2152  *      Same as the corresponding parameter to wimlib_extract_image(), except
2153  *      for the following exceptions:  ::WIMLIB_EXTRACT_FLAG_SEQUENTIAL is
2154  *      always implied, since data is always read from @p pipe_fd sequentially
2155  *      in this mode; also, ::WIMLIB_EXTRACT_FLAG_TO_STDOUT is invalid and will
2156  *      result in ::WIMLIB_ERR_INVALID_PARAM being returned.
2157  * @param progress_func
2158  *      Same as the corresponding parameter to wimlib_extract_image(), except
2159  *      ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN messages will also be
2160  *      received.
2161  *
2162  * @return 0 on success; nonzero on error.  The possible error codes include
2163  * those returned by wimlib_extract_image() as well as the following:
2164  *
2165  * @retval ::WIMLIB_ERR_INVALID_PIPABLE_WIM
2166  *      Data read from the pipable WIM was invalid.
2167  * @retval ::WIMLIB_ERR_NOT_PIPABLE
2168  *      The WIM being piped in a @p pipe_fd is a normal WIM, not a pipable WIM.
2169  */
2170 extern int
2171 wimlib_extract_image_from_pipe(int pipe_fd,
2172                                const wimlib_tchar *image_num_or_name,
2173                                const wimlib_tchar *target, int extract_flags,
2174                                wimlib_progress_func_t progress_func);
2175
2176 /**
2177  * Extracts the XML data of a WIM file to a file stream.  Every WIM file
2178  * includes a string of XML that describes the images contained in the WIM.
2179  *
2180  * @param wim
2181  *      Pointer to the ::WIMStruct for a WIM file, which does not necessarily
2182  *      have to be standalone (e.g. it could be part of a split WIM).
2183  * @param fp
2184  *      @c stdout, or a FILE* opened for writing, to extract the data to.
2185  *
2186  * @return 0 on success; nonzero on error.
2187  * @retval ::WIMLIB_ERR_INVALID_PARAM
2188  *      @p wim is not a ::WIMStruct that was created by wimlib_open_wim().
2189  * @retval ::WIMLIB_ERR_NOMEM
2190  * @retval ::WIMLIB_ERR_READ
2191  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
2192  *      Failed to read the XML data from the WIM.
2193  * @retval ::WIMLIB_ERR_WRITE
2194  *      Failed to completely write the XML data to @p fp.
2195  */
2196 extern int
2197 wimlib_extract_xml_data(WIMStruct *wim, FILE *fp);
2198
2199 /**
2200  * Frees all memory allocated for a WIMStruct and closes all files associated
2201  * with it.
2202  *
2203  * @param wim
2204  *      Pointer to the ::WIMStruct for a WIM file.
2205  *
2206  * @return This function has no return value.
2207  */
2208 extern void
2209 wimlib_free(WIMStruct *wim);
2210
2211 /**
2212  * Converts a ::wimlib_compression_type value into a string.
2213  *
2214  * @param ctype
2215  *      ::WIMLIB_COMPRESSION_TYPE_NONE, ::WIMLIB_COMPRESSION_TYPE_LZX,
2216  *      ::WIMLIB_COMPRESSION_TYPE_XPRESS, or another value.
2217  *
2218  * @return
2219  *      A statically allocated string: "None", "LZX", "XPRESS", or "Invalid",
2220  *      respectively.
2221  */
2222 extern const wimlib_tchar *
2223 wimlib_get_compression_type_string(int ctype);
2224
2225 /**
2226  * Converts an error code into a string describing it.
2227  *
2228  * @param code
2229  *      The error code returned by one of wimlib's functions.
2230  *
2231  * @return
2232  *      Pointer to a statically allocated string describing the error code,
2233  *      or @c NULL if the error code is not valid.
2234  */
2235 extern const wimlib_tchar *
2236 wimlib_get_error_string(enum wimlib_error_code code);
2237
2238 /**
2239  * Returns the description of the specified image.
2240  *
2241  * @param wim
2242  *      Pointer to the ::WIMStruct for a WIM file that does not necessarily have
2243  *      to be standalone (e.g. it could be part of a split WIM).
2244  * @param image
2245  *      The number of the image, numbered starting at 1.
2246  *
2247  * @return
2248  *      The description of the image, or @c NULL if there is no such image, or
2249  *      @c NULL if the specified image has no description.  The description
2250  *      string is in library-internal memory and may not be modified or freed;
2251  *      in addition, the string will become invalid if the description of the
2252  *      image is changed, the image is deleted, or the ::WIMStruct is destroyed.
2253  */
2254 extern const wimlib_tchar *
2255 wimlib_get_image_description(const WIMStruct *wim, int image);
2256
2257 /**
2258  * Returns the name of the specified image.
2259  *
2260  * @param wim
2261  *      Pointer to the ::WIMStruct for a WIM file that does not necessarily have
2262  *      to be standalone (e.g. it could be part of a split WIM).
2263  * @param image
2264  *      The number of the image, numbered starting at 1.
2265  *
2266  * @return
2267  *      The name of the image, or @c NULL if there is no such image, or an empty
2268  *      string if the image is unnamed.  The name string is in
2269  *      library-internal memory and may not be modified or freed; in addition,
2270  *      the string will become invalid if the name of the image is changed, the
2271  *      image is deleted, or the ::WIMStruct is destroyed.
2272  */
2273 extern const wimlib_tchar *
2274 wimlib_get_image_name(const WIMStruct *wim, int image);
2275
2276
2277 /**
2278  * Get basic information about a WIM file.
2279  *
2280  * @param wim
2281  *      Pointer to the ::WIMStruct for a WIM file that does not necessarily have
2282  *      to be standalone (e.g. it could be part of a split WIM).
2283  * @param info
2284  *      A ::wimlib_wim_info structure that will be filled in with information
2285  *      about the WIM file.
2286  * @return
2287  *      0
2288  */
2289 extern int
2290 wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info);
2291
2292 /**
2293  * Initialization function for wimlib.  Call before using any other wimlib
2294  * function except wimlib_set_print_errors().  If not done manually, this
2295  * function will be called automatically with @p init_flags set to
2296  * ::WIMLIB_INIT_FLAG_ASSUME_UTF8.
2297  *
2298  * @param init_flags
2299  *      Bitwise OR of flags prefixed with WIMLIB_INIT_FLAG.
2300  *
2301  * @return 0 on success; nonzero on failure.  Currently, only the following
2302  * error code is defined:
2303  *
2304  * @retval ::WIMLIB_ERR_INSUFFICIENT_PRIVILEGES
2305  *      ::WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES and/or
2306  *      ::WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES were specified in @p
2307  *      init_flags, but the corresponding privileges could not be acquired.
2308  */
2309 extern int
2310 wimlib_global_init(int init_flags);
2311
2312 /**
2313  * Cleanup function for wimlib.  You are not required to call this function, but
2314  * it will release any global resources allocated by the library.
2315  */
2316 extern void
2317 wimlib_global_cleanup(void);
2318
2319 /**
2320  * Determines if an image name is already used by some image in the WIM.
2321  *
2322  * @param wim
2323  *      Pointer to the ::WIMStruct for a WIM file.
2324  * @param name
2325  *      The name to check.
2326  *
2327  * @return
2328  *      @c true if there is already an image in @p wim named @p name; @c false
2329  *      if there is no image named @p name in @p wim.  If @p name is @c NULL or
2330  *      the empty string, @c false is returned.
2331  */
2332 extern bool
2333 wimlib_image_name_in_use(const WIMStruct *wim, const wimlib_tchar *name);
2334
2335 /**
2336  * Iterate through a file or directory tree in the WIM image.  By specifying
2337  * appropriate flags and a callback function, you can get the attributes of a
2338  * file in the WIM, get a directory listing, or even get a listing of the entire
2339  * WIM image.
2340  *
2341  * @param wim
2342  *      The WIM containing the image(s) over which to iterate, specified as a
2343  *      pointer to the ::WIMStruct for a standalone WIM file, a delta WIM file,
2344  *      or part 1 of a split WIM.  In the case of a WIM file that is not
2345  *      standalone, this ::WIMStruct must have had any needed external resources
2346  *      previously referenced using wimlib_reference_resources() or
2347  *      wimlib_reference_resource_files().
2348  *
2349  * @param image
2350  *      The 1-based number of the image in @p wim that contains the files or
2351  *      directories to iterate over, or ::WIMLIB_ALL_IMAGES to repeat the same
2352  *      iteration on all images in the WIM.
2353  *
2354  * @param path
2355  *      Path in the WIM image at which to do the iteration.
2356  *
2357  * @param flags
2358  *      Bitwise OR of ::WIMLIB_ITERATE_DIR_TREE_FLAG_RECURSIVE and/or
2359  *      ::WIMLIB_ITERATE_DIR_TREE_FLAG_CHILDREN.
2360  *
2361  * @param cb
2362  *      A callback function that will receive each directory entry.
2363  *
2364  * @param user_ctx
2365  *      An extra parameter that will always be passed to the callback function
2366  *      @p cb.
2367  *
2368  * @return Normally, returns 0 if all calls to @p cb returned 0; otherwise the
2369  * first nonzero value that was returned from @p cb.  However, additional error
2370  * codes may be returned, including the following:
2371  *
2372  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
2373  *      @p path did not exist in the WIM image.
2374  * @retval ::WIMLIB_ERR_NOMEM
2375  *      Failed to allocate memory needed to create a ::wimlib_dir_entry.
2376  *
2377  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2378  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2379  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2380  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2381  * different reasons) to read the metadata resource for an image over which
2382  * iteration needed to be done.
2383  */
2384 extern int
2385 wimlib_iterate_dir_tree(WIMStruct *wim, int image, const wimlib_tchar *path,
2386                         int flags,
2387                         wimlib_iterate_dir_tree_callback_t cb, void *user_ctx);
2388
2389 /**
2390  * Iterate through the lookup table of a WIM file.  This can be used to directly
2391  * get a listing of the unique resources contained in a WIM file over all
2392  * images.  Both file resources and metadata resources are included.  However,
2393  * only resources actually included in the file represented by @a wim, plus
2394  * explicitly referenced external resources (via wimlib_reference_resources() or
2395  * wimlib_reference_resource_files()) are included in the iteration.  For
2396  * example, if @p wim represents just one part of a split WIM, then only
2397  * resources in that part will be included, unless other resources were
2398  * explicitly referenced.
2399  *
2400  * @param wim
2401  *      Pointer to the ::WIMStruct for a WIM file that does not necessarily have
2402  *      to be standalone (e.g. it could be part of a split WIM).
2403  *
2404  * @param flags
2405  *      Reserved; set to 0.
2406  *
2407  * @param cb
2408  *      A callback function that will receive each resource.
2409  *
2410  * @param user_ctx
2411  *      An extra parameter that will always be passed to the callback function
2412  *      @p cb.
2413  *
2414  * @return 0 if all calls to @p cb returned 0; otherwise the first nonzero value
2415  * that was returned from @p cb.
2416  */
2417 extern int
2418 wimlib_iterate_lookup_table(WIMStruct *wim, int flags,
2419                             wimlib_iterate_lookup_table_callback_t cb,
2420                             void *user_ctx);
2421
2422 /**
2423  * Joins a split WIM into a stand-alone one-part WIM.
2424  *
2425  * @param swms
2426  *      An array of strings that gives the filenames of all parts of the split
2427  *      WIM.  No specific order is required, but all parts must be included with
2428  *      no duplicates.
2429  * @param num_swms
2430  *      Number of filenames in @p swms.
2431  * @param swm_open_flags
2432  *      Open flags for the split WIM parts (e.g.
2433  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY).
2434  * @param wim_write_flags
2435  *      Bitwise OR of relevant flags prefixed with WIMLIB_WRITE_FLAG, which will
2436  *      be used to write the joined WIM.
2437  * @param output_path
2438  *      The path to write the joined WIM file to.
2439  * @param progress_func
2440  *      If non-NULL, a function that will be called periodically with the
2441  *      progress of the current operation.
2442  *
2443  * @return 0 on success; nonzero on error.  This function may return most error
2444  * codes that can be returned by wimlib_open_wim() and wimlib_write(), as well
2445  * as the following error code:
2446  *
2447  * @retval ::WIMLIB_ERR_SPLIT_INVALID
2448  *      The split WIMs do not form a valid WIM because they do not include all
2449  *      the parts of the original WIM, there are duplicate parts, or not all the
2450  *      parts have the same GUID and compression type.
2451  *
2452  * Note: wimlib is generalized enough that this function is not actually needed
2453  * to join a split WIM; instead, you could open the first part of the split WIM,
2454  * then reference the other parts with wimlib_reference_resource_files(), then
2455  * write the joined WIM using wimlib_write().  However, wimlib_join() provides
2456  * an easy-to-use wrapper around this that has some advantages (e.g.  extra
2457  * sanity checks).
2458  */
2459 extern int
2460 wimlib_join(const wimlib_tchar * const *swms,
2461             unsigned num_swms,
2462             const wimlib_tchar *output_path,
2463             int swm_open_flags,
2464             int wim_write_flags,
2465             wimlib_progress_func_t progress_func);
2466
2467 /**
2468  * Compress a chunk of a WIM resource using LZX compression.
2469  *
2470  * This function is exported for convenience only and should only be used by
2471  * library clients looking to make use of wimlib's compression code for another
2472  * purpose.
2473  *
2474  * @param chunk
2475  *      Uncompressed data of the chunk.
2476  * @param chunk_size
2477  *      Size of the uncompressed chunk, in bytes.
2478  * @param out
2479  *      Pointer to output buffer of size at least (@p chunk_size - 1) bytes.
2480  *
2481  * @return
2482  *      The size of the compressed data written to @p out in bytes, or 0 if the
2483  *      data could not be compressed to (@p chunk_size - 1) bytes or fewer.
2484  *
2485  * As a special requirement, the compression code is optimized for the WIM
2486  * format and therefore requires (@p chunk_size <= 32768).
2487  */
2488 extern unsigned
2489 wimlib_lzx_compress(const void *chunk, unsigned chunk_size, void *out);
2490
2491 /**
2492  * Decompresses a block of LZX-compressed data as used in the WIM file format.
2493  *
2494  * Note that this will NOT work unmodified for LZX as used in the cabinet
2495  * format, which is not the same as in the WIM format!
2496  *
2497  * This function is exported for convenience only and should only be used by
2498  * library clients looking to make use of wimlib's compression code for another
2499  * purpose.
2500  *
2501  * @param compressed_data
2502  *      Pointer to the compressed data.
2503  *
2504  * @param compressed_len
2505  *      Length of the compressed data, in bytes.
2506  *
2507  * @param uncompressed_data
2508  *      Pointer to the buffer into which to write the uncompressed data.
2509  *
2510  * @param uncompressed_len
2511  *      Length of the uncompressed data.  It must be 32768 bytes or less.
2512  *
2513  * @return
2514  *      0 on success; non-zero on failure.
2515  */
2516 extern int
2517 wimlib_lzx_decompress(const void *compressed_data, unsigned compressed_len,
2518                       void *uncompressed_data, unsigned uncompressed_len);
2519
2520
2521 /**
2522  * Mounts an image in a WIM file on a directory read-only or read-write.
2523  *
2524  * As this is implemented using FUSE (Filesystme in UserSpacE), this is not
2525  * supported if wimlib was configured with @c --without-fuse.  This includes
2526  * Windows builds of wimlib; ::WIMLIB_ERR_UNSUPPORTED will be returned in such
2527  * cases.
2528  *
2529  * Calling this function daemonizes the process, unless
2530  * ::WIMLIB_MOUNT_FLAG_DEBUG was specified or an early occur occurs.  If the
2531  * mount is read-write (::WIMLIB_MOUNT_FLAG_READWRITE specified), modifications
2532  * to the WIM are staged in a temporary directory.
2533  *
2534  * It is safe to mount multiple images from the same underlying WIM file
2535  * read-only at the same time, but only if different ::WIMStruct's are used.  It
2536  * is @b not safe to mount multiple images from the same WIM file read-write at
2537  * the same time.
2538  *
2539  * wimlib_mount_image() cannot be used on an image that was exported with
2540  * wimlib_export_image() while the dentry trees for both images are still in
2541  * memory.  In addition, wimlib_mount_image() may not be used to mount an image
2542  * that already has modifications pending (e.g. an image added with
2543  * wimlib_add_image()).
2544  *
2545  * @param wim
2546  *      Pointer to the ::WIMStruct containing the image to be mounted.
2547  * @param image
2548  *      The number of the image to mount, indexed starting from it.  It must be
2549  *      an existing, single image.
2550  * @param dir
2551  *      The path to an existing empty directory to mount the image on.
2552  * @param mount_flags
2553  *      Bitwise OR of the flags prefixed with WIMLIB_MOUNT_FLAG.
2554  * @param staging_dir
2555  *      If non-NULL, the name of a directory in which the staging directory will
2556  *      be created.  Ignored if ::WIMLIB_MOUNT_FLAG_READWRITE is not specified
2557  *      in @p mount_flags.  If left @c NULL, the staging directory is created in
2558  *      the same directory as the WIM file that @p wim was originally read from.
2559  *
2560  * @return 0 on success; nonzero on error.
2561  *
2562  * @retval ::WIMLIB_ERR_ALREADY_LOCKED
2563  *      A read-write mount was requested, but an an exclusive advisory lock on
2564  *      the on-disk WIM file could not be acquired because another thread or
2565  *      process has mounted an image from the WIM read-write or is currently
2566  *      modifying the WIM in-place.
2567  * @retval ::WIMLIB_ERR_FUSE
2568  *      A non-zero status was returned by @c fuse_main().
2569  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2570  *      @p image does not specify an existing, single image in @p wim.
2571  * @retval ::WIMLIB_ERR_INVALID_PARAM
2572  *      @p image is shared among multiple ::WIMStruct's as a result of a call to
2573  *      wimlib_export_image(), or @p image has been added with
2574  *      wimlib_add_image().
2575  * @retval ::WIMLIB_ERR_MKDIR
2576  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @p mount_flags, but the
2577  *      staging directory could not be created.
2578  * @retval ::WIMLIB_ERR_NOTDIR
2579  *      Could not determine the current working directory.
2580  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
2581  *      One of the dentries in the image referenced a stream not present in the
2582  *      WIM's lookup table (or in any of the lookup tables of the split WIM
2583  *      parts).
2584  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
2585  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @p mount_flags, but @p
2586  *      wim is considered read-only because of any of the reasons mentioned in
2587  *      the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
2588  * @retval ::WIMLIB_ERR_UNSUPPORTED
2589  *      Mounting is not supported, either because the platform is Windows, or
2590  *      because the platform is UNIX-like and wimlib was compiled with @c
2591  *      --without-fuse.
2592  *
2593  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2594  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2595  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2596  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2597  * different reasons) to read the metadata resource for the image to mount.
2598  */
2599 extern int
2600 wimlib_mount_image(WIMStruct *wim,
2601                    int image,
2602                    const wimlib_tchar *dir,
2603                    int mount_flags,
2604                    const wimlib_tchar *staging_dir);
2605
2606 /**
2607  * Opens a WIM file and creates a ::WIMStruct for it.
2608  *
2609  * @param wim_file
2610  *      The path to the WIM file to open.
2611  *
2612  * @param open_flags
2613  *      Bitwise OR of flags prefixed with WIMLIB_OPEN_FLAG.
2614  *
2615  * @param progress_func
2616  *      If non-NULL, a function that will be called periodically with the
2617  *      progress of the current operation.  Currently, the only messages sent
2618  *      will be ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY, and only if
2619  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @p open_flags.
2620  *
2621  * @param wim_ret
2622  *      On success, a pointer to an opaque ::WIMStruct for the opened WIM file
2623  *      is written to the memory location pointed to by this parameter.  The
2624  *      ::WIMStruct can be freed using using wimlib_free() when finished with
2625  *      it.
2626  *
2627  * @return 0 on success; nonzero on error.
2628  * @retval ::WIMLIB_ERR_IMAGE_COUNT
2629  *      The WIM is not the non-first part of a split WIM, and the number of
2630  *      metadata resources found in the WIM did not match the image count given
2631  *      in the WIM header, or the number of &lt;IMAGE&gt; elements in the XML
2632  *      data for the WIM did not match the image count given in the WIM header.
2633  * @retval ::WIMLIB_ERR_INTEGRITY
2634  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @p open_flags and @p
2635  *      wim_file contains an integrity table, but the SHA1 message digest for a
2636  *      chunk of the WIM does not match the corresponding message digest given
2637  *      in the integrity table.
2638  * @retval ::WIMLIB_ERR_INVALID_CHUNK_SIZE
2639  *      Resources in @p wim_file are compressed, but the chunk size is not 32768.
2640  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
2641  *      The header of @p wim_file says that resources in the WIM are compressed,
2642  *      but the header flag indicating LZX or XPRESS compression is not set.
2643  * @retval ::WIMLIB_ERR_INVALID_HEADER
2644  *      The header of @p wim_file was otherwise invalid.
2645  * @retval ::WIMLIB_ERR_INVALID_INTEGRITY_TABLE
2646  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @p open_flags and @p
2647  *      wim_file contains an integrity table, but the integrity table is
2648  *      invalid.
2649  * @retval ::WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY
2650  *      The lookup table for the WIM contained duplicate entries that are not
2651  *      for metadata resources, or it contained an entry with a SHA1 message
2652  *      digest of all 0's.
2653  * @retval ::WIMLIB_ERR_INVALID_PARAM
2654  *      @p wim_ret was @c NULL.
2655  * @retval ::WIMLIB_ERR_IS_SPLIT_WIM
2656  *      @p wim_file is a split WIM and ::WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT was
2657  *      specified in @p open_flags.
2658  * @retval ::WIMLIB_ERR_NOMEM
2659  *      Failed to allocated needed memory.
2660  * @retval ::WIMLIB_ERR_NOT_A_WIM_FILE
2661  *      @p wim_file does not begin with the expected magic characters.
2662  * @retval ::WIMLIB_ERR_OPEN
2663  *      Failed to open the file @p wim_file for reading.
2664  * @retval ::WIMLIB_ERR_READ
2665  *      Failed to read data from @p wim_file.
2666  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
2667  *      Unexpected end-of-file while reading data from @p wim_file.
2668  * @retval ::WIMLIB_ERR_UNKNOWN_VERSION
2669  *      A number other than 0x10d00 is written in the version field of the WIM
2670  *      header of @p wim_file.  (May be a pre-Vista WIM.)
2671  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
2672  *      ::WIMLIB_OPEN_FLAG_WRITE_ACCESS was specified but the WIM file was
2673  *      considered read-only because of any of the reasons mentioned in the
2674  *      documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
2675  * @retval ::WIMLIB_ERR_XML
2676  *      The XML data for @p wim_file is invalid.
2677  */
2678 extern int
2679 wimlib_open_wim(const wimlib_tchar *wim_file,
2680                 int open_flags,
2681                 WIMStruct **wim_ret,
2682                 wimlib_progress_func_t progress_func);
2683
2684 /**
2685  * Overwrites the file that the WIM was originally read from, with changes made.
2686  * This only makes sense for ::WIMStruct's obtained from wimlib_open_wim()
2687  * rather than wimlib_create_new_wim().
2688  *
2689  * There are two ways that a WIM may be overwritten.  The first is to do a full
2690  * rebuild.  In this mode, the new WIM is written to a temporary file and then
2691  * renamed to the original file after it is has been completely written.  The
2692  * temporary file is made in the same directory as the original WIM file.  A
2693  * full rebuild may take a while, but can be used even if images have been
2694  * modified or deleted, will produce a WIM with no holes, and has little chance
2695  * of unintentional data loss because the temporary WIM is fsync()ed before
2696  * being renamed to the original WIM.
2697  *
2698  * The second way to overwrite a WIM is by appending to the end of it and
2699  * overwriting the header.  This can be much faster than a full rebuild, but the
2700  * disadvantage is that some space will be wasted.  Writing a WIM in this mode
2701  * begins with writing any new file resources *after* everything in the old WIM,
2702  * even though this will leave a hole where the old lookup table, XML data, and
2703  * integrity were.  This is done so that the WIM remains valid even if the
2704  * operation is aborted mid-write.  The WIM header is only overwritten at the
2705  * very last moment, and up until that point the WIM will be seen as the old
2706  * version.
2707  *
2708  * By default, wimlib_overwrite() does the append-style overwrite described
2709  * above, unless resources in the WIM are arranged in an unusual way or if
2710  * images have been deleted from the WIM.  Use the flag
2711  * ::WIMLIB_WRITE_FLAG_REBUILD to explicitly request a full rebuild, and use the
2712  * ::WIMLIB_WRITE_FLAG_SOFT_DELETE to request the in-place overwrite even if
2713  * images have been deleted from the WIM.
2714  *
2715  * In the temporary-file overwrite mode, no changes are made to the WIM on
2716  * failure, and the temporary file is deleted if possible.  Abnormal termination
2717  * of the program will result in the temporary file being orphaned.  In the
2718  * direct append mode, the WIM is truncated to the original length on failure;
2719  * and while abnormal termination of the program will result in extra data
2720  * appended to the original WIM, it should still be a valid WIM.
2721  *
2722  * If this function completes successfully, no more functions should be called
2723  * on @p wim other than wimlib_free().  You must use wimlib_open_wim() to read
2724  * the WIM file anew.
2725  *
2726  * @param wim
2727  *      Pointer to the ::WIMStruct for the WIM file to write.  There may have
2728  *      been in-memory changes made to it, which are then reflected in the
2729  *      output file.
2730  * @param write_flags
2731  *      Bitwise OR of relevant flags prefixed with WIMLIB_WRITE_FLAG.
2732  * @param num_threads
2733  *      Number of threads to use for compression (see wimlib_write()).
2734  * @param progress_func
2735  *      If non-NULL, a function that will be called periodically with the
2736  *      progress of the current operation.
2737  *
2738  * @return 0 on success; nonzero on error.  This function may return most error
2739  * codes returned by wimlib_write() as well as the following error codes:
2740  *
2741  * @retval ::WIMLIB_ERR_ALREADY_LOCKED
2742  *      The WIM was going to be modified in-place (with no temporary file), but
2743  *      an exclusive advisory lock on the on-disk WIM file could not be acquired
2744  *      because another thread or process has mounted an image from the WIM
2745  *      read-write or is currently modifying the WIM in-place.
2746  * @retval ::WIMLIB_ERR_NO_FILENAME
2747  *      @p wim corresponds to a WIM created with wimlib_create_new_wim() rather
2748  *      than a WIM read with wimlib_open_wim().
2749  * @retval ::WIMLIB_ERR_RENAME
2750  *      The temporary file that the WIM was written to could not be renamed to
2751  *      the original filename of @p wim.
2752  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
2753  *      The WIM file is considered read-only because of any of the reasons
2754  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
2755  *      flag.
2756  */
2757 extern int
2758 wimlib_overwrite(WIMStruct *wim, int write_flags, unsigned num_threads,
2759                  wimlib_progress_func_t progress_func);
2760
2761 /**
2762  * Prints information about one image, or all images, contained in a WIM.
2763  *
2764  * @param wim
2765  *      Pointer to the ::WIMStruct for a WIM file.
2766  * @param image
2767  *      The image about which to print information.  Can be the number of an
2768  *      image, or ::WIMLIB_ALL_IMAGES to print information about all images in the
2769  *      WIM.
2770  *
2771  * @return This function has no return value.  No error checking is done when
2772  * printing the information.  If @p image is invalid, an error message is
2773  * printed.
2774  */
2775 extern void
2776 wimlib_print_available_images(const WIMStruct *wim, int image);
2777
2778 /**
2779  * Deprecated in favor of wimlib_get_wim_info(), which provides the information
2780  * in a way that can be accessed programatically.
2781  */
2782 extern void
2783 wimlib_print_header(const WIMStruct *wim) _wimlib_deprecated;
2784
2785 /**
2786  * Deprecated in favor of wimlib_iterate_dir_tree(), which provides the
2787  * information in a way that can be accessed programatically.
2788  */
2789 extern int
2790 wimlib_print_metadata(WIMStruct *wim, int image) _wimlib_deprecated;
2791
2792 /**
2793  * Reference resources from other WIM files or split WIM parts.  This function
2794  * can be used on WIMs that are not standalone, such as split or "delta" WIMs,
2795  * to load needed resources (that is, "streams" keyed by SHA1 message digest)
2796  * from other files, before calling a function such as wimlib_extract_image()
2797  * that requires the resources to be present.
2798  *
2799  * @param wim
2800  *      The ::WIMStruct for a WIM that contains metadata resources, but is not
2801  *      necessarily "standalone".  In the case of split WIMs, this should be the
2802  *      first part, since only the first part contains the metadata resources.
2803  *      In the case of delta WIMs, this should be the delta WIM rather than the
2804  *      WIM on which it is based.
2805  * @param resource_wimfiles_or_globs
2806  *      Array of paths to WIM files and/or split WIM parts to reference.
2807  *      Alternatively, when ::WIMLIB_REF_FLAG_GLOB_ENABLE is specified in @p
2808  *      ref_flags, these are treated as globs rather than literal paths.  That
2809  *      is, using this function you can specify zero or more globs, each of
2810  *      which expands to one or more literal paths.
2811  * @param count
2812  *      Number of entries in @p resource_wimfiles_or_globs.
2813  * @param ref_flags
2814  *      Bitwise OR of ::WIMLIB_REF_FLAG_GLOB_ENABLE and/or
2815  *      ::WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH.
2816  * @param open_flags
2817  *      Additional open flags, such as ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY, to
2818  *      pass to internal calls to wimlib_open_wim() on the reference files.
2819  * @param progress_func
2820  *      Passed to internal calls to wimlib_open_wim() on the reference files.
2821  *
2822  * @return 0 on success; nonzero on error.
2823  *
2824  * @retval ::WIMLIB_ERR_GLOB_HAD_NO_MATCHES
2825  *      One of the specified globs did not match any paths (only with both
2826  *      ::WIMLIB_REF_FLAG_GLOB_ENABLE and ::WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH
2827  *      specified in @p ref_flags).
2828  * @retval ::WIMLIB_ERR_NOMEM
2829  *      Failed to allocate memory.
2830  * @retval ::WIMLIB_ERR_READ
2831  *      I/O or permissions error while processing a file glob.
2832  *
2833  * This function can additionally return most values that can be returned by
2834  * wimlib_open_wim().
2835  */
2836 extern int
2837 wimlib_reference_resource_files(WIMStruct *wim,
2838                                 const wimlib_tchar * const *resource_wimfiles_or_globs,
2839                                 unsigned count,
2840                                 int ref_flags,
2841                                 int open_flags,
2842                                 wimlib_progress_func_t progress_func);
2843
2844 /**
2845  * Similar to wimlib_reference_resource_files(), but operates at a lower level
2846  * where the caller must open the ::WIMStruct for each referenced file itself.
2847  *
2848  * @param wim
2849  *      The ::WIMStruct for a WIM that contains metadata resources, but is not
2850  *      necessarily "standalone".  In the case of split WIMs, this should be the
2851  *      first part, since only the first part contains the metadata resources.
2852  * @param resource_wims
2853  *      Array of pointers to the ::WIMStruct's for additional resource WIMs or
2854  *      split WIM parts to reference.
2855  * @param num_resource_wims
2856  *      Number of entries in @p resource_wims.
2857  * @param ref_flags
2858  *      Currently ignored (set to 0).
2859  *
2860  * @return 0 on success; nonzero on error.  On success, the ::WIMStruct's of the
2861  * @p resource_wims are referenced internally by @p wim and must not be freed
2862  * with wimlib_free() or overwritten with wimlib_overwrite() until @p wim has
2863  * been freed with wimlib_free(), or immediately before freeing @p wim with
2864  * wimlib_free().
2865  *
2866  * @retval ::WIMLIB_ERR_INVALID_PARAM
2867  *      @p wim was @c NULL, or @p num_resource_wims was nonzero but @p
2868  *      resource_wims was @c NULL, or an entry in @p resource_wims was @p NULL.
2869  * @retval ::WIMLIB_ERR_NOMEM
2870  *      Failed to allocate memory.
2871  */
2872 extern int
2873 wimlib_reference_resources(WIMStruct *wim, WIMStruct **resource_wims,
2874                            unsigned num_resource_wims, int ref_flags);
2875
2876 /**
2877  * Declares that a newly added image is mostly the same as a prior image, but
2878  * captured at a later point in time, possibly with some modifications in the
2879  * intervening time.  This is designed to be used in incremental backups of the
2880  * same filesystem or directory tree.
2881  *
2882  * This function compares the metadata of the directory tree of the newly added
2883  * image against that of the old image.  Any files that are present in both the
2884  * newly added image and the old image and have timestamps that indicate they
2885  * haven't been modified are deemed not to have been modified and have their
2886  * SHA1 message digest copied from the old image.  Because of this and because
2887  * WIM uses single-instance streams, such files need not be read from the
2888  * filesystem when the WIM is being written or overwritten.  Note that these
2889  * unchanged files will still be "archived" and will be logically present in the
2890  * new image; the optimization is that they don't need to actually be read from
2891  * the filesystem because the WIM already contains them.
2892  *
2893  * This function is provided to optimize incremental backups.  The resulting WIM
2894  * file will still be the same regardless of whether this function is called.
2895  * (This is, however, assuming that timestamps have not been manipulated or
2896  * unmaintained as to trick this function into thinking a file has not been
2897  * modified when really it has.  To partly guard against such cases, other
2898  * metadata such as file sizes will be checked as well.)
2899  *
2900  * This function must be called after adding the new image (e.g. with
2901  * wimlib_add_image()), but before writing the updated WIM file (e.g. with
2902  * wimlib_overwrite()).
2903  *
2904  * @param wim
2905  *      Pointer to the ::WIMStruct for a WIM.
2906  * @param new_image
2907  *      1-based index in the WIM of the newly added image.  This image can have
2908  *      been added with wimlib_add_image() or wimlib_add_image_multisource(), or
2909  *      wimlib_add_empty_image() followed by wimlib_update_image().
2910  * @param template_wim
2911  *      The ::WIMStruct for the WIM containing the template image.  This can be
2912  *      the same as @p wim, or it can be a different ::WIMStruct.
2913  * @param template_image
2914  *      1-based index in the WIM of a template image that reflects a prior state
2915  *      of the directory tree being captured.
2916  * @param flags
2917  *      Reserved; must be 0.
2918  * @param progress_func
2919  *      Currently ignored, but reserved for a function that will be called with
2920  *      information about the operation.  Use NULL if no additional information
2921  *      is desired.
2922  *
2923  * @return 0 on success; nonzero on error.
2924  *
2925  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2926  *      @p new_image and/or @p template_image were not a valid image indices in
2927  *      the WIM.
2928  * @retval ::WIMLIB_ERR_METADATA_NOT_FOUND
2929  *      The specified ::WIMStruct did not actually contain the metadata resource
2930  *      for the new or template image; for example, it was a non-first part of a
2931  *      split WIM.
2932  * @retval ::WIMLIB_ERR_NOMEM
2933  *      Failed to allocate needed memory.
2934  * @retval ::WIMLIB_ERR_INVALID_PARAM
2935  *      @p new_image was equal to @p template_image, or @p new_image specified
2936  *      an image that had not been modified since opening the WIM.
2937  *
2938  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2939  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2940  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2941  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2942  * different reasons) to read the metadata resource for the template image.
2943  */
2944 extern int
2945 wimlib_reference_template_image(WIMStruct *wim, int new_image,
2946                                 WIMStruct *template_wim, int template_image,
2947                                 int flags, wimlib_progress_func_t progress_func);
2948
2949 /**
2950  * Translates a string specifying the name or number of an image in the WIM into
2951  * the number of the image.  The images are numbered starting at 1.
2952  *
2953  * @param wim
2954  *      Pointer to the ::WIMStruct for a WIM.
2955  * @param image_name_or_num
2956  *      A string specifying the name or number of an image in the WIM.  If it
2957  *      parses to a positive integer, this integer is taken to specify the
2958  *      number of the image, indexed starting at 1.  Otherwise, it is taken to
2959  *      be the name of an image, as given in the XML data for the WIM file.  It
2960  *      also may be the keyword "all" or the string "*", both of which will
2961  *      resolve to ::WIMLIB_ALL_IMAGES.
2962  *      <br/> <br/>
2963  *      There is no way to search for an image actually named "all", "*", or an
2964  *      integer number, or an image that has no name.  However, you can use
2965  *      wimlib_get_image_name() to get the name of any image.
2966  *
2967  * @return
2968  *      If the string resolved to a single existing image, the number of that
2969  *      image, indexed starting at 1, is returned.  If the keyword "all" or "*"
2970  *      was specified, ::WIMLIB_ALL_IMAGES is returned.  Otherwise,
2971  *      ::WIMLIB_NO_IMAGE is returned.  If @p image_name_or_num was @c NULL or
2972  *      the empty string, ::WIMLIB_NO_IMAGE is returned, even if one or more
2973  *      images in @p wim has no name.
2974  */
2975 extern int
2976 wimlib_resolve_image(WIMStruct *wim,
2977                      const wimlib_tchar *image_name_or_num);
2978
2979 /**
2980  * Changes the description of an image in the WIM.
2981  *
2982  * @param wim
2983  *      Pointer to the ::WIMStruct for a WIM.
2984  * @param image
2985  *      The number of the image for which to change the description.
2986  * @param description
2987  *      The new description to give the image.  It may be @c NULL, which
2988  *      indicates that the image is to be given no description.
2989  *
2990  * @return 0 on success; nonzero on error.
2991  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2992  *      @p image does not specify a single existing image in @p wim.
2993  * @retval ::WIMLIB_ERR_NOMEM
2994  *      Failed to allocate the memory needed to duplicate the @p description
2995  *      string.
2996  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
2997  *      @p wim is considered read-only because of any of the reasons mentioned
2998  *      in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
2999  */
3000 extern int
3001 wimlib_set_image_descripton(WIMStruct *wim, int image,
3002                             const wimlib_tchar *description);
3003
3004 /**
3005  * Set basic information about a WIM.
3006  *
3007  * @param wim
3008  *      Pointer to the ::WIMStruct for a WIM.
3009  * @param info
3010  *      A struct ::wimlib_wim_info that contains the information to set.  Only
3011  *      the information explicitly specified in the @p which flags need be
3012  *      valid.
3013  * @param which
3014  *      Flags that specify which information to set.  This is a bitwise OR of
3015  *      ::WIMLIB_CHANGE_READONLY_FLAG, ::WIMLIB_CHANGE_GUID,
3016  *      ::WIMLIB_CHANGE_BOOT_INDEX, and/or ::WIMLIB_CHANGE_RPFIX_FLAG.
3017  *
3018  * @return 0 on success; nonzero on failure.
3019  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3020  *      The WIM file is considered read-only because of any of the reasons
3021  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
3022  *      flag.  However, as a special case, if you are using
3023  *      ::WIMLIB_CHANGE_READONLY_FLAG to unset the readonly flag, then this
3024  *      function will not fail due to the readonly flag being previously set.
3025  * @retval ::WIMLIB_ERR_IMAGE_COUNT
3026  *      ::WIMLIB_CHANGE_BOOT_INDEX was specified, but
3027  *      ::wimlib_wim_info.boot_index did not specify 0 or a valid 1-based image
3028  *      index in the WIM.
3029  */
3030 extern int
3031 wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info,
3032                     int which);
3033
3034 /**
3035  * Changes what is written in the \<FLAGS\> element in the WIM XML data
3036  * (something like "Core" or "Ultimate")
3037  *
3038  * @param wim
3039  *      Pointer to the ::WIMStruct for a WIM.
3040  * @param image
3041  *      The number of the image for which to change the description.
3042  * @param flags
3043  *      The new \<FLAGS\> element to give the image.  It may be @c NULL, which
3044  *      indicates that the image is to be given no \<FLAGS\> element.
3045  *
3046  * @return 0 on success; nonzero on error.
3047  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3048  *      @p image does not specify a single existing image in @p wim.
3049  * @retval ::WIMLIB_ERR_NOMEM
3050  *      Failed to allocate the memory needed to duplicate the @p flags string.
3051  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3052  *      @p wim is considered read-only because of any of the reasons mentioned
3053  *      in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
3054  */
3055 extern int
3056 wimlib_set_image_flags(WIMStruct *wim, int image, const wimlib_tchar *flags);
3057
3058 /**
3059  * Changes the name of an image in the WIM.
3060  *
3061  * @param wim
3062  *      Pointer to the ::WIMStruct for a WIM.
3063  * @param image
3064  *      The number of the image for which to change the name.
3065  * @param name
3066  *      New name to give the new image.  If @c NULL or empty, the new image is
3067  *      given no name.  If nonempty, it must specify a name that does not
3068  *      already exist in @p wim.
3069  *
3070  * @return 0 on success; nonzero on error.
3071  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
3072  *      There is already an image named @p name in @p wim.
3073  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3074  *      @p image does not specify a single existing image in @p wim.
3075  * @retval ::WIMLIB_ERR_NOMEM
3076  *      Failed to allocate the memory needed to duplicate the @p name string.
3077  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3078  *      @p wim is considered read-only because of any of the reasons mentioned
3079  *      in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
3080  */
3081 extern int
3082 wimlib_set_image_name(WIMStruct *wim, int image, const wimlib_tchar *name);
3083
3084 /**
3085  * Set the functions that wimlib uses to allocate and free memory.
3086  *
3087  * These settings are global and not per-WIM.
3088  *
3089  * The default is to use the default @c malloc() and @c free() from the C
3090  * library.
3091  *
3092  * Please note that some external functions, such as those in @c libntfs-3g, may
3093  * use the standard memory allocation functions.
3094  *
3095  * @param malloc_func
3096  *      A function equivalent to @c malloc() that wimlib will use to allocate
3097  *      memory.  If @c NULL, the allocator function is set back to the default
3098  *      @c malloc() from the C library.
3099  * @param free_func
3100  *      A function equivalent to @c free() that wimlib will use to free memory.
3101  *      If @c NULL, the free function is set back to the default @c free() from
3102  *      the C library.
3103  * @param realloc_func
3104  *      A function equivalent to @c realloc() that wimlib will use to reallocate
3105  *      memory.  If @c NULL, the free function is set back to the default @c
3106  *      realloc() from the C library.
3107  * @return 0 on success; nonzero on error.
3108  * @retval ::WIMLIB_ERR_UNSUPPORTED
3109  *      wimlib was compiled with the @c --without-custom-memory-allocator flag,
3110  *      so custom memory allocators are unsupported.
3111  */
3112 extern int
3113 wimlib_set_memory_allocator(void *(*malloc_func)(size_t),
3114                             void (*free_func)(void *),
3115                             void *(*realloc_func)(void *, size_t));
3116
3117 /**
3118  * Sets whether wimlib is to print error messages to @c stderr when a function
3119  * fails.  These error messages may provide information that cannot be
3120  * determined only from the error code that is returned.  Not every error will
3121  * result in an error message being printed.
3122  *
3123  * This setting is global and not per-WIM.
3124  *
3125  * By default, error messages are not printed.
3126  *
3127  * This can be called before wimlib_global_init().
3128  *
3129  * @param show_messages
3130  *      @c true if error messages are to be printed; @c false if error messages
3131  *      are not to be printed.
3132  *
3133  * @return 0 on success; nonzero on error.
3134  * @retval ::WIMLIB_ERR_UNSUPPORTED
3135  *      @p show_messages was @c true, but wimlib was compiled with the @c
3136  *      --without-error-messages option.   Therefore, error messages cannot be
3137  *      shown.
3138  */
3139 extern int
3140 wimlib_set_print_errors(bool show_messages);
3141
3142 /**
3143  * Splits a WIM into multiple parts.
3144  *
3145  * @param wim
3146  *      The ::WIMStruct for the WIM to split.
3147  * @param swm_name
3148  *      Name of the SWM file to create.  This will be the name of the first
3149  *      part.  The other parts will have the same name with 2, 3, 4, ..., etc.
3150  *      appended before the suffix.
3151  * @param part_size
3152  *      The maximum size per part, in bytes.  Unfortunately, it is not
3153  *      guaranteed that this will really be the maximum size per part, because
3154  *      some file resources in the WIM may be larger than this size, and the WIM
3155  *      file format provides no way to split up file resources among multiple
3156  *      WIMs.
3157  * @param write_flags
3158  *      Bitwise OR of relevant flags prefixed with @c WIMLIB_WRITE_FLAG.  These
3159  *      flags will be used to write each split WIM part.  Specify 0 here to get
3160  *      the default behavior.
3161  * @param progress_func
3162  *      If non-NULL, a function that will be called periodically with the
3163  *      progress of the current operation
3164  *      (::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART and
3165  *      ::WIMLIB_PROGRESS_MSG_SPLIT_END_PART).
3166  *
3167  * @return 0 on success; nonzero on error.  This function may return most error
3168  * codes that can be returned by wimlib_write() as well as the following error
3169  * codes:
3170  *
3171  * @retval ::WIMLIB_ERR_INVALID_PARAM
3172  *      @p swm_name was not a nonempty string, or @p part_size was 0.
3173  *
3174  * Note: the WIM's uncompressed and compressed resources are not checksummed
3175  * when they are copied from the joined WIM to the split WIM parts, nor are
3176  * compressed resources re-compressed (unless explicitly requested with
3177  * ::WIMLIB_WRITE_FLAG_RECOMPRESS).
3178  */
3179 extern int
3180 wimlib_split(WIMStruct *wim,
3181              const wimlib_tchar *swm_name,
3182              uint64_t part_size,
3183              int write_flags,
3184              wimlib_progress_func_t progress_func);
3185
3186 /**
3187  * Unmounts a WIM image that was mounted using wimlib_mount_image().
3188  *
3189  * The image to unmount is specified by the path to the mountpoint, not the
3190  * original ::WIMStruct passed to wimlib_mount_image(), which should not be
3191  * touched and also may have been allocated in a different process.
3192  *
3193  * To unmount the image, the process calling this function communicates with the
3194  * process that is managing the mounted WIM image.  This function blocks until it
3195  * is known whether the unmount succeeded or failed.  In the case of a
3196  * read-write mounted WIM, the unmount is not considered to have succeeded until
3197  * all changes have been saved to the underlying WIM file.
3198  *
3199  * @param dir
3200  *      The directory that the WIM image was mounted on.
3201  * @param unmount_flags
3202  *      Bitwise OR of the flags ::WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY,
3203  *      ::WIMLIB_UNMOUNT_FLAG_COMMIT, ::WIMLIB_UNMOUNT_FLAG_REBUILD, and/or
3204  *      ::WIMLIB_UNMOUNT_FLAG_RECOMPRESS.  None of these flags affect read-only
3205  *      mounts.
3206  * @param progress_func
3207  *      If non-NULL, a function that will be called periodically with the
3208  *      progress of the current operation.  Currently, only
3209  *      ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS will be sent.
3210  *
3211  * @return 0 on success; nonzero on error.
3212  *
3213  * @retval ::WIMLIB_ERR_DELETE_STAGING_DIR
3214  *      The filesystem daemon was unable to remove the staging directory and the
3215  *      temporary files that it contains.
3216  * @retval ::WIMLIB_ERR_FILESYSTEM_DAEMON_CRASHED
3217  *      The filesystem daemon appears to have terminated before sending an exit
3218  *      status.
3219  * @retval ::WIMLIB_ERR_FORK
3220  *      Could not @c fork() the process.
3221  * @retval ::WIMLIB_ERR_FUSERMOUNT
3222  *      The @b fusermount program could not be executed or exited with a failure
3223  *      status.
3224  * @retval ::WIMLIB_ERR_MQUEUE
3225  *      Could not open a POSIX message queue to communicate with the filesystem
3226  *      daemon servicing the mounted filesystem, could not send a message
3227  *      through the queue, or could not receive a message through the queue.
3228  * @retval ::WIMLIB_ERR_NOMEM
3229  *      Failed to allocate needed memory.
3230  * @retval ::WIMLIB_ERR_OPEN
3231  *      The filesystem daemon could not open a temporary file for writing the
3232  *      new WIM.
3233  * @retval ::WIMLIB_ERR_READ
3234  *      A read error occurred when the filesystem daemon tried to a file from
3235  *      the staging directory
3236  * @retval ::WIMLIB_ERR_RENAME
3237  *      The filesystem daemon failed to rename the newly written WIM file to the
3238  *      original WIM file.
3239  * @retval ::WIMLIB_ERR_UNSUPPORTED
3240  *      Mounting is not supported, either because the platform is Windows, or
3241  *      because the platform is UNIX-like and wimlib was compiled with @c
3242  *      --without-fuse.
3243  * @retval ::WIMLIB_ERR_WRITE
3244  *      A write error occurred when the filesystem daemon was writing to the new
3245  *      WIM file, or the filesystem daemon was unable to flush changes that had
3246  *      been made to files in the staging directory.
3247  */
3248 extern int
3249 wimlib_unmount_image(const wimlib_tchar *dir,
3250                      int unmount_flags,
3251                      wimlib_progress_func_t progress_func);
3252
3253 /**
3254  * Update a WIM image by adding, deleting, and/or renaming files or directories.
3255  *
3256  * @param wim
3257  *      Pointer to the ::WIMStruct for the WIM file to update.
3258  * @param image
3259  *      The 1-based index of the image in the WIM to update.  It cannot be
3260  *      ::WIMLIB_ALL_IMAGES.
3261  * @param cmds
3262  *      An array of ::wimlib_update_command's that specify the update operations
3263  *      to perform.
3264  * @param num_cmds
3265  *      Number of commands in @p cmds.
3266  * @param update_flags
3267  *      ::WIMLIB_UPDATE_FLAG_SEND_PROGRESS or 0.
3268  * @param progress_func
3269  *      If non-NULL, a function that will be called periodically with the
3270  *      progress of the current operation.
3271  *
3272  * @return 0 on success; nonzero on error.  On failure, some but not all of the
3273  * update commands may have been executed.  No individual update command will
3274  * have been partially executed.  Possible error codes include:
3275  *
3276  * @retval ::WIMLIB_ERR_INVALID_CAPTURE_CONFIG
3277  *      The capture configuration structure specified for an add command was
3278  *      invalid.
3279  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3280  *      @p image did not specify a single, existing image in @p wim.
3281  * @retval ::WIMLIB_ERR_INVALID_OVERLAY
3282  *      Attempted to perform an add command that conflicted with previously
3283  *      existing files in the WIM when an overlay was attempted.
3284  * @retval ::WIMLIB_ERR_INVALID_PARAM
3285  *      An unknown operation type was specified in the update commands; or,
3286  *      attempted to execute an add command where ::WIMLIB_ADD_FLAG_NTFS was set
3287  *      in the @p add_flags, but the same image had previously already been
3288  *      added from a NTFS volume; or, both ::WIMLIB_ADD_FLAG_RPFIX and
3289  *      ::WIMLIB_ADD_FLAG_NORPFIX were specified in the @p add_flags for one add
3290  *      command; or, ::WIMLIB_ADD_FLAG_NTFS or ::WIMLIB_ADD_FLAG_RPFIX were
3291  *      specified in the @p add_flags for an add command in which @p
3292  *      wim_target_path was not the root directory of the WIM image.
3293  * @retval ::WIMLIB_ERR_INVALID_REPARSE_DATA
3294  *      (Windows only):  While executing an add command, tried to capture a
3295  *      reparse point with invalid data.
3296  * @retval ::WIMLIB_ERR_IS_DIRECTORY
3297  *      A delete command without ::WIMLIB_DELETE_FLAG_RECURSIVE specified was
3298  *      for a WIM path that corresponded to a directory; or, a rename command
3299  *      attempted to rename a directory to a non-directory.
3300  * @retval ::WIMLIB_ERR_NOMEM
3301  *      Failed to allocate needed memory.
3302  * @retval ::WIMLIB_ERR_NOTDIR
3303  *      A rename command attempted to rename a directory to a non-directory; or,
3304  *      an add command was executed that attempted to set the root of the WIM
3305  *      image as a non-directory; or, a path component used as a directory in a
3306  *      rename command was not, in fact, a directory.
3307  * @retval ::WIMLIB_ERR_NOTEMPTY
3308  *      A rename command attempted to rename a directory to a non-empty
3309  *      directory.
3310  * @retval ::WIMLIB_ERR_NTFS_3G
3311  *      While executing an add command with ::WIMLIB_ADD_FLAG_NTFS specified, an
3312  *      error occurred while reading data from the NTFS volume using libntfs-3g.
3313  * @retval ::WIMLIB_ERR_OPEN
3314  *      Failed to open a file to be captured while executing an add command.
3315  * @retval ::WIMLIB_ERR_OPENDIR
3316  *      Failed to open a directory to be captured while executing an add command.
3317  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
3318  *      A delete command without ::WIMLIB_DELETE_FLAG_FORCE specified was for a
3319  *      WIM path that did not exist; or, a rename command attempted to rename a
3320  *      file that does not exist.
3321  * @retval ::WIMLIB_ERR_READ
3322  *      While executing an add command, failed to read data from a file or
3323  *      directory to be captured.
3324  * @retval ::WIMLIB_ERR_READLINK
3325  *      While executing an add command, failed to read the target of a symbolic
3326  *      link or junction point.
3327  * @retval ::WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED
3328  *      (Windows only) Failed to perform a reparse point fixup because of
3329  *      problems with the data of a reparse point.
3330  * @retval ::WIMLIB_ERR_STAT
3331  *      While executing an add command, failed to get attributes for a file or
3332  *      directory.
3333  * @retval ::WIMLIB_ERR_UNSUPPORTED
3334  *      ::WIMLIB_ADD_FLAG_NTFS was specified in the @p add_flags for an update
3335  *      command, but wimlib was configured with the @c --without-ntfs-3g flag;
3336  *      or, the platform is Windows and either the ::WIMLIB_ADD_FLAG_UNIX_DATA
3337  *      or the ::WIMLIB_ADD_FLAG_DEREFERENCE flags were specified in the @p
3338  *      add_flags for an update command.
3339  * @retval ::WIMLIB_ERR_UNSUPPORTED_FILE
3340  *      While executing an add command, attempted to capture a file that was not
3341  *      a supported file type (e.g. a device file).  Only if
3342  *      ::WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE specified in @p the add_flags
3343  *      for an update command.
3344  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3345  *      The WIM file is considered read-only because of any of the reasons
3346  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
3347  *      flag.
3348  *
3349  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
3350  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
3351  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
3352  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
3353  * different reasons) to read the metadata resource for an image that needed to
3354  * be updated.
3355  */
3356 extern int
3357 wimlib_update_image(WIMStruct *wim,
3358                     int image,
3359                     const struct wimlib_update_command *cmds,
3360                     size_t num_cmds,
3361                     int update_flags,
3362                     wimlib_progress_func_t progress_func);
3363
3364 /**
3365  * Writes a WIM to a file.
3366  *
3367  * This brings in resources from any external locations, such as directory trees
3368  * or NTFS volumes scanned with wimlib_add_image(), or other WIM files via
3369  * wimlib_export_image(), and incorporates them into a new on-disk WIM file.
3370  *
3371  * By default, the new WIM file is written as stand-alone.  Using the
3372  * ::WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIMS flag, a "delta" WIM can be written
3373  * instead.  However, this function cannot directly write a "split" WIM; use
3374  * wimlib_split() for that.
3375  *
3376  * @param wim
3377  *      Pointer to the ::WIMStruct for a WIM.  There may have been in-memory
3378  *      changes made to it, which are then reflected in the output file.
3379  * @param path
3380  *      The path to the file to write the WIM to.
3381  * @param image
3382  *      Normally, specify ::WIMLIB_ALL_IMAGES here.  This indicates that all
3383  *      images are to be included in the new on-disk WIM file.  If for some
3384  *      reason you only want to include a single image, specify the index of
3385  *      that image instead.
3386  * @param write_flags
3387  *      Bitwise OR of any of the flags prefixed with @c WIMLIB_WRITE_FLAG.
3388  * @param num_threads
3389  *      Number of threads to use for compressing data.  If 0, the number of
3390  *      threads is taken to be the number of online processors.  Note: if no
3391  *      data compression needs to be done, no additional threads will be created
3392  *      regardless of this parameter (e.g. if writing an uncompressed WIM, or
3393  *      exporting an image from a compressed WIM to another WIM of the same
3394  *      compression type without ::WIMLIB_WRITE_FLAG_RECOMPRESS specified in @p
3395  *      write_flags).
3396  * @param progress_func
3397  *      If non-NULL, a function that will be called periodically with the
3398  *      progress of the current operation.  The possible messages are
3399  *      ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN,
3400  *      ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_END, and
3401  *      ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS.
3402  *
3403  * @return 0 on success; nonzero on error.
3404  *
3405  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3406  *      @p image does not specify a single existing image in @p wim, and is not
3407  *      ::WIMLIB_ALL_IMAGES.
3408  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
3409  *      A file that had previously been scanned for inclusion in the WIM by
3410  *      wimlib_add_image() was concurrently modified, so it failed the SHA1
3411  *      message digest check.
3412  * @retval ::WIMLIB_ERR_INVALID_PARAM
3413  *      @p path was @c NULL.
3414  * @retval ::WIMLIB_ERR_NOMEM
3415  *      Failed to allocate needed memory.
3416  * @retval ::WIMLIB_ERR_OPEN
3417  *      Failed to open @p path for writing, or some file resources in @p wim
3418  *      refer to files in the outside filesystem, and one of these files could
3419  *      not be opened for reading.
3420  * @retval ::WIMLIB_ERR_READ
3421  *      An error occurred when trying to read data from the WIM file associated
3422  *      with @p wim, or some file resources in @p wim refer to files in the
3423  *      outside filesystem, and a read error occurred when reading one of these
3424  *      files.
3425  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
3426  *      A stream that needed to be written could not be found in the stream
3427  *      lookup table of @p wim.  This error can occur if, for example, @p wim is
3428  *      part of a split WIM but needed resources from the other split WIM parts
3429  *      were not referenced with wimlib_reference_resources() or
3430  *      wimlib_reference_resource_files() before the call to wimlib_write().
3431  * @retval ::WIMLIB_ERR_WRITE
3432  *      An error occurred when trying to write data to the new WIM file.
3433  *
3434  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
3435  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
3436  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
3437  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
3438  * different reasons) to read the metadata resource for an image that needed to
3439  * be written.
3440  */
3441 extern int
3442 wimlib_write(WIMStruct *wim,
3443              const wimlib_tchar *path,
3444              int image,
3445              int write_flags,
3446              unsigned num_threads,
3447              wimlib_progress_func_t progress_func);
3448
3449 /**
3450  * Since wimlib v1.5.0:  Same as wimlib_write(), but write the WIM directly to a
3451  * file descriptor, which need not be seekable if the write is done in a special
3452  * pipable WIM format by providing ::WIMLIB_WRITE_FLAG_PIPABLE in @p
3453  * write_flags.  This can, for example, allow capturing a WIM image and
3454  * streaming it over the network.  See the documentation for
3455  * ::WIMLIB_WRITE_FLAG_PIPABLE for more information about pipable WIMs.
3456  *
3457  * The file descriptor @p fd will @b not be closed when the write is complete;
3458  * the calling code is responsible for this.
3459  *
3460  * Returns 0 on success; nonzero on failure.  The possible error codes include
3461  * those that can be returned by wimlib_write() as well as the following:
3462  *
3463  * @retval ::WIMLIB_ERR_INVALID_PARAM
3464  *      @p fd was not seekable, but ::WIMLIB_WRITE_FLAG_PIPABLE was not
3465  *      specified in @p write_flags.
3466  */
3467 extern int
3468 wimlib_write_to_fd(WIMStruct *wim,
3469                    int fd,
3470                    int image,
3471                    int write_flags,
3472                    unsigned num_threads,
3473                    wimlib_progress_func_t progress_func);
3474
3475 /**
3476  * This function is equivalent to wimlib_lzx_compress(), but instead compresses
3477  * the data using "XPRESS" compression.
3478  */
3479 extern unsigned
3480 wimlib_xpress_compress(const void *chunk, unsigned chunk_size, void *out);
3481
3482 /**
3483  * This function is equivalent to wimlib_lzx_decompress(), but instead assumes
3484  * the data is compressed using "XPRESS" compression.
3485  */
3486 extern int
3487 wimlib_xpress_decompress(const void *compressed_data, unsigned compressed_len,
3488                          void *uncompressed_data, unsigned uncompressed_len);
3489
3490 #ifdef __cplusplus
3491 }
3492 #endif
3493
3494 #endif /* _WIMLIB_H */