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