/* Calculate the full path of @dentry. The full path of its parent must have
* already been calculated, or it must be the root dentry. */
-int
-calculate_dentry_full_path(struct wim_dentry *dentry, void *ignore)
+static int
+calculate_dentry_full_path(struct wim_dentry *dentry)
{
tchar *full_path;
u32 full_path_nbytes;
+ int ret;
- wimlib_assert(dentry_is_root(dentry) ||
- dentry->parent->full_path != NULL);
+ if (dentry->_full_path)
+ return 0;
if (dentry_is_root(dentry)) {
full_path = TSTRDUP(T("/"));
return WIMLIB_ERR_NOMEM;
full_path_nbytes = 1 * sizeof(tchar);
} else {
- const struct wim_dentry *parent;
+ struct wim_dentry *parent;
tchar *parent_full_path;
u32 parent_full_path_nbytes;
size_t filename_nbytes;
parent_full_path = T("");
parent_full_path_nbytes = 0;
} else {
- parent_full_path = parent->full_path;
+ if (!parent->_full_path) {
+ ret = calculate_dentry_full_path(parent);
+ if (ret)
+ return ret;
+ }
+ parent_full_path = parent->_full_path;
parent_full_path_nbytes = parent->full_path_nbytes;
}
sizeof(tchar) + 1]);
#endif
}
- FREE(dentry->full_path);
- dentry->full_path = full_path;
+ dentry->_full_path = full_path;
dentry->full_path_nbytes= full_path_nbytes;
return 0;
}
+tchar *
+dentry_full_path(struct wim_dentry *dentry)
+{
+ calculate_dentry_full_path(dentry);
+ return dentry->_full_path;
+}
+
static int
increment_subdir_offset(struct wim_dentry *dentry, void *subdir_offset_p)
{
/* Prints the full path of a dentry. */
int
-print_dentry_full_path(struct wim_dentry *dentry, void *ignore)
+print_dentry_full_path(struct wim_dentry *dentry, void *_ignore)
{
- if (dentry->full_path)
- tprintf(T("%"TS"\n"), dentry->full_path);
+ tchar *full_path = dentry_full_path(dentry);
+ if (!full_path)
+ return WIMLIB_ERR_NOMEM;
+ tprintf(T("%"TS"\n"), full_path);
+ FREE(full_path);
+ dentry->_full_path = 0;
+ dentry->full_path_nbytes = 0;
return 0;
}
wimlib_printf(T("Filename = \"%"WS"\"\n"), dentry->file_name);
if (dentry_has_short_name(dentry))
wimlib_printf(T("Short Name \"%"WS"\"\n"), dentry->short_name);
- if (dentry->full_path)
- tprintf(T("Full Path = \"%"TS"\"\n"), dentry->full_path);
+ if (dentry->_full_path)
+ tprintf(T("Full Path = \"%"TS"\"\n"), dentry->_full_path);
lte = inode_stream_lte(dentry->d_inode, 0, lookup_table);
if (lte) {
hash = inode_stream_hash(inode, 0);
if (hash) {
tprintf(T("Hash = 0x"));
- print_hash(hash);
+ print_hash(hash, stdout);
tputchar(T('\n'));
tputchar(T('\n'));
}
hash = inode_stream_hash(inode, i + 1);
if (hash) {
tprintf(T("Hash = 0x"));
- print_hash(hash);
+ print_hash(hash, stdout);
tputchar(T('\n'));
}
print_lookup_table_entry(inode_stream_lte(inode, i + 1, lookup_table),
dentry_common_init(struct wim_dentry *dentry)
{
memset(dentry, 0, sizeof(struct wim_dentry));
- dentry->refcnt = 1;
}
-static struct wim_inode *
+struct wim_inode *
new_timeless_inode()
{
struct wim_inode *inode = CALLOC(1, sizeof(struct wim_inode));
if (inode) {
inode->i_security_id = -1;
inode->i_nlink = 1;
- #ifdef WITH_FUSE
inode->i_next_stream_id = 1;
+ #ifdef WITH_FUSE
if (pthread_mutex_init(&inode->i_mutex, NULL) != 0) {
ERROR_WITH_ERRNO("Error initializing mutex");
FREE(inode);
}
/* Frees an inode. */
-void free_inode(struct wim_inode *inode)
+void
+free_inode(struct wim_inode *inode)
{
if (inode) {
if (inode->i_ads_entries) {
/* Decrements link count on an inode and frees it if the link count reaches 0.
* */
-static void put_inode(struct wim_inode *inode)
+static void
+put_inode(struct wim_inode *inode)
{
wimlib_assert(inode->i_nlink != 0);
if (--inode->i_nlink == 0) {
* The corresponding inode (if any) is freed only if its link count is
* decremented to 0.
*/
-void free_dentry(struct wim_dentry *dentry)
+void
+free_dentry(struct wim_dentry *dentry)
{
FREE(dentry->file_name);
FREE(dentry->short_name);
- FREE(dentry->full_path);
+ FREE(dentry->_full_path);
if (dentry->d_inode)
put_inode(dentry->d_inode);
FREE(dentry);
}
-void put_dentry(struct wim_dentry *dentry)
-{
- wimlib_assert(dentry->refcnt != 0);
- if (--dentry->refcnt == 0)
- free_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)
+static int
+do_free_dentry(struct wim_dentry *dentry, void *__lookup_table)
{
struct wim_lookup_table *lookup_table = __lookup_table;
unsigned i;
lte_decrement_refcnt(lte, lookup_table);
}
}
-
- put_dentry(dentry);
+ free_dentry(dentry);
return 0;
}
* table entries corresponding to the dentries will be
* decremented.
*/
-void free_dentry_tree(struct wim_dentry *root, struct wim_lookup_table *lookup_table)
+void
+free_dentry_tree(struct wim_dentry *root, struct wim_lookup_table *lookup_table)
{
if (root)
for_dentry_in_tree_depth(root, do_free_dentry, lookup_table);
}
-int increment_dentry_refcnt(struct wim_dentry *dentry, void *ignore)
-{
- dentry->refcnt++;
- return 0;
-}
-
/*
* Links a dentry into the directory tree.
*
new_entry = &inode->i_ads_entries[num_ads - 1];
if (init_ads_entry(new_entry, stream_name, stream_name_nbytes, is_utf16le))
return NULL;
-#ifdef WITH_FUSE
new_entry->stream_id = inode->i_next_stream_id++;
-#endif
inode->i_num_ads = num_ads;
return new_entry;
}
if (size != sizeof(struct wimlib_unix_data))
return BAD_UNIX_DATA;
- ret = read_full_wim_resource(lte, unix_data, 0);
+ ret = read_full_resource_into_buf(lte, unix_data, true);
if (ret)
return ret;