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