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