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