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