]> wimlib.net Git - wimlib/blob - src/wimlib.h
License and documentation
[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  * The main intended use of wimlib is to create customized images of Windows PE,
38  * the Windows Preinstallation Environment, without having to rely on Windows.
39  * Windows PE, which is the operating system that runs when you boot from the
40  * Windows Vista or Windows 7 DVD, is a lightweight version of Windows that can
41  * run entirely from memory. It can be used to install Windows from local media
42  * or a network drive or perform maintenance. 
43  * 
44  * You can find Windows PE on the installation media for Windows Vista, Windows
45  * 7, and Windows 8.  The Windows PE image itself is a WIM file, @c
46  * sources/boot.wim, on the ISO filesystem.  Windows PE can also be found in the
47  * Windows Automated Installation Kit (WAIK) inside the @c WinPE.cab file, which
48  * you can extract if you install the @c cabextract program.
49  *
50  * \section format WIM files
51  *
52  * A <b>Windows Imaging (WIM)</b> file is an archive.  Like some other archive
53  * formats such as ZIP, files in WIM archives may be compressed.  WIM archives
54  * support two Microsoft-specific compression formats:  @b LZX and @b XPRESS.
55  * Both are based on LZ77 and Huffman encoding, and both are supported by
56  * wimlib.
57  *
58  * Unlike ZIP files, WIM files can contain multiple independent toplevel
59  * directory trees known as @a images.  While each image has its own metadata,
60  * files are not duplicated for each image; instead, each file is included only
61  * once in the entire WIM. Microsoft did this so that in one WIM file, they
62  * could do things like have 5 different versions of Windows that are almost
63  * exactly the same.
64  *
65  * WIM files may contain a integrity table.  The integrity table, if it exists,
66  * is located at the end of the WIM file and contains SHA1 message digests of
67  * 10MB chunks of the WIM.
68  *
69  * Microsoft provides documentation for the WIM file format, XPRESS compression
70  * format, and LZX compression format.  However, there are errors and omissions
71  * in some places in their documentation.
72  *
73  * \section starting Getting Started
74  *
75  * wimlib uses the GNU autotools, so it should be easy to install with
76  * <code>configure && make && sudo make install</code>, provided that you have
77  * @c libxml2 and @c libfuse installed.  To use wimlib in a program after
78  * installing it, include @c wimlib.h and link your program with @c -lwim.
79  *
80  * wimlib wraps up a WIM file in an opaque ::WIMStruct structure.
81  *
82  * All functions in wimlib's public API are prefixed with @c wimlib.  Most
83  * return an integer error code on failure.  Use wimlib_get_error_string() to
84  * get a string that describes an error code.  wimlib also can print error
85  * messages itself when an error happens, and these may be more informative than
86  * the error code; to enable this, call wimlib_set_print_errors().
87  *
88  * wimlib is thread-safe as long as different ::WIMStruct's are used, with the
89  * following exceptions:  wimlib_set_print_errors() and
90  * wimlib_set_memory_allocator() apply globally, and wimlib_mount() can only be
91  * used by one ::WIMStruct at a time.
92  *
93  * To open an existing WIM, use wimlib_open_wim().
94  *
95  * To create a new WIM that initially contains no images, use
96  * wimlib_create_new_wim().
97  *
98  * To add an image to a WIM file from a directory tree on your filesystem, call
99  * wimlib_add_image().  This can be done with a ::WIMStruct gotten from
100  * wimlib_open_wim() or from wimlib_create_new_wim().
101  *
102  * To extract an image from a WIM file, call wimlib_set_output_dir() to set the
103  * output directory, then call wimlib_extract_image().
104  *
105  * wimlib supports mounting WIM files either read-only or read-write.  Mounting
106  * is done using wimlib_mount() and unmounting is done using wimlib_unmount().
107  * Mounting can be done without root privileges because it is implemented using
108  * FUSE (Filesystem in Userspace).  If wimlib is compiled with the
109  * <code>--without-fuse</code> flag, these functions will be available but will
110  * fail.
111  *
112  * After creating or modifying a WIM file, you can write it to a file using
113  * wimlib_write().  Alternatively,  if the WIM was originally read from a file,
114  * you can use wimlib_overwrite() to overwrite the original file.  In some
115  * cases, wimlib_overwrite_xml_and_header() can be used instead.
116  *
117  * After you are done with the WIM file, use wimlib_free() to free all memory
118  * associated with a ::WIMStruct and close all files associated with it.
119  *
120  * To see an example of how to use wimlib, see the file
121  * @c programs/imagex.c in wimlib's source tree.
122  *
123  * wimlib supports custom memory allocators; use wimlib_set_memory_allocator()
124  * for this.
125  *
126  * \section imagex imagex
127  *
128  * wimlib comes with the <b>imagex</b> program, which is documented in man pages.
129  *
130  * \section mkwinpeimg mkwinpeimg
131  * 
132  * wimlib comes with the <b>mkwinpeimg</b> script, which is documented in a man
133  * page.
134  *
135  * \section Limitations
136  *
137  * While wimlib supports the main features of WIM files, wimlib currently has
138  * the following limitations:
139  * - wimlib does not support modifying or creating "security data", which
140  *   describes the access rights of the files in the WIM.  This data is very
141  *   Windows-specific, and it would be difficult to do anything with it.
142  *   Microsoft's software can still read a WIM without security data, including
143  *   a boot.wim for Windows PE, but <b>do not expect to be able to use wimlib to
144  *   image a Windows installation and preserve file attributes</b>.  However, by
145  *   default, wimlib will preserve security data for existing WIMs.
146  * - There is no way to directly extract or mount split WIMs.
147  * - There is not yet any code to verify that there are no collisions between
148  *   different files that happen to have the same SHA1 message digest.
149  *   This is extremely unlikely, but could result in something bad such as a
150  *   file going missing.
151  * - Alternate stream entries for directory entries are ignored.
152  * - Different versions of the WIM file format, if they even exist, are
153  *   unsupported.  Let me know if you notice WIM files with a different version.
154  * - Chunk sizes other than 32768 are unsupported (except for uncompressed WIMs,
155  *   for which the chunk size field is ignored).  As far as I can tell, other
156  *   chunk sizes are not used in compressed WIMs.  Let me know if you find a WIM
157  *   file with a different chunk size.
158  * - wimlib does not provide a clone of the @b PEImg tool that allows you to
159  *   make certain Windows-specific modifications to a Windows PE image, such as
160  *   adding a driver or Windows component.  Such a tool could conceivably be
161  *   implemented on top of wimlib, although it likely would be hard to implement
162  *   because it would have to do very Windows-specific things such as
163  *   manipulating the driver store.  wimlib does provide the @b mkwinpeimg
164  *   script for a similar purpose, however.  With regards to adding drivers to
165  *   Windows PE, you have the option of putting them anywhere in the Windows PE
166  *   image, then loading them after boot using @b drvload.exe.
167  * - There is not yet a way to extract specific files or directories from a WIM
168  *   file without mounting it, or to add, remove, or modify files in a WIM
169  *   without mounting it, other than by adding or removing an entire image.  I
170  *   can implement this if requested, but I intend the FUSE mount feature to be
171  *   used for this purpose, as it is easy to do these things in whatever way you
172  *   want after the image is mounted.
173  *
174  * Currently, Microsoft's @a image.exe can create slightly smaller WIM files
175  * than wimlib when using maximum (LZX) compression because it knows how to
176  * split up LZX compressed blocks, which is not yet implemented in wimlib.
177  *
178  * wimlib is experimental and likely contains bugs; use Microsoft's @a
179  * imagex.exe if you want to make sure your WIM files are made "correctly".
180  *
181  * \section legal License
182  *
183  * The wimlib library is licensed under the GNU General Public License
184  * version 3 or later.
185  *
186  * @b imagex and @b mkwinpeiso are licensed under the GNU General Public License
187  * version 3 or later.
188  */
189
190 #ifndef _WIMLIB_H
191 #define _WIMLIB_H
192
193 #include <stdio.h>
194 #include <stddef.h>
195 #include <stdbool.h>
196
197 #ifndef _WIMLIB_INTERNAL_H
198 /** 
199  * Opaque structure that represents a WIM file. 
200  */
201 typedef struct WIMStruct WIMStruct;
202 #endif
203
204 /**
205  * Specifies the compression type of a WIM file.
206  */
207
208 enum wim_compression_type {
209         /** An invalid compression type. */
210         WIM_COMPRESSION_TYPE_INVALID = -1,
211
212         /** The WIM does not include any compressed resources. */
213         WIM_COMPRESSION_TYPE_NONE = 0,
214
215         /** Compressed resources in the WIM use LZX compression. */
216         WIM_COMPRESSION_TYPE_LZX = 1,
217
218         /** Compressed resources in the WIM use XPRESS compression. */
219         WIM_COMPRESSION_TYPE_XPRESS = 2,
220 };
221
222 /** Mount the WIM read-write. */
223 #define WIMLIB_MOUNT_FLAG_READWRITE             0x00000001
224
225 /** For debugging only. (This passes the @c -d flag to @c fuse_main()).*/
226 #define WIMLIB_MOUNT_FLAG_DEBUG                 0x00000002
227
228 /** Do not allow accessing alternate data streams. */
229 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE         0x00000010
230
231 /** Access alternate data streams through extended file attributes.  This is the
232  * default mode. */
233 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR        0x00000020
234
235 /** Access alternate data streams by specifying the file name, a colon, then the
236  * alternate file stream name. */
237 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS      0x00000040
238
239 /** Include an integrity table in the new WIM being written during the unmount. 
240  * Ignored for read-only mounts. */
241 #define WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY     0x00000001
242
243 /** Unless this flag is given, changes to a mounted WIM are discarded.  Ignored
244  * for read-only mounts. */
245 #define WIMLIB_UNMOUNT_FLAG_COMMIT              0x00000002
246
247 /** Include an integrity table in the new WIM file. */
248 #define WIMLIB_WRITE_FLAG_CHECK_INTEGRITY       0x00000001
249
250 /** Print progress information when writing the integrity table. */
251 #define WIMLIB_WRITE_FLAG_SHOW_PROGRESS         0x00000002
252
253 /** Print file paths as we write then */
254 #define WIMLIB_WRITE_FLAG_VERBOSE               0x00000004
255
256 /** Mark the image being added as the bootable image of the WIM. */
257 #define WIMLIB_ADD_IMAGE_FLAG_BOOT              0x00000001
258
259 /** Print the name of each file or directory as it is scanned to be included in
260  * the WIM image. */
261 #define WIMLIB_ADD_IMAGE_FLAG_VERBOSE           0x00000002
262
263 /** Follow symlinks; archive and dump the files they point to. */
264 #define WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE       0x00000004
265
266 /** See documentation for wimlib_export_image(). */
267 #define WIMLIB_EXPORT_FLAG_BOOT                 0x00000001
268
269 /** Verify the integrity of the WIM if an integrity table is present. */
270 #define WIMLIB_OPEN_FLAG_CHECK_INTEGRITY        0x00000001
271
272 /** Print progress information when verifying integrity table. */
273 #define WIMLIB_OPEN_FLAG_SHOW_PROGRESS          0x00000002
274
275 /** If this flag is not given, an error is issued if the WIM is part of a split
276  * WIM.  */
277 #define WIMLIB_OPEN_FLAG_SPLIT_OK               0x00000004
278
279
280 /** When identical files are extracted from the WIM, always hard link them
281  * together. */
282 #define WIMLIB_EXTRACT_FLAG_HARDLINK            0x00000001
283
284 /** When identical files are extracted from the WIM, always symlink them
285  * together. */
286 #define WIMLIB_EXTRACT_FLAG_SYMLINK             0x00000002
287
288 /** Print the name of each file as it is extracted from the WIM image. */
289 #define WIMLIB_EXTRACT_FLAG_VERBOSE             0x00000008
290
291 /**
292  * Possible values of the error code returned by many functions in wimlib.
293  *
294  * See the documentation for each wimlib function to see specifically what error
295  * codes can be returned by a given function, and what they mean.
296  */
297 enum wimlib_error_code {
298         WIMLIB_ERR_SUCCESS = 0,
299         WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE,
300         WIMLIB_ERR_DECOMPRESSION,
301         WIMLIB_ERR_DELETE_STAGING_DIR,
302         WIMLIB_ERR_FORK,
303         WIMLIB_ERR_FUSE,
304         WIMLIB_ERR_FUSERMOUNT,
305         WIMLIB_ERR_IMAGE_COUNT,
306         WIMLIB_ERR_IMAGE_NAME_COLLISION,
307         WIMLIB_ERR_INTEGRITY,
308         WIMLIB_ERR_INVALID_CAPTURE_CONFIG,
309         WIMLIB_ERR_INVALID_CHUNK_SIZE,
310         WIMLIB_ERR_INVALID_COMPRESSION_TYPE,
311         WIMLIB_ERR_INVALID_DENTRY,
312         WIMLIB_ERR_INVALID_HEADER_SIZE,
313         WIMLIB_ERR_INVALID_IMAGE,
314         WIMLIB_ERR_INVALID_INTEGRITY_TABLE,
315         WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY,
316         WIMLIB_ERR_INVALID_PARAM,
317         WIMLIB_ERR_INVALID_RESOURCE_HASH,
318         WIMLIB_ERR_INVALID_RESOURCE_SIZE,
319         WIMLIB_ERR_INVALID_SECURITY_DATA,
320         WIMLIB_ERR_LINK,
321         WIMLIB_ERR_MKDIR,
322         WIMLIB_ERR_MQUEUE,
323         WIMLIB_ERR_NOMEM,
324         WIMLIB_ERR_NOTDIR,
325         WIMLIB_ERR_NOT_A_WIM_FILE,
326         WIMLIB_ERR_NO_FILENAME,
327         WIMLIB_ERR_NTFS_3G,
328         WIMLIB_ERR_OPEN,
329         WIMLIB_ERR_OPENDIR,
330         WIMLIB_ERR_READLINK,
331         WIMLIB_ERR_READ,
332         WIMLIB_ERR_RENAME,
333         WIMLIB_ERR_SPECIAL_FILE,
334         WIMLIB_ERR_SPLIT_INVALID,
335         WIMLIB_ERR_SPLIT_UNSUPPORTED,
336         WIMLIB_ERR_STAT,
337         WIMLIB_ERR_TIMEOUT,
338         WIMLIB_ERR_UNKNOWN_VERSION,
339         WIMLIB_ERR_UNSUPPORTED,
340         WIMLIB_ERR_WRITE,
341         WIMLIB_ERR_XML,
342 };
343
344
345 /** Used to indicate that no WIM image is currently selected. */
346 #define WIM_NO_IMAGE    0
347
348 /** Used to specify all images in the WIM. */
349 #define WIM_ALL_IMAGES  (-1)
350
351
352 /**
353  * Adds an image to a WIM file from a directory tree on disk.
354  *
355  * The directory tree is read immediately for the purpose of constructing a
356  * directory entry tree in-memory.  Also, all files are read to calculate their
357  * SHA1 message digests.  However, because the directory tree may contain a very
358  * large amount of data, the files themselves are not read into memory
359  * permanently, and instead references to their paths saved.  This means that
360  * the directory tree must not be modified, other than by adding entirely new
361  * files or directories, before executing a call to wimlib_write() or
362  * wimlib_overwrite(). Otherwise, wimlib_write() may fail or incorrect files may
363  * be included in the WIM written by wimlib_write().
364  *
365  * @param wim
366  *      Pointer to the ::WIMStruct for a WIM file to which the image will be
367  *      added.
368  * @param dir
369  *      A path to a directory in the outside filesystem.  It will become the
370  *      root directory for the WIM image.
371  * @param name
372  *      The name to give the image.  This must be non-@c NULL.
373  * @param description
374  *      The description to give the image.  This parameter may be left @c
375  *      NULL, in which case no description is given to the image.
376  * @param flags_element
377  *      What to put in the &lt;FLAGS&gt; element for the image's XML data.  This
378  *      parameter may be left @c NULL, in which case no &lt;FLAGS&gt; element is
379  *      given to the image.
380  * @param flags
381  *      If set to ::WIMLIB_ADD_IMAGE_FLAG_BOOT, change the image in @a wim
382  *      marked as bootable to the one being added. Otherwise, leave the boot
383  *      index unchanged.
384  *
385  * @return 0 on success; nonzero on error.  On error, changes to @a wim are
386  * discarded so that it appears to be in the same state as when this function
387  * was called.
388  *
389  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION 
390  *      There is already an image named @a name in @a w.
391  * @retval ::WIMLIB_ERR_INVALID_PARAM 
392  *      @a dir was @c NULL, @a name was @c NULL, or @a name was the empty string.
393  * @retval ::WIMLIB_ERR_NOMEM
394  *      Failed to allocate needed memory.
395  * @retval ::WIMLIB_ERR_NOTDIR
396  *      @a dir is not a directory.
397  * @retval ::WIMLIB_ERR_OPEN
398  *      Failed to open a file or directory in the directory tree rooted at @a
399  *      dir.
400  * @retval ::WIMLIB_ERR_READ
401  *      Failed to read a file in the directory tree rooted at @a dir.
402  * @retval ::WIMLIB_ERR_STAT
403  *      Failed obtain the metadata for a file or directory in the directory tree
404  *      rooted at @a dir.
405  *
406  */
407 extern int wimlib_add_image(WIMStruct *wim, const char *dir, 
408                             const char *name, const char *config,
409                             size_t config_len, int flags);
410
411 extern int wimlib_add_image_from_ntfs_volume(WIMStruct *w, const char *device,
412                                              const char *name,
413                                              const char *config,
414                                              size_t config_len,
415                                              int flags);
416
417 extern int wimlib_apply_image_to_ntfs_volume(WIMStruct *w, int image,
418                                              const char *device, int flags);
419
420 /** 
421  * Creates a WIMStruct for a new WIM file.
422  *
423  * @param ctype 
424  *      The type of compression to be used in the new WIM file.  Must be
425  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX, or
426  *      ::WIM_COMPRESSION_TYPE_XPRESS.
427  * @param wim_ret
428  *      On success, a pointer to an opaque ::WIMStruct for the new WIM file is
429  *      written to the memory location pointed to by this paramater.  The
430  *      ::WIMStruct must be freed using using wimlib_free() when finished with
431  *      it.
432  * @return 0 on success; nonzero on error.
433  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
434  *      @a ctype was not ::WIM_COMPRESSION_TYPE_NONE,
435  *      ::WIM_COMPRESSION_TYPE_LZX, or ::WIM_COMPRESSION_TYPE_XPRESS.
436  * @retval ::WIMLIB_ERR_NOMEM
437  *      Failed to allocate needed memory.
438  */
439 extern int wimlib_create_new_wim(int ctype, WIMStruct **wim_ret);
440
441 /**
442  * Deletes an image, or all images, from a WIM file.
443  *
444  * All file resources referenced by the image(s) being deleted are removed from
445  * the WIM if they are not referenced by any other images in the WIM.
446  *
447  * @param wim
448  *      Pointer to the ::WIMStruct for the WIM file that contains the image(s)
449  *      being deleted.
450  * @param image
451  *      The number of the image to delete, or ::WIM_ALL_IMAGES to delete all
452  *      images.
453  * @return 0 on success; nonzero on error.  On error, @a wim is left in an
454  * indeterminate state and should be freed with wimlib_free().
455  * @retval ::WIMLIB_ERR_DECOMPRESSION
456  *      Could not decompress the metadata resource for @a image.
457  * @retval ::WIMLIB_ERR_INVALID_DENTRY
458  *      A directory entry in the metadata resource for @a image in the WIM is
459  *      invalid.
460  * @retval ::WIMLIB_ERR_INVALID_IMAGE
461  *      @a image does not exist in the WIM and is not ::WIM_ALL_IMAGES.
462  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
463  *      The metadata resource for @a image in the WIM is invalid.       
464  * @retval ::WIMLIB_ERR_NOMEM Failed to allocate needed memory.
465  * @retval ::WIMLIB_ERR_READ
466  *      Could not read the metadata resource for @a image from the WIM.
467  */
468 extern int wimlib_delete_image(WIMStruct *wim, int image);
469
470 /**
471  * Copies an image, or all the images, from a WIM file, into another WIM file.
472  *
473  * @param src_wim
474  *      Pointer to the ::WIMStruct for a WIM file that contains the image(s)
475  *      being exported.
476  * @param src_image
477  *      The image to export from @a src_wim.  Can be the number of an image, or
478  *      ::WIM_ALL_IMAGES to export all images.
479  * @param dest_wim
480  *      Pointer to the ::WIMStruct for a WIM filethat will receive the images being
481  *      exported.
482  * @param dest_name
483  *      The name to give the exported image in the new WIM file.  If left @c NULL,
484  *      the name from @a src_wim is used.  This parameter must be left @c NULL
485  *      if @a src_image is ::WIM_ALL_IMAGES and @a src_wim contains more than one
486  *      image; in that case, the names are all taken from the @a src_wim.
487  * @param dest_description
488  *      The description to give the exported image in the new WIM file.  If left
489  *      @c NULL, the description from the @a src_wim is used.  This parameter must
490  *      be left @c NULL if @a src_image is ::WIM_ALL_IMAGES and @a src_wim contains
491  *      more than one image; in that case, the descriptions are all taken from
492  *      @a src_wim.
493  * @param flags
494  *      ::WIMLIB_EXPORT_FLAG_BOOT if the image being exported is to be made
495  *      bootable, or 0 if which image is marked as bootable in the destination
496  *      WIM is to be left unchanged.  If @a src_image is ::WIM_ALL_IMAGES and
497  *      there are multiple images in @a src_wim, specifying
498  *      ::WIMLIB_EXPORT_FLAG_BOOT is valid only if one of the exported images is
499  *      currently marked as bootable in @a src_wim; if that is the case, then
500  *      that image is marked as bootable in the destination WIM.
501  *
502  * @return 0 on success; nonzero on error.  On error, @dest_wim is left in an
503  * indeterminate state and should be freed with wimlib_free().
504  * @retval ::WIMLIB_ERR_DECOMPRESSION
505  *      Could not decompress the metadata resource for @a src_image
506  *      in @a src_wim
507  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
508  *      One or more of the names being given to an exported image was already in
509  *      use in the destination WIM.
510  * @retval ::WIMLIB_ERR_INVALID_DENTRY 
511  *      A directory entry in the metadata resource for @a src_image in @a
512  *      src_wim is invalid.
513  * @retval ::WIMLIB_ERR_INVALID_IMAGE
514  *      @a src_image does not exist in @a src_wim.
515  * @retval ::WIMLIB_ERR_INVALID_PARAM
516  *      ::WIMLIB_EXPORT_FLAG_BOOT was specified in @a flags, @a src_image was
517  *      ::WIM_ALL_IMAGES, @a src_wim contains multiple images, and no images in
518  *      @a src_wim are marked as bootable; or @a dest_name and/or @a
519  *      dest_description were non-<code>NULL</code>, @a src_image was
520  *      ::WIM_ALL_IMAGES, and @a src_wim contains multiple images.
521  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
522  *      The metadata resource for @a src_image in @a src_wim is invalid.        
523  * @retval ::WIMLIB_ERR_NOMEM 
524  *      Failed to allocate needed memory.
525  * @retval ::WIMLIB_ERR_READ
526  *      Could not read the metadata resource for @a src_image from @a src_wim.
527  */
528 extern int wimlib_export_image(WIMStruct *src_wim, int src_image, 
529                                WIMStruct *dest_wim, const char *dest_name, 
530                                const char *dest_description, int flags);
531
532 /**
533  * Extracts an image, or all images, from a WIM file.
534  *
535  * The output directory must have been previously set with
536  * wimlib_set_output_dir().
537  *
538  * The link type used for extracted files is that specified by a previous call
539  * to wimlib_set_link_type(), or ::WIM_LINK_TYPE_NONE by default.
540  *
541  * @param wim
542  *      Pointer to the ::WIMStruct for a WIM file.
543  * @param image
544  *      The image to extract.  Can be the number of an image, or ::WIM_ALL_IMAGES
545  *      to specify that all images are to be extracted.
546  *
547  * @return 0 on success; nonzero on error.
548  * @retval ::WIMLIB_ERR_DECOMPRESSION
549  *      Could not decompress a resource (file or metadata) for @a image in @a
550  *      wim.
551  * @retval ::WIMLIB_ERR_INVALID_DENTRY 
552  *      A directory entry in the metadata resource for @a image in @a wim is
553  *      invalid.
554  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
555  *      A resource (file or metadata) for @a image in @a wim is invalid.        
556  * @retval ::WIMLIB_ERR_LINK
557  *      Failed to create a symbolic link or a hard link.
558  * @retval ::WIMLIB_ERR_MKDIR
559  *      Failed create a needed directory.
560  * @retval ::WIMLIB_ERR_NOMEM
561  *      Failed to allocate needed memory.
562  * @retval ::WIMLIB_ERR_NOTDIR
563  *      wimlib_set_output_dir() has not been successfully called on @a wim.
564  * @retval ::WIMLIB_ERR_OPEN
565  *      Could not open one of the files being extracted for writing.
566  * @retval ::WIMLIB_ERR_READ
567  *      A unexpected end-of-file or read error occurred when trying to read data
568  *      from the WIM file associated with @a wim.
569  * @retval ::WIMLIB_ERR_WRITE
570  *      Failed to write a file being extracted.
571  */
572 extern int wimlib_extract_image(WIMStruct *wim, int image,
573                                 const char *output_dir, int flags);
574
575 /**
576  * Extracts the XML data for a WIM file to a file stream.  Every WIM file
577  * includes a string of XML that describes the images contained in the WIM.
578  *
579  * @param wim
580  *      Pointer to the ::WIMStruct for a WIM file.
581  * @param fp 
582  *      @c stdout, or a FILE* opened for writing, to extract the data to.  
583  *
584  * @return 0 on success; nonzero on error.
585  * @retval ::WIMLIB_ERR_WRITE
586  *      Failed to completely write the XML data to @a fp.
587  */
588 extern int wimlib_extract_xml_data(WIMStruct *wim, FILE *fp);
589
590 /**
591  * Frees all memory allocated for a WIMStruct and closes all files associated
592  * with it. 
593  *
594  * @param wim
595  *      Pointer to the ::WIMStruct for a WIM file.
596  *
597  * @return This function has no return value.
598  */
599 extern void wimlib_free(WIMStruct *wim);
600
601 /**
602  * Finds which image in a WIM is bootable.
603  *
604  * @param wim
605  *      Pointer to the ::WIMStruct for a WIM file.
606  * 
607  * @return
608  *      0 if no image is marked as bootable, or the number of the image marked
609  *      as bootable (numbered starting at 1).
610  */
611 extern int wimlib_get_boot_idx(const WIMStruct *wim);
612
613 /**
614  * Gets the compression type used in the WIM.
615  *
616  * @param wim
617  *      Pointer to the ::WIMStruct for a WIM file
618  * 
619  * @return
620  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX, or
621  *      ::WIM_COMPRESSION_TYPE_XPRESS.
622  */
623 extern int wimlib_get_compression_type(const WIMStruct *wim);
624
625 /**
626  * Converts a compression type enumeration value into a string.
627  *
628  * @param ctype
629  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX,
630  *      ::WIM_COMPRESSION_TYPE_XPRESS, or another value.
631  *
632  * @return
633  *      A statically allocated string: "None", "LZX", "XPRESS", or "Invalid",
634  *      respectively.
635  */
636 extern const char *wimlib_get_compression_type_string(int ctype);
637
638 /**
639  * Converts an error code into a string describing it.
640  *
641  * @param code
642  *      The error code returned by one of wimlib's functions.
643  *
644  * @return
645  *      Pointer to a statically allocated string describing the error code,
646  *      or @c NULL if the error code is not valid.
647  */
648 extern const char *wimlib_get_error_string(enum wimlib_error_code code);
649
650 /**
651  * Returns the description of the specified image.
652  *
653  * @param wim
654  *      Pointer to the ::WIMStruct for a WIM file.
655  * @param image
656  *      The number of the image, numbered starting at 1.
657  *
658  * @return
659  *      The description of the image, or @c NULL if there is no such image, or @c NULL
660  *      if the specified image has no description.
661  */
662 extern const char *wimlib_get_image_description(const WIMStruct *wim, int image);
663
664 /**
665  * Returns the name of the specified image.
666  *
667  * @param wim
668  *      Pointer to the ::WIMStruct for a WIM file.
669  * @param image
670  *      The number of the image, numbered starting at 1.
671  *
672  * @return
673  *      The name of the image, or @c NULL if there is no such image.
674  */
675 extern const char *wimlib_get_image_name(const WIMStruct *wim, int image);
676
677
678 /**
679  * Gets the number of images contained in the WIM.
680  *
681  * @param wim
682  *      Pointer to the ::WIMStruct for a WIM file.
683  * 
684  * @return
685  *      The number of images contained in the WIM file.
686  */
687 extern int wimlib_get_num_images(const WIMStruct *wim);
688
689 /**
690  * Gets the part number of the wim (in a split WIM).
691  *
692  * @param wim
693  *      Pointer to the ::WIMStruct for a WIM file.
694  * @param total_parts_ret
695  *      If non-@c NULL, the total number of parts in the split WIM (1 for
696  *      non-split WIMs) is written to this location.
697  *
698  * @return 
699  *      The part number of the WIM (1 for non-split WIMs)
700  */
701 extern int wimlib_get_part_number(const WIMStruct *wim, int *total_parts_ret);
702
703 /**
704  * Returns true if the WIM has an integrity table.
705  *
706  * @param wim
707  *      Pointer to the ::WIMStruct for a WIM file.
708  * @return
709  *      @c true if the WIM has an integrity table; false otherwise.
710  */
711 extern bool wimlib_has_integrity_table(const WIMStruct *wim);
712
713
714 /**
715  * Determines if an image name is already used by some image in the WIM.
716  *
717  * @param wim
718  *      Pointer to the ::WIMStruct for a WIM file.
719  * @param name
720  *      The name to check.
721  *
722  * @return
723  *      @c true if there is already an image in @a wim named @a name; @c
724  *      false if there is no image named @a name in @a wim.
725  */
726 extern bool wimlib_image_name_in_use(const WIMStruct *wim, const char *name);
727
728 /**
729  * Joins a set of split WIMs into a one-part WIM.
730  *
731  * @param swms
732  *      An array of strings that give the filenames of all parts of the split
733  *      WIM.
734  * @param num_swms
735  *      Number of filenames in @a swms.
736  * @param output_path
737  *      The path to write the one-part WIM to.
738  * @param flags
739  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY to check the split WIMs' integrity
740  *      tables (if present) when opening them, and include an integrity table in
741  *      the output WIM.
742  *
743  * @return 0 on success; nonzero on error.  This function may return any value
744  * returned by wimlib_open_wim() except ::WIMLIB_ERR_SPLIT_UNSUPPORTED, as well
745  * as the following error codes:
746  *
747  * @retval ::WIMLIB_ERR_SPLIT_INVALID
748  *      The split WIMs do not form a valid WIM because they do not include all
749  *      the parts of the original WIM, there are duplicate parts, or not all the
750  *      parts have the same GUID and compression type.
751  * @retval ::WIMLIB_ERR_WRITE
752  *      An error occurred when trying to write data to the new WIM at @a output_path.
753  *
754  * Note that this function merely copies the resources, so it will not check to
755  * see if the resources, including the metadata resource, are valid or not.
756  */
757 extern int wimlib_join(const char **swms, int num_swms,
758                        const char *output_path, int flags);
759
760 /**
761  * Mounts an image in a WIM file on a directory read-only or read-write.
762  *
763  * A daemon will be forked to service the filesystem.
764  *
765  * If the mount is read-write, modifications to the WIM are staged in a staging
766  * directory.
767  *
768  * wimlib_mount() currently cannot be used with multiple ::WIMStruct's without
769  * intervening wimlib_unmount()s.  If there was a way to have libfuse pass a
770  * pointer to user data to each FUSE callback, then this would be possible, but
771  * there doesn't seem to be a way to do this currently.
772  *
773  * @param wim
774  *      Pointer to the ::WIMStruct for the WIM file to be mounted.
775  * @param image
776  *      The number of the image to mount, numbered from 1.  It must be an
777  *      existing, single image.
778  * @param dir
779  *      The path to an existing directory to mount the image on.
780  * @param flags
781  *      Bitwise OR of the flags ::WIMLIB_MOUNT_FLAG_READWRITE or
782  *      ::WIMLIB_MOUNT_FLAG_DEBUG.  If ::WIMLIB_MOUNT_FLAG_READWRITE is not
783  *      given, the WIM is mounted read-only.
784  *
785  * @return 0 on success; nonzero on error.
786  * @retval ::WIMLIB_ERR_DECOMPRESSION
787  *      Could not decompress the metadata resource for @a image in @a wim.
788  * @retval ::WIMLIB_ERR_FUSE
789  *      A non-zero status was returned by @c fuse_main().
790  * @retval ::WIMLIB_ERR_INVALID_DENTRY 
791  *      A directory entry in the metadata resource for @a image in @a wim is
792  *      invalid.
793  * @retval ::WIMLIB_ERR_INVALID_IMAGE
794  *      @a image does not specify an existing, single image in @a wim.
795  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
796  *      The metadata resource for @a image in @a wim is invalid.        
797  * @retval ::WIMLIB_ERR_MKDIR
798  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @a flags, but the staging
799  *      directory could not be created.
800  * @retval ::WIMLIB_ERR_NOMEM
801  *      Failed to allocate needed memory.
802  * @retval ::WIMLIB_ERR_NOTDIR
803  *      Could not determine the current working directory.
804  * @retval ::WIMLIB_ERR_READ
805  *      An unexpected end-of-file or read error occurred when trying to read
806  *      data from the WIM file associated with @a wim.
807  *
808  */
809 extern int wimlib_mount(WIMStruct *wim, int image, const char *dir, int flags);
810
811 /**
812  * Opens a WIM file and creates a ::WIMStruct for it.
813  *
814  * @param wim_file 
815  *      The path to the WIM file to open.
816  * @param flags
817  *      Bitwise OR of ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY and/or
818  *      ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS.
819  *      If ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY is given, the integrity table
820  *      of the WIM, if it exists, is checked, and the function will fail with an
821  *      ::WIMLIB_ERR_INTEGRITY status if any of the computed SHA1 message
822  *      digests of the WIM do not exactly match the corresponding message
823  *      digests given in the integrity table.
824  *      If ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS is given, progress information will
825  *      be shown if the integrity of the WIM is checked.
826  *      If ::WIMLIB_OPEN_FLAG_SPLIT_OK is given, no error will be issued if the
827  *      WIM is part of a split WIM.  However, wimlib does not fully support
828  *      split WIMs, so not all functions will work correctly after opening a
829  *      split WIM.  For example, you cannot use wimlib_mount() or
830  *      wimlib_extract_image() on a split WIM.
831  *
832  * @param wim_ret
833  *      On success, a pointer to an opaque ::WIMStruct for the opened WIM file
834  *      is written to the memory location pointed to by this parameter.  The
835  *      ::WIMStruct must be freed using using wimlib_free() when finished with
836  *      it.
837  *
838  * @return 0 on success; nonzero on error.
839  * @retval ::WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE
840  *      The lookup table of @a wim_file is compressed.  Support for this can be
841  *      added to wimlib if needed, but it appears to be the case that the lookup
842  *      table is never compressed.
843  * @retval ::WIMLIB_ERR_IMAGE_COUNT
844  *      The WIM is not the non-first part of a split WIM, and the number of
845  *      metadata resources found in the WIM did not match the image count given
846  *      in the WIM header, or the number of &lt;IMAGE&gt; elements in the XML
847  *      data for the WIM did not match the image count given in the WIM header.
848  * @retval ::WIMLIB_ERR_INTEGRITY
849  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @a flags and @a
850  *      wim_file contains an integrity table, but the SHA1 message digest for a
851  *      chunk of the WIM does not match the corresponding message digest given
852  *      in the integrity table.
853  * @retval ::WIMLIB_ERR_INVALID_CHUNK_SIZE
854  *      Resources in @a wim_file are compressed, but the chunk size is not 32768.
855  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
856  *      The header of @a wim_file says that resources in the WIM are compressed,
857  *      but the header flag indicating LZX or XPRESS compression is not set.
858  * @retval ::WIMLIB_ERR_INVALID_HEADER_SIZE
859  *      The length field of the WIM header is not 208.
860  * @retval ::WIMLIB_ERR_INVALID_INTEGRITY_TABLE
861  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @a flags and @a
862  *      wim_file contains an integrity table, but the integrity table is
863  *      invalid.
864  * @retval ::WIMLIB_ERR_NOMEM
865  *      Failed to allocated needed memory.
866  * @retval ::WIMLIB_ERR_NOT_A_WIM_FILE
867  *      @a wim_file does not begin with the expected magic characters.
868  * @retval ::WIMLIB_ERR_OPEN
869  *      Failed to open the file @a wim_file for reading.
870  * @retval ::WIMLIB_ERR_READ
871  *      An unexpected end-of-file or read error occurred when trying to read
872  *      data from @a wim_file.
873  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
874  *      @a wim_file is a split WIM, but ::WIMLIB_OPEN_FLAG_SPLIT_OK was not
875  *      givin in @a flags.
876  * @retval ::WIMLIB_ERR_UNKNOWN_VERSION
877  *      A number other than 0x10d00 is written in the version field of the WIM
878  *      header of @a wim_file.
879  * @retval ::WIMLIB_ERR_XML
880  *      The XML data for @a wim_file is invalid.
881  */
882 extern int wimlib_open_wim(const char *wim_file, int flags, 
883                            WIMStruct **wim_ret);
884
885 /**
886  * Overwrites the file that the WIM was originally read from, with changes made.
887  *
888  * The new WIM is written to a temporary file and then renamed to the original
889  * file after it is has been completely written.  The temporary file currently
890  * is made in the same directory as the original WIM file.
891  *
892  * Note that it is not possible for this function to delete the original file
893  * before having written the new file because it is very likely that file
894  * resources in the new WIM file need to be retrieved from the old WIM file.
895  *
896  * After this function returns, @a wim must be freed using wimlib_free().  Any
897  * further actions on @a wim before doing this are undefined.
898  *
899  * @param wim
900  *      Pointer to the ::WIMStruct for the WIM file to write.  There may have
901  *      been in-memory changes made to it, which are then reflected in the
902  *      output file.
903  * @param flags 
904  *      Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
905  *      ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.
906  *
907  * @return 0 on success; nonzero on error.  This function may return any value
908  * returned by wimlib_write() as well as the following error codes:
909  * @retval ::WIMLIB_ERR_NO_FILENAME
910  *      @a wim corresponds to a WIM created with wimlib_create_new_wim() rather
911  *      than a WIM read with wimlib_open_wim().
912  * @retval ::WIMLIB_ERR_RENAME
913  *      The temporary file that the WIM was written to could not be renamed to
914  *      the original filename of @a wim.
915  */
916 extern int wimlib_overwrite(WIMStruct *wim, int flags);
917
918 /**
919  * Updates the header and XML data of the WIM file, without the need to write
920  * out the entire WIM to a temporary file as in wimlib_write().
921  *
922  * This function must only be used if no files, directories, or images have been
923  * added, removed, or changed in the WIM.  It must be used when only the boot
924  * index or the name or description of image(s) has been changed.
925  *
926  * After this function returns, @a wim must be freed using wimlib_free().  Any
927  * further actions on @a wim before doing this are undefined.
928  *
929  * @param wim
930  *      Pointer to the ::WIMStruct for the WIM file to overwrite.
931  * @param flags 
932  *      Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
933  *      ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.
934  *
935  * @return 0 on success; nonzero on error.
936  *
937  * @retval ::WIMLIB_ERR_NO_FILENAME
938  *      @a wim corresponds to a WIM created with wimlib_create_new_wim() rather
939  *      than a WIM read with wimlib_open_wim().
940  * @retval ::WIMLIB_ERR_NOMEM
941  *      Failed to allocate needed memory.
942  * @retval ::WIMLIB_ERR_OPEN
943  *      The WIM file associated with @a wim could not be re-opened read-write.
944  * @retval ::WIMLIB_ERR_READ
945  *      ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY was specified in @a flags, but data
946  *      from the WIM file associated with @a wim could not be read to compute
947  *      the SHA1 message digests, or the old integrity table (if it existed)
948  *      could not be read.
949  * @retval ::WIMLIB_ERR_WRITE
950  *      Failed to write the WIM header, the XML data, or the integrity table to
951  *      the WIM file associated with @a wim.
952  */
953 extern int wimlib_overwrite_xml_and_header(WIMStruct *wim, int flags);
954
955 /**
956  * Prints information about one image, or all images, contained in a WIM.
957  *
958  * @param wim
959  *      Pointer to the ::WIMStruct for a WIM file.
960  * @param image 
961  *      The image about which to print information.  Can be the number of an
962  *      image, or ::WIM_ALL_IMAGES to print information about all images in the
963  *      WIM.
964  * 
965  * @return This function has no return value.
966  */
967 extern void wimlib_print_available_images(const WIMStruct *wim, int image);
968
969 /**
970  * Prints the full paths to all files contained in an image, or all images, in a
971  * WIM file.
972  *
973  * @param wim
974  *      Pointer to the ::WIMStruct for a WIM file.
975  * @param image 
976  *      Which image to print files for.  Can be the number of an image, or
977  *      ::WIM_ALL_IMAGES to print the files contained in all images.  
978  *
979  * @return 0 on success; nonzero on error.
980  * @retval ::WIMLIB_ERR_DECOMPRESSION
981  *      The metadata resource for one of the specified images could not be
982  *      decompressed.
983  * @retval ::WIMLIB_ERR_INVALID_DENTRY
984  *      A directory entry in the metadata resource for one of the specified
985  *      images is invaled.
986  * @retval ::WIMLIB_ERR_INVALID_IMAGE
987  *      @a image does not specify a valid image in @a wim, and is not
988  *      ::WIM_ALL_IMAGES.
989  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
990  *      The metadata resource for one of the specified images is invalid.
991  * @retval ::WIMLIB_ERR_NOMEM
992  *      Failed to allocate needed memory.
993  * @retval ::WIMLIB_ERR_READ
994  *      An unexpected read error or end-of-file occurred when reading the
995  *      metadata resource for one of the specified images.
996  */
997 extern int wimlib_print_files(WIMStruct *wim, int image);
998
999 /**
1000  * Prints detailed information from the header of a WIM file.
1001  *
1002  * @param wim
1003  *      Pointer to the ::WIMStruct for a WIM file.
1004  *
1005  * @return This function has no return value.
1006  *
1007  */
1008 extern void wimlib_print_header(const WIMStruct *wim);
1009
1010 /** 
1011  * Prints the lookup table of a WIM file.  The lookup table maps SHA1 message
1012  * digests, as found in the directory entry tree in the WIM file, to file
1013  * resources in the WIM file.  This table includes one entry for each unique
1014  * file in the WIM, so it can be quite long.  There is only one lookup table per
1015  * WIM.
1016  *
1017  * @param wim
1018  *      Pointer to the ::WIMStruct for a WIM file.
1019  *
1020  * @return This function has no return value.
1021  */
1022 extern void wimlib_print_lookup_table(WIMStruct *wim);
1023
1024 /**
1025  * Prints the metadata of the specified image in a WIM file.  The metadata
1026  * consists of the security data as well as the directory entry tree, and each
1027  * image has its own metadata.  
1028  *
1029  * @param wim
1030  *      Pointer to the ::WIMStruct for a WIM file.
1031  * @param image 
1032  *      Which image to print the metadata for.  Can be the number of an image,
1033  *      or ::WIM_ALL_IMAGES to print the metadata for all images in the WIM.
1034  *
1035  * @return 0 on success; nonzero on error.
1036  * @retval ::WIMLIB_ERR_DECOMPRESSION
1037  *      The metadata resource for one of the specified images could not be
1038  *      decompressed.
1039  * @retval ::WIMLIB_ERR_INVALID_DENTRY
1040  *      A directory entry in the metadata resource for one of the specified
1041  *      images is invaled.
1042  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1043  *      @a image does not specify a valid image in @a wim, and is not
1044  *      ::WIM_ALL_IMAGES.
1045  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1046  *      The metadata resource for one of the specified images is invalid.
1047  * @retval ::WIMLIB_ERR_NOMEM
1048  *      Failed to allocate needed memory.
1049  * @retval ::WIMLIB_ERR_READ
1050  *      An unexpected read error or end-of-file occurred when reading the
1051  *      metadata resource for one of the specified images.
1052  */
1053 extern int wimlib_print_metadata(WIMStruct *wim, int image);
1054
1055 /**
1056  * Prints some basic information about a WIM file.  All information printed by
1057  * this function is also printed by wimlib_print_header(), but
1058  * wimlib_print_wim_information() prints some of this information more concisely
1059  * and in a more readable form.
1060  *
1061  * @param wim
1062  *      Pointer to the ::WIMStruct for a WIM file.
1063  *
1064  * @return This function has no return value.  
1065  */
1066 extern void wimlib_print_wim_information(const WIMStruct *wim);
1067
1068 /**
1069  * Translates a string specifying the name or number of an image in the WIM into
1070  * the number of the image.  The images are numbered starting at 1.
1071  *
1072  * @param wim
1073  *      Pointer to the ::WIMStruct for a WIM file.
1074  * @param image_name_or_num  
1075  *      A string specifying which image.  If it begins with a number, it is
1076  *      taken to be a string specifying the image number.  Otherwise, it is
1077  *      taken to be the name of an image, as specified in the XML data for the
1078  *      WIM file.  It also may be the keyword "all", which will resolve to
1079  *      ::WIM_ALL_IMAGES.
1080  *
1081  * @return 
1082  *      If the string resolved to a single existing image, the number of that
1083  *      image, counting starting at 1, is returned.  If the keyword "all" was
1084  *      specified, ::WIM_ALL_IMAGES is returned.  Otherwise, ::WIM_NO_IMAGE is
1085  *      returned.
1086  */
1087 extern int wimlib_resolve_image(WIMStruct *wim, const char *image_name_or_num);
1088
1089 /**
1090  * Sets which image in the WIM is marked as bootable.
1091  *
1092  * @param wim
1093  *      Pointer to the ::WIMStruct for a WIM file.
1094  * @param boot_idx
1095  *      The number of the image to mark as bootable, or 0 to mark no image as
1096  *      bootable.
1097  * @return 0 on success; nonzero on error.
1098  * @retval ::WIMLIB_ERR_INVALID_IMAGE 
1099  *      @a boot_idx does not specify an existing image in @a wim, and it was not
1100  *      0.
1101  */
1102 extern int wimlib_set_boot_idx(WIMStruct *wim, int boot_idx);
1103
1104 /**
1105  * Changes the description of an image in the WIM.
1106  *
1107  * @param wim
1108  *      Pointer to the ::WIMStruct for a WIM file.
1109  * @param image
1110  *      The number of the image for which to change the description.
1111  * @param description
1112  *      The new description to give the image.  It may be @c NULL, which
1113  *      indicates that the image is to be given no description.
1114  *
1115  * @return 0 on success; nonzero on error.
1116  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1117  *      @a image does not specify a single existing image in @a wim.
1118  * @retval ::WIMLIB_ERR_NOMEM
1119  *      Failed to allocate the memory needed to duplicate the @a description
1120  *      string.
1121  */
1122 extern int wimlib_set_image_descripton(WIMStruct *wim, int image, 
1123                                        const char *description);
1124
1125 extern int wimlib_set_image_flags(WIMStruct *w, int image,
1126                                   const char *flags);
1127
1128 /**
1129  * Changes the name of an image in the WIM.
1130  *
1131  * @param wim
1132  *      Pointer to the ::WIMStruct for a WIM file.
1133  * @param image
1134  *      The number of the image for which to change the name.
1135  * @param name
1136  *      The new name to give the image.  It must not be @c NULL.
1137  *
1138  * @return 0 on success; nonzero on error.
1139  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
1140  *      There is already an image named @a name in @a wim.
1141  * @retval ::WIMLIB_ERR_INVALID_PARAM
1142  *      @a name was @c NULL or the empty string.
1143  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1144  *      @a image does not specify a single existing image in @a wim.
1145  * @retval ::WIMLIB_ERR_NOMEM
1146  *      Failed to allocate the memory needed to duplicate the @a name string.
1147  */
1148 extern int wimlib_set_image_name(WIMStruct *wim, int image, const char *name);
1149
1150 /**
1151  * Set the functions that wimlib uses to allocate and free memory.
1152  *
1153  * These settings are global and not per-WIM.
1154  *
1155  * The default is to use the default @c malloc() and @c free() from the C
1156  * library.
1157  *
1158  * @param malloc_func
1159  *      A function equivalent to @c malloc() that wimlib will use to allocate
1160  *      memory.  If @c NULL, the allocator function is set back to the default
1161  *      @c malloc() from the C library.
1162  * @param free_func
1163  *      A function equivalent to @c free() that wimlib will use to free memory.
1164  *      If @c NULL, the free function is set back to the default @c free() from
1165  *      the C library.
1166  * @param realloc_func
1167  *      A function equivalent to @c realloc() that wimlib will use to reallocate
1168  *      memory.  If @c NULL, the free function is set back to the default @c
1169  *      realloc() from the C library.
1170  * @return 0 on success; nonzero on error.
1171  * @retval ::WIMLIB_ERR_UNSUPPORTED
1172  *      wimlib was compiled with the @c --without-custom-memory-allocator flag,
1173  *      so custom memory allocators are unsupported.
1174  */
1175 int wimlib_set_memory_allocator(void *(*malloc_func)(size_t),
1176                                  void (*free_func)(void *),
1177                                  void *(*realloc_func)(void *, size_t));
1178
1179 /**
1180  * Sets whether wimlib is to print error messages to @c stderr when a function
1181  * fails or not.  These error messages may provide information that cannot be
1182  * determined only from the error code that is returned.
1183  *
1184  * This setting is global and not per-WIM.
1185  *
1186  * By default, error messages are not printed.
1187  *
1188  * @param show_messages
1189  *      @c true if error messages are to be printed; @c false if error messages
1190  *      are not to be printed.
1191  *
1192  * @return 0 on success; nonzero on error.
1193  * @retval ::WIMLIB_ERR_UNSUPPORTED
1194  *      @a show_messages was @c true, but wimlib was compiled with the @c
1195  *      --without-error-messages option.   Therefore, error messages cannot be
1196  *      shown.
1197  */
1198 extern int wimlib_set_print_errors(bool show_messages);
1199
1200 /**
1201  * Splits a WIM into multiple parts.
1202  *
1203  * @param wimfile
1204  *      Name of the WIM file to split.  It must be a standalone, one-part WIM.
1205  * @param swm_name
1206  *      Name of the SWM file to create.  This will be the name of the first
1207  *      part.  The other parts will have the same name with 2, 3, 4, ..., etc.
1208  *      appended.
1209  * @param part_size
1210  *      The maximum size per part.  It is not guaranteed that this will really
1211  *      be the maximum size per part, because some file resources in the WIM may
1212  *      be larger than this size, and the WIM file format provides no way to
1213  *      split up file resources among multiple WIMs.
1214  * @param flags
1215  *      Bitwise OR of ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY and/or
1216  *      ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS.
1217  *
1218  * @return 0 on success; nonzero on error.  This function may return any value
1219  * returned by wimlib_open_wim() as well as the following error codes:
1220  *
1221  * @retval ::WIMLIB_ERR_WRITE
1222  *      An error occurred when trying to write data to one of the split WIMs.
1223  *
1224  */
1225 extern int wimlib_split(const char *wimfile, const char *swm_name, 
1226                         size_t part_size, int flags);
1227
1228 /**
1229  * Unmounts a WIM image that was mounted using wimlib_mount().
1230  *
1231  * Blocks until it is known whether the mount succeeded or failed.
1232  *
1233  * To perform this operation, the process calling wimlib_unmount() communicates
1234  * with the process that had called wimlib_mount().
1235  *
1236  * There is currently a design problem with this function because it is hard to
1237  * know whether the filesystem daemon is still working or whether it has
1238  * crashed, has been killed, or has reached an infinite loop. However, ideally
1239  * there should be no infinite loops or crashes in the code, so this wouldn't be
1240  * much of a problem.  Currently, a timeout of 600 seconds (so long because WIMs
1241  * can be very large) is implemented so that this function will not wait forever
1242  * before returning failure.  
1243  *
1244  * @param dir
1245  *      The directory that the WIM image was mounted on.
1246  * @param flags
1247  *      Bitwise OR of the flags ::WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY or
1248  *      ::WIMLIB_UNMOUNT_FLAG_COMMIT.  Neither of these flags affect read-only
1249  *      mounts.
1250  *
1251  * @return 0 on success; nonzero on error.
1252  * @retval ::WIMLIB_ERR_DELETE_STAGING_DIR
1253  *      The filesystem daemon was unable to remove the staging directory and the
1254  *      temporary files that it contains.
1255  * @retval ::WIMLIB_ERR_FORK
1256  *      Could not @c fork() the process.
1257  * @retval ::WIMLIB_ERR_FUSERMOUNT
1258  *      The @b fusermount program could not be executed or exited with a failure
1259  *      status.
1260  * @retval ::WIMLIB_ERR_MQUEUE
1261  *      Could not open a POSIX message queue to communicate with the filesystem
1262  *      daemon servicing the mounted filesystem, could not send a message
1263  *      through the queue, or could not receive a message through the queue.
1264  * @retval ::WIMLIB_ERR_NOMEM
1265  *      Failed to allocate needed memory.
1266  * @retval ::WIMLIB_ERR_OPEN
1267  *      The filesystem daemon could not open a temporary file for writing the
1268  *      new WIM.
1269  * @retval ::WIMLIB_ERR_TIMEOUT
1270  *      600 seconds elapsed while waiting for the filesystem daemon to notify
1271  *      the process of its exit status, so the WIM file probably was not written
1272  *      successfully.
1273  * @retval ::WIMLIB_ERR_READ
1274  *      A read error occurred when the filesystem daemon tried to a file from
1275  *      the staging directory
1276  * @retval ::WIMLIB_ERR_RENAME
1277  *      The filesystem daemon failed to rename the newly written WIM file to the
1278  *      original WIM file.
1279  * @retval ::WIMLIB_ERR_WRITE
1280  *      A write error occurred when the filesystem daemon was writing to the new
1281  *      WIM file, or the filesystem daemon was unable to flush changes that had
1282  *      been made to files in the staging directory.
1283  */
1284 extern int wimlib_unmount(const char *dir, int flags);
1285
1286 /**
1287  * Writes the WIM to a file.
1288  *
1289  * @param wim
1290  *      Pointer to the ::WIMStruct for a WIM file.  There may have been
1291  *      in-memory changes made to it, which are then reflected in the output
1292  *      file.
1293  * @param path
1294  *      The path to the file to write the WIM to.
1295  * @param image
1296  *      The image inside the WIM to write.  Use ::WIM_ALL_IMAGES to include all
1297  *      images.
1298  * @param flags 
1299  *      Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
1300  *      ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.  If
1301  *      ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY is given, an integrity table is
1302  *      included in the WIM being written.  If ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS
1303  *      is given, the progress of the calculation of the integrity table is
1304  *      shown.
1305  *
1306  * @return 0 on success; nonzero on error.
1307  * @retval ::WIMLIB_ERR_DECOMPRESSION
1308  *      Failed to decompress a metadata or file resource in @a wim.
1309  * @retval ::WIMLIB_ERR_INVALID_DENTRY 
1310  *      A directory entry in the metadata resource for @a image in @a wim is
1311  *      invalid.
1312  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1313  *      @a image does not specify a single existing image in @a wim, and is not
1314  *      ::WIM_ALL_IMAGES.
1315  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1316  *      The metadata resource for @a image in @a wim is invalid.        
1317  * @retval ::WIMLIB_ERR_NOMEM
1318  *      Failed to allocate needed memory.
1319  * @retval ::WIMLIB_ERR_OPEN
1320  *      Failed to open @a path for writing, or some file resources in @a
1321  *      wim refer to files in the outside filesystem, and one of these files
1322  *      could not be opened for reading.
1323  * @retval ::WIMLIB_ERR_READ
1324  *      An error occurred when trying to read data from the WIM file associated
1325  *      with @a wim, or some file resources in @a wim refer to files in the
1326  *      outside filesystem, and a read error occurred when reading one of these
1327  *      files.
1328  * @retval ::WIMLIB_ERR_WRITE
1329  *      An error occurred when trying to write data to the new WIM file at @a
1330  *      path.
1331  */
1332 extern int wimlib_write(WIMStruct *wim, const char *path, int image, int flags);
1333
1334
1335
1336 #endif /* _WIMLIB_H */
1337