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