static int print_metadata(WIMStruct *w)
{
-#if 0
+#ifdef ENABLE_SECURITY_DATA
print_security_data(wim_security_data(w));
#endif
return for_dentry_in_tree(wim_root_dentry(w), print_dentry,
NULL);
}
-static WIMStruct *new_wim_struct()
+WIMStruct *new_wim_struct()
{
WIMStruct *w;
DEBUG("Freeing image %u\n", w->current_image);
imd = wim_get_current_image_metadata(w);
free_dentry_tree(imd->root_dentry, NULL, false);
-#if 0
- destroy_security_data(&imd->security_data);
-#endif
imd->root_dentry = NULL;
+#ifdef ENABLE_SECURITY_DATA
+ free_security_data(imd->security_data);
+ imd->security_data = NULL;
+#endif
}
w->current_image = image;
- if (wim_root_dentry(w))
+ if (wim_root_dentry(w)) {
return 0;
- else
+ } else {
+ #ifdef ENABLE_DEBUG
+ DEBUG("Reading metadata resource specified by the following "
+ "lookup table entry:\n");
+ print_lookup_table_entry(wim_metadata_lookup_table_entry(w), NULL);
+ #endif
return read_metadata_resource(w->fp,
wim_metadata_resource_entry(w),
wimlib_get_compression_type(w),
- /*wim_security_data(w), */
- wim_root_dentry_p(w));
+ wim_get_current_image_metadata(w));
+ }
}
printf("Image Count: %d\n", hdr->image_count);
printf("Compression: %s\n", wimlib_get_compression_type_string(
wimlib_get_compression_type(w)));
- printf("Part Number: %d/%d\n", 1, 1);
+ printf("Part Number: %d/%d\n", hdr->part_number, hdr->total_parts);
printf("Boot Index: %d\n", hdr->boot_idx);
printf("Size: %"PRIu64" bytes\n",
wim_info_get_total_bytes(w->wim_info));
return 0;
}
+WIMLIBAPI int wimlib_get_part_number(const WIMStruct *w, int *total_parts_ret)
+{
+ if (total_parts_ret)
+ *total_parts_ret = w->hdr.total_parts;
+ return w->hdr.part_number;
+}
+
+
WIMLIBAPI int wimlib_get_boot_idx(const WIMStruct *w)
{
return w->hdr.boot_idx;
* Begins the reading of a WIM file; opens the file and reads its header and
* lookup table, and optionally checks the integrity.
*/
-static int wim_begin_read(WIMStruct *w, const char *in_wim_path, int flags)
+static int begin_read(WIMStruct *w, const char *in_wim_path, int flags)
{
int ret;
uint xml_num_images;
goto done;
}
- ret = read_header(w->fp, &w->hdr);
+ ret = read_header(w->fp, &w->hdr, flags & WIMLIB_OPEN_FLAG_SPLIT_OK);
if (ret != 0)
goto done;
/* If the boot index is invalid, print a warning and set it to 0 */
if (w->hdr.boot_idx > w->hdr.image_count) {
- ERROR("WARNING: In `%s', image %u is marked as bootable,\n",
- in_wim_path, w->hdr.boot_idx);
- ERROR(" but there are only %u images!\n",
- w->hdr.image_count);
+ WARNING("In `%s', image %u is marked as bootable,\n"
+ "\tbut there are only %u images!\n",
+ in_wim_path, w->hdr.boot_idx, w->hdr.image_count);
w->hdr.boot_idx = 0;
}
goto done;
}
if (integrity_status == WIM_INTEGRITY_NONEXISTENT) {
- DEBUG("WARNING: No integrity information; skipping "
- "integrity check.\n");
+ WARNING("No integrity information for `%s'; skipping "
+ "integrity check.\n", w->filename);
} else if (integrity_status == WIM_INTEGRITY_NOT_OK) {
ERROR("WIM is not intact! (Failed integrity check)\n");
ret = WIMLIB_ERR_INTEGRITY;
ret = for_lookup_table_entry(w->lookup_table,
append_metadata_resource_entry, w);
- if (ret != 0)
+ if (ret != 0 && w->hdr.part_number == 1)
goto done;
/* 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) {
+ if (w->current_image != w->hdr.image_count && w->hdr.part_number == 1) {
ERROR("Only found %u images in WIM, but expected %u!\n",
w->current_image, w->hdr.image_count);
ret = WIMLIB_ERR_IMAGE_COUNT;
goto done;
}
- w->current_image = WIM_NO_IMAGE;
/* Sort images by the position of their metadata resources. I'm
* assuming that is what determines the other of the images in the WIM
* file, rather than their order in the lookup table, which may be
* random because of hashing. */
- qsort(w->image_metadata, w->hdr.image_count,
+ qsort(w->image_metadata, w->current_image,
sizeof(struct image_metadata), sort_image_metadata_by_position);
+ w->current_image = WIM_NO_IMAGE;
+
/* Read the XML data. */
ret = read_xml_data(w->fp, &w->hdr.xml_res_entry,
&w->xml_data, &w->wim_info);
if (!w)
return WIMLIB_ERR_NOMEM;
- ret = wim_begin_read(w, wim_file, flags);
+ ret = begin_read(w, wim_file, flags);
if (ret != 0) {
ERROR("Could not begin reading the WIM file `%s'\n", wim_file);
FREE(w);
return 0;
}
-/**
- * Frees internal memory allocated by WIMLIB for a WIM file, and closes it if it
- * is still open.
- */
-void wimlib_destroy(WIMStruct *w)
-{
-
-}
-
/* Frees the memory for the WIMStruct, including all internal memory; also
* closes all files associated with the WIMStruct. */
WIMLIBAPI void wimlib_free(WIMStruct *w)
FREE(w->xml_data);
free_wim_info(w->wim_info);
if (w->image_metadata) {
- for (i = 0; i < w->hdr.image_count; i++)
+ for (i = 0; i < w->hdr.image_count; i++) {
free_dentry_tree(w->image_metadata[i].root_dentry,
NULL, false);
+ #ifdef ENABLE_SECURITY_DATA
+ free_security_data(w->image_metadata[i].security_data);
+ #endif
+ }
FREE(w->image_metadata);
}
FREE(w);