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