+/* Fix up a "true" inode and check for inconsistencies */
+static int
+fix_true_inode(struct wim_inode *inode, struct list_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;
+ list_add_tail(&ref_inode->i_list, 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;
+ }
+ /* Free the unneeded `struct wim_inode'. */
+ free_inode(dentry->d_inode);
+ dentry->d_inode = ref_inode;
+ ref_inode->i_nlink++;
+ }
+ }
+ ref_inode->i_creation_time = last_ctime;
+ ref_inode->i_last_write_time = last_mtime;
+ ref_inode->i_last_access_time = last_atime;
+ wimlib_assert(inode_link_count(ref_inode) == ref_inode->i_nlink);
+ return 0;
+}
+
+/*
+ * Fixes up a nominal inode.
+ *
+ * By a nominal inode we mean a group of two or more dentries that share the
+ * same hard link group ID.
+ *
+ * If dentries in the inode are found to be inconsistent, we may split the inode
+ * into several "true" inodes.
+ *
+ * After splitting up each nominal inode into the "true" inodes we will
+ * canonicalize the link group by getting rid of all the unnecessary `struct
+ * wim_inode's. There will be just one `struct wim_inode' for each hard link
+ * group remaining.
+ */
+static int
+fix_nominal_inode(struct wim_inode *inode, struct list_head *inode_list,
+ bool *ino_changes_needed)