- /* Make sure all the expected images were found. (We already have
- * returned false if *extra* images were found) */
- if (w->current_image != w->hdr.image_count &&
- w->hdr.part_number == 1)
- {
- ERROR("Only found %u images in WIM, but expected %u",
- w->current_image, w->hdr.image_count);
- return WIMLIB_ERR_IMAGE_COUNT;
+ ret = begin_read(wim, wim_filename_or_fd, open_flags, progress_func);
+ if (ret)
+ goto out_wimlib_free;
+
+ ret = 0;
+ *wim_ret = wim;
+ goto out;
+out_wimlib_free:
+ wimlib_free(wim);
+out:
+ return ret;
+}
+
+/* API function documented in wimlib.h */
+WIMLIBAPI int
+wimlib_open_wim(const tchar *wimfile, int open_flags,
+ WIMStruct **wim_ret, wimlib_progress_func_t progress_func)
+{
+ open_flags &= WIMLIB_OPEN_MASK_PUBLIC;
+ return open_wim_as_WIMStruct(wimfile, open_flags, wim_ret,
+ progress_func);
+}
+
+void
+destroy_image_metadata(struct wim_image_metadata *imd,
+ struct wim_lookup_table *table,
+ bool free_metadata_lte)
+{
+ free_dentry_tree(imd->root_dentry, table);
+ imd->root_dentry = NULL;
+ free_wim_security_data(imd->security_data);
+ imd->security_data = NULL;
+
+ if (free_metadata_lte) {
+ free_lookup_table_entry(imd->metadata_lte);
+ imd->metadata_lte = NULL;
+ }
+ if (!table) {
+ struct wim_lookup_table_entry *lte, *tmp;
+ list_for_each_entry_safe(lte, tmp, &imd->unhashed_streams, unhashed_list)
+ free_lookup_table_entry(lte);
+ }
+ INIT_LIST_HEAD(&imd->unhashed_streams);
+ INIT_LIST_HEAD(&imd->inode_list);
+#ifdef WITH_NTFS_3G
+ if (imd->ntfs_vol) {
+ do_ntfs_umount(imd->ntfs_vol);
+ imd->ntfs_vol = NULL;