]> wimlib.net Git - wimlib/blobdiff - src/dentry.c
Fix up calculation of image XML statistics
[wimlib] / src / dentry.c
index f176f0b9dba405efcc2c9acbc2c4fd402a26d819..aec94c3435c901778f73894459f208eef33e7db0 100644 (file)
@@ -594,6 +594,9 @@ static struct inode *new_timeless_inode()
                return NULL;
        inode->security_id = -1;
        inode->link_count = 1;
+#ifdef WITH_FUSE
+       inode->next_stream_id = 1;
+#endif
        INIT_LIST_HEAD(&inode->dentry_list);
        return inode;
 }
@@ -839,58 +842,6 @@ void unlink_dentry(struct dentry *dentry)
 }
 #endif
 
-/* Parameters for calculate_dentry_statistics(). */
-struct image_statistics {
-       struct lookup_table *lookup_table;
-       u64 *dir_count;
-       u64 *file_count;
-       u64 *total_bytes;
-       u64 *hard_link_bytes;
-};
-
-static int calculate_dentry_statistics(struct dentry *dentry, void *arg)
-{
-       struct image_statistics *stats;
-       struct lookup_table_entry *lte; 
-       
-       stats = arg;
-
-       if (dentry_is_directory(dentry) && !dentry_is_root(dentry))
-               ++*stats->dir_count;
-       else
-               ++*stats->file_count;
-
-       for (unsigned i = 0; i <= dentry->d_inode->num_ads; i++) {
-               lte = inode_stream_lte(dentry->d_inode, i, stats->lookup_table);
-               if (lte) {
-                       *stats->total_bytes += wim_resource_size(lte);
-                       if (++lte->out_refcnt == 1)
-                               *stats->hard_link_bytes += wim_resource_size(lte);
-               }
-       }
-       return 0;
-}
-
-/* Calculates some statistics about a dentry tree. */
-void calculate_dir_tree_statistics(struct dentry *root, struct lookup_table *table, 
-                                  u64 *dir_count_ret, u64 *file_count_ret, 
-                                  u64 *total_bytes_ret, 
-                                  u64 *hard_link_bytes_ret)
-{
-       struct image_statistics stats;
-       *dir_count_ret         = 0;
-       *file_count_ret        = 0;
-       *total_bytes_ret       = 0;
-       *hard_link_bytes_ret   = 0;
-       stats.lookup_table     = table;
-       stats.dir_count       = dir_count_ret;
-       stats.file_count      = file_count_ret;
-       stats.total_bytes     = total_bytes_ret;
-       stats.hard_link_bytes = hard_link_bytes_ret;
-       for_lookup_table_entry(table, lte_zero_out_refcnt, NULL);
-       for_dentry_in_tree(root, calculate_dentry_statistics, &stats);
-}
-
 static inline struct dentry *inode_first_dentry(struct inode *inode)
 {
        wimlib_assert(inode->dentry_list.next != &inode->dentry_list);
@@ -1068,6 +1019,8 @@ struct ads_entry *inode_add_ads(struct inode *inode, const char *stream_name)
        struct ads_entry *ads_entries;
        struct ads_entry *new_entry;
 
+       DEBUG("Add alternate data stream \"%s\"", stream_name);
+
        if (inode->num_ads >= 0xfffe) {
                ERROR("Too many alternate data streams in one inode!");
                return NULL;
@@ -1087,6 +1040,7 @@ struct ads_entry *inode_add_ads(struct inode *inode, const char *stream_name)
 #ifdef WITH_FUSE
        new_entry->stream_id = inode->next_stream_id++;
 #endif
+       inode->num_ads = num_ads;
        return new_entry;
 }
 #endif
@@ -1099,19 +1053,19 @@ void inode_remove_ads(struct inode *inode, u16 idx,
        struct ads_entry *ads_entry;
        struct lookup_table_entry *lte;
 
+       wimlib_assert(idx < inode->num_ads);
+       wimlib_assert(inode->resolved);
+
        ads_entry = &inode->ads_entries[idx];
 
-       wimlib_assert(ads_entry);
-       wimlib_assert(inode->resolved);
+       DEBUG("Remove alternate data stream \"%s\"", ads_entry->stream_name_utf8);
 
        lte = ads_entry->lte;
-
        if (lte)
                lte_decrement_refcnt(lte, lookup_table);
 
        destroy_ads_entry(ads_entry);
 
-       wimlib_assert(inode->num_ads);
        memcpy(&inode->ads_entries[idx],
               &inode->ads_entries[idx + 1],
               (inode->num_ads - idx - 1) * sizeof(inode->ads_entries[0]));
@@ -1693,8 +1647,7 @@ static u8 *write_dentry(const struct dentry *dentry, u8 *p)
        }
 
        /* Align to 8-byte boundary */
-       wimlib_assert(length >= (p - orig_p)
-                       && length - (p - orig_p) <= 7);
+       wimlib_assert(length >= (p - orig_p) && length - (p - orig_p) <= 7);
        p = put_zeroes(p, length - (p - orig_p));
 
        /* Write the alternate data streams, if there are any.  Please see
@@ -1713,9 +1666,7 @@ static u8 *write_dentry(const struct dentry *dentry, u8 *p)
                }
                p = put_zeroes(p, (8 - (p - orig_p) % 8) % 8);
        }
-#ifdef ENABLE_ASSERTIONS
        wimlib_assert(p - orig_p == __dentry_total_length(dentry, length));
-#endif
        return p;
 }