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