]> wimlib.net Git - wimlib/blob - include/wimlib.h
fcc88b028cf4c44b3a6a94d4a4effead6fae0e22
[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         WIMLIB_ERR_WIM_IS_ENCRYPTED,
1890 };
1891
1892
1893 /** Used to indicate no WIM image or an invalid WIM image. */
1894 #define WIMLIB_NO_IMAGE         0
1895
1896 /** Used to specify all images in the WIM. */
1897 #define WIMLIB_ALL_IMAGES       (-1)
1898
1899 /**
1900  * @ingroup G_modifying_wims
1901  *
1902  * Appends an empty image to a WIM file.  This empty image will initially
1903  * contain no files or directories, although if written without further
1904  * modifications, a root directory will be created automatically for it.  After
1905  * calling this function, you can use wimlib_update_image() to add files to the
1906  * new WIM image.  This gives you slightly more control over making the new
1907  * image compared to calling wimlib_add_image() or
1908  * wimlib_add_image_multisource() directly.
1909  *
1910  * @param wim
1911  *      Pointer to the ::WIMStruct for the WIM file to which the image is to be
1912  *      added.
1913  * @param name
1914  *      Name to give the new image.  If @c NULL or empty, the new image is given
1915  *      no name.  If nonempty, it must specify a name that does not already
1916  *      exist in @p wim.
1917  * @param new_idx_ret
1918  *      If non-<code>NULL</code>, the index of the newly added image is returned
1919  *      in this location.
1920  *
1921  * @return 0 on success; nonzero on failure.  The possible error codes are:
1922  *
1923  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
1924  *      There is already an image in @p wim named @p name.
1925  * @retval ::WIMLIB_ERR_NOMEM
1926  *      Failed to allocate the memory needed to add the new image.
1927  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
1928  *      The WIM file is considered read-only because of any of the reasons
1929  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
1930  *      flag.
1931  */
1932 extern int
1933 wimlib_add_empty_image(WIMStruct *wim,
1934                        const wimlib_tchar *name,
1935                        int *new_idx_ret);
1936
1937 /**
1938  * @ingroup G_modifying_wims
1939  *
1940  * Adds an image to a WIM file from an on-disk directory tree or NTFS volume.
1941  *
1942  * The directory tree or NTFS volume is scanned immediately to load the dentry
1943  * tree into memory, and file attributes and symbolic links are read.  However,
1944  * actual file data is not read until wimlib_write() or wimlib_overwrite() is
1945  * called.
1946  *
1947  * See the manual page for the @b wimlib-imagex program for more information
1948  * about the "normal" capture mode versus the NTFS capture mode (entered by
1949  * providing the flag ::WIMLIB_ADD_FLAG_NTFS).
1950  *
1951  * Note that @b no changes are committed to the underlying WIM file (if
1952  * any) until wimlib_write() or wimlib_overwrite() is called.
1953  *
1954  * @param wim
1955  *      Pointer to the ::WIMStruct for a WIM file to which the image will be
1956  *      added.
1957  * @param source
1958  *      A path to a directory or unmounted NTFS volume that will be captured as
1959  *      a WIM image.
1960  * @param name
1961  *      Name to give the new image.  If @c NULL or empty, the new image is given
1962  *      no name.  If nonempty, it must specify a name that does not already
1963  *      exist in @p wim.
1964  * @param config
1965  *      Capture configuration that specifies files, directories, or path globs
1966  *      to exclude from being captured.  If @c NULL, a dummy configuration where
1967  *      no paths are treated specially is used.
1968  * @param add_flags
1969  *      Bitwise OR of flags prefixed with WIMLIB_ADD_FLAG.
1970  * @param progress_func
1971  *      If non-NULL, a function that will be called periodically with the
1972  *      progress of the current operation.  The progress messages that will be
1973  *      received are ::WIMLIB_PROGRESS_MSG_SCAN_BEGIN,
1974  *      ::WIMLIB_PROGRESS_MSG_SCAN_END, and, if ::WIMLIB_ADD_FLAG_VERBOSE was
1975  *      included in @p add_flags, also ::WIMLIB_PROGRESS_MSG_SCAN_DENTRY.
1976  *
1977  * @return 0 on success; nonzero on error.  On error, changes to @p wim are
1978  * discarded so that it appears to be in the same state as when this function
1979  * was called.
1980  *
1981  * This function is implemented by calling wimlib_add_empty_image(), then
1982  * calling wimlib_update_image() with a single "add" command, so any error code
1983  * returned by wimlib_add_empty_image() may be returned, as well as any error
1984  * codes returned by wimlib_update_image() other than ones documented as only
1985  * being returned specifically by an update involving delete or rename commands.
1986  */
1987 extern int
1988 wimlib_add_image(WIMStruct *wim,
1989                  const wimlib_tchar *source,
1990                  const wimlib_tchar *name,
1991                  const struct wimlib_capture_config *config,
1992                  int add_flags,
1993                  wimlib_progress_func_t progress_func);
1994
1995 /**
1996  * @ingroup G_modifying_wims
1997  *
1998  * This function is equivalent to wimlib_add_image() except it allows for
1999  * multiple sources to be combined into a single WIM image.  This is done by
2000  * specifying the @p sources and @p num_sources parameters instead of the @p
2001  * source parameter of wimlib_add_image().  The rest of the parameters are the
2002  * same as wimlib_add_image().  See the documentation for <b>wimlib-imagex
2003  * capture</b> for full details on how this mode works.
2004  *
2005  * In addition to the error codes that wimlib_add_image() can return,
2006  * wimlib_add_image_multisource() can return ::WIMLIB_ERR_INVALID_OVERLAY
2007  * when trying to overlay a non-directory on a directory or when otherwise
2008  * trying to overlay multiple conflicting files to the same location in the WIM
2009  * image.  It will also return ::WIMLIB_ERR_INVALID_PARAM if
2010  * ::WIMLIB_ADD_FLAG_NTFS was specified in @p add_flags but there
2011  * was not exactly one capture source with the target being the root directory.
2012  * (In this respect, there is no advantage to using
2013  * wimlib_add_image_multisource() instead of wimlib_add_image() when requesting
2014  * NTFS mode.) */
2015 extern int
2016 wimlib_add_image_multisource(WIMStruct *wim,
2017                              const struct wimlib_capture_source *sources,
2018                              size_t num_sources,
2019                              const wimlib_tchar *name,
2020                              const struct wimlib_capture_config *config,
2021                              int add_flags,
2022                              wimlib_progress_func_t progress_func);
2023
2024 /**
2025  * @ingroup G_creating_and_opening_wims
2026  *
2027  * Creates a ::WIMStruct for a new WIM file.
2028  *
2029  * This only creates an in-memory structure for a WIM that initially contains no
2030  * images.  No on-disk file is created until wimlib_write() is called.
2031  *
2032  * @param ctype
2033  *      The type of compression to be used in the new WIM file.  Must be
2034  *      ::WIMLIB_COMPRESSION_TYPE_NONE, ::WIMLIB_COMPRESSION_TYPE_LZX, or
2035  *      ::WIMLIB_COMPRESSION_TYPE_XPRESS.
2036  * @param wim_ret
2037  *      On success, a pointer to an opaque ::WIMStruct for the new WIM file is
2038  *      written to the memory location pointed to by this paramater.  The
2039  *      ::WIMStruct must be freed using using wimlib_free() when finished with
2040  *      it.
2041  * @return 0 on success; nonzero on error.
2042  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
2043  *      @p ctype was not ::WIMLIB_COMPRESSION_TYPE_NONE,
2044  *      ::WIMLIB_COMPRESSION_TYPE_LZX, or ::WIMLIB_COMPRESSION_TYPE_XPRESS.
2045  * @retval ::WIMLIB_ERR_NOMEM
2046  *      Failed to allocate needed memory.
2047  */
2048 extern int
2049 wimlib_create_new_wim(int ctype, WIMStruct **wim_ret);
2050
2051 /**
2052  * @ingroup G_modifying_wims
2053  *
2054  * Deletes an image, or all images, from a WIM file.
2055  *
2056  * All streams referenced by the image(s) being deleted are removed from the
2057  * lookup table of the WIM if they are not referenced by any other images in the
2058  * WIM.
2059  *
2060  * Please note that @b no changes are committed to the underlying WIM file (if
2061  * any) until wimlib_write() or wimlib_overwrite() is called.
2062  *
2063  * @param wim
2064  *      Pointer to the ::WIMStruct for the WIM file that contains the image(s)
2065  *      being deleted.
2066  * @param image
2067  *      The number of the image to delete, or ::WIMLIB_ALL_IMAGES to delete all
2068  *      images.
2069  * @return 0 on success; nonzero on failure.  On failure, @p wim is guaranteed
2070  * to be left unmodified only if @p image specified a single image.  If instead
2071  * @p image was ::WIMLIB_ALL_IMAGES and @p wim contained more than one image, it's
2072  * possible for some but not all of the images to have been deleted when a
2073  * failure status is returned.
2074  *
2075  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2076  *      @p image does not exist in the WIM and is not ::WIMLIB_ALL_IMAGES.
2077  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
2078  *      The WIM file is considered read-only because of any of the reasons
2079  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
2080  *      flag.
2081  *
2082  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2083  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2084  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2085  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2086  * different reasons) to read the metadata resource for an image that needed to
2087  * be deleted.
2088  */
2089 extern int
2090 wimlib_delete_image(WIMStruct *wim, int image);
2091
2092 /**
2093  * @ingroup G_modifying_wims
2094  *
2095  * Exports an image, or all the images, from a WIM file, into another WIM file.
2096  *
2097  * The destination image is made to share the same dentry tree and security data
2098  * structure as the source image.  This places some restrictions on additional
2099  * functions that may be called.  wimlib_mount_image() may not be called on
2100  * either the source image or the destination image without an intervening call
2101  * to a function that un-shares the images, such as wimlib_free() on @p
2102  * dest_wim, or wimlib_delete_image() on either the source or destination image.
2103  * Furthermore, you may not call wimlib_free() on @p src_wim before calling
2104  * wimlib_write() or wimlib_overwrite() on @p dest_wim because @p dest_wim will
2105  * have references back to @p src_wim.
2106  *
2107  * If this function fails, all changes to @p dest_wim are rolled back.
2108  *
2109  * Please note that no changes are committed to the underlying WIM file of @p
2110  * dest_wim (if any) until wimlib_write() or wimlib_overwrite() is called.
2111  *
2112  * @param src_wim
2113  *      The WIM from which to export the images, specified as a pointer to the
2114  *      ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1 of a
2115  *      split WIM.  In the case of a WIM file that is not standalone, this
2116  *      ::WIMStruct must have had any needed external resources previously
2117  *      referenced using wimlib_reference_resources() or
2118  *      wimlib_reference_resource_files().
2119  * @param src_image
2120  *      The image to export from @p src_wim, as either a 1-based image index to
2121  *      export a single image, or ::WIMLIB_ALL_IMAGES to export all images.
2122  * @param dest_wim
2123  *      Pointer to the ::WIMStruct for a WIM that will receive the images being
2124  *      exported.
2125  * @param dest_name
2126  *      For single-image exports, the name to give the exported image in @p
2127  *      dest_wim.  If left @c NULL, the name from @p src_wim is used.  For
2128  *      ::WIMLIB_ALL_IMAGES exports, this parameter must be left @c NULL; in
2129  *      that case, the names are all taken from @p src_wim.  This parameter is
2130  *      overridden by ::WIMLIB_EXPORT_FLAG_NO_NAMES.
2131  * @param dest_description
2132  *      For single-image exports, the description to give the exported image in
2133  *      the new WIM file.  If left @c NULL, the description from @p src_wim is
2134  *      used.  For ::WIMLIB_ALL_IMAGES exports, this parameter must be left @c
2135  *      NULL; in that case, the description are all taken from @p src_wim.  This
2136  *      parameter is overridden by ::WIMLIB_EXPORT_FLAG_NO_DESCRIPTIONS.
2137  * @param export_flags
2138  *      Bitwise OR of flags prefixed with WIMLIB_EXPORT_FLAG.
2139  * @param progress_func
2140  *      Currently ignored, but reserved for a function that will be called with
2141  *      information about the operation.  Use NULL if no additional information
2142  *      is desired.
2143  *
2144  * @return 0 on success; nonzero on error.
2145  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
2146  *      One or more of the names being given to an exported image was already in
2147  *      use in the destination WIM.
2148  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2149  *      @p src_image does not exist in @p src_wim and was not
2150  *      ::WIMLIB_ALL_IMAGES.
2151  * @retval ::WIMLIB_ERR_INVALID_PARAM
2152  *      @p src_wim and/or @p dest_wim were @c NULL; or @p src_image was
2153  *      ::WIMLIB_ALL_IMAGES but @p dest_name and/or @p dest_description were not
2154  *      @c NULL.
2155  * @retval ::WIMLIB_ERR_METADATA_NOT_FOUND
2156  *      Either @p src_wim or @p dest_wim did not contain metadata resources; for
2157  *      example, one of them was a non-first part of a split WIM.
2158  * @retval ::WIMLIB_ERR_NOMEM
2159  *      Failed to allocate needed memory.
2160  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
2161  *      A resource that needed to be exported could not be found in either the
2162  *      source or destination WIMs.  This error can occur if, for example, @p
2163  *      src_wim is part of a split WIM but needed resources from the other split
2164  *      WIM parts were not referenced with wimlib_reference_resources() or
2165  *      wimlib_reference_resource_files() before the call to
2166  *      wimlib_export_image().
2167  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
2168  *      @p dest_wim is considered read-only because of any of the reasons
2169  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
2170  *      flag.
2171  *
2172  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2173  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2174  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2175  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2176  * different reasons) to read the metadata resource for an image in @p src_wim
2177  * that needed to be exported.
2178  */
2179 extern int
2180 wimlib_export_image(WIMStruct *src_wim, int src_image,
2181                     WIMStruct *dest_wim,
2182                     const wimlib_tchar *dest_name,
2183                     const wimlib_tchar *dest_description,
2184                     int export_flags,
2185                     wimlib_progress_func_t progress_func);
2186
2187 /**
2188  * @ingroup G_extracting_wims
2189  *
2190  * Extract zero or more files or directory trees from a WIM image.
2191  *
2192  * This generalizes the single-image extraction functionality of
2193  * wimlib_extract_image() to allow extracting only the specified subsets of the
2194  * image.
2195  *
2196  * @param wim
2197  *      The WIM from which to extract the files, specified as a pointer to the
2198  *      ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1 of a
2199  *      split WIM.  In the case of a WIM file that is not standalone, this
2200  *      ::WIMStruct must have had any needed external resources previously
2201  *      referenced using wimlib_reference_resources() or
2202  *      wimlib_reference_resource_files().
2203  *
2204  * @param image
2205  *      The 1-based number of the image in @p wim from which the files or
2206  *      directory trees are to be extracted.  It cannot be ::WIMLIB_ALL_IMAGES.
2207  *
2208  * @param cmds
2209  *      An array of ::wimlib_extract_command structures that specifies the
2210  *      extractions to perform.
2211  *
2212  * @param num_cmds
2213  *      Number of commands in the @p cmds array.
2214  *
2215  * @param default_extract_flags
2216  *      Default extraction flags; the behavior shall be as if these flags had
2217  *      been specified in the ::wimlib_extract_command.extract_flags member in
2218  *      each extraction command, in combination with any flags already present.
2219  *
2220  * @param progress_func
2221  *      If non-NULL, a function that will be called periodically with the
2222  *      progress of the current operation.
2223  *
2224  * @return 0 on success; nonzero on error.  The possible error codes include
2225  * most of those documented as returned by wimlib_extract_image() as well as the
2226  * following additional error codes:
2227  *
2228  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2229  *      @p image was ::WIMLIB_ALL_IMAGES (or was not otherwise a valid image in
2230  *      the WIM file).
2231  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
2232  *      The ::wimlib_extract_command.wim_source_path member in one of the
2233  *      extract commands did not exist in the WIM.
2234  * @retval ::WIMLIB_ERR_NOT_A_REGULAR_FILE
2235  *      ::WIMLIB_EXTRACT_FLAG_TO_STDOUT was specified for an extraction command
2236  *      in which ::wimlib_extract_command.wim_source_path existed but was not a
2237  *      regular file or directory.
2238  * @retval ::WIMLIB_ERR_INVALID_PARAM
2239  *      ::WIMLIB_EXTRACT_FLAG_HARDLINK or ::WIMLIB_EXTRACT_FLAG_SYMLINK was
2240  *      specified for some commands but not all; or
2241  *      ::wimlib_extract_command.fs_dest_path was @c NULL or the empty string
2242  *      for one or more commands; or ::WIMLIB_EXTRACT_FLAG_RPFIX was specified
2243  *      for a command in which ::wimlib_extract_command.wim_source_path did not
2244  *      specify the root directory of the WIM image.
2245  */
2246 extern int
2247 wimlib_extract_files(WIMStruct *wim,
2248                      int image,
2249                      const struct wimlib_extract_command *cmds,
2250                      size_t num_cmds,
2251                      int default_extract_flags,
2252                      wimlib_progress_func_t progress_func);
2253
2254 /**
2255  * @ingroup G_extracting_wims
2256  *
2257  * Extracts an image, or all images, from a WIM to a directory or directly to a
2258  * NTFS volume image.
2259  *
2260  * The exact behavior of how wimlib extracts files from a WIM image is
2261  * controllable by the @p extract_flags parameter, but there also are
2262  * differences depending on the platform (UNIX-like vs Windows).  See the manual
2263  * page for <b>wimlib-imagex apply</b> for more information, including about the
2264  * special "NTFS volume extraction mode" entered by providing
2265  * ::WIMLIB_EXTRACT_FLAG_NTFS.
2266  *
2267  * All extracted data is SHA1-summed, and ::WIMLIB_ERR_INVALID_RESOURCE_HASH is
2268  * returned if any resulting SHA1 message digests do not match the values
2269  * provided in the WIM file.  Therefore, if this function is successful, you can
2270  * be fairly sure that any compressed data in the WIM was uncompressed
2271  * correctly.
2272  *
2273  * @param wim
2274  *      The WIM from which to extract the image(s), specified as a pointer to
2275  *      the ::WIMStruct for a standalone WIM file, a delta WIM file, or part 1
2276  *      of a split WIM.  In the case of a WIM file that is not standalone, this
2277  *      ::WIMStruct must have had any needed external resources previously
2278  *      referenced using wimlib_reference_resources() or
2279  *      wimlib_reference_resource_files().
2280  * @param image
2281  *      The image to extract.  Can be the number of an image, or ::WIMLIB_ALL_IMAGES
2282  *      to specify that all images are to be extracted.  ::WIMLIB_ALL_IMAGES cannot
2283  *      be used if ::WIMLIB_EXTRACT_FLAG_NTFS is specified in @p extract_flags.
2284  * @param target
2285  *      Directory to extract the WIM image(s) to (created if it does not already
2286  *      exist); or, with ::WIMLIB_EXTRACT_FLAG_NTFS in @p extract_flags, the
2287  *      path to the unmounted NTFS volume to extract the image to.
2288  * @param extract_flags
2289  *      Bitwise OR of the flags prefixed with WIMLIB_EXTRACT_FLAG.
2290  * @param progress_func
2291  *      If non-NULL, a function that will be called periodically with the
2292  *      progress of the current operation.
2293  *
2294  * @return 0 on success; nonzero on error.
2295  * @retval ::WIMLIB_ERR_DECOMPRESSION
2296  *      Failed to decompress a resource to be extracted.
2297  * @retval ::WIMLIB_ERR_INVALID_PARAM
2298  *      Both ::WIMLIB_EXTRACT_FLAG_HARDLINK and ::WIMLIB_EXTRACT_FLAG_SYMLINK
2299  *      were specified in @p extract_flags; or both
2300  *      ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS and ::WIMLIB_EXTRACT_FLAG_NO_ACLS were
2301  *      specified in @p extract_flags; or both ::WIMLIB_EXTRACT_FLAG_RPFIX and
2302  *      ::WIMLIB_EXTRACT_FLAG_NORPFIX were specified in @p extract_flags; or
2303  *      ::WIMLIB_EXTRACT_FLAG_RESUME was specified in @p extract_flags; or if
2304  *      ::WIMLIB_EXTRACT_FLAG_NTFS was specified in @p extract_flags and
2305  *      @p image was ::WIMLIB_ALL_IMAGES.
2306  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
2307  *      The SHA1 message digest of an extracted stream did not match the SHA1
2308  *      message digest given in the WIM file.
2309  * @retval ::WIMLIB_ERR_LINK
2310  *      Failed to create a symbolic link or a hard link.
2311  * @retval ::WIMLIB_ERR_MKDIR
2312  *      Failed create a directory.
2313  * @retval ::WIMLIB_ERR_NOMEM
2314  *      Failed to allocate needed memory.
2315  * @retval ::WIMLIB_ERR_OPEN
2316  *      Could not create a file, or failed to open an already-extracted file.
2317  * @retval ::WIMLIB_ERR_READ
2318  *      Failed to read data from the WIM file associated with @p wim.
2319  * @retval ::WIMLIB_ERR_READLINK
2320  *      Failed to determine the target of a symbolic link in the WIM.
2321  * @retval ::WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED
2322  *      Failed to fix the target of an absolute symbolic link (e.g. if the
2323  *      target would have exceeded the maximum allowed length).  (Only if
2324  *      reparse data was supported by the extraction mode and
2325  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS was specified in @p extract_flags.)
2326  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
2327  *      One of the files or directories that needed to be extracted referenced a
2328  *      stream not present in the WIM's lookup table (or in any of the lookup
2329  *      tables of the split WIM parts).
2330  * @retval ::WIMLIB_ERR_SET_ATTRIBUTES
2331  *      Failed to set attributes on a file.
2332  * @retval ::WIMLIB_ERR_SET_REPARSE_DATA
2333  *      Failed to set reparse data on a file (only if reparse data was supported
2334  *      by the extraction mode).
2335  * @retval ::WIMLIB_ERR_SET_SECURITY
2336  *      Failed to set security descriptor on a file
2337  *      (only if ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS was specified in @p
2338  *      extract_flags).
2339  * @retval ::WIMLIB_ERR_SET_SHORT_NAME
2340  *      Failed to set the short name of a file (only if
2341  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES was specified in @p extract_flags).
2342  * @retval ::WIMLIB_ERR_SET_TIMESTAMPS
2343  *      Failed to set timestamps on a file (only if
2344  *      ::WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS was specified in @p extract_flags).
2345  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
2346  *      Unexpected end-of-file occurred when reading data from the WIM file
2347  *      associated with @p wim.
2348  * @retval ::WIMLIB_ERR_UNSUPPORTED
2349  *      A requested extraction flag, or the data or metadata that must be
2350  *      extracted to support it, is unsupported in the build and configuration
2351  *      of wimlib, or on the current platform or extraction mode or target
2352  *      volume.  Flags affected by this include ::WIMLIB_EXTRACT_FLAG_NTFS,
2353  *      ::WIMLIB_EXTRACT_FLAG_UNIX_DATA, ::WIMLIB_EXTRACT_FLAG_STRICT_ACLS,
2354  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES,
2355  *      ::WIMLIB_EXTRACT_FLAG_STRICT_TIMESTAMPS,
2356  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SYMLINKS, ::WIMLIB_EXTRACT_FLAG_SYMLINK,
2357  *      and ::WIMLIB_EXTRACT_FLAG_HARDLINK.  For example, if
2358  *      ::WIMLIB_EXTRACT_FLAG_STRICT_SHORT_NAMES is specified in @p
2359  *      extract_flags,
2360  *      ::WIMLIB_ERR_UNSUPPORTED will be returned if the WIM image contains one
2361  *      or more files with short names, but extracting short names is not
2362  *      supported --- on Windows, this occurs if the target volume does not
2363  *      support short names, while on non-Windows, this occurs if
2364  *      ::WIMLIB_EXTRACT_FLAG_NTFS was not specified in @p extract_flags.
2365  * @retval ::WIMLIB_ERR_WRITE
2366  *      Failed to write data to a file being extracted.
2367  *
2368  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2369  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2370  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2371  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2372  * different reasons) to read the metadata resource for an image that needed to
2373  * be extracted.
2374  */
2375 extern int
2376 wimlib_extract_image(WIMStruct *wim, int image,
2377                      const wimlib_tchar *target,
2378                      int extract_flags,
2379                      wimlib_progress_func_t progress_func);
2380
2381 /**
2382  * @ingroup G_extracting_wims
2383  *
2384  * Since wimlib v1.5.0:  Extract one or more images from a pipe on which a
2385  * pipable WIM is being sent.
2386  *
2387  * See the documentation for ::WIMLIB_WRITE_FLAG_PIPABLE for more information
2388  * about pipable WIMs.
2389  *
2390  * This function operates in a special way to read the WIM fully sequentially.
2391  * As a result, there is no ::WIMStruct is made visible to library users, and
2392  * you cannot call wimlib_open_wim() on the pipe.  (You can, however, use
2393  * wimlib_open_wim() to transparently open a pipable WIM if it's available as a
2394  * seekable file, not a pipe.)
2395  *
2396  * @param pipe_fd
2397  *      File descriptor, which may be a pipe, opened for reading and positioned
2398  *      at the start of the pipable WIM.
2399  * @param image_num_or_name
2400  *      String that specifies the 1-based index or name of the image to extract.
2401  *      It is translated to an image index using the same rules that
2402  *      wimlib_resolve_image() uses.  However, unlike wimlib_extract_image(),
2403  *      only a single image (not all images) can be specified.  Alternatively,
2404  *      specify @p NULL here to use the first image in the WIM if it contains
2405  *      exactly one image but otherwise return ::WIMLIB_ERR_INVALID_IMAGE.
2406  * @param target
2407  *      Same as the corresponding parameter to wimlib_extract_image().
2408  * @param extract_flags
2409  *      Same as the corresponding parameter to wimlib_extract_image(), except
2410  *      for the following exceptions:  ::WIMLIB_EXTRACT_FLAG_SEQUENTIAL is
2411  *      always implied, since data is always read from @p pipe_fd sequentially
2412  *      in this mode; also, ::WIMLIB_EXTRACT_FLAG_TO_STDOUT is invalid and will
2413  *      result in ::WIMLIB_ERR_INVALID_PARAM being returned.
2414  * @param progress_func
2415  *      Same as the corresponding parameter to wimlib_extract_image(), except
2416  *      ::WIMLIB_PROGRESS_MSG_EXTRACT_SPWM_PART_BEGIN messages will also be
2417  *      received.
2418  *
2419  * @return 0 on success; nonzero on error.  The possible error codes include
2420  * those returned by wimlib_extract_image() as well as the following:
2421  *
2422  * @retval ::WIMLIB_ERR_INVALID_PIPABLE_WIM
2423  *      Data read from the pipable WIM was invalid.
2424  * @retval ::WIMLIB_ERR_NOT_PIPABLE
2425  *      The WIM being piped in a @p pipe_fd is a normal WIM, not a pipable WIM.
2426  */
2427 extern int
2428 wimlib_extract_image_from_pipe(int pipe_fd,
2429                                const wimlib_tchar *image_num_or_name,
2430                                const wimlib_tchar *target, int extract_flags,
2431                                wimlib_progress_func_t progress_func);
2432
2433 /**
2434  * Similar to wimlib_extract_paths(), but the paths to extract from the WIM
2435  * image specified in the UTF-8 text file named by @p path_list_file which
2436  * itself contains the list of paths to use, one per line.  Leading and trailing
2437  * whitespace, and otherwise empty lines and lines beginning with the ';'
2438  * character are ignored.  No quotes are needed as paths are otherwise delimited
2439  * by the newline character.
2440  */
2441 extern int
2442 wimlib_extract_pathlist(WIMStruct *wim, int image,
2443                         const wimlib_tchar *target,
2444                         const wimlib_tchar *path_list_file,
2445                         int extract_flags,
2446                         wimlib_progress_func_t progress_func);
2447
2448 /**
2449  * Similar to wimlib_extract_files(), but the files or directories to extract
2450  * from the WIM image are specified as an array of paths.
2451  *
2452  * Each path will be extracted to a corresponding subdirectory of the @p target
2453  * based on its location in the WIM image.  For example, if one of the paths to
2454  * extract is "/Windows/explorer.exe" and the target is "outdir", the file will
2455  * be extracted to "outdir/Windows/explorer.exe".  Each path to extract must be
2456  * specified as the absolute path to a directory within the WIM image.
2457  * Separators in the paths to extract may be either forwards or backwards
2458  * slashes, and leading path separators are optional.  Symbolic links are not
2459  * dereferenced when interpreting paths to extract.  Paths to extract will be
2460  * interpreted either case-sensitively (UNIX default) or case-insensitively
2461  * (Windows default); this can be changed by wimlib_global_init().
2462  *
2463  * The @p target path, on the other hand, is expected to be a native path.  On
2464  * UNIX-like systems it may not contain backslashes, for example.
2465  *
2466  * By default, if any paths to extract do not exist,
2467  * ::WIMLIB_ERR_PATH_DOES_NOT_EXIST is issued.  This behavior changes if
2468  * ::WIMLIB_EXTRACT_FLAG_GLOB_PATHS is specified.
2469  *
2470  * With ::WIMLIB_EXTRACT_FLAG_GLOB_PATHS specified in @p extract_flags, this
2471  * function additionally allows paths to be globs using the wildcard characters
2472  * '*' and '?'.
2473  */
2474 extern int
2475 wimlib_extract_paths(WIMStruct *wim,
2476                      int image,
2477                      const wimlib_tchar *target,
2478                      const wimlib_tchar * const *paths,
2479                      size_t num_paths,
2480                      int extract_flags,
2481                      wimlib_progress_func_t progress_func);
2482
2483 /**
2484  * @ingroup G_wim_information
2485  *
2486  * Extracts the XML data of a WIM file to a file stream.  Every WIM file
2487  * includes a string of XML that describes the images contained in the WIM.
2488  *
2489  * See wimlib_get_xml_data() to read the XML data into memory instead.
2490  *
2491  * @param wim
2492  *      Pointer to the ::WIMStruct for a WIM file, which does not necessarily
2493  *      have to be standalone (e.g. it could be part of a split WIM).
2494  * @param fp
2495  *      @c stdout, or a FILE* opened for writing, to extract the data to.
2496  *
2497  * @return 0 on success; nonzero on error.
2498  * @retval ::WIMLIB_ERR_INVALID_PARAM
2499  *      @p wim is not a ::WIMStruct that was created by wimlib_open_wim().
2500  * @retval ::WIMLIB_ERR_NOMEM
2501  * @retval ::WIMLIB_ERR_READ
2502  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
2503  *      Failed to read the XML data from the WIM.
2504  * @retval ::WIMLIB_ERR_WRITE
2505  *      Failed to completely write the XML data to @p fp.
2506  */
2507 extern int
2508 wimlib_extract_xml_data(WIMStruct *wim, FILE *fp);
2509
2510 /**
2511  * @ingroup G_general
2512  *
2513  * Frees all memory allocated for a WIMStruct and closes all files associated
2514  * with it.
2515  *
2516  * @param wim
2517  *      Pointer to the ::WIMStruct for a WIM file.
2518  *
2519  * @return This function has no return value.
2520  */
2521 extern void
2522 wimlib_free(WIMStruct *wim);
2523
2524 /**
2525  * @ingroup G_general
2526  *
2527  * Converts a ::wimlib_compression_type value into a string.
2528  *
2529  * @param ctype
2530  *      ::WIMLIB_COMPRESSION_TYPE_NONE, ::WIMLIB_COMPRESSION_TYPE_LZX,
2531  *      ::WIMLIB_COMPRESSION_TYPE_XPRESS, or another value.
2532  *
2533  * @return
2534  *      A statically allocated string: "None", "LZX", "XPRESS", or "Invalid",
2535  *      respectively.
2536  */
2537 extern const wimlib_tchar *
2538 wimlib_get_compression_type_string(int ctype);
2539
2540 /**
2541  * @ingroup G_general
2542  *
2543  * Converts an error code into a string describing it.
2544  *
2545  * @param code
2546  *      The error code returned by one of wimlib's functions.
2547  *
2548  * @return
2549  *      Pointer to a statically allocated string describing the error code,
2550  *      or @c NULL if the error code is not valid.
2551  */
2552 extern const wimlib_tchar *
2553 wimlib_get_error_string(enum wimlib_error_code code);
2554
2555 /**
2556  * @ingroup G_wim_information
2557  *
2558  * Returns the description of the specified image.
2559  *
2560  * @param wim
2561  *      Pointer to the ::WIMStruct for a WIM file that does not necessarily have
2562  *      to be standalone (e.g. it could be part of a split WIM).
2563  * @param image
2564  *      The number of the image, numbered starting at 1.
2565  *
2566  * @return
2567  *      The description of the image, or @c NULL if there is no such image, or
2568  *      @c NULL if the specified image has no description.  The description
2569  *      string is in library-internal memory and may not be modified or freed;
2570  *      in addition, the string will become invalid if the description of the
2571  *      image is changed, the image is deleted, or the ::WIMStruct is destroyed.
2572  */
2573 extern const wimlib_tchar *
2574 wimlib_get_image_description(const WIMStruct *wim, int image);
2575
2576 /**
2577  * @ingroup G_wim_information
2578  *
2579  * Returns the name of the specified image.
2580  *
2581  * @param wim
2582  *      Pointer to the ::WIMStruct for a WIM file that does not necessarily have
2583  *      to be standalone (e.g. it could be part of a split WIM).
2584  * @param image
2585  *      The number of the image, numbered starting at 1.
2586  *
2587  * @return
2588  *      The name of the image, or @c NULL if there is no such image, or an empty
2589  *      string if the image is unnamed.  The name string is in
2590  *      library-internal memory and may not be modified or freed; in addition,
2591  *      the string will become invalid if the name of the image is changed, the
2592  *      image is deleted, or the ::WIMStruct is destroyed.
2593  */
2594 extern const wimlib_tchar *
2595 wimlib_get_image_name(const WIMStruct *wim, int image);
2596
2597
2598 /**
2599  * @ingroup G_wim_information
2600  *
2601  * Get basic information about a WIM file.
2602  *
2603  * @param wim
2604  *      Pointer to the ::WIMStruct for a WIM file that does not necessarily have
2605  *      to be standalone (e.g. it could be part of a split WIM).
2606  * @param info
2607  *      A ::wimlib_wim_info structure that will be filled in with information
2608  *      about the WIM file.
2609  * @return
2610  *      0
2611  */
2612 extern int
2613 wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info);
2614
2615 /**
2616  * @ingroup G_wim_information
2617  *
2618  * Read the XML data of a WIM file into an in-memory buffer.  Every WIM file
2619  * includes a string of XML that describes the images contained in the WIM.
2620  *
2621  * See wimlib_extract_xml_data() to extract the XML data to a file stream
2622  * instead.
2623  *
2624  * @param wim
2625  *      Pointer to the ::WIMStruct for a WIM file, which does not necessarily
2626  *      have to be standalone (e.g. it could be part of a split WIM).
2627  * @param buf_ret
2628  *      On success, a pointer to an allocated buffer containing the raw UTF16-LE
2629  *      XML data is written to this location.
2630  * @param bufsize_ret
2631  *      The size of the XML data in bytes is written to this location.
2632  *
2633  * @return 0 on success; nonzero on error.
2634  * @retval ::WIMLIB_ERR_INVALID_PARAM
2635  *      @p wim is not a ::WIMStruct that was created by wimlib_open_wim(), or
2636  *      @p buf_ret or @p bufsize_ret was @c NULL.
2637  * @retval ::WIMLIB_ERR_NOMEM
2638  * @retval ::WIMLIB_ERR_READ
2639  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
2640  *      Failed to read the XML data from the WIM.
2641  */
2642 extern int
2643 wimlib_get_xml_data(WIMStruct *wim, void **buf_ret, size_t *bufsize_ret);
2644
2645 /**
2646  * @ingroup G_general
2647  *
2648  * Initialization function for wimlib.  Call before using any other wimlib
2649  * function except wimlib_set_print_errors().  If not done manually, this
2650  * function will be called automatically with @p init_flags set to
2651  * ::WIMLIB_INIT_FLAG_ASSUME_UTF8.  This function does nothing if called again
2652  * after it has already successfully run.
2653  *
2654  * @param init_flags
2655  *      Bitwise OR of flags prefixed with WIMLIB_INIT_FLAG.
2656  *
2657  * @return 0 on success; nonzero on failure.  Currently, only the following
2658  * error code is defined:
2659  *
2660  * @retval ::WIMLIB_ERR_INSUFFICIENT_PRIVILEGES
2661  *      ::WIMLIB_INIT_FLAG_STRICT_APPLY_PRIVILEGES and/or
2662  *      ::WIMLIB_INIT_FLAG_STRICT_CAPTURE_PRIVILEGES were specified in @p
2663  *      init_flags, but the corresponding privileges could not be acquired.
2664  */
2665 extern int
2666 wimlib_global_init(int init_flags);
2667
2668 /**
2669  * @ingroup G_general
2670  *
2671  * Cleanup function for wimlib.  You are not required to call this function, but
2672  * it will release any global resources allocated by the library.
2673  */
2674 extern void
2675 wimlib_global_cleanup(void);
2676
2677 /**
2678  * @ingroup G_wim_information
2679  *
2680  * Determines if an image name is already used by some image in the WIM.
2681  *
2682  * @param wim
2683  *      Pointer to the ::WIMStruct for a WIM file.
2684  * @param name
2685  *      The name to check.
2686  *
2687  * @return
2688  *      @c true if there is already an image in @p wim named @p name; @c false
2689  *      if there is no image named @p name in @p wim.  If @p name is @c NULL or
2690  *      the empty string, @c false is returned.
2691  */
2692 extern bool
2693 wimlib_image_name_in_use(const WIMStruct *wim, const wimlib_tchar *name);
2694
2695 /**
2696  * @ingroup G_wim_information
2697  *
2698  * Iterate through a file or directory tree in the WIM image.  By specifying
2699  * appropriate flags and a callback function, you can get the attributes of a
2700  * file in the WIM, get a directory listing, or even get a listing of the entire
2701  * WIM image.
2702  *
2703  * @param wim
2704  *      The WIM containing the image(s) over which to iterate, specified as a
2705  *      pointer to the ::WIMStruct for a standalone WIM file, a delta WIM file,
2706  *      or part 1 of a split WIM.  In the case of a WIM file that is not
2707  *      standalone, this ::WIMStruct should have had any needed external
2708  *      resources previously referenced using wimlib_reference_resources() or
2709  *      wimlib_reference_resource_files().  If not, see
2710  *      ::WIMLIB_ITERATE_DIR_TREE_FLAG_RESOURCES_NEEDED for information about
2711  *      the behavior when resources are missing.
2712  *
2713  * @param image
2714  *      The 1-based number of the image in @p wim that contains the files or
2715  *      directories to iterate over, or ::WIMLIB_ALL_IMAGES to repeat the same
2716  *      iteration on all images in the WIM.
2717  *
2718  * @param path
2719  *      Path in the WIM image at which to do the iteration.
2720  *
2721  * @param flags
2722  *      Bitwise OR of flags prefixed with WIMLIB_ITERATE_DIR_TREE_FLAG.
2723  *
2724  * @param cb
2725  *      A callback function that will receive each directory entry.
2726  *
2727  * @param user_ctx
2728  *      An extra parameter that will always be passed to the callback function
2729  *      @p cb.
2730  *
2731  * @return Normally, returns 0 if all calls to @p cb returned 0; otherwise the
2732  * first nonzero value that was returned from @p cb.  However, additional error
2733  * codes may be returned, including the following:
2734  *
2735  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
2736  *      @p path did not exist in the WIM image.
2737  * @retval ::WIMLIB_ERR_NOMEM
2738  *      Failed to allocate memory needed to create a ::wimlib_dir_entry.
2739  *
2740  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2741  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2742  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2743  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2744  * different reasons) to read the metadata resource for an image over which
2745  * iteration needed to be done.
2746  */
2747 extern int
2748 wimlib_iterate_dir_tree(WIMStruct *wim, int image, const wimlib_tchar *path,
2749                         int flags,
2750                         wimlib_iterate_dir_tree_callback_t cb, void *user_ctx);
2751
2752 /**
2753  * @ingroup G_wim_information
2754  *
2755  * Iterate through the lookup table of a WIM file.  This can be used to directly
2756  * get a listing of the unique resources contained in a WIM file over all
2757  * images.  Both file resources and metadata resources are included.  However,
2758  * only resources actually included in the file represented by @a wim, plus
2759  * explicitly referenced external resources (via wimlib_reference_resources() or
2760  * wimlib_reference_resource_files()) are included in the iteration.  For
2761  * example, if @p wim represents just one part of a split WIM, then only
2762  * resources in that part will be included, unless other resources were
2763  * explicitly referenced.
2764  *
2765  * @param wim
2766  *      Pointer to the ::WIMStruct for a WIM file that does not necessarily have
2767  *      to be standalone (e.g. it could be part of a split WIM).
2768  *
2769  * @param flags
2770  *      Reserved; set to 0.
2771  *
2772  * @param cb
2773  *      A callback function that will receive each resource.
2774  *
2775  * @param user_ctx
2776  *      An extra parameter that will always be passed to the callback function
2777  *      @p cb.
2778  *
2779  * @return 0 if all calls to @p cb returned 0; otherwise the first nonzero value
2780  * that was returned from @p cb.
2781  */
2782 extern int
2783 wimlib_iterate_lookup_table(WIMStruct *wim, int flags,
2784                             wimlib_iterate_lookup_table_callback_t cb,
2785                             void *user_ctx);
2786
2787 /**
2788  * @ingroup G_nonstandalone_wims
2789  *
2790  * Joins a split WIM into a stand-alone one-part WIM.
2791  *
2792  * @param swms
2793  *      An array of strings that gives the filenames of all parts of the split
2794  *      WIM.  No specific order is required, but all parts must be included with
2795  *      no duplicates.
2796  * @param num_swms
2797  *      Number of filenames in @p swms.
2798  * @param swm_open_flags
2799  *      Open flags for the split WIM parts (e.g.
2800  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY).
2801  * @param wim_write_flags
2802  *      Bitwise OR of relevant flags prefixed with WIMLIB_WRITE_FLAG, which will
2803  *      be used to write the joined WIM.
2804  * @param output_path
2805  *      The path to write the joined WIM file to.
2806  * @param progress_func
2807  *      If non-NULL, a function that will be called periodically with the
2808  *      progress of the current operation.
2809  *
2810  * @return 0 on success; nonzero on error.  This function may return most error
2811  * codes that can be returned by wimlib_open_wim() and wimlib_write(), as well
2812  * as the following error code:
2813  *
2814  * @retval ::WIMLIB_ERR_SPLIT_INVALID
2815  *      The split WIMs do not form a valid WIM because they do not include all
2816  *      the parts of the original WIM, there are duplicate parts, or not all the
2817  *      parts have the same GUID and compression type.
2818  *
2819  * Note: wimlib is generalized enough that this function is not actually needed
2820  * to join a split WIM; instead, you could open the first part of the split WIM,
2821  * then reference the other parts with wimlib_reference_resource_files(), then
2822  * write the joined WIM using wimlib_write().  However, wimlib_join() provides
2823  * an easy-to-use wrapper around this that has some advantages (e.g.  extra
2824  * sanity checks).
2825  */
2826 extern int
2827 wimlib_join(const wimlib_tchar * const *swms,
2828             unsigned num_swms,
2829             const wimlib_tchar *output_path,
2830             int swm_open_flags,
2831             int wim_write_flags,
2832             wimlib_progress_func_t progress_func);
2833
2834
2835 /**
2836  * @ingroup G_mounting_wim_images
2837  *
2838  * Mounts an image in a WIM file on a directory read-only or read-write.
2839  *
2840  * As this is implemented using FUSE (Filesystme in UserSpacE), this is not
2841  * supported if wimlib was configured with @c --without-fuse.  This includes
2842  * Windows builds of wimlib; ::WIMLIB_ERR_UNSUPPORTED will be returned in such
2843  * cases.
2844  *
2845  * Calling this function daemonizes the process, unless
2846  * ::WIMLIB_MOUNT_FLAG_DEBUG was specified or an early occur occurs.  If the
2847  * mount is read-write (::WIMLIB_MOUNT_FLAG_READWRITE specified), modifications
2848  * to the WIM are staged in a temporary directory.
2849  *
2850  * It is safe to mount multiple images from the same underlying WIM file
2851  * read-only at the same time, but only if different ::WIMStruct's are used.  It
2852  * is @b not safe to mount multiple images from the same WIM file read-write at
2853  * the same time.
2854  *
2855  * wimlib_mount_image() cannot be used on an image that was exported with
2856  * wimlib_export_image() while the dentry trees for both images are still in
2857  * memory.  In addition, wimlib_mount_image() may not be used to mount an image
2858  * that already has modifications pending (e.g. an image added with
2859  * wimlib_add_image()).
2860  *
2861  * @param wim
2862  *      Pointer to the ::WIMStruct containing the image to be mounted.
2863  * @param image
2864  *      The number of the image to mount, indexed starting from it.  It must be
2865  *      an existing, single image.
2866  * @param dir
2867  *      The path to an existing empty directory to mount the image on.
2868  * @param mount_flags
2869  *      Bitwise OR of the flags prefixed with WIMLIB_MOUNT_FLAG.
2870  * @param staging_dir
2871  *      If non-NULL, the name of a directory in which the staging directory will
2872  *      be created.  Ignored if ::WIMLIB_MOUNT_FLAG_READWRITE is not specified
2873  *      in @p mount_flags.  If left @c NULL, the staging directory is created in
2874  *      the same directory as the WIM file that @p wim was originally read from.
2875  *
2876  * @return 0 on success; nonzero on error.
2877  *
2878  * @retval ::WIMLIB_ERR_ALREADY_LOCKED
2879  *      A read-write mount was requested, but an an exclusive advisory lock on
2880  *      the on-disk WIM file could not be acquired because another thread or
2881  *      process has mounted an image from the WIM read-write or is currently
2882  *      modifying the WIM in-place.
2883  * @retval ::WIMLIB_ERR_FUSE
2884  *      A non-zero status was returned by @c fuse_main().
2885  * @retval ::WIMLIB_ERR_INVALID_IMAGE
2886  *      @p image does not specify an existing, single image in @p wim.
2887  * @retval ::WIMLIB_ERR_INVALID_PARAM
2888  *      @p image is shared among multiple ::WIMStruct's as a result of a call to
2889  *      wimlib_export_image(), or @p image has been added with
2890  *      wimlib_add_image().
2891  * @retval ::WIMLIB_ERR_MKDIR
2892  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @p mount_flags, but the
2893  *      staging directory could not be created.
2894  * @retval ::WIMLIB_ERR_NOTDIR
2895  *      Could not determine the current working directory.
2896  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
2897  *      One of the dentries in the image referenced a stream not present in the
2898  *      WIM's lookup table (or in any of the lookup tables of the split WIM
2899  *      parts).
2900  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
2901  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @p mount_flags, but @p
2902  *      wim is considered read-only because of any of the reasons mentioned in
2903  *      the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
2904  * @retval ::WIMLIB_ERR_UNSUPPORTED
2905  *      Mounting is not supported, either because the platform is Windows, or
2906  *      because the platform is UNIX-like and wimlib was compiled with @c
2907  *      --without-fuse.
2908  *
2909  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
2910  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
2911  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
2912  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
2913  * different reasons) to read the metadata resource for the image to mount.
2914  */
2915 extern int
2916 wimlib_mount_image(WIMStruct *wim,
2917                    int image,
2918                    const wimlib_tchar *dir,
2919                    int mount_flags,
2920                    const wimlib_tchar *staging_dir);
2921
2922 /**
2923  * @ingroup G_creating_and_opening_wims
2924  *
2925  * Opens a WIM file and creates a ::WIMStruct for it.
2926  *
2927  * @param wim_file
2928  *      The path to the WIM file to open.
2929  *
2930  * @param open_flags
2931  *      Bitwise OR of flags prefixed with WIMLIB_OPEN_FLAG.
2932  *
2933  * @param progress_func
2934  *      If non-NULL, a function that will be called periodically with the
2935  *      progress of the current operation.  Currently, the only messages sent
2936  *      will be ::WIMLIB_PROGRESS_MSG_VERIFY_INTEGRITY, and only if
2937  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @p open_flags.
2938  *
2939  * @param wim_ret
2940  *      On success, a pointer to an opaque ::WIMStruct for the opened WIM file
2941  *      is written to the memory location pointed to by this parameter.  The
2942  *      ::WIMStruct can be freed using using wimlib_free() when finished with
2943  *      it.
2944  *
2945  * @return 0 on success; nonzero on error.
2946  * @retval ::WIMLIB_ERR_IMAGE_COUNT
2947  *      The WIM is not the non-first part of a split WIM, and the number of
2948  *      metadata resources found in the WIM did not match the image count given
2949  *      in the WIM header, or the number of &lt;IMAGE&gt; elements in the XML
2950  *      data for the WIM did not match the image count given in the WIM header.
2951  * @retval ::WIMLIB_ERR_INTEGRITY
2952  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @p open_flags and @p
2953  *      wim_file contains an integrity table, but the SHA1 message digest for a
2954  *      chunk of the WIM does not match the corresponding message digest given
2955  *      in the integrity table.
2956  * @retval ::WIMLIB_ERR_INVALID_CHUNK_SIZE
2957  *      Resources in @p wim_file are compressed, but the chunk size was invalid
2958  *      for the WIM's compression format.
2959  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
2960  *      The header of @p wim_file says that resources in the WIM are compressed,
2961  *      but the header flag indicating LZX or XPRESS compression is not set.
2962  * @retval ::WIMLIB_ERR_INVALID_HEADER
2963  *      The header of @p wim_file was otherwise invalid.
2964  * @retval ::WIMLIB_ERR_INVALID_INTEGRITY_TABLE
2965  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @p open_flags and @p
2966  *      wim_file contains an integrity table, but the integrity table is
2967  *      invalid.
2968  * @retval ::WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY
2969  *      The lookup table for the WIM contained duplicate entries that are not
2970  *      for metadata resources, or it contained an entry with a SHA1 message
2971  *      digest of all 0's.
2972  * @retval ::WIMLIB_ERR_INVALID_PARAM
2973  *      @p wim_ret was @c NULL.
2974  * @retval ::WIMLIB_ERR_IS_SPLIT_WIM
2975  *      @p wim_file is a split WIM and ::WIMLIB_OPEN_FLAG_ERROR_IF_SPLIT was
2976  *      specified in @p open_flags.
2977  * @retval ::WIMLIB_ERR_NOMEM
2978  *      Failed to allocated needed memory.
2979  * @retval ::WIMLIB_ERR_NOT_A_WIM_FILE
2980  *      @p wim_file does not begin with the expected magic characters.
2981  * @retval ::WIMLIB_ERR_OPEN
2982  *      Failed to open the file @p wim_file for reading.
2983  * @retval ::WIMLIB_ERR_READ
2984  *      Failed to read data from @p wim_file.
2985  * @retval ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE
2986  *      Unexpected end-of-file while reading data from @p wim_file.
2987  * @retval ::WIMLIB_ERR_UNKNOWN_VERSION
2988  *      A number other than 0x10d00 is written in the version field of the WIM
2989  *      header of @p wim_file.  (May be a pre-Vista WIM.)
2990  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
2991  *      ::WIMLIB_OPEN_FLAG_WRITE_ACCESS was specified but the WIM file was
2992  *      considered read-only because of any of the reasons mentioned in the
2993  *      documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
2994  * @retval ::WIMLIB_ERR_XML
2995  *      The XML data for @p wim_file is invalid.
2996  */
2997 extern int
2998 wimlib_open_wim(const wimlib_tchar *wim_file,
2999                 int open_flags,
3000                 WIMStruct **wim_ret,
3001                 wimlib_progress_func_t progress_func);
3002
3003 /**
3004  * @ingroup G_writing_and_overwriting_wims
3005  *
3006  * Overwrites the file that the WIM was originally read from, with changes made.
3007  * This only makes sense for ::WIMStruct's obtained from wimlib_open_wim()
3008  * rather than wimlib_create_new_wim().
3009  *
3010  * There are two ways that a WIM may be overwritten.  The first is to do a full
3011  * rebuild.  In this mode, the new WIM is written to a temporary file and then
3012  * renamed to the original file after it is has been completely written.  The
3013  * temporary file is made in the same directory as the original WIM file.  A
3014  * full rebuild may take a while, but can be used even if images have been
3015  * modified or deleted, will produce a WIM with no holes, and has little chance
3016  * of unintentional data loss because the temporary WIM is fsync()ed before
3017  * being renamed to the original WIM.
3018  *
3019  * The second way to overwrite a WIM is by appending to the end of it and
3020  * overwriting the header.  This can be much faster than a full rebuild, but the
3021  * disadvantage is that some space will be wasted.  Writing a WIM in this mode
3022  * begins with writing any new file resources *after* everything in the old WIM,
3023  * even though this will leave a hole where the old lookup table, XML data, and
3024  * integrity were.  This is done so that the WIM remains valid even if the
3025  * operation is aborted mid-write.  The WIM header is only overwritten at the
3026  * very last moment, and up until that point the WIM will be seen as the old
3027  * version.
3028  *
3029  * By default, wimlib_overwrite() does the append-style overwrite described
3030  * above, unless resources in the WIM are arranged in an unusual way or if
3031  * images have been deleted from the WIM.  Use the flag
3032  * ::WIMLIB_WRITE_FLAG_REBUILD to explicitly request a full rebuild, and use the
3033  * ::WIMLIB_WRITE_FLAG_SOFT_DELETE to request the in-place overwrite even if
3034  * images have been deleted from the WIM.
3035  *
3036  * In the temporary-file overwrite mode, no changes are made to the WIM on
3037  * failure, and the temporary file is deleted if possible.  Abnormal termination
3038  * of the program will result in the temporary file being orphaned.  In the
3039  * direct append mode, the WIM is truncated to the original length on failure;
3040  * and while abnormal termination of the program will result in extra data
3041  * appended to the original WIM, it should still be a valid WIM.
3042  *
3043  * If this function completes successfully, no more functions should be called
3044  * on @p wim other than wimlib_free().  You must use wimlib_open_wim() to read
3045  * the WIM file anew.
3046  *
3047  * @param wim
3048  *      Pointer to the ::WIMStruct for the WIM file to write.  There may have
3049  *      been in-memory changes made to it, which are then reflected in the
3050  *      output file.
3051  * @param write_flags
3052  *      Bitwise OR of relevant flags prefixed with WIMLIB_WRITE_FLAG.
3053  * @param num_threads
3054  *      Number of threads to use for compression (see wimlib_write()).
3055  * @param progress_func
3056  *      If non-NULL, a function that will be called periodically with the
3057  *      progress of the current operation.
3058  *
3059  * @return 0 on success; nonzero on error.  This function may return most error
3060  * codes returned by wimlib_write() as well as the following error codes:
3061  *
3062  * @retval ::WIMLIB_ERR_ALREADY_LOCKED
3063  *      The WIM was going to be modified in-place (with no temporary file), but
3064  *      an exclusive advisory lock on the on-disk WIM file could not be acquired
3065  *      because another thread or process has mounted an image from the WIM
3066  *      read-write or is currently modifying the WIM in-place.
3067  * @retval ::WIMLIB_ERR_NO_FILENAME
3068  *      @p wim corresponds to a WIM created with wimlib_create_new_wim() rather
3069  *      than a WIM read with wimlib_open_wim().
3070  * @retval ::WIMLIB_ERR_RENAME
3071  *      The temporary file that the WIM was written to could not be renamed to
3072  *      the original filename of @p wim.
3073  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3074  *      The WIM file is considered read-only because of any of the reasons
3075  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
3076  *      flag.
3077  */
3078 extern int
3079 wimlib_overwrite(WIMStruct *wim, int write_flags, unsigned num_threads,
3080                  wimlib_progress_func_t progress_func);
3081
3082 /**
3083  * @ingroup G_wim_information
3084  *
3085  * Prints information about one image, or all images, contained in a WIM.
3086  *
3087  * @param wim
3088  *      Pointer to the ::WIMStruct for a WIM file.
3089  * @param image
3090  *      The image about which to print information.  Can be the number of an
3091  *      image, or ::WIMLIB_ALL_IMAGES to print information about all images in the
3092  *      WIM.
3093  *
3094  * @return This function has no return value.  No error checking is done when
3095  * printing the information.  If @p image is invalid, an error message is
3096  * printed.
3097  */
3098 extern void
3099 wimlib_print_available_images(const WIMStruct *wim, int image);
3100
3101 /**
3102  * @ingroup G_wim_information
3103  *
3104  * Deprecated in favor of wimlib_get_wim_info(), which provides the information
3105  * in a way that can be accessed programatically.
3106  */
3107 extern void
3108 wimlib_print_header(const WIMStruct *wim) _wimlib_deprecated;
3109
3110 /**
3111  * @ingroup G_wim_information
3112  *
3113  * Deprecated in favor of wimlib_iterate_dir_tree(), which provides the
3114  * information in a way that can be accessed programatically.
3115  */
3116 extern int
3117 wimlib_print_metadata(WIMStruct *wim, int image) _wimlib_deprecated;
3118
3119 /**
3120  * @ingroup G_nonstandalone_wims
3121  *
3122  * Reference resources from other WIM files or split WIM parts.  This function
3123  * can be used on WIMs that are not standalone, such as split or "delta" WIMs,
3124  * to load needed resources (that is, "streams" keyed by SHA1 message digest)
3125  * from other files, before calling a function such as wimlib_extract_image()
3126  * that requires the resources to be present.
3127  *
3128  * @param wim
3129  *      The ::WIMStruct for a WIM that contains metadata resources, but is not
3130  *      necessarily "standalone".  In the case of split WIMs, this should be the
3131  *      first part, since only the first part contains the metadata resources.
3132  *      In the case of delta WIMs, this should be the delta WIM rather than the
3133  *      WIM on which it is based.
3134  * @param resource_wimfiles_or_globs
3135  *      Array of paths to WIM files and/or split WIM parts to reference.
3136  *      Alternatively, when ::WIMLIB_REF_FLAG_GLOB_ENABLE is specified in @p
3137  *      ref_flags, these are treated as globs rather than literal paths.  That
3138  *      is, using this function you can specify zero or more globs, each of
3139  *      which expands to one or more literal paths.
3140  * @param count
3141  *      Number of entries in @p resource_wimfiles_or_globs.
3142  * @param ref_flags
3143  *      Bitwise OR of ::WIMLIB_REF_FLAG_GLOB_ENABLE and/or
3144  *      ::WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH.
3145  * @param open_flags
3146  *      Additional open flags, such as ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY, to
3147  *      pass to internal calls to wimlib_open_wim() on the reference files.
3148  * @param progress_func
3149  *      Passed to internal calls to wimlib_open_wim() on the reference files.
3150  *
3151  * @return 0 on success; nonzero on error.
3152  *
3153  * @retval ::WIMLIB_ERR_GLOB_HAD_NO_MATCHES
3154  *      One of the specified globs did not match any paths (only with both
3155  *      ::WIMLIB_REF_FLAG_GLOB_ENABLE and ::WIMLIB_REF_FLAG_GLOB_ERR_ON_NOMATCH
3156  *      specified in @p ref_flags).
3157  * @retval ::WIMLIB_ERR_NOMEM
3158  *      Failed to allocate memory.
3159  * @retval ::WIMLIB_ERR_READ
3160  *      I/O or permissions error while processing a file glob.
3161  *
3162  * This function can additionally return most values that can be returned by
3163  * wimlib_open_wim().
3164  */
3165 extern int
3166 wimlib_reference_resource_files(WIMStruct *wim,
3167                                 const wimlib_tchar * const *resource_wimfiles_or_globs,
3168                                 unsigned count,
3169                                 int ref_flags,
3170                                 int open_flags,
3171                                 wimlib_progress_func_t progress_func);
3172
3173 /**
3174  * @ingroup G_nonstandalone_wims
3175  *
3176  * Similar to wimlib_reference_resource_files(), but operates at a lower level
3177  * where the caller must open the ::WIMStruct for each referenced file itself.
3178  *
3179  * @param wim
3180  *      The ::WIMStruct for a WIM that contains metadata resources, but is not
3181  *      necessarily "standalone".  In the case of split WIMs, this should be the
3182  *      first part, since only the first part contains the metadata resources.
3183  * @param resource_wims
3184  *      Array of pointers to the ::WIMStruct's for additional resource WIMs or
3185  *      split WIM parts to reference.
3186  * @param num_resource_wims
3187  *      Number of entries in @p resource_wims.
3188  * @param ref_flags
3189  *      Currently ignored (set to 0).
3190  *
3191  * @return 0 on success; nonzero on error.  On success, the ::WIMStruct's of the
3192  * @p resource_wims are referenced internally by @p wim and must not be freed
3193  * with wimlib_free() or overwritten with wimlib_overwrite() until @p wim has
3194  * been freed with wimlib_free(), or immediately before freeing @p wim with
3195  * wimlib_free().
3196  *
3197  * @retval ::WIMLIB_ERR_INVALID_PARAM
3198  *      @p wim was @c NULL, or @p num_resource_wims was nonzero but @p
3199  *      resource_wims was @c NULL, or an entry in @p resource_wims was @p NULL.
3200  * @retval ::WIMLIB_ERR_NOMEM
3201  *      Failed to allocate memory.
3202  */
3203 extern int
3204 wimlib_reference_resources(WIMStruct *wim, WIMStruct **resource_wims,
3205                            unsigned num_resource_wims, int ref_flags);
3206
3207 /**
3208  * @ingroup G_modifying_wims
3209  *
3210  * Declares that a newly added image is mostly the same as a prior image, but
3211  * captured at a later point in time, possibly with some modifications in the
3212  * intervening time.  This is designed to be used in incremental backups of the
3213  * same filesystem or directory tree.
3214  *
3215  * This function compares the metadata of the directory tree of the newly added
3216  * image against that of the old image.  Any files that are present in both the
3217  * newly added image and the old image and have timestamps that indicate they
3218  * haven't been modified are deemed not to have been modified and have their
3219  * SHA1 message digest copied from the old image.  Because of this and because
3220  * WIM uses single-instance streams, such files need not be read from the
3221  * filesystem when the WIM is being written or overwritten.  Note that these
3222  * unchanged files will still be "archived" and will be logically present in the
3223  * new image; the optimization is that they don't need to actually be read from
3224  * the filesystem because the WIM already contains them.
3225  *
3226  * This function is provided to optimize incremental backups.  The resulting WIM
3227  * file will still be the same regardless of whether this function is called.
3228  * (This is, however, assuming that timestamps have not been manipulated or
3229  * unmaintained as to trick this function into thinking a file has not been
3230  * modified when really it has.  To partly guard against such cases, other
3231  * metadata such as file sizes will be checked as well.)
3232  *
3233  * This function must be called after adding the new image (e.g. with
3234  * wimlib_add_image()), but before writing the updated WIM file (e.g. with
3235  * wimlib_overwrite()).
3236  *
3237  * @param wim
3238  *      Pointer to the ::WIMStruct for a WIM.
3239  * @param new_image
3240  *      1-based index in the WIM of the newly added image.  This image can have
3241  *      been added with wimlib_add_image() or wimlib_add_image_multisource(), or
3242  *      wimlib_add_empty_image() followed by wimlib_update_image().
3243  * @param template_wim
3244  *      The ::WIMStruct for the WIM containing the template image.  This can be
3245  *      the same as @p wim, or it can be a different ::WIMStruct.
3246  * @param template_image
3247  *      1-based index in the WIM of a template image that reflects a prior state
3248  *      of the directory tree being captured.
3249  * @param flags
3250  *      Reserved; must be 0.
3251  * @param progress_func
3252  *      Currently ignored, but reserved for a function that will be called with
3253  *      information about the operation.  Use NULL if no additional information
3254  *      is desired.
3255  *
3256  * @return 0 on success; nonzero on error.
3257  *
3258  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3259  *      @p new_image and/or @p template_image were not a valid image indices in
3260  *      the WIM.
3261  * @retval ::WIMLIB_ERR_METADATA_NOT_FOUND
3262  *      The specified ::WIMStruct did not actually contain the metadata resource
3263  *      for the new or template image; for example, it was a non-first part of a
3264  *      split WIM.
3265  * @retval ::WIMLIB_ERR_NOMEM
3266  *      Failed to allocate needed memory.
3267  * @retval ::WIMLIB_ERR_INVALID_PARAM
3268  *      @p new_image was equal to @p template_image, or @p new_image specified
3269  *      an image that had not been modified since opening the WIM.
3270  *
3271  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
3272  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
3273  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
3274  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
3275  * different reasons) to read the metadata resource for the template image.
3276  */
3277 extern int
3278 wimlib_reference_template_image(WIMStruct *wim, int new_image,
3279                                 WIMStruct *template_wim, int template_image,
3280                                 int flags, wimlib_progress_func_t progress_func);
3281
3282 /**
3283  * @ingroup G_wim_information
3284  *
3285  * Translates a string specifying the name or number of an image in the WIM into
3286  * the number of the image.  The images are numbered starting at 1.
3287  *
3288  * @param wim
3289  *      Pointer to the ::WIMStruct for a WIM.
3290  * @param image_name_or_num
3291  *      A string specifying the name or number of an image in the WIM.  If it
3292  *      parses to a positive integer, this integer is taken to specify the
3293  *      number of the image, indexed starting at 1.  Otherwise, it is taken to
3294  *      be the name of an image, as given in the XML data for the WIM file.  It
3295  *      also may be the keyword "all" or the string "*", both of which will
3296  *      resolve to ::WIMLIB_ALL_IMAGES.
3297  *      <br/> <br/>
3298  *      There is no way to search for an image actually named "all", "*", or an
3299  *      integer number, or an image that has no name.  However, you can use
3300  *      wimlib_get_image_name() to get the name of any image.
3301  *
3302  * @return
3303  *      If the string resolved to a single existing image, the number of that
3304  *      image, indexed starting at 1, is returned.  If the keyword "all" or "*"
3305  *      was specified, ::WIMLIB_ALL_IMAGES is returned.  Otherwise,
3306  *      ::WIMLIB_NO_IMAGE is returned.  If @p image_name_or_num was @c NULL or
3307  *      the empty string, ::WIMLIB_NO_IMAGE is returned, even if one or more
3308  *      images in @p wim has no name.
3309  */
3310 extern int
3311 wimlib_resolve_image(WIMStruct *wim,
3312                      const wimlib_tchar *image_name_or_num);
3313
3314 /**
3315  * @ingroup G_modifying_wims
3316  *
3317  * Changes the description of an image in the WIM.
3318  *
3319  * @param wim
3320  *      Pointer to the ::WIMStruct for a WIM.
3321  * @param image
3322  *      The number of the image for which to change the description.
3323  * @param description
3324  *      The new description to give the image.  It may be @c NULL, which
3325  *      indicates that the image is to be given no description.
3326  *
3327  * @return 0 on success; nonzero on error.
3328  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3329  *      @p image does not specify a single existing image in @p wim.
3330  * @retval ::WIMLIB_ERR_NOMEM
3331  *      Failed to allocate the memory needed to duplicate the @p description
3332  *      string.
3333  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3334  *      @p wim is considered read-only because of any of the reasons mentioned
3335  *      in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
3336  */
3337 extern int
3338 wimlib_set_image_descripton(WIMStruct *wim, int image,
3339                             const wimlib_tchar *description);
3340
3341 /**
3342  * @ingroup G_writing_and_overwriting_wims
3343  *
3344  * Set the compression chunk size of a WIM to use in subsequent calls to
3345  * wimlib_write() or wimlib_overwrite().
3346  *
3347  * A compression chunk size will result in a greater compression ratio, but the
3348  * speed of random access to the WIM will be reduced, and the effect of an
3349  * increased compression chunk size is limited by the size of each file being
3350  * compressed.
3351  *
3352  * <b>WARNING: Microsoft's software is seemingly incompatible with LZX chunk
3353  * sizes other than 32768.  Chunk sizes other than 32768 (for any format) are
3354  * also incompatible with wimlib v1.5.3 and earlier.</b>
3355  *
3356  * @param wim
3357  *      ::WIMStruct for a WIM.
3358  * @param out_chunk_size
3359  *      The chunk size (in bytes) to set.  The valid chunk sizes are dependent
3360  *      on the compression format.  The XPRESS compression format supports chunk
3361  *      sizes that are powers of 2 with exponents between 15 and 26 inclusively,
3362  *      whereas the LZX compression format supports chunk sizes that are powers
3363  *      of 2 with exponents between 15 and 21 inclusively.  As a special case,
3364  *      if @p out_chunk_size is specified as 0, the chunk size is set to the
3365  *      default for the currently selected output compression type.
3366  *
3367  * @return 0 on success; nonzero on error.
3368  *
3369  * @retval ::WIMLIB_ERR_INVALID_CHUNK_SIZE
3370  *      @p ctype is not a supported chunk size.
3371  */
3372 extern int
3373 wimlib_set_output_chunk_size(WIMStruct *wim, uint32_t chunk_size);
3374
3375 /**
3376  * @ingroup G_writing_and_overwriting_wims
3377  *
3378  * Similar to wimlib_set_output_chunk_size(), but set the chunk size for writing
3379  * packed streams.
3380  */
3381 extern int
3382 wimlib_set_output_pack_chunk_size(WIMStruct *wim, uint32_t chunk_size);
3383
3384 /**
3385  * @ingroup G_writing_and_overwriting_wims
3386  *
3387  * Set the compression type of a WIM to use in subsequent calls to
3388  * wimlib_write() or wimlib_overwrite().
3389  *
3390  * @param wim
3391  *      ::WIMStruct for a WIM.
3392  * @param ctype
3393  *      The compression type to set (one of ::wimlib_compression_type).  If this
3394  *      compression type is incompatible with the current output chunk size
3395  *      (either the default or as set with wimlib_set_output_chunk_size()), the
3396  *      output chunk size is reset to the default for that compression type.
3397  *
3398  * @return 0 on success; nonzero on error.
3399  *
3400  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
3401  *      @p ctype did not specify a valid compression type.
3402  */
3403 extern int
3404 wimlib_set_output_compression_type(WIMStruct *wim, int ctype);
3405
3406 /**
3407  * @ingroup G_writing_and_overwriting_wims
3408  *
3409  * Similar to wimlib_set_output_compression_type(), but set the compression type
3410  * for writing packed streams.
3411  */
3412 extern int
3413 wimlib_set_output_pack_compression_type(WIMStruct *wim, int ctype);
3414
3415 /**
3416  * @ingroup G_modifying_wims
3417  *
3418  * Set basic information about a WIM.
3419  *
3420  * @param wim
3421  *      Pointer to the ::WIMStruct for a WIM.
3422  * @param info
3423  *      A struct ::wimlib_wim_info that contains the information to set.  Only
3424  *      the information explicitly specified in the @p which flags need be
3425  *      valid.
3426  * @param which
3427  *      Flags that specify which information to set.  This is a bitwise OR of
3428  *      ::WIMLIB_CHANGE_READONLY_FLAG, ::WIMLIB_CHANGE_GUID,
3429  *      ::WIMLIB_CHANGE_BOOT_INDEX, and/or ::WIMLIB_CHANGE_RPFIX_FLAG.
3430  *
3431  * @return 0 on success; nonzero on failure.
3432  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3433  *      The WIM file is considered read-only because of any of the reasons
3434  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
3435  *      flag.  However, as a special case, if you are using
3436  *      ::WIMLIB_CHANGE_READONLY_FLAG to unset the readonly flag, then this
3437  *      function will not fail due to the readonly flag being previously set.
3438  * @retval ::WIMLIB_ERR_IMAGE_COUNT
3439  *      ::WIMLIB_CHANGE_BOOT_INDEX was specified, but
3440  *      ::wimlib_wim_info.boot_index did not specify 0 or a valid 1-based image
3441  *      index in the WIM.
3442  */
3443 extern int
3444 wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info,
3445                     int which);
3446
3447 /**
3448  * @ingroup G_modifying_wims
3449  *
3450  * Changes what is written in the \<FLAGS\> element in the WIM XML data
3451  * (something like "Core" or "Ultimate")
3452  *
3453  * @param wim
3454  *      Pointer to the ::WIMStruct for a WIM.
3455  * @param image
3456  *      The number of the image for which to change the description.
3457  * @param flags
3458  *      The new \<FLAGS\> element to give the image.  It may be @c NULL, which
3459  *      indicates that the image is to be given no \<FLAGS\> element.
3460  *
3461  * @return 0 on success; nonzero on error.
3462  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3463  *      @p image does not specify a single existing image in @p wim.
3464  * @retval ::WIMLIB_ERR_NOMEM
3465  *      Failed to allocate the memory needed to duplicate the @p flags string.
3466  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3467  *      @p wim is considered read-only because of any of the reasons mentioned
3468  *      in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
3469  */
3470 extern int
3471 wimlib_set_image_flags(WIMStruct *wim, int image, const wimlib_tchar *flags);
3472
3473 /**
3474  * @ingroup G_modifying_wims
3475  *
3476  * Changes the name of an image in the WIM.
3477  *
3478  * @param wim
3479  *      Pointer to the ::WIMStruct for a WIM.
3480  * @param image
3481  *      The number of the image for which to change the name.
3482  * @param name
3483  *      New name to give the new image.  If @c NULL or empty, the new image is
3484  *      given no name.  If nonempty, it must specify a name that does not
3485  *      already exist in @p wim.
3486  *
3487  * @return 0 on success; nonzero on error.
3488  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
3489  *      There is already an image named @p name in @p wim.
3490  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3491  *      @p image does not specify a single existing image in @p wim.
3492  * @retval ::WIMLIB_ERR_NOMEM
3493  *      Failed to allocate the memory needed to duplicate the @p name string.
3494  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3495  *      @p wim is considered read-only because of any of the reasons mentioned
3496  *      in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS flag.
3497  */
3498 extern int
3499 wimlib_set_image_name(WIMStruct *wim, int image, const wimlib_tchar *name);
3500
3501 /**
3502  * @ingroup G_general
3503  *
3504  * Set the functions that wimlib uses to allocate and free memory.
3505  *
3506  * These settings are global and not per-WIM.
3507  *
3508  * The default is to use the default @c malloc() and @c free() from the C
3509  * library.
3510  *
3511  * Please note that some external functions, such as those in @c libntfs-3g, may
3512  * use the standard memory allocation functions.
3513  *
3514  * @param malloc_func
3515  *      A function equivalent to @c malloc() that wimlib will use to allocate
3516  *      memory.  If @c NULL, the allocator function is set back to the default
3517  *      @c malloc() from the C library.
3518  * @param free_func
3519  *      A function equivalent to @c free() that wimlib will use to free memory.
3520  *      If @c NULL, the free function is set back to the default @c free() from
3521  *      the C library.
3522  * @param realloc_func
3523  *      A function equivalent to @c realloc() that wimlib will use to reallocate
3524  *      memory.  If @c NULL, the free function is set back to the default @c
3525  *      realloc() from the C library.
3526  * @return 0
3527  */
3528 extern int
3529 wimlib_set_memory_allocator(void *(*malloc_func)(size_t),
3530                             void (*free_func)(void *),
3531                             void *(*realloc_func)(void *, size_t));
3532
3533 /**
3534  * @ingroup G_general
3535  *
3536  * Sets whether wimlib is to print error messages to @c stderr when a function
3537  * fails.  These error messages may provide information that cannot be
3538  * determined only from the error code that is returned.  Not every error will
3539  * result in an error message being printed.
3540  *
3541  * This setting is global and not per-WIM.
3542  *
3543  * By default, error messages are not printed.
3544  *
3545  * This can be called before wimlib_global_init().
3546  *
3547  * @param show_messages
3548  *      @c true if error messages are to be printed; @c false if error messages
3549  *      are not to be printed.
3550  *
3551  * @return 0 on success; nonzero on error.
3552  * @retval ::WIMLIB_ERR_UNSUPPORTED
3553  *      @p show_messages was @c true, but wimlib was compiled with the @c
3554  *      --without-error-messages option.   Therefore, error messages cannot be
3555  *      shown.
3556  */
3557 extern int
3558 wimlib_set_print_errors(bool show_messages);
3559
3560 /**
3561  * @ingroup G_nonstandalone_wims
3562  *
3563  * Splits a WIM into multiple parts.
3564  *
3565  * @param wim
3566  *      The ::WIMStruct for the WIM to split.
3567  * @param swm_name
3568  *      Name of the SWM file to create.  This will be the name of the first
3569  *      part.  The other parts will have the same name with 2, 3, 4, ..., etc.
3570  *      appended before the suffix.
3571  * @param part_size
3572  *      The maximum size per part, in bytes.  Unfortunately, it is not
3573  *      guaranteed that this will really be the maximum size per part, because
3574  *      some file resources in the WIM may be larger than this size, and the WIM
3575  *      file format provides no way to split up file resources among multiple
3576  *      WIMs.
3577  * @param write_flags
3578  *      Bitwise OR of relevant flags prefixed with @c WIMLIB_WRITE_FLAG.  These
3579  *      flags will be used to write each split WIM part.  Specify 0 here to get
3580  *      the default behavior.
3581  * @param progress_func
3582  *      If non-NULL, a function that will be called periodically with the
3583  *      progress of the current operation
3584  *      (::WIMLIB_PROGRESS_MSG_SPLIT_BEGIN_PART and
3585  *      ::WIMLIB_PROGRESS_MSG_SPLIT_END_PART).
3586  *
3587  * @return 0 on success; nonzero on error.  This function may return most error
3588  * codes that can be returned by wimlib_write() as well as the following error
3589  * codes:
3590  *
3591  * @retval ::WIMLIB_ERR_INVALID_PARAM
3592  *      @p swm_name was not a nonempty string, or @p part_size was 0.
3593  *
3594  * Note: the WIM's uncompressed and compressed resources are not checksummed
3595  * when they are copied from the joined WIM to the split WIM parts, nor are
3596  * compressed resources re-compressed (unless explicitly requested with
3597  * ::WIMLIB_WRITE_FLAG_RECOMPRESS).
3598  */
3599 extern int
3600 wimlib_split(WIMStruct *wim,
3601              const wimlib_tchar *swm_name,
3602              uint64_t part_size,
3603              int write_flags,
3604              wimlib_progress_func_t progress_func);
3605
3606 /**
3607  * @ingroup G_mounting_wim_images
3608  *
3609  * Unmounts a WIM image that was mounted using wimlib_mount_image().
3610  *
3611  * The image to unmount is specified by the path to the mountpoint, not the
3612  * original ::WIMStruct passed to wimlib_mount_image(), which should not be
3613  * touched and also may have been allocated in a different process.
3614  *
3615  * To unmount the image, the process calling this function communicates with the
3616  * process that is managing the mounted WIM image.  This function blocks until it
3617  * is known whether the unmount succeeded or failed.  In the case of a
3618  * read-write mounted WIM, the unmount is not considered to have succeeded until
3619  * all changes have been saved to the underlying WIM file.
3620  *
3621  * @param dir
3622  *      The directory that the WIM image was mounted on.
3623  * @param unmount_flags
3624  *      Bitwise OR of the flags ::WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY,
3625  *      ::WIMLIB_UNMOUNT_FLAG_COMMIT, ::WIMLIB_UNMOUNT_FLAG_REBUILD, and/or
3626  *      ::WIMLIB_UNMOUNT_FLAG_RECOMPRESS.  None of these flags affect read-only
3627  *      mounts.
3628  * @param progress_func
3629  *      If non-NULL, a function that will be called periodically with the
3630  *      progress of the current operation.  Currently, only
3631  *      ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS will be sent.
3632  *
3633  * @return 0 on success; nonzero on error.
3634  *
3635  * @retval ::WIMLIB_ERR_DELETE_STAGING_DIR
3636  *      The filesystem daemon was unable to remove the staging directory and the
3637  *      temporary files that it contains.
3638  * @retval ::WIMLIB_ERR_FILESYSTEM_DAEMON_CRASHED
3639  *      The filesystem daemon appears to have terminated before sending an exit
3640  *      status.
3641  * @retval ::WIMLIB_ERR_FORK
3642  *      Could not @c fork() the process.
3643  * @retval ::WIMLIB_ERR_FUSERMOUNT
3644  *      The @b fusermount program could not be executed or exited with a failure
3645  *      status.
3646  * @retval ::WIMLIB_ERR_MQUEUE
3647  *      Could not open a POSIX message queue to communicate with the filesystem
3648  *      daemon servicing the mounted filesystem, could not send a message
3649  *      through the queue, or could not receive a message through the queue.
3650  * @retval ::WIMLIB_ERR_NOMEM
3651  *      Failed to allocate needed memory.
3652  * @retval ::WIMLIB_ERR_OPEN
3653  *      The filesystem daemon could not open a temporary file for writing the
3654  *      new WIM.
3655  * @retval ::WIMLIB_ERR_READ
3656  *      A read error occurred when the filesystem daemon tried to a file from
3657  *      the staging directory
3658  * @retval ::WIMLIB_ERR_RENAME
3659  *      The filesystem daemon failed to rename the newly written WIM file to the
3660  *      original WIM file.
3661  * @retval ::WIMLIB_ERR_UNSUPPORTED
3662  *      Mounting is not supported, either because the platform is Windows, or
3663  *      because the platform is UNIX-like and wimlib was compiled with @c
3664  *      --without-fuse.
3665  * @retval ::WIMLIB_ERR_WRITE
3666  *      A write error occurred when the filesystem daemon was writing to the new
3667  *      WIM file, or the filesystem daemon was unable to flush changes that had
3668  *      been made to files in the staging directory.
3669  */
3670 extern int
3671 wimlib_unmount_image(const wimlib_tchar *dir,
3672                      int unmount_flags,
3673                      wimlib_progress_func_t progress_func);
3674
3675 /**
3676  * @ingroup G_modifying_wims
3677  *
3678  * Update a WIM image by adding, deleting, and/or renaming files or directories.
3679  *
3680  * @param wim
3681  *      Pointer to the ::WIMStruct for the WIM file to update.
3682  * @param image
3683  *      The 1-based index of the image in the WIM to update.  It cannot be
3684  *      ::WIMLIB_ALL_IMAGES.
3685  * @param cmds
3686  *      An array of ::wimlib_update_command's that specify the update operations
3687  *      to perform.
3688  * @param num_cmds
3689  *      Number of commands in @p cmds.
3690  * @param update_flags
3691  *      ::WIMLIB_UPDATE_FLAG_SEND_PROGRESS or 0.
3692  * @param progress_func
3693  *      If non-NULL, a function that will be called periodically with the
3694  *      progress of the current operation.
3695  *
3696  * @return 0 on success; nonzero on error.  On failure, some but not all of the
3697  * update commands may have been executed.  No individual update command will
3698  * have been partially executed.  Possible error codes include:
3699  *
3700  * @retval ::WIMLIB_ERR_INVALID_CAPTURE_CONFIG
3701  *      The capture configuration structure specified for an add command was
3702  *      invalid.
3703  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3704  *      @p image did not specify a single, existing image in @p wim.
3705  * @retval ::WIMLIB_ERR_INVALID_OVERLAY
3706  *      Attempted to perform an add command that conflicted with previously
3707  *      existing files in the WIM when an overlay was attempted.
3708  * @retval ::WIMLIB_ERR_INVALID_PARAM
3709  *      An unknown operation type was specified in the update commands; or,
3710  *      attempted to execute an add command where ::WIMLIB_ADD_FLAG_NTFS was set
3711  *      in the @p add_flags, but the same image had previously already been
3712  *      added from a NTFS volume; or, both ::WIMLIB_ADD_FLAG_RPFIX and
3713  *      ::WIMLIB_ADD_FLAG_NORPFIX were specified in the @p add_flags for one add
3714  *      command; or, ::WIMLIB_ADD_FLAG_NTFS or ::WIMLIB_ADD_FLAG_RPFIX were
3715  *      specified in the @p add_flags for an add command in which @p
3716  *      wim_target_path was not the root directory of the WIM image.
3717  * @retval ::WIMLIB_ERR_INVALID_REPARSE_DATA
3718  *      (Windows only):  While executing an add command, tried to capture a
3719  *      reparse point with invalid data.
3720  * @retval ::WIMLIB_ERR_IS_DIRECTORY
3721  *      A delete command without ::WIMLIB_DELETE_FLAG_RECURSIVE specified was
3722  *      for a WIM path that corresponded to a directory; or, a rename command
3723  *      attempted to rename a directory to a non-directory.
3724  * @retval ::WIMLIB_ERR_NOMEM
3725  *      Failed to allocate needed memory.
3726  * @retval ::WIMLIB_ERR_NOTDIR
3727  *      A rename command attempted to rename a directory to a non-directory; or,
3728  *      an add command was executed that attempted to set the root of the WIM
3729  *      image as a non-directory; or, a path component used as a directory in a
3730  *      rename command was not, in fact, a directory.
3731  * @retval ::WIMLIB_ERR_NOTEMPTY
3732  *      A rename command attempted to rename a directory to a non-empty
3733  *      directory.
3734  * @retval ::WIMLIB_ERR_NTFS_3G
3735  *      While executing an add command with ::WIMLIB_ADD_FLAG_NTFS specified, an
3736  *      error occurred while reading data from the NTFS volume using libntfs-3g.
3737  * @retval ::WIMLIB_ERR_OPEN
3738  *      Failed to open a file to be captured while executing an add command.
3739  * @retval ::WIMLIB_ERR_OPENDIR
3740  *      Failed to open a directory to be captured while executing an add command.
3741  * @retval ::WIMLIB_ERR_PATH_DOES_NOT_EXIST
3742  *      A delete command without ::WIMLIB_DELETE_FLAG_FORCE specified was for a
3743  *      WIM path that did not exist; or, a rename command attempted to rename a
3744  *      file that does not exist.
3745  * @retval ::WIMLIB_ERR_READ
3746  *      While executing an add command, failed to read data from a file or
3747  *      directory to be captured.
3748  * @retval ::WIMLIB_ERR_READLINK
3749  *      While executing an add command, failed to read the target of a symbolic
3750  *      link or junction point.
3751  * @retval ::WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED
3752  *      (Windows only) Failed to perform a reparse point fixup because of
3753  *      problems with the data of a reparse point.
3754  * @retval ::WIMLIB_ERR_STAT
3755  *      While executing an add command, failed to get attributes for a file or
3756  *      directory.
3757  * @retval ::WIMLIB_ERR_UNSUPPORTED
3758  *      ::WIMLIB_ADD_FLAG_NTFS was specified in the @p add_flags for an update
3759  *      command, but wimlib was configured with the @c --without-ntfs-3g flag;
3760  *      or, the platform is Windows and either the ::WIMLIB_ADD_FLAG_UNIX_DATA
3761  *      or the ::WIMLIB_ADD_FLAG_DEREFERENCE flags were specified in the @p
3762  *      add_flags for an update command.
3763  * @retval ::WIMLIB_ERR_UNSUPPORTED_FILE
3764  *      While executing an add command, attempted to capture a file that was not
3765  *      a supported file type (e.g. a device file).  Only if
3766  *      ::WIMLIB_ADD_FLAG_NO_UNSUPPORTED_EXCLUDE specified in @p the add_flags
3767  *      for an update command.
3768  * @retval ::WIMLIB_ERR_WIM_IS_READONLY
3769  *      The WIM file is considered read-only because of any of the reasons
3770  *      mentioned in the documentation for the ::WIMLIB_OPEN_FLAG_WRITE_ACCESS
3771  *      flag.
3772  *
3773  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
3774  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
3775  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
3776  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
3777  * different reasons) to read the metadata resource for an image that needed to
3778  * be updated.
3779  */
3780 extern int
3781 wimlib_update_image(WIMStruct *wim,
3782                     int image,
3783                     const struct wimlib_update_command *cmds,
3784                     size_t num_cmds,
3785                     int update_flags,
3786                     wimlib_progress_func_t progress_func);
3787
3788 /**
3789  * @ingroup G_writing_and_overwriting_wims
3790  *
3791  * Writes a WIM to a file.
3792  *
3793  * This brings in resources from any external locations, such as directory trees
3794  * or NTFS volumes scanned with wimlib_add_image(), or other WIM files via
3795  * wimlib_export_image(), and incorporates them into a new on-disk WIM file.
3796  *
3797  * By default, the new WIM file is written as stand-alone.  Using the
3798  * ::WIMLIB_WRITE_FLAG_SKIP_EXTERNAL_WIMS flag, a "delta" WIM can be written
3799  * instead.  However, this function cannot directly write a "split" WIM; use
3800  * wimlib_split() for that.
3801  *
3802  * @param wim
3803  *      Pointer to the ::WIMStruct for a WIM.  There may have been in-memory
3804  *      changes made to it, which are then reflected in the output file.
3805  * @param path
3806  *      The path to the file to write the WIM to.
3807  * @param image
3808  *      Normally, specify ::WIMLIB_ALL_IMAGES here.  This indicates that all
3809  *      images are to be included in the new on-disk WIM file.  If for some
3810  *      reason you only want to include a single image, specify the index of
3811  *      that image instead.
3812  * @param write_flags
3813  *      Bitwise OR of any of the flags prefixed with @c WIMLIB_WRITE_FLAG.
3814  * @param num_threads
3815  *      Number of threads to use for compressing data.  If 0, the number of
3816  *      threads is taken to be the number of online processors.  Note: if no
3817  *      data compression needs to be done, no additional threads will be created
3818  *      regardless of this parameter (e.g. if writing an uncompressed WIM, or
3819  *      exporting an image from a compressed WIM to another WIM of the same
3820  *      compression type without ::WIMLIB_WRITE_FLAG_RECOMPRESS specified in @p
3821  *      write_flags).
3822  * @param progress_func
3823  *      If non-NULL, a function that will be called periodically with the
3824  *      progress of the current operation.  The possible messages are
3825  *      ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_BEGIN,
3826  *      ::WIMLIB_PROGRESS_MSG_WRITE_METADATA_END, and
3827  *      ::WIMLIB_PROGRESS_MSG_WRITE_STREAMS.
3828  *
3829  * @return 0 on success; nonzero on error.
3830  *
3831  * @retval ::WIMLIB_ERR_INVALID_IMAGE
3832  *      @p image does not specify a single existing image in @p wim, and is not
3833  *      ::WIMLIB_ALL_IMAGES.
3834  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
3835  *      A file that had previously been scanned for inclusion in the WIM by
3836  *      wimlib_add_image() was concurrently modified, so it failed the SHA1
3837  *      message digest check.
3838  * @retval ::WIMLIB_ERR_INVALID_PARAM
3839  *      @p path was @c NULL.
3840  * @retval ::WIMLIB_ERR_NOMEM
3841  *      Failed to allocate needed memory.
3842  * @retval ::WIMLIB_ERR_OPEN
3843  *      Failed to open @p path for writing, or some file resources in @p wim
3844  *      refer to files in the outside filesystem, and one of these files could
3845  *      not be opened for reading.
3846  * @retval ::WIMLIB_ERR_READ
3847  *      An error occurred when trying to read data from the WIM file associated
3848  *      with @p wim, or some file resources in @p wim refer to files in the
3849  *      outside filesystem, and a read error occurred when reading one of these
3850  *      files.
3851  * @retval ::WIMLIB_ERR_RESOURCE_NOT_FOUND
3852  *      A stream that needed to be written could not be found in the stream
3853  *      lookup table of @p wim.  This error can occur if, for example, @p wim is
3854  *      part of a split WIM but needed resources from the other split WIM parts
3855  *      were not referenced with wimlib_reference_resources() or
3856  *      wimlib_reference_resource_files() before the call to wimlib_write().
3857  * @retval ::WIMLIB_ERR_WRITE
3858  *      An error occurred when trying to write data to the new WIM file.
3859  *
3860  * This function can additionally return ::WIMLIB_ERR_DECOMPRESSION,
3861  * ::WIMLIB_ERR_INVALID_METADATA_RESOURCE, ::WIMLIB_ERR_METADATA_NOT_FOUND,
3862  * ::WIMLIB_ERR_NOMEM, ::WIMLIB_ERR_READ, or
3863  * ::WIMLIB_ERR_UNEXPECTED_END_OF_FILE, all of which indicate failure (for
3864  * different reasons) to read the metadata resource for an image that needed to
3865  * be written.
3866  */
3867 extern int
3868 wimlib_write(WIMStruct *wim,
3869              const wimlib_tchar *path,
3870              int image,
3871              int write_flags,
3872              unsigned num_threads,
3873              wimlib_progress_func_t progress_func);
3874
3875 /**
3876  * @ingroup G_writing_and_overwriting_wims
3877  *
3878  * Since wimlib v1.5.0:  Same as wimlib_write(), but write the WIM directly to a
3879  * file descriptor, which need not be seekable if the write is done in a special
3880  * pipable WIM format by providing ::WIMLIB_WRITE_FLAG_PIPABLE in @p
3881  * write_flags.  This can, for example, allow capturing a WIM image and
3882  * streaming it over the network.  See the documentation for
3883  * ::WIMLIB_WRITE_FLAG_PIPABLE for more information about pipable WIMs.
3884  *
3885  * The file descriptor @p fd will @b not be closed when the write is complete;
3886  * the calling code is responsible for this.
3887  *
3888  * Returns 0 on success; nonzero on failure.  The possible error codes include
3889  * those that can be returned by wimlib_write() as well as the following:
3890  *
3891  * @retval ::WIMLIB_ERR_INVALID_PARAM
3892  *      @p fd was not seekable, but ::WIMLIB_WRITE_FLAG_PIPABLE was not
3893  *      specified in @p write_flags.
3894  */
3895 extern int
3896 wimlib_write_to_fd(WIMStruct *wim,
3897                    int fd,
3898                    int image,
3899                    int write_flags,
3900                    unsigned num_threads,
3901                    wimlib_progress_func_t progress_func);
3902
3903 /**
3904  * @defgroup G_compression Compression and decompression functions
3905  *
3906  * @brief Functions for LZX, XPRESS, and LZMS compression and decompression,
3907  * exported for convenience only, as they are already used by wimlib internally
3908  * when appropriate.
3909  *
3910  * These functions can be used for general-purpose lossless data compression,
3911  * but some limitations apply; for example, none of the compressors or
3912  * decompressors currently support sliding windows, and there also exist
3913  * slightly different variants of these formats that are not supported
3914  * unmodified.
3915  */
3916
3917 /**
3918  * @ingroup G_compression
3919  * @{
3920  */
3921
3922 /** Header for compression parameters to pass to wimlib_create_compressor() or
3923  * wimlib_set_default_compressor_params().  */
3924 struct wimlib_compressor_params_header {
3925         /** Size of the parameters, in bytes.  */
3926         uint32_t size;
3927 };
3928
3929 /** Header for decompression parameters to pass to wimlib_create_decompressor()
3930  * or wimlib_set_default_decompressor_params() */
3931 struct wimlib_decompressor_params_header {
3932         /** Size of the parameters, in bytes.  */
3933         uint32_t size;
3934 };
3935
3936 /** LZX compression parameters that can optionally be passed to
3937  * wimlib_create_compressor() with the compression type
3938  * ::WIMLIB_COMPRESSION_TYPE_LZX.  */
3939 struct wimlib_lzx_compressor_params {
3940         /** hdr.size Must be set to the size of this structure, in bytes.  */
3941         struct wimlib_compressor_params_header hdr;
3942
3943         /** Relatively fast LZX compression algorithm with a decent compression
3944          * ratio; the suggested default.  */
3945 #define WIMLIB_LZX_ALGORITHM_FAST 0
3946
3947         /** Slower LZX compression algorithm that provides a better compression
3948          * ratio.  */
3949 #define WIMLIB_LZX_ALGORITHM_SLOW 1
3950
3951         /** Algorithm to use to perform the compression: either
3952          * ::WIMLIB_LZX_ALGORITHM_FAST or ::WIMLIB_LZX_ALGORITHM_SLOW.  The
3953          * format is still LZX; this refers to the method the code will use to
3954          * perform LZX-compatible compression.  */
3955         uint32_t algorithm : 3;
3956
3957         /** If set to 1, the default parameters for the specified algorithm are
3958          * used rather than the ones specified in the following union.  */
3959         uint32_t use_defaults : 1;
3960
3961         union {
3962                 /** Parameters for the fast algorithm.  */
3963                 struct wimlib_lzx_fast_params {
3964                         uint32_t fast_reserved1[10];
3965                 } fast;
3966
3967                 /** Parameters for the slow algorithm.  */
3968                 struct wimlib_lzx_slow_params {
3969                         /** If set to 1, the compressor can output length 2
3970                          * matches.  If set 0, the compressor only outputs
3971                          * matches of length 3 or greater.  Suggested value: 1
3972                          */
3973                         uint32_t use_len2_matches : 1;
3974
3975                         uint32_t slow_reserved1 : 31;
3976
3977                         /** Matches with length (in bytes) longer than this
3978                          * value are immediately taken without spending time on
3979                          * minimum-cost measurements.  Suggested value: 32.  */
3980                         uint32_t num_fast_bytes;
3981
3982                         /** Number of passes to compute a match/literal sequence
3983                          * for each LZX block.  This is for an iterative
3984                          * algorithm that attempts to minimize the cost of the
3985                          * match/literal sequence by using a cost model provided
3986                          * by the previous iteration.  Must be at least 1.
3987                          * Suggested value: 2.  */
3988                         uint32_t num_optim_passes;
3989
3990                         /** Reserved; set to 0.  */
3991                         uint32_t slow_reserved_blocksplit;
3992
3993                         /** Maximum depth to search for matches at each
3994                          * position.  Suggested value: 50.  */
3995                         uint32_t max_search_depth;
3996
3997                         /** Maximum number of potentially good matches to
3998                          * consider for each position.  Suggested value: 3.  */
3999                         uint32_t max_matches_per_pos;
4000
4001                         uint32_t slow_reserved2[2];
4002
4003                         /** Assumed cost of a main symbol with zero frequency.
4004                          * Must be at least 1 and no more than 16.  Suggested
4005                          * value: 15.  */
4006                         uint8_t main_nostat_cost;
4007
4008                         /** Assumed cost of a length symbol with zero frequency.
4009                          * Must be at least 1 and no more than 16.  Suggested
4010                          * value: 15.  */
4011                         uint8_t len_nostat_cost;
4012
4013                         /** Assumed cost of an aligned symbol with zero
4014                          * frequency.  Must be at least 1 and no more than 8.
4015                          * Suggested value: 7.  */
4016                         uint8_t aligned_nostat_cost;
4017
4018                         uint8_t slow_reserved3[5];
4019                 } slow;
4020         } alg_params;
4021 };
4022
4023 /** Opaque compressor handle.  */
4024 struct wimlib_compressor;
4025
4026 /** Opaque decompressor handle.  */
4027 struct wimlib_decompressor;
4028
4029 /**
4030  * Set the default compression parameters for the specified compression type.
4031  * This will affect both explicit and wimlib-internal calls to
4032  * wimlib_create_compressor().
4033  *
4034  * @param ctype
4035  *      Compression type for which to set the default compression parameters.
4036  * @param params
4037  *      Compression-type specific parameters.  This may be @c NULL, in which
4038  *      case the "default default" parameters are restored.
4039  *
4040  * @return 0 on success; nonzero on error.
4041  *
4042  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
4043  *      @p ctype was not a supported compression type.
4044  * @retval ::WIMLIB_ERR_NOMEM
4045  *      Not enough memory to duplicate the parameters (perhaps @c params->size
4046  *      was invalid).
4047  */
4048 extern int
4049 wimlib_set_default_compressor_params(enum wimlib_compression_type ctype,
4050                                      const struct wimlib_compressor_params_header *params);
4051
4052 /**
4053  * Allocate a compressor for the specified compression type using the specified
4054  * parameters.
4055  *
4056  * @param ctype
4057  *      Compression type for which to create the compressor.
4058  * @param max_block_size
4059  *      Maximum block size to support.  The exact meaning and allowed values for
4060  *      this parameter depend on the compression type, but it at least specifies
4061  *      the maximum allowed value for @p uncompressed_size to wimlib_compress().
4062  * @param extra_params
4063  *      An optional pointer to extra compressor parameters for the specified
4064  *      compression type.  For LZX, a pointer to ::wimlib_lzx_compressor_params
4065  *      may be specified here.  If left @c NULL, the default parameters are
4066  *      used.
4067  * @param compressor_ret
4068  *      A location into which to return the pointer to the allocated compressor,
4069  *      which can be used for any number of calls to wimlib_compress() before
4070  *      being freed with wimlib_free_compressor().
4071  *
4072  * @return 0 on success; nonzero on error.
4073  *
4074  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
4075  *      @p ctype was not a supported compression type.
4076  * @retval ::WIMLIB_ERR_INVALID_PARAM
4077  *      The compression parameters were invalid.
4078  * @retval ::WIMLIB_ERR_NOMEM
4079  *      Insufficient memory to allocate the compressor.
4080  */
4081 extern int
4082 wimlib_create_compressor(enum wimlib_compression_type ctype,
4083                          size_t max_block_size,
4084                          const struct wimlib_compressor_params_header *extra_params,
4085                          struct wimlib_compressor **compressor_ret);
4086
4087 /**
4088  * Losslessly compress a block of data using a compressor previously created
4089  * with wimlib_create_compressor().
4090  *
4091  * @param uncompressed_data
4092  *      Buffer containing the data to compress.
4093  * @param uncompressed_size
4094  *      Size, in bytes, of the data to compress.
4095  * @param compressed_data
4096  *      Buffer into which to write the compressed data.
4097  * @param compressed_size_avail
4098  *      Number of bytes available in @p compressed_data.
4099  * @param compressor
4100  *      A compressor previously allocated with wimlib_create_compressor().
4101  *
4102  * @return
4103  *      The size of the compressed data, in bytes, or 0 if the input data could
4104  *      not be compressed to @p compressed_size_avail or fewer bytes.
4105  */
4106 extern size_t
4107 wimlib_compress(const void *uncompressed_data, size_t uncompressed_size,
4108                 void *compressed_data, size_t compressed_size_avail,
4109                 struct wimlib_compressor *compressor);
4110
4111 /**
4112  * Free a compressor previously allocated with wimlib_create_compressor().
4113  *
4114  * @param compressor
4115  *      The compressor to free.
4116  */
4117 extern void
4118 wimlib_free_compressor(struct wimlib_compressor *compressor);
4119
4120 /**
4121  * Set the default decompression parameters for the specified compression type.
4122  * This will affect both explicit and wimlib-internal calls to
4123  * wimlib_create_decompressor().
4124  *
4125  * @param ctype
4126  *      Compression type for which to set the default decompression parameters.
4127  * @param params
4128  *      Compression-type specific parameters.  This may be @c NULL, in which
4129  *      case the "default default" parameters are restored.
4130  *
4131  * @return 0 on success; nonzero on error.
4132  *
4133  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
4134  *      @p ctype was not a supported compression type.
4135  * @retval ::WIMLIB_ERR_NOMEM
4136  *      Not enough memory to duplicate the parameters (perhaps @c params->size
4137  *      was invalid).
4138  */
4139 extern int
4140 wimlib_set_default_decompressor_params(enum wimlib_compression_type ctype,
4141                                        const struct wimlib_decompressor_params_header *params);
4142
4143 /**
4144  * Allocate a decompressor for the specified compression type using the
4145  * specified parameters.
4146  *
4147  * @param ctype
4148  *      Compression type for which to create the decompressor.
4149  * @param max_block_size
4150  *      Maximum block size to support.  The exact meaning and allowed values for
4151  *      this parameter depend on the compression type, but it at least specifies
4152  *      the maximum allowed value for @p uncompressed_size to
4153  *      wimlib_decompress().
4154  * @param extra_params
4155  *      An optional pointer to extra decompressor parameters for the specified
4156  *      compression type.  If @c NULL, the default parameters are used.
4157  * @param decompressor_ret
4158  *      A location into which to return the pointer to the allocated
4159  *      decompressor, which can be used for any number of calls to
4160  *      wimlib_decompress() before being freed with wimlib_free_decompressor().
4161  *
4162  * @return 0 on success; nonzero on error.
4163  *
4164  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
4165  *      @p ctype was not a supported compression type.
4166  * @retval ::WIMLIB_ERR_INVALID_PARAM
4167  *      The decompression parameters were invalid.
4168  * @retval ::WIMLIB_ERR_NOMEM
4169  *      Insufficient memory to allocate the decompressor.
4170  */
4171 extern int
4172 wimlib_create_decompressor(enum wimlib_compression_type ctype,
4173                            size_t max_block_size,
4174                            const struct wimlib_decompressor_params_header *extra_params,
4175                            struct wimlib_decompressor **decompressor_ret);
4176
4177 /**
4178  * Decompress a block of data using a decompressor previously created with
4179  * wimlib_create_decompressor().
4180  *
4181  * @param compressed_data
4182  *      Buffer containing the data to decompress.
4183  * @param compressed_size
4184  *      Size, in bytes, of the data to decompress.
4185  * @param uncompressed_data
4186  *      Buffer into which to write the uncompressed data.
4187  * @param uncompressed_size
4188  *      Size, in bytes, of the data when uncompressed.
4189  * @param decompressor
4190  *      A decompressor previously allocated with wimlib_create_decompressor().
4191  *
4192  * @return 0 on success; nonzero on error.
4193  */
4194 extern int
4195 wimlib_decompress(const void *compressed_data, size_t compressed_size,
4196                   void *uncompressed_data, size_t uncompressed_size,
4197                   struct wimlib_decompressor *decompressor);
4198
4199 /**
4200  * Free a decompressor previously allocated with wimlib_create_decompressor().
4201  *
4202  * @param decompressor
4203  *      The decompressor to free.
4204  */
4205 extern void
4206 wimlib_free_decompressor(struct wimlib_decompressor *decompressor);
4207
4208
4209 struct wimlib_lzx_params_old;
4210 struct wimlib_lzx_context_old;
4211
4212 /** Deprecated; do not use.  */
4213 extern int
4214 wimlib_lzx_set_default_params(const struct wimlib_lzx_params_old *params)
4215                 _wimlib_deprecated;
4216
4217 /** Deprecated; do not use.  */
4218 extern int
4219 wimlib_lzx_alloc_context(const struct wimlib_lzx_params_old *params,
4220                          struct wimlib_lzx_context_old **ctx_pp)
4221                 _wimlib_deprecated;
4222
4223 /** Deprecated; do not use.  */
4224 extern void
4225 wimlib_lzx_free_context(struct wimlib_lzx_context_old *ctx)
4226                 _wimlib_deprecated;
4227
4228 /** Deprecated; do not use.  */
4229 extern unsigned
4230 wimlib_lzx_compress2(const void *udata, unsigned ulen, void *cdata,
4231                      struct wimlib_lzx_context_old *ctx)
4232                 _wimlib_deprecated;
4233
4234 /** Deprecated; do not use.  */
4235 extern unsigned
4236 wimlib_lzx_compress(const void *udata, unsigned ulen, void *cdata)
4237                 _wimlib_deprecated;
4238
4239 /** Deprecated; do not use.  */
4240 extern unsigned
4241 wimlib_xpress_compress(const void *udata, unsigned ulen, void *cdata)
4242                 _wimlib_deprecated;
4243
4244 /** Deprecated; do not use.  */
4245 extern int
4246 wimlib_lzx_decompress(const void *cdata, unsigned clen,
4247                       void *udata, unsigned ulen)
4248                 _wimlib_deprecated;
4249
4250 /** Deprecated; do not use.  */
4251 extern int
4252 wimlib_xpress_decompress(const void *cdata, unsigned clen,
4253                          void *udata, unsigned ulen)
4254                 _wimlib_deprecated;
4255
4256 /** @} */
4257
4258
4259
4260 #ifdef __cplusplus
4261 }
4262 #endif
4263
4264 #endif /* _WIMLIB_H */