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