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