]> wimlib.net Git - wimlib/blobdiff - src/lookup_table.c
link_group_set_stream_hash(), staging_list
[wimlib] / src / lookup_table.c
index 4df37ea2eb343ea2e2239e48c3e5316326a251d3..d3ed585445a225f53b91e82e7d437d127f9560ee 100644 (file)
@@ -27,6 +27,7 @@
 #include "wimlib_internal.h"
 #include "lookup_table.h"
 #include "io.h"
+#include <errno.h>
 
 struct lookup_table *new_lookup_table(size_t capacity)
 {
@@ -69,6 +70,15 @@ struct lookup_table_entry *new_lookup_table_entry()
 }
 
 
+void free_lookup_table_entry(struct lookup_table_entry *lte)
+{
+       if (lte) {
+               if (lte->staging_list.next)
+                       list_del(&lte->staging_list);
+               FREE(lte->file_on_disk);
+               FREE(lte);
+       }
+}
 
 /*
  * Inserts an entry into the lookup table.
@@ -261,7 +271,8 @@ int write_lookup_table_entry(struct lookup_table_entry *lte, void *__out)
                return 0;
 
        if (lte->output_resource_entry.flags & WIM_RESHDR_FLAG_METADATA)
-               DEBUG("Writing metadata entry at %lu", ftello(out));
+               DEBUG("Writing metadata entry at %lu (orig size = %zu)",
+                     ftello(out), lte->output_resource_entry.original_size);
 
        p = put_resource_entry(buf, &lte->output_resource_entry);
        p = put_u16(p, lte->part_number);
@@ -360,11 +371,12 @@ int lookup_resource(WIMStruct *w, const char *path,
                    int lookup_flags,
                    struct dentry **dentry_ret,
                    struct lookup_table_entry **lte_ret,
-                   u8 **hash_ret)
+                   unsigned *stream_idx_ret)
 {
        struct dentry *dentry = get_dentry(w, path);
        struct lookup_table_entry *lte;
-       u8 *hash;
+       unsigned stream_idx = 0;
+       const u8 *hash = dentry->hash;
        if (!dentry)
                return -ENOENT;
        if (!(lookup_flags & LOOKUP_FLAG_DIRECTORY_OK)
@@ -379,6 +391,7 @@ int lookup_resource(WIMStruct *w, const char *path,
                                                       stream_name,
                                                       stream_name_len))
                                {
+                                       stream_idx = i + 1;
                                        hash = dentry->ads_entries[i].hash;
                                        goto do_lookup;
                                }
@@ -386,14 +399,13 @@ int lookup_resource(WIMStruct *w, const char *path,
                        return -ENOENT;
                }
        }
-       hash = dentry->hash;
 do_lookup:
        lte = __lookup_resource(w->lookup_table, hash);
        if (dentry_ret)
                *dentry_ret = dentry;
        if (lte_ret)
                *lte_ret = lte;
-       if (hash_ret)
-               *hash_ret = hash;
+       if (stream_idx_ret)
+               *stream_idx_ret = stream_idx;
        return 0;
 }