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