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