]> wimlib.net Git - wimlib/blobdiff - src/inode_fixup.c
inode_fixup: don't warn about inode corrections
[wimlib] / src / inode_fixup.c
index 115779a410564c1e0c6bbeb937af907802313e76..8e1579db014617ac94bad6778d83ce3409453d9b 100644 (file)
@@ -5,20 +5,18 @@
 /*
  * Copyright (C) 2012, 2013, 2014 Eric Biggers
  *
- * This file is part of wimlib, a library for working with WIM files.
+ * This file is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option) any
+ * later version.
  *
- * wimlib is free software; you can redistribute it and/or modify it under the
- * terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option)
- * any later version.
- *
- * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * This file is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  * details.
  *
- * You should have received a copy of the GNU General Public License
- * along with wimlib; if not, see http://www.gnu.org/licenses/.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this file; if not, see http://www.gnu.org/licenses/.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -29,7 +27,6 @@
 #include "wimlib/error.h"
 #include "wimlib/inode.h"
 #include "wimlib/inode_table.h"
-#include "wimlib/lookup_table.h"
 
 struct inode_fixup_params {
        struct wim_inode_table inode_table;
@@ -56,8 +53,8 @@ inodes_consistent(const struct wim_inode *inode_1,
         * doesn't link the dentries.)
         *
         * For non-buggy WIMs this function will always return true.  */
-       return hashes_equal(inode_unnamed_stream_hash(inode_1),
-                           inode_unnamed_stream_hash(inode_2));
+       return hashes_equal(inode_get_hash_of_unnamed_data_stream(inode_1),
+                           inode_get_hash_of_unnamed_data_stream(inode_2));
 }
 
 static int
@@ -68,16 +65,15 @@ inode_table_insert(struct wim_dentry *dentry, void *_params)
        struct wim_inode *d_inode = dentry->d_inode;
        size_t pos;
        struct wim_inode *inode;
-       struct hlist_node *cur;
 
        if (d_inode->i_ino == 0) {
-               list_add_tail(&d_inode->i_list, &table->extra_inodes);
+               hlist_add_head(&d_inode->i_hlist_node, &table->extra_inodes);
                return 0;
        }
 
        /* Try adding this dentry to an existing inode.  */
-       pos = d_inode->i_ino % table->capacity;
-       hlist_for_each_entry(inode, cur, &table->array[pos], i_hlist) {
+       pos = hash_inode(table, d_inode->i_ino, 0);
+       hlist_for_each_entry(inode, &table->array[pos], i_hlist_node) {
                if (inode->i_ino != d_inode->i_ino) {
                        continue;
                }
@@ -95,7 +91,7 @@ inode_table_insert(struct wim_dentry *dentry, void *_params)
                                WARNING("Unsupported directory hard link "
                                        "\"%"TS"\" <=> \"%"TS"\"",
                                        dentry_full_path(dentry),
-                                       inode_first_full_path(inode));
+                                       inode_any_full_path(inode));
                        } else if (params->num_dir_hard_links ==
                                   MAX_DIR_HARD_LINK_WARNINGS + 1)
                        {
@@ -105,44 +101,47 @@ inode_table_insert(struct wim_dentry *dentry, void *_params)
                        continue;
                }
                /* Transfer this dentry to the existing inode.  */
-               free_inode(d_inode);
-               dentry->d_inode = inode;
-               inode->i_nlink++;
-               inode_add_dentry(dentry, inode);
+               d_disassociate(dentry);
+               d_associate(dentry, inode);
                return 0;
        }
 
        /* Keep this dentry's inode.  */
-       hlist_add_head(&d_inode->i_hlist, &table->array[pos]);
+       hlist_add_head(&d_inode->i_hlist_node, &table->array[pos]);
+       if (++table->filled > table->capacity)
+               enlarge_inode_table(table);
        return 0;
 }
 
+static void
+hlist_move_all(struct hlist_head *src, struct hlist_head *dest)
+{
+       struct hlist_node *node;
+
+       while ((node = src->first) != NULL) {
+               hlist_del(node);
+               hlist_add_head(node, dest);
+       }
+}
+
 /* Move the inodes from the 'struct wim_inode_table' to the 'inode_list'.  */
 static void
 build_inode_list(struct wim_inode_table *inode_table,
-                struct list_head *inode_list)
+                struct hlist_head *inode_list)
 {
-       list_splice(&inode_table->extra_inodes, inode_list);
-       for (size_t i = 0; i < inode_table->capacity; i++) {
-               while (!hlist_empty(&inode_table->array[i])) {
-                       struct wim_inode *inode;
-
-                       inode = hlist_entry(inode_table->array[i].first,
-                                           struct wim_inode, i_hlist);
-                       hlist_del(&inode->i_hlist);
-                       list_add(&inode->i_list, inode_list);
-               }
-       }
+       hlist_move_all(&inode_table->extra_inodes, inode_list);
+       for (size_t i = 0; i < inode_table->capacity; i++)
+               hlist_move_all(&inode_table->array[i], inode_list);
 }
 
 /* Re-assign inode numbers to the inodes in the list.  */
 static void
-reassign_inode_numbers(struct list_head *inode_list)
+reassign_inode_numbers(struct hlist_head *inode_list)
 {
        struct wim_inode *inode;
        u64 cur_ino = 1;
 
-       list_for_each_entry(inode, inode_list, i_list)
+       hlist_for_each_entry(inode, inode_list, i_hlist_node)
                inode->i_ino = cur_ino++;
 }
 
@@ -171,14 +170,14 @@ reassign_inode_numbers(struct list_head *inode_list)
  * i_ino fields.
  */
 int
-dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list)
+dentry_tree_fix_inodes(struct wim_dentry *root, struct hlist_head *inode_list)
 {
        struct inode_fixup_params params;
        int ret;
 
        /* We use a hash table to map inode numbers to inodes.  */
 
-       ret = init_inode_table(&params.inode_table, 9001);
+       ret = init_inode_table(&params.inode_table, 64);
        if (ret)
                return ret;
 
@@ -192,10 +191,6 @@ dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list)
        build_inode_list(&params.inode_table, inode_list);
        destroy_inode_table(&params.inode_table);
 
-       if (unlikely(params.num_inconsistent_inodes))
-               WARNING("Fixed %lu invalid hard links in WIM image",
-                       params.num_inconsistent_inodes);
-
        if (unlikely(params.num_dir_hard_links))
                WARNING("Ignoring %lu directory hard links",
                        params.num_dir_hard_links);