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