]> wimlib.net Git - wimlib/blob - src/wimlib.h
Fix sequential extraction, and include progress info
[wimlib] / src / wimlib.h
1 /*
2  * wimlib.h
3  *
4  * External header for wimlib.
5  */
6
7 /*
8  * Copyright (C) 2012 Eric Biggers
9  *
10  * This file is part of wimlib, a library for working with WIM files.
11  *
12  * wimlib is free software; you can redistribute it and/or modify it under the
13  * terms of the GNU General Public License as published by the Free
14  * Software Foundation; either version 3 of the License, or (at your option)
15  * any later version.
16  *
17  * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
18  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19  * A PARTICULAR PURPOSE. See the GNU General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with wimlib; if not, see http://www.gnu.org/licenses/.
24  */
25
26 /** \mainpage
27  *
28  * \section intro Introduction
29  *
30  * wimlib is a C library to read, write, and mount archive files in the Windows
31  * Imaging Format (WIM files).  These files are normally created using the @c
32  * imagex.exe utility on Windows, but this library provides a free
33  * implementetion of @c imagex for UNIX-based systems and an API to allow other
34  * programs to read, write, and mount WIM files.  wimlib is comparable to
35  * Microsoft's WIMGAPI, but was designed independently and is not a clone of it.
36  *
37  * \section format WIM files
38  *
39  * A <b>Windows Imaging (WIM)</b> file is an archive.  Like some other archive
40  * formats such as ZIP, files in WIM archives may be compressed.  WIM archives
41  * support two Microsoft-specific compression formats:  @b LZX and @b XPRESS.
42  * Both are based on LZ77 and Huffman encoding, and both are supported by
43  * wimlib.
44  *
45  * Unlike ZIP files, WIM files can contain multiple independent toplevel
46  * directory trees known as @a images.  While each image has its own metadata,
47  * files are not duplicated for each image; instead, each file is included only
48  * once in the entire WIM. Microsoft did this so that in one WIM file, they
49  * could do things like have 5 different versions of Windows that are almost
50  * exactly the same.
51  *
52  * Microsoft provides documentation for the WIM file format, XPRESS compression
53  * format, and LZX compression format.  The XPRESS documentation is acceptable,
54  * but the LZX documentation is not entirely correct, and the WIM documentation
55  * itself is very incomplete and is of unacceptable quality.
56  *
57  * A WIM file may be either stand-alone or split into multiple parts.
58  *
59  * \section winpe Windows PE
60  *
61  * A major use for this library is to create customized images of Windows PE, the
62  * Windows Preinstallation Environment, without having to rely on Windows.  Windows
63  * PE is a lightweight version of Windows that can run entirely from memory and can
64  * be used to install Windows from local media or a network drive or perform
65  * maintenance.  Windows PE is the operating system that runs when you boot from
66  * the Windows installation media.
67  *
68  * You can find Windows PE on the installation DVD for Windows Vista, Windows 7,
69  * or Windows 8, in the file @c sources/boot.wim.  Windows PE can also be found
70  * in the Windows Automated Installation Kit (WAIK), which is free to download
71  * from Microsoft, inside the @c WinPE.cab file, which you can extract if you
72  * install either the @c cabextract or @c p7zip programs.
73  *
74  * In addition, Windows installations and recovery partitions frequently contain a
75  * WIM containing an image of the Windows Recovery Environment, which is similar to
76  * Windows PE.
77  *
78  * \section ntfs NTFS support
79  *
80  * As of version 1.0.0, wimlib supports capturing and applying images directly
81  * to NTFS volumes.  This was made possible with the help of libntfs-3g from the
82  * NTFS-3g project.  This feature supports capturing and restoring NTFS-specific
83  * data such as security descriptors, alternate data streams, and reparse point
84  * data.
85
86  * The code for NTFS image capture and image application is complete enough that
87  * it is possible to apply an image from the "install.wim" contained in recent
88  * Windows installation media (Vista, Windows 7, or Windows 8) directly to a
89  * NTFS volume, and then boot Windows from it after preparing the Boot
90  * Configuration Data.  In addition, a Windows installation can be captured (or
91  * backed up) into a WIM file, and then re-applied later.
92  *
93  * \section starting Getting Started
94  *
95  * wimlib uses the GNU autotools, so it should be easy to install with
96  * <code>configure && make && sudo make install</code>; however, please see the
97  * README for more information about installing it.  To use wimlib in a program
98  * after installing it, include @c wimlib.h and link your program with @c -lwim.
99  *
100  * wimlib wraps up a WIM file in an opaque ::WIMStruct structure.  A ::WIMStruct
101  * may represent either a stand-alone WIM or one part of a split WIM.
102  *
103  * All functions in wimlib's public API are prefixed with @c wimlib.  Most
104  * return an integer error code on failure.  Use wimlib_get_error_string() to
105  * get a string that describes an error code.  wimlib also can print error
106  * messages itself when an error happens, and these may be more informative than
107  * the error code; to enable this, call wimlib_set_print_errors().  Please note
108  * that this is for convenience only, and some errors can occur without a
109  * message being printed.
110  *
111  * wimlib is thread-safe as long as different ::WIMStruct's are used, except for
112  * the fact that wimlib_set_print_errors() and wimlib_set_memory_allocator()
113  * both apply globally.
114  *
115  * To open an existing WIM, use wimlib_open_wim().
116  *
117  * To create a new WIM that initially contains no images, use
118  * wimlib_create_new_wim().
119  *
120  * To add an image to a WIM file from a directory tree on your filesystem, call
121  * wimlib_add_image().  This can be done with a ::WIMStruct gotten from
122  * wimlib_open_wim() or from wimlib_create_new_wim().  Alternatively, if you
123  * want to capture a WIM image directly from a NTFS volume while preserving
124  * NTFS-specific data such as security descriptors, call
125  * wimlib_add_image_from_ntfs_volume() instead.
126  *
127  * To extract an image from a WIM file, call wimlib_extract_image().
128  * Alternatively, if you want to apply a WIM image directly to a NTFS volume
129  * while setting NTFS-specific data such as security descriptors, call
130  * wimlib_apply_image_to_ntfs_volume().
131  *
132  * The NTFS functions will fail if wimlib was compiled with the
133  * <code>--without-ntfs-3g</code> flag.
134  *
135  * wimlib supports mounting WIM files either read-only or read-write.  Mounting
136  * is done using wimlib_mount() and unmounting is done using wimlib_unmount().
137  * Mounting can be done without root privileges because it is implemented using
138  * FUSE (Filesystem in Userspace).  If wimlib is compiled with the
139  * <code>--without-fuse</code> flag, these functions will be available but will
140  * fail.
141  *
142  * After creating or modifying a WIM file, you can write it to a file using
143  * wimlib_write().  Alternatively,  if the WIM was originally read from a file,
144  * you can use wimlib_overwrite() to overwrite the original file.
145  *
146  * Please not: merely by calling wimlib_add_image() or many of the other
147  * functions in this library that operate on ::WIMStruct's, you are @b not
148  * modifing the WIM file on disk.  Changes are not saved until you explicitly
149  * call wimlib_write() or wimlib_overwrite().
150  *
151  * After you are done with the WIM file, use wimlib_free() to free all memory
152  * associated with a ::WIMStruct and close all files associated with it.
153  *
154  * To see an example of how to use wimlib, see the file @c programs/imagex.c in
155  * wimlib's source tree.
156  *
157  * wimlib supports custom memory allocators; use wimlib_set_memory_allocator()
158  * for this.  However, if wimlib calls into @c libntfs-3g, the custom memory
159  * allocator may not be used.
160  *
161  * \section imagex imagex
162  *
163  * wimlib comes with the <b>imagex</b> program, which is documented in man pages.
164  *
165  * \section mkwinpeimg mkwinpeimg
166  *
167  * wimlib comes with the <b>mkwinpeimg</b> script, which is documented in a man
168  * page.
169  *
170  * \section Limitations
171  *
172  * While wimlib supports the main features of WIM files, wimlib currently has
173  * the following limitations:
174  * - Different versions of the WIM file format are unsupported.  There is one
175  *   different version of the format from development versions of Windows Vista,
176  *   but I'm not planning to support it.
177  * - Compressed resource chunk sizes other than 32768 are unsupported (except for
178  *   uncompressed WIMs, for which the chunk size field is ignored).  As far as I
179  *   can tell, other chunk sizes are not used in compressed WIMs.  Let me know
180  *   if you find a WIM file with a different chunk size.
181  * - wimlib does not provide a clone of the @b PEImg tool that allows you to
182  *   make certain Windows-specific modifications to a Windows PE image, such as
183  *   adding a driver or Windows component.  Such a tool could conceivably be
184  *   implemented on top of wimlib, although it likely would be hard to implement
185  *   because it would have to do very Windows-specific things such as
186  *   manipulating the driver store.  wimlib does provide the @b mkwinpeimg
187  *   script for a similar purpose, however.  With regards to adding drivers to
188  *   Windows PE, you have the option of putting them anywhere in the Windows PE
189  *   image, then loading them after boot using @b drvload.exe.
190  * - There is not yet a way to extract specific files or directories from a WIM
191  *   file without mounting it, or to add, remove, or modify files in a WIM
192  *   without mounting it, other than by adding or removing an entire image.  I
193  *   can implement this if requested, but I intend the FUSE mount feature to be
194  *   used for this purpose, as it is easy to do these things in whatever way you
195  *   want after the image is mounted.
196  * - Currently, Microsoft's @a image.exe can create slightly smaller WIM files
197  *   than wimlib when using maximum (LZX) compression because it knows how to
198  *   split up LZX compressed blocks, which is not yet implemented in wimlib.
199  * - wimlib is experimental and likely contains bugs; use Microsoft's @a
200  *   imagex.exe if you want to make sure your WIM files are made "correctly".
201  *
202  * \section legal License
203  *
204  * The wimlib library, as well as the programs and scripts distributed with it
205  * (@b imagex and @b mkwinpeimg), is licensed under the GNU General Public
206  * License version 3 or later.
207  */
208
209 #ifndef _WIMLIB_H
210 #define _WIMLIB_H
211
212 #include <stdio.h>
213 #include <stddef.h>
214 #include <stdbool.h>
215
216 #ifndef _WIMLIB_INTERNAL_H
217 /**
218  * Opaque structure that represents a WIM file.
219  */
220 typedef struct WIMStruct WIMStruct;
221 #endif
222
223 /**
224  * Specifies the compression type of a WIM file.
225  */
226
227 enum wim_compression_type {
228         /** An invalid compression type. */
229         WIM_COMPRESSION_TYPE_INVALID = -1,
230
231         /** The WIM does not include any compressed resources. */
232         WIM_COMPRESSION_TYPE_NONE = 0,
233
234         /** Compressed resources in the WIM use LZX compression. */
235         WIM_COMPRESSION_TYPE_LZX = 1,
236
237         /** Compressed resources in the WIM use XPRESS compression. */
238         WIM_COMPRESSION_TYPE_XPRESS = 2,
239 };
240
241 /** Mount the WIM read-write. */
242 #define WIMLIB_MOUNT_FLAG_READWRITE             0x00000001
243
244 /** For debugging only. (This passes the @c -d flag to @c fuse_main()).*/
245 #define WIMLIB_MOUNT_FLAG_DEBUG                 0x00000002
246
247 /** Do not allow accessing alternate data streams. */
248 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE         0x00000010
249
250 /** Access alternate data streams through extended file attributes.  This is the
251  * default mode. */
252 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR        0x00000020
253
254 /** Access alternate data streams by specifying the file name, a colon, then the
255  * alternate file stream name. */
256 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS      0x00000040
257
258 /** Include an integrity table in the new WIM being written during the unmount.
259  * Ignored for read-only mounts. */
260 #define WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY     0x00000001
261
262 /** Unless this flag is given, changes to a mounted WIM are discarded.  Ignored
263  * for read-only mounts. */
264 #define WIMLIB_UNMOUNT_FLAG_COMMIT              0x00000002
265
266 /** Include an integrity table in the new WIM file. */
267 #define WIMLIB_WRITE_FLAG_CHECK_INTEGRITY       0x00000001
268
269 /** Print progress information when writing streams and when writing the
270  * integrity table. */
271 #define WIMLIB_WRITE_FLAG_SHOW_PROGRESS         0x00000002
272
273 /** Print file paths as we write then */
274 #define WIMLIB_WRITE_FLAG_VERBOSE               0x00000004
275
276 /** Call fsync() when the WIM file is closed */
277 #define WIMLIB_WRITE_FLAG_FSYNC                 0x00000008
278
279 /** Re-build the entire WIM file rather than appending data to it, if possible.
280  * (Applies to wimlib_overwrite(), not wimlib_write()). */
281 #define WIMLIB_WRITE_FLAG_REBUILD               0x00000010
282
283 /** Do not copy compressed resources between WIMs if the compression type is the
284  * same.  Instead, recompress them. */
285 #define WIMLIB_WRITE_FLAG_RECOMPRESS            0x00000020
286
287 /** Specifying this flag overrides the default behavior of wimlib_overwrite()
288  * after one or more calls to wimlib_delete_image(), which is to rebuild the
289  * entire WIM.  If you specifiy this flag to wimlib_overwrite() instead, only
290  * minimal changes to correctly remove the image from the WIM will be taken.  In
291  * particular, all streams will be left alone, even if they are no longer
292  * references.  This is probably not what you want, because almost no space will
293  * be spaced by deleting an image in this way. */
294 #define WIMLIB_WRITE_FLAG_SOFT_DELETE           0x00000040
295
296 /** Mark the image being added as the bootable image of the WIM. */
297 #define WIMLIB_ADD_IMAGE_FLAG_BOOT              0x00000001
298
299 /** Print the name of each file or directory as it is scanned to be included in
300  * the WIM image. */
301 #define WIMLIB_ADD_IMAGE_FLAG_VERBOSE           0x00000002
302
303 /** Follow symlinks; archive and dump the files they point to. */
304 #define WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE       0x00000004
305
306 /** Show progress information when scanning a directory tree */
307 #define WIMLIB_ADD_IMAGE_FLAG_SHOW_PROGRESS     0x00000008
308
309 /** See documentation for wimlib_export_image(). */
310 #define WIMLIB_EXPORT_FLAG_BOOT                 0x00000001
311
312 /** Verify the integrity of the WIM if an integrity table is present. */
313 #define WIMLIB_OPEN_FLAG_CHECK_INTEGRITY        0x00000001
314
315 /** Print progress information when verifying integrity table. */
316 #define WIMLIB_OPEN_FLAG_SHOW_PROGRESS          0x00000002
317
318 /** If this flag is not given, an error is issued if the WIM is part of a split
319  * WIM.  */
320 #define WIMLIB_OPEN_FLAG_SPLIT_OK               0x00000004
321
322
323 /** When identical files are extracted from the WIM, always hard link them
324  * together. */
325 #define WIMLIB_EXTRACT_FLAG_HARDLINK            0x00000001
326
327 /** When identical files are extracted from the WIM, always symlink them
328  * together. */
329 #define WIMLIB_EXTRACT_FLAG_SYMLINK             0x00000002
330
331 /** Print the name of each file as it is extracted from the WIM image. */
332 #define WIMLIB_EXTRACT_FLAG_VERBOSE             0x00000008
333
334 /** Read the WIM file sequentially while extracting the image. */
335 #define WIMLIB_EXTRACT_FLAG_SEQUENTIAL          0x00000010
336
337 /** Print progress information while extracting the image. */
338 #define WIMLIB_EXTRACT_FLAG_SHOW_PROGRESS       0x00000020
339
340 /**
341  * Possible values of the error code returned by many functions in wimlib.
342  *
343  * See the documentation for each wimlib function to see specifically what error
344  * codes can be returned by a given function, and what they mean.
345  */
346 enum wimlib_error_code {
347         WIMLIB_ERR_SUCCESS = 0,
348         WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE,
349         WIMLIB_ERR_DECOMPRESSION,
350         WIMLIB_ERR_DELETE_STAGING_DIR,
351         WIMLIB_ERR_FORK,
352         WIMLIB_ERR_FUSE,
353         WIMLIB_ERR_FUSERMOUNT,
354         WIMLIB_ERR_IMAGE_COUNT,
355         WIMLIB_ERR_IMAGE_NAME_COLLISION,
356         WIMLIB_ERR_INTEGRITY,
357         WIMLIB_ERR_INVALID_CAPTURE_CONFIG,
358         WIMLIB_ERR_INVALID_CHUNK_SIZE,
359         WIMLIB_ERR_INVALID_COMPRESSION_TYPE,
360         WIMLIB_ERR_INVALID_DENTRY,
361         WIMLIB_ERR_INVALID_HEADER_SIZE,
362         WIMLIB_ERR_INVALID_IMAGE,
363         WIMLIB_ERR_INVALID_INTEGRITY_TABLE,
364         WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY,
365         WIMLIB_ERR_INVALID_PARAM,
366         WIMLIB_ERR_INVALID_RESOURCE_HASH,
367         WIMLIB_ERR_INVALID_RESOURCE_SIZE,
368         WIMLIB_ERR_INVALID_SECURITY_DATA,
369         WIMLIB_ERR_LINK,
370         WIMLIB_ERR_MKDIR,
371         WIMLIB_ERR_MQUEUE,
372         WIMLIB_ERR_NOMEM,
373         WIMLIB_ERR_NOTDIR,
374         WIMLIB_ERR_NOT_A_WIM_FILE,
375         WIMLIB_ERR_NO_FILENAME,
376         WIMLIB_ERR_NTFS_3G,
377         WIMLIB_ERR_OPEN,
378         WIMLIB_ERR_OPENDIR,
379         WIMLIB_ERR_READLINK,
380         WIMLIB_ERR_READ,
381         WIMLIB_ERR_RENAME,
382         WIMLIB_ERR_REOPEN,
383         WIMLIB_ERR_RESOURCE_ORDER,
384         WIMLIB_ERR_SPECIAL_FILE,
385         WIMLIB_ERR_SPLIT_INVALID,
386         WIMLIB_ERR_SPLIT_UNSUPPORTED,
387         WIMLIB_ERR_STAT,
388         WIMLIB_ERR_TIMEOUT,
389         WIMLIB_ERR_UNKNOWN_VERSION,
390         WIMLIB_ERR_UNSUPPORTED,
391         WIMLIB_ERR_WRITE,
392         WIMLIB_ERR_XML,
393 };
394
395
396 /** Used to indicate that no WIM image is currently selected. */
397 #define WIM_NO_IMAGE    0
398
399 /** Used to specify all images in the WIM. */
400 #define WIM_ALL_IMAGES  (-1)
401
402
403 /**
404  * Adds an image to a WIM file from a directory tree on disk.
405  *
406  * The directory tree is read immediately for the purpose of constructing a
407  * directory entry tree in-memory.  Also, all files are read to calculate their
408  * SHA1 message digests.  However, because the directory tree may contain a very
409  * large amount of data, the files themselves are not read into memory
410  * permanently, and instead references to their paths saved.  The files are then
411  * read on-demand if wimlib_write() or wimlib_overwrite() is called.
412  *
413  * @param wim
414  *      Pointer to the ::WIMStruct for a WIM file to which the image will be
415  *      added.
416  * @param dir
417  *      A path to a directory in the outside filesystem.  It will become the
418  *      root directory for the WIM image.
419  * @param name
420  *      The name to give the image.  This must be non-@c NULL.
421  * @param config
422  *      Pointer to the contents of an image capture configuration file.  If @c
423  *      NULL, a default string is used.  Please see the manual page for
424  *      <b>imagex capture</b> for more information.
425  * @param config_len
426  *      Length of the string @a config in bytes.  Ignored if @a config is @c
427  *      NULL.
428  *
429  * @param flags
430  *      Bitwise OR of flags prefixed with WIMLIB_ADD_IMAGE_FLAG.  If
431  *      ::WIMLIB_ADD_IMAGE_FLAG_BOOT is specified, the image in @a wim that is
432  *      marked as bootable is changed to the one being added.  If
433  *      ::WIMLIB_ADD_IMAGE_FLAG_VERBOSE is specified, the name of each file is
434  *      printed as it is scanned or captured.  If
435  *      ::WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE is specified, the files or
436  *      directories pointed to by symbolic links are archived rather than the
437  *      symbolic links themselves.  If ::WIMLIB_ADD_IMAGE_FLAG_SHOW_PROGRESS is
438  *      specified, progress information will be printed (distinct from the
439  *      verbose information).
440  *
441  * @return 0 on success; nonzero on error.  On error, changes to @a wim are
442  * discarded so that it appears to be in the same state as when this function
443  * was called.
444  *
445  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
446  *      There is already an image named @a name in @a w.
447  * @retval ::WIMLIB_ERR_INVALID_PARAM
448  *      @a dir was @c NULL, @a name was @c NULL, or @a name was the empty string.
449  * @retval ::WIMLIB_ERR_NOMEM
450  *      Failed to allocate needed memory.
451  * @retval ::WIMLIB_ERR_NOTDIR
452  *      @a dir is not a directory.
453  * @retval ::WIMLIB_ERR_OPEN
454  *      Failed to open a file or directory in the directory tree rooted at @a
455  *      dir.
456  * @retval ::WIMLIB_ERR_READ
457  *      Failed to read a file in the directory tree rooted at @a dir.
458  * @retval ::WIMLIB_ERR_SPECIAL_FILE
459  *      The directory tree rooted at @dir contains a special file that is not a
460  *      directory, regular file, or symbolic link.
461  * @retval ::WIMLIB_ERR_STAT
462  *      Failed obtain the metadata for a file or directory in the directory tree
463  *      rooted at @a dir.
464  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
465  *      @a wim is part of a split WIM.  Adding an image to a split WIM is
466  *      unsupported.
467  */
468 extern int wimlib_add_image(WIMStruct *wim, const char *dir,
469                             const char *name, const char *config,
470                             size_t config_len, int flags);
471
472 /**
473  * This function is similar to wimlib_add_image(), except instead of capturing
474  * the WIM image from a directory, it is captured from a NTFS volume specified
475  * by @a device.  NTFS-3g errors are reported as ::WIMLIB_ERR_NTFS_3G.
476  * ::WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE may not be specified because we capture
477  * the reparse points exactly as they are.
478  */
479 extern int wimlib_add_image_from_ntfs_volume(WIMStruct *wim, const char *device,
480                                              const char *name,
481                                              const char *config,
482                                              size_t config_len,
483                                              int flags);
484
485 /**
486  * This function is similar to wimlib_extract_image(), except that @a image may
487  * not be ::WIM_ALL_IMAGES, and @a device specifies the name of a file or block
488  * device containing a NTFS volume to apply the image to.  NTFS-3g errors are
489  * reported as ::WIMLIB_ERR_NTFS_3G, and ::WIMLIB_EXTRACT_FLAG_HARDLINK or
490  * ::WIMLIB_EXTRACT_FLAG_SYMLINK may not be specified because in the NTFS
491  * apply mode we apply the reparse points and hard links exactly as they are in
492  * the WIM.
493  */
494 extern int wimlib_apply_image_to_ntfs_volume(WIMStruct *wim, int image,
495                                              const char *device, int flags,
496                                              WIMStruct **additional_swms,
497                                              unsigned num_additional_swms);
498
499 /**
500  * Creates a WIMStruct for a new WIM file.
501  *
502  * @param ctype
503  *      The type of compression to be used in the new WIM file.  Must be
504  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX, or
505  *      ::WIM_COMPRESSION_TYPE_XPRESS.
506  * @param wim_ret
507  *      On success, a pointer to an opaque ::WIMStruct for the new WIM file is
508  *      written to the memory location pointed to by this paramater.  The
509  *      ::WIMStruct must be freed using using wimlib_free() when finished with
510  *      it.
511  * @return 0 on success; nonzero on error.
512  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
513  *      @a ctype was not ::WIM_COMPRESSION_TYPE_NONE,
514  *      ::WIM_COMPRESSION_TYPE_LZX, or ::WIM_COMPRESSION_TYPE_XPRESS.
515  * @retval ::WIMLIB_ERR_NOMEM
516  *      Failed to allocate needed memory.
517  */
518 extern int wimlib_create_new_wim(int ctype, WIMStruct **wim_ret);
519
520 /**
521  * Deletes an image, or all images, from a WIM file.
522  *
523  * All streams referenced by the image(s) being deleted are removed from the
524  * lookup table of the WIM if they are not referenced by any other images in the
525  * WIM.
526  *
527  * @param wim
528  *      Pointer to the ::WIMStruct for the WIM file that contains the image(s)
529  *      being deleted.
530  * @param image
531  *      The number of the image to delete, or ::WIM_ALL_IMAGES to delete all
532  *      images.
533  * @return 0 on success; nonzero on failure.  On failure, @a wim is guaranteed
534  * to be left unmodified only if @a image specified a single image.  If instead
535  * @a image was ::WIM_ALL_IMAGES and @a wim contained more than one image, it's
536  * possible for some but not all of the images to have been deleted when a
537  * failure status is returned.
538  *
539  * @retval ::WIMLIB_ERR_DECOMPRESSION
540  *      Could not decompress the metadata resource for @a image.
541  * @retval ::WIMLIB_ERR_INVALID_DENTRY
542  *      A directory entry in the metadata resource for @a image in the WIM is
543  *      invalid.
544  * @retval ::WIMLIB_ERR_INVALID_IMAGE
545  *      @a image does not exist in the WIM and is not ::WIM_ALL_IMAGES.
546  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
547  *      The metadata resource for @a image in the WIM is invalid.
548  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
549  *      The security data for @a image in the WIM is invalid.
550  * @retval ::WIMLIB_ERR_NOMEM
551  *      Failed to allocate needed memory.
552  * @retval ::WIMLIB_ERR_READ
553  *      Could not read the metadata resource for @a image from the WIM.
554  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
555  *      @a wim is part of a split WIM.  Deleting an image from a split WIM is
556  *      unsupported.
557  */
558 extern int wimlib_delete_image(WIMStruct *wim, int image);
559
560 /**
561  * Exports an image, or all the images, from a WIM file, into another WIM file.
562  *
563  * The destination image is made to share the same dentry tree and security data
564  * structure as the source image.  This places some restrictions on additional
565  * functions that may be called.  wimlib_mount() may not be called on either the
566  * source image or the destination image without an intervening call to a
567  * function that un-shares the images, such as wimlib_free() on @a dest_wim, or
568  * wimlib_delete_image() on either the source or destination image.
569  * Furthermore, you may not call wimlib_free() or wimlib_overwrite() on @a
570  * src_wim before any calls to functions such as wimlib_write() on @a dest_wim
571  * because @a dest_wim will have references back to @a src_wim.
572  *
573  * Previous versions of this function left @a dest_wim in an indeterminate state
574  * on failure.  This is no longer the case; all changes to @a dest_wim made by
575  * this function are rolled back on failure.
576  *
577  * Previous versions of this function did not allow exporting an image that had
578  * been added by wimlib_add_image().  This is no longer the case; you may now
579  * export an image regardless of how it was added.
580  *
581  * Regardless of whether this function succeeds or fails, no user-visible
582  * changes are made to @a src_wim.
583  *
584  * @param src_wim
585  *      Pointer to the ::WIMStruct for a stand-alone WIM or part 1 of a split
586  *      WIM that contains the image(s) being exported.
587  * @param src_image
588  *      The image to export from @a src_wim.  Can be the number of an image, or
589  *      ::WIM_ALL_IMAGES to export all images.
590  * @param dest_wim
591  *      Pointer to the ::WIMStruct for a WIM file that will receive the images
592  *      being exported.
593  * @param dest_name
594  *      The name to give the exported image in the new WIM file.  If left @c NULL,
595  *      the name from @a src_wim is used.  This parameter must be left @c NULL
596  *      if @a src_image is ::WIM_ALL_IMAGES and @a src_wim contains more than one
597  *      image; in that case, the names are all taken from the @a src_wim.
598  * @param dest_description
599  *      The description to give the exported image in the new WIM file.  If left
600  *      @c NULL, the description from the @a src_wim is used.  This parameter must
601  *      be left @c NULL if @a src_image is ::WIM_ALL_IMAGES and @a src_wim contains
602  *      more than one image; in that case, the descriptions are all taken from
603  *      @a src_wim.
604  * @param flags
605  *      ::WIMLIB_EXPORT_FLAG_BOOT if the image being exported is to be made
606  *      bootable, or 0 if which image is marked as bootable in the destination
607  *      WIM is to be left unchanged.  If @a src_image is ::WIM_ALL_IMAGES and
608  *      there are multiple images in @a src_wim, specifying
609  *      ::WIMLIB_EXPORT_FLAG_BOOT is valid only if one of the exported images is
610  *      currently marked as bootable in @a src_wim; if that is the case, then
611  *      that image is marked as bootable in the destination WIM.
612  * @param additional_swms
613  *      Array of pointers to the ::WIMStruct for each additional part in the
614  *      split WIM.  Ignored if @a num_additional_swms is 0.  The pointers do not
615  *      need to be in any particular order, but they must include all parts of
616  *      the split WIM other than the first part, which must be provided in the
617  *      @a wim parameter.
618  * @param num_additional_swms
619  *      Number of additional WIM parts provided in the @a additional_swms array.
620  *      This number should be one less than the total number of parts in the
621  *      split WIM.  Set to 0 if the WIM is a standalone WIM.
622  *
623  * @return 0 on success; nonzero on error.
624  * @retval ::WIMLIB_ERR_DECOMPRESSION
625  *      Could not decompress the metadata resource for @a src_image
626  *      in @a src_wim
627  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
628  *      One or more of the names being given to an exported image was already in
629  *      use in the destination WIM.
630  * @retval ::WIMLIB_ERR_INVALID_DENTRY
631  *      A directory entry in the metadata resource for @a src_image in @a
632  *      src_wim is invalid.
633  * @retval ::WIMLIB_ERR_INVALID_IMAGE
634  *      @a src_image does not exist in @a src_wim.
635  * @retval ::WIMLIB_ERR_INVALID_PARAM
636  *      ::WIMLIB_EXPORT_FLAG_BOOT was specified in @a flags, @a src_image was
637  *      ::WIM_ALL_IMAGES, @a src_wim contains multiple images, and no images in
638  *      @a src_wim are marked as bootable; or @a dest_name and/or @a
639  *      dest_description were non-<code>NULL</code>, @a src_image was
640  *      ::WIM_ALL_IMAGES, and @a src_wim contains multiple images; or @a src_wim
641  *      or @a dest_wim was @c NULL.
642  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
643  *      The metadata resource for @a src_image in @a src_wim is invalid.
644  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
645  *      The security data for @a src_image in @a src_wim is invalid.
646  * @retval ::WIMLIB_ERR_NOMEM
647  *      Failed to allocate needed memory.
648  * @retval ::WIMLIB_ERR_READ
649  *      Could not read the metadata resource for @a src_image from @a src_wim.
650  * @retval ::WIMLIB_ERR_SPLIT_INVALID
651  *      The source WIM is a split WIM, but the parts specified do not form a
652  *      complete split WIM because they do not include all the parts of the
653  *      original WIM, there are duplicate parts, or not all the parts have the
654  *      same GUID and compression type.
655  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
656  *      @a dest_wim is part of a split WIM.  Exporting an image to a split WIM
657  *      is unsupported.
658  */
659 extern int wimlib_export_image(WIMStruct *src_wim, int src_image,
660                                WIMStruct *dest_wim, const char *dest_name,
661                                const char *dest_description, int flags,
662                                WIMStruct **additional_swms,
663                                unsigned num_additional_swms);
664
665 /**
666  * Extracts an image, or all images, from a standalone or split WIM file.
667  *
668  * @param wim
669  *      Pointer to the ::WIMStruct for a standalone WIM file, or part 1 of a
670  *      split WIM.
671  * @param image
672  *      The image to extract.  Can be the number of an image, or ::WIM_ALL_IMAGES
673  *      to specify that all images are to be extracted.
674  * @param output_dir
675  *      Directory to extract the WIM image(s) to.  It is created if it does not
676  *      already exist.
677  * @param flags
678  *      Bitwise or of the flags prefixed with WIMLIB_EXTRACT_FLAG.
679  *
680  *      One or none of ::WIMLIB_EXTRACT_FLAG_HARDLINK or
681  *      ::WIMLIB_EXTRACT_FLAG_SYMLINK may be specified.  These flags cause
682  *      extracted files that are identical to be hardlinked or symlinked
683  *      together, depending on the flag.  These flags override the hard link
684  *      groups that are specified in the WIM file itself.  If ::WIM_ALL_IMAGES
685  *      is provided as the @a image parameter, files may be hardlinked or
686  *      symlinked across images if a file is found to occur in more than one
687  *      image.
688  *
689  *      You may also specify the flag ::WIMLIB_EXTRACT_FLAG_VERBOSE to cause
690  *      informational messages to be printed during the extraction, including
691  *      the name of each extracted file or directory.
692  * @param additional_swms
693  *      Array of pointers to the ::WIMStruct for each additional part in the
694  *      split WIM.  Ignored if @a num_additional_swms is 0.  The pointers do not
695  *      need to be in any particular order, but they must include all parts of
696  *      the split WIM other than the first part, which must be provided in the
697  *      @a wim parameter.
698  * @param num_additional_swms
699  *      Number of additional WIM parts provided in the @a additional_swms array.
700  *      This number should be one less than the total number of parts in the
701  *      split WIM.  Set to 0 if the WIM is a standalone WIM.
702  *
703  * @return 0 on success; nonzero on error.
704  * @retval ::WIMLIB_ERR_DECOMPRESSION
705  *      Could not decompress a resource (file or metadata) for @a image in @a
706  *      wim.
707  * @retval ::WIMLIB_ERR_INVALID_DENTRY
708  *      A directory entry in the metadata resource for @a image in @a wim is
709  *      invalid.
710  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
711  *      The SHA1 message digest of an extracted stream did not match the SHA1
712  *      message digest given in the WIM file.
713  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
714  *      A resource (file or metadata) for @a image in @a wim is invalid.
715  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
716  *      The security data for @a image in @a wim is invalid.
717  * @retval ::WIMLIB_ERR_LINK
718  *      Failed to create a symbolic link or a hard link.
719  * @retval ::WIMLIB_ERR_MKDIR
720  *      Failed create a needed directory.
721  * @retval ::WIMLIB_ERR_NOMEM
722  *      Failed to allocate needed memory.
723  * @retval ::WIMLIB_ERR_OPEN
724  *      Could not open one of the files being extracted for writing.
725  * @retval ::WIMLIB_ERR_READ
726  *      A unexpected end-of-file or read error occurred when trying to read data
727  *      from the WIM file associated with @a wim.
728  * @retval ::WIMLIB_ERR_SPLIT_INVALID
729  *      The WIM is a split WIM, but the parts specified do not form a complete
730  *      split WIM because they do not include all the parts of the original WIM,
731  *      there are duplicate parts, or not all the parts have the same GUID and
732  *      compression type.
733  * @retval ::WIMLIB_ERR_WRITE
734  *      Failed to write a file being extracted.
735  */
736 extern int wimlib_extract_image(WIMStruct *wim, int image,
737                                 const char *output_dir, int flags,
738                                 WIMStruct **additional_swms,
739                                 unsigned num_additional_swms);
740
741 /**
742  * Extracts the XML data for a WIM file to a file stream.  Every WIM file
743  * includes a string of XML that describes the images contained in the WIM.
744  * This function works on standalone WIMs as well as split WIM parts.
745  *
746  * @param wim
747  *      Pointer to the ::WIMStruct for a WIM file.
748  * @param fp
749  *      @c stdout, or a FILE* opened for writing, to extract the data to.
750  *
751  * @return 0 on success; nonzero on error.
752  * @retval ::WIMLIB_ERR_WRITE
753  *      Failed to completely write the XML data to @a fp.
754  */
755 extern int wimlib_extract_xml_data(WIMStruct *wim, FILE *fp);
756
757 /**
758  * Frees all memory allocated for a WIMStruct and closes all files associated
759  * with it.
760  *
761  * @param wim
762  *      Pointer to the ::WIMStruct for a WIM file.
763  *
764  * @return This function has no return value.
765  */
766 extern void wimlib_free(WIMStruct *wim);
767
768 /**
769  * Finds which image in a WIM is bootable.
770  *
771  * @param wim
772  *      Pointer to the ::WIMStruct for a WIM file.
773  *
774  * @return
775  *      0 if no image is marked as bootable, or the number of the image marked
776  *      as bootable (numbered starting at 1).
777  */
778 extern int wimlib_get_boot_idx(const WIMStruct *wim);
779
780 /**
781  * Gets the compression type used in the WIM.
782  *
783  * @param wim
784  *      Pointer to the ::WIMStruct for a WIM file
785  *
786  * @return
787  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX, or
788  *      ::WIM_COMPRESSION_TYPE_XPRESS.
789  */
790 extern int wimlib_get_compression_type(const WIMStruct *wim);
791
792 /**
793  * Converts a compression type enumeration value into a string.
794  *
795  * @param ctype
796  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX,
797  *      ::WIM_COMPRESSION_TYPE_XPRESS, or another value.
798  *
799  * @return
800  *      A statically allocated string: "None", "LZX", "XPRESS", or "Invalid",
801  *      respectively.
802  */
803 extern const char *wimlib_get_compression_type_string(int ctype);
804
805 /**
806  * Converts an error code into a string describing it.
807  *
808  * @param code
809  *      The error code returned by one of wimlib's functions.
810  *
811  * @return
812  *      Pointer to a statically allocated string describing the error code,
813  *      or @c NULL if the error code is not valid.
814  */
815 extern const char *wimlib_get_error_string(enum wimlib_error_code code);
816
817 /**
818  * Returns the description of the specified image.
819  *
820  * @param wim
821  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
822  *      standalone WIM or a split WIM part.
823  * @param image
824  *      The number of the image, numbered starting at 1.
825  *
826  * @return
827  *      The description of the image, or @c NULL if there is no such image, or
828  *      @c NULL if the specified image has no description.  The description
829  *      string is in library-internal memory and may not be modified or freed;
830  *      in addition, the string will become invalid if the description of the
831  *      image is changed, the image is deleted, or the ::WIMStruct is destroyed.
832  */
833 extern const char *wimlib_get_image_description(const WIMStruct *wim, int image);
834
835 /**
836  * Returns the name of the specified image.
837  *
838  * @param wim
839  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
840  *      standalone WIM or a split WIM part.
841  * @param image
842  *      The number of the image, numbered starting at 1.
843  *
844  * @return
845  *      The name of the image, or @c NULL if there is no such image.  The name
846  *      string is in library-internal memory and may not be modified or freed;
847  *      in addition, the string will become invalid if the name of the image is
848  *      changed, the image is deleted, or the ::WIMStruct is destroyed.
849  */
850 extern const char *wimlib_get_image_name(const WIMStruct *wim, int image);
851
852
853 /**
854  * Gets the number of images contained in the WIM.
855  *
856  * @param wim
857  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
858  *      standalone WIM or a split WIM part.
859  *
860  * @return
861  *      The number of images contained in the WIM file.
862  */
863 extern int wimlib_get_num_images(const WIMStruct *wim);
864
865 /**
866  * Gets the part number of part of a split WIM.
867  *
868  * @param wim
869  *      Pointer to the ::WIMStruct for a WIM file.
870  * @param total_parts_ret
871  *      If non-@c NULL, the total number of parts in the split WIM (1 for
872  *      non-split WIMs) is written to this location.
873  *
874  * @return
875  *      The part number of the WIM (1 for non-split WIMs)
876  */
877 extern int wimlib_get_part_number(const WIMStruct *wim, int *total_parts_ret);
878
879 /**
880  * Returns true if the WIM has an integrity table.
881  *
882  * @param wim
883  *      Pointer to the ::WIMStruct for a WIM file.
884  * @return
885  *      @c true if the WIM has an integrity table; @c false otherwise.
886  */
887 extern bool wimlib_has_integrity_table(const WIMStruct *wim);
888
889
890 /**
891  * Determines if an image name is already used by some image in the WIM.
892  *
893  * @param wim
894  *      Pointer to the ::WIMStruct for a WIM file.
895  * @param name
896  *      The name to check.
897  *
898  * @return
899  *      @c true if there is already an image in @a wim named @a name; @c false
900  *      if there is no image named @a name in @a wim.  (If @a name is @c NULL,
901  *      @c false is returned.)
902  */
903 extern bool wimlib_image_name_in_use(const WIMStruct *wim, const char *name);
904
905 /**
906  * Joins a set of split WIMs into a one-part WIM.
907  *
908  * @param swms
909  *      An array of strings that give the filenames of all parts of the split
910  *      WIM.
911  * @param num_swms
912  *      Number of filenames in @a swms.
913  * @param output_path
914  *      The path to write the one-part WIM to.
915  * @param flags
916  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY to check the split WIMs' integrity
917  *      tables (if present) when opening them, and include an integrity table in
918  *      the output WIM.
919  *
920  * @return 0 on success; nonzero on error.  This function may return any value
921  * returned by wimlib_open_wim() except ::WIMLIB_ERR_SPLIT_UNSUPPORTED, as well
922  * as the following error codes:
923  *
924  * @retval ::WIMLIB_ERR_SPLIT_INVALID
925  *      The split WIMs do not form a valid WIM because they do not include all
926  *      the parts of the original WIM, there are duplicate parts, or not all the
927  *      parts have the same GUID and compression type.
928  * @retval ::WIMLIB_ERR_WRITE
929  *      An error occurred when trying to write data to the new WIM at @a output_path.
930  *
931  * Note that this function merely copies the resources, so it will not check to
932  * see if the resources, including the metadata resources, are valid or not.
933  *
934  * Also, after this function is called, the only function that may be called on
935  * the ::WIMStruct's in the @a swms array is wimlib_free().
936  */
937 extern int wimlib_join(const char **swms, unsigned num_swms,
938                        const char *output_path, int flags);
939
940 /**
941  * Mounts an image in a WIM file on a directory read-only or read-write.
942  *
943  * A daemon will be forked to service the filesystem.
944  *
945  * If the mount is read-write, modifications to the WIM are staged in a staging
946  * directory.
947  *
948  * wimlib_mount() may be called from multiple threads without intervening calls
949  * to wimlib_unmount(), provided that different ::WIMStruct's are used.  (This
950  * was not the case for versions of this library 1.0.3 and earlier.)
951  *
952  * wimlib_mount() cannot be used on an image that was exported with
953  * wimlib_export_image() while the dentry trees for both images are still in
954  * memory.  In addition, wimlib_mount() may not be used to mount an image that
955  * has just been added with wimlib_add_image() or
956  * wimlib_add_image_from_ntfs_volume(), unless the WIM has been written and read
957  * into a new ::WIMStruct.
958  *
959  * @param wim
960  *      Pointer to the ::WIMStruct for the WIM file to be mounted.
961  * @param image
962  *      The number of the image to mount, numbered from 1.  It must be an
963  *      existing, single image.
964  * @param dir
965  *      The path to an existing directory to mount the image on.
966  * @param flags
967  *      Bitwise OR of the flags prefixed with WIMLIB_MOUNT_FLAG.  If
968  *      ::WIMLIB_MOUNT_FLAG_READWRITE is not given, the WIM is mounted
969  *      read-only.  The interface to the WIM named data streams is specified by
970  *      exactly one of ::WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE,
971  *      ::WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR, or
972  *      ::WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS.  The default interface is
973  *      the XATTR interface.
974  * @param additional_swms
975  *      Array of pointers to the ::WIMStruct for each additional part in the
976  *      split WIM.  Ignored if @a num_additional_swms is 0.  The pointers do not
977  *      need to be in any particular order, but they must include all parts of
978  *      the split WIM other than the first part, which must be provided in the
979  *      @a wim parameter.
980  * @param num_additional_swms
981  *      Number of additional WIM parts provided in the @a additional_swms array.
982  *      This number should be one less than the total number of parts in the
983  *      split WIM.  Set to 0 if the WIM is a standalone WIM.
984  *
985  * @return 0 on success; nonzero on error.
986  * @retval ::WIMLIB_ERR_DECOMPRESSION
987  *      Could not decompress the metadata resource for @a image in @a wim.
988  * @retval ::WIMLIB_ERR_FUSE
989  *      A non-zero status was returned by @c fuse_main().
990  * @retval ::WIMLIB_ERR_INVALID_DENTRY
991  *      A directory entry in the metadata resource for @a image in @a wim is
992  *      invalid.
993  * @retval ::WIMLIB_ERR_INVALID_IMAGE
994  *      @a image does not specify an existing, single image in @a wim.
995  * @retval ::WIMLIB_ERR_INVALID_PARAM
996  *      @a image is shared among multiple ::WIMStruct's as a result of a call to
997  *      wimlib_export_image(), or @a image has been added with
998  *      wimlib_add_image() or wimlib_add_image_from_ntfs_volume().
999  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1000  *      The metadata resource for @a image in @a wim is invalid.
1001  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
1002  *      The security data for @a image in @a wim is invalid.
1003  * @retval ::WIMLIB_ERR_MKDIR
1004  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @a flags, but the staging
1005  *      directory could not be created.
1006  * @retval ::WIMLIB_ERR_NOMEM
1007  *      Failed to allocate needed memory.
1008  * @retval ::WIMLIB_ERR_NOTDIR
1009  *      Could not determine the current working directory.
1010  * @retval ::WIMLIB_ERR_READ
1011  *      An unexpected end-of-file or read error occurred when trying to read
1012  *      data from the WIM file associated with @a wim.
1013  * @retval ::WIMLIB_ERR_SPLIT_INVALID
1014  *      The WIM is a split WIM, but the parts specified do not form a complete
1015  *      split WIM because they do not include all the parts of the original WIM,
1016  *      there are duplicate parts, or not all the parts have the same GUID and
1017  *      compression type.
1018  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1019  *      The WIM is a split WIM and a read-write mount was requested.  We only
1020  *      support mounting a split WIM read-only.
1021  */
1022 extern int wimlib_mount(WIMStruct *wim, int image, const char *dir, int flags,
1023                         WIMStruct **additional_swms,
1024                         unsigned num_additional_swms);
1025
1026 /**
1027  * Opens a WIM file and creates a ::WIMStruct for it.
1028  *
1029  * @param wim_file
1030  *      The path to the WIM file to open.
1031  * @param flags
1032  *      Bitwise OR of ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY and/or
1033  *      ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS.
1034  *      If ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY is given, the integrity table
1035  *      of the WIM, if it exists, is checked, and the function will fail with an
1036  *      ::WIMLIB_ERR_INTEGRITY status if any of the computed SHA1 message
1037  *      digests of the WIM do not exactly match the corresponding message
1038  *      digests given in the integrity table.
1039  *      If ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS is given, progress information will
1040  *      be shown if the integrity of the WIM is checked.
1041  *      If ::WIMLIB_OPEN_FLAG_SPLIT_OK is given, no error will be issued if the
1042  *      WIM is part of a split WIM; otherwise ::WIMLIB_ERR_SPLIT_UNSUPPORTED is
1043  *      returned.  (This flag may be removed in the future, in which case no
1044  *      error will be issued when opening a split WIM.)
1045  *
1046  * @param wim_ret
1047  *      On success, a pointer to an opaque ::WIMStruct for the opened WIM file
1048  *      is written to the memory location pointed to by this parameter.  The
1049  *      ::WIMStruct must be freed using using wimlib_free() when finished with
1050  *      it.
1051  *
1052  * @return 0 on success; nonzero on error.
1053  * @retval ::WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE
1054  *      The lookup table of @a wim_file is compressed.  Support for this can be
1055  *      added to wimlib if needed, but it appears to be the case that the lookup
1056  *      table is never compressed.
1057  * @retval ::WIMLIB_ERR_IMAGE_COUNT
1058  *      The WIM is not the non-first part of a split WIM, and the number of
1059  *      metadata resources found in the WIM did not match the image count given
1060  *      in the WIM header, or the number of &lt;IMAGE&gt; elements in the XML
1061  *      data for the WIM did not match the image count given in the WIM header.
1062  * @retval ::WIMLIB_ERR_INTEGRITY
1063  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @a flags and @a
1064  *      wim_file contains an integrity table, but the SHA1 message digest for a
1065  *      chunk of the WIM does not match the corresponding message digest given
1066  *      in the integrity table.
1067  * @retval ::WIMLIB_ERR_INVALID_CHUNK_SIZE
1068  *      Resources in @a wim_file are compressed, but the chunk size is not 32768.
1069  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
1070  *      The header of @a wim_file says that resources in the WIM are compressed,
1071  *      but the header flag indicating LZX or XPRESS compression is not set.
1072  * @retval ::WIMLIB_ERR_INVALID_HEADER_SIZE
1073  *      The length field of the WIM header is not 208.
1074  * @retval ::WIMLIB_ERR_INVALID_INTEGRITY_TABLE
1075  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @a flags and @a
1076  *      wim_file contains an integrity table, but the integrity table is
1077  *      invalid.
1078  * @retval ::WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY
1079  *      The lookup table for the WIM contained duplicate entries, or it
1080  *      contained an entry with a SHA1 message digest of all 0's.
1081  * @retval ::WIMLIB_ERR_NOMEM
1082  *      Failed to allocated needed memory.
1083  * @retval ::WIMLIB_ERR_NOT_A_WIM_FILE
1084  *      @a wim_file does not begin with the expected magic characters.
1085  * @retval ::WIMLIB_ERR_OPEN
1086  *      Failed to open the file @a wim_file for reading.
1087  * @retval ::WIMLIB_ERR_READ
1088  *      An unexpected end-of-file or read error occurred when trying to read
1089  *      data from @a wim_file.
1090  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1091  *      @a wim_file is a split WIM, but ::WIMLIB_OPEN_FLAG_SPLIT_OK was not
1092  *      givin in @a flags.
1093  * @retval ::WIMLIB_ERR_UNKNOWN_VERSION
1094  *      A number other than 0x10d00 is written in the version field of the WIM
1095  *      header of @a wim_file.
1096  * @retval ::WIMLIB_ERR_XML
1097  *      The XML data for @a wim_file is invalid.
1098  */
1099 extern int wimlib_open_wim(const char *wim_file, int flags,
1100                            WIMStruct **wim_ret);
1101
1102 /**
1103  * Overwrites the file that the WIM was originally read from, with changes made.
1104  *
1105  * There are two ways that a WIM may be overwritten.  The first is to do a full
1106  * rebuild: the new WIM is written to a temporary file and then renamed to the
1107  * original file after it is has been completely written.  The temporary file
1108  * currently is made in the same directory as the original WIM file.  A full
1109  * rebuild may take a while, but can be used even if images have been modified
1110  * or deleted, will produce a WIM with no holes, and has little chance of
1111  * unintentional data loss because the temporary WIM is fsync()ed before being
1112  * renamed to the original WIM.
1113  *
1114  * The second way to overwrite a WIM is by appending to the end of it.  This can
1115  * be much faster than a full rebuild, but it only works if the only operations
1116  * on the WIM have been to change the header or XML data, or to add new images.
1117  * Writing a WIM in this mode begins with writing any new file resources *after*
1118  * everything in the old WIM, even though this will leave a hole where the old
1119  * lookup table, XML data, and integrity were.  This is done so that the WIM
1120  * remains valid even if the operation is aborted mid-write.
1121  *
1122  * By default, the overwrite mode is chosen based on the past operations
1123  * performed on the WIM.  Use the flag ::WIMLIB_WRITE_FLAG_REBUILD to explicitly
1124  * request a full rebuild.
1125  *
1126  * In the temporary-file overwrite mode, no changes are made to the WIM on
1127  * failure, and the temporary file is deleted (if possible).  Abnormal
1128  * termination of the program will result in the temporary file being orphaned.
1129  * In the direct append mode, the WIM is truncated to the original length on
1130  * failure, while abnormal termination of the program will result in extra data
1131  * appended to the original WIM, but it will still be a valid WIM.
1132  *
1133  * @param wim
1134  *      Pointer to the ::WIMStruct for the WIM file to write.  There may have
1135  *      been in-memory changes made to it, which are then reflected in the
1136  *      output file.
1137  * @param write_flags
1138  *      Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
1139  *      ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.
1140  * @param num_threads
1141  *      Number of threads to use for compression (see wimlib_write()).
1142  *
1143  * @return 0 on success; nonzero on error.  This function may return any value
1144  * returned by wimlib_write() as well as the following error codes:
1145  * @retval ::WIMLIB_ERR_NO_FILENAME
1146  *      @a wim corresponds to a WIM created with wimlib_create_new_wim() rather
1147  *      than a WIM read with wimlib_open_wim().
1148  * @retval ::WIMLIB_ERR_RENAME
1149  *      The temporary file that the WIM was written to could not be renamed to
1150  *      the original filename of @a wim.
1151  * @retval ::WIMLIB_ERR_REOPEN
1152  *      The WIM was overwritten successfully, but it could not be re-opened
1153  *      read-only.  Therefore, the resources in the WIM can no longer be
1154  *      accessed, so this limits the functions that can be called on @a wim
1155  *      before calling wimlib_free().
1156  */
1157 extern int wimlib_overwrite(WIMStruct *wim, int write_flags,
1158                             unsigned num_threads);
1159
1160 /**
1161  * This function is deprecated; call wimlib_overwrite() instead.
1162  * (wimlib_overwrite() no longer rebuilds the full WIM unless it has to or is
1163  * specified explicitly with ::WIMLIB_WRITE_FLAG_REBUILD)
1164  */
1165 extern int wimlib_overwrite_xml_and_header(WIMStruct *wim, int write_flags);
1166
1167 /**
1168  * Prints information about one image, or all images, contained in a WIM.
1169  *
1170  * @param wim
1171  *      Pointer to the ::WIMStruct for a WIM file.
1172  * @param image
1173  *      The image about which to print information.  Can be the number of an
1174  *      image, or ::WIM_ALL_IMAGES to print information about all images in the
1175  *      WIM.
1176  *
1177  * @return This function has no return value.  No error checking is done when
1178  * printing the information.  If @a image is invalid, an error message is
1179  * printed.
1180  */
1181 extern void wimlib_print_available_images(const WIMStruct *wim, int image);
1182
1183 /**
1184  * Prints the full paths to all files contained in an image, or all images, in a
1185  * WIM file.
1186  *
1187  * @param wim
1188  *      Pointer to the ::WIMStruct for a WIM file.
1189  * @param image
1190  *      Which image to print files for.  Can be the number of an image, or
1191  *      ::WIM_ALL_IMAGES to print the files contained in all images.
1192  *
1193  * @return 0 on success; nonzero on error.
1194  * @retval ::WIMLIB_ERR_DECOMPRESSION
1195  *      The metadata resource for one of the specified images could not be
1196  *      decompressed.
1197  * @retval ::WIMLIB_ERR_INVALID_DENTRY
1198  *      A directory entry in the metadata resource for one of the specified
1199  *      images is invaled.
1200  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1201  *      @a image does not specify a valid image in @a wim, and is not
1202  *      ::WIM_ALL_IMAGES.
1203  * @retval ::WIMLIB_ERR_INVALID_PARAM
1204  *      @a wim was @c NULL.
1205  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1206  *      The metadata resource for one of the specified images is invalid.
1207  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
1208  *      The security data for one of the specified images is invalid.
1209  * @retval ::WIMLIB_ERR_NOMEM
1210  *      Failed to allocate needed memory.
1211  * @retval ::WIMLIB_ERR_READ
1212  *      An unexpected read error or end-of-file occurred when reading the
1213  *      metadata resource for one of the specified images.
1214  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1215  *      @a wim was not a standalone WIM and was not the first part of a split
1216  *      WIM.
1217  */
1218 extern int wimlib_print_files(WIMStruct *wim, int image);
1219
1220 /**
1221  * Prints detailed information from the header of a WIM file.
1222  *
1223  * @param wim
1224  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
1225  *      standalone WIM or part of a split WIM.
1226  *
1227  * @return This function has no return value.
1228  *
1229  */
1230 extern void wimlib_print_header(const WIMStruct *wim);
1231
1232 /**
1233  * Prints the lookup table of a WIM file.  The lookup table maps SHA1 message
1234  * digests, as found in the directory entry tree in the WIM file, to file
1235  * resources in the WIM file.  This table includes one entry for each unique
1236  * file in the WIM, so it can be quite long.  There is only one lookup table per
1237  * WIM.
1238  *
1239  * @param wim
1240  *      Pointer to the ::WIMStruct for a WIM file.
1241  *
1242  * @return This function has no return value.
1243  */
1244 extern void wimlib_print_lookup_table(WIMStruct *wim);
1245
1246 /**
1247  * Prints the metadata of the specified image in a WIM file.  The metadata
1248  * consists of the security data as well as the directory entry tree, and each
1249  * image has its own metadata.
1250  *
1251  * @param wim
1252  *      Pointer to the ::WIMStruct for a WIM file.
1253  * @param image
1254  *      Which image to print the metadata for.  Can be the number of an image,
1255  *      or ::WIM_ALL_IMAGES to print the metadata for all images in the WIM.
1256  *
1257  * @return 0 on success; nonzero on error.
1258  * @retval ::WIMLIB_ERR_DECOMPRESSION
1259  *      The metadata resource for one of the specified images could not be
1260  *      decompressed.
1261  * @retval ::WIMLIB_ERR_INVALID_DENTRY
1262  *      A directory entry in the metadata resource for one of the specified
1263  *      images is invaled.
1264  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1265  *      @a image does not specify a valid image in @a wim, and is not
1266  *      ::WIM_ALL_IMAGES.
1267  * @retval ::WIMLIB_ERR_INVALID_PARAM
1268  *      @a wim was @c NULL.
1269  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1270  *      The metadata resource for one of the specified images is invalid.
1271  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
1272  *      The security data for one of the specified images is invalid.
1273  * @retval ::WIMLIB_ERR_NOMEM
1274  *      Failed to allocate needed memory.
1275  * @retval ::WIMLIB_ERR_READ
1276  *      An unexpected read error or end-of-file occurred when reading the
1277  *      metadata resource for one of the specified images.
1278  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1279  *      @a wim was not a standalone WIM and was not the first part of a split
1280  *      WIM.
1281  */
1282 extern int wimlib_print_metadata(WIMStruct *wim, int image);
1283
1284 /**
1285  * Prints some basic information about a WIM file.  All information printed by
1286  * this function is also printed by wimlib_print_header(), but
1287  * wimlib_print_wim_information() prints some of this information more concisely
1288  * and in a more readable form.
1289  *
1290  * @param wim
1291  *      Pointer to the ::WIMStruct for a WIM file.
1292  *
1293  * @return This function has no return value.
1294  */
1295 extern void wimlib_print_wim_information(const WIMStruct *wim);
1296
1297 /**
1298  * Translates a string specifying the name or number of an image in the WIM into
1299  * the number of the image.  The images are numbered starting at 1.
1300  *
1301  * @param wim
1302  *      Pointer to the ::WIMStruct for a WIM file.
1303  * @param image_name_or_num
1304  *      A string specifying which image.  If it begins with a number, it is
1305  *      taken to be a string specifying the image number.  Otherwise, it is
1306  *      taken to be the name of an image, as specified in the XML data for the
1307  *      WIM file.  It also may be the keyword "all" or the string "*", both of
1308  *      which will resolve to ::WIM_ALL_IMAGES.
1309  *
1310  * @return
1311  *      If the string resolved to a single existing image, the number of that
1312  *      image, counting starting at 1, is returned.  If the keyword "all" was
1313  *      specified, ::WIM_ALL_IMAGES is returned.  Otherwise, ::WIM_NO_IMAGE is
1314  *      returned.
1315  */
1316 extern int wimlib_resolve_image(WIMStruct *wim, const char *image_name_or_num);
1317
1318 /**
1319  * Sets which image in the WIM is marked as bootable.
1320  *
1321  * @param wim
1322  *      Pointer to the ::WIMStruct for a WIM file.
1323  * @param boot_idx
1324  *      The number of the image to mark as bootable, or 0 to mark no image as
1325  *      bootable.
1326  * @return 0 on success; nonzero on error.
1327  * @retval ::WIMLIB_ERR_INVALID_PARAM
1328  *      @a wim was @c NULL.
1329  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1330  *      @a boot_idx does not specify an existing image in @a wim, and it was not
1331  *      0.
1332  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1333  *      @a wim is part of a split WIM.  We do not support changing the boot
1334  *      index of a split WIM.
1335  */
1336 extern int wimlib_set_boot_idx(WIMStruct *wim, int boot_idx);
1337
1338 /**
1339  * Changes the description of an image in the WIM.
1340  *
1341  * @param wim
1342  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
1343  *      standalone WIM or part of a split WIM; however, you should set the same
1344  *      description on all parts of a split WIM.
1345  * @param image
1346  *      The number of the image for which to change the description.
1347  * @param description
1348  *      The new description to give the image.  It may be @c NULL, which
1349  *      indicates that the image is to be given no description.
1350  *
1351  * @return 0 on success; nonzero on error.
1352  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1353  *      @a image does not specify a single existing image in @a wim.
1354  * @retval ::WIMLIB_ERR_INVALID_PARAM
1355  *      @a wim was @c NULL.
1356  * @retval ::WIMLIB_ERR_NOMEM
1357  *      Failed to allocate the memory needed to duplicate the @a description
1358  *      string.
1359  */
1360 extern int wimlib_set_image_descripton(WIMStruct *wim, int image,
1361                                        const char *description);
1362
1363 /**
1364  * Changes what is written in the \<FLAGS\> element in the WIM XML data
1365  * (something like "Core" or "Ultimate")
1366  *
1367  * @param wim
1368  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
1369  *      standalone WIM or part of a split WIM; however, you should set the same
1370  *      \<FLAGS\> element on all parts of a split WIM.
1371  * @param image
1372  *      The number of the image for which to change the description.
1373  * @param flags
1374  *      The new \<FLAGS\> element to give the image.  It may be @c NULL, which
1375  *      indicates that the image is to be given no \<FLAGS\> element.
1376  *
1377  * @return 0 on success; nonzero on error.
1378  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1379  *      @a image does not specify a single existing image in @a wim.
1380  * @retval ::WIMLIB_ERR_INVALID_PARAM
1381  *      @a wim was @c NULL.
1382  * @retval ::WIMLIB_ERR_NOMEM
1383  *      Failed to allocate the memory needed to duplicate the @a flags string.
1384  */
1385 extern int wimlib_set_image_flags(WIMStruct *wim, int image, const char *flags);
1386
1387 /**
1388  * Changes the name of an image in the WIM.
1389  *
1390  * @param wim
1391  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
1392  *      standalone WIM or part of a split WIM; however, you should set the same
1393  *      name on all parts of a split WIM.
1394  * @param image
1395  *      The number of the image for which to change the name.
1396  * @param name
1397  *      The new name to give the image.  It must not a nonempty string.
1398  *
1399  * @return 0 on success; nonzero on error.
1400  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
1401  *      There is already an image named @a name in @a wim.
1402  * @retval ::WIMLIB_ERR_INVALID_PARAM
1403  *      @a name was @c NULL or the empty string, or @a wim was @c NULL.
1404  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1405  *      @a image does not specify a single existing image in @a wim.
1406  * @retval ::WIMLIB_ERR_NOMEM
1407  *      Failed to allocate the memory needed to duplicate the @a name string.
1408  */
1409 extern int wimlib_set_image_name(WIMStruct *wim, int image, const char *name);
1410
1411 /**
1412  * Set the functions that wimlib uses to allocate and free memory.
1413  *
1414  * These settings are global and not per-WIM.
1415  *
1416  * The default is to use the default @c malloc() and @c free() from the C
1417  * library.
1418  *
1419  * Please note that some external functions we call still may use the standard
1420  * memory allocation functions.
1421  *
1422  * @param malloc_func
1423  *      A function equivalent to @c malloc() that wimlib will use to allocate
1424  *      memory.  If @c NULL, the allocator function is set back to the default
1425  *      @c malloc() from the C library.
1426  * @param free_func
1427  *      A function equivalent to @c free() that wimlib will use to free memory.
1428  *      If @c NULL, the free function is set back to the default @c free() from
1429  *      the C library.
1430  * @param realloc_func
1431  *      A function equivalent to @c realloc() that wimlib will use to reallocate
1432  *      memory.  If @c NULL, the free function is set back to the default @c
1433  *      realloc() from the C library.
1434  * @return 0 on success; nonzero on error.
1435  * @retval ::WIMLIB_ERR_UNSUPPORTED
1436  *      wimlib was compiled with the @c --without-custom-memory-allocator flag,
1437  *      so custom memory allocators are unsupported.
1438  */
1439 int wimlib_set_memory_allocator(void *(*malloc_func)(size_t),
1440                                  void (*free_func)(void *),
1441                                  void *(*realloc_func)(void *, size_t));
1442
1443 /**
1444  * Sets whether wimlib is to print error messages to @c stderr when a function
1445  * fails.  These error messages may provide information that cannot be
1446  * determined only from the error code that is returned.  Not every error will
1447  * result in an error message being printed.
1448  *
1449  * This setting is global and not per-WIM.
1450  *
1451  * By default, error messages are not printed.
1452  *
1453  * @param show_messages
1454  *      @c true if error messages are to be printed; @c false if error messages
1455  *      are not to be printed.
1456  *
1457  * @return 0 on success; nonzero on error.
1458  * @retval ::WIMLIB_ERR_UNSUPPORTED
1459  *      @a show_messages was @c true, but wimlib was compiled with the @c
1460  *      --without-error-messages option.   Therefore, error messages cannot be
1461  *      shown.
1462  */
1463 extern int wimlib_set_print_errors(bool show_messages);
1464
1465 /**
1466  * Splits a WIM into multiple parts.
1467  *
1468  * @param wimfile
1469  *      Name of the WIM file to split.  It must be a standalone, one-part WIM.
1470  * @param swm_name
1471  *      Name of the SWM file to create.  This will be the name of the first
1472  *      part.  The other parts will have the same name with 2, 3, 4, ..., etc.
1473  *      appended.
1474  * @param part_size
1475  *      The maximum size per part, in bytes.  It is not guaranteed that this
1476  *      will really be the maximum size per part, because some file resources in
1477  *      the WIM may be larger than this size, and the WIM file format provides
1478  *      no way to split up file resources among multiple WIMs.
1479  * @param flags
1480  *      Bitwise OR of ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY and/or
1481  *      ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS.
1482  *
1483  * @return 0 on success; nonzero on error.  This function may return any value
1484  * returned by wimlib_open_wim() as well as the following error codes:
1485  *
1486  * @retval ::WIMLIB_ERR_WRITE
1487  *      An error occurred when trying to write data to one of the split WIMs.
1488  *
1489  */
1490 extern int wimlib_split(const char *wimfile, const char *swm_name,
1491                         size_t part_size, int flags);
1492
1493 /**
1494  * Unmounts a WIM image that was mounted using wimlib_mount().
1495  *
1496  * Blocks until it is known whether the mount succeeded or failed.
1497  *
1498  * To perform this operation, the process calling wimlib_unmount() communicates
1499  * with the process that had called wimlib_mount().
1500  *
1501  * There is currently a design problem with this function because it is hard to
1502  * know whether the filesystem daemon is still working or whether it has
1503  * crashed, has been killed, or has reached an infinite loop. However, ideally
1504  * there should be no infinite loops or crashes in the code, so this wouldn't be
1505  * much of a problem.  Currently, a timeout of 600 seconds (so long because WIMs
1506  * can be very large) is implemented so that this function will not wait forever
1507  * before returning failure.
1508  *
1509  * @param dir
1510  *      The directory that the WIM image was mounted on.
1511  * @param flags
1512  *      Bitwise OR of the flags ::WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY or
1513  *      ::WIMLIB_UNMOUNT_FLAG_COMMIT.  Neither of these flags affect read-only
1514  *      mounts.
1515  *
1516  * @return 0 on success; nonzero on error.
1517  * @retval ::WIMLIB_ERR_DELETE_STAGING_DIR
1518  *      The filesystem daemon was unable to remove the staging directory and the
1519  *      temporary files that it contains.
1520  * @retval ::WIMLIB_ERR_FORK
1521  *      Could not @c fork() the process.
1522  * @retval ::WIMLIB_ERR_FUSERMOUNT
1523  *      The @b fusermount program could not be executed or exited with a failure
1524  *      status.
1525  * @retval ::WIMLIB_ERR_MQUEUE
1526  *      Could not open a POSIX message queue to communicate with the filesystem
1527  *      daemon servicing the mounted filesystem, could not send a message
1528  *      through the queue, or could not receive a message through the queue.
1529  * @retval ::WIMLIB_ERR_NOMEM
1530  *      Failed to allocate needed memory.
1531  * @retval ::WIMLIB_ERR_OPEN
1532  *      The filesystem daemon could not open a temporary file for writing the
1533  *      new WIM.
1534  * @retval ::WIMLIB_ERR_TIMEOUT
1535  *      600 seconds elapsed while waiting for the filesystem daemon to notify
1536  *      the process of its exit status, so the WIM file probably was not written
1537  *      successfully.
1538  * @retval ::WIMLIB_ERR_READ
1539  *      A read error occurred when the filesystem daemon tried to a file from
1540  *      the staging directory
1541  * @retval ::WIMLIB_ERR_RENAME
1542  *      The filesystem daemon failed to rename the newly written WIM file to the
1543  *      original WIM file.
1544  * @retval ::WIMLIB_ERR_WRITE
1545  *      A write error occurred when the filesystem daemon was writing to the new
1546  *      WIM file, or the filesystem daemon was unable to flush changes that had
1547  *      been made to files in the staging directory.
1548  */
1549 extern int wimlib_unmount(const char *dir, int flags);
1550
1551 /**
1552  * Writes the WIM to a file.
1553  *
1554  * @param wim
1555  *      Pointer to the ::WIMStruct for a WIM file.  There may have been
1556  *      in-memory changes made to it, which are then reflected in the output
1557  *      file.
1558  * @param path
1559  *      The path to the file to write the WIM to.
1560  * @param image
1561  *      The image inside the WIM to write.  Use ::WIM_ALL_IMAGES to include all
1562  *      images.
1563  * @param write_flags
1564  *      Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
1565  *      ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.  If
1566  *      ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY is given, an integrity table is
1567  *      included in the WIM being written.  If ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS
1568  *      is given, the progress of the calculation of the integrity table is
1569  *      shown.
1570  * @param num_threads
1571  *      Number of threads to use for compressing data.  Autodetected if set to
1572  *      0.  Note: if no data compression needs to be done, no threads will be
1573  *      created regardless of this parameter (e.g. if writing an uncompressed
1574  *      WIM, or exporting an image from a compressed WIM to another WIM of the
1575  *      same compression type).
1576  *
1577  * @return 0 on success; nonzero on error.
1578  * @retval ::WIMLIB_ERR_DECOMPRESSION
1579  *      Failed to decompress a metadata or file resource in @a wim.
1580  * @retval ::WIMLIB_ERR_INVALID_DENTRY
1581  *      A directory entry in the metadata resource for @a image in @a wim is
1582  *      invalid.
1583  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1584  *      @a image does not specify a single existing image in @a wim, and is not
1585  *      ::WIM_ALL_IMAGES.
1586  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
1587  *      A file that had previously been scanned for inclusion in the WIM by the
1588  *      wimlib_add_image() or wimlib_add_image_from_ntfs_volume() functions was
1589  *      concurrently modified, so it failed the SHA1 message digest check.
1590  * @retval ::WIMLIB_ERR_INVALID_PARAM
1591  *      @a wim or @a path was @c NULL.
1592  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1593  *      The metadata resource for @a image in @a wim is invalid.
1594  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
1595  *      The security data for @a image in @a wim is invalid.
1596  * @retval ::WIMLIB_ERR_NOMEM
1597  *      Failed to allocate needed memory.
1598  * @retval ::WIMLIB_ERR_OPEN
1599  *      Failed to open @a path for writing, or some file resources in @a
1600  *      wim refer to files in the outside filesystem, and one of these files
1601  *      could not be opened for reading.
1602  * @retval ::WIMLIB_ERR_READ
1603  *      An error occurred when trying to read data from the WIM file associated
1604  *      with @a wim, or some file resources in @a wim refer to files in the
1605  *      outside filesystem, and a read error occurred when reading one of these
1606  *      files.
1607  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1608  *      @a wim is part of a split WIM.  You may not call this function on a
1609  *      split WIM.
1610  * @retval ::WIMLIB_ERR_WRITE
1611  *      An error occurred when trying to write data to the new WIM file at @a
1612  *      path.
1613  */
1614 extern int wimlib_write(WIMStruct *wim, const char *path, int image,
1615                         int write_flags, unsigned num_threads);
1616
1617
1618
1619 #endif /* _WIMLIB_H */
1620