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