return 0;
}
-static int
-do_calculate_dentry_full_path(struct wim_dentry *dentry, void *_ignore)
-{
- return calculate_dentry_full_path(dentry);
-}
-
-int
-calculate_dentry_tree_full_paths(struct wim_dentry *root)
-{
- return for_dentry_in_tree(root, do_calculate_dentry_full_path, NULL);
-}
-
tchar *
dentry_full_path(struct wim_dentry *dentry)
{
if (ads_entry) {
stream_idx = ads_idx + 1;
lte = ads_entry->lte;
- goto out;
} else {
return -ENOENT;
}
} else {
lte = inode_unnamed_stream_resolved(inode, &stream_idx);
}
-out:
if (dentry_ret)
*dentry_ret = dentry;
if (lte_ret)
}
#endif /* WITH_FUSE */
-/* Initializations done on every `struct wim_dentry'. */
-static void
-dentry_common_init(struct wim_dentry *dentry)
-{
- memset(dentry, 0, sizeof(struct wim_dentry));
-}
-
/* Creates an unlinked directory entry. */
int
new_dentry(const tchar *name, struct wim_dentry **dentry_ret)
struct wim_dentry *dentry;
int ret;
- dentry = MALLOC(sizeof(struct wim_dentry));
- if (dentry == NULL)
+ dentry = CALLOC(1, sizeof(struct wim_dentry));
+ if (!dentry)
return WIMLIB_ERR_NOMEM;
- dentry_common_init(dentry);
if (*name) {
ret = dentry_set_name(dentry, name);
if (ret) {
}
int
-new_filler_directory(const tchar *name, struct wim_dentry **dentry_ret)
+new_filler_directory(struct wim_dentry **dentry_ret)
{
int ret;
struct wim_dentry *dentry;
- DEBUG("Creating filler directory \"%"TS"\"", name);
- ret = new_dentry_with_inode(name, &dentry);
+ ret = new_dentry_with_inode(T(""), &dentry);
if (ret)
return ret;
/* Leave the inode number as 0; this is allowed for non
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)
{
}
}
-/* 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;
}
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.
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);
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)
{
/* 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;
}