2 * wim.c - Stuff that doesn't fit into any other file
6 * Copyright (C) 2012, 2013 Eric Biggers
8 * This file is part of wimlib, a library for working with WIM files.
10 * wimlib is free software; you can redistribute it and/or modify it under the
11 * terms of the GNU General Public License as published by the Free
12 * Software Foundation; either version 3 of the License, or (at your option)
15 * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
16 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
17 * A PARTICULAR PURPOSE. See the GNU General Public License for more
20 * You should have received a copy of the GNU General Public License
21 * along with wimlib; if not, see http://www.gnu.org/licenses/.
28 #include "wimlib/error.h"
29 #include "wimlib/dentry.h"
30 #include "wimlib/encoding.h"
31 #include "wimlib/file_io.h"
32 #include "wimlib/integrity.h"
33 #include "wimlib/lookup_table.h"
34 #include "wimlib/metadata.h"
36 # include "wimlib/ntfs_3g.h" /* for do_ntfs_umount() */
38 #include "wimlib/security.h"
39 #include "wimlib/wim.h"
40 #include "wimlib/xml.h"
43 # include "wimlib/win32.h" /* for realpath() replacement */
49 # include <langinfo.h>
57 image_print_metadata(WIMStruct *wim)
59 DEBUG("Printing metadata for image %d", wim->current_image);
60 print_wim_security_data(wim_security_data(wim));
61 return for_dentry_in_tree(wim_root_dentry(wim), print_dentry,
67 image_print_files(WIMStruct *wim)
69 return for_dentry_in_tree(wim_root_dentry(wim), print_dentry_full_path,
76 WIMStruct *wim = CALLOC(1, sizeof(WIMStruct));
85 * Calls a function on images in the WIM. If @image is WIMLIB_ALL_IMAGES, @visitor
86 * is called on the WIM once for each image, with each image selected as the
87 * current image in turn. If @image is a certain image, @visitor is called on
88 * the WIM only once, with that image selected.
91 for_image(WIMStruct *wim, int image, int (*visitor)(WIMStruct *))
98 if (image == WIMLIB_ALL_IMAGES) {
100 end = wim->hdr.image_count;
101 } else if (image >= 1 && image <= wim->hdr.image_count) {
105 return WIMLIB_ERR_INVALID_IMAGE;
107 for (i = start; i <= end; i++) {
108 ret = select_wim_image(wim, i);
119 * Creates a WIMStruct for a new WIM file.
122 wimlib_create_new_wim(int ctype, WIMStruct **wim_ret)
125 struct wim_lookup_table *table;
128 wimlib_global_init(WIMLIB_INIT_FLAG_ASSUME_UTF8);
130 DEBUG("Creating new WIM with %"TS" compression.",
131 wimlib_get_compression_type_string(ctype));
133 /* Allocate the WIMStruct. */
134 wim = new_wim_struct();
136 return WIMLIB_ERR_NOMEM;
138 ret = init_header(&wim->hdr, ctype);
142 table = new_lookup_table(9001);
144 ret = WIMLIB_ERR_NOMEM;
147 wim->lookup_table = table;
149 wim->compression_type = ctype;
158 select_wim_image(WIMStruct *wim, int image)
160 struct wim_image_metadata *imd;
163 DEBUG("Selecting image %d", image);
165 if (image == WIMLIB_NO_IMAGE) {
166 ERROR("Invalid image: %d", WIMLIB_NO_IMAGE);
167 return WIMLIB_ERR_INVALID_IMAGE;
170 if (image == wim->current_image)
173 if (image < 1 || image > wim->hdr.image_count) {
174 ERROR("Cannot select image %d: There are only %u images",
175 image, wim->hdr.image_count);
176 return WIMLIB_ERR_INVALID_IMAGE;
179 if (wim->hdr.part_number != 1) {
180 ERROR("Cannot select an image from a non-first part of a split WIM");
181 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
184 /* If a valid image is currently selected, it can be freed if it is not
186 if (wim->current_image != WIMLIB_NO_IMAGE) {
187 imd = wim_get_current_image_metadata(wim);
188 if (!imd->modified) {
189 wimlib_assert(list_empty(&imd->unhashed_streams));
190 DEBUG("Freeing image %u", wim->current_image);
191 destroy_image_metadata(imd, NULL, false);
194 wim->current_image = image;
195 imd = wim_get_current_image_metadata(wim);
196 if (imd->root_dentry || imd->modified) {
200 DEBUG("Reading metadata resource specified by the following "
201 "lookup table entry:");
202 print_lookup_table_entry(imd->metadata_lte, stderr);
204 ret = read_metadata_resource(wim, imd);
206 wim->current_image = WIMLIB_NO_IMAGE;
212 WIMLIBAPI const tchar *
213 wimlib_get_compression_type_string(int ctype)
216 case WIMLIB_COMPRESSION_TYPE_NONE:
218 case WIMLIB_COMPRESSION_TYPE_LZX:
220 case WIMLIB_COMPRESSION_TYPE_XPRESS:
228 * Returns the number of an image in the WIM file, given a string that is either
229 * the number of the image, or the name of the image. The images are numbered
233 wimlib_resolve_image(WIMStruct *wim, const tchar *image_name_or_num)
239 if (!image_name_or_num || !*image_name_or_num)
240 return WIMLIB_NO_IMAGE;
242 if (!tstrcasecmp(image_name_or_num, T("all"))
243 || !tstrcasecmp(image_name_or_num, T("*")))
244 return WIMLIB_ALL_IMAGES;
245 image = tstrtol(image_name_or_num, &p, 10);
246 if (p != image_name_or_num && *p == T('\0') && image > 0) {
247 if (image > wim->hdr.image_count)
248 return WIMLIB_NO_IMAGE;
251 for (i = 1; i <= wim->hdr.image_count; i++) {
252 if (!tstrcmp(image_name_or_num,
253 wimlib_get_image_name(wim, i)))
256 return WIMLIB_NO_IMAGE;
260 /* Prints some basic information about a WIM file. */
262 wimlib_print_wim_information(const WIMStruct *wim)
264 struct wimlib_wim_info info;
266 wimlib_get_wim_info((WIMStruct*)wim, &info);
268 tputs(T("WIM Information:"));
269 tputs(T("----------------"));
270 tprintf(T("Path: %"TS"\n"), wim->filename);
271 tfputs(T("GUID: 0x"), stdout);
272 print_byte_field(info.guid, WIM_GID_LEN, stdout);
274 tprintf(T("Image Count: %d\n"), info.image_count);
275 tprintf(T("Compression: %"TS"\n"),
276 wimlib_get_compression_type_string(info.compression_type));
277 tprintf(T("Part Number: %d/%d\n"), info.part_number, info.total_parts);
278 tprintf(T("Boot Index: %d\n"), info.boot_index);
279 tprintf(T("Size: %"PRIu64" bytes\n"), info.total_bytes);
280 tprintf(T("Integrity Info: %"TS"\n"),
281 info.has_integrity_table ? T("yes") : T("no"));
282 tprintf(T("Relative path junction: %"TS"\n"),
283 info.has_rpfix ? T("yes") : T("no"));
288 wimlib_print_available_images(const WIMStruct *wim, int image)
294 if (image == WIMLIB_ALL_IMAGES) {
295 n = tprintf(T("Available Images:\n"));
297 last = wim->hdr.image_count;
298 } else if (image >= 1 && image <= wim->hdr.image_count) {
299 n = tprintf(T("Information for Image %d\n"), image);
303 tprintf(T("wimlib_print_available_images(): Invalid image %d"),
307 for (i = 0; i < n - 1; i++)
310 for (i = first; i <= last; i++)
311 print_image_info(wim->wim_info, i);
315 /* Prints the metadata for the specified image, which may be WIMLIB_ALL_IMAGES, but
316 * not WIMLIB_NO_IMAGE. */
318 wimlib_print_metadata(WIMStruct *wim, int image)
320 if (wim->hdr.part_number != 1) {
321 ERROR("Cannot show the metadata from part %hu of a %hu-part split WIM!",
322 wim->hdr.part_number, wim->hdr.total_parts);
323 ERROR("Select the first part of the split WIM to see the metadata.");
324 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
326 return for_image(wim, image, image_print_metadata);
330 wimlib_print_files(WIMStruct *wim, int image)
332 if (wim->hdr.part_number != 1) {
333 ERROR("Cannot list the files from part %hu of a %hu-part split WIM!",
334 wim->hdr.part_number, wim->hdr.total_parts);
335 ERROR("Select the first part of the split WIM if you'd like to list the files.");
336 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
338 return for_image(wim, image, image_print_files);
342 wimlib_get_wim_info(WIMStruct *wim, struct wimlib_wim_info *info)
344 memset(info, 0, sizeof(struct wimlib_wim_info));
345 memcpy(info->guid, wim->hdr.guid, WIMLIB_GUID_LEN);
346 info->image_count = wim->hdr.image_count;
347 info->boot_index = wim->hdr.boot_idx;
348 info->wim_version = WIM_VERSION;
349 info->chunk_size = WIM_CHUNK_SIZE;
350 info->part_number = wim->hdr.part_number;
351 info->total_parts = wim->hdr.total_parts;
352 info->compression_type = wim->compression_type;
354 info->total_bytes = wim->wim_info->total_bytes;
356 info->total_bytes = 0;
357 info->has_integrity_table = wim->hdr.integrity.offset != 0;
358 info->opened_from_file = (wim->filename != NULL);
359 info->is_readonly = (wim->hdr.flags & WIM_HDR_FLAG_READONLY) ||
360 (wim->hdr.total_parts != 1) ||
361 (wim->filename && taccess(wim->filename, W_OK));
362 info->has_rpfix = (wim->hdr.flags & WIM_HDR_FLAG_RP_FIX) != 0;
363 info->is_marked_readonly = (wim->hdr.flags & WIM_HDR_FLAG_READONLY) != 0;
364 info->write_in_progress = (wim->hdr.flags & WIM_HDR_FLAG_WRITE_IN_PROGRESS) != 0;
365 info->metadata_only = (wim->hdr.flags & WIM_HDR_FLAG_METADATA_ONLY) != 0;
366 info->resource_only = (wim->hdr.flags & WIM_HDR_FLAG_RESOURCE_ONLY) != 0;
367 info->spanned = (wim->hdr.flags & WIM_HDR_FLAG_SPANNED) != 0;
374 wimlib_get_boot_idx(const WIMStruct *wim)
376 struct wimlib_wim_info info;
378 wimlib_get_wim_info((WIMStruct*)wim, &info);
379 return info.boot_index;
384 wimlib_get_compression_type(const WIMStruct *wim)
386 struct wimlib_wim_info info;
388 wimlib_get_wim_info((WIMStruct*)wim, &info);
389 return info.compression_type;
394 wimlib_get_num_images(const WIMStruct *wim)
396 struct wimlib_wim_info info;
398 wimlib_get_wim_info((WIMStruct*)wim, &info);
399 return info.image_count;
404 wimlib_get_part_number(const WIMStruct *wim, int *total_parts_ret)
406 struct wimlib_wim_info info;
408 wimlib_get_wim_info((WIMStruct*)wim, &info);
410 *total_parts_ret = info.total_parts;
411 return info.part_number;
416 wimlib_has_integrity_table(const WIMStruct *wim)
418 struct wimlib_wim_info info;
420 wimlib_get_wim_info((WIMStruct*)wim, &info);
421 return info.has_integrity_table;
425 wimlib_set_wim_info(WIMStruct *wim, const struct wimlib_wim_info *info, int which)
429 if (which & WIMLIB_CHANGE_READONLY_FLAG) {
430 if (info->is_marked_readonly)
431 wim->hdr.flags |= WIM_HDR_FLAG_READONLY;
433 wim->hdr.flags &= ~WIM_HDR_FLAG_READONLY;
436 if ((which & ~WIMLIB_CHANGE_READONLY_FLAG) == 0)
439 ret = can_modify_wim(wim);
443 if (which & WIMLIB_CHANGE_GUID)
444 memcpy(wim->hdr.guid, info->guid, WIM_GID_LEN);
446 if (which & WIMLIB_CHANGE_BOOT_INDEX) {
447 if (info->boot_index < 0 || info->boot_index > wim->hdr.image_count)
449 ERROR("%u is not 0 or a valid image in the WIM to mark as bootable",
451 return WIMLIB_ERR_INVALID_IMAGE;
453 wim->hdr.boot_idx = info->boot_index;
456 if (which & WIMLIB_CHANGE_RPFIX_FLAG) {
458 wim->hdr.flags |= WIM_HDR_FLAG_RP_FIX;
460 wim->hdr.flags &= ~WIM_HDR_FLAG_RP_FIX;
467 wimlib_set_boot_idx(WIMStruct *wim, int boot_idx)
469 struct wimlib_wim_info info;
471 info.boot_index = boot_idx;
472 return wimlib_set_wim_info(wim, &info, WIMLIB_CHANGE_BOOT_INDEX);
476 do_open_wim(const tchar *filename, int *fd_ret)
480 fd = topen(filename, O_RDONLY | O_BINARY);
482 ERROR_WITH_ERRNO("Can't open \"%"TS"\" read-only", filename);
483 return WIMLIB_ERR_OPEN;
490 reopen_wim(WIMStruct *wim)
492 wimlib_assert(wim->in_fd == -1);
493 return do_open_wim(wim->filename, &wim->in_fd);
497 close_wim(WIMStruct *wim)
499 if (wim->in_fd != -1) {
507 * Begins the reading of a WIM file; opens the file and reads its header and
508 * lookup table, and optionally checks the integrity.
511 begin_read(WIMStruct *wim, const tchar *in_wim_path, int open_flags,
512 wimlib_progress_func_t progress_func)
517 DEBUG("Reading the WIM file `%"TS"'", in_wim_path);
519 ret = do_open_wim(in_wim_path, &wim->in_fd);
523 /* The absolute path to the WIM is requested so that wimlib_overwrite()
524 * still works even if the process changes its working directory. This
525 * actually happens if a WIM is mounted read-write, since the FUSE
526 * thread changes directory to "/", and it needs to be able to find the
529 * This will break if the full path to the WIM changes in the
530 * intervening time...
532 * Warning: in Windows native builds, realpath() calls the replacement
533 * function in win32.c.
535 wim->filename = realpath(in_wim_path, NULL);
536 if (!wim->filename) {
537 ERROR_WITH_ERRNO("Failed to resolve WIM filename");
539 return WIMLIB_ERR_NOMEM;
541 return WIMLIB_ERR_OPEN;
544 ret = read_header(wim->filename, wim->in_fd, &wim->hdr);
548 if (wim->hdr.flags & WIM_HDR_FLAG_WRITE_IN_PROGRESS) {
549 WARNING("The WIM_HDR_FLAG_WRITE_IN_PROGRESS is set in the header of \"%"TS"\".\n"
550 " It may be being changed by another process, or a process\n"
551 " may have crashed while writing the WIM.", in_wim_path);
554 if (open_flags & WIMLIB_OPEN_FLAG_WRITE_ACCESS) {
555 ret = can_modify_wim(wim);
560 if (wim->hdr.total_parts != 1 && !(open_flags & WIMLIB_OPEN_FLAG_SPLIT_OK)) {
561 ERROR("\"%"TS"\": This WIM is part %u of a %u-part WIM",
562 in_wim_path, wim->hdr.part_number, wim->hdr.total_parts);
563 return WIMLIB_ERR_SPLIT_UNSUPPORTED;
566 DEBUG("According to header, WIM contains %u images", wim->hdr.image_count);
568 /* If the boot index is invalid, print a warning and set it to 0 */
569 if (wim->hdr.boot_idx > wim->hdr.image_count) {
570 WARNING("In `%"TS"', image %u is marked as bootable, "
571 "but there are only %u images in the WIM",
572 in_wim_path, wim->hdr.boot_idx, wim->hdr.image_count);
573 wim->hdr.boot_idx = 0;
576 /* Check and cache the compression type */
577 if (wim->hdr.flags & WIM_HDR_FLAG_COMPRESSION) {
578 if (wim->hdr.flags & WIM_HDR_FLAG_COMPRESS_LZX) {
579 if (wim->hdr.flags & WIM_HDR_FLAG_COMPRESS_XPRESS) {
580 ERROR("Multiple compression flags are set in \"%"TS"\"",
582 return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
584 wim->compression_type = WIMLIB_COMPRESSION_TYPE_LZX;
585 } else if (wim->hdr.flags & WIM_HDR_FLAG_COMPRESS_XPRESS) {
586 wim->compression_type = WIMLIB_COMPRESSION_TYPE_XPRESS;
588 ERROR("The compression flag is set on \"%"TS"\", but "
589 "neither the XPRESS nor LZX flag is set",
591 return WIMLIB_ERR_INVALID_COMPRESSION_TYPE;
594 BUILD_BUG_ON(WIMLIB_COMPRESSION_TYPE_NONE != 0);
597 if (open_flags & WIMLIB_OPEN_FLAG_CHECK_INTEGRITY) {
598 ret = check_wim_integrity(wim, progress_func);
599 if (ret == WIM_INTEGRITY_NONEXISTENT) {
600 WARNING("No integrity information for `%"TS"'; skipping "
601 "integrity check.", in_wim_path);
602 } else if (ret == WIM_INTEGRITY_NOT_OK) {
603 ERROR("WIM is not intact! (Failed integrity check)");
604 return WIMLIB_ERR_INTEGRITY;
605 } else if (ret != WIM_INTEGRITY_OK) {
610 if (wim->hdr.image_count != 0 && wim->hdr.part_number == 1) {
611 wim->image_metadata = new_image_metadata_array(wim->hdr.image_count);
612 if (!wim->image_metadata)
613 return WIMLIB_ERR_NOMEM;
616 ret = read_lookup_table(wim);
620 ret = read_xml_data(wim->in_fd, &wim->hdr.xml_res_entry, &wim->wim_info);
624 xml_num_images = wim_info_get_num_images(wim->wim_info);
625 if (xml_num_images != wim->hdr.image_count) {
626 ERROR("In the file `%"TS"', there are %u <IMAGE> elements "
627 "in the XML data,", in_wim_path, xml_num_images);
628 ERROR("but %u images in the WIM! There must be exactly one "
629 "<IMAGE> element per image.", wim->hdr.image_count);
630 return WIMLIB_ERR_IMAGE_COUNT;
633 DEBUG("Done beginning read of WIM file `%"TS"'.", in_wim_path);
638 * Opens a WIM file and creates a WIMStruct for it.
641 wimlib_open_wim(const tchar *wim_file, int open_flags,
643 wimlib_progress_func_t progress_func)
648 wimlib_global_init(WIMLIB_INIT_FLAG_ASSUME_UTF8);
650 ret = WIMLIB_ERR_INVALID_PARAM;
651 if (!wim_file || !wim_ret)
654 ret = WIMLIB_ERR_NOMEM;
655 wim = new_wim_struct();
659 ret = begin_read(wim, wim_file, open_flags, progress_func);
661 goto out_wimlib_free;
673 destroy_image_metadata(struct wim_image_metadata *imd,
674 struct wim_lookup_table *table,
675 bool free_metadata_lte)
677 free_dentry_tree(imd->root_dentry, table);
678 imd->root_dentry = NULL;
679 free_wim_security_data(imd->security_data);
680 imd->security_data = NULL;
682 if (free_metadata_lte) {
683 free_lookup_table_entry(imd->metadata_lte);
684 imd->metadata_lte = NULL;
687 struct wim_lookup_table_entry *lte, *tmp;
688 list_for_each_entry_safe(lte, tmp, &imd->unhashed_streams, unhashed_list)
689 free_lookup_table_entry(lte);
691 INIT_LIST_HEAD(&imd->unhashed_streams);
692 INIT_LIST_HEAD(&imd->inode_list);
695 do_ntfs_umount(imd->ntfs_vol);
696 imd->ntfs_vol = NULL;
702 put_image_metadata(struct wim_image_metadata *imd,
703 struct wim_lookup_table *table)
705 if (imd && --imd->refcnt == 0) {
706 destroy_image_metadata(imd, table, true);
711 /* Appends the specified image metadata structure to the array of image metadata
712 * for a WIM, and increments the image count. */
714 append_image_metadata(WIMStruct *wim, struct wim_image_metadata *imd)
716 struct wim_image_metadata **imd_array;
718 DEBUG("Reallocating image metadata array for image_count = %u",
719 wim->hdr.image_count + 1);
720 imd_array = REALLOC(wim->image_metadata,
721 sizeof(wim->image_metadata[0]) * (wim->hdr.image_count + 1));
724 return WIMLIB_ERR_NOMEM;
725 wim->image_metadata = imd_array;
726 imd_array[wim->hdr.image_count++] = imd;
731 struct wim_image_metadata *
732 new_image_metadata(void)
734 struct wim_image_metadata *imd;
736 imd = CALLOC(1, sizeof(*imd));
739 INIT_LIST_HEAD(&imd->inode_list);
740 INIT_LIST_HEAD(&imd->unhashed_streams);
741 DEBUG("Created new image metadata (refcnt=1)");
743 ERROR_WITH_ERRNO("Failed to allocate new image metadata structure");
748 struct wim_image_metadata **
749 new_image_metadata_array(unsigned num_images)
751 struct wim_image_metadata **imd_array;
753 DEBUG("Creating new image metadata array for %u images",
756 imd_array = CALLOC(num_images, sizeof(imd_array[0]));
759 ERROR("Failed to allocate memory for %u image metadata structures",
763 for (unsigned i = 0; i < num_images; i++) {
764 imd_array[i] = new_image_metadata();
766 for (unsigned j = 0; j < i; j++)
767 put_image_metadata(imd_array[j], NULL);
775 /* Checksum all streams that are unhashed (other than the metadata streams),
776 * merging them into the lookup table as needed. This is a no-op unless the
777 * library has previously used to add or mount an image using the same
780 wim_checksum_unhashed_streams(WIMStruct *wim)
783 for (int i = 0; i < wim->hdr.image_count; i++) {
784 struct wim_lookup_table_entry *lte, *tmp;
785 struct wim_image_metadata *imd = wim->image_metadata[i];
786 image_for_each_unhashed_stream_safe(lte, tmp, imd) {
787 ret = hash_unhashed_stream(lte, wim->lookup_table, NULL);
796 * can_modify_wim - Check if a given WIM is writeable. This is only the case if
797 * it meets the following three conditions:
799 * 1. Write access is allowed to the underlying file (if any) at the filesystem level.
800 * 2. The WIM is not part of a spanned set.
801 * 3. The WIM_HDR_FLAG_READONLY flag is not set in the WIM header.
803 * Return value is 0 if writable; WIMLIB_ERR_WIM_IS_READONLY otherwise.
806 can_modify_wim(WIMStruct *wim)
809 if (taccess(wim->filename, W_OK)) {
810 ERROR_WITH_ERRNO("Can't modify \"%"TS"\"", wim->filename);
811 return WIMLIB_ERR_WIM_IS_READONLY;
814 if (wim->hdr.total_parts != 1) {
815 ERROR("Cannot modify \"%"TS"\": is part of a spanned set",
817 return WIMLIB_ERR_WIM_IS_READONLY;
819 if (wim->hdr.flags & WIM_HDR_FLAG_READONLY) {
820 ERROR("Cannot modify \"%"TS"\": is marked read-only",
822 return WIMLIB_ERR_WIM_IS_READONLY;
828 * can_delete_from_wim - Check if files or images can be deleted from a given
831 * This theoretically should be exactly the same as can_modify_wim(), but
832 * unfortunately, due to bugs in Microsoft's software that generate incorrect
833 * reference counts for some WIM resources, we need to run expensive
834 * verifications to make sure the reference counts are correct on all WIM
835 * resources. Otherwise we might delete a WIM resource whose reference count
836 * has fallen to 0, but is actually still referenced somewhere.
839 can_delete_from_wim(WIMStruct *wim)
843 ret = can_modify_wim(wim);
846 if (!wim->refcnts_ok)
847 wim_recalculate_refcnts(wim);
851 /* Frees the memory for the WIMStruct, including all internal memory; also
852 * closes all files associated with the WIMStruct. */
854 wimlib_free(WIMStruct *wim)
856 DEBUG("Freeing WIMStruct");
860 if (wim->in_fd != -1)
862 if (wim->out_fd != -1)
865 free_lookup_table(wim->lookup_table);
868 free_wim_info(wim->wim_info);
869 if (wim->image_metadata) {
870 for (unsigned i = 0; i < wim->hdr.image_count; i++)
871 put_image_metadata(wim->image_metadata[i], NULL);
872 FREE(wim->image_metadata);
875 DEBUG("Freed WIMStruct");
879 test_locale_ctype_utf8(void)
884 char *ctype = nl_langinfo(CODESET);
886 return (!strstr(ctype, "UTF-8") ||
887 !strstr(ctype, "UTF8") ||
888 !strstr(ctype, "utf8") ||
889 !strstr(ctype, "utf-8"));
894 wimlib_global_init(int init_flags)
896 static bool already_inited = false;
900 libxml_global_init();
901 if (!(init_flags & WIMLIB_INIT_FLAG_ASSUME_UTF8)) {
902 wimlib_mbs_is_utf8 = test_locale_ctype_utf8();
904 if (!wimlib_mbs_is_utf8)
905 libntfs3g_global_init();
911 already_inited = true;
915 /* Free global memory allocations. Not strictly necessary if the process using
916 * wimlib is just about to exit (as is the case for 'imagex'). */
918 wimlib_global_cleanup(void)
920 libxml_global_cleanup();
921 iconv_global_cleanup();
923 win32_global_cleanup();