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