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