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