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