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