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