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