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