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