X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Fhardlink.c;h=3f316f1d993d1f84fa9852fde53e9ec900ad3f09;hb=45d7e8a4f1740974e1dacd221676f9ec38c6b272;hp=23ae370fc029cb516e04c66f2a56025dd66a011f;hpb=ac0f66feae348981def9e4fcf0af84868ac0a731;p=wimlib diff --git a/src/hardlink.c b/src/hardlink.c index 23ae370f..3f316f1d 100644 --- a/src/hardlink.c +++ b/src/hardlink.c @@ -108,7 +108,7 @@ inode_table_insert(struct wim_dentry *dentry, void *_table) "\"%"TS"\" <=> \"%"TS"\"", dentry_full_path(dentry), dentry_full_path(inode_first_dentry(inode))); - return WIMLIB_ERR_INVALID_DENTRY; + return WIMLIB_ERR_INVALID_METADATA_RESOURCE; } inode_add_dentry(dentry, inode); return 0; @@ -209,25 +209,23 @@ inode_table_new_dentry(struct wim_inode_table *table, const tchar *name, return 0; } -#if defined(ENABLE_ERROR_MESSAGES) || defined(ENABLE_DEBUG) -static void +static inline void print_inode_dentries(const struct wim_inode *inode) { struct wim_dentry *dentry; inode_for_each_dentry(dentry, inode) tfprintf(stderr, T("%"TS"\n"), dentry_full_path(dentry)); } -#endif static void inconsistent_inode(const struct wim_inode *inode) { -#ifdef ENABLE_ERROR_MESSAGES - ERROR("An inconsistent hard link group that cannot be corrected has " - "been detected"); - ERROR("The dentries are located at the following paths:"); - print_inode_dentries(inode); -#endif + if (wimlib_print_errors) { + ERROR("An inconsistent hard link group that cannot be corrected has " + "been detected"); + ERROR("The dentries are located at the following paths:"); + print_inode_dentries(inode); + } } static bool @@ -313,7 +311,7 @@ fix_true_inode(struct wim_inode *inode, struct list_head *inode_list) if (dentry != ref_dentry) { if (!inodes_consistent(ref_inode, dentry->d_inode)) { inconsistent_inode(ref_inode); - return WIMLIB_ERR_INVALID_DENTRY; + return WIMLIB_ERR_INVALID_METADATA_RESOURCE; } /* Free the unneeded `struct wim_inode'. */ wimlib_assert(dentry->d_inode->i_nlink == 1); @@ -351,7 +349,6 @@ fix_nominal_inode(struct wim_inode *inode, struct list_head *inode_list, struct hlist_node *cur, *tmp; int ret; size_t num_true_inodes; - unsigned nominal_group_size = inode_link_count(inode); LIST_HEAD(dentries_with_data_streams); LIST_HEAD(dentries_with_no_data_streams); @@ -380,6 +377,7 @@ fix_nominal_inode(struct wim_inode *inode, struct list_head *inode_list, * inode to be a true inode */ if (list_empty(&dentries_with_data_streams)) { #ifdef ENABLE_DEBUG + unsigned nominal_group_size = inode_link_count(inode); if (nominal_group_size > 1) { DEBUG("Found link group of size %u without " "any data streams:", nominal_group_size); @@ -422,13 +420,13 @@ next_dentry_2: * streamless dentries to. */ if (!list_empty(&dentries_with_no_data_streams)) { if (num_true_inodes != 1) { - ERROR("Hard inode ambiguity detected!"); + ERROR("Hard link ambiguity detected!"); ERROR("We split up inode 0x%"PRIx64" due to " "inconsistencies,", inode->i_ino); ERROR("but dentries with no stream information remained. " "We don't know which inode"); ERROR("to assign them to."); - ret = WIMLIB_ERR_INVALID_DENTRY; + ret = WIMLIB_ERR_INVALID_METADATA_RESOURCE; goto out_cleanup_true_inode_list; } inode = container_of(true_inodes.first, struct wim_inode, i_hlist); @@ -516,9 +514,13 @@ fix_inodes(struct wim_inode_table *table, struct list_head *inode_list, * WIM) is examined for consistency and may be split into multiple "true" inodes * that are maximally sized consistent sets of dentries. * - * Return 0 on success; WIMLIB_ERR_NOMEM or WIMLIB_ERR_INVALID_DENTRY on - * failure. On success, the list of "true" inodes, linked by the i_hlist field, + * On success, the list of "true" inodes, linked by the i_hlist field, * is returned in the hlist @inode_list. + * + * Return values: + * WIMLIB_ERR_SUCCESS (0) + * WIMLIB_ERR_INVALID_METADATA_RESOURCE + * WIMLIB_ERR_NOMEM */ int dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list) @@ -583,31 +585,31 @@ void inode_table_prepare_inode_list(struct wim_inode_table *table, struct list_head *head) { - struct wim_inode *inode; + struct wim_inode *inode, *tmp_inode; struct hlist_node *cur, *tmp; u64 cur_ino = 1; /* Re-assign inode numbers in the existing list to avoid duplicates. */ - list_for_each_entry(inode, head, i_list) { - if (inode->i_nlink > 1) - inode->i_ino = cur_ino++; - else - inode->i_ino = 0; - } + list_for_each_entry(inode, head, i_list) + 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) { - if (inode->i_nlink > 1) - inode->i_ino = cur_ino++; - else - inode->i_ino = 0; + inode->i_ino = cur_ino++; + inode->i_devno = 0; list_add_tail(&inode->i_list, head); } INIT_HLIST_HEAD(&table->array[i]); } - list_splice_tail(&table->extra_inodes, head); + list_for_each_entry_safe(inode, tmp_inode, &table->extra_inodes, i_list) + { + inode->i_ino = cur_ino++; + inode->i_devno = 0; + list_add_tail(&inode->i_list, head); + } + INIT_LIST_HEAD(&table->extra_inodes); table->num_entries = 0; }