]> wimlib.net Git - wimlib/blob - src/wimlib.h
648345a5236bdd1655af4c16897485b1bc2776da
[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 General Public License as published by the Free
14  * Software Foundation; either version 3 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 General Public License for more
20  * details.
21  *
22  * You should have received a copy of the GNU 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  * \section format WIM files
38  *
39  * A <b>Windows Imaging (WIM)</b> file is an archive.  Like some other archive
40  * formats such as ZIP, files in WIM archives may be compressed.  WIM archives
41  * support two Microsoft-specific compression formats:  @b LZX and @b XPRESS.
42  * Both are based on LZ77 and Huffman encoding, and both are supported by
43  * wimlib.
44  *
45  * Unlike ZIP files, WIM files can contain multiple independent toplevel
46  * directory trees known as @a images.  While each image has its own metadata,
47  * files are not duplicated for each image; instead, each file is included only
48  * once in the entire WIM. Microsoft did this so that in one WIM file, they
49  * could do things like have 5 different versions of Windows that are almost
50  * exactly the same.
51  *
52  * Microsoft provides documentation for the WIM file format, XPRESS compression
53  * format, and LZX compression format.  The XPRESS documentation is acceptable,
54  * but the LZX documentation is not entirely correct, and the WIM documentation
55  * itself is very incomplete and is of unacceptable quality.
56  *
57  * A WIM file may be either stand-alone or split into multiple parts.
58  *
59  * \section winpe Windows PE
60  * 
61  * A major use for this library is to create customized images of Windows PE, the
62  * Windows Preinstallation Environment, without having to rely on Windows.  Windows
63  * PE is a lightweight version of Windows that can run entirely from memory and can
64  * be used to install Windows from local media or a network drive or perform
65  * maintenance.  Windows PE is the operating system that runs when you boot from
66  * the Windows installation media.
67  *
68  * You can find Windows PE on the installation DVD for Windows Vista, Windows 7,
69  * or Windows 8, in the file @c sources/boot.wim.  Windows PE can also be found
70  * in the Windows Automated Installation Kit (WAIK), which is free to download
71  * from Microsoft, inside the @c WinPE.cab file, which you can extract if you
72  * install either the @c cabextract or @c p7zip programs.
73  *
74  * In addition, Windows installations and recovery partitions frequently contain a
75  * WIM containing an image of the Windows Recovery Environment, which is similar to
76  * Windows PE.
77  *
78  * \section ntfs NTFS support
79  *
80  * As of version 1.0.0, wimlib supports capturing and applying images directly
81  * to NTFS volumes.  This was made possible with the help of libntfs-3g from the
82  * NTFS-3g project.  This feature supports capturing and restoring NTFS-specific
83  * data such as security descriptors, alternate data streams, and reparse point
84  * data.
85
86  * The code for NTFS image capture and image application is complete enough that
87  * it is possible to apply an image from the "install.wim" contained in recent
88  * Windows installation media (Vista, Windows 7, or Windows 8) directly to a
89  * NTFS volume, and then boot Windows from it after preparing the Boot
90  * Configuration Data.  In addition, a Windows installation can be captured (or
91  * backed up) into a WIM file, and then re-applied later.
92  *
93  * \section starting Getting Started
94  *
95  * wimlib uses the GNU autotools, so it should be easy to install with
96  * <code>configure && make && sudo make install</code>; however, please see the
97  * README for more information about installing it.  To use wimlib in a program
98  * after installing it, include @c wimlib.h and link your program with @c -lwim.
99  *
100  * wimlib wraps up a WIM file in an opaque ::WIMStruct structure.  A ::WIMStruct
101  * may represent either a stand-alone WIM or one part of a split WIM.
102  *
103  * All functions in wimlib's public API are prefixed with @c wimlib.  Most
104  * return an integer error code on failure.  Use wimlib_get_error_string() to
105  * get a string that describes an error code.  wimlib also can print error
106  * messages itself when an error happens, and these may be more informative than
107  * the error code; to enable this, call wimlib_set_print_errors().  Please note
108  * that this is for convenience only, and some errors can occur without a
109  * message being printed.
110  *
111  * wimlib is thread-safe as long as different ::WIMStruct's are used, with the
112  * following exceptions:  wimlib_set_print_errors() and
113  * wimlib_set_memory_allocator() apply globally, and wimlib_mount() can only be
114  * used by one ::WIMStruct at a time.
115  *
116  * To open an existing WIM, use wimlib_open_wim().
117  *
118  * To create a new WIM that initially contains no images, use
119  * wimlib_create_new_wim().
120  *
121  * To add an image to a WIM file from a directory tree on your filesystem, call
122  * wimlib_add_image().  This can be done with a ::WIMStruct gotten from
123  * wimlib_open_wim() or from wimlib_create_new_wim().  Alternatively, if you
124  * want to capture a WIM image directly from a NTFS volume while preserving
125  * NTFS-specific data such as security descriptors, call
126  * wimlib_add_image_from_ntfs_volume() instead.
127  *
128  * To extract an image from a WIM file, call wimlib_extract_image().
129  * Alternatively, if you want to apply a WIM image directly to a NTFS volume
130  * while setting NTFS-specific data such as security descriptors, call
131  * wimlib_apply_image_to_ntfs_volume().
132  *
133  * The NTFS functions will fail if wimlib was compiled with the
134  * <code>--without-ntfs-3g</code> flag.
135  *
136  * wimlib supports mounting WIM files either read-only or read-write.  Mounting
137  * is done using wimlib_mount() and unmounting is done using wimlib_unmount().
138  * Mounting can be done without root privileges because it is implemented using
139  * FUSE (Filesystem in Userspace).  If wimlib is compiled with the
140  * <code>--without-fuse</code> flag, these functions will be available but will
141  * fail.
142  *
143  * After creating or modifying a WIM file, you can write it to a file using
144  * wimlib_write().  Alternatively,  if the WIM was originally read from a file,
145  * you can use wimlib_overwrite() to overwrite the original file.  In some
146  * cases, wimlib_overwrite_xml_and_header() can be used instead.
147  *
148  * After you are done with the WIM file, use wimlib_free() to free all memory
149  * associated with a ::WIMStruct and close all files associated with it.
150  *
151  * To see an example of how to use wimlib, see the file
152  * @c programs/imagex.c in wimlib's source tree.
153  *
154  * wimlib supports custom memory allocators; use wimlib_set_memory_allocator()
155  * for this.  However, if wimlib calls into @c libntfs-3g, the custom memory
156  * allocator may not be used.
157  *
158  * \section imagex imagex
159  *
160  * wimlib comes with the <b>imagex</b> program, which is documented in man pages.
161  *
162  * \section mkwinpeimg mkwinpeimg
163  * 
164  * wimlib comes with the <b>mkwinpeimg</b> script, which is documented in a man
165  * page.
166  *
167  * \section Limitations
168  *
169  * While wimlib supports the main features of WIM files, wimlib currently has
170  * the following limitations:
171  * - Different versions of the WIM file format are unsupported.  There is one
172  *   different version of the format from development versions of Windows Vista,
173  *   but I'm not planning to support it.
174  * - Compressed resource chunk sizes other than 32768 are unsupported (except for
175  *   uncompressed WIMs, for which the chunk size field is ignored).  As far as I
176  *   can tell, other chunk sizes are not used in compressed WIMs.  Let me know
177  *   if you find a WIM file with a different chunk size.
178  * - wimlib does not provide a clone of the @b PEImg tool that allows you to
179  *   make certain Windows-specific modifications to a Windows PE image, such as
180  *   adding a driver or Windows component.  Such a tool could conceivably be
181  *   implemented on top of wimlib, although it likely would be hard to implement
182  *   because it would have to do very Windows-specific things such as
183  *   manipulating the driver store.  wimlib does provide the @b mkwinpeimg
184  *   script for a similar purpose, however.  With regards to adding drivers to
185  *   Windows PE, you have the option of putting them anywhere in the Windows PE
186  *   image, then loading them after boot using @b drvload.exe.
187  * - There is not yet a way to extract specific files or directories from a WIM
188  *   file without mounting it, or to add, remove, or modify files in a WIM
189  *   without mounting it, other than by adding or removing an entire image.  I
190  *   can implement this if requested, but I intend the FUSE mount feature to be
191  *   used for this purpose, as it is easy to do these things in whatever way you
192  *   want after the image is mounted.
193  * - Currently, Microsoft's @a image.exe can create slightly smaller WIM files
194  *   than wimlib when using maximum (LZX) compression because it knows how to
195  *   split up LZX compressed blocks, which is not yet implemented in wimlib.
196  * - wimlib is experimental and likely contains bugs; use Microsoft's @a
197  *   imagex.exe if you want to make sure your WIM files are made "correctly".
198  *
199  * \section legal License
200  *
201  * The wimlib library, as well as the programs and scripts distributed with it
202  * (@b imagex and @b mkwinpeimg), is licensed under the GNU General Public
203  * License version 3 or later.
204  */
205
206 #ifndef _WIMLIB_H
207 #define _WIMLIB_H
208
209 #include <stdio.h>
210 #include <stddef.h>
211 #include <stdbool.h>
212
213 #ifndef _WIMLIB_INTERNAL_H
214 /** 
215  * Opaque structure that represents a WIM file. 
216  */
217 typedef struct WIMStruct WIMStruct;
218 #endif
219
220 /**
221  * Specifies the compression type of a WIM file.
222  */
223
224 enum wim_compression_type {
225         /** An invalid compression type. */
226         WIM_COMPRESSION_TYPE_INVALID = -1,
227
228         /** The WIM does not include any compressed resources. */
229         WIM_COMPRESSION_TYPE_NONE = 0,
230
231         /** Compressed resources in the WIM use LZX compression. */
232         WIM_COMPRESSION_TYPE_LZX = 1,
233
234         /** Compressed resources in the WIM use XPRESS compression. */
235         WIM_COMPRESSION_TYPE_XPRESS = 2,
236 };
237
238 /** Mount the WIM read-write. */
239 #define WIMLIB_MOUNT_FLAG_READWRITE             0x00000001
240
241 /** For debugging only. (This passes the @c -d flag to @c fuse_main()).*/
242 #define WIMLIB_MOUNT_FLAG_DEBUG                 0x00000002
243
244 /** Do not allow accessing alternate data streams. */
245 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE         0x00000010
246
247 /** Access alternate data streams through extended file attributes.  This is the
248  * default mode. */
249 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR        0x00000020
250
251 /** Access alternate data streams by specifying the file name, a colon, then the
252  * alternate file stream name. */
253 #define WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS      0x00000040
254
255 /** Include an integrity table in the new WIM being written during the unmount. 
256  * Ignored for read-only mounts. */
257 #define WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY     0x00000001
258
259 /** Unless this flag is given, changes to a mounted WIM are discarded.  Ignored
260  * for read-only mounts. */
261 #define WIMLIB_UNMOUNT_FLAG_COMMIT              0x00000002
262
263 /** Include an integrity table in the new WIM file. */
264 #define WIMLIB_WRITE_FLAG_CHECK_INTEGRITY       0x00000001
265
266 /** Print progress information when writing the integrity table. */
267 #define WIMLIB_WRITE_FLAG_SHOW_PROGRESS         0x00000002
268
269 /** Print file paths as we write then */
270 #define WIMLIB_WRITE_FLAG_VERBOSE               0x00000004
271
272 /** Mark the image being added as the bootable image of the WIM. */
273 #define WIMLIB_ADD_IMAGE_FLAG_BOOT              0x00000001
274
275 /** Print the name of each file or directory as it is scanned to be included in
276  * the WIM image. */
277 #define WIMLIB_ADD_IMAGE_FLAG_VERBOSE           0x00000002
278
279 /** Follow symlinks; archive and dump the files they point to. */
280 #define WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE       0x00000004
281
282 /** See documentation for wimlib_export_image(). */
283 #define WIMLIB_EXPORT_FLAG_BOOT                 0x00000001
284
285 /** Verify the integrity of the WIM if an integrity table is present. */
286 #define WIMLIB_OPEN_FLAG_CHECK_INTEGRITY        0x00000001
287
288 /** Print progress information when verifying integrity table. */
289 #define WIMLIB_OPEN_FLAG_SHOW_PROGRESS          0x00000002
290
291 /** If this flag is not given, an error is issued if the WIM is part of a split
292  * WIM.  */
293 #define WIMLIB_OPEN_FLAG_SPLIT_OK               0x00000004
294
295
296 /** When identical files are extracted from the WIM, always hard link them
297  * together. */
298 #define WIMLIB_EXTRACT_FLAG_HARDLINK            0x00000001
299
300 /** When identical files are extracted from the WIM, always symlink them
301  * together. */
302 #define WIMLIB_EXTRACT_FLAG_SYMLINK             0x00000002
303
304 /** Print the name of each file as it is extracted from the WIM image. */
305 #define WIMLIB_EXTRACT_FLAG_VERBOSE             0x00000008
306
307 /**
308  * Possible values of the error code returned by many functions in wimlib.
309  *
310  * See the documentation for each wimlib function to see specifically what error
311  * codes can be returned by a given function, and what they mean.
312  */
313 enum wimlib_error_code {
314         WIMLIB_ERR_SUCCESS = 0,
315         WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE,
316         WIMLIB_ERR_DECOMPRESSION,
317         WIMLIB_ERR_DELETE_STAGING_DIR,
318         WIMLIB_ERR_FORK,
319         WIMLIB_ERR_FUSE,
320         WIMLIB_ERR_FUSERMOUNT,
321         WIMLIB_ERR_IMAGE_COUNT,
322         WIMLIB_ERR_IMAGE_NAME_COLLISION,
323         WIMLIB_ERR_INTEGRITY,
324         WIMLIB_ERR_INVALID_CAPTURE_CONFIG,
325         WIMLIB_ERR_INVALID_CHUNK_SIZE,
326         WIMLIB_ERR_INVALID_COMPRESSION_TYPE,
327         WIMLIB_ERR_INVALID_DENTRY,
328         WIMLIB_ERR_INVALID_HEADER_SIZE,
329         WIMLIB_ERR_INVALID_IMAGE,
330         WIMLIB_ERR_INVALID_INTEGRITY_TABLE,
331         WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY,
332         WIMLIB_ERR_INVALID_PARAM,
333         WIMLIB_ERR_INVALID_RESOURCE_HASH,
334         WIMLIB_ERR_INVALID_RESOURCE_SIZE,
335         WIMLIB_ERR_INVALID_SECURITY_DATA,
336         WIMLIB_ERR_LINK,
337         WIMLIB_ERR_MKDIR,
338         WIMLIB_ERR_MQUEUE,
339         WIMLIB_ERR_NOMEM,
340         WIMLIB_ERR_NOTDIR,
341         WIMLIB_ERR_NOT_A_WIM_FILE,
342         WIMLIB_ERR_NO_FILENAME,
343         WIMLIB_ERR_NTFS_3G,
344         WIMLIB_ERR_OPEN,
345         WIMLIB_ERR_OPENDIR,
346         WIMLIB_ERR_READLINK,
347         WIMLIB_ERR_READ,
348         WIMLIB_ERR_RENAME,
349         WIMLIB_ERR_SPECIAL_FILE,
350         WIMLIB_ERR_SPLIT_INVALID,
351         WIMLIB_ERR_SPLIT_UNSUPPORTED,
352         WIMLIB_ERR_STAT,
353         WIMLIB_ERR_TIMEOUT,
354         WIMLIB_ERR_UNKNOWN_VERSION,
355         WIMLIB_ERR_UNSUPPORTED,
356         WIMLIB_ERR_WRITE,
357         WIMLIB_ERR_XML,
358 };
359
360
361 /** Used to indicate that no WIM image is currently selected. */
362 #define WIM_NO_IMAGE    0
363
364 /** Used to specify all images in the WIM. */
365 #define WIM_ALL_IMAGES  (-1)
366
367
368 /**
369  * Adds an image to a WIM file from a directory tree on disk.
370  *
371  * The directory tree is read immediately for the purpose of constructing a
372  * directory entry tree in-memory.  Also, all files are read to calculate their
373  * SHA1 message digests.  However, because the directory tree may contain a very
374  * large amount of data, the files themselves are not read into memory
375  * permanently, and instead references to their paths saved.  The files are then
376  * read on-demand if wimlib_write() or wimlib_overwrite() is called.
377  *
378  * @param wim
379  *      Pointer to the ::WIMStruct for a WIM file to which the image will be
380  *      added.
381  * @param dir
382  *      A path to a directory in the outside filesystem.  It will become the
383  *      root directory for the WIM image.
384  * @param name
385  *      The name to give the image.  This must be non-@c NULL.
386  * @param config
387  *      Pointer to the contents of an image capture configuration file.  If @c
388  *      NULL, a default string is used.  Please see the manual page for
389  *      <b>imagex capture</b> for more information.
390  * @param config_len
391  *      Length of the string @a config in bytes.
392  *      
393  * @param flags
394  *      Bitwise OR of flags prefixed with WIMLIB_ADD_IMAGE_FLAG.  If
395  *      ::WIMLIB_ADD_IMAGE_FLAG_BOOT is specified, the image in @a wim that is
396  *      marked as bootable is changed to the one being added.  If
397  *      ::WIMLIB_ADD_IMAGE_FLAG_VERBOSE is specified, the name of each file is
398  *      printed as it is scanned or captured.  If
399  *      ::WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE is specified, the files or
400  *      directories pointed to by symbolic links are archived rather than the
401  *      symbolic links themselves.
402  *
403  * @return 0 on success; nonzero on error.  On error, changes to @a wim are
404  * discarded so that it appears to be in the same state as when this function
405  * was called.
406  *
407  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION 
408  *      There is already an image named @a name in @a w.
409  * @retval ::WIMLIB_ERR_INVALID_PARAM 
410  *      @a dir was @c NULL, @a name was @c NULL, or @a name was the empty string.
411  * @retval ::WIMLIB_ERR_NOMEM
412  *      Failed to allocate needed memory.
413  * @retval ::WIMLIB_ERR_NOTDIR
414  *      @a dir is not a directory.
415  * @retval ::WIMLIB_ERR_OPEN
416  *      Failed to open a file or directory in the directory tree rooted at @a
417  *      dir.
418  * @retval ::WIMLIB_ERR_READ
419  *      Failed to read a file in the directory tree rooted at @a dir.
420  * @retval ::WIMLIB_ERR_STAT
421  *      Failed obtain the metadata for a file or directory in the directory tree
422  *      rooted at @a dir.
423  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
424  *      @a wim is part of a split WIM.  Adding an image to a split WIM is
425  *      unsupported.
426  */
427 extern int wimlib_add_image(WIMStruct *wim, const char *dir, 
428                             const char *name, const char *config,
429                             size_t config_len, int flags);
430
431 /**
432  * This function is similar to wimlib_add_image(), except instead of capturing
433  * the WIM image from a directory, it is captured from a NTFS volume specified
434  * by @a device.  NTFS-3g errors are reported as ::WIMLIB_ERR_NTFS_3G.
435  * ::WIMLIB_ADD_IMAGE_FLAG_DEREFERENCE may not be specified because we capture
436  * the reparse points exactly as they are.
437  */
438 extern int wimlib_add_image_from_ntfs_volume(WIMStruct *wim, const char *device,
439                                              const char *name,
440                                              const char *config,
441                                              size_t config_len,
442                                              int flags);
443
444 /**
445  * This function is similar to wimlib_extract_image(), except that @a image may
446  * not be ::WIM_ALL_IMAGES, and @a device specifies the name of a file or block
447  * device containing a NTFS volume to apply the image to.  NTFS-3g errors are
448  * reported as ::WIMLIB_ERR_NTFS_3G, and ::WIMLIB_EXTRACT_FLAG_HARDLINK or
449  * ::WIMLIB_EXTRACT_FLAG_SYMLINK may not be specified because in the NTFS
450  * apply mode we apply the reparse points and hard links exactly as they are in
451  * the WIM.
452  */
453 extern int wimlib_apply_image_to_ntfs_volume(WIMStruct *wim, int image,
454                                              const char *device, int flags,
455                                              WIMStruct **additional_swms,
456                                              unsigned num_additional_swms);
457
458 /** 
459  * Creates a WIMStruct for a new WIM file.
460  *
461  * @param ctype 
462  *      The type of compression to be used in the new WIM file.  Must be
463  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX, or
464  *      ::WIM_COMPRESSION_TYPE_XPRESS.
465  * @param wim_ret
466  *      On success, a pointer to an opaque ::WIMStruct for the new WIM file is
467  *      written to the memory location pointed to by this paramater.  The
468  *      ::WIMStruct must be freed using using wimlib_free() when finished with
469  *      it.
470  * @return 0 on success; nonzero on error.
471  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
472  *      @a ctype was not ::WIM_COMPRESSION_TYPE_NONE,
473  *      ::WIM_COMPRESSION_TYPE_LZX, or ::WIM_COMPRESSION_TYPE_XPRESS.
474  * @retval ::WIMLIB_ERR_NOMEM
475  *      Failed to allocate needed memory.
476  */
477 extern int wimlib_create_new_wim(int ctype, WIMStruct **wim_ret);
478
479 /**
480  * Deletes an image, or all images, from a WIM file.
481  *
482  * All file resources referenced by the image(s) being deleted are removed from
483  * the WIM if they are not referenced by any other images in the WIM.
484  *
485  * @param wim
486  *      Pointer to the ::WIMStruct for the WIM file that contains the image(s)
487  *      being deleted.
488  * @param image
489  *      The number of the image to delete, or ::WIM_ALL_IMAGES to delete all
490  *      images.
491  * @return 0 on success; nonzero on error.  On error, @a wim is left in an
492  * indeterminate state and should be freed with wimlib_free().
493  * @retval ::WIMLIB_ERR_DECOMPRESSION
494  *      Could not decompress the metadata resource for @a image.
495  * @retval ::WIMLIB_ERR_INVALID_DENTRY
496  *      A directory entry in the metadata resource for @a image in the WIM is
497  *      invalid.
498  * @retval ::WIMLIB_ERR_INVALID_IMAGE
499  *      @a image does not exist in the WIM and is not ::WIM_ALL_IMAGES.
500  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
501  *      The metadata resource for @a image in the WIM is invalid.       
502  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
503  *      The security data for @a image in the WIM is invalid.   
504  * @retval ::WIMLIB_ERR_NOMEM Failed to allocate needed memory.
505  * @retval ::WIMLIB_ERR_READ
506  *      Could not read the metadata resource for @a image from the WIM.
507  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
508  *      @a wim is part of a split WIM.  Deleting an image from a split WIM is
509  *      unsupported.
510  */
511 extern int wimlib_delete_image(WIMStruct *wim, int image);
512
513 /**
514  * Copies an image, or all the images, from a WIM file, into another WIM file.
515  *
516  * @param src_wim
517  *      Pointer to the ::WIMStruct for a stand-alone WIM or part 1 of a split
518  *      WIM that contains the image(s) being exported.
519  * @param src_image
520  *      The image to export from @a src_wim.  Can be the number of an image, or
521  *      ::WIM_ALL_IMAGES to export all images.
522  * @param dest_wim
523  *      Pointer to the ::WIMStruct for a WIM file that will receive the images
524  *      being exported.
525  * @param dest_name
526  *      The name to give the exported image in the new WIM file.  If left @c NULL,
527  *      the name from @a src_wim is used.  This parameter must be left @c NULL
528  *      if @a src_image is ::WIM_ALL_IMAGES and @a src_wim contains more than one
529  *      image; in that case, the names are all taken from the @a src_wim.
530  * @param dest_description
531  *      The description to give the exported image in the new WIM file.  If left
532  *      @c NULL, the description from the @a src_wim is used.  This parameter must
533  *      be left @c NULL if @a src_image is ::WIM_ALL_IMAGES and @a src_wim contains
534  *      more than one image; in that case, the descriptions are all taken from
535  *      @a src_wim.
536  * @param flags
537  *      ::WIMLIB_EXPORT_FLAG_BOOT if the image being exported is to be made
538  *      bootable, or 0 if which image is marked as bootable in the destination
539  *      WIM is to be left unchanged.  If @a src_image is ::WIM_ALL_IMAGES and
540  *      there are multiple images in @a src_wim, specifying
541  *      ::WIMLIB_EXPORT_FLAG_BOOT is valid only if one of the exported images is
542  *      currently marked as bootable in @a src_wim; if that is the case, then
543  *      that image is marked as bootable in the destination WIM.
544  * @param additional_swms
545  *      Array of pointers to the ::WIMStruct for each additional part in the
546  *      split WIM.  Ignored if @a num_additional_swms is 0.  The pointers do not
547  *      need to be in any particular order, but they must include all parts of
548  *      the split WIM other than the first part, which must be provided in the
549  *      @a wim parameter.
550  * @param num_additional_swms
551  *      Number of additional WIM parts provided in the @a additional_swms array.
552  *      This number should be one less than the total number of parts in the
553  *      split WIM.  Set to 0 if the WIM is a standalone WIM.
554  *
555  * @return 0 on success; nonzero on error.  On error, @a dest_wim is left in an
556  * indeterminate state and should be freed with wimlib_free().
557  * @retval ::WIMLIB_ERR_DECOMPRESSION
558  *      Could not decompress the metadata resource for @a src_image
559  *      in @a src_wim
560  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
561  *      One or more of the names being given to an exported image was already in
562  *      use in the destination WIM.
563  * @retval ::WIMLIB_ERR_INVALID_DENTRY 
564  *      A directory entry in the metadata resource for @a src_image in @a
565  *      src_wim is invalid.
566  * @retval ::WIMLIB_ERR_INVALID_IMAGE
567  *      @a src_image does not exist in @a src_wim.
568  * @retval ::WIMLIB_ERR_INVALID_PARAM
569  *      ::WIMLIB_EXPORT_FLAG_BOOT was specified in @a flags, @a src_image was
570  *      ::WIM_ALL_IMAGES, @a src_wim contains multiple images, and no images in
571  *      @a src_wim are marked as bootable; or @a dest_name and/or @a
572  *      dest_description were non-<code>NULL</code>, @a src_image was
573  *      ::WIM_ALL_IMAGES, and @a src_wim contains multiple images; or @a src_wim
574  *      or @a dest_wim was @c NULL.
575  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
576  *      The metadata resource for @a src_image in @a src_wim is invalid.        
577  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
578  *      The security data for @a src_image in @a src_wim is invalid.    
579  * @retval ::WIMLIB_ERR_NOMEM 
580  *      Failed to allocate needed memory.
581  * @retval ::WIMLIB_ERR_READ
582  *      Could not read the metadata resource for @a src_image from @a src_wim.
583  * @retval ::WIMLIB_ERR_SPLIT_INVALID
584  *      The source WIM is a split WIM, but the parts specified do not form a
585  *      complete split WIM because they do not include all the parts of the
586  *      original WIM, there are duplicate parts, or not all the parts have the
587  *      same GUID and compression type.
588  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
589  *      @a dest_wim is part of a split WIM.  Exporting an image to a split WIM
590  *      is unsupported.
591  */
592 extern int wimlib_export_image(WIMStruct *src_wim, int src_image, 
593                                WIMStruct *dest_wim, const char *dest_name, 
594                                const char *dest_description, int flags,
595                                WIMStruct **additional_swms,
596                                unsigned num_additional_swms);
597
598 /**
599  * Extracts an image, or all images, from a standalone or split WIM file.
600  *
601  * @param wim
602  *      Pointer to the ::WIMStruct for a standalone WIM file, or part 1 of a
603  *      split WIM.
604  * @param image
605  *      The image to extract.  Can be the number of an image, or ::WIM_ALL_IMAGES
606  *      to specify that all images are to be extracted.
607  * @param output_dir
608  *      Directory to extract the WIM image(s) to.  It is created if it does not
609  *      already exist.
610  * @param flags
611  *      Bitwise or of the flags prefixed with WIMLIB_EXTRACT_FLAG.
612  *
613  *      One or none of ::WIMLIB_EXTRACT_FLAG_HARDLINK or
614  *      ::WIMLIB_EXTRACT_FLAG_SYMLINK may be specified.  These flags cause
615  *      extracted files that are identical to be hardlinked or symlinked
616  *      together, depending on the flag.  These flags override the hard link
617  *      groups that are specified in the WIM file itself.  If ::WIM_ALL_IMAGES
618  *      is provided as the @a image parameter, files may be hardlinked or
619  *      symlinked across images if a file is found to occur in more than one
620  *      image.
621  *
622  *      You may also specify the flag ::WIMLIB_EXTRACT_FLAG_VERBOSE to cause
623  *      informational messages to be printed during the extraction, including
624  *      the name of each extracted file or directory.
625  * @param additional_swms
626  *      Array of pointers to the ::WIMStruct for each additional part in the
627  *      split WIM.  Ignored if @a num_additional_swms is 0.  The pointers do not
628  *      need to be in any particular order, but they must include all parts of
629  *      the split WIM other than the first part, which must be provided in the
630  *      @a wim parameter.
631  * @param num_additional_swms
632  *      Number of additional WIM parts provided in the @a additional_swms array.
633  *      This number should be one less than the total number of parts in the
634  *      split WIM.  Set to 0 if the WIM is a standalone WIM.
635  *
636  * @return 0 on success; nonzero on error.
637  * @retval ::WIMLIB_ERR_DECOMPRESSION
638  *      Could not decompress a resource (file or metadata) for @a image in @a
639  *      wim.
640  * @retval ::WIMLIB_ERR_INVALID_DENTRY 
641  *      A directory entry in the metadata resource for @a image in @a wim is
642  *      invalid.
643  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
644  *      The SHA1 message digest of an extracted stream did not match the SHA1
645  *      message digest given in the WIM file.
646  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
647  *      A resource (file or metadata) for @a image in @a wim is invalid.        
648  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
649  *      The security data for @a image in @a wim is invalid.    
650  * @retval ::WIMLIB_ERR_LINK
651  *      Failed to create a symbolic link or a hard link.
652  * @retval ::WIMLIB_ERR_MKDIR
653  *      Failed create a needed directory.
654  * @retval ::WIMLIB_ERR_NOMEM
655  *      Failed to allocate needed memory.
656  * @retval ::WIMLIB_ERR_OPEN
657  *      Could not open one of the files being extracted for writing.
658  * @retval ::WIMLIB_ERR_READ
659  *      A unexpected end-of-file or read error occurred when trying to read data
660  *      from the WIM file associated with @a wim.
661  * @retval ::WIMLIB_ERR_SPLIT_INVALID
662  *      The WIM is a split WIM, but the parts specified do not form a complete
663  *      split WIM because they do not include all the parts of the original WIM,
664  *      there are duplicate parts, or not all the parts have the same GUID and
665  *      compression type.
666  * @retval ::WIMLIB_ERR_WRITE
667  *      Failed to write a file being extracted.
668  */
669 extern int wimlib_extract_image(WIMStruct *wim, int image,
670                                 const char *output_dir, int flags,
671                                 WIMStruct **additional_swms,
672                                 unsigned num_additional_swms);
673
674 /**
675  * Extracts the XML data for a WIM file to a file stream.  Every WIM file
676  * includes a string of XML that describes the images contained in the WIM.
677  * This function works on standalone WIMs as well as split WIM parts.
678  *
679  * @param wim
680  *      Pointer to the ::WIMStruct for a WIM file.
681  * @param fp 
682  *      @c stdout, or a FILE* opened for writing, to extract the data to.  
683  *
684  * @return 0 on success; nonzero on error.
685  * @retval ::WIMLIB_ERR_WRITE
686  *      Failed to completely write the XML data to @a fp.
687  */
688 extern int wimlib_extract_xml_data(WIMStruct *wim, FILE *fp);
689
690 /**
691  * Frees all memory allocated for a WIMStruct and closes all files associated
692  * with it. 
693  *
694  * @param wim
695  *      Pointer to the ::WIMStruct for a WIM file.
696  *
697  * @return This function has no return value.
698  */
699 extern void wimlib_free(WIMStruct *wim);
700
701 /**
702  * Finds which image in a WIM is bootable.
703  *
704  * @param wim
705  *      Pointer to the ::WIMStruct for a WIM file.
706  * 
707  * @return
708  *      0 if no image is marked as bootable, or the number of the image marked
709  *      as bootable (numbered starting at 1).
710  */
711 extern int wimlib_get_boot_idx(const WIMStruct *wim);
712
713 /**
714  * Gets the compression type used in the WIM.
715  *
716  * @param wim
717  *      Pointer to the ::WIMStruct for a WIM file
718  * 
719  * @return
720  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX, or
721  *      ::WIM_COMPRESSION_TYPE_XPRESS.
722  */
723 extern int wimlib_get_compression_type(const WIMStruct *wim);
724
725 /**
726  * Converts a compression type enumeration value into a string.
727  *
728  * @param ctype
729  *      ::WIM_COMPRESSION_TYPE_NONE, ::WIM_COMPRESSION_TYPE_LZX,
730  *      ::WIM_COMPRESSION_TYPE_XPRESS, or another value.
731  *
732  * @return
733  *      A statically allocated string: "None", "LZX", "XPRESS", or "Invalid",
734  *      respectively.
735  */
736 extern const char *wimlib_get_compression_type_string(int ctype);
737
738 /**
739  * Converts an error code into a string describing it.
740  *
741  * @param code
742  *      The error code returned by one of wimlib's functions.
743  *
744  * @return
745  *      Pointer to a statically allocated string describing the error code,
746  *      or @c NULL if the error code is not valid.
747  */
748 extern const char *wimlib_get_error_string(enum wimlib_error_code code);
749
750 /**
751  * Returns the description of the specified image.
752  *
753  * @param wim
754  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
755  *      standalone WIM or a split WIM part.
756  * @param image
757  *      The number of the image, numbered starting at 1.
758  *
759  * @return
760  *      The description of the image, or @c NULL if there is no such image, or @c NULL
761  *      if the specified image has no description.
762  */
763 extern const char *wimlib_get_image_description(const WIMStruct *wim, int image);
764
765 /**
766  * Returns the name of the specified image.
767  *
768  * @param wim
769  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
770  *      standalone WIM or a split WIM part.
771  * @param image
772  *      The number of the image, numbered starting at 1.
773  *
774  * @return
775  *      The name of the image, or @c NULL if there is no such image.
776  */
777 extern const char *wimlib_get_image_name(const WIMStruct *wim, int image);
778
779
780 /**
781  * Gets the number of images contained in the WIM.
782  *
783  * @param wim
784  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
785  *      standalone WIM or a split WIM part.
786  * 
787  * @return
788  *      The number of images contained in the WIM file.
789  */
790 extern int wimlib_get_num_images(const WIMStruct *wim);
791
792 /**
793  * Gets the part number of part of a split WIM.
794  *
795  * @param wim
796  *      Pointer to the ::WIMStruct for a WIM file.
797  * @param total_parts_ret
798  *      If non-@c NULL, the total number of parts in the split WIM (1 for
799  *      non-split WIMs) is written to this location.
800  *
801  * @return 
802  *      The part number of the WIM (1 for non-split WIMs)
803  */
804 extern int wimlib_get_part_number(const WIMStruct *wim, int *total_parts_ret);
805
806 /**
807  * Returns true if the WIM has an integrity table.
808  *
809  * @param wim
810  *      Pointer to the ::WIMStruct for a WIM file.
811  * @return
812  *      @c true if the WIM has an integrity table; @c false otherwise.
813  */
814 extern bool wimlib_has_integrity_table(const WIMStruct *wim);
815
816
817 /**
818  * Determines if an image name is already used by some image in the WIM.
819  *
820  * @param wim
821  *      Pointer to the ::WIMStruct for a WIM file.
822  * @param name
823  *      The name to check.
824  *
825  * @return
826  *      @c true if there is already an image in @a wim named @a name; @c
827  *      false if there is no image named @a name in @a wim.
828  */
829 extern bool wimlib_image_name_in_use(const WIMStruct *wim, const char *name);
830
831 /**
832  * Joins a set of split WIMs into a one-part WIM.
833  *
834  * @param swms
835  *      An array of strings that give the filenames of all parts of the split
836  *      WIM.
837  * @param num_swms
838  *      Number of filenames in @a swms.
839  * @param output_path
840  *      The path to write the one-part WIM to.
841  * @param flags
842  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY to check the split WIMs' integrity
843  *      tables (if present) when opening them, and include an integrity table in
844  *      the output WIM.
845  *
846  * @return 0 on success; nonzero on error.  This function may return any value
847  * returned by wimlib_open_wim() except ::WIMLIB_ERR_SPLIT_UNSUPPORTED, as well
848  * as the following error codes:
849  *
850  * @retval ::WIMLIB_ERR_SPLIT_INVALID
851  *      The split WIMs do not form a valid WIM because they do not include all
852  *      the parts of the original WIM, there are duplicate parts, or not all the
853  *      parts have the same GUID and compression type.
854  * @retval ::WIMLIB_ERR_WRITE
855  *      An error occurred when trying to write data to the new WIM at @a output_path.
856  *
857  * Note that this function merely copies the resources, so it will not check to
858  * see if the resources, including the metadata resource, are valid or not.
859  */
860 extern int wimlib_join(const char **swms, unsigned num_swms,
861                        const char *output_path, int flags);
862
863 /**
864  * Mounts an image in a WIM file on a directory read-only or read-write.
865  *
866  * A daemon will be forked to service the filesystem.
867  *
868  * If the mount is read-write, modifications to the WIM are staged in a staging
869  * directory.
870  *
871  * wimlib_mount() currently cannot be used with multiple ::WIMStruct's without
872  * intervening wimlib_unmount()s.  If there was a way to have libfuse pass a
873  * pointer to user data to each FUSE callback, then this would be possible, but
874  * there doesn't seem to be a way to do this currently.
875  *
876  * @param wim
877  *      Pointer to the ::WIMStruct for the WIM file to be mounted.
878  * @param image
879  *      The number of the image to mount, numbered from 1.  It must be an
880  *      existing, single image.
881  * @param dir
882  *      The path to an existing directory to mount the image on.
883  * @param flags
884  *      Bitwise OR of the flags prefixed with WIMLIB_MOUNT_FLAG.  If
885  *      ::WIMLIB_MOUNT_FLAG_READWRITE is not given, the WIM is mounted
886  *      read-only.  The interface to the WIM named data streams is specified by
887  *      exactly one of ::WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_NONE,
888  *      ::WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_XATTR, or
889  *      ::WIMLIB_MOUNT_FLAG_STREAM_INTERFACE_WINDOWS.  The default interface is
890  *      the XATTR interface.
891  * @param additional_swms
892  *      Array of pointers to the ::WIMStruct for each additional part in the
893  *      split WIM.  Ignored if @a num_additional_swms is 0.  The pointers do not
894  *      need to be in any particular order, but they must include all parts of
895  *      the split WIM other than the first part, which must be provided in the
896  *      @a wim parameter.
897  * @param num_additional_swms
898  *      Number of additional WIM parts provided in the @a additional_swms array.
899  *      This number should be one less than the total number of parts in the
900  *      split WIM.  Set to 0 if the WIM is a standalone WIM.
901  *
902  * @return 0 on success; nonzero on error.
903  * @retval ::WIMLIB_ERR_DECOMPRESSION
904  *      Could not decompress the metadata resource for @a image in @a wim.
905  * @retval ::WIMLIB_ERR_FUSE
906  *      A non-zero status was returned by @c fuse_main().
907  * @retval ::WIMLIB_ERR_INVALID_DENTRY 
908  *      A directory entry in the metadata resource for @a image in @a wim is
909  *      invalid.
910  * @retval ::WIMLIB_ERR_INVALID_IMAGE
911  *      @a image does not specify an existing, single image in @a wim.
912  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
913  *      The metadata resource for @a image in @a wim is invalid.        
914  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
915  *      The security data for @a image in @a wim is invalid.    
916  * @retval ::WIMLIB_ERR_MKDIR
917  *      ::WIMLIB_MOUNT_FLAG_READWRITE was specified in @a flags, but the staging
918  *      directory could not be created.
919  * @retval ::WIMLIB_ERR_NOMEM
920  *      Failed to allocate needed memory.
921  * @retval ::WIMLIB_ERR_NOTDIR
922  *      Could not determine the current working directory.
923  * @retval ::WIMLIB_ERR_READ
924  *      An unexpected end-of-file or read error occurred when trying to read
925  *      data from the WIM file associated with @a wim.
926  * @retval ::WIMLIB_ERR_SPLIT_INVALID
927  *      The WIM is a split WIM, but the parts specified do not form a complete
928  *      split WIM because they do not include all the parts of the original WIM,
929  *      there are duplicate parts, or not all the parts have the same GUID and
930  *      compression type.
931  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
932  *      The WIM is a split WIM and a read-write mount was requested.  We only
933  *      support mounting a split WIM read-only.
934  */
935 extern int wimlib_mount(WIMStruct *wim, int image, const char *dir, int flags,
936                         WIMStruct **additional_swms,
937                         unsigned num_additional_swms);
938
939 /**
940  * Opens a WIM file and creates a ::WIMStruct for it.
941  *
942  * @param wim_file 
943  *      The path to the WIM file to open.
944  * @param flags
945  *      Bitwise OR of ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY and/or
946  *      ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS.
947  *      If ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY is given, the integrity table
948  *      of the WIM, if it exists, is checked, and the function will fail with an
949  *      ::WIMLIB_ERR_INTEGRITY status if any of the computed SHA1 message
950  *      digests of the WIM do not exactly match the corresponding message
951  *      digests given in the integrity table.
952  *      If ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS is given, progress information will
953  *      be shown if the integrity of the WIM is checked.
954  *      If ::WIMLIB_OPEN_FLAG_SPLIT_OK is given, no error will be issued if the
955  *      WIM is part of a split WIM; otherwise WIMLIB_ERR_SPLIT_UNSUPPORTED is
956  *      returned.  (This flag may be removed in the future, in which case no
957  *      error will be issued when opening a split WIM.)
958  *
959  * @param wim_ret
960  *      On success, a pointer to an opaque ::WIMStruct for the opened WIM file
961  *      is written to the memory location pointed to by this parameter.  The
962  *      ::WIMStruct must be freed using using wimlib_free() when finished with
963  *      it.
964  *
965  * @return 0 on success; nonzero on error.
966  * @retval ::WIMLIB_ERR_COMPRESSED_LOOKUP_TABLE
967  *      The lookup table of @a wim_file is compressed.  Support for this can be
968  *      added to wimlib if needed, but it appears to be the case that the lookup
969  *      table is never compressed.
970  * @retval ::WIMLIB_ERR_IMAGE_COUNT
971  *      The WIM is not the non-first part of a split WIM, and the number of
972  *      metadata resources found in the WIM did not match the image count given
973  *      in the WIM header, or the number of &lt;IMAGE&gt; elements in the XML
974  *      data for the WIM did not match the image count given in the WIM header.
975  * @retval ::WIMLIB_ERR_INTEGRITY
976  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @a flags and @a
977  *      wim_file contains an integrity table, but the SHA1 message digest for a
978  *      chunk of the WIM does not match the corresponding message digest given
979  *      in the integrity table.
980  * @retval ::WIMLIB_ERR_INVALID_CHUNK_SIZE
981  *      Resources in @a wim_file are compressed, but the chunk size is not 32768.
982  * @retval ::WIMLIB_ERR_INVALID_COMPRESSION_TYPE
983  *      The header of @a wim_file says that resources in the WIM are compressed,
984  *      but the header flag indicating LZX or XPRESS compression is not set.
985  * @retval ::WIMLIB_ERR_INVALID_HEADER_SIZE
986  *      The length field of the WIM header is not 208.
987  * @retval ::WIMLIB_ERR_INVALID_INTEGRITY_TABLE
988  *      ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY was specified in @a flags and @a
989  *      wim_file contains an integrity table, but the integrity table is
990  *      invalid.
991  * @retval ::WIMLIB_ERR_INVALID_LOOKUP_TABLE_ENTRY
992  *      The lookup table for the WIM contained duplicate entries, or it
993  *      contained an entry with a SHA1 message digest of all 0's.
994  * @retval ::WIMLIB_ERR_NOMEM
995  *      Failed to allocated needed memory.
996  * @retval ::WIMLIB_ERR_NOT_A_WIM_FILE
997  *      @a wim_file does not begin with the expected magic characters.
998  * @retval ::WIMLIB_ERR_OPEN
999  *      Failed to open the file @a wim_file for reading.
1000  * @retval ::WIMLIB_ERR_READ
1001  *      An unexpected end-of-file or read error occurred when trying to read
1002  *      data from @a wim_file.
1003  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1004  *      @a wim_file is a split WIM, but ::WIMLIB_OPEN_FLAG_SPLIT_OK was not
1005  *      givin in @a flags.
1006  * @retval ::WIMLIB_ERR_UNKNOWN_VERSION
1007  *      A number other than 0x10d00 is written in the version field of the WIM
1008  *      header of @a wim_file.
1009  * @retval ::WIMLIB_ERR_XML
1010  *      The XML data for @a wim_file is invalid.
1011  */
1012 extern int wimlib_open_wim(const char *wim_file, int flags, 
1013                            WIMStruct **wim_ret);
1014
1015 /**
1016  * Overwrites the file that the WIM was originally read from, with changes made.
1017  *
1018  * The new WIM is written to a temporary file and then renamed to the original
1019  * file after it is has been completely written.  The temporary file currently
1020  * is made in the same directory as the original WIM file.
1021  *
1022  * After this function returns, @a wim must be freed using wimlib_free().  Any
1023  * further actions on @a wim before doing this are undefined.
1024  *
1025  * @param wim
1026  *      Pointer to the ::WIMStruct for the WIM file to write.  There may have
1027  *      been in-memory changes made to it, which are then reflected in the
1028  *      output file.
1029  * @param flags 
1030  *      Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
1031  *      ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.
1032  *
1033  * @return 0 on success; nonzero on error.  This function may return any value
1034  * returned by wimlib_write() as well as the following error codes:
1035  * @retval ::WIMLIB_ERR_NO_FILENAME
1036  *      @a wim corresponds to a WIM created with wimlib_create_new_wim() rather
1037  *      than a WIM read with wimlib_open_wim().
1038  * @retval ::WIMLIB_ERR_RENAME
1039  *      The temporary file that the WIM was written to could not be renamed to
1040  *      the original filename of @a wim.
1041  */
1042 extern int wimlib_overwrite(WIMStruct *wim, int flags);
1043
1044 /**
1045  * Updates the header and XML data of the WIM file, without the need to write
1046  * out the entire WIM to a temporary file as in wimlib_write().
1047  *
1048  * This function must only be used if no files, directories, or images have been
1049  * added, removed, or changed in the WIM.  It must be used when only the boot
1050  * index or the name or description of image(s) has been changed.
1051  *
1052  * After this function returns, @a wim must be freed using wimlib_free().  Any
1053  * further actions on @a wim before doing this are undefined.
1054  *
1055  * @param wim
1056  *      Pointer to the ::WIMStruct for the WIM file to overwrite.
1057  * @param flags 
1058  *      Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
1059  *      ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.
1060  *
1061  * @return 0 on success; nonzero on error.
1062  *
1063  * @retval ::WIMLIB_ERR_NO_FILENAME
1064  *      @a wim corresponds to a WIM created with wimlib_create_new_wim() rather
1065  *      than a WIM read with wimlib_open_wim().
1066  * @retval ::WIMLIB_ERR_NOMEM
1067  *      Failed to allocate needed memory.
1068  * @retval ::WIMLIB_ERR_OPEN
1069  *      The WIM file associated with @a wim could not be re-opened read-write.
1070  * @retval ::WIMLIB_ERR_READ
1071  *      ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY was specified in @a flags, but data
1072  *      from the WIM file associated with @a wim could not be read to compute
1073  *      the SHA1 message digests, or the old integrity table (if it existed)
1074  *      could not be read.
1075  * @retval ::WIMLIB_ERR_WRITE
1076  *      Failed to write the WIM header, the XML data, or the integrity table to
1077  *      the WIM file associated with @a wim.
1078  */
1079 extern int wimlib_overwrite_xml_and_header(WIMStruct *wim, int flags);
1080
1081 /**
1082  * Prints information about one image, or all images, contained in a WIM.
1083  *
1084  * @param wim
1085  *      Pointer to the ::WIMStruct for a WIM file.
1086  * @param image 
1087  *      The image about which to print information.  Can be the number of an
1088  *      image, or ::WIM_ALL_IMAGES to print information about all images in the
1089  *      WIM.
1090  * 
1091  * @return This function has no return value.
1092  */
1093 extern void wimlib_print_available_images(const WIMStruct *wim, int image);
1094
1095 /**
1096  * Prints the full paths to all files contained in an image, or all images, in a
1097  * WIM file.
1098  *
1099  * @param wim
1100  *      Pointer to the ::WIMStruct for a WIM file.
1101  * @param image 
1102  *      Which image to print files for.  Can be the number of an image, or
1103  *      ::WIM_ALL_IMAGES to print the files contained in all images.  
1104  *
1105  * @return 0 on success; nonzero on error.
1106  * @retval ::WIMLIB_ERR_DECOMPRESSION
1107  *      The metadata resource for one of the specified images could not be
1108  *      decompressed.
1109  * @retval ::WIMLIB_ERR_INVALID_DENTRY
1110  *      A directory entry in the metadata resource for one of the specified
1111  *      images is invaled.
1112  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1113  *      @a image does not specify a valid image in @a wim, and is not
1114  *      ::WIM_ALL_IMAGES.
1115  * @retval ::WIMLIB_ERR_INVALID_PARAM
1116  *      @a wim was @c NULL.
1117  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1118  *      The metadata resource for one of the specified images is invalid.
1119  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
1120  *      The security data for one of the specified images is invalid.
1121  * @retval ::WIMLIB_ERR_NOMEM
1122  *      Failed to allocate needed memory.
1123  * @retval ::WIMLIB_ERR_READ
1124  *      An unexpected read error or end-of-file occurred when reading the
1125  *      metadata resource for one of the specified images.
1126  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1127  *      @a wim was not a standalone WIM and was not the first part of a split
1128  *      WIM.
1129  */
1130 extern int wimlib_print_files(WIMStruct *wim, int image);
1131
1132 /**
1133  * Prints detailed information from the header of a WIM file.
1134  *
1135  * @param wim
1136  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
1137  *      standalone WIM or part of a split WIM.
1138  *
1139  * @return This function has no return value.
1140  *
1141  */
1142 extern void wimlib_print_header(const WIMStruct *wim);
1143
1144 /** 
1145  * Prints the lookup table of a WIM file.  The lookup table maps SHA1 message
1146  * digests, as found in the directory entry tree in the WIM file, to file
1147  * resources in the WIM file.  This table includes one entry for each unique
1148  * file in the WIM, so it can be quite long.  There is only one lookup table per
1149  * WIM.
1150  *
1151  * @param wim
1152  *      Pointer to the ::WIMStruct for a WIM file.
1153  *
1154  * @return This function has no return value.
1155  */
1156 extern void wimlib_print_lookup_table(WIMStruct *wim);
1157
1158 /**
1159  * Prints the metadata of the specified image in a WIM file.  The metadata
1160  * consists of the security data as well as the directory entry tree, and each
1161  * image has its own metadata.  
1162  *
1163  * @param wim
1164  *      Pointer to the ::WIMStruct for a WIM file.
1165  * @param image 
1166  *      Which image to print the metadata for.  Can be the number of an image,
1167  *      or ::WIM_ALL_IMAGES to print the metadata for all images in the WIM.
1168  *
1169  * @return 0 on success; nonzero on error.
1170  * @retval ::WIMLIB_ERR_DECOMPRESSION
1171  *      The metadata resource for one of the specified images could not be
1172  *      decompressed.
1173  * @retval ::WIMLIB_ERR_INVALID_DENTRY
1174  *      A directory entry in the metadata resource for one of the specified
1175  *      images is invaled.
1176  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1177  *      @a image does not specify a valid image in @a wim, and is not
1178  *      ::WIM_ALL_IMAGES.
1179  * @retval ::WIMLIB_ERR_INVALID_PARAM
1180  *      @a wim was @c NULL.
1181  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1182  *      The metadata resource for one of the specified images is invalid.
1183  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
1184  *      The security data for one of the specified images is invalid.
1185  * @retval ::WIMLIB_ERR_NOMEM
1186  *      Failed to allocate needed memory.
1187  * @retval ::WIMLIB_ERR_READ
1188  *      An unexpected read error or end-of-file occurred when reading the
1189  *      metadata resource for one of the specified images.
1190  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1191  *      @a wim was not a standalone WIM and was not the first part of a split
1192  *      WIM.
1193  */
1194 extern int wimlib_print_metadata(WIMStruct *wim, int image);
1195
1196 /**
1197  * Prints some basic information about a WIM file.  All information printed by
1198  * this function is also printed by wimlib_print_header(), but
1199  * wimlib_print_wim_information() prints some of this information more concisely
1200  * and in a more readable form.
1201  *
1202  * @param wim
1203  *      Pointer to the ::WIMStruct for a WIM file.
1204  *
1205  * @return This function has no return value.  
1206  */
1207 extern void wimlib_print_wim_information(const WIMStruct *wim);
1208
1209 /**
1210  * Translates a string specifying the name or number of an image in the WIM into
1211  * the number of the image.  The images are numbered starting at 1.
1212  *
1213  * @param wim
1214  *      Pointer to the ::WIMStruct for a WIM file.
1215  * @param image_name_or_num  
1216  *      A string specifying which image.  If it begins with a number, it is
1217  *      taken to be a string specifying the image number.  Otherwise, it is
1218  *      taken to be the name of an image, as specified in the XML data for the
1219  *      WIM file.  It also may be the keyword "all", which will resolve to
1220  *      ::WIM_ALL_IMAGES.
1221  *
1222  * @return 
1223  *      If the string resolved to a single existing image, the number of that
1224  *      image, counting starting at 1, is returned.  If the keyword "all" was
1225  *      specified, ::WIM_ALL_IMAGES is returned.  Otherwise, ::WIM_NO_IMAGE is
1226  *      returned.
1227  */
1228 extern int wimlib_resolve_image(WIMStruct *wim, const char *image_name_or_num);
1229
1230 /**
1231  * Sets which image in the WIM is marked as bootable.
1232  *
1233  * @param wim
1234  *      Pointer to the ::WIMStruct for a WIM file.
1235  * @param boot_idx
1236  *      The number of the image to mark as bootable, or 0 to mark no image as
1237  *      bootable.
1238  * @return 0 on success; nonzero on error.
1239  * @retval ::WIMLIB_ERR_INVALID_PARAM
1240  *      @a wim was @c NULL.
1241  * @retval ::WIMLIB_ERR_INVALID_IMAGE 
1242  *      @a boot_idx does not specify an existing image in @a wim, and it was not
1243  *      0.
1244  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1245  *      @a wim is part of a split WIM.  We do not support changing the boot
1246  *      index of a split WIM.
1247  */
1248 extern int wimlib_set_boot_idx(WIMStruct *wim, int boot_idx);
1249
1250 /**
1251  * Changes the description of an image in the WIM.
1252  *
1253  * @param wim
1254  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
1255  *      standalone WIM or part of a split WIM; however, you should set the same
1256  *      description on all parts of a split WIM.
1257  * @param image
1258  *      The number of the image for which to change the description.
1259  * @param description
1260  *      The new description to give the image.  It may be @c NULL, which
1261  *      indicates that the image is to be given no description.
1262  *
1263  * @return 0 on success; nonzero on error.
1264  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1265  *      @a image does not specify a single existing image in @a wim.
1266  * @retval ::WIMLIB_ERR_INVALID_PARAM
1267  *      @a wim was @c NULL.
1268  * @retval ::WIMLIB_ERR_NOMEM
1269  *      Failed to allocate the memory needed to duplicate the @a description
1270  *      string.
1271  */
1272 extern int wimlib_set_image_descripton(WIMStruct *wim, int image, 
1273                                        const char *description);
1274
1275 /**
1276  * Changes what is written in the \<FLAGS\> element in the WIM XML data
1277  * (something like "Core" or "Ultimate")
1278  *
1279  * @param wim
1280  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
1281  *      standalone WIM or part of a split WIM; however, you should set the same
1282  *      \<FLAGS\> element on all parts of a split WIM.
1283  * @param image
1284  *      The number of the image for which to change the description.
1285  * @param flags
1286  *      The new \<FLAGS\> element to give the image.  It may be @c NULL, which
1287  *      indicates that the image is to be given no \<FLAGS\> element.
1288  *
1289  * @return 0 on success; nonzero on error.
1290  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1291  *      @a image does not specify a single existing image in @a wim.
1292  * @retval ::WIMLIB_ERR_INVALID_PARAM
1293  *      @a wim was @c NULL.
1294  * @retval ::WIMLIB_ERR_NOMEM
1295  *      Failed to allocate the memory needed to duplicate the @a flags string.
1296  */
1297 extern int wimlib_set_image_flags(WIMStruct *wim, int image, const char *flags);
1298
1299 /**
1300  * Changes the name of an image in the WIM.
1301  *
1302  * @param wim
1303  *      Pointer to the ::WIMStruct for a WIM file.  It may be either a
1304  *      standalone WIM or part of a split WIM; however, you should set the same
1305  *      name on all parts of a split WIM.
1306  * @param image
1307  *      The number of the image for which to change the name.
1308  * @param name
1309  *      The new name to give the image.  It must not a nonempty string.
1310  *
1311  * @return 0 on success; nonzero on error.
1312  * @retval ::WIMLIB_ERR_IMAGE_NAME_COLLISION
1313  *      There is already an image named @a name in @a wim.
1314  * @retval ::WIMLIB_ERR_INVALID_PARAM
1315  *      @a name was @c NULL or the empty string, or @a wim was @c NULL.
1316  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1317  *      @a image does not specify a single existing image in @a wim.
1318  * @retval ::WIMLIB_ERR_NOMEM
1319  *      Failed to allocate the memory needed to duplicate the @a name string.
1320  */
1321 extern int wimlib_set_image_name(WIMStruct *wim, int image, const char *name);
1322
1323 /**
1324  * Set the functions that wimlib uses to allocate and free memory.
1325  *
1326  * These settings are global and not per-WIM.
1327  *
1328  * The default is to use the default @c malloc() and @c free() from the C
1329  * library.
1330  *
1331  * Please note that some external functions we call still may use the standard
1332  * memory allocation functions.
1333  *
1334  * @param malloc_func
1335  *      A function equivalent to @c malloc() that wimlib will use to allocate
1336  *      memory.  If @c NULL, the allocator function is set back to the default
1337  *      @c malloc() from the C library.
1338  * @param free_func
1339  *      A function equivalent to @c free() that wimlib will use to free memory.
1340  *      If @c NULL, the free function is set back to the default @c free() from
1341  *      the C library.
1342  * @param realloc_func
1343  *      A function equivalent to @c realloc() that wimlib will use to reallocate
1344  *      memory.  If @c NULL, the free function is set back to the default @c
1345  *      realloc() from the C library.
1346  * @return 0 on success; nonzero on error.
1347  * @retval ::WIMLIB_ERR_UNSUPPORTED
1348  *      wimlib was compiled with the @c --without-custom-memory-allocator flag,
1349  *      so custom memory allocators are unsupported.
1350  */
1351 int wimlib_set_memory_allocator(void *(*malloc_func)(size_t),
1352                                  void (*free_func)(void *),
1353                                  void *(*realloc_func)(void *, size_t));
1354
1355 /**
1356  * Sets whether wimlib is to print error messages to @c stderr when a function
1357  * fails.  These error messages may provide information that cannot be
1358  * determined only from the error code that is returned.  Not every error will
1359  * result in an error message being printed.
1360  *
1361  * This setting is global and not per-WIM.
1362  *
1363  * By default, error messages are not printed.
1364  *
1365  * @param show_messages
1366  *      @c true if error messages are to be printed; @c false if error messages
1367  *      are not to be printed.
1368  *
1369  * @return 0 on success; nonzero on error.
1370  * @retval ::WIMLIB_ERR_UNSUPPORTED
1371  *      @a show_messages was @c true, but wimlib was compiled with the @c
1372  *      --without-error-messages option.   Therefore, error messages cannot be
1373  *      shown.
1374  */
1375 extern int wimlib_set_print_errors(bool show_messages);
1376
1377 /**
1378  * Splits a WIM into multiple parts.
1379  *
1380  * @param wimfile
1381  *      Name of the WIM file to split.  It must be a standalone, one-part WIM.
1382  * @param swm_name
1383  *      Name of the SWM file to create.  This will be the name of the first
1384  *      part.  The other parts will have the same name with 2, 3, 4, ..., etc.
1385  *      appended.
1386  * @param part_size
1387  *      The maximum size per part, in bytes.  It is not guaranteed that this
1388  *      will really be the maximum size per part, because some file resources in
1389  *      the WIM may be larger than this size, and the WIM file format provides
1390  *      no way to split up file resources among multiple WIMs.
1391  * @param flags
1392  *      Bitwise OR of ::WIMLIB_OPEN_FLAG_CHECK_INTEGRITY and/or
1393  *      ::WIMLIB_OPEN_FLAG_SHOW_PROGRESS.
1394  *
1395  * @return 0 on success; nonzero on error.  This function may return any value
1396  * returned by wimlib_open_wim() as well as the following error codes:
1397  *
1398  * @retval ::WIMLIB_ERR_WRITE
1399  *      An error occurred when trying to write data to one of the split WIMs.
1400  *
1401  */
1402 extern int wimlib_split(const char *wimfile, const char *swm_name, 
1403                         size_t part_size, int flags);
1404
1405 /**
1406  * Unmounts a WIM image that was mounted using wimlib_mount().
1407  *
1408  * Blocks until it is known whether the mount succeeded or failed.
1409  *
1410  * To perform this operation, the process calling wimlib_unmount() communicates
1411  * with the process that had called wimlib_mount().
1412  *
1413  * There is currently a design problem with this function because it is hard to
1414  * know whether the filesystem daemon is still working or whether it has
1415  * crashed, has been killed, or has reached an infinite loop. However, ideally
1416  * there should be no infinite loops or crashes in the code, so this wouldn't be
1417  * much of a problem.  Currently, a timeout of 600 seconds (so long because WIMs
1418  * can be very large) is implemented so that this function will not wait forever
1419  * before returning failure.  
1420  *
1421  * @param dir
1422  *      The directory that the WIM image was mounted on.
1423  * @param flags
1424  *      Bitwise OR of the flags ::WIMLIB_UNMOUNT_FLAG_CHECK_INTEGRITY or
1425  *      ::WIMLIB_UNMOUNT_FLAG_COMMIT.  Neither of these flags affect read-only
1426  *      mounts.
1427  *
1428  * @return 0 on success; nonzero on error.
1429  * @retval ::WIMLIB_ERR_DELETE_STAGING_DIR
1430  *      The filesystem daemon was unable to remove the staging directory and the
1431  *      temporary files that it contains.
1432  * @retval ::WIMLIB_ERR_FORK
1433  *      Could not @c fork() the process.
1434  * @retval ::WIMLIB_ERR_FUSERMOUNT
1435  *      The @b fusermount program could not be executed or exited with a failure
1436  *      status.
1437  * @retval ::WIMLIB_ERR_MQUEUE
1438  *      Could not open a POSIX message queue to communicate with the filesystem
1439  *      daemon servicing the mounted filesystem, could not send a message
1440  *      through the queue, or could not receive a message through the queue.
1441  * @retval ::WIMLIB_ERR_NOMEM
1442  *      Failed to allocate needed memory.
1443  * @retval ::WIMLIB_ERR_OPEN
1444  *      The filesystem daemon could not open a temporary file for writing the
1445  *      new WIM.
1446  * @retval ::WIMLIB_ERR_TIMEOUT
1447  *      600 seconds elapsed while waiting for the filesystem daemon to notify
1448  *      the process of its exit status, so the WIM file probably was not written
1449  *      successfully.
1450  * @retval ::WIMLIB_ERR_READ
1451  *      A read error occurred when the filesystem daemon tried to a file from
1452  *      the staging directory
1453  * @retval ::WIMLIB_ERR_RENAME
1454  *      The filesystem daemon failed to rename the newly written WIM file to the
1455  *      original WIM file.
1456  * @retval ::WIMLIB_ERR_WRITE
1457  *      A write error occurred when the filesystem daemon was writing to the new
1458  *      WIM file, or the filesystem daemon was unable to flush changes that had
1459  *      been made to files in the staging directory.
1460  */
1461 extern int wimlib_unmount(const char *dir, int flags);
1462
1463 /**
1464  * Writes the WIM to a file.
1465  *
1466  * @param wim
1467  *      Pointer to the ::WIMStruct for a WIM file.  There may have been
1468  *      in-memory changes made to it, which are then reflected in the output
1469  *      file.
1470  * @param path
1471  *      The path to the file to write the WIM to.
1472  * @param image
1473  *      The image inside the WIM to write.  Use ::WIM_ALL_IMAGES to include all
1474  *      images.
1475  * @param flags 
1476  *      Bitwise OR of ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY and/or
1477  *      ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS.  If
1478  *      ::WIMLIB_WRITE_FLAG_CHECK_INTEGRITY is given, an integrity table is
1479  *      included in the WIM being written.  If ::WIMLIB_WRITE_FLAG_SHOW_PROGRESS
1480  *      is given, the progress of the calculation of the integrity table is
1481  *      shown.
1482  *
1483  * @return 0 on success; nonzero on error.
1484  * @retval ::WIMLIB_ERR_DECOMPRESSION
1485  *      Failed to decompress a metadata or file resource in @a wim.
1486  * @retval ::WIMLIB_ERR_INVALID_DENTRY 
1487  *      A directory entry in the metadata resource for @a image in @a wim is
1488  *      invalid.
1489  * @retval ::WIMLIB_ERR_INVALID_IMAGE
1490  *      @a image does not specify a single existing image in @a wim, and is not
1491  *      ::WIM_ALL_IMAGES.
1492  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_HASH
1493  *      A file that had previously been scanned for inclusion in the WIM by the
1494  *      wimlib_add_image() or wimlib_add_image_from_ntfs_volume() functions was
1495  *      concurrently modified, so it failed the SHA1 message digest check.
1496  * @retval ::WIMLIB_ERR_INVALID_PARAM
1497  *      @a wim or @a path was @c NULL.
1498  * @retval ::WIMLIB_ERR_INVALID_RESOURCE_SIZE
1499  *      The metadata resource for @a image in @a wim is invalid.        
1500  * @retval ::WIMLIB_ERR_INVALID_SECURITY_DATA
1501  *      The security data for @a image in @a wim is invalid.
1502  * @retval ::WIMLIB_ERR_NOMEM
1503  *      Failed to allocate needed memory.
1504  * @retval ::WIMLIB_ERR_OPEN
1505  *      Failed to open @a path for writing, or some file resources in @a
1506  *      wim refer to files in the outside filesystem, and one of these files
1507  *      could not be opened for reading.
1508  * @retval ::WIMLIB_ERR_READ
1509  *      An error occurred when trying to read data from the WIM file associated
1510  *      with @a wim, or some file resources in @a wim refer to files in the
1511  *      outside filesystem, and a read error occurred when reading one of these
1512  *      files.
1513  * @retval ::WIMLIB_ERR_SPLIT_UNSUPPORTED
1514  *      @a wim is part of a split WIM.  You may not call this function on a
1515  *      split WIM.
1516  * @retval ::WIMLIB_ERR_WRITE
1517  *      An error occurred when trying to write data to the new WIM file at @a
1518  *      path.
1519  */
1520 extern int wimlib_write(WIMStruct *wim, const char *path, int image, int flags);
1521
1522
1523
1524 #endif /* _WIMLIB_H */
1525