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