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