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