]> wimlib.net Git - wimlib/blobdiff - src/inode_table.c
New helper: wim_reshdr_to_desc_and_blob()
[wimlib] / src / inode_table.c
index f6de4e6047ab7ec8ce4555fad223ab9b936dffe2..86e3155fdc82f995a2b2a1d034449e270cdae7f3 100644 (file)
@@ -39,7 +39,7 @@ init_inode_table(struct wim_inode_table *table, size_t capacity)
                return WIMLIB_ERR_NOMEM;
        table->num_entries = 0;
        table->capacity = capacity;
-       INIT_LIST_HEAD(&table->extra_inodes);
+       INIT_HLIST_HEAD(&table->extra_inodes);
        return 0;
 }
 
@@ -96,44 +96,33 @@ inode_table_new_dentry(struct wim_inode_table *table, const tchar *name,
        if (noshare) {
                /* File that cannot be hardlinked--- Return a new inode with its
                 * inode and device numbers left at 0. */
-               ret = new_dentry_with_timeless_inode(name, &dentry);
+               ret = new_dentry_with_new_inode(name, false, &dentry);
                if (ret)
                        return ret;
-               list_add_tail(&dentry->d_inode->i_list, &table->extra_inodes);
+               hlist_add_head(&dentry->d_inode->i_hlist, &table->extra_inodes);
        } else {
                size_t pos;
-               struct hlist_node *cur;
 
                /* File that can be hardlinked--- search the table for an
-                * existing inode matching the inode number and device;
-                * otherwise create a new inode. */
-               ret = new_dentry(name, &dentry);
-               if (ret)
-                       return ret;
-
-               /* Search for an existing inode having the same inode number and
-                * device number.  */
+                * existing inode matching the inode number and device.  */
                pos = hash_u64(hash_u64(ino) + hash_u64(devno)) % table->capacity;
-               hlist_for_each_entry(inode, cur, &table->array[pos], i_hlist) {
+               hlist_for_each_entry(inode, &table->array[pos], i_hlist) {
                        if (inode->i_ino == ino && inode->i_devno == devno) {
                                /* Found; use the existing inode.  */
-                               inode_ref_blobs(inode);
-                               goto have_inode;
+                               return new_dentry_with_existing_inode(name, inode,
+                                                                     dentry_ret);
                        }
                }
 
-               /* Create a new inode and insert it into the table.  */
-               inode = new_timeless_inode();
-               if (!inode) {
-                       free_dentry(dentry);
-                       return WIMLIB_ERR_NOMEM;
-               }
+               /* Not found; create a new inode and add it to the table.  */
+               ret = new_dentry_with_new_inode(name, false, &dentry);
+               if (ret)
+                       return ret;
+               inode = dentry->d_inode;
                inode->i_ino = ino;
                inode->i_devno = devno;
                hlist_add_head(&inode->i_hlist, &table->array[pos]);
                table->num_entries++;
-       have_inode:
-               d_associate(dentry, inode);
        }
        *dentry_ret = dentry;
        return 0;
@@ -147,33 +136,31 @@ inode_table_new_dentry(struct wim_inode_table *table, const tchar *name,
  */
 void
 inode_table_prepare_inode_list(struct wim_inode_table *table,
-                              struct list_head *head)
+                              struct hlist_head *head)
 {
-       struct wim_inode *inode, *tmp_inode;
-       struct hlist_node *cur, *tmp;
+       struct wim_inode *inode;
+       struct hlist_node *tmp;
        u64 cur_ino = 1;
 
        /* Re-assign inode numbers in the existing list to avoid duplicates. */
-       list_for_each_entry(inode, head, i_list)
+       hlist_for_each_entry(inode, head, i_hlist)
                inode->i_ino = cur_ino++;
 
        /* Assign inode numbers to the new inodes and move them to the image's
         * inode list. */
        for (size_t i = 0; i < table->capacity; i++) {
-               hlist_for_each_entry_safe(inode, cur, tmp, &table->array[i], i_hlist)
-               {
+               hlist_for_each_entry_safe(inode, tmp, &table->array[i], i_hlist) {
                        inode->i_ino = cur_ino++;
                        inode->i_devno = 0;
-                       list_add_tail(&inode->i_list, head);
+                       hlist_add_head(&inode->i_hlist, head);
                }
                INIT_HLIST_HEAD(&table->array[i]);
        }
-       list_for_each_entry_safe(inode, tmp_inode, &table->extra_inodes, i_list)
-       {
+       hlist_for_each_entry_safe(inode, tmp, &table->extra_inodes, i_hlist) {
                inode->i_ino = cur_ino++;
                inode->i_devno = 0;
-               list_add_tail(&inode->i_list, head);
+               hlist_add_head(&inode->i_hlist, head);
        }
-       INIT_LIST_HEAD(&table->extra_inodes);
+       INIT_HLIST_HEAD(&table->extra_inodes);
        table->num_entries = 0;
 }