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