X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fdentry.c;h=a90934672185d69ad67221d8f53fb007c81a4fb5;hp=b371d31adc9b305231189c8ece6d715f12c563f1;hb=0c2a83873e2c1e9ecea018227b14677aa29dc574;hpb=dfd4355cb99cfcbdfd8b120c52c32df674e787f9 diff --git a/src/dentry.c b/src/dentry.c index b371d31a..a9093467 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -998,10 +998,13 @@ dentry_tree_clear_inode_visited(struct wim_dentry *root) for_dentry_in_tree(root, dentry_clear_inode_visited, NULL); } -/* Frees a WIM dentry. +/* + * Free a WIM dentry. * - * The corresponding inode (if any) is freed only if its link count is - * decremented to 0. */ + * In addition to freeing the dentry itself, this decrements the link count of + * the corresponding inode (if any). If the inode's link count reaches 0, the + * inode is freed as well. + */ void free_dentry(struct wim_dentry *dentry) { @@ -1015,23 +1018,17 @@ free_dentry(struct wim_dentry *dentry) } } -/* This function is passed as an argument to for_dentry_in_tree_depth() in order - * to free a directory tree. */ static int -do_free_dentry(struct wim_dentry *dentry, void *_lookup_table) +do_free_dentry(struct wim_dentry *dentry, void *_ignore) { - struct wim_lookup_table *lookup_table = _lookup_table; - - if (lookup_table) { - struct wim_inode *inode = dentry->d_inode; - for (unsigned i = 0; i <= inode->i_num_ads; i++) { - struct wim_lookup_table_entry *lte; + free_dentry(dentry); + return 0; +} - lte = inode_stream_lte(inode, i, lookup_table); - if (lte) - lte_decrement_refcnt(lte, lookup_table); - } - } +static int +do_free_dentry_and_unref_streams(struct wim_dentry *dentry, void *lookup_table) +{ + inode_unref_streams(dentry->d_inode, lookup_table); free_dentry(dentry); return 0; } @@ -1054,7 +1051,14 @@ do_free_dentry(struct wim_dentry *dentry, void *_lookup_table) void free_dentry_tree(struct wim_dentry *root, struct wim_lookup_table *lookup_table) { - for_dentry_in_tree_depth(root, do_free_dentry, lookup_table); + int (*f)(struct wim_dentry *, void *); + + if (lookup_table) + f = do_free_dentry_and_unref_streams; + else + f = do_free_dentry; + + for_dentry_in_tree_depth(root, f, lookup_table); } /* Insert the @child dentry into the case sensitive index of the @dir directory. @@ -1217,9 +1221,6 @@ read_dentry(const u8 * restrict buf, size_t buf_len, p = &buf[offset]; disk_dentry = (const struct wim_dentry_on_disk*)p; - if (unlikely((uintptr_t)p & 7)) - WARNING("WIM dentry is not 8-byte aligned"); - /* Get dentry length. */ length = le64_to_cpu(disk_dentry->length); @@ -1374,18 +1375,6 @@ err_free_dentry: return ret; } -static const tchar * -dentry_get_file_type_string(const struct wim_dentry *dentry) -{ - const struct wim_inode *inode = dentry->d_inode; - if (inode_is_directory(inode)) - return T("directory"); - else if (inode_is_symlink(inode)) - return T("symbolic link"); - else - return T("file"); -} - static bool dentry_is_dot_or_dotdot(const struct wim_dentry *dentry) { @@ -1464,14 +1453,10 @@ read_dentry_tree_recursive(const u8 * restrict buf, size_t buf_len, /* We already found a dentry with this same * case-sensitive long name. Only keep the first one. */ - const tchar *child_type, *duplicate_type; - child_type = dentry_get_file_type_string(child); - duplicate_type = dentry_get_file_type_string(duplicate); - WARNING("Ignoring duplicate %"TS" \"%"TS"\" " - "(the WIM image already contains a %"TS" " + WARNING("Ignoring duplicate file \"%"TS"\" " + "(the WIM image already contains a file " "at that path with the exact same name)", - child_type, dentry_full_path(duplicate), - duplicate_type); + dentry_full_path(duplicate)); free_dentry(child); continue; }