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