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