]> wimlib.net Git - wimlib/blob - src/wim.c
592cc440aba90c0e5a25b7c5b5d7148f3298edeb
[wimlib] / src / wim.c
1 /*
2  * wim.c - Stuff that doesn't fit into any other file
3  */
4
5 /*
6  * Copyright (C) 2012, 2013 Eric Biggers
7  *
8  * wimlib - Library for working with WIM files
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 #include "config.h"
27
28 #include <errno.h>
29 #include <fcntl.h>
30 #include <limits.h>
31 #include <stdarg.h>
32 #include <stdlib.h>
33 #include <unistd.h>
34
35 #ifdef __WIN32__
36 #  include "win32.h"
37 #else
38 #  include <langinfo.h>
39 #endif
40
41 #include "buffer_io.h"
42 #include "dentry.h"
43 #include "lookup_table.h"
44 #include "wimlib_internal.h"
45 #include "xml.h"
46
47 static int
48 image_print_metadata(WIMStruct *w)
49 {
50         DEBUG("Printing metadata for image %d", w->current_image);
51         print_security_data(wim_security_data(w));
52         return for_dentry_in_tree(wim_root_dentry(w), print_dentry,
53                                   w->lookup_table);
54 }
55
56
57 static int
58 image_print_files(WIMStruct *w)
59 {
60         return for_dentry_in_tree(wim_root_dentry(w), print_dentry_full_path,
61                                   NULL);
62 }
63
64 static WIMStruct *
65 new_wim_struct()
66 {
67         WIMStruct *w = CALLOC(1, sizeof(WIMStruct));
68 #if defined(WITH_FUSE) || defined(ENABLE_MULTITHREADED_COMPRESSION)
69         if (pthread_mutex_init(&w->fp_tab_mutex, NULL) != 0) {
70                 ERROR_WITH_ERRNO("Failed to initialize mutex");
71                 FREE(w);
72                 w = NULL;
73         }
74 #endif
75         return w;
76
77 }
78
79 /*
80  * Calls a function on images in the WIM.  If @image is WIMLIB_ALL_IMAGES, @visitor
81  * is called on the WIM once for each image, with each image selected as the
82  * current image in turn.  If @image is a certain image, @visitor is called on
83  * the WIM only once, with that image selected.
84  */
85 int
86 for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *))
87 {
88         int ret;
89         int start;
90         int end;
91         int i;
92
93         if (image == WIMLIB_ALL_IMAGES) {
94                 start = 1;
95                 end = w->hdr.image_count;
96         } else if (image >= 1 && image <= w->hdr.image_count) {
97                 start = image;
98                 end = image;
99         } else {
100                 return WIMLIB_ERR_INVALID_IMAGE;
101         }
102         for (i = start; i <= end; i++) {
103                 ret = select_wim_image(w, i);
104                 if (ret != 0)
105                         return ret;
106                 ret = visitor(w);
107                 if (ret != 0)
108                         return ret;
109         }
110         return 0;
111 }
112
113 /* Returns the compression type given in the flags of a WIM header. */
114 static int
115 wim_hdr_flags_compression_type(int wim_hdr_flags)
116 {
117         if (wim_hdr_flags & WIM_HDR_FLAG_COMPRESSION) {
118                 if (wim_hdr_flags & WIM_HDR_FLAG_COMPRESS_LZX)
119                         return WIMLIB_COMPRESSION_TYPE_LZX;
120                 else if (wim_hdr_flags & WIM_HDR_FLAG_COMPRESS_XPRESS)
121                         return WIMLIB_COMPRESSION_TYPE_XPRESS;
122                 else
123                         return WIMLIB_COMPRESSION_TYPE_INVALID;
124         } else {
125                 return WIMLIB_COMPRESSION_TYPE_NONE;
126         }
127 }
128
129 /*
130  * Creates a WIMStruct for a new WIM file.
131  */
132 WIMLIBAPI int
133 wimlib_create_new_wim(int ctype, WIMStruct **w_ret)
134 {
135         WIMStruct *w;
136         struct wim_lookup_table *table;
137         int ret;
138
139         DEBUG("Creating new WIM with %"TS" compression.",
140               wimlib_get_compression_type_string(ctype));
141
142         /* Allocate the WIMStruct. */
143         w = new_wim_struct();
144         if (!w)
145                 return WIMLIB_ERR_NOMEM;
146
147         ret = init_header(&w->hdr, ctype);
148         if (ret != 0)
149                 goto out_free;
150
151         table = new_lookup_table(9001);
152         if (!table) {
153                 ret = WIMLIB_ERR_NOMEM;
154                 goto out_free;
155         }
156         w->lookup_table = table;
157         *w_ret = w;
158         return 0;
159 out_free:
160         FREE(w);
161         return ret;
162 }
163
164 WIMLIBAPI int
165 wimlib_get_num_images(const WIMStruct *w)
166 {
167         return w->hdr.image_count;
168 }
169
170 int
171 select_wim_image(WIMStruct *w, int image)
172 {
173         struct wim_image_metadata *imd;
174         int ret;
175
176         DEBUG("Selecting image %d", image);
177
178         if (image == WIMLIB_NO_IMAGE) {
179                 ERROR("Invalid image: %d", WIMLIB_NO_IMAGE);
180                 return WIMLIB_ERR_INVALID_IMAGE;
181         }
182
183         if (image == w->current_image)
184                 return 0;
185
186         if (image < 1 || image > w->hdr.image_count) {
187                 ERROR("Cannot select image %d: There are only %u images",
188                       image, w->hdr.image_count);
189                 return WIMLIB_ERR_INVALID_IMAGE;
190         }
191
192         /* If a valid image is currently selected, it can be freed if it is not
193          * modified.  */
194         if (w->current_image != WIMLIB_NO_IMAGE) {
195                 imd = wim_get_current_image_metadata(w);
196                 if (!imd->modified) {
197                         wimlib_assert(list_empty(&imd->unhashed_streams));
198                         DEBUG("Freeing image %u", w->current_image);
199                         destroy_image_metadata(imd, NULL, false);
200                 }
201         }
202         w->current_image = image;
203         imd = wim_get_current_image_metadata(w);
204         if (imd->root_dentry) {
205                 ret = 0;
206         } else {
207                 #ifdef ENABLE_DEBUG
208                 DEBUG("Reading metadata resource specified by the following "
209                       "lookup table entry:");
210                 print_lookup_table_entry(imd->metadata_lte, stderr);
211                 #endif
212                 ret = read_metadata_resource(w, imd);
213                 if (ret)
214                         w->current_image = WIMLIB_NO_IMAGE;
215         }
216         return ret;
217 }
218
219
220 /* Returns the compression type of the WIM file. */
221 WIMLIBAPI int
222 wimlib_get_compression_type(const WIMStruct *w)
223 {
224         return wim_hdr_flags_compression_type(w->hdr.flags);
225 }
226
227 WIMLIBAPI const tchar *
228 wimlib_get_compression_type_string(int ctype)
229 {
230         switch (ctype) {
231                 case WIMLIB_COMPRESSION_TYPE_NONE:
232                         return T("None");
233                 case WIMLIB_COMPRESSION_TYPE_LZX:
234                         return T("LZX");
235                 case WIMLIB_COMPRESSION_TYPE_XPRESS:
236                         return T("XPRESS");
237                 default:
238                         return T("Invalid");
239         }
240 }
241
242 /*
243  * Returns the number of an image in the WIM file, given a string that is either
244  * the number of the image, or the name of the image.  The images are numbered
245  * starting at 1.
246  */
247 WIMLIBAPI int
248 wimlib_resolve_image(WIMStruct *w, const tchar *image_name_or_num)
249 {
250         tchar *p;
251         long image;
252         int i;
253
254         if (!image_name_or_num || !*image_name_or_num)
255                 return WIMLIB_NO_IMAGE;
256
257         if (!tstrcasecmp(image_name_or_num, T("all"))
258             || !tstrcasecmp(image_name_or_num, T("*")))
259                 return WIMLIB_ALL_IMAGES;
260         image = tstrtol(image_name_or_num, &p, 10);
261         if (p != image_name_or_num && *p == T('\0') && image > 0) {
262                 if (image > w->hdr.image_count)
263                         return WIMLIB_NO_IMAGE;
264                 return image;
265         } else {
266                 for (i = 1; i <= w->hdr.image_count; i++) {
267                         if (!tstrcmp(image_name_or_num,
268                                      wimlib_get_image_name(w, i)))
269                                 return i;
270                 }
271                 return WIMLIB_NO_IMAGE;
272         }
273 }
274
275 /* Prints some basic information about a WIM file. */
276 WIMLIBAPI void
277 wimlib_print_wim_information(const WIMStruct *w)
278 {
279         const struct wim_header *hdr;
280
281         hdr = &w->hdr;
282         tputs(T("WIM Information:"));
283         tputs(T("----------------"));
284         tprintf(T("Path:           %"TS"\n"), w->filename);
285         tfputs(T("GUID:           0x"), stdout);
286         print_byte_field(hdr->guid, WIM_GID_LEN, stdout);
287         tputchar(T('\n'));
288         tprintf(T("Image Count:    %d\n"), hdr->image_count);
289         tprintf(T("Compression:    %"TS"\n"),
290                 wimlib_get_compression_type_string(wimlib_get_compression_type(w)));
291         tprintf(T("Part Number:    %d/%d\n"), hdr->part_number, hdr->total_parts);
292         tprintf(T("Boot Index:     %d\n"), hdr->boot_idx);
293         tprintf(T("Size:           %"PRIu64" bytes\n"),
294                 wim_info_get_total_bytes(w->wim_info));
295         tprintf(T("Integrity Info: %"TS"\n"),
296                 (w->hdr.integrity.offset != 0) ? T("yes") : T("no"));
297         tprintf(T("Relative path junction: %"TS"\n"),
298                 (hdr->flags & WIM_HDR_FLAG_RP_FIX) ? T("yes") : T("no"));
299         tputchar(T('\n'));
300 }
301
302 WIMLIBAPI bool
303 wimlib_has_integrity_table(const WIMStruct *w)
304 {
305         return w->hdr.integrity.size != 0;
306 }
307
308 WIMLIBAPI void
309 wimlib_print_available_images(const WIMStruct *w, int image)
310 {
311         int first;
312         int last;
313         int i;
314         int n;
315         if (image == WIMLIB_ALL_IMAGES) {
316                 n = tprintf(T("Available Images:\n"));
317                 first = 1;
318                 last = w->hdr.image_count;
319         } else if (image >= 1 && image <= w->hdr.image_count) {
320                 n = tprintf(T("Information for Image %d\n"), image);
321                 first = image;
322                 last = image;
323         } else {
324                 tprintf(T("wimlib_print_available_images(): Invalid image %d"),
325                         image);
326                 return;
327         }
328         for (i = 0; i < n - 1; i++)
329                 tputchar(T('-'));
330         tputchar(T('\n'));
331         for (i = first; i <= last; i++)
332                 print_image_info(w->wim_info, i);
333 }
334
335
336 /* Prints the metadata for the specified image, which may be WIMLIB_ALL_IMAGES, but
337  * not WIMLIB_NO_IMAGE. */
338 WIMLIBAPI int
339 wimlib_print_metadata(WIMStruct *w, int image)
340 {
341         if (w->hdr.part_number != 1) {
342                 ERROR("Cannot show the metadata from part %hu of a %hu-part split WIM!",
343                        w->hdr.part_number, w->hdr.total_parts);
344                 ERROR("Select the first part of the split WIM to see the metadata.");
345                 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
346         }
347         return for_image(w, image, image_print_metadata);
348 }
349
350 WIMLIBAPI int
351 wimlib_print_files(WIMStruct *w, int image)
352 {
353         if (w->hdr.part_number != 1) {
354                 ERROR("Cannot list the files from part %hu of a %hu-part split WIM!",
355                        w->hdr.part_number, w->hdr.total_parts);
356                 ERROR("Select the first part of the split WIM if you'd like to list the files.");
357                 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
358         }
359         return for_image(w, image, image_print_files);
360 }
361
362 /* Sets the index of the bootable image. */
363 WIMLIBAPI int
364 wimlib_set_boot_idx(WIMStruct *w, int boot_idx)
365 {
366         if (w->hdr.total_parts != 1) {
367                 ERROR("Cannot modify the boot index of a split WIM!");
368                 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
369         }
370         if (boot_idx < 0 || boot_idx > w->hdr.image_count)
371                 return WIMLIB_ERR_INVALID_IMAGE;
372         w->hdr.boot_idx = boot_idx;
373         return 0;
374 }
375
376 WIMLIBAPI int
377 wimlib_get_part_number(const WIMStruct *w, int *total_parts_ret)
378 {
379         if (total_parts_ret)
380                 *total_parts_ret = w->hdr.total_parts;
381         return w->hdr.part_number;
382 }
383
384
385 WIMLIBAPI int
386 wimlib_get_boot_idx(const WIMStruct *w)
387 {
388         return w->hdr.boot_idx;
389 }
390
391 /*
392  * Begins the reading of a WIM file; opens the file and reads its header and
393  * lookup table, and optionally checks the integrity.
394  */
395 static int
396 begin_read(WIMStruct *w, const tchar *in_wim_path, int open_flags,
397            wimlib_progress_func_t progress_func)
398 {
399         int ret;
400         int xml_num_images;
401
402         DEBUG("Reading the WIM file `%"TS"'", in_wim_path);
403
404         w->fp = tfopen(in_wim_path, T("rb"));
405         if (!w->fp) {
406                 ERROR_WITH_ERRNO("Failed to open `%"TS"' for reading",
407                                  in_wim_path);
408                 return WIMLIB_ERR_OPEN;
409         }
410
411         /* The absolute path to the WIM is requested so that wimlib_overwrite()
412          * still works even if the process changes its working directory.  This
413          * actually happens if a WIM is mounted read-write, since the FUSE
414          * thread changes directory to "/", and it needs to be able to find the
415          * WIM file again.
416          *
417          * This will break if the full path to the WIM changes in the
418          * intervening time...
419          *
420          * Warning: in Windows native builds, realpath() calls the replacement
421          * function in win32.c.
422          */
423         w->filename = realpath(in_wim_path, NULL);
424         if (!w->filename) {
425                 ERROR_WITH_ERRNO("Failed to resolve WIM filename");
426                 if (errno == ENOMEM)
427                         return WIMLIB_ERR_NOMEM;
428                 else
429                         return WIMLIB_ERR_OPEN;
430         }
431
432         ret = read_header(w->fp, &w->hdr, open_flags);
433         if (ret)
434                 return ret;
435
436         DEBUG("According to header, WIM contains %u images", w->hdr.image_count);
437
438         /* If the boot index is invalid, print a warning and set it to 0 */
439         if (w->hdr.boot_idx > w->hdr.image_count) {
440                 WARNING("In `%"TS"', image %u is marked as bootable, "
441                         "but there are only %u images in the WIM",
442                         in_wim_path, w->hdr.boot_idx, w->hdr.image_count);
443                 w->hdr.boot_idx = 0;
444         }
445
446         if (wimlib_get_compression_type(w) == WIMLIB_COMPRESSION_TYPE_INVALID) {
447                 ERROR("Invalid compression type (WIM header flags = 0x%x)",
448                       w->hdr.flags);
449                 return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
450         }
451
452         if (open_flags & WIMLIB_OPEN_FLAG_CHECK_INTEGRITY) {
453                 ret = check_wim_integrity(w, progress_func);
454                 if (ret == WIM_INTEGRITY_NONEXISTENT) {
455                         WARNING("No integrity information for `%"TS"'; skipping "
456                                 "integrity check.", in_wim_path);
457                 } else if (ret == WIM_INTEGRITY_NOT_OK) {
458                         ERROR("WIM is not intact! (Failed integrity check)");
459                         return WIMLIB_ERR_INTEGRITY;
460                 } else if (ret != WIM_INTEGRITY_OK) {
461                         return ret;
462                 }
463         }
464
465         if (w->hdr.image_count != 0 && w->hdr.part_number == 1) {
466                 w->image_metadata = new_image_metadata_array(w->hdr.image_count);
467                 if (!w->image_metadata)
468                         return WIMLIB_ERR_NOMEM;
469         }
470
471         ret = read_lookup_table(w);
472         if (ret)
473                 return ret;
474
475         ret = read_xml_data(w->fp, &w->hdr.xml_res_entry, &w->wim_info);
476         if (ret)
477                 return ret;
478
479         xml_num_images = wim_info_get_num_images(w->wim_info);
480         if (xml_num_images != w->hdr.image_count) {
481                 ERROR("In the file `%"TS"', there are %u <IMAGE> elements "
482                       "in the XML data,", in_wim_path, xml_num_images);
483                 ERROR("but %u images in the WIM!  There must be exactly one "
484                       "<IMAGE> element per image.", w->hdr.image_count);
485                 return WIMLIB_ERR_IMAGE_COUNT;
486         }
487
488         DEBUG("Done beginning read of WIM file `%"TS"'.", in_wim_path);
489         return 0;
490 }
491
492 /*
493  * Opens a WIM file and creates a WIMStruct for it.
494  */
495 WIMLIBAPI int
496 wimlib_open_wim(const tchar *wim_file, int open_flags,
497                 WIMStruct **w_ret,
498                 wimlib_progress_func_t progress_func)
499 {
500         WIMStruct *w;
501         int ret;
502
503         if (!wim_file || !w_ret)
504                 return WIMLIB_ERR_INVALID_PARAM;
505
506         w = new_wim_struct();
507         if (!w)
508                 return WIMLIB_ERR_NOMEM;
509
510         ret = begin_read(w, wim_file, open_flags, progress_func);
511         if (ret == 0)
512                 *w_ret = w;
513         else
514                 wimlib_free(w);
515         return ret;
516 }
517
518 void
519 destroy_image_metadata(struct wim_image_metadata *imd,
520                        struct wim_lookup_table *table,
521                        bool free_metadata_lte)
522 {
523         free_dentry_tree(imd->root_dentry, table);
524         imd->root_dentry = NULL;
525         free_security_data(imd->security_data);
526         imd->security_data = NULL;
527
528         if (free_metadata_lte) {
529                 free_lookup_table_entry(imd->metadata_lte);
530                 imd->metadata_lte = NULL;
531         }
532         if (!table) {
533                 struct wim_lookup_table_entry *lte, *tmp;
534                 list_for_each_entry_safe(lte, tmp, &imd->unhashed_streams, unhashed_list)
535                         free_lookup_table_entry(lte);
536         }
537         INIT_LIST_HEAD(&imd->unhashed_streams);
538         INIT_LIST_HEAD(&imd->inode_list);
539 #ifdef WITH_NTFS_3G
540         if (imd->ntfs_vol) {
541                 do_ntfs_umount(imd->ntfs_vol);
542                 imd->ntfs_vol = NULL;
543         }
544 #endif
545 }
546
547 void
548 put_image_metadata(struct wim_image_metadata *imd,
549                    struct wim_lookup_table *table)
550 {
551         if (imd && --imd->refcnt == 0) {
552                 destroy_image_metadata(imd, table, true);
553                 FREE(imd);
554         }
555 }
556
557 /* Appends the specified image metadata structure to the array of image metadata
558  * for a WIM, and increments the image count. */
559 int
560 append_image_metadata(WIMStruct *w, struct wim_image_metadata *imd)
561 {
562         struct wim_image_metadata **imd_array;
563
564         DEBUG("Reallocating image metadata array for image_count = %u",
565               w->hdr.image_count + 1);
566         imd_array = REALLOC(w->image_metadata,
567                             sizeof(w->image_metadata[0]) * (w->hdr.image_count + 1));
568
569         if (!imd_array)
570                 return WIMLIB_ERR_NOMEM;
571         w->image_metadata = imd_array;
572         imd_array[w->hdr.image_count++] = imd;
573         return 0;
574 }
575
576
577 struct wim_image_metadata *
578 new_image_metadata()
579 {
580         struct wim_image_metadata *imd;
581
582         imd = CALLOC(1, sizeof(*imd));
583         if (imd) {
584                 imd->refcnt = 1;
585                 INIT_LIST_HEAD(&imd->inode_list);
586                 INIT_LIST_HEAD(&imd->unhashed_streams);
587                 DEBUG("Created new image metadata (refcnt=1)");
588         } else {
589                 ERROR_WITH_ERRNO("Failed to allocate new image metadata structure");
590         }
591         return imd;
592 }
593
594 struct wim_image_metadata **
595 new_image_metadata_array(unsigned num_images)
596 {
597         struct wim_image_metadata **imd_array;
598
599         DEBUG("Creating new image metadata array for %u images",
600               num_images);
601
602         imd_array = CALLOC(num_images, sizeof(imd_array[0]));
603
604         if (!imd_array) {
605                 ERROR("Failed to allocate memory for %u image metadata structures",
606                       num_images);
607                 return NULL;
608         }
609         for (unsigned i = 0; i < num_images; i++) {
610                 imd_array[i] = new_image_metadata();
611                 if (!imd_array[i]) {
612                         for (unsigned j = 0; j < i; j++)
613                                 put_image_metadata(imd_array[j], NULL);
614                         FREE(imd_array);
615                         return NULL;
616                 }
617         }
618         return imd_array;
619 }
620
621 /* Checksum all streams that are unhashed (other than the metadata streams),
622  * merging them into the lookup table as needed.  This is a no-op unless the
623  * library has previously used to add or mount an image using the same
624  * WIMStruct. */
625 int
626 wim_checksum_unhashed_streams(WIMStruct *w)
627 {
628         int ret;
629         for (int i = 0; i < w->hdr.image_count; i++) {
630                 struct wim_lookup_table_entry *lte, *tmp;
631                 struct wim_image_metadata *imd = w->image_metadata[i];
632                 image_for_each_unhashed_stream_safe(lte, tmp, imd) {
633                         ret = hash_unhashed_stream(lte, w->lookup_table, NULL);
634                         if (ret)
635                                 return ret;
636                 }
637         }
638         return 0;
639 }
640
641 /* Frees the memory for the WIMStruct, including all internal memory; also
642  * closes all files associated with the WIMStruct.  */
643 WIMLIBAPI void
644 wimlib_free(WIMStruct *w)
645 {
646         DEBUG("Freeing WIMStruct");
647
648         if (!w)
649                 return;
650         if (w->fp)
651                 fclose(w->fp);
652         if (w->out_fp)
653                 fclose(w->out_fp);
654
655 #if defined(WITH_FUSE) || defined(ENABLE_MULTITHREADED_COMPRESSION)
656         if (w->fp_tab) {
657                 for (size_t i = 0; i < w->num_allocated_fps; i++)
658                         if (w->fp_tab[i])
659                                 fclose(w->fp_tab[i]);
660                 FREE(w->fp_tab);
661         }
662         pthread_mutex_destroy(&w->fp_tab_mutex);
663 #endif
664
665         free_lookup_table(w->lookup_table);
666
667         FREE(w->filename);
668         free_wim_info(w->wim_info);
669         if (w->image_metadata) {
670                 for (unsigned i = 0; i < w->hdr.image_count; i++)
671                         put_image_metadata(w->image_metadata[i], NULL);
672                 FREE(w->image_metadata);
673         }
674         FREE(w);
675         DEBUG("Freed WIMStruct");
676 }
677
678 static bool
679 test_locale_ctype_utf8()
680 {
681 #ifdef __WIN32__
682         return false;
683 #else
684         char *ctype = nl_langinfo(CODESET);
685
686         return (!strstr(ctype, "UTF-8") ||
687                 !strstr(ctype, "UTF8") ||
688                 !strstr(ctype, "utf8") ||
689                 !strstr(ctype, "utf-8"));
690 #endif
691 }
692
693 WIMLIBAPI int
694 wimlib_global_init(int init_flags)
695 {
696         libxml_global_init();
697         if (!(init_flags & WIMLIB_INIT_FLAG_ASSUME_UTF8)) {
698                 wimlib_mbs_is_utf8 = test_locale_ctype_utf8();
699         #ifdef WITH_NTFS_3G
700                 if (!wimlib_mbs_is_utf8)
701                         libntfs3g_global_init();
702         #endif
703         }
704 #ifdef __WIN32__
705         win32_global_init();
706 #endif
707         return 0;
708 }
709
710 /* Free global memory allocations.  Not strictly necessary if the process using
711  * wimlib is just about to exit (as is the case for 'imagex'). */
712 WIMLIBAPI void
713 wimlib_global_cleanup()
714 {
715         libxml_global_cleanup();
716         iconv_global_cleanup();
717 #ifdef __WIN32__
718         win32_global_cleanup();
719 #endif
720 }