+ for (size_t i = 0; i < table->capacity; i++)
+ id = assign_link_group_ids_to_list(table->array[i], id);
+
+ /* Assign link group IDs to the "extra" link groups and insert them into
+ * the hash table */
+ id = assign_link_group_ids_to_list(table->extra_groups, id);
+ insert_extra_groups(table);
+ return id;
+}
+
+
+
+static void inconsistent_link_group(const struct dentry *first_dentry)
+{
+ const struct dentry *dentry = first_dentry;
+
+ ERROR("An inconsistent hard link group that we cannot correct has been "
+ "detected");
+ ERROR("The dentries are located at the following paths:");
+ do {
+ ERROR("`%s'", dentry->full_path_utf8);
+ } while ((dentry = container_of(dentry->link_group_list.next,
+ struct dentry,
+ link_group_list)) != first_dentry);
+}
+
+static bool ref_dentries_consistent(const struct dentry * restrict ref_dentry_1,
+ const struct dentry * restrict ref_dentry_2)
+{
+ wimlib_assert(ref_dentry_1 != ref_dentry_2);
+
+ if (ref_dentry_1->num_ads != ref_dentry_2->num_ads)
+ return false;
+ if (ref_dentry_1->security_id != ref_dentry_2->security_id
+ || ref_dentry_1->attributes != ref_dentry_2->attributes)
+ return false;
+ for (unsigned i = 0; i <= ref_dentry_1->num_ads; i++) {
+ const u8 *ref_1_hash, *ref_2_hash;
+ ref_1_hash = dentry_stream_hash_unresolved(ref_dentry_1, i);
+ ref_2_hash = dentry_stream_hash_unresolved(ref_dentry_2, i);
+ if (!hashes_equal(ref_1_hash, ref_2_hash))
+ return false;
+ if (i && !ads_entries_have_same_name(&ref_dentry_1->ads_entries[i - 1],
+ &ref_dentry_2->ads_entries[i - 1]))
+ return false;
+
+ }
+ return true;
+}
+
+static bool dentries_consistent(const struct dentry * restrict ref_dentry,
+ const struct dentry * restrict dentry)
+{
+ wimlib_assert(ref_dentry != dentry);
+
+ if (ref_dentry->num_ads != dentry->num_ads && dentry->num_ads != 0)
+ return false;
+ if (ref_dentry->security_id != dentry->security_id
+ || ref_dentry->attributes != dentry->attributes)
+ return false;
+ for (unsigned i = 0; i <= min(ref_dentry->num_ads, dentry->num_ads); i++) {
+ const u8 *ref_hash, *hash;
+ ref_hash = dentry_stream_hash_unresolved(ref_dentry, i);
+ hash = dentry_stream_hash_unresolved(dentry, i);
+ if (!hashes_equal(ref_hash, hash) && !is_zero_hash(hash))
+ return false;
+ if (i && !ads_entries_have_same_name(&ref_dentry->ads_entries[i - 1],
+ &dentry->ads_entries[i - 1]))
+ return false;