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