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