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