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