X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fwim.c;h=38792a59c7b406c114c9f8295cd405a5ad4ba37a;hp=89b0156c82e1d5365d2cc6b564563c7fed116c47;hb=9e56d04309e3e6a896319225288f0c86bd36d34e;hpb=1530b6dab02a9e1e5faf81529ab502aee68d8cd2 diff --git a/src/wim.c b/src/wim.c index 89b0156c..38792a59 100644 --- a/src/wim.c +++ b/src/wim.c @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2012 Eric Biggers + * Copyright (C) 2012, 2013 Eric Biggers * * wimlib - Library for working with WIM files * @@ -107,8 +107,8 @@ int for_image(WIMStruct *w, int image, int (*visitor)(WIMStruct *)) static int sort_image_metadata_by_position(const void *p1, const void *p2) { - const struct image_metadata *imd1 = p1; - const struct image_metadata *imd2 = p2; + const struct wim_image_metadata *imd1 = p1; + const struct wim_image_metadata *imd2 = p2; u64 offset1 = imd1->metadata_lte->resource_entry.offset; u64 offset2 = imd2->metadata_lte->resource_entry.offset; if (offset1 < offset2) @@ -203,7 +203,8 @@ WIMLIBAPI int wimlib_get_num_images(const WIMStruct *w) int select_wim_image(WIMStruct *w, int image) { - struct image_metadata *imd; + struct wim_image_metadata *imd; + int ret; DEBUG("Selecting image %d", image); @@ -233,20 +234,21 @@ int select_wim_image(WIMStruct *w, int image) INIT_HLIST_HEAD(&imd->inode_list); } } - w->current_image = image; - imd = wim_get_current_image_metadata(w); - + imd = &w->image_metadata[image - 1]; if (imd->root_dentry) { - return 0; + ret = 0; } else { #ifdef ENABLE_DEBUG DEBUG("Reading metadata resource specified by the following " "lookup table entry:"); - print_lookup_table_entry(imd->metadata_lte); + print_lookup_table_entry(imd->metadata_lte, stdout); #endif - return read_metadata_resource(w, imd); + ret = read_metadata_resource(w, imd); + if (ret) + w->current_image = WIMLIB_NO_IMAGE; } + return ret; } @@ -495,7 +497,7 @@ static int begin_read(WIMStruct *w, const char *in_wim_path, int open_flags, if (w->hdr.image_count != 0) { w->image_metadata = CALLOC(w->hdr.image_count, - sizeof(struct image_metadata)); + sizeof(struct wim_image_metadata)); if (!w->image_metadata) { ERROR("Failed to allocate memory for %u image metadata structures", @@ -515,7 +517,7 @@ static int begin_read(WIMStruct *w, const char *in_wim_path, int open_flags, return ret; /* Make sure all the expected images were found. (We already have - * returned false if *extra* images were found) */ + * returned WIMLIB_ERR_IMAGE_COUNT if *extra* images were found) */ if (w->current_image != w->hdr.image_count && w->hdr.part_number == 1) { @@ -529,7 +531,7 @@ static int begin_read(WIMStruct *w, const char *in_wim_path, int open_flags, * file, rather than their order in the lookup table, which is random * because of hashing. */ qsort(w->image_metadata, w->current_image, - sizeof(struct image_metadata), sort_image_metadata_by_position); + sizeof(struct wim_image_metadata), sort_image_metadata_by_position); w->current_image = WIMLIB_NO_IMAGE; @@ -579,7 +581,7 @@ WIMLIBAPI int wimlib_open_wim(const char *wim_file, int open_flags, return ret; } -void destroy_image_metadata(struct image_metadata *imd, +void destroy_image_metadata(struct wim_image_metadata *imd, struct wim_lookup_table *table) { free_dentry_tree(imd->root_dentry, table); @@ -634,3 +636,19 @@ WIMLIBAPI void wimlib_free(WIMStruct *w) #endif FREE(w); } + +/* Get global memory allocations out of the way. Not strictly necessary in + * single-threaded programs like 'imagex'. */ +WIMLIBAPI int wimlib_global_init() +{ + libxml_global_init(); + return iconv_global_init(); +} + +/* Free global memory allocations. Not strictly necessary if the process using + * wimlib is just about to exit (as is the case for 'imagex'). */ +WIMLIBAPI void wimlib_global_cleanup() +{ + libxml_global_cleanup(); + iconv_global_cleanup(); +}