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