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