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