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