]> wimlib.net Git - wimlib/blobdiff - src/dentry.c
Return WIMLIB_ERR_NOMEM if security data cannot be allocated
[wimlib] / src / dentry.c
index d92fb85263942593b02afa228a423b5d39e7507f..fa7ff56b2073dfa88f43f26f2c231c9899149d9e 100644 (file)
@@ -176,7 +176,7 @@ static u64 dentry_total_length(const struct dentry *dentry)
        return __dentry_total_length(dentry, dentry->length);
 }
 
-/* Transfers file attributes from a `stat' buffer to an inode. */
+/* Transfers file attributes from a `stat' buffer to a WIM "inode". */
 void stbuf_to_inode(const struct stat *stbuf, struct inode *inode)
 {
        if (S_ISLNK(stbuf->st_mode)) {
@@ -191,7 +191,7 @@ void stbuf_to_inode(const struct stat *stbuf, struct inode *inode)
                inode->ino = (u64)stbuf->st_ino;
        else
                inode->ino = (u64)stbuf->st_ino |
-                                  ((u64)stbuf->st_dev << (sizeof(ino_t) * 8));
+                                  ((u64)stbuf->st_dev << ((sizeof(ino_t) * 8) & 63));
        /* Set timestamps */
        inode->creation_time = timespec_to_wim_timestamp(&stbuf->st_mtim);
        inode->last_write_time = timespec_to_wim_timestamp(&stbuf->st_mtim);
@@ -590,26 +590,26 @@ static void dentry_common_init(struct dentry *dentry)
 static struct inode *new_timeless_inode()
 {
        struct inode *inode = CALLOC(1, sizeof(struct inode));
-       if (!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);
+       if (inode) {
+               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;
 }
 
 static struct inode *new_inode()
 {
        struct inode *inode = new_timeless_inode();
-       if (!inode)
-               return NULL;
-       u64 now = get_wim_timestamp();
-       inode->creation_time = now;
-       inode->last_access_time = now;
-       inode->last_write_time = now;
+       if (inode) {
+               u64 now = get_wim_timestamp();
+               inode->creation_time = now;
+               inode->last_access_time = now;
+               inode->last_write_time = now;
+       }
        return inode;
 }
 
@@ -703,6 +703,7 @@ void free_inode(struct inode *inode)
                wimlib_assert(inode->num_opened_fds == 0);
                FREE(inode->fds);
        #endif
+               FREE(inode->extracted_file);
                FREE(inode);
        }
 }
@@ -719,7 +720,6 @@ static void put_inode(struct inode *inode)
        #endif
                {
                        free_inode(inode);
-                       inode = NULL;
                }
        }
 }
@@ -737,7 +737,8 @@ void free_dentry(struct dentry *dentry)
        FREE(dentry->file_name_utf8);
        FREE(dentry->short_name);
        FREE(dentry->full_path_utf8);
-       put_inode(dentry->d_inode);
+       if (dentry->d_inode)
+               put_inode(dentry->d_inode);
        FREE(dentry);
 }
 
@@ -842,58 +843,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);