]> wimlib.net Git - wimlib/blob - include/wimlib.h
wimlib.h: test _WIN32 instead of __WIN32__
[wimlib] / include / wimlib.h
1 /**
2  * @file wimlib.h
3  * @brief External header for wimlib.
4  *
5  * This file contains comments for generating documentation with Doxygen.  The
6  * built HTML documentation can be viewed at https://wimlib.net/apidoc.  Make
7  * sure to see the <a href="modules.html">Modules page</a> to make more sense of
8  * the declarations in this header.
9  */
10
11 /**
12  * @mainpage
13  *
14  * This is the documentation for the library interface of wimlib 1.10.0, a C
15  * library for creating, modifying, extracting, and mounting files in the
16  * Windows Imaging Format.  This documentation is intended for developers only.
17  * If you have installed wimlib and want to know how to use the @b wimlib-imagex
18  * program, please see the manual pages and also the <a
19  * href="https://wimlib.net/git/?p=wimlib;a=blob;f=README">README file</a>.
20  *
21  * @section sec_installing Installing
22  *
23  * @subsection UNIX
24  *
25  * Download the source code from https://wimlib.net.  Install the library by
26  * running <c>configure && make && sudo make install</c>.  See the README for
27  * information about configuration options.  To use wimlib in your program after
28  * installing it, include wimlib.h and link your program with <c>-lwim</c>.
29  *
30  * @subsection Windows
31  *
32  * Download the Windows binary distribution with the appropriate architecture
33  * (i686 or x86_64 --- also called "x86" and "amd64" respectively) from
34  * https://wimlib.net.  Link your program with the libwim-15.dll file.  Make
35  * sure to also download the source code so you can get wimlib.h, as it is not
36  * included in the binary distribution.  If you need to access the DLL from
37  * other programming languages, note that the calling convention is "cdecl".
38  *
39  * Note that wimlib is developed using MinGW-w64, and there may be a little work
40  * required if you plan to use the header and DLL with Visual Studio.
41  *
42  * @section sec_examples Examples
43  *
44  * Several examples are located in the "examples" directory of the source
45  * distribution.  Also see @ref sec_basic_wim_handling_concepts below.
46  *
47  * There is also the <a
48  * href="https://wimlib.net/git/?p=wimlib;a=blob;f=programs/imagex.c">
49  * source code of <b>wimlib-imagex</b></a>, which is complicated but uses most
50  * capabilities of wimlib.
51  *
52  * @section backward_compatibility Backward Compatibility
53  *
54  * New releases of wimlib are intended to be backward compatible with old
55  * releases, except when the libtool "age" is reset.  This most recently
56  * occurred for the v1.7.0 (libwim15) release (June 2014).  Since the library is
57  * becoming increasingly stable, the goal is to maintain the current API/ABI for
58  * as long as possible unless there is a strong reason not to.
59  *
60  * As with any other library, applications should not rely on internal
61  * implementation details that may be subject to change.
62  *
63  * @section sec_basic_wim_handling_concepts Basic WIM handling concepts
64  *
65  * wimlib wraps up a WIM file in an opaque ::WIMStruct structure.   There are
66  * two ways to create such a structure:
67  *
68  * 1. wimlib_open_wim() opens an on-disk WIM file and creates a ::WIMStruct for
69  *    it.
70  * 2. wimlib_create_new_wim() creates a new ::WIMStruct that initially contains
71  *    no images and does not yet have a backing on-disk file.
72  *
73  * A ::WIMStruct contains zero or more independent directory trees called @a
74  * images.  Images may be extracted, added, deleted, exported, and updated using
75  * various API functions.  (See @ref G_extracting_wims and @ref G_modifying_wims
76  * for more details.)
77  *
78  * Changes made to a WIM represented by a ::WIMStruct have no persistent effect
79  * until the WIM is actually written to an on-disk file.  This can be done using
80  * wimlib_write(), but if the WIM was originally opened using wimlib_open_wim(),
81  * then wimlib_overwrite() can be used instead.  (See @ref
82  * G_writing_and_overwriting_wims for more details.)
83  *
84  * wimlib's API is designed to let you combine functions to accomplish tasks in
85  * a flexible way.  Here are some example sequences of function calls:
86  *
87  * Apply an image from a WIM file, similar to the command-line program
88  * <b>wimapply</b>:
89  *
90  * 1. wimlib_open_wim()
91  * 2. wimlib_extract_image()
92  *
93  * Capture an image into a new WIM file, similar to <b>wimcapture</b>:
94  *
95  * 1. wimlib_create_new_wim()
96  * 2. wimlib_add_image()
97  * 3. wimlib_write()
98  *
99  * Append an image to an existing WIM file, similar to <b>wimappend</b>:
100  *
101  * 1. wimlib_open_wim()
102  * 2. wimlib_add_image()
103  * 3. wimlib_overwrite()
104  *
105  * Delete an image from an existing WIM file, similar to <b>wimdelete</b>:
106  *
107  * 1. wimlib_open_wim()
108  * 2. wimlib_delete_image()
109  * 3. wimlib_overwrite()
110  *
111  * Export an image from one WIM file to another, similar to <b>wimexport</b>:
112  *
113  * 1. wimlib_open_wim() (on source)
114  * 2. wimlib_open_wim() (on destination)
115  * 3. wimlib_export_image()
116  * 4. wimlib_overwrite() (on destination)
117  *
118  * The API also lets you do things the command-line tools don't directly allow.
119  * For example, you could make multiple changes to a WIM before efficiently
120  * committing the changes with just one call to wimlib_overwrite().  Perhaps you
121  * want to both delete an image and add a new one; or perhaps you want to
122  * customize an image with wimlib_update_image() after adding it.  All these use
123  * cases are supported by the API.
124  *
125  * @section sec_cleaning_up Cleaning up
126  *
127  * After you are done with any ::WIMStruct, you can call wimlib_free() to free
128  * all resources associated with it.  Also, when you are completely done with
129  * using wimlib in your program, you can call wimlib_global_cleanup() to free
130  * any other resources allocated by the library.
131  *
132  * @section sec_error_handling Error Handling
133  *
134  * Most functions in wimlib return 0 on success and a positive
135  * ::wimlib_error_code value on failure.  Use wimlib_get_error_string() to get a
136  * string that describes an error code.  wimlib also can print error messages to
137  * standard error or a custom file when an error occurs, and these may be more
138  * informative than the error code; to enable this, call
139  * wimlib_set_print_errors().  Please note that this is for convenience only,
140  * and some errors can occur without a message being printed.  Currently, error
141  * messages and strings (as well as all documentation, for that matter) are only
142  * available in English.
143  *
144  * @section sec_encodings Character encoding
145  *
146  * To support Windows as well as UNIX-like systems, wimlib's API typically takes
147  * and returns strings of ::wimlib_tchar which have a platform-dependent type
148  * and encoding.
149  *
150  * On Windows, each ::wimlib_tchar is a 2-byte <tt>wchar_t</tt>.  The encoding
151  * is meant to be UTF-16LE.  However, unpaired surrogates are permitted because
152  * neither Windows nor the NTFS filesystem forbids them in filenames.
153  *
154  * On UNIX-like systems, each ::wimlib_tchar is a 1 byte <tt>char</tt>.  The
155  * encoding is meant to be UTF-8.  However, for compatibility with Windows-style
156  * filenames that are not valid UTF-16LE, surrogate codepoints are permitted.
157  * Other multibyte encodings (e.g. ISO-8859-1) or garbage sequences of bytes are
158  * not permitted.
159  *
160  * @section sec_advanced Additional information and features
161  *
162  *
163  * @subsection subsec_mounting_wim_images Mounting WIM images
164  *
165  * See @ref G_mounting_wim_images.
166  *
167  * @subsection subsec_progress_functions Progress Messages
168  *
169  * See @ref G_progress.
170  *
171  * @subsection subsec_non_standalone_wims Non-standalone WIMs
172  *
173  * See @ref G_nonstandalone_wims.
174  *
175  * @subsection subsec_pipable_wims Pipable WIMs
176  *
177  * wimlib supports a special "pipable" WIM format which unfortunately is @b not
178  * compatible with Microsoft's software.  To create a pipable WIM, call
179  * wimlib_write(), wimlib_write_to_fd(), or wimlib_overwrite() with
180  * ::WIMLIB_WRITE_FLAG_PIPABLE specified.  Pipable WIMs are pipable in both
181  * directions, so wimlib_write_to_fd() can be used to write a pipable WIM to a
182  * pipe, and wimlib_extract_image_from_pipe() can be used to apply an image from
183  * a pipable WIM.  wimlib can also transparently open and operate on pipable WIM
184  * s using a seekable file descriptor using the regular function calls (e.g.
185  * wimlib_open_wim(), wimlib_extract_image()).
186  *
187  * See the documentation for the <b>--pipable</b> flag of <b>wimcapture</b> for
188  * more information about pipable WIMs.
189  *
190  * @subsection subsec_thread_safety Thread Safety
191  *
192  * A ::WIMStruct is not thread-safe and cannot be accessed by multiple threads
193  * concurrently, even for "read-only" operations such as extraction.  However,
194  * users are free to use <i>different</i> ::WIMStruct's from different threads
195  * concurrently.  It is even allowed for multiple ::WIMStruct's to be backed by
196  * the same on-disk WIM file, although "overwrites" should never be done in such
197  * a scenario.
198  *
199  * In addition, several functions change global state and should only be called
200  * when a single thread is active in the library.  These functions are:
201  *
202  * - wimlib_global_init()
203  * - wimlib_global_cleanup()
204  * - wimlib_set_memory_allocator()
205  * - wimlib_set_print_errors()
206  * - wimlib_set_error_file()
207  * - wimlib_set_error_file_by_name()
208  *
209  * @subsection subsec_limitations Limitations
210  *
211  * This section documents some technical limitations of wimlib not already
212  * described in the documentation for @b wimlib-imagex.
213  *
214  * - The old WIM format from Vista pre-releases is not supported.
215  * - wimlib does not provide a clone of the @b PEImg tool, or the @b DISM
216  *   functionality other than that already present in @b ImageX, that allows you
217  *   to make certain Windows-specific modifications to a Windows PE image, such
218  *   as adding a driver or Windows component.  Such a tool could be implemented
219  *   on top of wimlib.
220  *
221  * @subsection more_info More information
222  *
223  * You are advised to read the README as well as the documentation for
224  * <b>wimlib-imagex</b>, since not all relevant information is repeated here in
225  * the API documentation.
226  */
227
228 /** @defgroup G_general General
229  *
230  * @brief Declarations and structures shared across the library.
231  */
232
233 /** @defgroup G_creating_and_opening_wims Creating and Opening WIMs
234  *
235  * @brief Open an existing WIM file as a ::WIMStruct, or create a new
236  * ::WIMStruct which can be used to create a new WIM file.
237  */
238
239 /** @defgroup G_wim_information Retrieving WIM information and directory listings
240  *
241  * @brief Retrieve information about a WIM or WIM image.
242  */
243
244 /** @defgroup G_modifying_wims Modifying WIMs
245  *
246  * @brief Make changes to a ::WIMStruct, in preparation of persisting the
247  * ::WIMStruct to an on-disk file.
248  *
249  * @section sec_adding_images Capturing and adding WIM images
250  *
251  * As described in @ref sec_basic_wim_handling_concepts, capturing a new WIM or
252  * appending an image to an existing WIM is a multi-step process, but at its
253  * core is wimlib_add_image() or an equivalent function.  Normally,
254  * wimlib_add_image() takes an on-disk directory tree and logically adds it to a
255  * ::WIMStruct as a new image.  However, when supported by the build of the
256  * library, there is also a special NTFS volume capture mode (entered when
257  * ::WIMLIB_ADD_FLAG_NTFS is specified) that allows adding the image directly
258  * from an unmounted NTFS volume.
259  *
260  * Another function, wimlib_add_image_multisource() is also provided.  It
261  * generalizes wimlib_add_image() to allow combining multiple files or directory
262  * trees into a single WIM image in a configurable way.
263  *
264  * For maximum customization of WIM image creation, it is also possible to add a
265  * completely empty WIM image with wimlib_add_empty_image(), then update it with
266  * wimlib_update_image().  (This is in fact what wimlib_add_image() and
267  * wimlib_add_image_multisource() do internally.)
268  *
269  * Note that some details of how image addition/capture works are documented
270  * more fully in the documentation for <b>wimcapture</b>.
271  *
272  * @section sec_deleting_images Deleting WIM images
273  *
274  * wimlib_delete_image() can delete an image from a ::WIMStruct.  But as usual,
275  * wimlib_write() or wimlib_overwrite() must be called to cause the changes to
276  * be made persistent in an on-disk WIM file.
277  *
278  * @section sec_exporting_images Exporting WIM images
279  *
280  * wimlib_export_image() can copy, or "export", an image from one WIM to
281  * another.
282  *
283  * @section sec_other_modifications Other modifications
284  *
285  * wimlib_update_image() can add, delete, and rename files in a WIM image.
286  *
287  * wimlib_set_image_property() can change other image metadata.
288  *
289  * wimlib_set_wim_info() can change information about the WIM file itself, such
290  * as the boot index.
291  */
292
293 /** @defgroup G_extracting_wims Extracting WIMs
294  *
295  * @brief Extract files, directories, and images from a WIM.
296  *
297  * wimlib_extract_image() extracts, or "applies", an image from a WIM,
298  * represented by a ::WIMStruct.  This normally extracts the image to a
299  * directory, but when supported by the build of the library there is also a
300  * special NTFS volume extraction mode (entered when ::WIMLIB_EXTRACT_FLAG_NTFS
301  * is specified) that allows extracting a WIM image directly to an unmounted
302  * NTFS volume.  Various other flags allow further customization of image
303  * extraction.
304  *
305  * wimlib_extract_paths() and wimlib_extract_pathlist() allow extracting a list
306  * of (possibly wildcard) paths from a WIM image.
307  *
308  * wimlib_extract_image_from_pipe() extracts an image from a pipable WIM sent
309  * over a pipe; see @ref subsec_pipable_wims.
310  *
311  * Some details of how WIM extraction works are described more fully in the
312  * documentation for <b>wimapply</b> and <b>wimextract</b>.
313  */
314
315 /** @defgroup G_mounting_wim_images Mounting WIM images
316  *
317  * @brief Mount and unmount WIM images.
318  *
319  * On Linux, wimlib supports mounting images from WIM files either read-only or
320  * read-write.  To mount an image, call wimlib_mount_image().  To unmount an
321  * image, call wimlib_unmount_image().  Mounting can be done without root
322  * privileges because it is implemented using FUSE (Filesystem in Userspace).
323  *
324  * If wimlib is compiled using the <c>--without-fuse</c> flag, these functions
325  * will be available but will fail with ::WIMLIB_ERR_UNSUPPORTED.
326  *
327  * Note: if mounting is unsupported, wimlib still provides another way to modify
328  * a WIM image (wimlib_update_image()).
329  */
330
331 /**
332  * @defgroup G_progress Progress Messages
333  *
334  * @brief Track the progress of long WIM operations.
335  *
336  * Library users can provide a progress function which will be called
337  * periodically during operations such as extracting a WIM image or writing a
338  * WIM image.  A ::WIMStruct can have a progress function of type
339  * ::wimlib_progress_func_t associated with it by calling
340  * wimlib_register_progress_function() or by opening the ::WIMStruct using
341  * wimlib_open_wim_with_progress().  Once this is done, the progress function
342  * will be called automatically during many operations, such as
343  * wimlib_extract_image() and wimlib_write().
344  *
345  * Some functions that do not operate directly on a user-provided ::WIMStruct,
346  * such as wimlib_join(), also take the progress function directly using an
347  * extended version of the function, such as wimlib_join_with_progress().
348  *
349  * Since wimlib v1.7.0, progress functions are no longer just unidirectional.
350  * You can now return ::WIMLIB_PROGRESS_STATUS_ABORT to cause the current
351  * operation to be aborted.  wimlib v1.7.0 also added the third argument to
352  * ::wimlib_progress_func_t, which is a user-supplied context.
353  */
354
355 /** @defgroup G_writing_and_overwriting_wims Writing and Overwriting WIMs
356  *
357  * @brief Create or update an on-disk WIM file.
358  *
359  * wimlib_write() creates a new on-disk WIM file, whereas wimlib_overwrite()
360  * updates an existing WIM file.  See @ref sec_basic_wim_handling_concepts for
361  * more information about the API design.
362  */
363
364 /** @defgroup G_nonstandalone_wims Creating and handling non-standalone WIMs
365  *
366  * @brief Create and handle non-standalone WIMs, such as split and delta WIMs.
367  *
368  * A ::WIMStruct backed by an on-disk file normally represents a fully
369  * standalone WIM archive.  However, WIM archives can also be arranged in
370  * non-standalone ways, such as a set of on-disk files that together form a
371  * single "split WIM" or "delta WIM".  Such arrangements are fully supported by
372  * wimlib.  However, as a result, in such cases a ::WIMStruct created from one
373  * of these on-disk files initially only partially represents the full WIM and
374  * needs to, in effect, be logically combined with other ::WIMStruct's before
375  * performing certain operations, such as extracting files with
376  * wimlib_extract_image() or wimlib_extract_paths().  This is done by calling
377  * wimlib_reference_resource_files() or wimlib_reference_resources().  Note: if
378  * you fail to do so, you may see the error code
379  * ::WIMLIB_ERR_RESOURCE_NOT_FOUND; this just indicates that data is not
380  * available because the appropriate WIM files have not yet been referenced.
381  *
382  * wimlib_write() can create delta WIMs as well as standalone WIMs, but a
383  * specialized function (wimlib_split()) is needed to create a split WIM.
384  */
385
386 #ifndef _WIMLIB_H
387 #define _WIMLIB_H
388
389 #include <stdio.h>
390 #include <stddef.h>
391 #include <stdbool.h>
392 #include <inttypes.h>
393 #include <time.h>
394
395 /** @addtogroup G_general
396  * @{ */
397
398 /** Major version of the library (for example, the 1 in 1.2.5).  */
399 #define WIMLIB_MAJOR_VERSION 1
400
401 /** Minor version of the library (for example, the 2 in 1.2.5). */
402 #define WIMLIB_MINOR_VERSION 10
403
404 /** Patch version of the library (for example, the 5 in 1.2.5). */
405 #define WIMLIB_PATCH_VERSION 0
406
407 #ifdef __cplusplus
408 extern "C" {
409 #endif
410
411 /*
412  * To represent file timestamps, wimlib's API uses the POSIX 'struct timespec'.
413  * This was probably a mistake because it doesn't play well with Visual Studio.
414  * In old VS versions it isn't present at all; in newer VS versions it is
415  * supposedly present, but I wouldn't trust it to be the same size as the one
416  * MinGW uses.  The solution is to define a compatible structure ourselves when
417  * this header is included on Windows and the compiler is not MinGW.
418  */
419 #if defined(_WIN32) && !defined(__GNUC__)
420 typedef struct {
421         /* Seconds since start of UNIX epoch (January 1, 1970) */
422 #ifdef _WIN64
423         int64_t tv_sec;
424 #else
425         int32_t tv_sec;
426 #endif
427         /* Nanoseconds (0-999999999) */
428         int32_t tv_nsec;
429 } wimlib_timespec;
430 #else
431 #  define wimlib_timespec  struct timespec  /* standard definition */
432 #endif
433
434 /**
435  * Opaque structure that represents a WIM, possibly backed by an on-disk file.
436  * See @ref sec_basic_wim_handling_concepts for more information.
437  */
438 #ifndef WIMLIB_WIMSTRUCT_DECLARED
439 typedef struct WIMStruct WIMStruct;
440 #define WIMLIB_WIMSTRUCT_DECLARED
441 #endif
442
443 #ifdef _WIN32
444 typedef wchar_t wimlib_tchar;
445 #else
446 /** See @ref sec_encodings */
447 typedef char wimlib_tchar;
448 #endif
449
450 #ifdef _WIN32
451 /** Path separator for WIM paths passed back to progress callbacks.
452  * This is forward slash on UNIX and backslash on Windows.  */
453 #  define WIMLIB_WIM_PATH_SEPARATOR '\\'
454 #  define WIMLIB_WIM_PATH_SEPARATOR_STRING L"\\"
455 #else
456 /** Path separator for WIM paths passed back to progress callbacks.
457  * This is forward slash on UNIX and backslash on Windows.  */
458 #  define WIMLIB_WIM_PATH_SEPARATOR '/'
459 #  define WIMLIB_WIM_PATH_SEPARATOR_STRING "/"
460 #endif
461
462 /** A string containing a single path separator; use this to specify the root
463  * directory of a WIM image.  */
464 #define WIMLIB_WIM_ROOT_PATH WIMLIB_WIM_PATH_SEPARATOR_STRING
465
466 /** Use this to test if the specified path refers to the root directory of the
467  * WIM image.  */
468 #define WIMLIB_IS_WIM_ROOT_PATH(path) \
469                 ((path)[0] == WIMLIB_WIM_PATH_SEPARATOR &&      \
470                  (path)[1] == 0)
471
472 /** Length of a Globally Unique Identifier (GUID), in bytes.  */
473 #define WIMLIB_GUID_LEN 16
474
475 /**
476  * Specifies a compression type.
477  *
478  * A WIM file has a default compression type, indicated by its file header.
479  * Normally, each resource in the WIM file is compressed with this compression
480  * type.  However, resources may be stored as uncompressed; for example, wimlib
481  * may do so if a resource does not compress to less than its original size.  In
482  * addition, a WIM with the new version number of 3584, or "ESD file", might
483  * contain solid resources with different compression types.
484  */
485 enum wimlib_compression_type {
486         /**
487          * No compression.
488          *
489          * This is a valid argument to wimlib_create_new_wim() and
490          * wimlib_set_output_compression_type(), but not to the functions in the
491          * compression API such as wimlib_create_compressor().
492          */
493         WIMLIB_COMPRESSION_TYPE_NONE = 0,
494
495         /**
496          * The XPRESS compression format.  This format combines Lempel-Ziv
497          * factorization with Huffman encoding.  Compression and decompression
498          * are both fast.  This format supports chunk sizes that are powers of 2
499          * between <c>2^12</c> and <c>2^16</c>, inclusively.
500          *
501          * wimlib's XPRESS compressor will, with the default settings, usually
502          * produce a better compression ratio, and work more quickly, than the
503          * implementation in Microsoft's WIMGAPI (as of Windows 8.1).
504          * Non-default compression levels are also supported.  For example,
505          * level 80 will enable two-pass optimal parsing, which is significantly
506          * slower but usually improves compression by several percent over the
507          * default level of 50.
508          *
509          * If using wimlib_create_compressor() to create an XPRESS compressor
510          * directly, the @p max_block_size parameter may be any positive value
511          * up to and including <c>2^16</c>.
512          */
513         WIMLIB_COMPRESSION_TYPE_XPRESS = 1,
514
515         /**
516          * The LZX compression format.  This format combines Lempel-Ziv
517          * factorization with Huffman encoding, but with more features and
518          * complexity than XPRESS.  Compression is slow to somewhat fast,
519          * depending on the settings.  Decompression is fast but slower than
520          * XPRESS.  This format supports chunk sizes that are powers of 2
521          * between <c>2^15</c> and <c>2^21</c>, inclusively.  Note: chunk sizes
522          * other than <c>2^15</c> are not compatible with the Microsoft
523          * implementation.
524          *
525          * wimlib's LZX compressor will, with the default settings, usually
526          * produce a better compression ratio, and work more quickly, than the
527          * implementation in Microsoft's WIMGAPI (as of Windows 8.1).
528          * Non-default compression levels are also supported.  For example,
529          * level 20 will provide fast compression, almost as fast as XPRESS.
530          *
531          * If using wimlib_create_compressor() to create an LZX compressor
532          * directly, the @p max_block_size parameter may be any positive value
533          * up to and including <c>2^21</c>.
534          */
535         WIMLIB_COMPRESSION_TYPE_LZX = 2,
536
537         /**
538          * The LZMS compression format.  This format combines Lempel-Ziv
539          * factorization with adaptive Huffman encoding and range coding.
540          * Compression and decompression are both fairly slow.  This format
541          * supports chunk sizes that are powers of 2 between <c>2^15</c> and
542          * <c>2^30</c>, inclusively.  This format is best used for large chunk
543          * sizes.  Note: LZMS compression is only compatible with wimlib v1.6.0
544          * and later, WIMGAPI Windows 8 and later, and DISM Windows 8.1 and
545          * later.  Also, chunk sizes larger than <c>2^26</c> are not compatible
546          * with the Microsoft implementation.
547          *
548          * wimlib's LZMS compressor will, with the default settings, usually
549          * produce a better compression ratio, and work more quickly, than the
550          * implementation in Microsoft's WIMGAPI (as of Windows 8.1).  There is
551          * limited support for non-default compression levels, but compression
552          * will be noticeably faster if you choose a level < 35.
553          *
554          * If using wimlib_create_compressor() to create an LZMS compressor
555          * directly, the @p max_block_size parameter may be any positive value
556          * up to and including <c>2^30</c>.
557          */
558         WIMLIB_COMPRESSION_TYPE_LZMS = 3,
559 };
560
561 /** @} */
562 /** @addtogroup G_progress
563  * @{ */
564
565 /** Possible values of the first parameter to the user-supplied
566  * ::wimlib_progress_func_t progress function */
567 enum wimlib_progress_msg {
568
569         /** A WIM image is about to be extracted.  @p info will point to
570          * ::wimlib_progress_info.extract.  This message is received once per
571          * image for calls to wimlib_extract_image() and
572          * wimlib_extract_image_from_pipe().  */
573         WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN = 0,
574
575         /** One or more file or directory trees within a WIM image is about to
576          * be extracted.  @p info will point to ::wimlib_progress_info.extract.
577          * This message is received only once per wimlib_extract_paths() and
578          * wimlib_extract_pathlist(), since wimlib combines all paths into a
579          * single extraction operation for optimization purposes.  */
580         WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN = 1,
581
582         /** This message may be sent periodically (not for every file) while
583          * files and directories are being created, prior to file data
584          * extraction.  @p info will point to ::wimlib_progress_info.extract.
585          * In particular, the @p current_file_count and @p end_file_count
586          * members may be used to track the progress of this phase of
587          * extraction.  */
588         WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE = 3,
589
590         /** File data is currently being extracted.  @p info will point to
591          * ::wimlib_progress_info.extract.  This is the main message to track
592          * the progress of an extraction operation.  */
593         WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS = 4,
594
595         /** Starting to read a new part of a split pipable WIM over the pipe.
596          * @p info will point to ::wimlib_progress_info.extract.  */
597         WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN = 5,
598
599         /** This message may be sent periodically (not necessarily for every
600          * file) while file and directory metadata is being extracted, following
601          * file data extraction.  @p info will point to
602          * ::wimlib_progress_info.extract.  The @p current_file_count and @p
603          * end_file_count members may be used to track the progress of this
604          * phase of extraction.  */
605         WIMLIB_PROGRESS_MSG_EXTRACT_METADATA = 6,
606
607         /** The image has been successfully extracted.  @p info will point to
608          * ::wimlib_progress_info.extract.  This is paired with
609          * ::WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN.  */
610         WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END = 7,
611
612         /** The files or directory trees have been successfully extracted.  @p
613          * info will point to ::wimlib_progress_info.extract.  This is paired
614          * with ::WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN.  */
615         WIMLIB_PROGRESS_MSG_EXTRACT_TREE_END = 8,
616
617         /** The directory or NTFS volume is about to be scanned for metadata.
618          * @p info will point to ::wimlib_progress_info.scan.  This message is
619          * received once per call to wimlib_add_image(), or once per capture
620          * source passed to wimlib_add_image_multisource(), or once per add
621          * command passed to wimlib_update_image().  */
622         WIMLIB_PROGRESS_MSG_SCAN_BEGIN = 9,
623
624         /** A directory or file has been scanned.  @p info will point to
625          * ::wimlib_progress_info.scan, and its @p cur_path member will be
626          * valid.  This message is only sent if ::WIMLIB_ADD_FLAG_VERBOSE has
627          * been specified.  */
628         WIMLIB_PROGRESS_MSG_SCAN_DENTRY = 10,
629
630         /** The directory or NTFS volume has been successfully scanned.  @p info
631          * will point to ::wimlib_progress_info.scan.  This is paired with a
632          * previous ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN message, possibly with many
633          * intervening ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY messages.  */
634         WIMLIB_PROGRESS_MSG_SCAN_END = 11,
635
636         /** File data is currently being written to the WIM.  @p info will point
637          * to ::wimlib_progress_info.write_streams.  This message may be
638          * received many times while the WIM file is being written or appended
639          * to with wimlib_write(), wimlib_overwrite(), or wimlib_write_to_fd().
640          */
641         WIMLIB_PROGRESS_MSG_WRITE_STREAMS = 12,
642
643         /** Per-image metadata is about to be written to the WIM file.  @p info
644          * will not be valid. */
645         WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN = 13,
646
647         /** The per-image metadata has been written to the WIM file.  @p info
648          * will not be valid.  This message is paired with a preceding
649          * ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN message.  */
650         WIMLIB_PROGRESS_MSG_WRITE_METADATA_END = 14,
651
652         /** wimlib_overwrite() has successfully renamed the temporary file to
653          * the original WIM file, thereby committing the changes to the WIM
654          * file.  @p info will point to ::wimlib_progress_info.rename.  Note:
655          * this message is not received if wimlib_overwrite() chose to append to
656          * the WIM file in-place.  */
657         WIMLIB_PROGRESS_MSG_RENAME = 15,
658
659         /** The contents of the WIM file are being checked against the integrity
660          * table.  @p info will point to ::wimlib_progress_info.integrity.  This
661          * message is only received (and may be received many times) when
662          * wimlib_open_wim_with_progress() is called with the
663          * ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY flag.  */
664         WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY = 16,
665
666         /** An integrity table is being calculated for the WIM being written.
667          * @p info will point to ::wimlib_progress_info.integrity.  This message
668          * is only received (and may be received many times) when a WIM file is
669          * being written with the flag ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY.  */
670         WIMLIB_PROGRESS_MSG_CALC_INTEGRITY = 17,
671
672         /** A wimlib_split() operation is in progress, and a new split part is
673          * about to be started.  @p info will point to
674          * ::wimlib_progress_info.split.  */
675         WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART = 19,
676
677         /** A wimlib_split() operation is in progress, and a split part has been
678          * finished. @p info will point to ::wimlib_progress_info.split.  */
679         WIMLIB_PROGRESS_MSG_SPLIT_END_PART = 20,
680
681         /** A WIM update command is about to be executed. @p info will point to
682          * ::wimlib_progress_info.update.  This message is received once per
683          * update command when wimlib_update_image() is called with the flag
684          * ::WIMLIB_UPDATE_FLAG_SEND_PROGRESS.  */
685         WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND = 21,
686
687         /** A WIM update command has been executed. @p info will point to
688          * ::wimlib_progress_info.update.  This message is received once per
689          * update command when wimlib_update_image() is called with the flag
690          * ::WIMLIB_UPDATE_FLAG_SEND_PROGRESS.  */
691         WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND = 22,
692
693         /** A file in the image is being replaced as a result of a
694          * ::wimlib_add_command without ::WIMLIB_ADD_FLAG_NO_REPLACE specified.
695          * @p info will point to ::wimlib_progress_info.replace.  This is only
696          * received when ::WIMLIB_ADD_FLAG_VERBOSE is also specified in the add
697          * command.  */
698         WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM = 23,
699
700         /** An image is being extracted with ::WIMLIB_EXTRACT_FLAG_WIMBOOT, and
701          * a file is being extracted normally (not as a "WIMBoot pointer file")
702          * due to it matching a pattern in the <c>[PrepopulateList]</c> section
703          * of the configuration file
704          * <c>/Windows/System32/WimBootCompress.ini</c> in the WIM image.  @p
705          * info will point to ::wimlib_progress_info.wimboot_exclude.  */
706         WIMLIB_PROGRESS_MSG_WIMBOOT_EXCLUDE = 24,
707
708         /** Starting to unmount an image.  @p info will point to
709          * ::wimlib_progress_info.unmount.  */
710         WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN = 25,
711
712         /** wimlib has used a file's data for the last time (including all data
713          * streams, if it has multiple).  @p info will point to
714          * ::wimlib_progress_info.done_with_file.  This message is only received
715          * if ::WIMLIB_WRITE_FLAG_SEND_DONE_WITH_FILE_MESSAGES was provided.  */
716         WIMLIB_PROGRESS_MSG_DONE_WITH_FILE = 26,
717
718         /** wimlib_verify_wim() is starting to verify the metadata for an image.
719          * @p info will point to ::wimlib_progress_info.verify_image.  */
720         WIMLIB_PROGRESS_MSG_BEGIN_VERIFY_IMAGE = 27,
721
722         /** wimlib_verify_wim() has finished verifying the metadata for an
723          * image.  @p info will point to ::wimlib_progress_info.verify_image.
724          */
725         WIMLIB_PROGRESS_MSG_END_VERIFY_IMAGE = 28,
726
727         /** wimlib_verify_wim() is verifying file data integrity.  @p info will
728          * point to ::wimlib_progress_info.verify_streams.  */
729         WIMLIB_PROGRESS_MSG_VERIFY_STREAMS = 29,
730
731         /**
732          * The progress function is being asked whether a file should be
733          * excluded from capture or not.  @p info will point to
734          * ::wimlib_progress_info.test_file_exclusion.  This is a bidirectional
735          * message that allows the progress function to set a flag if the file
736          * should be excluded.
737          *
738          * This message is only received if the flag
739          * ::WIMLIB_ADD_FLAG_TEST_FILE_EXCLUSION is used.  This method for file
740          * exclusions is independent of the "capture configuration file"
741          * mechanism.
742          */
743         WIMLIB_PROGRESS_MSG_TEST_FILE_EXCLUSION = 30,
744
745         /**
746          * An error has occurred and the progress function is being asked
747          * whether to ignore the error or not.  @p info will point to
748          * ::wimlib_progress_info.handle_error.  This is a bidirectional
749          * message.
750          *
751          * This message provides a limited capability for applications to
752          * recover from "unexpected" errors (i.e. those with no in-library
753          * handling policy) arising from the underlying operating system.
754          * Normally, any such error will cause the library to abort the current
755          * operation.  By implementing a handler for this message, the
756          * application can instead choose to ignore a given error.
757          *
758          * Currently, only the following types of errors will result in this
759          * progress message being sent:
760          *
761          *      - Directory tree scan errors, e.g. from wimlib_add_image()
762          *      - Most extraction errors; currently restricted to the Windows
763          *        build of the library only.
764          */
765         WIMLIB_PROGRESS_MSG_HANDLE_ERROR = 31,
766 };
767
768 /** Valid return values from user-provided progress functions
769  * (::wimlib_progress_func_t).
770  *
771  * (Note: if an invalid value is returned, ::WIMLIB_ERR_UNKNOWN_PROGRESS_STATUS
772  * will be issued.)
773  */
774 enum wimlib_progress_status {
775
776         /** The operation should be continued.  This is the normal return value.
777          */
778         WIMLIB_PROGRESS_STATUS_CONTINUE = 0,
779
780         /** The operation should be aborted.  This will cause the current
781          * operation to fail with ::WIMLIB_ERR_ABORTED_BY_PROGRESS.  */
782         WIMLIB_PROGRESS_STATUS_ABORT    = 1,
783 };
784
785 /**
786  * A pointer to this union is passed to the user-supplied
787  * ::wimlib_progress_func_t progress function.  One (or none) of the structures
788  * contained in this union will be applicable for the operation
789  * (::wimlib_progress_msg) indicated in the first argument to the progress
790  * function. */
791 union wimlib_progress_info {
792
793         /** Valid on the message ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS.  This is
794          * the primary message for tracking the progress of writing a WIM file.
795          */
796         struct wimlib_progress_info_write_streams {
797
798                 /** An upper bound on the number of bytes of file data that will
799                  * be written.  This number is the uncompressed size; the actual
800                  * size may be lower due to compression.  In addition, this
801                  * number may decrease over time as duplicated file data is
802                  * discovered.  */
803                 uint64_t total_bytes;
804
805                 /** An upper bound on the number of distinct file data "blobs"
806                  * that will be written.  This will often be similar to the
807                  * "number of files", but for several reasons (hard links, named
808                  * data streams, empty files, etc.) it can be different.  In
809                  * addition, this number may decrease over time as duplicated
810                  * file data is discovered.  */
811                 uint64_t total_streams;
812
813                 /** The number of bytes of file data that have been written so
814                  * far.  This starts at 0 and ends at @p total_bytes.  This
815                  * number is the uncompressed size; the actual size may be lower
816                  * due to compression.  */
817                 uint64_t completed_bytes;
818
819                 /** The number of distinct file data "blobs" that have been
820                  * written so far.  This starts at 0 and ends at @p
821                  * total_streams.  */
822                 uint64_t completed_streams;
823
824                 /** The number of threads being used for data compression; or,
825                  * if no compression is being performed, this will be 1.  */
826                 uint32_t num_threads;
827
828                 /** The compression type being used, as one of the
829                  * ::wimlib_compression_type constants.  */
830                 int32_t  compression_type;
831
832                 /** The number of on-disk WIM files from which file data is
833                  * being exported into the output WIM file.  This can be 0, 1,
834                  * or more than 1, depending on the situation.  */
835                 uint32_t total_parts;
836
837                 /** This is currently broken and will always be 0.  */
838                 uint32_t completed_parts;
839         } write_streams;
840
841         /** Valid on messages ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN,
842          * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY, and
843          * ::WIMLIB_PROGRESS_MSG_SCAN_END.  */
844         struct wimlib_progress_info_scan {
845
846                 /** Top-level directory being scanned; or, when capturing an NTFS
847                  * volume with ::WIMLIB_ADD_FLAG_NTFS, this is instead the path
848                  * to the file or block device that contains the NTFS volume
849                  * being scanned.  */
850                 const wimlib_tchar *source;
851
852                 /** Path to the file (or directory) that has been scanned, valid
853                  * on ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY.  When capturing an NTFS
854                  * volume with ::WIMLIB_ADD_FLAG_NTFS, this path will be
855                  * relative to the root of the NTFS volume.  */
856                 const wimlib_tchar *cur_path;
857
858                 /** Dentry scan status, valid on
859                  * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY.  */
860                 enum {
861                         /** File looks okay and will be captured.  */
862                         WIMLIB_SCAN_DENTRY_OK = 0,
863
864                         /** File is being excluded from capture due to the
865                          * capture configuration.  */
866                         WIMLIB_SCAN_DENTRY_EXCLUDED = 1,
867
868                         /** File is being excluded from capture due to being of
869                          * an unsupported type.  */
870                         WIMLIB_SCAN_DENTRY_UNSUPPORTED = 2,
871
872                         /** The file is an absolute symbolic link or junction
873                          * that points into the capture directory, and
874                          * reparse-point fixups are enabled, so its target is
875                          * being adjusted.  (Reparse point fixups can be
876                          * disabled with the flag ::WIMLIB_ADD_FLAG_NORPFIX.)
877                          */
878                         WIMLIB_SCAN_DENTRY_FIXED_SYMLINK = 3,
879
880                         /** Reparse-point fixups are enabled, but the file is an
881                          * absolute symbolic link or junction that does
882                          * <b>not</b> point into the capture directory, so its
883                          * target is <b>not</b> being adjusted.  */
884                         WIMLIB_SCAN_DENTRY_NOT_FIXED_SYMLINK = 4,
885                 } status;
886
887                 union {
888                         /** Target path in the image.  Only valid on messages
889                          * ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN and
890                          * ::WIMLIB_PROGRESS_MSG_SCAN_END.  */
891                         const wimlib_tchar *wim_target_path;
892
893                         /** For ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY and a status
894                          * of @p WIMLIB_SCAN_DENTRY_FIXED_SYMLINK or @p
895                          * WIMLIB_SCAN_DENTRY_NOT_FIXED_SYMLINK, this is the
896                          * target of the absolute symbolic link or junction.  */
897                         const wimlib_tchar *symlink_target;
898                 };
899
900                 /** The number of directories scanned so far, not counting
901                  * excluded/unsupported files.  */
902                 uint64_t num_dirs_scanned;
903
904                 /** The number of non-directories scanned so far, not counting
905                  * excluded/unsupported files.  */
906                 uint64_t num_nondirs_scanned;
907
908                 /** The number of bytes of file data detected so far, not
909                  * counting excluded/unsupported files.  */
910                 uint64_t num_bytes_scanned;
911         } scan;
912
913         /** Valid on messages
914          * ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN,
915          * ::WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN,
916          * ::WIMLIB_PROGRESS_MSG_EXTRACT_TREE_BEGIN,
917          * ::WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE,
918          * ::WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS,
919          * ::WIMLIB_PROGRESS_MSG_EXTRACT_METADATA,
920          * ::WIMLIB_PROGRESS_MSG_EXTRACT_TREE_END, and
921          * ::WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END.
922          *
923          * Note: most of the time of an extraction operation will be spent
924          * extracting file data, and the application will receive
925          * ::WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS during this time.  Using @p
926          * completed_bytes and @p total_bytes, the application can calculate a
927          * percentage complete.  However, there is no way for applications to
928          * know which file is currently being extracted.  This is by design
929          * because the best way to complete the extraction operation is not
930          * necessarily file-by-file.
931          */
932         struct wimlib_progress_info_extract {
933
934                 /** The 1-based index of the image from which files are being
935                  * extracted.  */
936                 uint32_t image;
937
938                 /** Extraction flags being used.  */
939                 uint32_t extract_flags;
940
941                 /** If the ::WIMStruct from which the extraction being performed
942                  * has a backing file, then this is an absolute path to that
943                  * backing file.  Otherwise, this is @c NULL.  */
944                 const wimlib_tchar *wimfile_name;
945
946                 /** Name of the image from which files are being extracted, or
947                  * the empty string if the image is unnamed.  */
948                 const wimlib_tchar *image_name;
949
950                 /** Path to the directory or NTFS volume to which the files are
951                  * being extracted.  */
952                 const wimlib_tchar *target;
953
954                 /** Reserved.  */
955                 const wimlib_tchar *reserved;
956
957                 /** The number of bytes of file data that will be extracted.  */
958                 uint64_t total_bytes;
959
960                 /** The number of bytes of file data that have been extracted so
961                  * far.  This starts at 0 and ends at @p total_bytes.  */
962                 uint64_t completed_bytes;
963
964                 /** The number of file streams that will be extracted.  This
965                  * will often be similar to the "number of files", but for
966                  * several reasons (hard links, named data streams, empty files,
967                  * etc.) it can be different.  */
968                 uint64_t total_streams;
969
970                 /** The number of file streams that have been extracted so far.
971                  * This starts at 0 and ends at @p total_streams.  */
972                 uint64_t completed_streams;
973
974                 /** Currently only used for
975                  * ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN.  */
976                 uint32_t part_number;
977
978                 /** Currently only used for
979                  * ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN.  */
980                 uint32_t total_parts;
981
982                 /** Currently only used for
983                  * ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN.  */
984                 uint8_t guid[WIMLIB_GUID_LEN];
985
986                 /** For ::WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE and
987                  * ::WIMLIB_PROGRESS_MSG_EXTRACT_METADATA messages, this is the
988                  * number of files that have been processed so far.  Once the
989                  * corresponding phase of extraction is complete, this value
990                  * will be equal to @c end_file_count.  */
991                 uint64_t current_file_count;
992
993                 /** For ::WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE and
994                  * ::WIMLIB_PROGRESS_MSG_EXTRACT_METADATA messages, this is
995                  * total number of files that will be processed.
996                  *
997                  * This number is provided for informational purposes only, e.g.
998                  * for a progress bar.  This number will not necessarily be
999                  * equal to the number of files actually being extracted.  This
1000                  * is because extraction backends are free to implement an
1001                  * extraction algorithm that might be more efficient than
1002                  * processing every file in the "extract file structure" and
1003                  * "extract file metadata" phases.  For example, the current
1004                  * implementation of the UNIX extraction backend will create
1005                  * files on-demand during the "extract file data" phase.
1006                  * Therefore, when using that particular extraction backend, @p
1007                  * end_file_count will only include directories and empty files.
1008                  */
1009                 uint64_t end_file_count;
1010         } extract;
1011
1012         /** Valid on messages ::WIMLIB_PROGRESS_MSG_RENAME. */
1013         struct wimlib_progress_info_rename {
1014                 /** Name of the temporary file that the WIM was written to. */
1015                 const wimlib_tchar *from;
1016
1017                 /** Name of the original WIM file to which the temporary file is
1018                  * being renamed. */
1019                 const wimlib_tchar *to;
1020         } rename;
1021
1022         /** Valid on messages ::WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND and
1023          * ::WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND. */
1024         struct wimlib_progress_info_update {
1025                 /** Pointer to the update command that will be executed or has
1026                  * just been executed. */
1027                 const struct wimlib_update_command *command;
1028
1029                 /** Number of update commands that have been completed so far.
1030                  */
1031                 size_t completed_commands;
1032
1033                 /** Number of update commands that are being executed as part of
1034                  * this call to wimlib_update_image(). */
1035                 size_t total_commands;
1036         } update;
1037
1038         /** Valid on messages ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY and
1039          * ::WIMLIB_PROGRESS_MSG_CALC_INTEGRITY. */
1040         struct wimlib_progress_info_integrity {
1041
1042                 /** The number of bytes in the WIM file that are covered by
1043                  * integrity checks.  */
1044                 uint64_t total_bytes;
1045
1046                 /** The number of bytes that have been checksummed so far.  This
1047                  * starts at 0 and ends at @p total_bytes.  */
1048                 uint64_t completed_bytes;
1049
1050                 /** The number of individually checksummed "chunks" the
1051                  * integrity-checked region is divided into.  */
1052                 uint32_t total_chunks;
1053
1054                 /** The number of chunks that have been checksummed so far.
1055                  * This starts at 0 and ends at @p total_chunks.  */
1056                 uint32_t completed_chunks;
1057
1058                 /** The size of each individually checksummed "chunk" in the
1059                  * integrity-checked region.  */
1060                 uint32_t chunk_size;
1061
1062                 /** For ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY messages, this is
1063                  * the path to the WIM file being checked.  */
1064                 const wimlib_tchar *filename;
1065         } integrity;
1066
1067         /** Valid on messages ::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART and
1068          * ::WIMLIB_PROGRESS_MSG_SPLIT_END_PART. */
1069         struct wimlib_progress_info_split {
1070                 /** Total size of the original WIM's file and metadata resources
1071                  * (compressed). */
1072                 uint64_t total_bytes;
1073
1074                 /** Number of bytes of file and metadata resources that have
1075                  * been copied out of the original WIM so far.  Will be 0
1076                  * initially, and equal to @p total_bytes at the end. */
1077                 uint64_t completed_bytes;
1078
1079                 /** Number of the split WIM part that is about to be started
1080                  * (::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART) or has just been
1081                  * finished (::WIMLIB_PROGRESS_MSG_SPLIT_END_PART). */
1082                 unsigned cur_part_number;
1083
1084                 /** Total number of split WIM parts that are being written.  */
1085                 unsigned total_parts;
1086
1087                 /** Name of the split WIM part that is about to be started
1088                  * (::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART) or has just been
1089                  * finished (::WIMLIB_PROGRESS_MSG_SPLIT_END_PART).  Since
1090                  * wimlib v1.7.0, the library user may change this when
1091                  * receiving ::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART in order to
1092                  * cause the next split WIM part to be written to a different
1093                  * location.  */
1094                 wimlib_tchar *part_name;
1095         } split;
1096
1097         /** Valid on messages ::WIMLIB_PROGRESS_MSG_REPLACE_FILE_IN_WIM  */
1098         struct wimlib_progress_info_replace {
1099                 /** Path to the file in the image that is being replaced  */
1100                 const wimlib_tchar *path_in_wim;
1101         } replace;
1102
1103         /** Valid on messages ::WIMLIB_PROGRESS_MSG_WIMBOOT_EXCLUDE  */
1104         struct wimlib_progress_info_wimboot_exclude {
1105                 /** Path to the file in the image  */
1106                 const wimlib_tchar *path_in_wim;
1107
1108                 /** Path to which the file is being extracted  */
1109                 const wimlib_tchar *extraction_path;
1110         } wimboot_exclude;
1111
1112         /** Valid on messages ::WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN.  */
1113         struct wimlib_progress_info_unmount {
1114                 /** Path to directory being unmounted  */
1115                 const wimlib_tchar *mountpoint;
1116
1117                 /** Path to WIM file being unmounted  */
1118                 const wimlib_tchar *mounted_wim;
1119
1120                 /** 1-based index of image being unmounted.  */
1121                 uint32_t mounted_image;
1122
1123                 /** Flags that were passed to wimlib_mount_image() when the
1124                  * mountpoint was set up.  */
1125                 uint32_t mount_flags;
1126
1127                 /** Flags passed to wimlib_unmount_image().  */
1128                 uint32_t unmount_flags;
1129         } unmount;
1130
1131         /** Valid on messages ::WIMLIB_PROGRESS_MSG_DONE_WITH_FILE.  */
1132         struct wimlib_progress_info_done_with_file {
1133                 /**
1134                  * Path to the file whose data has been written to the WIM file,
1135                  * or is currently being asynchronously compressed in memory,
1136                  * and therefore is no longer needed by wimlib.
1137                  *
1138                  * WARNING: The file data will not actually be accessible in the
1139                  * WIM file until the WIM file has been completely written.
1140                  * Ordinarily you should <b>not</b> treat this message as a
1141                  * green light to go ahead and delete the specified file, since
1142                  * that would result in data loss if the WIM file cannot be
1143                  * successfully created for any reason.
1144                  *
1145                  * If a file has multiple names (hard links),
1146                  * ::WIMLIB_PROGRESS_MSG_DONE_WITH_FILE will only be received
1147                  * for one name.  Also, this message will not be received for
1148                  * empty files or reparse points (or symbolic links), unless
1149                  * they have nonempty named data streams.
1150                  */
1151                 const wimlib_tchar *path_to_file;
1152         } done_with_file;
1153
1154         /** Valid on messages ::WIMLIB_PROGRESS_MSG_BEGIN_VERIFY_IMAGE and
1155          * ::WIMLIB_PROGRESS_MSG_END_VERIFY_IMAGE.  */
1156         struct wimlib_progress_info_verify_image {
1157                 const wimlib_tchar *wimfile;
1158                 uint32_t total_images;
1159                 uint32_t current_image;
1160         } verify_image;
1161
1162         /** Valid on messages ::WIMLIB_PROGRESS_MSG_VERIFY_STREAMS.  */
1163         struct wimlib_progress_info_verify_streams {
1164                 const wimlib_tchar *wimfile;
1165                 uint64_t total_streams;
1166                 uint64_t total_bytes;
1167                 uint64_t completed_streams;
1168                 uint64_t completed_bytes;
1169         } verify_streams;
1170
1171         /** Valid on messages ::WIMLIB_PROGRESS_MSG_TEST_FILE_EXCLUSION.  */
1172         struct wimlib_progress_info_test_file_exclusion {
1173
1174                 /**
1175                  * Path to the file for which exclusion is being tested.
1176                  *
1177                  * UNIX capture mode:  The path will be a standard relative or
1178                  * absolute UNIX filesystem path.
1179                  *
1180                  * NTFS-3G capture mode:  The path will be given relative to the
1181                  * root of the NTFS volume, with a leading slash.
1182                  *
1183                  * Windows capture mode:  The path will be a Win32 namespace
1184                  * path to the file.
1185                  */
1186                 const wimlib_tchar *path;
1187
1188                 /**
1189                  * Indicates whether the file or directory will be excluded from
1190                  * capture or not.  This will be <c>false</c> by default.  The
1191                  * progress function can set this to <c>true</c> if it decides
1192                  * that the file needs to be excluded.
1193                  */
1194                 bool will_exclude;
1195         } test_file_exclusion;
1196
1197         /** Valid on messages ::WIMLIB_PROGRESS_MSG_HANDLE_ERROR.  */
1198         struct wimlib_progress_info_handle_error {
1199
1200                 /** Path to the file for which the error occurred, or NULL if
1201                  * not relevant.  */
1202                 const wimlib_tchar *path;
1203
1204                 /** The wimlib error code associated with the error.  */
1205                 int error_code;
1206
1207                 /**
1208                  * Indicates whether the error will be ignored or not.  This
1209                  * will be <c>false</c> by default; the progress function may
1210                  * set it to <c>true</c>.
1211                  */
1212                 bool will_ignore;
1213         } handle_error;
1214 };
1215
1216 /**
1217  * A user-supplied function that will be called periodically during certain WIM
1218  * operations.
1219  *
1220  * The first argument will be the type of operation that is being performed or
1221  * is about to be started or has been completed.
1222  *
1223  * The second argument will be a pointer to one of a number of structures
1224  * depending on the first argument.  It may be @c NULL for some message types.
1225  * Note that although this argument is not @c const, users should not modify it
1226  * except in explicitly documented cases.
1227  *
1228  * The third argument will be a user-supplied value that was provided when
1229  * registering or specifying the progress function.
1230  *
1231  * This function must return one of the ::wimlib_progress_status values.  By
1232  * default, you should return ::WIMLIB_PROGRESS_STATUS_CONTINUE (0).
1233  */
1234 typedef enum wimlib_progress_status
1235         (*wimlib_progress_func_t)(enum wimlib_progress_msg msg_type,
1236                                   union wimlib_progress_info *info,
1237                                   void *progctx);
1238
1239 /** @} */
1240 /** @addtogroup G_modifying_wims
1241  * @{ */
1242
1243 /** An array of these structures is passed to wimlib_add_image_multisource() to
1244  * specify the sources from which to create a WIM image. */
1245 struct wimlib_capture_source {
1246         /** Absolute or relative path to a file or directory on the external
1247          * filesystem to be included in the image. */
1248         wimlib_tchar *fs_source_path;
1249
1250         /** Destination path in the image.  To specify the root directory of the
1251          * image, use ::WIMLIB_WIM_ROOT_PATH.  */
1252         wimlib_tchar *wim_target_path;
1253
1254         /** Reserved; set to 0. */
1255         long reserved;
1256 };
1257
1258 /** Set or unset the "readonly" WIM header flag (<c>WIM_HDR_FLAG_READONLY</c> in
1259  * Microsoft's documentation), based on the ::wimlib_wim_info.is_marked_readonly
1260  * member of the @p info parameter.  This is distinct from basic file
1261  * permissions; this flag can be set on a WIM file that is physically writable.
1262  *
1263  * wimlib disallows modifying on-disk WIM files with the readonly flag set.
1264  * However, wimlib_overwrite() with ::WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG
1265  * will override this --- and in fact, this is necessary to set the readonly
1266  * flag persistently on an existing WIM file.
1267  */
1268 #define WIMLIB_CHANGE_READONLY_FLAG             0x00000001
1269
1270 /** Set the GUID (globally unique identifier) of the WIM file to the value
1271  * specified in ::wimlib_wim_info.guid of the @p info parameter. */
1272 #define WIMLIB_CHANGE_GUID                      0x00000002
1273
1274 /** Change the bootable image of the WIM to the value specified in
1275  * ::wimlib_wim_info.boot_index of the @p info parameter.  */
1276 #define WIMLIB_CHANGE_BOOT_INDEX                0x00000004
1277
1278 /** Change the <c>WIM_HDR_FLAG_RP_FIX</c> flag of the WIM file to the value
1279  * specified in ::wimlib_wim_info.has_rpfix of the @p info parameter.  This flag
1280  * generally indicates whether an image in the WIM has been captured with
1281  * reparse-point fixups enabled.  wimlib also treats this flag as specifying
1282  * whether to do reparse-point fixups by default when capturing or applying WIM
1283  * images.  */
1284 #define WIMLIB_CHANGE_RPFIX_FLAG                0x00000008
1285
1286 /** @} */
1287
1288 /** @addtogroup G_wim_information  */
1289
1290 /** @{ */
1291
1292 /**
1293  * General information about a WIM file.
1294  *
1295  * This info can also be requested for a ::WIMStruct that does not have a
1296  * backing file.  In this case, fields that only make sense given a backing file
1297  * are set to default values.
1298  */
1299 struct wimlib_wim_info {
1300
1301         /** The globally unique identifier for this WIM.  (Note: all parts of a
1302          * split WIM normally have identical GUIDs.)  */
1303         uint8_t guid[WIMLIB_GUID_LEN];
1304
1305         /** The number of images in this WIM file.  */
1306         uint32_t image_count;
1307
1308         /** The 1-based index of the bootable image in this WIM file, or 0 if no
1309          * image is bootable.  */
1310         uint32_t boot_index;
1311
1312         /** The version of the WIM file format used in this WIM file.  */
1313         uint32_t wim_version;
1314
1315         /** The default compression chunk size of resources in this WIM file.
1316          */
1317         uint32_t chunk_size;
1318
1319         /** For split WIMs, the 1-based index of this part within the split WIM;
1320          * otherwise 1.  */
1321         uint16_t part_number;
1322
1323         /** For split WIMs, the total number of parts in the split WIM;
1324          * otherwise 1.  */
1325         uint16_t total_parts;
1326
1327         /** The default compression type of resources in this WIM file, as one
1328          * of the ::wimlib_compression_type constants.  */
1329         int32_t compression_type;
1330
1331         /** The size of this WIM file in bytes, excluding the XML data and
1332          * integrity table.  */
1333         uint64_t total_bytes;
1334
1335         /** 1 iff this WIM file has an integrity table.  */
1336         uint32_t has_integrity_table : 1;
1337
1338         /** 1 iff this info struct is for a ::WIMStruct that has a backing file.
1339          */
1340         uint32_t opened_from_file : 1;
1341
1342         /** 1 iff this WIM file is considered readonly for any reason (e.g. the
1343          * "readonly" header flag is set, or this is part of a split WIM, or
1344          * filesystem permissions deny writing)  */
1345         uint32_t is_readonly : 1;
1346
1347         /** 1 iff the "reparse point fix" flag is set in this WIM's header  */
1348         uint32_t has_rpfix : 1;
1349
1350         /** 1 iff the "readonly" flag is set in this WIM's header  */
1351         uint32_t is_marked_readonly : 1;
1352
1353         /** 1 iff the "spanned" flag is set in this WIM's header  */
1354         uint32_t spanned : 1;
1355
1356         /** 1 iff the "write in progress" flag is set in this WIM's header  */
1357         uint32_t write_in_progress : 1;
1358
1359         /** 1 iff the "metadata only" flag is set in this WIM's header  */
1360         uint32_t metadata_only : 1;
1361
1362         /** 1 iff the "resource only" flag is set in this WIM's header  */
1363         uint32_t resource_only : 1;
1364
1365         /** 1 iff this WIM file is pipable (see ::WIMLIB_WRITE_FLAG_PIPABLE).  */
1366         uint32_t pipable : 1;
1367         uint32_t reserved_flags : 22;
1368         uint32_t reserved[9];
1369 };
1370
1371 /**
1372  * Information about a "blob", which is a fixed length sequence of binary data.
1373  * Each nonempty stream of each file in a WIM image is associated with a blob.
1374  * Blobs are deduplicated within a WIM file.
1375  *
1376  * TODO: this struct needs to be renamed, and perhaps made into a union since
1377  * there are several cases.  I'll try to list them below:
1378  *
1379  * 1. The blob is "missing", meaning that it is referenced by hash but not
1380  *    actually present in the WIM file.  In this case we only know the
1381  *    sha1_hash.  This case can only occur with wimlib_iterate_dir_tree(), never
1382  *    wimlib_iterate_lookup_table().
1383  *
1384  * 2. Otherwise we know the sha1_hash, the uncompressed_size, the
1385  *    reference_count, and the is_metadata flag.  In addition:
1386  *
1387  *    A. If the blob is located in a non-solid WIM resource, then we also know
1388  *       the compressed_size and offset.
1389  *
1390  *    B. If the blob is located in a solid WIM resource, then we also know the
1391  *       offset, raw_resource_offset_in_wim, raw_resource_compressed_size, and
1392  *       raw_resource_uncompressed_size.  But the "offset" is actually the
1393  *       offset in the uncompressed solid resource rather than the offset from
1394  *       the beginning of the WIM file.
1395  *
1396  *    C. If the blob is *not* located in any type of WIM resource, then we don't
1397  *       know any additional information.
1398  *
1399  * Unknown or irrelevant fields are left zeroed.
1400  */
1401 struct wimlib_resource_entry {
1402
1403         /** If this blob is not missing, then this is the uncompressed size of
1404          * this blob in bytes.  */
1405         uint64_t uncompressed_size;
1406
1407         /** If this blob is located in a non-solid WIM resource, then this is
1408          * the compressed size of that resource.  */
1409         uint64_t compressed_size;
1410
1411         /** If this blob is located in a non-solid WIM resource, then this is
1412          * the offset of that resource within the WIM file containing it.  If
1413          * this blob is located in a solid WIM resource, then this is the offset
1414          * of this blob within that solid resource when uncompressed.  */
1415         uint64_t offset;
1416
1417         /** The SHA-1 message digest of the blob's uncompressed contents.  */
1418         uint8_t sha1_hash[20];
1419
1420         /** If this blob is located in a WIM resource, then this is the part
1421          * number of the WIM file containing it.  */
1422         uint32_t part_number;
1423
1424         /** If this blob is not missing, then this is the number of times this
1425          * blob is referenced over all images in the WIM.  This number is not
1426          * guaranteed to be correct.  */
1427         uint32_t reference_count;
1428
1429         /** 1 iff this blob is located in a non-solid compressed WIM resource.
1430          */
1431         uint32_t is_compressed : 1;
1432
1433         /** 1 iff this blob contains the metadata for an image.  */
1434         uint32_t is_metadata : 1;
1435
1436         uint32_t is_free : 1;
1437         uint32_t is_spanned : 1;
1438
1439         /** 1 iff a blob with this hash was not found in the blob lookup table
1440          * of the ::WIMStruct.  This normally implies a missing call to
1441          * wimlib_reference_resource_files() or wimlib_reference_resources(). */
1442         uint32_t is_missing : 1;
1443
1444         /** 1 iff this blob is located in a solid resource.  */
1445         uint32_t packed : 1;
1446
1447         uint32_t reserved_flags : 26;
1448
1449         /** If this blob is located in a solid WIM resource, then this is the
1450          * offset of that solid resource within the WIM file containing it.  */
1451         uint64_t raw_resource_offset_in_wim;
1452
1453         /** If this blob is located in a solid WIM resource, then this is the
1454          * compressed size of that solid resource.  */
1455         uint64_t raw_resource_compressed_size;
1456
1457         /** If this blob is located in a solid WIM resource, then this is the
1458          * uncompressed size of that solid resource.  */
1459         uint64_t raw_resource_uncompressed_size;
1460
1461         uint64_t reserved[1];
1462 };
1463
1464 /**
1465  * Information about a stream of a particular file in the WIM.
1466  *
1467  * Normally, only WIM images captured from NTFS filesystems will have multiple
1468  * streams per file.  In practice, this is a rarely used feature of the
1469  * filesystem.
1470  *
1471  * TODO: the library now explicitly tracks stream types, which allows it to have
1472  * multiple unnamed streams (e.g. both a reparse point stream and unnamed data
1473  * stream).  However, this isn't yet exposed by wimlib_iterate_dir_tree().
1474  */
1475 struct wimlib_stream_entry {
1476
1477         /** Name of the stream, or NULL if the stream is unnamed.  */
1478         const wimlib_tchar *stream_name;
1479
1480         /** Info about this stream's data, such as its hash and size if known.*/
1481         struct wimlib_resource_entry resource;
1482
1483         uint64_t reserved[4];
1484 };
1485
1486 /**
1487  * Since wimlib v1.9.1: an object ID, which is an extra piece of metadata that
1488  * may be associated with a file on NTFS filesystems.  See:
1489  * https://msdn.microsoft.com/en-us/library/windows/desktop/aa363997(v=vs.85).aspx
1490  */
1491 struct wimlib_object_id {
1492         uint8_t object_id[WIMLIB_GUID_LEN];
1493         uint8_t birth_volume_id[WIMLIB_GUID_LEN];
1494         uint8_t birth_object_id[WIMLIB_GUID_LEN];
1495         uint8_t domain_id[WIMLIB_GUID_LEN];
1496 };
1497
1498 /** Structure passed to the wimlib_iterate_dir_tree() callback function.
1499  * Roughly, the information about a "file" in the WIM image --- but really a
1500  * directory entry ("dentry") because hard links are allowed.  The
1501  * hard_link_group_id field can be used to distinguish actual file inodes.  */
1502 struct wimlib_dir_entry {
1503         /** Name of the file, or NULL if this file is unnamed.  Only the root
1504          * directory of an image will be unnamed.  */
1505         const wimlib_tchar *filename;
1506
1507         /** 8.3 name (or "DOS name", or "short name") of this file; or NULL if
1508          * this file has no such name.  */
1509         const wimlib_tchar *dos_name;
1510
1511         /** Full path to this file within the image.  Path separators will be
1512          * ::WIMLIB_WIM_PATH_SEPARATOR.  */
1513         const wimlib_tchar *full_path;
1514
1515         /** Depth of this directory entry, where 0 is the root, 1 is the root's
1516          * children, ..., etc. */
1517         size_t depth;
1518
1519         /** Pointer to the security descriptor for this file, in Windows
1520          * SECURITY_DESCRIPTOR_RELATIVE format, or NULL if this file has no
1521          * security descriptor.  */
1522         const char *security_descriptor;
1523
1524         /** Size of the above security descriptor, in bytes.  */
1525         size_t security_descriptor_size;
1526
1527 #define WIMLIB_FILE_ATTRIBUTE_READONLY            0x00000001
1528 #define WIMLIB_FILE_ATTRIBUTE_HIDDEN              0x00000002
1529 #define WIMLIB_FILE_ATTRIBUTE_SYSTEM              0x00000004
1530 #define WIMLIB_FILE_ATTRIBUTE_DIRECTORY           0x00000010
1531 #define WIMLIB_FILE_ATTRIBUTE_ARCHIVE             0x00000020
1532 #define WIMLIB_FILE_ATTRIBUTE_DEVICE              0x00000040
1533 #define WIMLIB_FILE_ATTRIBUTE_NORMAL              0x00000080
1534 #define WIMLIB_FILE_ATTRIBUTE_TEMPORARY           0x00000100
1535 #define WIMLIB_FILE_ATTRIBUTE_SPARSE_FILE         0x00000200
1536 #define WIMLIB_FILE_ATTRIBUTE_REPARSE_POINT       0x00000400
1537 #define WIMLIB_FILE_ATTRIBUTE_COMPRESSED          0x00000800
1538 #define WIMLIB_FILE_ATTRIBUTE_OFFLINE             0x00001000
1539 #define WIMLIB_FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000
1540 #define WIMLIB_FILE_ATTRIBUTE_ENCRYPTED           0x00004000
1541 #define WIMLIB_FILE_ATTRIBUTE_VIRTUAL             0x00010000
1542         /** File attributes, such as whether the file is a directory or not.
1543          * These are the "standard" Windows FILE_ATTRIBUTE_* values, although in
1544          * wimlib.h they are defined as WIMLIB_FILE_ATTRIBUTE_* for convenience
1545          * on other platforms.  */
1546         uint32_t attributes;
1547
1548 #define WIMLIB_REPARSE_TAG_RESERVED_ZERO        0x00000000
1549 #define WIMLIB_REPARSE_TAG_RESERVED_ONE         0x00000001
1550 #define WIMLIB_REPARSE_TAG_MOUNT_POINT          0xA0000003
1551 #define WIMLIB_REPARSE_TAG_HSM                  0xC0000004
1552 #define WIMLIB_REPARSE_TAG_HSM2                 0x80000006
1553 #define WIMLIB_REPARSE_TAG_DRIVER_EXTENDER      0x80000005
1554 #define WIMLIB_REPARSE_TAG_SIS                  0x80000007
1555 #define WIMLIB_REPARSE_TAG_DFS                  0x8000000A
1556 #define WIMLIB_REPARSE_TAG_DFSR                 0x80000012
1557 #define WIMLIB_REPARSE_TAG_FILTER_MANAGER       0x8000000B
1558 #define WIMLIB_REPARSE_TAG_WOF                  0x80000017
1559 #define WIMLIB_REPARSE_TAG_SYMLINK              0xA000000C
1560         /** If the file is a reparse point (FILE_ATTRIBUTE_REPARSE_POINT set in
1561          * the attributes), this will give the reparse tag.  This tells you
1562          * whether the reparse point is a symbolic link, junction point, or some
1563          * other, more unusual kind of reparse point.  */
1564         uint32_t reparse_tag;
1565
1566         /** Number of links to this file's inode (hard links).
1567          *
1568          * Currently, this will always be 1 for directories.  However, it can be
1569          * greater than 1 for nondirectory files.  */
1570         uint32_t num_links;
1571
1572         /** Number of named data streams this file has.  Normally 0.  */
1573         uint32_t num_named_streams;
1574
1575         /** A unique identifier for this file's inode.  However, as a special
1576          * case, if the inode only has a single link (@p num_links == 1), this
1577          * value may be 0.
1578          *
1579          * Note: if a WIM image is captured from a filesystem, this value is not
1580          * guaranteed to be the same as the original number of the inode on the
1581          * filesystem.  */
1582         uint64_t hard_link_group_id;
1583
1584         /** Time this file was created.  */
1585         wimlib_timespec creation_time;
1586
1587         /** Time this file was last written to.  */
1588         wimlib_timespec last_write_time;
1589
1590         /** Time this file was last accessed.  */
1591         wimlib_timespec last_access_time;
1592
1593         /** The UNIX user ID of this file.  This is a wimlib extension.
1594          *
1595          * This field is only valid if @p unix_mode != 0.  */
1596         uint32_t unix_uid;
1597
1598         /** The UNIX group ID of this file.  This is a wimlib extension.
1599          *
1600          * This field is only valid if @p unix_mode != 0.  */
1601         uint32_t unix_gid;
1602
1603         /** The UNIX mode of this file.  This is a wimlib extension.
1604          *
1605          * If this field is 0, then @p unix_uid, @p unix_gid, @p unix_mode, and
1606          * @p unix_rdev are all unknown (fields are not present in the WIM
1607          * image).  */
1608         uint32_t unix_mode;
1609
1610         /** The UNIX device ID (major and minor number) of this file.  This is a
1611          * wimlib extension.
1612          *
1613          * This field is only valid if @p unix_mode != 0.  */
1614         uint32_t unix_rdev;
1615
1616         /* The object ID of this file, if any.  Only valid if
1617          * object_id.object_id is not all zeroes.  */
1618         struct wimlib_object_id object_id;
1619
1620         uint64_t reserved[6];
1621
1622         /**
1623          * Variable-length array of streams that make up this file.
1624          *
1625          * The first entry will always exist and will correspond to the unnamed
1626          * data stream (default file contents), so it will have <c>stream_name
1627          * == NULL</c>.  Alternatively, for reparse point files, the first entry
1628          * will correspond to the reparse data stream.  Alternatively, for
1629          * encrypted files, the first entry will correspond to the encrypted
1630          * data.
1631          *
1632          * Then, following the first entry, there be @p num_named_streams
1633          * additional entries that specify the named data streams, if any, each
1634          * of which will have <c>stream_name != NULL</c>.
1635          */
1636         struct wimlib_stream_entry streams[];
1637 };
1638
1639 /**
1640  * Type of a callback function to wimlib_iterate_dir_tree().  Must return 0 on
1641  * success.
1642  */
1643 typedef int (*wimlib_iterate_dir_tree_callback_t)(const struct wimlib_dir_entry *dentry,
1644                                                   void *user_ctx);
1645
1646 /**
1647  * Type of a callback function to wimlib_iterate_lookup_table().  Must return 0
1648  * on success.
1649  */
1650 typedef int (*wimlib_iterate_lookup_table_callback_t)(const struct wimlib_resource_entry *resource,
1651                                                       void *user_ctx);
1652
1653 /** For wimlib_iterate_dir_tree(): Iterate recursively on children rather than
1654  * just on the specified path. */
1655 #define WIMLIB_ITERATE_DIR_TREE_FLAG_RECURSIVE 0x00000001
1656
1657 /** For wimlib_iterate_dir_tree(): Don't iterate on the file or directory
1658  * itself; only its children (in the case of a non-empty directory) */
1659 #define WIMLIB_ITERATE_DIR_TREE_FLAG_CHILDREN  0x00000002
1660
1661 /** Return ::WIMLIB_ERR_RESOURCE_NOT_FOUND if any file data blobs needed to fill
1662  * in the ::wimlib_resource_entry's for the iteration cannot be found in the
1663  * blob lookup table of the ::WIMStruct.  The default behavior without this flag
1664  * is to fill in the @ref wimlib_resource_entry::sha1_hash "sha1_hash" and set
1665  * the @ref wimlib_resource_entry::is_missing "is_missing" flag.  */
1666 #define WIMLIB_ITERATE_DIR_TREE_FLAG_RESOURCES_NEEDED  0x00000004
1667
1668
1669 /** @} */
1670 /** @addtogroup G_modifying_wims
1671  * @{ */
1672
1673 /** UNIX-like systems only: Directly capture an NTFS volume rather than a
1674  * generic directory.  This requires that wimlib was compiled with support for
1675  * libntfs-3g.
1676  *
1677  * This flag cannot be combined with ::WIMLIB_ADD_FLAG_DEREFERENCE or
1678  * ::WIMLIB_ADD_FLAG_UNIX_DATA.
1679  *
1680  * Do not use this flag on Windows, where wimlib already supports all
1681  * Windows-native filesystems, including NTFS, through the Windows APIs.  */
1682 #define WIMLIB_ADD_FLAG_NTFS                    0x00000001
1683
1684 /** Follow symbolic links when scanning the directory tree.  Currently only
1685  * supported on UNIX-like systems.  */
1686 #define WIMLIB_ADD_FLAG_DEREFERENCE             0x00000002
1687
1688 /** Call the progress function with the message
1689  * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY when each directory or file has been
1690  * scanned.  */
1691 #define WIMLIB_ADD_FLAG_VERBOSE                 0x00000004
1692
1693 /** Mark the image being added as the bootable image of the WIM.  This flag is
1694  * valid only for wimlib_add_image() and wimlib_add_image_multisource().
1695  *
1696  * Note that you can also change the bootable image of a WIM using
1697  * wimlib_set_wim_info().
1698  *
1699  * Note: ::WIMLIB_ADD_FLAG_BOOT does something different from, and independent
1700  * from, ::WIMLIB_ADD_FLAG_WIMBOOT.  */
1701 #define WIMLIB_ADD_FLAG_BOOT                    0x00000008
1702
1703 /** UNIX-like systems only: Store the UNIX owner, group, mode, and device ID
1704  * (major and minor number) of each file.  In addition, capture special files
1705  * such as device nodes and FIFOs.  See the documentation for the
1706  * <b>--unix-data</b> option to <b>wimcapture</b> for more information.  */
1707 #define WIMLIB_ADD_FLAG_UNIX_DATA               0x00000010
1708
1709 /** Do not capture security descriptors.  Only has an effect in NTFS-3G capture
1710  * mode, or in Windows native builds.  */
1711 #define WIMLIB_ADD_FLAG_NO_ACLS                 0x00000020
1712
1713 /** Fail immediately if the full security descriptor of any file or directory
1714  * cannot be accessed.  Only has an effect in Windows native builds.  The
1715  * default behavior without this flag is to first try omitting the SACL from the
1716  * security descriptor, then to try omitting the security descriptor entirely.
1717  */
1718 #define WIMLIB_ADD_FLAG_STRICT_ACLS             0x00000040
1719
1720 /** Call the progress function with the message
1721  * ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY when a directory or file is excluded from
1722  * capture.  This is a subset of the messages provided by
1723  * ::WIMLIB_ADD_FLAG_VERBOSE.  */
1724 #define WIMLIB_ADD_FLAG_EXCLUDE_VERBOSE         0x00000080
1725
1726 /** Reparse-point fixups:  Modify absolute symbolic links (and junctions, in the
1727  * case of Windows) that point inside the directory being captured to instead be
1728  * absolute relative to the directory being captured.
1729  *
1730  * Without this flag, the default is to do reparse-point fixups if
1731  * <c>WIM_HDR_FLAG_RP_FIX</c> is set in the WIM header or if this is the first
1732  * image being added.  */
1733 #define WIMLIB_ADD_FLAG_RPFIX                   0x00000100
1734
1735 /** Don't do reparse point fixups.  See ::WIMLIB_ADD_FLAG_RPFIX.  */
1736 #define WIMLIB_ADD_FLAG_NORPFIX                 0x00000200
1737
1738 /** Do not automatically exclude unsupported files or directories from capture,
1739  * such as encrypted files in NTFS-3G capture mode, or device files and FIFOs on
1740  * UNIX-like systems when not also using ::WIMLIB_ADD_FLAG_UNIX_DATA.  Instead,
1741  * fail with ::WIMLIB_ERR_UNSUPPORTED_FILE when such a file is encountered.  */
1742 #define WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE  0x00000400
1743
1744 /**
1745  * Automatically select a capture configuration appropriate for capturing
1746  * filesystems containing Windows operating systems.  For example,
1747  * <c>/pagefile.sys</c> and <c>"/System Volume Information"</c> will be
1748  * excluded.
1749  *
1750  * When this flag is specified, the corresponding @p config parameter (for
1751  * wimlib_add_image()) or member (for wimlib_update_image()) must be @c NULL.
1752  * Otherwise, ::WIMLIB_ERR_INVALID_PARAM will be returned.
1753  *
1754  * Note that the default behavior--- that is, when neither
1755  * ::WIMLIB_ADD_FLAG_WINCONFIG nor ::WIMLIB_ADD_FLAG_WIMBOOT is specified and @p
1756  * config is @c NULL--- is to use no capture configuration, meaning that no
1757  * files are excluded from capture.
1758  */
1759 #define WIMLIB_ADD_FLAG_WINCONFIG               0x00000800
1760
1761 /**
1762  * Capture image as "WIMBoot compatible".  In addition, if no capture
1763  * configuration file is explicitly specified use the capture configuration file
1764  * <c>$SOURCE/Windows/System32/WimBootCompress.ini</c> if it exists, where
1765  * <c>$SOURCE</c> is the directory being captured; or, if a capture
1766  * configuration file is explicitly specified, use it and also place it at
1767  * <c>/Windows/System32/WimBootCompress.ini</c> in the WIM image.
1768  *
1769  * This flag does not, by itself, change the compression type or chunk size.
1770  * Before writing the WIM file, you may wish to set the compression format to
1771  * be the same as that used by WIMGAPI and DISM:
1772  *
1773  * \code
1774  *      wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_XPRESS);
1775  *      wimlib_set_output_chunk_size(wim, 4096);
1776  * \endcode
1777  *
1778  * However, "WIMBoot" also works with other XPRESS chunk sizes as well as LZX
1779  * with 32768 byte chunks.
1780  *
1781  * Note: ::WIMLIB_ADD_FLAG_WIMBOOT does something different from, and
1782  * independent from, ::WIMLIB_ADD_FLAG_BOOT.
1783  *
1784  * Since wimlib v1.8.3, ::WIMLIB_ADD_FLAG_WIMBOOT also causes offline WIM-backed
1785  * files to be added as the "real" files rather than as their reparse points,
1786  * provided that their data is already present in the WIM.  This feature can be
1787  * useful when updating a backing WIM file in an "offline" state.
1788  */
1789 #define WIMLIB_ADD_FLAG_WIMBOOT                 0x00001000
1790
1791 /**
1792  * If the add command involves adding a non-directory file to a location at
1793  * which there already exists a nondirectory file in the image, issue
1794  * ::WIMLIB_ERR_INVALID_OVERLAY instead of replacing the file.  This was the
1795  * default behavior before wimlib v1.7.0.
1796  */
1797 #define WIMLIB_ADD_FLAG_NO_REPLACE              0x00002000
1798
1799 /**
1800  * Send ::WIMLIB_PROGRESS_MSG_TEST_FILE_EXCLUSION messages to the progress
1801  * function.
1802  *
1803  * Note: This method for file exclusions is independent from the capture
1804  * configuration file mechanism.
1805  */
1806 #define WIMLIB_ADD_FLAG_TEST_FILE_EXCLUSION     0x00004000
1807
1808 /**
1809  * Since wimlib v1.9.0: create a temporary filesystem snapshot of the source
1810  * directory and add the files from it.  Currently, this option is only
1811  * supported on Windows, where it uses the Volume Shadow Copy Service (VSS).
1812  * Using this option, you can create a consistent backup of the system volume of
1813  * a running Windows system without running into problems with locked files.
1814  * For the VSS snapshot to be successfully created, your application must be run
1815  * as an Administrator, and it cannot be run in WoW64 mode (i.e. if Windows is
1816  * 64-bit, then your application must be 64-bit as well).
1817  */
1818 #define WIMLIB_ADD_FLAG_SNAPSHOT                0x00008000
1819
1820 /**
1821  * Since wimlib v1.9.0: permit the library to discard file paths after the
1822  * initial scan.  If the application won't use
1823  * ::WIMLIB_WRITE_FLAG_SEND_DONE_WITH_FILE_MESSAGES while writing the WIM
1824  * archive, this flag can be used to allow the library to enable optimizations
1825  * such as opening files by inode number rather than by path.  Currently this
1826  * only makes a difference on Windows.
1827  */
1828 #define WIMLIB_ADD_FLAG_FILE_PATHS_UNNEEDED     0x00010000
1829
1830 /** @} */
1831 /** @addtogroup G_modifying_wims
1832  * @{ */
1833
1834 /** Do not issue an error if the path to delete does not exist. */
1835 #define WIMLIB_DELETE_FLAG_FORCE                        0x00000001
1836
1837 /** Delete the file or directory tree recursively; if not specified, an error is
1838  * issued if the path to delete is a directory. */
1839 #define WIMLIB_DELETE_FLAG_RECURSIVE                    0x00000002
1840
1841 /** @} */
1842 /** @addtogroup G_modifying_wims
1843  * @{ */
1844
1845 /**
1846  * If a single image is being exported, mark it bootable in the destination WIM.
1847  * Alternatively, if ::WIMLIB_ALL_IMAGES is specified as the image to export,
1848  * the image in the source WIM (if any) that is marked as bootable is also
1849  * marked as bootable in the destination WIM.
1850  */
1851 #define WIMLIB_EXPORT_FLAG_BOOT                         0x00000001
1852
1853 /** Give the exported image(s) no names.  Avoids problems with image name
1854  * collisions.
1855  */
1856 #define WIMLIB_EXPORT_FLAG_NO_NAMES                     0x00000002
1857
1858 /** Give the exported image(s) no descriptions.  */
1859 #define WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS              0x00000004
1860
1861 /** This advises the library that the program is finished with the source
1862  * WIMStruct and will not attempt to access it after the call to
1863  * wimlib_export_image(), with the exception of the call to wimlib_free().  */
1864 #define WIMLIB_EXPORT_FLAG_GIFT                         0x00000008
1865
1866 /**
1867  * Mark each exported image as WIMBoot-compatible.
1868  *
1869  * Note: by itself, this does change the destination WIM's compression type, nor
1870  * does it add the file @c \\Windows\\System32\\WimBootCompress.ini in the WIM
1871  * image.  Before writing the destination WIM, it's recommended to do something
1872  * like:
1873  *
1874  * \code
1875  *      wimlib_set_output_compression_type(wim, WIMLIB_COMPRESSION_TYPE_XPRESS);
1876  *      wimlib_set_output_chunk_size(wim, 4096);
1877  *      wimlib_add_tree(wim, image, L"myconfig.ini",
1878  *                      L"\\Windows\\System32\\WimBootCompress.ini", 0);
1879  * \endcode
1880  */
1881 #define WIMLIB_EXPORT_FLAG_WIMBOOT                      0x00000010
1882
1883 /** @} */
1884 /** @addtogroup G_extracting_wims
1885  * @{ */
1886
1887 /** Extract the image directly to an NTFS volume rather than a generic directory.
1888  * This mode is only available if wimlib was compiled with libntfs-3g support;
1889  * if not, ::WIMLIB_ERR_UNSUPPORTED will be returned.  In this mode, the
1890  * extraction target will be interpreted as the path to an NTFS volume image (as
1891  * a regular file or block device) rather than a directory.  It will be opened
1892  * using libntfs-3g, and the image will be extracted to the NTFS filesystem's
1893  * root directory.  Note: this flag cannot be used when wimlib_extract_image()
1894  * is called with ::WIMLIB_ALL_IMAGES as the @p image, nor can it be used with
1895  * wimlib_extract_paths() when passed multiple paths.  */
1896 #define WIMLIB_EXTRACT_FLAG_NTFS                        0x00000001
1897
1898 /** UNIX-like systems only:  Extract special UNIX data captured with
1899  * ::WIMLIB_ADD_FLAG_UNIX_DATA.  This flag cannot be combined with
1900  * ::WIMLIB_EXTRACT_FLAG_NTFS.  */
1901 #define WIMLIB_EXTRACT_FLAG_UNIX_DATA                   0x00000020
1902
1903 /** Do not extract security descriptors.  This flag cannot be combined with
1904  * ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS.  */
1905 #define WIMLIB_EXTRACT_FLAG_NO_ACLS                     0x00000040
1906
1907 /**
1908  * Fail immediately if the full security descriptor of any file or directory
1909  * cannot be set exactly as specified in the WIM image.  On Windows, the default
1910  * behavior without this flag when wimlib does not have permission to set the
1911  * correct security descriptor is to fall back to setting the security
1912  * descriptor with the SACL omitted, then with the DACL omitted, then with the
1913  * owner omitted, then not at all.  This flag cannot be combined with
1914  * ::WIMLIB_EXTRACT_FLAG_NO_ACLS.
1915  */
1916 #define WIMLIB_EXTRACT_FLAG_STRICT_ACLS                 0x00000080
1917
1918 /**
1919  * This is the extraction equivalent to ::WIMLIB_ADD_FLAG_RPFIX.  This forces
1920  * reparse-point fixups on, so absolute symbolic links or junction points will
1921  * be fixed to be absolute relative to the actual extraction root.  Reparse-
1922  * point fixups are done by default for wimlib_extract_image() and
1923  * wimlib_extract_image_from_pipe() if <c>WIM_HDR_FLAG_RP_FIX</c> is set in the
1924  * WIM header.  This flag cannot be combined with ::WIMLIB_EXTRACT_FLAG_NORPFIX.
1925  */
1926 #define WIMLIB_EXTRACT_FLAG_RPFIX                       0x00000100
1927
1928 /** Force reparse-point fixups on extraction off, regardless of the state of the
1929  * WIM_HDR_FLAG_RP_FIX flag in the WIM header.  This flag cannot be combined
1930  * with ::WIMLIB_EXTRACT_FLAG_RPFIX.  */
1931 #define WIMLIB_EXTRACT_FLAG_NORPFIX                     0x00000200
1932
1933 /** For wimlib_extract_paths() and wimlib_extract_pathlist() only:  Extract the
1934  * paths, each of which must name a regular file, to standard output.  */
1935 #define WIMLIB_EXTRACT_FLAG_TO_STDOUT                   0x00000400
1936
1937 /**
1938  * Instead of ignoring files and directories with names that cannot be
1939  * represented on the current platform (note: Windows has more restrictions on
1940  * filenames than POSIX-compliant systems), try to replace characters or append
1941  * junk to the names so that they can be extracted in some form.
1942  *
1943  * Note: this flag is unlikely to have any effect when extracting a WIM image
1944  * that was captured on Windows.
1945  */
1946 #define WIMLIB_EXTRACT_FLAG_REPLACE_INVALID_FILENAMES   0x00000800
1947
1948 /**
1949  * On Windows, when there exist two or more files with the same case insensitive
1950  * name but different case sensitive names, try to extract them all by appending
1951  * junk to the end of them, rather than arbitrarily extracting only one.
1952  *
1953  * Note: this flag is unlikely to have any effect when extracting a WIM image
1954  * that was captured on Windows.
1955  */
1956 #define WIMLIB_EXTRACT_FLAG_ALL_CASE_CONFLICTS          0x00001000
1957
1958 /** Do not ignore failure to set timestamps on extracted files.  This flag
1959  * currently only has an effect when extracting to a directory on UNIX-like
1960  * systems.  */
1961 #define WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS           0x00002000
1962
1963 /** Do not ignore failure to set short names on extracted files.  This flag
1964  * currently only has an effect on Windows.  */
1965 #define WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES          0x00004000
1966
1967 /** Do not ignore failure to extract symbolic links and junctions due to
1968  * permissions problems.  This flag currently only has an effect on Windows.  By
1969  * default, such failures are ignored since the default configuration of Windows
1970  * only allows the Administrator to create symbolic links.  */
1971 #define WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS             0x00008000
1972
1973 /**
1974  * For wimlib_extract_paths() and wimlib_extract_pathlist() only:  Treat the
1975  * paths to extract as wildcard patterns ("globs") which may contain the
1976  * wildcard characters @c ? and @c *.  The @c ? character matches any
1977  * non-path-separator character, whereas the @c * character matches zero or more
1978  * non-path-separator characters.  Consequently, each glob may match zero or
1979  * more actual paths in the WIM image.
1980  *
1981  * By default, if a glob does not match any files, a warning but not an error
1982  * will be issued.  This is the case even if the glob did not actually contain
1983  * wildcard characters.  Use ::WIMLIB_EXTRACT_FLAG_STRICT_GLOB to get an error
1984  * instead.
1985  */
1986 #define WIMLIB_EXTRACT_FLAG_GLOB_PATHS                  0x00040000
1987
1988 /** In combination with ::WIMLIB_EXTRACT_FLAG_GLOB_PATHS, causes an error
1989  * (::WIMLIB_ERR_PATH_DOES_NOT_EXIST) rather than a warning to be issued when
1990  * one of the provided globs did not match a file.  */
1991 #define WIMLIB_EXTRACT_FLAG_STRICT_GLOB                 0x00080000
1992
1993 /**
1994  * Do not extract Windows file attributes such as readonly, hidden, etc.
1995  *
1996  * This flag has an effect on Windows as well as in the NTFS-3G extraction mode.
1997  */
1998 #define WIMLIB_EXTRACT_FLAG_NO_ATTRIBUTES               0x00100000
1999
2000 /**
2001  * For wimlib_extract_paths() and wimlib_extract_pathlist() only:  Do not
2002  * preserve the directory structure of the archive when extracting --- that is,
2003  * place each extracted file or directory tree directly in the target directory.
2004  * The target directory will still be created if it does not already exist.
2005  */
2006 #define WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE   0x00200000
2007
2008 /**
2009  * Windows only: Extract files as "pointers" back to the WIM archive.
2010  *
2011  * The effects of this option are fairly complex.  See the documentation for the
2012  * <b>--wimboot</b> option of <b>wimapply</b> for more information.
2013  */
2014 #define WIMLIB_EXTRACT_FLAG_WIMBOOT                     0x00400000
2015
2016 /**
2017  * Since wimlib v1.8.2 and Windows-only: compress the extracted files using
2018  * System Compression, when possible.  This only works on either Windows 10 or
2019  * later, or on an older Windows to which Microsoft's wofadk.sys driver has been
2020  * added.  Several different compression formats may be used with System
2021  * Compression; this particular flag selects the XPRESS compression format with
2022  * 4096 byte chunks.
2023  */
2024 #define WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K            0x01000000
2025
2026 /** Like ::WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K, but use XPRESS compression with
2027  * 8192 byte chunks.  */
2028 #define WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS8K            0x02000000
2029
2030 /** Like ::WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K, but use XPRESS compression with
2031  * 16384 byte chunks.  */
2032 #define WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS16K           0x04000000
2033
2034 /** Like ::WIMLIB_EXTRACT_FLAG_COMPACT_XPRESS4K, but use LZX compression with
2035  * 32768 byte chunks.  */
2036 #define WIMLIB_EXTRACT_FLAG_COMPACT_LZX                 0x08000000
2037
2038 /** @} */
2039 /** @addtogroup G_mounting_wim_images
2040  * @{ */
2041
2042 /** Mount the WIM image read-write rather than the default of read-only. */
2043 #define WIMLIB_MOUNT_FLAG_READWRITE                     0x00000001
2044
2045 /** Enable FUSE debugging by passing the @c -d option to @c fuse_main().  */
2046 #define WIMLIB_MOUNT_FLAG_DEBUG                         0x00000002
2047
2048 /** Do not allow accessing named data streams in the mounted WIM image.  */
2049 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE         0x00000004
2050
2051 /** Access named data streams in the mounted WIM image through extended file
2052  * attributes named "user.X", where X is the name of a data stream.  This is the
2053  * default mode.  */
2054 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR        0x00000008
2055
2056 /** Access named data streams in the mounted WIM image by specifying the file
2057  * name, a colon, then the name of the data stream.  */
2058 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS      0x00000010
2059
2060 /** Use UNIX metadata if available in the WIM image.  See
2061  * ::WIMLIB_ADD_FLAG_UNIX_DATA.  */
2062 #define WIMLIB_MOUNT_FLAG_UNIX_DATA                     0x00000020
2063
2064 /** Allow other users to see the mounted filesystem.  This passes the @c
2065  * allow_other option to fuse_main().  */
2066 #define WIMLIB_MOUNT_FLAG_ALLOW_OTHER                   0x00000040
2067
2068 /** @} */
2069 /** @addtogroup G_creating_and_opening_wims
2070  * @{ */
2071
2072 /** Verify the WIM contents against the WIM's integrity table, if present.  The
2073  * integrity table stores checksums for the raw data of the WIM file, divided
2074  * into fixed size chunks.  Verification will compute checksums and compare them
2075  * with the stored values.  If there are any mismatches, then
2076  * ::WIMLIB_ERR_INTEGRITY will be issued.  If the WIM file does not contain an
2077  * integrity table, then this flag has no effect.  */
2078 #define WIMLIB_OPEN_FLAG_CHECK_INTEGRITY                0x00000001
2079
2080 /** Issue an error (::WIMLIB_ERR_IS_SPLIT_WIM) if the WIM is part of a split
2081  * WIM.  Software can provide this flag for convenience if it explicitly does
2082  * not want to support split WIMs.  */
2083 #define WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT                 0x00000002
2084
2085 /** Check if the WIM is writable and issue an error
2086  * (::WIMLIB_ERR_WIM_IS_READONLY) if it is not.  A WIM is considered writable
2087  * only if it is writable at the filesystem level, does not have the
2088  * <c>WIM_HDR_FLAG_READONLY</c> flag set in its header, and is not part of a
2089  * spanned set.  It is not required to provide this flag before attempting to
2090  * make changes to the WIM, but with this flag you get an error immediately
2091  * rather than potentially much later, when wimlib_overwrite() is finally
2092  * called.  */
2093 #define WIMLIB_OPEN_FLAG_WRITE_ACCESS                   0x00000004
2094
2095 /** @} */
2096 /** @addtogroup G_mounting_wim_images
2097  * @{ */
2098
2099 /** Provide ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY when committing the WIM image.
2100  * Ignored if ::WIMLIB_UNMOUNT_FLAG_COMMIT not also specified.  */
2101 #define WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY             0x00000001
2102
2103 /** Commit changes to the read-write mounted WIM image.
2104  * If this flag is not specified, changes will be discarded.  */
2105 #define WIMLIB_UNMOUNT_FLAG_COMMIT                      0x00000002
2106
2107 /** Provide ::WIMLIB_WRITE_FLAG_REBUILD when committing the WIM image.
2108  * Ignored if ::WIMLIB_UNMOUNT_FLAG_COMMIT not also specified.  */
2109 #define WIMLIB_UNMOUNT_FLAG_REBUILD                     0x00000004
2110
2111 /** Provide ::WIMLIB_WRITE_FLAG_RECOMPRESS when committing the WIM image.
2112  * Ignored if ::WIMLIB_UNMOUNT_FLAG_COMMIT not also specified.  */
2113 #define WIMLIB_UNMOUNT_FLAG_RECOMPRESS                  0x00000008
2114
2115 /**
2116  * In combination with ::WIMLIB_UNMOUNT_FLAG_COMMIT for a read-write mounted WIM
2117  * image, forces all file descriptors to the open WIM image to be closed before
2118  * committing it.
2119  *
2120  * Without ::WIMLIB_UNMOUNT_FLAG_COMMIT or with a read-only mounted WIM image,
2121  * this flag has no effect.
2122  */
2123 #define WIMLIB_UNMOUNT_FLAG_FORCE                       0x00000010
2124
2125 /** In combination with ::WIMLIB_UNMOUNT_FLAG_COMMIT for a read-write mounted
2126  * WIM image, causes the modified image to be committed to the WIM file as a
2127  * new, unnamed image appended to the archive.  The original image in the WIM
2128  * file will be unmodified.  */
2129 #define WIMLIB_UNMOUNT_FLAG_NEW_IMAGE                   0x00000020
2130
2131 /** @} */
2132 /** @addtogroup G_modifying_wims
2133  * @{ */
2134
2135 /** Send ::WIMLIB_PROGRESS_MSG_UPDATE_BEGIN_COMMAND and
2136  * ::WIMLIB_PROGRESS_MSG_UPDATE_END_COMMAND messages.  */
2137 #define WIMLIB_UPDATE_FLAG_SEND_PROGRESS                0x00000001
2138
2139 /** @} */
2140 /** @addtogroup G_writing_and_overwriting_wims
2141  * @{ */
2142
2143 /**
2144  * Include an integrity table in the resulting WIM file.
2145  *
2146  * For ::WIMStruct's created with wimlib_open_wim(), the default behavior is to
2147  * include an integrity table if and only if one was present before.  For
2148  * ::WIMStruct's created with wimlib_create_new_wim(), the default behavior is
2149  * to not include an integrity table.
2150  */
2151 #define WIMLIB_WRITE_FLAG_CHECK_INTEGRITY               0x00000001
2152
2153 /**
2154  * Do not include an integrity table in the resulting WIM file.  This is the
2155  * default behavior, unless the ::WIMStruct was created by opening a WIM with an
2156  * integrity table.
2157  */
2158 #define WIMLIB_WRITE_FLAG_NO_CHECK_INTEGRITY            0x00000002
2159
2160 /**
2161  * Write the WIM as "pipable".  After writing a WIM with this flag specified,
2162  * images from it can be applied directly from a pipe using
2163  * wimlib_extract_image_from_pipe().  See the documentation for the
2164  * <b>--pipable</b> option of <b>wimcapture</b> for more information.  Beware:
2165  * WIMs written with this flag will not be compatible with Microsoft's software.
2166  *
2167  * For ::WIMStruct's created with wimlib_open_wim(), the default behavior is to
2168  * write the WIM as pipable if and only if it was pipable before.  For
2169  * ::WIMStruct's created with wimlib_create_new_wim(), the default behavior is
2170  * to write the WIM as non-pipable.
2171  */
2172 #define WIMLIB_WRITE_FLAG_PIPABLE                       0x00000004
2173
2174 /**
2175  * Do not write the WIM as "pipable".  This is the default behavior, unless the
2176  * ::WIMStruct was created by opening a pipable WIM.
2177  */
2178 #define WIMLIB_WRITE_FLAG_NOT_PIPABLE                   0x00000008
2179
2180 /**
2181  * When writing data to the WIM file, recompress it, even if the data is already
2182  * available in the desired compressed form (for example, in a WIM file from
2183  * which an image has been exported using wimlib_export_image()).
2184  *
2185  * ::WIMLIB_WRITE_FLAG_RECOMPRESS can be used to recompress with a higher
2186  * compression ratio for the same compression type and chunk size.  Simply using
2187  * the default compression settings may suffice for this, especially if the WIM
2188  * file was created using another program/library that may not use as
2189  * sophisticated compression algorithms.  Or,
2190  * wimlib_set_default_compression_level() can be called beforehand to set an
2191  * even higher compression level than the default.
2192  *
2193  * If the WIM contains solid resources, then ::WIMLIB_WRITE_FLAG_RECOMPRESS can
2194  * be used in combination with ::WIMLIB_WRITE_FLAG_SOLID to prevent any solid
2195  * resources from being re-used.  Otherwise, solid resources are re-used
2196  * somewhat more liberally than normal compressed resources.
2197  *
2198  * ::WIMLIB_WRITE_FLAG_RECOMPRESS does <b>not</b> cause recompression of data
2199  * that would not otherwise be written.  For example, a call to
2200  * wimlib_overwrite() with ::WIMLIB_WRITE_FLAG_RECOMPRESS will not, by itself,
2201  * cause already-existing data in the WIM file to be recompressed.  To force the
2202  * WIM file to be fully rebuilt and recompressed, combine
2203  * ::WIMLIB_WRITE_FLAG_RECOMPRESS with ::WIMLIB_WRITE_FLAG_REBUILD.
2204  */
2205 #define WIMLIB_WRITE_FLAG_RECOMPRESS                    0x00000010
2206
2207 /**
2208  * Immediately before closing the WIM file, sync its data to disk.
2209  *
2210  * This flag forces the function to wait until the data is safely on disk before
2211  * returning success.  Otherwise, modern operating systems tend to cache data
2212  * for some time (in some cases, 30+ seconds) before actually writing it to
2213  * disk, even after reporting to the application that the writes have succeeded.
2214  *
2215  * wimlib_overwrite() will set this flag automatically if it decides to
2216  * overwrite the WIM file via a temporary file instead of in-place.  This is
2217  * necessary on POSIX systems; it will, for example, avoid problems with delayed
2218  * allocation on ext4.
2219  */
2220 #define WIMLIB_WRITE_FLAG_FSYNC                         0x00000020
2221
2222 /**
2223  * For wimlib_overwrite(): rebuild the entire WIM file, even if it otherwise
2224  * could be updated in-place by appending to it.  Any data that existed in the
2225  * original WIM file but is not actually needed by any of the remaining images
2226  * will not be included.  This can free up space left over after previous
2227  * in-place modifications to the WIM file.
2228  *
2229  * This flag can be combined with ::WIMLIB_WRITE_FLAG_RECOMPRESS to force all
2230  * data to be recompressed.  Otherwise, compressed data is re-used if possible.
2231  *
2232  * wimlib_write() ignores this flag.
2233  */
2234 #define WIMLIB_WRITE_FLAG_REBUILD                       0x00000040
2235
2236 /**
2237  * For wimlib_overwrite(): override the default behavior after one or more calls
2238  * to wimlib_delete_image(), which is to rebuild the entire WIM file.  With this
2239  * flag, only minimal changes to correctly remove the image from the WIM file
2240  * will be taken.  This can be much faster, but it will result in the WIM file
2241  * getting larger rather than smaller.
2242  *
2243  * wimlib_write() ignores this flag.
2244  */
2245 #define WIMLIB_WRITE_FLAG_SOFT_DELETE                   0x00000080
2246
2247 /**
2248  * For wimlib_overwrite(), allow overwriting the WIM file even if the readonly
2249  * flag (<c>WIM_HDR_FLAG_READONLY</c>) is set in the WIM header.  This can be
2250  * used following a call to wimlib_set_wim_info() with the
2251  * ::WIMLIB_CHANGE_READONLY_FLAG flag to actually set the readonly flag on the
2252  * on-disk WIM file.
2253  *
2254  * wimlib_write() ignores this flag.
2255  */
2256 #define WIMLIB_WRITE_FLAG_IGNORE_READONLY_FLAG          0x00000100
2257
2258 /**
2259  * Do not include file data already present in other WIMs.  This flag can be
2260  * used to write a "delta" WIM after the WIM files on which the delta is to be
2261  * based were referenced with wimlib_reference_resource_files() or
2262  * wimlib_reference_resources().
2263  */
2264 #define WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIMS            0x00000200
2265
2266 /** Deprecated; this flag should not be used outside of the library itself.  */
2267 #define WIMLIB_WRITE_FLAG_STREAMS_OK                    0x00000400
2268
2269 /**
2270  * For wimlib_write(), retain the WIM's GUID instead of generating a new one.
2271  *
2272  * wimlib_overwrite() sets this by default, since the WIM remains, logically,
2273  * the same file.
2274  */
2275 #define WIMLIB_WRITE_FLAG_RETAIN_GUID                   0x00000800
2276
2277 /**
2278  * Concatenate files and compress them together, rather than compress each file
2279  * independently.  This is also known as creating a "solid archive".  This tends
2280  * to produce a better compression ratio at the cost of much slower random
2281  * access.
2282  *
2283  * WIM files created with this flag are only compatible with wimlib v1.6.0 or
2284  * later, WIMGAPI Windows 8 or later, and DISM Windows 8.1 or later.  WIM files
2285  * created with this flag use a different version number in their header (3584
2286  * instead of 68864) and are also called "ESD files".
2287  *
2288  * Note that providing this flag does not affect the "append by default"
2289  * behavior of wimlib_overwrite().  In other words, wimlib_overwrite() with just
2290  * ::WIMLIB_WRITE_FLAG_SOLID can be used to append solid-compressed data to a
2291  * WIM file that originally did not contain any solid-compressed data.  But if
2292  * you instead want to rebuild and recompress an entire WIM file in solid mode,
2293  * then also provide ::WIMLIB_WRITE_FLAG_REBUILD and
2294  * ::WIMLIB_WRITE_FLAG_RECOMPRESS.
2295  *
2296  * Currently, new solid resources will, by default, be written using LZMS
2297  * compression with 64 MiB (67108864 byte) chunks.  Use
2298  * wimlib_set_output_pack_compression_type() and/or
2299  * wimlib_set_output_pack_chunk_size() to change this.  This is independent of
2300  * the WIM's main compression type and chunk size; you can have a WIM that
2301  * nominally uses LZX compression and 32768 byte chunks but actually contains
2302  * LZMS-compressed solid resources, for example.  However, if including solid
2303  * resources, I suggest that you set the WIM's main compression type to LZMS as
2304  * well, either by creating the WIM with
2305  * ::wimlib_create_new_wim(::WIMLIB_COMPRESSION_TYPE_LZMS, ...) or by calling
2306  * ::wimlib_set_output_compression_type(..., ::WIMLIB_COMPRESSION_TYPE_LZMS).
2307  *
2308  * This flag will be set by default when writing or overwriting a WIM file that
2309  * either already contains solid resources, or has had solid resources exported
2310  * into it and the WIM's main compression type is LZMS.
2311  */
2312 #define WIMLIB_WRITE_FLAG_SOLID                         0x00001000
2313
2314 /**
2315  * Send ::WIMLIB_PROGRESS_MSG_DONE_WITH_FILE messages while writing the WIM
2316  * file.  This is only needed in the unusual case that the library user needs to
2317  * know exactly when wimlib has read each file for the last time.
2318  */
2319 #define WIMLIB_WRITE_FLAG_SEND_DONE_WITH_FILE_MESSAGES  0x00002000
2320
2321 /**
2322  * Do not consider content similarity when arranging file data for solid
2323  * compression.  Providing this flag will typically worsen the compression
2324  * ratio, so only provide this flag if you know what you are doing.
2325  */
2326 #define WIMLIB_WRITE_FLAG_NO_SOLID_SORT                 0x00004000
2327
2328 /**
2329  * Since wimlib v1.8.3 and for wimlib_overwrite() only: <b>unsafely</b> compact
2330  * the WIM file in-place, without appending.  Existing resources are shifted
2331  * down to fill holes and new resources are appended as needed.  The WIM file is
2332  * truncated to its final size, which may shrink the on-disk file.  <b>This
2333  * operation cannot be safely interrupted.  If the operation is interrupted,
2334  * then the WIM file will be corrupted, and it may be impossible (or at least
2335  * very difficult) to recover any data from it.  Users of this flag are expected
2336  * to know what they are doing and assume responsibility for any data corruption
2337  * that may result.</b>
2338  *
2339  * If the WIM file cannot be compacted in-place because of its structure, its
2340  * layout, or other requested write parameters, then wimlib_overwrite() fails
2341  * with ::WIMLIB_ERR_COMPACTION_NOT_POSSIBLE, and the caller may wish to retry
2342  * the operation without this flag.
2343  */
2344 #define WIMLIB_WRITE_FLAG_UNSAFE_COMPACT                0x00008000
2345
2346 /** @} */
2347 /** @addtogroup G_general
2348  * @{ */
2349
2350 /** Deprecated; no longer has any effect.  */
2351 #define WIMLIB_INIT_FLAG_ASSUME_UTF8                    0x00000001
2352
2353 /** Windows-only: do not attempt to acquire additional privileges (currently
2354  * SeBackupPrivilege, SeRestorePrivilege, SeSecurityPrivilege,
2355  * SeTakeOwnershipPrivilege, and SeManageVolumePrivilege) when initializing the
2356  * library.  This flag is intended for the case where the calling program
2357  * manages these privileges itself.  Note: by default, no error is issued if
2358  * privileges cannot be acquired, although related errors may be reported later,
2359  * depending on if the operations performed actually require additional
2360  * privileges or not.  */
2361 #define WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES        0x00000002
2362
2363 /** Windows only:  If ::WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES not specified,
2364  * return ::WIMLIB_ERR_INSUFFICIENT_PRIVILEGES if privileges that may be needed
2365  * to read all possible data and metadata for a capture operation could not be
2366  * acquired.  Can be combined with ::WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES.
2367  */
2368 #define WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES      0x00000004
2369
2370 /** Windows only:  If ::WIMLIB_INIT_FLAG_DONT_ACQUIRE_PRIVILEGES not specified,
2371  * return ::WIMLIB_ERR_INSUFFICIENT_PRIVILEGES if privileges that may be needed
2372  * to restore all possible data and metadata for an apply operation could not be
2373  * acquired.  Can be combined with ::WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES.
2374  */
2375 #define WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES        0x00000008
2376
2377 /** Default to interpreting WIM paths case sensitively (default on UNIX-like
2378  * systems).  */
2379 #define WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE         0x00000010
2380
2381 /** Default to interpreting WIM paths case insensitively (default on Windows).
2382  * This does not apply to mounted images.  */
2383 #define WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE       0x00000020
2384
2385 /** @} */
2386 /** @addtogroup G_nonstandalone_wims
2387  * @{ */
2388
2389 /** For wimlib_reference_resource_files(), enable shell-style filename globbing.
2390  * Ignored by wimlib_reference_resources().  */
2391 #define WIMLIB_REF_FLAG_GLOB_ENABLE             0x00000001
2392
2393 /** For wimlib_reference_resource_files(), issue an error
2394  * (::WIMLIB_ERR_GLOB_HAD_NO_MATCHES) if a glob did not match any files.  The
2395  * default behavior without this flag is to issue no error at that point, but
2396  * then attempt to open the glob as a literal path, which of course will fail
2397  * anyway if no file exists at that path.  No effect if
2398  * ::WIMLIB_REF_FLAG_GLOB_ENABLE is not also specified.  Ignored by
2399  * wimlib_reference_resources().  */
2400 #define WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH     0x00000002
2401
2402 /** @} */
2403 /** @addtogroup G_modifying_wims
2404  * @{ */
2405
2406 /** The specific type of update to perform. */
2407 enum wimlib_update_op {
2408         /** Add a new file or directory tree to the image.  */
2409         WIMLIB_UPDATE_OP_ADD = 0,
2410
2411         /** Delete a file or directory tree from the image.  */
2412         WIMLIB_UPDATE_OP_DELETE = 1,
2413
2414         /** Rename a file or directory tree in the image.  */
2415         WIMLIB_UPDATE_OP_RENAME = 2,
2416 };
2417
2418 /** Data for a ::WIMLIB_UPDATE_OP_ADD operation. */
2419 struct wimlib_add_command {
2420         /** Filesystem path to the file or directory tree to add.  */
2421         wimlib_tchar *fs_source_path;
2422
2423         /** Destination path in the image.  To specify the root directory of the
2424          * image, use ::WIMLIB_WIM_ROOT_PATH.  */
2425         wimlib_tchar *wim_target_path;
2426
2427         /** Path to capture configuration file to use, or @c NULL if not
2428          * specified.  */
2429         wimlib_tchar *config_file;
2430
2431         /** Bitwise OR of WIMLIB_ADD_FLAG_* flags. */
2432         int add_flags;
2433 };
2434
2435 /** Data for a ::WIMLIB_UPDATE_OP_DELETE operation. */
2436 struct wimlib_delete_command {
2437
2438         /** The path to the file or directory within the image to delete.  */
2439         wimlib_tchar *wim_path;
2440
2441         /** Bitwise OR of WIMLIB_DELETE_FLAG_* flags.  */
2442         int delete_flags;
2443 };
2444
2445 /** Data for a ::WIMLIB_UPDATE_OP_RENAME operation. */
2446 struct wimlib_rename_command {
2447
2448         /** The path to the source file or directory within the image.  */
2449         wimlib_tchar *wim_source_path;
2450
2451         /** The path to the destination file or directory within the image.  */
2452         wimlib_tchar *wim_target_path;
2453
2454         /** Reserved; set to 0.  */
2455         int rename_flags;
2456 };
2457
2458 /** Specification of an update to perform on a WIM image. */
2459 struct wimlib_update_command {
2460
2461         enum wimlib_update_op op;
2462
2463         union {
2464                 struct wimlib_add_command add;
2465                 struct wimlib_delete_command delete_; /* Underscore is for C++
2466                                                          compatibility.  */
2467                 struct wimlib_rename_command rename;
2468         };
2469 };
2470
2471 /** @} */
2472 /** @addtogroup G_general
2473  * @{ */
2474
2475 /**
2476  * Possible values of the error code returned by many functions in wimlib.
2477  *
2478  * See the documentation for each wimlib function to see specifically what error
2479  * codes can be returned by a given function, and what they mean.
2480  */
2481 enum wimlib_error_code {
2482         WIMLIB_ERR_SUCCESS                            = 0,
2483         WIMLIB_ERR_ALREADY_LOCKED                     = 1,
2484         WIMLIB_ERR_DECOMPRESSION                      = 2,
2485         WIMLIB_ERR_FUSE                               = 6,
2486         WIMLIB_ERR_GLOB_HAD_NO_MATCHES                = 8,
2487         WIMLIB_ERR_IMAGE_COUNT                        = 10,
2488         WIMLIB_ERR_IMAGE_NAME_COLLISION               = 11,
2489         WIMLIB_ERR_INSUFFICIENT_PRIVILEGES            = 12,
2490         WIMLIB_ERR_INTEGRITY                          = 13,
2491         WIMLIB_ERR_INVALID_CAPTURE_CONFIG             = 14,
2492         WIMLIB_ERR_INVALID_CHUNK_SIZE                 = 15,
2493         WIMLIB_ERR_INVALID_COMPRESSION_TYPE           = 16,
2494         WIMLIB_ERR_INVALID_HEADER                     = 17,
2495         WIMLIB_ERR_INVALID_IMAGE                      = 18,
2496         WIMLIB_ERR_INVALID_INTEGRITY_TABLE            = 19,
2497         WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY         = 20,
2498         WIMLIB_ERR_INVALID_METADATA_RESOURCE          = 21,
2499         WIMLIB_ERR_INVALID_OVERLAY                    = 23,
2500         WIMLIB_ERR_INVALID_PARAM                      = 24,
2501         WIMLIB_ERR_INVALID_PART_NUMBER                = 25,
2502         WIMLIB_ERR_INVALID_PIPABLE_WIM                = 26,
2503         WIMLIB_ERR_INVALID_REPARSE_DATA               = 27,
2504         WIMLIB_ERR_INVALID_RESOURCE_HASH              = 28,
2505         WIMLIB_ERR_INVALID_UTF16_STRING               = 30,
2506         WIMLIB_ERR_INVALID_UTF8_STRING                = 31,
2507         WIMLIB_ERR_IS_DIRECTORY                       = 32,
2508         WIMLIB_ERR_IS_SPLIT_WIM                       = 33,
2509         WIMLIB_ERR_LINK                               = 35,
2510         WIMLIB_ERR_METADATA_NOT_FOUND                 = 36,
2511         WIMLIB_ERR_MKDIR                              = 37,
2512         WIMLIB_ERR_MQUEUE                             = 38,
2513         WIMLIB_ERR_NOMEM                              = 39,
2514         WIMLIB_ERR_NOTDIR                             = 40,
2515         WIMLIB_ERR_NOTEMPTY                           = 41,
2516         WIMLIB_ERR_NOT_A_REGULAR_FILE                 = 42,
2517         WIMLIB_ERR_NOT_A_WIM_FILE                     = 43,
2518         WIMLIB_ERR_NOT_PIPABLE                        = 44,
2519         WIMLIB_ERR_NO_FILENAME                        = 45,
2520         WIMLIB_ERR_NTFS_3G                            = 46,
2521         WIMLIB_ERR_OPEN                               = 47,
2522         WIMLIB_ERR_OPENDIR                            = 48,
2523         WIMLIB_ERR_PATH_DOES_NOT_EXIST                = 49,
2524         WIMLIB_ERR_READ                               = 50,
2525         WIMLIB_ERR_READLINK                           = 51,
2526         WIMLIB_ERR_RENAME                             = 52,
2527         WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED         = 54,
2528         WIMLIB_ERR_RESOURCE_NOT_FOUND                 = 55,
2529         WIMLIB_ERR_RESOURCE_ORDER                     = 56,
2530         WIMLIB_ERR_SET_ATTRIBUTES                     = 57,
2531         WIMLIB_ERR_SET_REPARSE_DATA                   = 58,
2532         WIMLIB_ERR_SET_SECURITY                       = 59,
2533         WIMLIB_ERR_SET_SHORT_NAME                     = 60,
2534         WIMLIB_ERR_SET_TIMESTAMPS                     = 61,
2535         WIMLIB_ERR_SPLIT_INVALID                      = 62,
2536         WIMLIB_ERR_STAT                               = 63,
2537         WIMLIB_ERR_UNEXPECTED_END_OF_FILE             = 65,
2538         WIMLIB_ERR_UNICODE_STRING_NOT_REPRESENTABLE   = 66,
2539         WIMLIB_ERR_UNKNOWN_VERSION                    = 67,
2540         WIMLIB_ERR_UNSUPPORTED                        = 68,
2541         WIMLIB_ERR_UNSUPPORTED_FILE                   = 69,
2542         WIMLIB_ERR_WIM_IS_READONLY                    = 71,
2543         WIMLIB_ERR_WRITE                              = 72,
2544         WIMLIB_ERR_XML                                = 73,
2545         WIMLIB_ERR_WIM_IS_ENCRYPTED                   = 74,
2546         WIMLIB_ERR_WIMBOOT                            = 75,
2547         WIMLIB_ERR_ABORTED_BY_PROGRESS                = 76,
2548         WIMLIB_ERR_UNKNOWN_PROGRESS_STATUS            = 77,
2549         WIMLIB_ERR_MKNOD                              = 78,
2550         WIMLIB_ERR_MOUNTED_IMAGE_IS_BUSY              = 79,
2551         WIMLIB_ERR_NOT_A_MOUNTPOINT                   = 80,
2552         WIMLIB_ERR_NOT_PERMITTED_TO_UNMOUNT           = 81,
2553         WIMLIB_ERR_FVE_LOCKED_VOLUME                  = 82,
2554         WIMLIB_ERR_UNABLE_TO_READ_CAPTURE_CONFIG      = 83,
2555         WIMLIB_ERR_WIM_IS_INCOMPLETE                  = 84,
2556         WIMLIB_ERR_COMPACTION_NOT_POSSIBLE            = 85,
2557         WIMLIB_ERR_IMAGE_HAS_MULTIPLE_REFERENCES      = 86,
2558         WIMLIB_ERR_DUPLICATE_EXPORTED_IMAGE           = 87,
2559         WIMLIB_ERR_CONCURRENT_MODIFICATION_DETECTED   = 88,
2560         WIMLIB_ERR_SNAPSHOT_FAILURE                   = 89,
2561 };
2562
2563
2564 /** Used to indicate no image or an invalid image. */
2565 #define WIMLIB_NO_IMAGE         0
2566
2567 /** Used to specify all images in the WIM. */
2568 #define WIMLIB_ALL_IMAGES       (-1)
2569
2570 /** @}  */
2571
2572 /**
2573  * @ingroup G_modifying_wims
2574  *
2575  * Append an empty image to a ::WIMStruct.
2576  *
2577  * The new image will initially contain no files or directories, although if
2578  * written without further modifications, then a root directory will be created
2579  * automatically for it.
2580  *
2581  * After calling this function, you can use wimlib_update_image() to add files
2582  * to the new image.  This gives you more control over making the new image
2583  * compared to calling wimlib_add_image() or wimlib_add_image_multisource().
2584  *
2585  * @param wim
2586  *      Pointer to the ::WIMStruct to which to add the image.
2587  * @param name
2588  *      Name to give the new image.  If @c NULL or empty, the new image is given
2589  *      no name.  If nonempty, it must specify a name that does not already
2590  *      exist in @p wim.
2591  * @param new_idx_ret
2592  *      If non-<c>NULL</c>, the index of the newly added image is returned in
2593  *      this location.
2594  *
2595  * @return 0 on success; a ::wimlib_error_code value on failure.
2596  *
2597  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
2598  *      The WIM already contains an image with the requested name.
2599  */
2600 extern int
2601 wimlib_add_empty_image(WIMStruct *wim,
2602                        const wimlib_tchar *name,
2603                        int *new_idx_ret);
2604
2605 /**
2606  * @ingroup G_modifying_wims
2607  *
2608  * Add an image to a ::WIMStruct from an on-disk directory tree or NTFS volume.
2609  *
2610  * The directory tree or NTFS volume is scanned immediately to load the dentry
2611  * tree into memory, and file metadata is read.  However, actual file data may
2612  * not be read until the ::WIMStruct is persisted to disk using wimlib_write()
2613  * or wimlib_overwrite().
2614  *
2615  * See the documentation for the @b wimlib-imagex program for more information
2616  * about the "normal" capture mode versus the NTFS capture mode (entered by
2617  * providing the flag ::WIMLIB_ADD_FLAG_NTFS).
2618  *
2619  * Note that no changes are committed to disk until wimlib_write() or
2620  * wimlib_overwrite() is called.
2621  *
2622  * @param wim
2623  *      Pointer to the ::WIMStruct to which to add the image.
2624  * @param source
2625  *      A path to a directory or unmounted NTFS volume that will be captured as
2626  *      a WIM image.
2627  * @param name
2628  *      Name to give the new image.  If @c NULL or empty, the new image is given
2629  *      no name.  If nonempty, it must specify a name that does not already
2630  *      exist in @p wim.
2631  * @param config_file
2632  *      Path to capture configuration file, or @c NULL.  This file may specify,
2633  *      among other things, which files to exclude from capture.  See the
2634  *      documentation for <b>wimcapture</b> (<b>--config</b> option) for details
2635  *      of the file format.  If @c NULL, the default capture configuration will
2636  *      be used.  Ordinarily, the default capture configuration will result in
2637  *      no files being excluded from capture purely based on name; however, the
2638  *      ::WIMLIB_ADD_FLAG_WINCONFIG and ::WIMLIB_ADD_FLAG_WIMBOOT flags modify
2639  *      the default.
2640  * @param add_flags
2641  *      Bitwise OR of flags prefixed with WIMLIB_ADD_FLAG.
2642  *
2643  * @return 0 on success; a ::wimlib_error_code value on failure.
2644  *
2645  * This function is implemented by calling wimlib_add_empty_image(), then
2646  * calling wimlib_update_image() with a single "add" command, so any error code
2647  * returned by wimlib_add_empty_image() may be returned, as well as any error
2648  * codes returned by wimlib_update_image() other than ones documented as only
2649  * being returned specifically by an update involving delete or rename commands.
2650  *
2651  * If a progress function is registered with @p wim, then it will receive the
2652  * messages ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN and ::WIMLIB_PROGRESS_MSG_SCAN_END.
2653  * In addition, if ::WIMLIB_ADD_FLAG_VERBOSE is specified in @p add_flags, it
2654  * will receive ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY.
2655  */
2656 extern int
2657 wimlib_add_image(WIMStruct *wim,
2658                  const wimlib_tchar *source,
2659                  const wimlib_tchar *name,
2660                  const wimlib_tchar *config_file,
2661                  int add_flags);
2662
2663 /**
2664  * @ingroup G_modifying_wims
2665  *
2666  * This function is equivalent to wimlib_add_image() except it allows for
2667  * multiple sources to be combined into a single WIM image.  This is done by
2668  * specifying the @p sources and @p num_sources parameters instead of the @p
2669  * source parameter of wimlib_add_image().  The rest of the parameters are the
2670  * same as wimlib_add_image().  See the documentation for <b>wimcapture</b> for
2671  * full details on how this mode works.
2672  */
2673 extern int
2674 wimlib_add_image_multisource(WIMStruct *wim,
2675                              const struct wimlib_capture_source *sources,
2676                              size_t num_sources,
2677                              const wimlib_tchar *name,
2678                              const wimlib_tchar *config_file,
2679                              int add_flags);
2680
2681 /**
2682  * @ingroup G_modifying_wims
2683  *
2684  * Add the file or directory tree at @p fs_source_path on the filesystem to the
2685  * location @p wim_target_path within the specified @p image of the @p wim.
2686  *
2687  * This just builds an appropriate ::wimlib_add_command and passes it to
2688  * wimlib_update_image().
2689  */
2690 extern int
2691 wimlib_add_tree(WIMStruct *wim, int image,
2692                 const wimlib_tchar *fs_source_path,
2693                 const wimlib_tchar *wim_target_path, int add_flags);
2694
2695 /**
2696  * @ingroup G_creating_and_opening_wims
2697  *
2698  * Create a ::WIMStruct which initially contains no images and is not backed by
2699  * an on-disk file.
2700  *
2701  * @param ctype
2702  *      The "output compression type" to assign to the ::WIMStruct.  This is the
2703  *      compression type that will be used if the ::WIMStruct is later persisted
2704  *      to an on-disk file using wimlib_write().
2705  *      <br/>
2706  *      This choice is not necessarily final.  If desired, it can still be
2707  *      changed at any time before wimlib_write() is called, using
2708  *      wimlib_set_output_compression_type().  In addition, if you wish to use a
2709  *      non-default compression chunk size, then you will need to call
2710  *      wimlib_set_output_chunk_size().
2711  * @param wim_ret
2712  *      On success, a pointer to the new ::WIMStruct is written to the memory
2713  *      location pointed to by this parameter.  This ::WIMStruct must be freed
2714  *      using using wimlib_free() when finished with it.
2715  *
2716  * @return 0 on success; a ::wimlib_error_code value on failure.
2717  *
2718  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
2719  *      @p ctype was not a supported compression type.
2720  * @retval ::WIMLIB_ERR_NOMEM
2721  *      Insufficient memory to allocate a new ::WIMStruct.
2722  */
2723 extern int
2724 wimlib_create_new_wim(enum wimlib_compression_type ctype, WIMStruct **wim_ret);
2725
2726 /**
2727  * @ingroup G_modifying_wims
2728  *
2729  * Delete an image, or all images, from a ::WIMStruct.
2730  *
2731  * Note that no changes are committed to disk until wimlib_write() or
2732  * wimlib_overwrite() is called.
2733  *
2734  * @param wim
2735  *      Pointer to the ::WIMStruct from which to delete the image.
2736  * @param image
2737  *      The 1-based index of the image to delete, or ::WIMLIB_ALL_IMAGES to
2738  *      delete all images.
2739  *
2740  * @return 0 on success; a ::wimlib_error_code value on failure.
2741  *
2742  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2743  *      @p image does not exist in the WIM.
2744  *
2745  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2746  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2747  * ::WIMLIB_ERR_READ, or ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which
2748  * indicate failure (for different reasons) to read the metadata resource for an
2749  * image that needed to be deleted.
2750  *
2751  * If this function fails when @p image was ::WIMLIB_ALL_IMAGES, then it's
2752  * possible that some but not all of the images were deleted.
2753  */
2754 extern int
2755 wimlib_delete_image(WIMStruct *wim, int image);
2756
2757 /**
2758  * @ingroup G_modifying_wims
2759  *
2760  * Delete the @p path from the specified @p image of the @p wim.
2761  *
2762  * This just builds an appropriate ::wimlib_delete_command and passes it to
2763  * wimlib_update_image().
2764  */
2765 extern int
2766 wimlib_delete_path(WIMStruct *wim, int image,
2767                    const wimlib_tchar *path, int delete_flags);
2768
2769 /**
2770  * @ingroup G_modifying_wims
2771  *
2772  * Export an image, or all images, from a ::WIMStruct into another ::WIMStruct.
2773  *
2774  * Specifically, if the destination ::WIMStruct contains <tt>n</tt> images, then
2775  * the source image(s) will be appended, in order, starting at destination index
2776  * <tt>n + 1</tt>.  By default, all image metadata will be exported verbatim,
2777  * but certain changes can be made by passing appropriate parameters.
2778  *
2779  * wimlib_export_image() is only an in-memory operation; no changes are
2780  * committed to disk until wimlib_write() or wimlib_overwrite() is called.
2781  *
2782  * A limitation of the current implementation of wimlib_export_image() is that
2783  * the directory tree of a source or destination image cannot be updated
2784  * following an export until one of the two images has been freed from memory.
2785  *
2786  * @param src_wim
2787  *      The WIM from which to export the images, specified as a pointer to the
2788  *      ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1 of a
2789  *      split WIM.  In the case of a WIM file that is not standalone, this
2790  *      ::WIMStruct must have had any needed external resources previously
2791  *      referenced using wimlib_reference_resources() or
2792  *      wimlib_reference_resource_files().
2793  * @param src_image
2794  *      The 1-based index of the image from @p src_wim to export, or
2795  *      ::WIMLIB_ALL_IMAGES.
2796  * @param dest_wim
2797  *      The ::WIMStruct to which to export the images.
2798  * @param dest_name
2799  *      For single-image exports, the name to give the exported image in @p
2800  *      dest_wim.  If left @c NULL, the name from @p src_wim is used.  For
2801  *      ::WIMLIB_ALL_IMAGES exports, this parameter must be left @c NULL; in
2802  *      that case, the names are all taken from @p src_wim.  This parameter is
2803  *      overridden by ::WIMLIB_EXPORT_FLAG_NO_NAMES.
2804  * @param dest_description
2805  *      For single-image exports, the description to give the exported image in
2806  *      the new WIM file.  If left @c NULL, the description from @p src_wim is
2807  *      used.  For ::WIMLIB_ALL_IMAGES exports, this parameter must be left @c
2808  *      NULL; in that case, the description are all taken from @p src_wim.  This
2809  *      parameter is overridden by ::WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS.
2810  * @param export_flags
2811  *      Bitwise OR of flags prefixed with WIMLIB_EXPORT_FLAG.
2812  *
2813  * @return 0 on success; a ::wimlib_error_code value on failure.
2814  *
2815  * @retval ::WIMLIB_ERR_DUPLICATE_EXPORTED_IMAGE
2816  *      One or more of the source images had already been exported into the
2817  *      destination WIM.
2818  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
2819  *      One or more of the names being given to an exported image was already in
2820  *      use in the destination WIM.
2821  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2822  *      @p src_image does not exist in @p src_wim.
2823  * @retval ::WIMLIB_ERR_METADATA_NOT_FOUND
2824  *      At least one of @p src_wim and @p dest_wim does not contain image
2825  *      metadata; for example, one of them represents a non-first part of a
2826  *      split WIM.
2827  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
2828  *      A file data blob that needed to be exported could not be found in the
2829  *      blob lookup table of @p src_wim.  See @ref G_nonstandalone_wims.
2830  *
2831  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2832  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2833  * ::WIMLIB_ERR_READ, or ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which
2834  * indicate failure (for different reasons) to read the metadata resource for an
2835  * image in @p src_wim that needed to be exported.
2836  */
2837 extern int
2838 wimlib_export_image(WIMStruct *src_wim, int src_image,
2839                     WIMStruct *dest_wim,
2840                     const wimlib_tchar *dest_name,
2841                     const wimlib_tchar *dest_description,
2842                     int export_flags);
2843
2844 /**
2845  * @ingroup G_extracting_wims
2846  *
2847  * Extract an image, or all images, from a ::WIMStruct.
2848  *
2849  * The exact behavior of how wimlib extracts files from a WIM image is
2850  * controllable by the @p extract_flags parameter, but there also are
2851  * differences depending on the platform (UNIX-like vs Windows).  See the
2852  * documentation for <b>wimapply</b> for more information, including about the
2853  * NTFS-3G extraction mode.
2854  *
2855  * @param wim
2856  *      The WIM from which to extract the image(s), specified as a pointer to the
2857  *      ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1 of a
2858  *      split WIM.  In the case of a WIM file that is not standalone, this
2859  *      ::WIMStruct must have had any needed external resources previously
2860  *      referenced using wimlib_reference_resources() or
2861  *      wimlib_reference_resource_files().
2862  * @param image
2863  *      The 1-based index of the image to extract, or ::WIMLIB_ALL_IMAGES to
2864  *      extract all images.  Note: ::WIMLIB_ALL_IMAGES is unsupported in NTFS-3G
2865  *      extraction mode.
2866  * @param target
2867  *      A null-terminated string which names the location to which the image(s)
2868  *      will be extracted.  By default, this is interpreted as a path to a
2869  *      directory.  Alternatively, if ::WIMLIB_EXTRACT_FLAG_NTFS is specified in
2870  *      @p extract_flags, then this is interpreted as a path to an unmounted
2871  *      NTFS volume.
2872  * @param extract_flags
2873  *      Bitwise OR of flags prefixed with WIMLIB_EXTRACT_FLAG.
2874  *
2875  * @return 0 on success; a ::wimlib_error_code value on failure.
2876  *
2877  * @retval ::WIMLIB_ERR_DECOMPRESSION
2878  *      The WIM file contains invalid compressed data.
2879  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2880  *      @p image does not exist in @p wim.
2881  * @retval ::WIMLIB_ERR_INVALID_METADATA_RESOURCE
2882  *      The metadata for an image to extract was invalid.
2883  * @retval ::WIMLIB_ERR_INVALID_PARAM
2884  *      The extraction flags were invalid; more details may be found in the
2885  *      documentation for the specific extraction flags that were specified.  Or
2886  *      @p target was @c NULL or an empty string, or @p wim was @c NULL.
2887  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
2888  *      The data of a file that needed to be extracted was corrupt.
2889  * @retval ::WIMLIB_ERR_LINK
2890  *      Failed to create a symbolic link or a hard link.
2891  * @retval ::WIMLIB_ERR_METADATA_NOT_FOUND
2892  *      @p wim does not contain image metadata; for example, it represents a
2893  *      non-first part of a split WIM.
2894  * @retval ::WIMLIB_ERR_MKDIR
2895  *      Failed create a directory.
2896  * @retval ::WIMLIB_ERR_NTFS_3G
2897  *      libntfs-3g reported that a problem occurred while writing to the NTFS
2898  *      volume.
2899  * @retval ::WIMLIB_ERR_OPEN
2900  *      Could not create a file, or failed to open an already-extracted file.
2901  * @retval ::WIMLIB_ERR_READ
2902  *      Failed to read data from the WIM.
2903  * @retval ::WIMLIB_ERR_READLINK
2904  *      Failed to determine the target of a symbolic link in the WIM.
2905  * @retval ::WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED
2906  *      Failed to fix the target of an absolute symbolic link (e.g. if the
2907  *      target would have exceeded the maximum allowed length).  (Only if
2908  *      reparse data was supported by the extraction mode and
2909  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS was specified in @p
2910  *      extract_flags.)
2911  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
2912  *      A file data blob that needed to be extracted could not be found in the
2913  *      blob lookup table of @p wim.  See @ref G_nonstandalone_wims.
2914  * @retval ::WIMLIB_ERR_SET_ATTRIBUTES
2915  *      Failed to set attributes on a file.
2916  * @retval ::WIMLIB_ERR_SET_REPARSE_DATA
2917  *      Failed to set reparse data on a file (only if reparse data was supported
2918  *      by the extraction mode).
2919  * @retval ::WIMLIB_ERR_SET_SECURITY
2920  *      Failed to set security descriptor on a file.
2921  * @retval ::WIMLIB_ERR_SET_SHORT_NAME
2922  *      Failed to set the short name of a file.
2923  * @retval ::WIMLIB_ERR_SET_TIMESTAMPS
2924  *      Failed to set timestamps on a file.
2925  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
2926  *      Unexpected end-of-file occurred when reading data from the WIM.
2927  * @retval ::WIMLIB_ERR_UNSUPPORTED
2928  *      A requested extraction flag, or the data or metadata that must be
2929  *      extracted to support it, is unsupported in the build and configuration
2930  *      of wimlib, or on the current platform or extraction mode or target
2931  *      volume.  Flags affected by this include ::WIMLIB_EXTRACT_FLAG_NTFS,
2932  *      ::WIMLIB_EXTRACT_FLAG_UNIX_DATA, ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS,
2933  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES,
2934  *      ::WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS, and
2935  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS.  For example, if
2936  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES is specified in @p
2937  *      extract_flags, ::WIMLIB_ERR_UNSUPPORTED will be returned if the WIM
2938  *      image contains one or more files with short names, but extracting short
2939  *      names is not supported --- on Windows, this occurs if the target volume
2940  *      does not support short names, while on non-Windows, this occurs if
2941  *      ::WIMLIB_EXTRACT_FLAG_NTFS was not specified in @p extract_flags.
2942  * @retval ::WIMLIB_ERR_WIMBOOT
2943  *      ::WIMLIB_EXTRACT_FLAG_WIMBOOT was specified in @p extract_flags, but
2944  *      there was a problem creating WIMBoot pointer files or registering a
2945  *      source WIM file with the Windows Overlay Filesystem (WOF) driver.
2946  * @retval ::WIMLIB_ERR_WRITE
2947  *      Failed to write data to a file being extracted.
2948  *
2949  * If a progress function is registered with @p wim, then as each image is
2950  * extracted it will receive ::WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_BEGIN, then
2951  * zero or more ::WIMLIB_PROGRESS_MSG_EXTRACT_FILE_STRUCTURE messages, then zero
2952  * or more ::WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS messages, then zero or more
2953  * ::WIMLIB_PROGRESS_MSG_EXTRACT_METADATA messages, then
2954  * ::WIMLIB_PROGRESS_MSG_EXTRACT_IMAGE_END.
2955  */
2956 extern int
2957 wimlib_extract_image(WIMStruct *wim, int image,
2958                      const wimlib_tchar *target, int extract_flags);
2959
2960 /**
2961  * @ingroup G_extracting_wims
2962  *
2963  * Extract one image from a pipe on which a pipable WIM is being sent.
2964  *
2965  * See the documentation for ::WIMLIB_WRITE_FLAG_PIPABLE, and @ref
2966  * subsec_pipable_wims, for more information about pipable WIMs.
2967  *
2968  * This function operates in a special way to read the WIM fully sequentially.
2969  * As a result, there is no ::WIMStruct is made visible to library users, and
2970  * you cannot call wimlib_open_wim() on the pipe.  (You can, however, use
2971  * wimlib_open_wim() to transparently open a pipable WIM if it's available as a
2972  * seekable file, not a pipe.)
2973  *
2974  * @param pipe_fd
2975  *      File descriptor, which may be a pipe, opened for reading and positioned
2976  *      at the start of the pipable WIM.
2977  * @param image_num_or_name
2978  *      String that specifies the 1-based index or name of the image to extract.
2979  *      It is translated to an image index using the same rules that
2980  *      wimlib_resolve_image() uses.  However, unlike wimlib_extract_image(),
2981  *      only a single image (not all images) can be specified.  Alternatively,
2982  *      specify @p NULL here to use the first image in the WIM if it contains
2983  *      exactly one image but otherwise return ::WIMLIB_ERR_INVALID_IMAGE.
2984  * @param target
2985  *      Same as the corresponding parameter to wimlib_extract_image().
2986  * @param extract_flags
2987  *      Same as the corresponding parameter to wimlib_extract_image().
2988  *
2989  * @return 0 on success; a ::wimlib_error_code value on failure.  The possible
2990  * error codes include those returned by wimlib_extract_image() and
2991  * wimlib_open_wim() as well as the following:
2992  *
2993  * @retval ::WIMLIB_ERR_INVALID_PIPABLE_WIM
2994  *      Data read from the pipable WIM was invalid.
2995  * @retval ::WIMLIB_ERR_NOT_PIPABLE
2996  *      The WIM being piped over @p pipe_fd is a normal WIM, not a pipable WIM.
2997  */
2998 extern int
2999 wimlib_extract_image_from_pipe(int pipe_fd,
3000                                const wimlib_tchar *image_num_or_name,
3001                                const wimlib_tchar *target, int extract_flags);
3002
3003 /**
3004  * @ingroup G_extracting_wims
3005  *
3006  * Same as wimlib_extract_image_from_pipe(), but allows specifying a progress
3007  * function.  The progress function will be used while extracting the image and
3008  * will receive the normal extraction progress messages, such as
3009  * ::WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS, in addition to
3010  * ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN.
3011  */
3012 extern int
3013 wimlib_extract_image_from_pipe_with_progress(int pipe_fd,
3014                                              const wimlib_tchar *image_num_or_name,
3015                                              const wimlib_tchar *target,
3016                                              int extract_flags,
3017                                              wimlib_progress_func_t progfunc,
3018                                              void *progctx);
3019
3020 /**
3021  * @ingroup G_extracting_wims
3022  *
3023  * Similar to wimlib_extract_paths(), but the paths to extract from the WIM
3024  * image are specified in the ASCII, UTF-8, or UTF-16LE text file named by @p
3025  * path_list_file which itself contains the list of paths to use, one per line.
3026  * Leading and trailing whitespace is ignored.  Empty lines and lines beginning
3027  * with the ';' or '#' characters are ignored.  No quotes are needed, as paths
3028  * are otherwise delimited by the newline character.  However, quotes will be
3029  * stripped if present.
3030  *
3031  * The error codes are the same as those returned by wimlib_extract_paths(),
3032  * except that wimlib_extract_pathlist() returns an appropriate error code if it
3033  * cannot read the path list file (e.g. ::WIMLIB_ERR_OPEN, ::WIMLIB_ERR_STAT,
3034  * ::WIMLIB_ERR_READ).
3035  */
3036 extern int
3037 wimlib_extract_pathlist(WIMStruct *wim, int image,
3038                         const wimlib_tchar *target,
3039                         const wimlib_tchar *path_list_file,
3040                         int extract_flags);
3041
3042 /**
3043  * @ingroup G_extracting_wims
3044  *
3045  * Extract zero or more paths (files or directory trees) from the specified WIM
3046  * image.
3047  *
3048  * By default, each path will be extracted to a corresponding subdirectory of
3049  * the target based on its location in the image.  For example, if one of the
3050  * paths to extract is <c>/Windows/explorer.exe</c> and the target is
3051  * <c>outdir</c>, the file will be extracted to
3052  * <c>outdir/Windows/explorer.exe</c>.  This behavior can be changed by
3053  * providing the flag ::WIMLIB_EXTRACT_FLAG_NO_PRESERVE_DIR_STRUCTURE, which
3054  * will cause each file or directory tree to be placed directly in the target
3055  * directory --- so the same example would extract <c>/Windows/explorer.exe</c>
3056  * to <c>outdir/explorer.exe</c>.
3057  *
3058  * With globbing turned off (the default), paths are always checked for
3059  * existence strictly; that is, if any path to extract does not exist in the
3060  * image, then nothing is extracted and the function fails with
3061  * ::WIMLIB_ERR_PATH_DOES_NOT_EXIST.  But with globbing turned on
3062  * (::WIMLIB_EXTRACT_FLAG_GLOB_PATHS specified), globs are by default permitted
3063  * to match no files, and there is a flag (::WIMLIB_EXTRACT_FLAG_STRICT_GLOB) to
3064  * enable the strict behavior if desired.
3065  *
3066  * Symbolic links are not dereferenced when paths in the image are interpreted.
3067  *
3068  * @param wim
3069  *      WIM from which to extract the paths, specified as a pointer to the
3070  *      ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1 of a
3071  *      split WIM.  In the case of a WIM file that is not standalone, this
3072  *      ::WIMStruct must have had any needed external resources previously
3073  *      referenced using wimlib_reference_resources() or
3074  *      wimlib_reference_resource_files().
3075  * @param image
3076  *      The 1-based index of the WIM image from which to extract the paths.
3077  * @param paths
3078  *      Array of paths to extract.  Each element must be the absolute path to a
3079  *      file or directory within the image.  Path separators may be either
3080  *      forwards or backwards slashes, and leading path separators are optional.
3081  *      The paths will be interpreted either case-sensitively (UNIX default) or
3082  *      case-insensitively (Windows default); however, the case sensitivity can
3083  *      be configured explicitly at library initialization time by passing an
3084  *      appropriate flag to wimlib_global_init().
3085  *      <br/>
3086  *      By default, "globbing" is disabled, so the characters @c * and @c ? are
3087  *      interpreted literally.  This can be changed by specifying
3088  *      ::WIMLIB_EXTRACT_FLAG_GLOB_PATHS in @p extract_flags.
3089  * @param num_paths
3090  *      Number of paths specified in @p paths.
3091  * @param target
3092  *      Directory to which to extract the paths.
3093  * @param extract_flags
3094  *      Bitwise OR of flags prefixed with WIMLIB_EXTRACT_FLAG.
3095  *
3096  * @return 0 on success; a ::wimlib_error_code value on failure.  Most of the
3097  * error codes are the same as those returned by wimlib_extract_image().  Below,
3098  * some of the error codes returned in situations specific to path-mode
3099  * extraction are documented:
3100  *
3101  * @retval ::WIMLIB_ERR_NOT_A_REGULAR_FILE
3102  *      ::WIMLIB_EXTRACT_FLAG_TO_STDOUT was specified in @p extract_flags, but
3103  *      one of the paths to extract did not name a regular file.
3104  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
3105  *      One of the paths to extract does not exist in the image; see discussion
3106  *      above about strict vs. non-strict behavior.
3107  *
3108  * If a progress function is registered with @p wim, then it will receive
3109  * ::WIMLIB_PROGRESS_MSG_EXTRACT_STREAMS.
3110  */
3111 extern int
3112 wimlib_extract_paths(WIMStruct *wim,
3113                      int image,
3114                      const wimlib_tchar *target,
3115                      const wimlib_tchar * const *paths,
3116                      size_t num_paths,
3117                      int extract_flags);
3118
3119 /**
3120  * @ingroup G_wim_information
3121  *
3122  * Similar to wimlib_get_xml_data(), but the XML document will be written to the
3123  * specified standard C <c>FILE*</c> instead of retrieved in an in-memory
3124  * buffer.
3125  *
3126  * @return 0 on success; a ::wimlib_error_code value on failure.  This may
3127  * return any error code which can be returned by wimlib_get_xml_data() as well
3128  * as the following error codes:
3129  *
3130  * @retval ::WIMLIB_ERR_WRITE
3131  *      Failed to write the data to the requested file.
3132  */
3133 extern int
3134 wimlib_extract_xml_data(WIMStruct *wim, FILE *fp);
3135
3136 /**
3137  * @ingroup G_general
3138  *
3139  * Release a reference to a ::WIMStruct.  If the ::WIMStruct is still referenced
3140  * by other ::WIMStruct's (e.g. following calls to wimlib_export_image() or
3141  * wimlib_reference_resources()), then the library will free it later, when the
3142  * last reference is released; otherwise it is freed immediately and any
3143  * associated file descriptors are closed.
3144  *
3145  * @param wim
3146  *      Pointer to the ::WIMStruct to release.  If @c NULL, no action is taken.
3147  */
3148 extern void
3149 wimlib_free(WIMStruct *wim);
3150
3151 /**
3152  * @ingroup G_general
3153  *
3154  * Convert a ::wimlib_compression_type value into a string.
3155  *
3156  * @param ctype
3157  *      The compression type value to convert.
3158  *
3159  * @return
3160  *      A statically allocated string naming the compression type, such as
3161  *      "None", "LZX", or "XPRESS".  If the value was unrecognized, then
3162  *      the resulting string will be "Invalid".
3163  */
3164 extern const wimlib_tchar *
3165 wimlib_get_compression_type_string(enum wimlib_compression_type ctype);
3166
3167 /**
3168  * @ingroup G_general
3169  *
3170  * Convert a wimlib error code into a string describing it.
3171  *
3172  * @param code
3173  *      An error code returned by one of wimlib's functions.
3174  *
3175  * @return
3176  *      Pointer to a statically allocated string describing the error code.  If
3177  *      the value was unrecognized, then the resulting string will be "Unknown
3178  *      error".
3179  */
3180 extern const wimlib_tchar *
3181 wimlib_get_error_string(enum wimlib_error_code code);
3182
3183 /**
3184  * @ingroup G_wim_information
3185  *
3186  * Get the description of the specified image.  Equivalent to
3187  * <tt>wimlib_get_image_property(wim, image, "DESCRIPTION")</tt>.
3188  */
3189 extern const wimlib_tchar *
3190 wimlib_get_image_description(const WIMStruct *wim, int image);
3191
3192 /**
3193  * @ingroup G_wim_information
3194  *
3195  * Get the name of the specified image.  Equivalent to
3196  * <tt>wimlib_get_image_property(wim, image, "NAME")</tt>, except that
3197  * wimlib_get_image_name() will return an empty string if the image is unnamed
3198  * whereas wimlib_get_image_property() may return @c NULL in that case.
3199  */
3200 extern const wimlib_tchar *
3201 wimlib_get_image_name(const WIMStruct *wim, int image);
3202
3203 /**
3204  * @ingroup G_wim_information
3205  *
3206  * Since wimlib v1.8.3: get a per-image property from the WIM's XML document.
3207  * This is an alternative to wimlib_get_image_name() and
3208  * wimlib_get_image_description() which allows getting any simple string
3209  * property.
3210  *
3211  * @param wim
3212  *      Pointer to the ::WIMStruct for the WIM.
3213  * @param image
3214  *      The 1-based index of the image for which to get the property.
3215  * @param property_name
3216  *      The name of the image property, for example "NAME", "DESCRIPTION", or
3217  *      "TOTALBYTES".  The name can contain forward slashes to indicate a nested
3218  *      XML element; for example, "WINDOWS/VERSION/BUILD" indicates the BUILD
3219  *      element nested within the VERSION element nested within the WINDOWS
3220  *      element.  Since wimlib v1.9.0, a bracketed number can be used to
3221  *      indicate one of several identically-named elements; for example,
3222  *      "WINDOWS/LANGUAGES/LANGUAGE[2]" indicates the second "LANGUAGE" element
3223  *      nested within the "WINDOWS/LANGUAGES" element.  Note that element names
3224  *      are case sensitive.
3225  *
3226  * @return
3227  *      The property's value as a ::wimlib_tchar string, or @c NULL if there is
3228  *      no such property.  The string may not remain valid after later library
3229  *      calls, so the caller should duplicate it if needed.
3230  */
3231 extern const wimlib_tchar *
3232 wimlib_get_image_property(const WIMStruct *wim, int image,
3233                           const wimlib_tchar *property_name);
3234
3235 /**
3236  * @ingroup G_general
3237  *
3238  * Return the version of wimlib as a 32-bit number whose top 12 bits contain the
3239  * major version, the next 10 bits contain the minor version, and the low 10
3240  * bits contain the patch version.
3241  *
3242  * In other words, the returned value is equal to <c>((WIMLIB_MAJOR_VERSION <<
3243  * 20) | (WIMLIB_MINOR_VERSION << 10) | WIMLIB_PATCH_VERSION)</c> for the
3244  * corresponding header file.
3245  */
3246 extern uint32_t
3247 wimlib_get_version(void);
3248
3249 /**
3250  * @ingroup G_wim_information
3251  *
3252  * Get basic information about a WIM file.
3253  *
3254  * @param wim
3255  *      Pointer to the ::WIMStruct to query.  This need not represent a
3256  *      standalone WIM (e.g. it could represent part of a split WIM).
3257  * @param info
3258  *      A ::wimlib_wim_info structure that will be filled in with information
3259  *      about the WIM file.
3260  *
3261  * @return 0
3262  */
3263 extern int
3264 wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info);
3265
3266 /**
3267  * @ingroup G_wim_information
3268  *
3269  * Read a WIM file's XML document into an in-memory buffer.
3270  *
3271  * The XML document contains metadata about the WIM file and the images stored
3272  * in it.
3273  *
3274  * @param wim
3275  *      Pointer to the ::WIMStruct to query.  This need not represent a
3276  *      standalone WIM (e.g. it could represent part of a split WIM).
3277  * @param buf_ret
3278  *      On success, a pointer to an allocated buffer containing the raw UTF16-LE
3279  *      XML document is written to this location.
3280  * @param bufsize_ret
3281  *      The size of the XML document in bytes is written to this location.
3282  *
3283  * @return 0 on success; a ::wimlib_error_code value on failure.
3284  *
3285  * @retval ::WIMLIB_ERR_NO_FILENAME
3286  *      @p wim is not backed by a file and therefore does not have an XML
3287  *      document.
3288  * @retval ::WIMLIB_ERR_READ
3289  *      Failed to read the XML document from the WIM file.
3290  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
3291  *      Failed to read the XML document from the WIM file.
3292  */
3293 extern int
3294 wimlib_get_xml_data(WIMStruct *wim, void **buf_ret, size_t *bufsize_ret);
3295
3296 /**
3297  * @ingroup G_general
3298  *
3299  * Initialization function for wimlib.  Call before using any other wimlib
3300  * function (except possibly wimlib_set_print_errors()).  If not done manually,
3301  * this function will be called automatically with a flags argument of 0.  This
3302  * function does nothing if called again after it has already successfully run.
3303  *
3304  * @param init_flags
3305  *      Bitwise OR of flags prefixed with WIMLIB_INIT_FLAG.
3306  *
3307  * @return 0 on success; a ::wimlib_error_code value on failure.
3308  *
3309  * @retval ::WIMLIB_ERR_INSUFFICIENT_PRIVILEGES
3310  *      ::WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES and/or
3311  *      ::WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES were specified in @p
3312  *      init_flags, but the corresponding privileges could not be acquired.
3313  */
3314 extern int
3315 wimlib_global_init(int init_flags);
3316
3317 /**
3318  * @ingroup G_general
3319  *
3320  * Cleanup function for wimlib.  You are not required to call this function, but
3321  * it will release any global resources allocated by the library.
3322  */
3323 extern void
3324 wimlib_global_cleanup(void);
3325
3326 /**
3327  * @ingroup G_wim_information
3328  *
3329  * Determine if an image name is already used by some image in the WIM.
3330  *
3331  * @param wim
3332  *      Pointer to the ::WIMStruct to query.  This need not represent a
3333  *      standalone WIM (e.g. it could represent part of a split WIM).
3334  * @param name
3335  *      The name to check.
3336  *
3337  * @return
3338  *      @c true if there is already an image in @p wim named @p name; @c false
3339  *      if there is no image named @p name in @p wim.  If @p name is @c NULL or
3340  *      the empty string, then @c false is returned.
3341  */
3342 extern bool
3343 wimlib_image_name_in_use(const WIMStruct *wim, const wimlib_tchar *name);
3344
3345 /**
3346  * @ingroup G_wim_information
3347  *
3348  * Iterate through a file or directory tree in a WIM image.  By specifying
3349  * appropriate flags and a callback function, you can get the attributes of a
3350  * file in the image, get a directory listing, or even get a listing of the
3351  * entire image.
3352  *
3353  * @param wim
3354  *      The ::WIMStruct containing the image(s) over which to iterate.  This
3355  *      ::WIMStruct must contain image metadata, so it cannot be the non-first
3356  *      part of a split WIM (for example).
3357  * @param image
3358  *      The 1-based index of the image that contains the files or directories to
3359  *      iterate over, or ::WIMLIB_ALL_IMAGES to iterate over all images.
3360  * @param path
3361  *      Path in the image at which to do the iteration.
3362  * @param flags
3363  *      Bitwise OR of flags prefixed with WIMLIB_ITERATE_DIR_TREE_FLAG.
3364  * @param cb
3365  *      A callback function that will receive each directory entry.
3366  * @param user_ctx
3367  *      An extra parameter that will always be passed to the callback function
3368  *      @p cb.
3369  *
3370  * @return Normally, returns 0 if all calls to @p cb returned 0; otherwise the
3371  * first nonzero value that was returned from @p cb.  However, additional
3372  * ::wimlib_error_code values may be returned, including the following:
3373  *
3374  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3375  *      @p image does not exist in @p wim.
3376  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
3377  *      @p path does not exist in the image.
3378  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
3379  *      ::WIMLIB_ITERATE_DIR_TREE_FLAG_RESOURCES_NEEDED was specified, but the
3380  *      data for some files could not be found in the blob lookup table of @p
3381  *      wim.
3382  *
3383  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
3384  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
3385  * ::WIMLIB_ERR_READ, or ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which
3386  * indicate failure (for different reasons) to read the metadata resource for an
3387  * image over which iteration needed to be done.
3388  */
3389 extern int
3390 wimlib_iterate_dir_tree(WIMStruct *wim, int image, const wimlib_tchar *path,
3391                         int flags,
3392                         wimlib_iterate_dir_tree_callback_t cb, void *user_ctx);
3393
3394 /**
3395  * @ingroup G_wim_information
3396  *
3397  * Iterate through the blob lookup table of a ::WIMStruct.  This can be used to
3398  * directly get a listing of the unique "blobs" contained in a WIM file, which
3399  * are deduplicated over all images.
3400  *
3401  * Specifically, each listed blob may be from any of the following sources:
3402  *
3403  * - Metadata blobs, if the ::WIMStruct contains image metadata
3404  * - File blobs from the on-disk WIM file (if any) backing the ::WIMStruct
3405  * - File blobs from files that have been added to the in-memory ::WIMStruct,
3406  *   e.g. by using wimlib_add_image()
3407  * - File blobs from external WIMs referenced by
3408  *   wimlib_reference_resource_files() or wimlib_reference_resources()
3409  *
3410  * @param wim
3411  *      Pointer to the ::WIMStruct for which to get the blob listing.
3412  * @param flags
3413  *      Reserved; set to 0.
3414  * @param cb
3415  *      A callback function that will receive each blob.
3416  * @param user_ctx
3417  *      An extra parameter that will always be passed to the callback function
3418  *      @p cb.
3419  *
3420  * @return 0 if all calls to @p cb returned 0; otherwise the first nonzero value
3421  * that was returned from @p cb.
3422  */
3423 extern int
3424 wimlib_iterate_lookup_table(WIMStruct *wim, int flags,
3425                             wimlib_iterate_lookup_table_callback_t cb,
3426                             void *user_ctx);
3427
3428 /**
3429  * @ingroup G_nonstandalone_wims
3430  *
3431  * Join a split WIM into a stand-alone (one-part) WIM.
3432  *
3433  * @param swms
3434  *      An array of strings that gives the filenames of all parts of the split
3435  *      WIM.  No specific order is required, but all parts must be included with
3436  *      no duplicates.
3437  * @param num_swms
3438  *      Number of filenames in @p swms.
3439  * @param swm_open_flags
3440  *      Open flags for the split WIM parts (e.g.
3441  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY).
3442  * @param wim_write_flags
3443  *      Bitwise OR of relevant flags prefixed with WIMLIB_WRITE_FLAG, which will
3444  *      be used to write the joined WIM.
3445  * @param output_path
3446  *      The path to write the joined WIM file to.
3447  *
3448  * @return 0 on success; a ::wimlib_error_code value on failure.  This function
3449  * may return most error codes that can be returned by wimlib_open_wim() and
3450  * wimlib_write(), as well as the following error codes:
3451  *
3452  * @retval ::WIMLIB_ERR_SPLIT_INVALID
3453  *      The split WIMs do not form a valid WIM because they do not include all
3454  *      the parts of the original WIM, there are duplicate parts, or not all the
3455  *      parts have the same GUID and compression type.
3456  *
3457  * Note: wimlib is generalized enough that this function is not actually needed
3458  * to join a split WIM; instead, you could open the first part of the split WIM,
3459  * then reference the other parts with wimlib_reference_resource_files(), then
3460  * write the joined WIM using wimlib_write().  However, wimlib_join() provides
3461  * an easy-to-use wrapper around this that has some advantages (e.g.  extra
3462  * sanity checks).
3463  */
3464 extern int
3465 wimlib_join(const wimlib_tchar * const *swms,
3466             unsigned num_swms,
3467             const wimlib_tchar *output_path,
3468             int swm_open_flags,
3469             int wim_write_flags);
3470
3471 /**
3472  * @ingroup G_nonstandalone_wims
3473  *
3474  * Same as wimlib_join(), but allows specifying a progress function.  The
3475  * progress function will receive the write progress messages, such as
3476  * ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS, while writing the joined WIM.  In
3477  * addition, if ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY is specified in @p
3478  * swm_open_flags, the progress function will receive a series of
3479  * ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY messages when each of the split WIM
3480  * parts is opened.
3481  */
3482 extern int
3483 wimlib_join_with_progress(const wimlib_tchar * const *swms,
3484                           unsigned num_swms,
3485                           const wimlib_tchar *output_path,
3486                           int swm_open_flags,
3487                           int wim_write_flags,
3488                           wimlib_progress_func_t progfunc,
3489                           void *progctx);
3490
3491
3492 /**
3493  * @ingroup G_mounting_wim_images
3494  *
3495  * Mount an image from a WIM file on a directory read-only or read-write.
3496  *
3497  * @param wim
3498  *      Pointer to the ::WIMStruct containing the image to be mounted.  This
3499  *      ::WIMStruct must have a backing file.
3500  * @param image
3501  *      The 1-based index of the image to mount.  This image cannot have been
3502  *      previously modified in memory.
3503  * @param dir
3504  *      The path to an existing empty directory on which to mount the image.
3505  * @param mount_flags
3506  *      Bitwise OR of flags prefixed with WIMLIB_MOUNT_FLAG.  Use
3507  *      ::WIMLIB_MOUNT_FLAG_READWRITE to request a read-write mount instead of a
3508  *      read-only mount.
3509  * @param staging_dir
3510  *      If non-NULL, the name of a directory in which a temporary directory for
3511  *      storing modified or added files will be created.  Ignored if
3512  *      ::WIMLIB_MOUNT_FLAG_READWRITE is not specified in @p mount_flags.  If
3513  *      left @c NULL, the staging directory is created in the same directory as
3514  *      the backing WIM file.  The staging directory is automatically deleted
3515  *      when the image is unmounted.
3516  *
3517  * @return 0 on success; a ::wimlib_error_code value on failure.
3518  *
3519  * @retval ::WIMLIB_ERR_ALREADY_LOCKED
3520  *      Another process is currently modifying the WIM file.
3521  * @retval ::WIMLIB_ERR_FUSE
3522  *      A non-zero status code was returned by @c fuse_main().
3523  * @retval ::WIMLIB_ERR_IMAGE_HAS_MULTIPLE_REFERENCES
3524  *      There are currently multiple references to the image as a result of a
3525  *      call to wimlib_export_image().  Free one before attempting the
3526  *      read-write mount.
3527  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3528  *      @p image does not exist in @p wim.
3529  * @retval ::WIMLIB_ERR_INVALID_PARAM
3530  *      @p wim was @c NULL; or @p dir was NULL or an empty string; or an
3531  *      unrecognized flag was specified in @p mount_flags; or the image has
3532  *      already been modified in memory (e.g. by wimlib_update_image()).
3533  * @retval ::WIMLIB_ERR_MKDIR
3534  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @p mount_flags, but the
3535  *      staging directory could not be created.
3536  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3537  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @p mount_flags, but the
3538  *      WIM file is considered read-only because of any of the reasons mentioned
3539  *      in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
3540  * @retval ::WIMLIB_ERR_UNSUPPORTED
3541  *      Mounting is not supported in this build of the library.
3542  *
3543  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
3544  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
3545  * ::WIMLIB_ERR_READ, or ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which
3546  * indicate failure (for different reasons) to read the metadata resource for
3547  * the image to mount.
3548  *
3549  * The ability to mount WIM images is implemented using FUSE (Filesystem in
3550  * UserSpacE).  Depending on how FUSE is set up on your system, this function
3551  * may work as normal users in addition to the root user.
3552  *
3553  * Mounting WIM images is not supported if wimlib was configured
3554  * <c>--without-fuse</c>.  This includes Windows builds of wimlib;
3555  * ::WIMLIB_ERR_UNSUPPORTED will be returned in such cases.
3556  *
3557  * Calling this function daemonizes the process, unless
3558  * ::WIMLIB_MOUNT_FLAG_DEBUG was specified or an early error occurs.
3559  *
3560  * It is safe to mount multiple images from the same WIM file read-only at the
3561  * same time, but only if different ::WIMStruct's are used.  It is @b not safe
3562  * to mount multiple images from the same WIM file read-write at the same time.
3563  *
3564  * To unmount the image, call wimlib_unmount_image().  This may be done in a
3565  * different process.
3566  */
3567 extern int
3568 wimlib_mount_image(WIMStruct *wim,
3569                    int image,
3570                    const wimlib_tchar *dir,
3571                    int mount_flags,
3572                    const wimlib_tchar *staging_dir);
3573
3574 /**
3575  * @ingroup G_creating_and_opening_wims
3576  *
3577  * Open a WIM file and create a ::WIMStruct for it.
3578  *
3579  * @param wim_file
3580  *      The path to the WIM file to open.
3581  * @param open_flags
3582  *      Bitwise OR of flags prefixed with WIMLIB_OPEN_FLAG.
3583  * @param wim_ret
3584  *      On success, a pointer to a new ::WIMStruct backed by the specified
3585  *      on-disk WIM file is written to the memory location pointed to by this
3586  *      parameter.  This ::WIMStruct must be freed using using wimlib_free()
3587  *      when finished with it.
3588  *
3589  * @return 0 on success; a ::wimlib_error_code value on failure.
3590  *
3591  * @retval ::WIMLIB_ERR_IMAGE_COUNT
3592  *      The number of metadata resources found in the WIM did not match the
3593  *      image count specified in the WIM header, or the number of &lt;IMAGE&gt;
3594  *      elements in the XML data of the WIM did not match the image count
3595  *      specified in the WIM header.
3596  * @retval ::WIMLIB_ERR_INTEGRITY
3597  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @p open_flags, and
3598  *      the WIM file failed the integrity check.
3599  * @retval ::WIMLIB_ERR_INVALID_CHUNK_SIZE
3600  *      The library did not recognize the compression chunk size of the WIM as
3601  *      valid for its compression type.
3602  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
3603  *      The library did not recognize the compression type of the WIM.
3604  * @retval ::WIMLIB_ERR_INVALID_HEADER
3605  *      The header of the WIM was otherwise invalid.
3606  * @retval ::WIMLIB_ERR_INVALID_INTEGRITY_TABLE
3607  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @p open_flags and
3608  *      the WIM contained an integrity table, but the integrity table was
3609  *      invalid.
3610  * @retval ::WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY
3611  *      The lookup table of the WIM was invalid.
3612  * @retval ::WIMLIB_ERR_INVALID_PARAM
3613  *      @p wim_ret was @c NULL; or, @p wim_file was not a nonempty string.
3614  * @retval ::WIMLIB_ERR_IS_SPLIT_WIM
3615  *      The WIM was a split WIM and ::WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT was
3616  *      specified in @p open_flags.
3617  * @retval ::WIMLIB_ERR_NOT_A_WIM_FILE
3618  *      The file did not begin with the magic characters that identify a WIM
3619  *      file.
3620  * @retval ::WIMLIB_ERR_OPEN
3621  *      Failed to open the WIM file for reading.  Some possible reasons: the WIM
3622  *      file does not exist, or the calling process does not have permission to
3623  *      open it.
3624  * @retval ::WIMLIB_ERR_READ
3625  *      Failed to read data from the WIM file.
3626  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
3627  *      Unexpected end-of-file while reading data from the WIM file.
3628  * @retval ::WIMLIB_ERR_UNKNOWN_VERSION
3629  *      The WIM version number was not recognized. (May be a pre-Vista WIM.)
3630  * @retval ::WIMLIB_ERR_WIM_IS_ENCRYPTED
3631  *      The WIM cannot be opened because it contains encrypted segments.  (It
3632  *      may be a Windows 8 "ESD" file.)
3633  * @retval ::WIMLIB_ERR_WIM_IS_INCOMPLETE
3634  *      The WIM file is not complete (e.g. the program which wrote it was
3635  *      terminated before it finished)
3636  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3637  *      ::WIMLIB_OPEN_FLAG_WRITE_ACCESS was specified but the WIM file was
3638  *      considered read-only because of any of the reasons mentioned in the
3639  *      documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
3640  * @retval ::WIMLIB_ERR_XML
3641  *      The XML data of the WIM was invalid.
3642  */
3643 extern int
3644 wimlib_open_wim(const wimlib_tchar *wim_file,
3645                 int open_flags,
3646                 WIMStruct **wim_ret);
3647
3648 /**
3649  * @ingroup G_creating_and_opening_wims
3650  *
3651  * Same as wimlib_open_wim(), but allows specifying a progress function and
3652  * progress context.  If successful, the progress function will be registered in
3653  * the newly open ::WIMStruct, as if by an automatic call to
3654  * wimlib_register_progress_function().  In addition, if
3655  * ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY is specified in @p open_flags, then the
3656  * progress function will receive ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY
3657  * messages while checking the WIM file's integrity.
3658  */
3659 extern int
3660 wimlib_open_wim_with_progress(const wimlib_tchar *wim_file,
3661                               int open_flags,
3662                               WIMStruct **wim_ret,
3663                               wimlib_progress_func_t progfunc,
3664                               void *progctx);
3665
3666 /**
3667  * @ingroup G_writing_and_overwriting_wims
3668  *
3669  * Commit a ::WIMStruct to disk, updating its backing file.
3670  *
3671  * There are several alternative ways in which changes may be committed:
3672  *
3673  *   1. Full rebuild: write the updated WIM to a temporary file, then rename the
3674  *      temporary file to the original.
3675  *   2. Appending: append updates to the new original WIM file, then overwrite
3676  *      its header such that those changes become visible to new readers.
3677  *   3. Compaction: normally should not be used; see
3678  *      ::WIMLIB_WRITE_FLAG_UNSAFE_COMPACT for details.
3679  *
3680  * Append mode is often much faster than a full rebuild, but it wastes some
3681  * amount of space due to leaving "holes" in the WIM file.  Because of the
3682  * greater efficiency, wimlib_overwrite() normally defaults to append mode.
3683  * However, ::WIMLIB_WRITE_FLAG_REBUILD can be used to explicitly request a full
3684  * rebuild.  In addition, if wimlib_delete_image() has been used on the
3685  * ::WIMStruct, then the default mode switches to rebuild mode, and
3686  * ::WIMLIB_WRITE_FLAG_SOFT_DELETE can be used to explicitly request append
3687  * mode.
3688  *
3689  * If this function completes successfully, then no more functions can be called
3690  * on the ::WIMStruct other than wimlib_free().  If you need to continue using
3691  * the WIM file, you must use wimlib_open_wim() to open a new ::WIMStruct for
3692  * it.
3693  *
3694  * @param wim
3695  *      Pointer to a ::WIMStruct to commit to its backing file.
3696  * @param write_flags
3697  *      Bitwise OR of relevant flags prefixed with WIMLIB_WRITE_FLAG.
3698  * @param num_threads
3699  *      The number of threads to use for compressing data, or 0 to have the
3700  *      library automatically choose an appropriate number.
3701  *
3702  * @return 0 on success; a ::wimlib_error_code value on failure.  This function
3703  * may return most error codes returned by wimlib_write() as well as the
3704  * following error codes:
3705  *
3706  * @retval ::WIMLIB_ERR_ALREADY_LOCKED
3707  *      Another process is currently modifying the WIM file.
3708  * @retval ::WIMLIB_ERR_NO_FILENAME
3709  *      @p wim is not backed by an on-disk file.  In other words, it is a
3710  *      ::WIMStruct created by wimlib_create_new_wim() rather than
3711  *      wimlib_open_wim().
3712  * @retval ::WIMLIB_ERR_RENAME
3713  *      The temporary file to which the WIM was written could not be renamed to
3714  *      the original file.
3715  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3716  *      The WIM file is considered read-only because of any of the reasons
3717  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
3718  *      flag.
3719  *
3720  * If a progress function is registered with @p wim, then it will receive the
3721  * messages ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS,
3722  * ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN, and
3723  * ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_END.
3724  */
3725 extern int
3726 wimlib_overwrite(WIMStruct *wim, int write_flags, unsigned num_threads);
3727
3728 /**
3729  * @ingroup G_wim_information
3730  *
3731  * (Deprecated) Print information about one image, or all images, contained in a
3732  * WIM.
3733  *
3734  * @param wim
3735  *      Pointer to the ::WIMStruct to query.  This need not represent a
3736  *      standalone WIM (e.g. it could represent part of a split WIM).
3737  * @param image
3738  *      The 1-based index of the image for which to print information, or
3739  *      ::WIMLIB_ALL_IMAGES to print information about all images.
3740  *
3741  * @return This function has no return value.  No error checking is done when
3742  * printing the information.  If @p image is invalid, an error message is
3743  * printed.
3744  *
3745  * This function is deprecated; use wimlib_get_xml_data() or
3746  * wimlib_get_image_property() to query image information instead.
3747  */
3748 extern void
3749 wimlib_print_available_images(const WIMStruct *wim, int image);
3750
3751 /**
3752  * @ingroup G_wim_information
3753  *
3754  * Print the header of the WIM file (intended for debugging only).
3755  */
3756 extern void
3757 wimlib_print_header(const WIMStruct *wim);
3758
3759 /**
3760  * @ingroup G_nonstandalone_wims
3761  *
3762  * Reference file data from other WIM files or split WIM parts.  This function
3763  * can be used on WIMs that are not standalone, such as split or "delta" WIMs,
3764  * to load additional file data before calling a function such as
3765  * wimlib_extract_image() that requires the file data to be present.
3766  *
3767  * @param wim
3768  *      The ::WIMStruct for a WIM that contains metadata resources, but is not
3769  *      necessarily "standalone".  In the case of split WIMs, this should be the
3770  *      first part, since only the first part contains the metadata resources.
3771  *      In the case of delta WIMs, this should be the delta WIM rather than the
3772  *      WIM on which it is based.
3773  * @param resource_wimfiles_or_globs
3774  *      Array of paths to WIM files and/or split WIM parts to reference.
3775  *      Alternatively, when ::WIMLIB_REF_FLAG_GLOB_ENABLE is specified in @p
3776  *      ref_flags, these are treated as globs rather than literal paths.  That
3777  *      is, using this function you can specify zero or more globs, each of
3778  *      which expands to one or more literal paths.
3779  * @param count
3780  *      Number of entries in @p resource_wimfiles_or_globs.
3781  * @param ref_flags
3782  *      Bitwise OR of ::WIMLIB_REF_FLAG_GLOB_ENABLE and/or
3783  *      ::WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH.
3784  * @param open_flags
3785  *      Additional open flags, such as ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY, to
3786  *      pass to internal calls to wimlib_open_wim() on the reference files.
3787  *
3788  * @return 0 on success; a ::wimlib_error_code value on failure.
3789  *
3790  * @retval ::WIMLIB_ERR_GLOB_HAD_NO_MATCHES
3791  *      One of the specified globs did not match any paths (only with both
3792  *      ::WIMLIB_REF_FLAG_GLOB_ENABLE and ::WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH
3793  *      specified in @p ref_flags).
3794  * @retval ::WIMLIB_ERR_READ
3795  *      I/O or permissions error while processing a file glob.
3796  *
3797  * This function can additionally return most values that can be returned by
3798  * wimlib_open_wim().
3799  */
3800 extern int
3801 wimlib_reference_resource_files(WIMStruct *wim,
3802                                 const wimlib_tchar * const *resource_wimfiles_or_globs,
3803                                 unsigned count,
3804                                 int ref_flags,
3805                                 int open_flags);
3806
3807 /**
3808  * @ingroup G_nonstandalone_wims
3809  *
3810  * Similar to wimlib_reference_resource_files(), but operates at a lower level
3811  * where the caller must open the ::WIMStruct for each referenced file itself.
3812  *
3813  * @param wim
3814  *      The ::WIMStruct for a WIM that contains metadata resources, but is not
3815  *      necessarily "standalone".  In the case of split WIMs, this should be the
3816  *      first part, since only the first part contains the metadata resources.
3817  * @param resource_wims
3818  *      Array of pointers to the ::WIMStruct's for additional resource WIMs or
3819  *      split WIM parts to reference.
3820  * @param num_resource_wims
3821  *      Number of entries in @p resource_wims.
3822  * @param ref_flags
3823  *      Reserved; must be 0.
3824  *
3825  * @return 0 on success; a ::wimlib_error_code value on failure.
3826  */
3827 extern int
3828 wimlib_reference_resources(WIMStruct *wim, WIMStruct **resource_wims,
3829                            unsigned num_resource_wims, int ref_flags);
3830
3831 /**
3832  * @ingroup G_modifying_wims
3833  *
3834  * Declare that a newly added image is mostly the same as a prior image, but
3835  * captured at a later point in time, possibly with some modifications in the
3836  * intervening time.  This is designed to be used in incremental backups of the
3837  * same filesystem or directory tree.
3838  *
3839  * This function compares the metadata of the directory tree of the newly added
3840  * image against that of the old image.  Any files that are present in both the
3841  * newly added image and the old image and have timestamps that indicate they
3842  * haven't been modified are deemed not to have been modified and have their
3843  * checksums copied from the old image.  Because of this and because WIM uses
3844  * single-instance streams, such files need not be read from the filesystem when
3845  * the WIM is being written or overwritten.  Note that these unchanged files
3846  * will still be "archived" and will be logically present in the new image; the
3847  * optimization is that they don't need to actually be read from the filesystem
3848  * because the WIM already contains them.
3849  *
3850  * This function is provided to optimize incremental backups.  The resulting WIM
3851  * file will still be the same regardless of whether this function is called.
3852  * (This is, however, assuming that timestamps have not been manipulated or
3853  * unmaintained as to trick this function into thinking a file has not been
3854  * modified when really it has.  To partly guard against such cases, other
3855  * metadata such as file sizes will be checked as well.)
3856  *
3857  * This function must be called after adding the new image (e.g. with
3858  * wimlib_add_image()), but before writing the updated WIM file (e.g. with
3859  * wimlib_overwrite()).
3860  *
3861  * @param wim
3862  *      Pointer to the ::WIMStruct containing the newly added image.
3863  * @param new_image
3864  *      The 1-based index in @p wim of the newly added image.
3865  * @param template_wim
3866  *      Pointer to the ::WIMStruct containing the template image.  This can be,
3867  *      but does not have to be, the same ::WIMStruct as @p wim.
3868  * @param template_image
3869  *      The 1-based index in @p template_wim of the template image.
3870  * @param flags
3871  *      Reserved; must be 0.
3872  *
3873  * @return 0 on success; a ::wimlib_error_code value on failure.
3874  *
3875  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3876  *      @p new_image does not exist in @p wim or @p template_image does not
3877  *      exist in @p template_wim.
3878  * @retval ::WIMLIB_ERR_METADATA_NOT_FOUND
3879  *      At least one of @p wim and @p template_wim does not contain image
3880  *      metadata; for example, one of them represents a non-first part of a
3881  *      split WIM.
3882  * @retval ::WIMLIB_ERR_INVALID_PARAM
3883  *      Identical values were provided for the template and new image; or @p
3884  *      new_image specified an image that had not been modified since opening
3885  *      the WIM.
3886  *
3887  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
3888  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
3889  * ::WIMLIB_ERR_READ, or ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which
3890  * indicate failure (for different reasons) to read the metadata resource for
3891  * the template image.
3892  */
3893 extern int
3894 wimlib_reference_template_image(WIMStruct *wim, int new_image,
3895                                 WIMStruct *template_wim, int template_image,
3896                                 int flags);
3897
3898 /**
3899  * @ingroup G_general
3900  *
3901  * Register a progress function with a ::WIMStruct.
3902  *
3903  * @param wim
3904  *      The ::WIMStruct for which to register the progress function.
3905  * @param progfunc
3906  *      Pointer to the progress function to register.  If the WIM already has a
3907  *      progress function registered, it will be replaced with this one.  If @p
3908  *      NULL, the current progress function (if any) will be unregistered.
3909  * @param progctx
3910  *      The value which will be passed as the third argument to calls to @p
3911  *      progfunc.
3912  */
3913 extern void
3914 wimlib_register_progress_function(WIMStruct *wim,
3915                                   wimlib_progress_func_t progfunc,
3916                                   void *progctx);
3917
3918 /**
3919  * @ingroup G_modifying_wims
3920  *
3921  * Rename the @p source_path to the @p dest_path in the specified @p image of
3922  * the @p wim.
3923  *
3924  * This just builds an appropriate ::wimlib_rename_command and passes it to
3925  * wimlib_update_image().
3926  */
3927 extern int
3928 wimlib_rename_path(WIMStruct *wim, int image,
3929                    const wimlib_tchar *source_path, const wimlib_tchar *dest_path);
3930
3931 /**
3932  * @ingroup G_wim_information
3933  *
3934  * Translate a string specifying the name or number of an image in the WIM into
3935  * the number of the image.  The images are numbered starting at 1.
3936  *
3937  * @param wim
3938  *      Pointer to the ::WIMStruct for a WIM.
3939  * @param image_name_or_num
3940  *      A string specifying the name or number of an image in the WIM.  If it
3941  *      parses to a positive integer, this integer is taken to specify the
3942  *      number of the image, indexed starting at 1.  Otherwise, it is taken to
3943  *      be the name of an image, as given in the XML data for the WIM file.  It
3944  *      also may be the keyword "all" or the string "*", both of which will
3945  *      resolve to ::WIMLIB_ALL_IMAGES.
3946  *      <br/> <br/>
3947  *      There is no way to search for an image actually named "all", "*", or an
3948  *      integer number, or an image that has no name.  However, you can use
3949  *      wimlib_get_image_name() to get the name of any image.
3950  *
3951  * @return
3952  *      If the string resolved to a single existing image, the number of that
3953  *      image, indexed starting at 1, is returned.  If the keyword "all" or "*"
3954  *      was specified, ::WIMLIB_ALL_IMAGES is returned.  Otherwise,
3955  *      ::WIMLIB_NO_IMAGE is returned.  If @p image_name_or_num was @c NULL or
3956  *      the empty string, ::WIMLIB_NO_IMAGE is returned, even if one or more
3957  *      images in @p wim has no name.  (Since a WIM may have multiple unnamed
3958  *      images, an unnamed image must be specified by index to eliminate the
3959  *      ambiguity.)
3960  */
3961 extern int
3962 wimlib_resolve_image(WIMStruct *wim,
3963                      const wimlib_tchar *image_name_or_num);
3964
3965 /**
3966  * @ingroup G_general
3967  *
3968  * Set the file to which the library will print error and warning messages.
3969  *
3970  * This version of the function takes a C library <c>FILE*</c> opened for
3971  * writing (or appending).  Use wimlib_set_error_file_by_name() to specify the
3972  * file by name instead.
3973  *
3974  * This also enables error messages, as if by a call to
3975  * wimlib_set_print_errors(true).
3976  *
3977  * @return 0 on success; a ::wimlib_error_code value on failure.
3978  *
3979  * @retval ::WIMLIB_ERR_UNSUPPORTED
3980  *      wimlib was compiled using the <c>--without-error-messages</c> option.
3981  */
3982 extern int
3983 wimlib_set_error_file(FILE *fp);
3984
3985 /**
3986  * @ingroup G_general
3987  *
3988  * Set the path to the file to which the library will print error and warning
3989  * messages.  The library will open this file for appending.
3990  *
3991  * This also enables error messages, as if by a call to
3992  * wimlib_set_print_errors(true).
3993  *
3994  * @return 0 on success; a ::wimlib_error_code value on failure.
3995  *
3996  * @retval ::WIMLIB_ERR_OPEN
3997  *      The file named by @p path could not be opened for appending.
3998  * @retval ::WIMLIB_ERR_UNSUPPORTED
3999  *      wimlib was compiled using the <c>--without-error-messages</c> option.
4000  */
4001 extern int
4002 wimlib_set_error_file_by_name(const wimlib_tchar *path);
4003
4004 /**
4005  * @ingroup G_modifying_wims
4006  *
4007  * Change the description of a WIM image.  Equivalent to
4008  * <tt>wimlib_set_image_property(wim, image, "DESCRIPTION", description)</tt>.
4009  *
4010  * Note that "description" is misspelled in the name of this function.
4011  */
4012 extern int
4013 wimlib_set_image_descripton(WIMStruct *wim, int image,
4014                             const wimlib_tchar *description);
4015
4016 /**
4017  * @ingroup G_modifying_wims
4018  *
4019  * Change what is stored in the \<FLAGS\> element in the WIM XML document
4020  * (usually something like "Core" or "Ultimate").  Equivalent to
4021  * <tt>wimlib_set_image_property(wim, image, "FLAGS", flags)</tt>.
4022  */
4023 extern int
4024 wimlib_set_image_flags(WIMStruct *wim, int image, const wimlib_tchar *flags);
4025
4026 /**
4027  * @ingroup G_modifying_wims
4028  *
4029  * Change the name of a WIM image.  Equivalent to
4030  * <tt>wimlib_set_image_property(wim, image, "NAME", name)</tt>.
4031  */
4032 extern int
4033 wimlib_set_image_name(WIMStruct *wim, int image, const wimlib_tchar *name);
4034
4035 /**
4036  * @ingroup G_modifying_wims
4037  *
4038  * Since wimlib v1.8.3: add, modify, or remove a per-image property from the
4039  * WIM's XML document.  This is an alternative to wimlib_set_image_name(),
4040  * wimlib_set_image_descripton(), and wimlib_set_image_flags() which allows
4041  * manipulating any simple string property.
4042  *
4043  * @param wim
4044  *      Pointer to the ::WIMStruct for the WIM.
4045  * @param image
4046  *      The 1-based index of the image for which to set the property.
4047  * @param property_name
4048  *      The name of the image property in the same format documented for
4049  *      wimlib_get_image_property().
4050  *      <br/>
4051  *      Note: if creating a new element using a bracketed index such as
4052  *      "WINDOWS/LANGUAGES/LANGUAGE[2]", the highest index that can be specified
4053  *      is one greater than the number of existing elements with that same name,
4054  *      excluding the index.  That means that if you are adding a list of new
4055  *      elements, they must be added sequentially from the first index (1) to
4056  *      the last index (n).
4057  * @param property_value
4058  *      If not NULL and not empty, the property is set to this value.
4059  *      Otherwise, the property is removed from the XML document.
4060  *
4061  * @return 0 on success; a ::wimlib_error_code value on failure.
4062  *
4063  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
4064  *      The user requested to set the image name (the <tt>NAME</tt> property),
4065  *      but another image in the WIM already had the requested name.
4066  * @retval ::WIMLIB_ERR_INVALID_IMAGE
4067  *      @p image does not exist in @p wim.
4068  * @retval ::WIMLIB_ERR_INVALID_PARAM
4069  *      @p property_name has an unsupported format, or @p property_name included
4070  *      a bracketed index that was too high.
4071  */
4072 extern int
4073 wimlib_set_image_property(WIMStruct *wim, int image,
4074                           const wimlib_tchar *property_name,
4075                           const wimlib_tchar *property_value);
4076
4077 /**
4078  * @ingroup G_general
4079  *
4080  * Set the functions that wimlib uses to allocate and free memory.
4081  *
4082  * These settings are global and not per-WIM.
4083  *
4084  * The default is to use the default @c malloc(), @c free(), and @c realloc()
4085  * from the standard C library.
4086  *
4087  * Note: some external functions, such as those in @c libntfs-3g, may use the
4088  * standard memory allocation functions regardless of this setting.
4089  *
4090  * @param malloc_func
4091  *      A function equivalent to @c malloc() that wimlib will use to allocate
4092  *      memory.  If @c NULL, the allocator function is set back to the default
4093  *      @c malloc() from the C library.
4094  * @param free_func
4095  *      A function equivalent to @c free() that wimlib will use to free memory.
4096  *      If @c NULL, the free function is set back to the default @c free() from
4097  *      the C library.
4098  * @param realloc_func
4099  *      A function equivalent to @c realloc() that wimlib will use to reallocate
4100  *      memory.  If @c NULL, the free function is set back to the default @c
4101  *      realloc() from the C library.
4102  *
4103  * @return 0
4104  */
4105 extern int
4106 wimlib_set_memory_allocator(void *(*malloc_func)(size_t),
4107                             void (*free_func)(void *),
4108                             void *(*realloc_func)(void *, size_t));
4109
4110 /**
4111  * @ingroup G_writing_and_overwriting_wims
4112  *
4113  * Set a ::WIMStruct's output compression chunk size.  This is the compression
4114  * chunk size that will be used for writing non-solid resources in subsequent
4115  * calls to wimlib_write() or wimlib_overwrite().  A larger compression chunk
4116  * size often results in a better compression ratio, but compression may be
4117  * slower and the speed of random access to data may be reduced.  In addition,
4118  * some chunk sizes are not compatible with Microsoft software.
4119  *
4120  * @param wim
4121  *      The ::WIMStruct for which to set the output chunk size.
4122  * @param chunk_size
4123  *      The chunk size (in bytes) to set.  The valid chunk sizes are dependent
4124  *      on the compression type.  See the documentation for each
4125  *      ::wimlib_compression_type constant for more information.  As a special
4126  *      case, if @p chunk_size is specified as 0, then the chunk size will be
4127  *      reset to the default for the currently selected output compression type.
4128  *
4129  * @return 0 on success; a ::wimlib_error_code value on failure.
4130  *
4131  * @retval ::WIMLIB_ERR_INVALID_CHUNK_SIZE
4132  *      @p chunk_size was not 0 or a supported chunk size for the currently
4133  *      selected output compression type.
4134  */
4135 extern int
4136 wimlib_set_output_chunk_size(WIMStruct *wim, uint32_t chunk_size);
4137
4138 /**
4139  * @ingroup G_writing_and_overwriting_wims
4140  *
4141  * Similar to wimlib_set_output_chunk_size(), but set the chunk size for writing
4142  * solid resources.
4143  */
4144 extern int
4145 wimlib_set_output_pack_chunk_size(WIMStruct *wim, uint32_t chunk_size);
4146
4147 /**
4148  * @ingroup G_writing_and_overwriting_wims
4149  *
4150  * Set a ::WIMStruct's output compression type.  This is the compression type
4151  * that will be used for writing non-solid resources in subsequent calls to
4152  * wimlib_write() or wimlib_overwrite().
4153  *
4154  * @param wim
4155  *      The ::WIMStruct for which to set the output compression type.
4156  * @param ctype
4157  *      The compression type to set.  If this compression type is incompatible
4158  *      with the current output chunk size, then the output chunk size will be
4159  *      reset to the default for the new compression type.
4160  *
4161  * @return 0 on success; a ::wimlib_error_code value on failure.
4162  *
4163  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
4164  *      @p ctype did not specify a valid compression type.
4165  */
4166 extern int
4167 wimlib_set_output_compression_type(WIMStruct *wim,
4168                                    enum wimlib_compression_type ctype);
4169
4170 /**
4171  * @ingroup G_writing_and_overwriting_wims
4172  *
4173  * Similar to wimlib_set_output_compression_type(), but set the compression type
4174  * for writing solid resources.  This cannot be ::WIMLIB_COMPRESSION_TYPE_NONE.
4175  */
4176 extern int
4177 wimlib_set_output_pack_compression_type(WIMStruct *wim,
4178                                         enum wimlib_compression_type ctype);
4179
4180 /**
4181  * @ingroup G_general
4182  *
4183  * Set whether wimlib can print error and warning messages to the error file,
4184  * which defaults to standard error.  Error and warning messages may provide
4185  * information that cannot be determined only from returned error codes.
4186  *
4187  * By default, error messages are not printed.
4188  *
4189  * This setting applies globally (it is not per-WIM).
4190  *
4191  * This can be called before wimlib_global_init().
4192  *
4193  * @param show_messages
4194  *      @c true if messages are to be printed; @c false if messages are not to
4195  *      be printed.
4196  *
4197  * @return 0 on success; a ::wimlib_error_code value on failure.
4198  *
4199  * @retval ::WIMLIB_ERR_UNSUPPORTED
4200  *      wimlib was compiled using the <c>--without-error-messages</c> option.
4201  */
4202 extern int
4203 wimlib_set_print_errors(bool show_messages);
4204
4205 /**
4206  * @ingroup G_modifying_wims
4207  *
4208  * Set basic information about a WIM.
4209  *
4210  * @param wim
4211  *      Pointer to the ::WIMStruct for a WIM.
4212  * @param info
4213  *      Pointer to a ::wimlib_wim_info structure that contains the information
4214  *      to set.  Only the information explicitly specified in the @p which flags
4215  *      need be valid.
4216  * @param which
4217  *      Flags that specify which information to set.  This is a bitwise OR of
4218  *      ::WIMLIB_CHANGE_READONLY_FLAG, ::WIMLIB_CHANGE_GUID,
4219  *      ::WIMLIB_CHANGE_BOOT_INDEX, and/or ::WIMLIB_CHANGE_RPFIX_FLAG.
4220  *
4221  * @return 0 on success; a ::wimlib_error_code value on failure.
4222  *
4223  * @retval ::WIMLIB_ERR_IMAGE_COUNT
4224  *      ::WIMLIB_CHANGE_BOOT_INDEX was specified, but
4225  *      ::wimlib_wim_info.boot_index did not specify 0 or a valid 1-based image
4226  *      index in the WIM.
4227  */
4228 extern int
4229 wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info,
4230                     int which);
4231
4232 /**
4233  * @ingroup G_nonstandalone_wims
4234  *
4235  * Split a WIM into multiple parts.
4236  *
4237  * @param wim
4238  *      The ::WIMStruct for the WIM to split.
4239  * @param swm_name
4240  *      Name of the split WIM (SWM) file to create.  This will be the name of
4241  *      the first part.  The other parts will, by default, have the same name
4242  *      with 2, 3, 4, ..., etc.  appended before the suffix.  However, the exact
4243  *      names can be customized using the progress function.
4244  * @param part_size
4245  *      The maximum size per part, in bytes.  Unfortunately, it is not
4246  *      guaranteed that this will really be the maximum size per part, because
4247  *      some file resources in the WIM may be larger than this size, and the WIM
4248  *      file format provides no way to split up file resources among multiple
4249  *      WIMs.
4250  * @param write_flags
4251  *      Bitwise OR of relevant flags prefixed with @c WIMLIB_WRITE_FLAG.  These
4252  *      flags will be used to write each split WIM part.  Specify 0 here to get
4253  *      the default behavior.
4254  *
4255  * @return 0 on success; a ::wimlib_error_code value on failure.  This function
4256  * may return most error codes that can be returned by wimlib_write() as well as
4257  * the following error codes:
4258  *
4259  * @retval ::WIMLIB_ERR_INVALID_PARAM
4260  *      @p swm_name was not a nonempty string, or @p part_size was 0.
4261  * @retval ::WIMLIB_ERR_UNSUPPORTED
4262  *      The WIM contains solid resources.  Splitting a WIM containing solid
4263  *      resources is not supported.
4264  *
4265  * If a progress function is registered with @p wim, then for each split WIM
4266  * part that is written it will receive the messages
4267  * ::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART and
4268  * ::WIMLIB_PROGRESS_MSG_SPLIT_END_PART.
4269  */
4270 extern int
4271 wimlib_split(WIMStruct *wim,
4272              const wimlib_tchar *swm_name,
4273              uint64_t part_size,
4274              int write_flags);
4275
4276 /**
4277  * @ingroup G_general
4278  *
4279  * Perform verification checks on a WIM file.
4280  *
4281  * This function is intended for safety checking and/or debugging.  If used on a
4282  * well-formed WIM file, it should always succeed.
4283  *
4284  * @param wim
4285  *      The ::WIMStruct for the WIM file to verify.  Note: for an extra layer of
4286  *      verification, it is a good idea to have used
4287  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY when you opened the file.
4288  *      <br/>
4289  *      If verifying a split WIM, specify the first part of the split WIM here,
4290  *      and reference the other parts using wimlib_reference_resource_files()
4291  *      before calling this function.
4292  * @param verify_flags
4293  *      Reserved; must be 0.
4294  *
4295  * @return 0 if the WIM file was successfully verified; a ::wimlib_error_code
4296  * value if it failed verification or another error occurred.
4297  *
4298  * @retval ::WIMLIB_ERR_DECOMPRESSION
4299  *      The WIM file contains invalid compressed data.
4300  * @retval ::WIMLIB_ERR_INVALID_METADATA_RESOURCE
4301  *      The metadata resource for an image is invalid.
4302  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
4303  *      File data stored in the WIM file is corrupt.
4304  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
4305  *      The data for a file in an image could not be found.  See @ref
4306  *      G_nonstandalone_wims.
4307  *
4308  * If a progress function is registered with @p wim, then it will receive the
4309  * following progress messages: ::WIMLIB_PROGRESS_MSG_BEGIN_VERIFY_IMAGE,
4310  * ::WIMLIB_PROGRESS_MSG_END_VERIFY_IMAGE, and
4311  * ::WIMLIB_PROGRESS_MSG_VERIFY_STREAMS.
4312  */
4313 extern int
4314 wimlib_verify_wim(WIMStruct *wim, int verify_flags);
4315
4316 /**
4317  * @ingroup G_mounting_wim_images
4318  *
4319  * Unmount a WIM image that was mounted using wimlib_mount_image().
4320  *
4321  * When unmounting a read-write mounted image, the default behavior is to
4322  * discard changes to the image.  Use ::WIMLIB_UNMOUNT_FLAG_COMMIT to cause the
4323  * image to be committed.
4324  *
4325  * @param dir
4326  *      The directory on which the WIM image is mounted.
4327  * @param unmount_flags
4328  *      Bitwise OR of flags prefixed with @p WIMLIB_UNMOUNT_FLAG.
4329  *
4330  * @return 0 on success; a ::wimlib_error_code value on failure.
4331  *
4332  * @retval ::WIMLIB_ERR_NOT_A_MOUNTPOINT
4333  *      There is no WIM image mounted on the specified directory.
4334  * @retval ::WIMLIB_ERR_MOUNTED_IMAGE_IS_BUSY
4335  *      The read-write mounted image cannot be committed because there are file
4336  *      descriptors open to it, and ::WIMLIB_UNMOUNT_FLAG_FORCE was not
4337  *      specified.
4338  * @retval ::WIMLIB_ERR_MQUEUE
4339  *      Could not create a POSIX message queue.
4340  * @retval ::WIMLIB_ERR_NOT_PERMITTED_TO_UNMOUNT
4341  *      The image was mounted by a different user.
4342  * @retval ::WIMLIB_ERR_UNSUPPORTED
4343  *      Mounting is not supported in this build of the library.
4344  *
4345  * Note: you can also unmount the image by using the @c umount() system call, or
4346  * by using the @c umount or @c fusermount programs.  However, you need to call
4347  * this function if you want changes to be committed.
4348  */
4349 extern int
4350 wimlib_unmount_image(const wimlib_tchar *dir, int unmount_flags);
4351
4352 /**
4353  * @ingroup G_mounting_wim_images
4354  *
4355  * Same as wimlib_unmount_image(), but allows specifying a progress function.
4356  * The progress function will receive a ::WIMLIB_PROGRESS_MSG_UNMOUNT_BEGIN
4357  * message.  In addition, if changes are committed from a read-write mount, the
4358  * progress function will receive ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS messages.
4359  */
4360 extern int
4361 wimlib_unmount_image_with_progress(const wimlib_tchar *dir,
4362                                    int unmount_flags,
4363                                    wimlib_progress_func_t progfunc,
4364                                    void *progctx);
4365
4366 /**
4367  * @ingroup G_modifying_wims
4368  *
4369  * Update a WIM image by adding, deleting, and/or renaming files or directories.
4370  *
4371  * @param wim
4372  *      Pointer to the ::WIMStruct containing the image to update.
4373  * @param image
4374  *      The 1-based index of the image to update.
4375  * @param cmds
4376  *      An array of ::wimlib_update_command's that specify the update operations
4377  *      to perform.
4378  * @param num_cmds
4379  *      Number of commands in @p cmds.
4380  * @param update_flags
4381  *      ::WIMLIB_UPDATE_FLAG_SEND_PROGRESS or 0.
4382  *
4383  * @return 0 on success; a ::wimlib_error_code value on failure.  On failure,
4384  * all update commands will be rolled back, and no visible changes will have
4385  * been made to @p wim.
4386  *
4387  * @retval ::WIMLIB_ERR_FVE_LOCKED_VOLUME
4388  *      Windows-only: One of the "add" commands attempted to add files from an
4389  *      encrypted BitLocker volume that hasn't yet been unlocked.
4390  * @retval ::WIMLIB_ERR_IMAGE_HAS_MULTIPLE_REFERENCES
4391  *      There are currently multiple references to the image as a result of a
4392  *      call to wimlib_export_image().  Free one before attempting the update.
4393  * @retval ::WIMLIB_ERR_INVALID_CAPTURE_CONFIG
4394  *      The contents of a capture configuration file were invalid.
4395  * @retval ::WIMLIB_ERR_INVALID_IMAGE
4396  *      @p image did not exist in @p wim.
4397  * @retval ::WIMLIB_ERR_INVALID_OVERLAY
4398  *      An add command with ::WIMLIB_ADD_FLAG_NO_REPLACE specified attempted to
4399  *      replace an existing nondirectory file.
4400  * @retval ::WIMLIB_ERR_INVALID_PARAM
4401  *      An unknown operation type was provided in the update commands; or
4402  *      unknown or incompatible flags were provided in a flags parameter; or
4403  *      there was another problem with the provided parameters.
4404  * @retval ::WIMLIB_ERR_INVALID_REPARSE_DATA
4405  *      While executing an add command, a reparse point had invalid data.
4406  * @retval ::WIMLIB_ERR_IS_DIRECTORY
4407  *      An add command attempted to replace a directory with a non-directory; or
4408  *      a delete command without ::WIMLIB_DELETE_FLAG_RECURSIVE attempted to
4409  *      delete a directory; or a rename command attempted to rename a directory
4410  *      to a non-directory.
4411  * @retval ::WIMLIB_ERR_NOTDIR
4412  *      An add command attempted to replace a non-directory with a directory; or
4413  *      an add command attempted to set the root of the image to a
4414  *      non-directory; or a rename command attempted to rename a directory to a
4415  *      non-directory; or a component of an image path that was used as a
4416  *      directory was not, in fact, a directory.
4417  * @retval ::WIMLIB_ERR_NOTEMPTY
4418  *      A rename command attempted to rename a directory to a non-empty
4419  *      directory; or a rename command would have created a loop.
4420  * @retval ::WIMLIB_ERR_NTFS_3G
4421  *      While executing an add command with ::WIMLIB_ADD_FLAG_NTFS specified, an
4422  *      error occurred while reading data from the NTFS volume using libntfs-3g.
4423  * @retval ::WIMLIB_ERR_OPEN
4424  *      Failed to open a file to be captured while executing an add command.
4425  * @retval ::WIMLIB_ERR_OPENDIR
4426  *      Failed to open a directory to be captured while executing an add
4427  *      command.
4428  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
4429  *      A delete command without ::WIMLIB_DELETE_FLAG_FORCE specified was for a
4430  *      WIM path that did not exist; or a rename command attempted to rename a
4431  *      file that does not exist.
4432  * @retval ::WIMLIB_ERR_READ
4433  *      While executing an add command, failed to read data from a file or
4434  *      directory to be captured.
4435  * @retval ::WIMLIB_ERR_READLINK
4436  *      While executing an add command, failed to read the target of a symbolic
4437  *      link, junction, or other reparse point.
4438  * @retval ::WIMLIB_ERR_STAT
4439  *      While executing an add command, failed to read metadata for a file or
4440  *      directory.
4441  * @retval ::WIMLIB_ERR_UNABLE_TO_READ_CAPTURE_CONFIG
4442  *      A capture configuration file could not be read.
4443  * @retval ::WIMLIB_ERR_UNSUPPORTED
4444  *      A command had flags provided that are not supported on this platform or
4445  *      in this build of the library.
4446  * @retval ::WIMLIB_ERR_UNSUPPORTED_FILE
4447  *      An add command with ::WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE specified
4448  *      discovered a file that was not of a supported type.
4449  *
4450  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
4451  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
4452  * ::WIMLIB_ERR_READ, or ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which
4453  * indicate failure (for different reasons) to read the metadata resource for an
4454  * image that needed to be updated.
4455  */
4456 extern int
4457 wimlib_update_image(WIMStruct *wim,
4458                     int image,
4459                     const struct wimlib_update_command *cmds,
4460                     size_t num_cmds,
4461                     int update_flags);
4462
4463 /**
4464  * @ingroup G_writing_and_overwriting_wims
4465  *
4466  * Persist a ::WIMStruct to a new on-disk WIM file.
4467  *
4468  * This brings in file data from any external locations, such as directory trees
4469  * or NTFS volumes scanned with wimlib_add_image(), or other WIM files via
4470  * wimlib_export_image(), and incorporates it into a new on-disk WIM file.
4471  *
4472  * By default, the new WIM file is written as stand-alone.  Using the
4473  * ::WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIMS flag, a "delta" WIM can be written
4474  * instead.  However, this function cannot directly write a "split" WIM; use
4475  * wimlib_split() for that.
4476  *
4477  * @param wim
4478  *      Pointer to the ::WIMStruct being persisted.
4479  * @param path
4480  *      The path to the on-disk file to write.
4481  * @param image
4482  *      Normally, specify ::WIMLIB_ALL_IMAGES here.  This indicates that all
4483  *      images are to be included in the new on-disk WIM file.  If for some
4484  *      reason you only want to include a single image, specify the 1-based
4485  *      index of that image instead.
4486  * @param write_flags
4487  *      Bitwise OR of flags prefixed with @c WIMLIB_WRITE_FLAG.
4488  * @param num_threads
4489  *      The number of threads to use for compressing data, or 0 to have the
4490  *      library automatically choose an appropriate number.
4491  *
4492  * @return 0 on success; a ::wimlib_error_code value on failure.
4493  *
4494  * @retval ::WIMLIB_ERR_CONCURRENT_MODIFICATION_DETECTED
4495  *      A file that had previously been scanned for inclusion in the WIM was
4496  *      concurrently modified.
4497  * @retval ::WIMLIB_ERR_INVALID_IMAGE
4498  *      @p image did not exist in @p wim.
4499  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
4500  *      A file, stored in another WIM, which needed to be written was corrupt.
4501  * @retval ::WIMLIB_ERR_INVALID_PARAM
4502  *      @p path was not a nonempty string, or invalid flags were passed.
4503  * @retval ::WIMLIB_ERR_OPEN
4504  *      Failed to open the output WIM file for writing, or failed to open a file
4505  *      whose data needed to be included in the WIM.
4506  * @retval ::WIMLIB_ERR_READ
4507  *      Failed to read data that needed to be included in the WIM.
4508  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
4509  *      A file data blob that needed to be written could not be found in the
4510  *      blob lookup table of @p wim.  See @ref G_nonstandalone_wims.
4511  * @retval ::WIMLIB_ERR_WRITE
4512  *      An error occurred when trying to write data to the new WIM file.
4513  *
4514  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
4515  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
4516  * ::WIMLIB_ERR_READ, or ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which
4517  * indicate failure (for different reasons) to read the data from a WIM file.
4518  *
4519  * If a progress function is registered with @p wim, then it will receive the
4520  * messages ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS,
4521  * ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN, and
4522  * ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_END.
4523  */
4524 extern int
4525 wimlib_write(WIMStruct *wim,
4526              const wimlib_tchar *path,
4527              int image,
4528              int write_flags,
4529              unsigned num_threads);
4530
4531 /**
4532  * @ingroup G_writing_and_overwriting_wims
4533  *
4534  * Same as wimlib_write(), but write the WIM directly to a file descriptor,
4535  * which need not be seekable if the write is done in a special pipable WIM
4536  * format by providing ::WIMLIB_WRITE_FLAG_PIPABLE in @p write_flags.  This can,
4537  * for example, allow capturing a WIM image and streaming it over the network.
4538  * See @ref subsec_pipable_wims for more information about pipable WIMs.
4539  *
4540  * The file descriptor @p fd will @b not be closed when the write is complete;
4541  * the calling code is responsible for this.
4542  *
4543  * @return 0 on success; a ::wimlib_error_code value on failure.  The possible
4544  * error codes include those that can be returned by wimlib_write() as well as
4545  * the following:
4546  *
4547  * @retval ::WIMLIB_ERR_INVALID_PARAM
4548  *      @p fd was not seekable, but ::WIMLIB_WRITE_FLAG_PIPABLE was not
4549  *      specified in @p write_flags.
4550  */
4551 extern int
4552 wimlib_write_to_fd(WIMStruct *wim,
4553                    int fd,
4554                    int image,
4555                    int write_flags,
4556                    unsigned num_threads);
4557
4558 /**
4559  * @defgroup G_compression Compression and decompression functions
4560  *
4561  * @brief Functions for XPRESS, LZX, and LZMS compression and decompression.
4562  *
4563  * These functions are already used by wimlib internally when appropriate for
4564  * reading and writing WIM archives.  But they are exported and documented so
4565  * that they can be used in other applications or libraries for general-purpose
4566  * lossless data compression.  They are implemented in highly optimized C code,
4567  * using state-of-the-art compression techniques.  The main limitation is the
4568  * lack of sliding window support; this has, however, allowed the algorithms to
4569  * be optimized for block-based compression.
4570  *
4571  * @{
4572  */
4573
4574 /** Opaque compressor handle.  */
4575 struct wimlib_compressor;
4576
4577 /** Opaque decompressor handle.  */
4578 struct wimlib_decompressor;
4579
4580 /**
4581  * Set the default compression level for the specified compression type.  This
4582  * is the compression level that wimlib_create_compressor() assumes if it is
4583  * called with @p compression_level specified as 0.
4584  *
4585  * wimlib's WIM writing code (e.g. wimlib_write()) will pass 0 to
4586  * wimlib_create_compressor() internally.  Therefore, calling this function will
4587  * affect the compression level of any data later written to WIM files using the
4588  * specified compression type.
4589  *
4590  * The initial state, before this function is called, is that all compression
4591  * types have a default compression level of 50.
4592  *
4593  * @param ctype
4594  *      Compression type for which to set the default compression level, as one
4595  *      of the ::wimlib_compression_type constants.  Or, if this is the special
4596  *      value -1, the default compression levels for all compression types will
4597  *      be set.
4598  * @param compression_level
4599  *      The default compression level to set.  If 0, the "default default" level
4600  *      of 50 is restored.  Otherwise, a higher value indicates higher
4601  *      compression, whereas a lower value indicates lower compression.  See
4602  *      wimlib_create_compressor() for more information.
4603  *
4604  * @return 0 on success; a ::wimlib_error_code value on failure.
4605  *
4606  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
4607  *      @p ctype was neither a supported compression type nor -1.
4608  */
4609 extern int
4610 wimlib_set_default_compression_level(int ctype, unsigned int compression_level);
4611
4612 /**
4613  * Return the approximate number of bytes needed to allocate a compressor with
4614  * wimlib_create_compressor() for the specified compression type, maximum block
4615  * size, and compression level.  @p compression_level may be 0, in which case
4616  * the current default compression level for @p ctype is used.  Returns 0 if the
4617  * compression type is invalid, or the @p max_block_size for that compression
4618  * type is invalid.
4619  */
4620 extern uint64_t
4621 wimlib_get_compressor_needed_memory(enum wimlib_compression_type ctype,
4622                                     size_t max_block_size,
4623                                     unsigned int compression_level);
4624
4625 #define WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE      0x80000000
4626
4627 /**
4628  * Allocate a compressor for the specified compression type using the specified
4629  * parameters.  This function is part of wimlib's compression API; it is not
4630  * necessary to call this to process a WIM file.
4631  *
4632  * @param ctype
4633  *      Compression type for which to create the compressor, as one of the
4634  *      ::wimlib_compression_type constants.
4635  * @param max_block_size
4636  *      The maximum compression block size to support.  This specifies the
4637  *      maximum allowed value for the @p uncompressed_size parameter of
4638  *      wimlib_compress() when called using this compressor.
4639  *      <br/>
4640  *      Usually, the amount of memory used by the compressor will scale in
4641  *      proportion to the @p max_block_size parameter.
4642  *      wimlib_get_compressor_needed_memory() can be used to query the specific
4643  *      amount of memory that will be required.
4644  *      <br/>
4645  *      This parameter must be at least 1 and must be less than or equal to a
4646  *      compression-type-specific limit.
4647  *      <br/>
4648  *      In general, the same value of @p max_block_size must be passed to
4649  *      wimlib_create_decompressor() when the data is later decompressed.
4650  *      However, some compression types have looser requirements regarding this.
4651  * @param compression_level
4652  *      The compression level to use.  If 0, the default compression level (50,
4653  *      or another value as set through wimlib_set_default_compression_level())
4654  *      is used.  Otherwise, a higher value indicates higher compression.  The
4655  *      values are scaled so that 10 is low compression, 50 is medium
4656  *      compression, and 100 is high compression.  This is not a percentage;
4657  *      values above 100 are also valid.
4658  *      <br/>
4659  *      Using a higher-than-default compression level can result in a better
4660  *      compression ratio, but can significantly reduce performance.  Similarly,
4661  *      using a lower-than-default compression level can result in better
4662  *      performance, but can significantly worsen the compression ratio.  The
4663  *      exact results will depend heavily on the compression type and what
4664  *      algorithms are implemented for it.  If you are considering using a
4665  *      non-default compression level, you should run benchmarks to see if it is
4666  *      worthwhile for your application.
4667  *      <br/>
4668  *      The compression level does not affect the format of the compressed data.
4669  *      Therefore, it is a compressor-only parameter and does not need to be
4670  *      passed to the decompressor.
4671  *      <br/>
4672  *      Since wimlib v1.8.0, this parameter can be OR-ed with the flag
4673  *      ::WIMLIB_COMPRESSOR_FLAG_DESTRUCTIVE.  This creates the compressor in a
4674  *      mode where it is allowed to modify the input buffer.  Specifically, in
4675  *      this mode, if compression succeeds, the input buffer may have been
4676  *      modified, whereas if compression does not succeed the input buffer still
4677  *      may have been written to but will have been restored exactly to its
4678  *      original state.  This mode is designed to save some memory when using
4679  *      large buffer sizes.
4680  * @param compressor_ret
4681  *      A location into which to return the pointer to the allocated compressor.
4682  *      The allocated compressor can be used for any number of calls to
4683  *      wimlib_compress() before being freed with wimlib_free_compressor().
4684  *
4685  * @return 0 on success; a ::wimlib_error_code value on failure.
4686  *
4687  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
4688  *      @p ctype was not a supported compression type.
4689  * @retval ::WIMLIB_ERR_INVALID_PARAM
4690  *      @p max_block_size was invalid for the compression type, or @p
4691  *      compressor_ret was @c NULL.
4692  * @retval ::WIMLIB_ERR_NOMEM
4693  *      Insufficient memory to allocate the compressor.
4694  */
4695 extern int
4696 wimlib_create_compressor(enum wimlib_compression_type ctype,
4697                          size_t max_block_size,
4698                          unsigned int compression_level,
4699                          struct wimlib_compressor **compressor_ret);
4700
4701 /**
4702  * Compress a buffer of data.
4703  *
4704  * @param uncompressed_data
4705  *      Buffer containing the data to compress.
4706  * @param uncompressed_size
4707  *      Size, in bytes, of the data to compress.  This cannot be greater than
4708  *      the @p max_block_size with which wimlib_create_compressor() was called.
4709  *      (If it is, the data will not be compressed and 0 will be returned.)
4710  * @param compressed_data
4711  *      Buffer into which to write the compressed data.
4712  * @param compressed_size_avail
4713  *      Number of bytes available in @p compressed_data.
4714  * @param compressor
4715  *      A compressor previously allocated with wimlib_create_compressor().
4716  *
4717  * @return
4718  *      The size of the compressed data, in bytes, or 0 if the data could not be
4719  *      compressed to @p compressed_size_avail or fewer bytes.
4720  */
4721 extern size_t
4722 wimlib_compress(const void *uncompressed_data, size_t uncompressed_size,
4723                 void *compressed_data, size_t compressed_size_avail,
4724                 struct wimlib_compressor *compressor);
4725
4726 /**
4727  * Free a compressor previously allocated with wimlib_create_compressor().
4728  *
4729  * @param compressor
4730  *      The compressor to free.  If @c NULL, no action is taken.
4731  */
4732 extern void
4733 wimlib_free_compressor(struct wimlib_compressor *compressor);
4734
4735 /**
4736  * Allocate a decompressor for the specified compression type.  This function is
4737  * part of wimlib's compression API; it is not necessary to call this to process
4738  * a WIM file.
4739  *
4740  * @param ctype
4741  *      Compression type for which to create the decompressor, as one of the
4742  *      ::wimlib_compression_type constants.
4743  * @param max_block_size
4744  *      The maximum compression block size to support.  This specifies the
4745  *      maximum allowed value for the @p uncompressed_size parameter of
4746  *      wimlib_decompress().
4747  *      <br/>
4748  *      In general, this parameter must be the same as the @p max_block_size
4749  *      that was passed to wimlib_create_compressor() when the data was
4750  *      compressed.  However, some compression types have looser requirements
4751  *      regarding this.
4752  * @param decompressor_ret
4753  *      A location into which to return the pointer to the allocated
4754  *      decompressor.  The allocated decompressor can be used for any number of
4755  *      calls to wimlib_decompress() before being freed with
4756  *      wimlib_free_decompressor().
4757  *
4758  * @return 0 on success; a ::wimlib_error_code value on failure.
4759  *
4760  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
4761  *      @p ctype was not a supported compression type.
4762  * @retval ::WIMLIB_ERR_INVALID_PARAM
4763  *      @p max_block_size was invalid for the compression type, or @p
4764  *      decompressor_ret was @c NULL.
4765  * @retval ::WIMLIB_ERR_NOMEM
4766  *      Insufficient memory to allocate the decompressor.
4767  */
4768 extern int
4769 wimlib_create_decompressor(enum wimlib_compression_type ctype,
4770                            size_t max_block_size,
4771                            struct wimlib_decompressor **decompressor_ret);
4772
4773 /**
4774  * Decompress a buffer of data.
4775  *
4776  * @param compressed_data
4777  *      Buffer containing the data to decompress.
4778  * @param compressed_size
4779  *      Size, in bytes, of the data to decompress.
4780  * @param uncompressed_data
4781  *      Buffer into which to write the uncompressed data.
4782  * @param uncompressed_size
4783  *      Size, in bytes, of the data when uncompressed.  This cannot exceed the
4784  *      @p max_block_size with which wimlib_create_decompressor() was called.
4785  *      (If it does, the data will not be decompressed and a nonzero value will
4786  *      be returned.)
4787  * @param decompressor
4788  *      A decompressor previously allocated with wimlib_create_decompressor().
4789  *
4790  * @return 0 on success; nonzero on failure.
4791  *
4792  * No specific error codes are defined; any nonzero value indicates that the
4793  * decompression failed.  This can only occur if the data is truly invalid;
4794  * there will never be transient errors like "out of memory", for example.
4795  *
4796  * This function requires that the exact uncompressed size of the data be passed
4797  * as the @p uncompressed_size parameter.  If this is not done correctly,
4798  * decompression may fail or the data may be decompressed incorrectly.
4799  */
4800 extern int
4801 wimlib_decompress(const void *compressed_data, size_t compressed_size,
4802                   void *uncompressed_data, size_t uncompressed_size,
4803                   struct wimlib_decompressor *decompressor);
4804
4805 /**
4806  * Free a decompressor previously allocated with wimlib_create_decompressor().
4807  *
4808  * @param decompressor
4809  *      The decompressor to free.  If @c NULL, no action is taken.
4810  */
4811 extern void
4812 wimlib_free_decompressor(struct wimlib_decompressor *decompressor);
4813
4814
4815 /**
4816  * @}
4817  */
4818
4819
4820 #ifdef __cplusplus
4821 }
4822 #endif
4823
4824 #endif /* _WIMLIB_H */