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