From: Eric Biggers Date: Wed, 22 May 2013 02:43:13 +0000 (-0500) Subject: Detect directory hard links as early as possible X-Git-Tag: v1.4.1~42 X-Git-Url: https://wimlib.net/git/?p=wimlib;a=commitdiff_plain;h=86a767c28bfb9df8921ef9ff61a32c971beb51aa;ds=sidebyside Detect directory hard links as early as possible --- diff --git a/src/hardlink.c b/src/hardlink.c index 5e2c6261..042b0576 100644 --- a/src/hardlink.c +++ b/src/hardlink.c @@ -105,6 +105,15 @@ inode_table_insert(struct wim_dentry *dentry, void *_table) pos = d_inode->i_ino % table->capacity; hlist_for_each_entry(inode, cur, &table->array[pos], i_hlist) { if (inode->i_ino == d_inode->i_ino) { + if (unlikely((inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) || + (d_inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY))) + { + ERROR("Unsupported directory hard link " + "\"%"TS"\" <=> \"%"TS"\"", + dentry_full_path(dentry), + dentry_full_path(inode_first_dentry(inode))); + return WIMLIB_ERR_INVALID_DENTRY; + } inode_add_dentry(dentry, inode); inode->i_nlink++; return 0; @@ -522,16 +531,19 @@ dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list) DEBUG("Inserting dentries into inode table"); ret = init_inode_table(&inode_tab, 9001); if (ret) - return ret; + goto out; - for_dentry_in_tree(root, inode_table_insert, &inode_tab); + ret = for_dentry_in_tree(root, inode_table_insert, &inode_tab); + if (ret) + goto out_destroy_image_table; DEBUG("Cleaning up the hard link groups"); ino_changes_needed = false; ret = fix_inodes(&inode_tab, inode_list, &ino_changes_needed); - destroy_inode_table(&inode_tab); + if (ret) + goto out_destroy_image_table; - if (ret == 0 && ino_changes_needed) { + if (ino_changes_needed) { u64 cur_ino = 1; struct wim_inode *inode; @@ -543,6 +555,10 @@ dentry_tree_fix_inodes(struct wim_dentry *root, struct list_head *inode_list) inode->i_ino = 0; } } + ret = 0; +out_destroy_image_table: + destroy_inode_table(&inode_tab); +out: return ret; } diff --git a/src/verify.c b/src/verify.c index a4fb17c0..3085e6a6 100644 --- a/src/verify.c +++ b/src/verify.c @@ -114,13 +114,6 @@ verify_inode(struct wim_inode *inode, const WIMStruct *w) } } - /* Directories with multiple links have not been tested. XXX */ - if (inode->i_nlink > 1 && inode->i_attributes & FILE_ATTRIBUTE_DIRECTORY) { - ERROR("Hard-linked directory `%"TS"' is unsupported", - dentry_full_path(first_dentry)); - return WIMLIB_ERR_INVALID_DENTRY; - } - inode->i_verified = 1; return 0; }