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