+ ERROR("An inconsistent hard link group that cannot be corrected has "
+ "been detected");
+ ERROR("The dentries are located at the following paths:");
+#ifdef ENABLE_ERROR_MESSAGES
+ print_inode_dentries(inode);
+#endif
+}
+
+static bool ref_inodes_consistent(const struct wim_inode * restrict ref_inode_1,
+ const struct wim_inode * restrict ref_inode_2)
+{
+ wimlib_assert(ref_inode_1 != ref_inode_2);
+
+ if (ref_inode_1->i_num_ads != ref_inode_2->i_num_ads)
+ return false;
+ if (ref_inode_1->i_security_id != ref_inode_2->i_security_id
+ || ref_inode_1->i_attributes != ref_inode_2->i_attributes)
+ return false;
+ for (unsigned i = 0; i <= ref_inode_1->i_num_ads; i++) {
+ const u8 *ref_1_hash, *ref_2_hash;
+ ref_1_hash = inode_stream_hash(ref_inode_1, i);
+ ref_2_hash = inode_stream_hash(ref_inode_2, i);
+ if (!hashes_equal(ref_1_hash, ref_2_hash))
+ return false;
+ if (i && !ads_entries_have_same_name(&ref_inode_1->i_ads_entries[i - 1],
+ &ref_inode_2->i_ads_entries[i - 1]))
+ return false;
+
+ }
+ return true;
+}
+
+static bool inodes_consistent(const struct wim_inode * restrict ref_inode,
+ const struct wim_inode * restrict inode)
+{
+ wimlib_assert(ref_inode != inode);
+
+ if (ref_inode->i_num_ads != inode->i_num_ads &&
+ inode->i_num_ads != 0)
+ return false;
+ if (ref_inode->i_security_id != inode->i_security_id
+ || ref_inode->i_attributes != inode->i_attributes)
+ return false;
+ for (unsigned i = 0; i <= min(ref_inode->i_num_ads, inode->i_num_ads); i++) {
+ const u8 *ref_hash, *hash;
+ ref_hash = inode_stream_hash(ref_inode, i);
+ hash = inode_stream_hash(inode, i);
+ if (!hashes_equal(ref_hash, hash) && !is_zero_hash(hash))
+ return false;
+ if (i && !ads_entries_have_same_name(&ref_inode->i_ads_entries[i - 1],
+ &inode->i_ads_entries[i - 1]))
+ return false;
+ }
+ return true;
+}
+
+/* Fix up a "true" inode and check for inconsistencies */
+static int fix_true_inode(struct wim_inode *inode, struct hlist_head *inode_list)
+{
+ struct wim_dentry *dentry;
+ struct wim_dentry *ref_dentry = NULL;
+ struct wim_inode *ref_inode;
+ u64 last_ctime = 0;
+ u64 last_mtime = 0;
+ u64 last_atime = 0;
+
+ inode_for_each_dentry(dentry, inode) {
+ if (!ref_dentry || dentry->d_inode->i_num_ads > ref_dentry->d_inode->i_num_ads)
+ ref_dentry = dentry;
+ if (dentry->d_inode->i_creation_time > last_ctime)
+ last_ctime = dentry->d_inode->i_creation_time;
+ if (dentry->d_inode->i_last_write_time > last_mtime)
+ last_mtime = dentry->d_inode->i_last_write_time;
+ if (dentry->d_inode->i_last_access_time > last_atime)
+ last_atime = dentry->d_inode->i_last_access_time;
+ }
+
+ ref_inode = ref_dentry->d_inode;
+ ref_inode->i_nlink = 1;
+ hlist_add_head(&ref_inode->i_hlist, inode_list);
+
+ list_del(&inode->i_dentry);
+ list_add(&ref_inode->i_dentry, &ref_dentry->d_alias);
+
+ inode_for_each_dentry(dentry, ref_inode) {
+ if (dentry != ref_dentry) {
+ if (!inodes_consistent(ref_inode, dentry->d_inode)) {
+ inconsistent_inode(ref_inode);
+ return WIMLIB_ERR_INVALID_DENTRY;