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