]> wimlib.net Git - wimlib/blobdiff - src/lookup_table.c
Fixes, comments
[wimlib] / src / lookup_table.c
index 064215ec0cf75529de50fe677ea758dbdd2fff5b..4d62ca5b29c7ede86bfd0fcfb460d40c60f425d9 100644 (file)
@@ -40,7 +40,7 @@ new_lookup_table(size_t capacity)
        struct wim_lookup_table *table;
        struct hlist_head *array;
 
-       table = MALLOC(sizeof(struct wim_lookup_table));
+       table = CALLOC(1, sizeof(struct wim_lookup_table));
        if (table) {
                array = CALLOC(capacity, sizeof(array[0]));
                if (array) {
@@ -215,7 +215,7 @@ finalize_lte(struct wim_lookup_table_entry *lte)
        #ifdef WITH_FUSE
        if (lte->resource_location == RESOURCE_IN_STAGING_FILE) {
                unlink(lte->staging_file_name);
-               list_del(&lte->staging_list);
+               list_del(&lte->unhashed_list);
        }
        #endif
        free_lookup_table_entry(lte);
@@ -232,7 +232,8 @@ lte_decrement_refcnt(struct wim_lookup_table_entry *lte,
        wimlib_assert(lte != NULL);
        wimlib_assert(lte->refcnt != 0);
        if (--lte->refcnt == 0) {
-               lookup_table_unlink(table, lte);
+               if (!lte->unhashed)
+                       lookup_table_unlink(table, lte);
        #ifdef WITH_FUSE
                if (lte->num_opened_fds == 0)
        #endif
@@ -267,14 +268,14 @@ for_lookup_table_entry(struct wim_lookup_table *table,
                {
                        wimlib_assert2(!(lte->resource_entry.flags & WIM_RESHDR_FLAG_METADATA));
                        ret = visitor(lte, arg);
-                       if (ret != 0)
+                       if (ret)
                                return ret;
                }
        }
        return 0;
 }
 
-static int
+int
 cmp_streams_by_wim_position(const void *p1, const void *p2)
 {
        const struct wim_lookup_table_entry *lte1, *lte2;
@@ -288,40 +289,6 @@ cmp_streams_by_wim_position(const void *p1, const void *p2)
                return 0;
 }
 
-int
-sort_stream_list_by_wim_position(struct list_head *stream_list)
-{
-       struct list_head *cur;
-       size_t num_streams;
-       struct wim_lookup_table_entry **array;
-       size_t i;
-       size_t array_size;
-
-       num_streams = 0;
-       list_for_each(cur, stream_list)
-               num_streams++;
-       array_size = num_streams * sizeof(array[0]);
-       array = MALLOC(array_size);
-       if (!array) {
-               ERROR("Failed to allocate %zu bytes to sort stream entries",
-                     array_size);
-               return WIMLIB_ERR_NOMEM;
-       }
-       cur = stream_list->next;
-       for (i = 0; i < num_streams; i++) {
-               array[i] = container_of(cur, struct wim_lookup_table_entry, staging_list);
-               cur = cur->next;
-       }
-
-       qsort(array, num_streams, sizeof(array[0]), cmp_streams_by_wim_position);
-
-       INIT_LIST_HEAD(stream_list);
-       for (i = 0; i < num_streams; i++)
-               list_add_tail(&array[i]->staging_list, stream_list);
-       FREE(array);
-       return 0;
-}
-
 
 static int
 add_lte_to_array(struct wim_lookup_table_entry *lte,
@@ -495,7 +462,7 @@ read_lookup_table(WIMStruct *w)
                              w->current_image + 1,
                              cur_entry->resource_entry.offset);
                        w->image_metadata[
-                               w->current_image++].metadata_lte = cur_entry;
+                               w->current_image++]->metadata_lte = cur_entry;
                } else {
                        /* Lookup table entry for a stream that is not a
                         * metadata resource */
@@ -597,7 +564,7 @@ write_lookup_table(WIMStruct *w, int image, struct resource_entry *out_res_entry
        for (int i = start_image; i <= end_image; i++) {
                struct wim_lookup_table_entry *metadata_lte;
 
-               metadata_lte = w->image_metadata[i - 1].metadata_lte;
+               metadata_lte = w->image_metadata[i - 1]->metadata_lte;
                metadata_lte->out_refcnt = 1;
                metadata_lte->output_resource_entry.flags |= WIM_RESHDR_FLAG_METADATA;
                ret = write_lookup_table_entry(metadata_lte, out);
@@ -666,9 +633,13 @@ print_lookup_table_entry(const struct wim_lookup_table_entry *lte, FILE *out)
        tfprintf(out, T("Part Number       = %hu\n"), lte->part_number);
        tfprintf(out, T("Reference Count   = %u\n"), lte->refcnt);
 
-       tfprintf(out, T("Hash              = 0x"));
-       print_hash(lte->hash, out);
-       tputc(T('\n'), out);
+       if (lte->unhashed) {
+               tfprintf(out, T("(Unhashed, back ptr at %p)\n"), lte->my_ptr);
+       } else {
+               tfprintf(out, T("Hash              = 0x"));
+               print_hash(lte->hash, out);
+               tputc(T('\n'), out);
+       }
 
        tfprintf(out, T("Flags             = "));
        u8 flags = lte->resource_entry.flags;
@@ -920,3 +891,15 @@ lookup_table_total_stream_size(struct wim_lookup_table *table)
        for_lookup_table_entry(table, lte_add_stream_size, &total_size);
        return total_size;
 }
+
+void
+free_lte_list(struct list_head *list)
+{
+       struct wim_lookup_table_entry *lte, *tmp;
+
+       list_for_each_entry_safe(lte, tmp, list, staging_list) {
+               DEBUG("%p", lte);
+               free_lookup_table_entry(lte);
+}
+       INIT_LIST_HEAD(list);
+}