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