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