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