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