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