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