From b001aca524f15cb0239518537378924725cc5b12 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sun, 16 Dec 2012 13:06:08 -0600 Subject: [PATCH] Move inode_to_stbuf() to mount_image.c --- src/dentry.c | 56 +---------------------------------------------- src/dentry.h | 3 --- src/mount_image.c | 44 +++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 58 deletions(-) diff --git a/src/dentry.c b/src/dentry.c index ae71c1d5..daab2fea 100644 --- a/src/dentry.c +++ b/src/dentry.c @@ -27,19 +27,12 @@ * wimlib; if not, see http://www.gnu.org/licenses/. */ -#include -#include -#include -#include - -#include "dentry.h" #include "buffer_io.h" +#include "dentry.h" #include "lookup_table.h" -#include "sha1.h" #include "timestamp.h" #include "wimlib_internal.h" - /* Calculates the unaligned length, in bytes, of an on-disk WIM dentry that has * a file name and short name that take the specified numbers of bytes. This * excludes any alternate data stream entries that may follow the dentry. */ @@ -175,52 +168,6 @@ static u64 dentry_total_length(const struct dentry *dentry) return __dentry_total_length(dentry, dentry->length); } -#ifdef WITH_FUSE -/* Transfers file attributes from a struct inode to a `stat' buffer. - * - * The lookup table entry tells us which stream in the inode we are statting. - * For a named data stream, everything returned is the same as the unnamed data - * stream except possibly the size and block count. */ -int inode_to_stbuf(const struct inode *inode, struct lookup_table_entry *lte, - struct stat *stbuf) -{ - if (inode_is_symlink(inode)) - stbuf->st_mode = S_IFLNK | 0777; - else if (inode_is_directory(inode)) - stbuf->st_mode = S_IFDIR | 0755; - else - stbuf->st_mode = S_IFREG | 0755; - - stbuf->st_ino = (ino_t)inode->ino; - stbuf->st_nlink = inode->link_count; - stbuf->st_uid = getuid(); - stbuf->st_gid = getgid(); - - if (lte) { - if (lte->resource_location == RESOURCE_IN_STAGING_FILE) { - wimlib_assert(lte->staging_file_name); - struct stat native_stat; - if (stat(lte->staging_file_name, &native_stat) != 0) { - DEBUG("Failed to stat `%s': %m", - lte->staging_file_name); - return -errno; - } - stbuf->st_size = native_stat.st_size; - } else { - stbuf->st_size = wim_resource_size(lte); - } - } else { - stbuf->st_size = 0; - } - - stbuf->st_atime = wim_timestamp_to_unix(inode->last_access_time); - stbuf->st_mtime = wim_timestamp_to_unix(inode->last_write_time); - stbuf->st_ctime = wim_timestamp_to_unix(inode->creation_time); - stbuf->st_blocks = (stbuf->st_size + 511) / 512; - return 0; -} -#endif - int for_dentry_in_rbtree(struct rb_node *root, int (*visitor)(struct dentry *, void *), void *arg) @@ -1833,4 +1780,3 @@ u8 *write_dentry_tree(const struct dentry *root, u8 *p) /* Recursively write the rest of the dentry tree. */ return write_dentry_tree_recursive(root, p); } - diff --git a/src/dentry.h b/src/dentry.h index d03d42e9..18089704 100644 --- a/src/dentry.h +++ b/src/dentry.h @@ -334,9 +334,6 @@ static inline bool dentry_is_first_in_inode(const struct dentry *dentry) extern u64 dentry_correct_total_length(const struct dentry *dentry); -extern int inode_to_stbuf(const struct inode *inode, - struct lookup_table_entry *lte, struct stat *stbuf); - extern int for_dentry_in_tree(struct dentry *root, int (*visitor)(struct dentry*, void*), void *args); diff --git a/src/mount_image.c b/src/mount_image.c index 6ab60d9a..d3021a53 100644 --- a/src/mount_image.c +++ b/src/mount_image.c @@ -295,6 +295,50 @@ static void remove_dentry(struct dentry *dentry, put_dentry(dentry); } +/* Transfers file attributes from a struct inode to a `stat' buffer. + * + * The lookup table entry tells us which stream in the inode we are statting. + * For a named data stream, everything returned is the same as the unnamed data + * stream except possibly the size and block count. */ +static int inode_to_stbuf(const struct inode *inode, + struct lookup_table_entry *lte, struct stat *stbuf) +{ + if (inode_is_symlink(inode)) + stbuf->st_mode = S_IFLNK | 0777; + else if (inode_is_directory(inode)) + stbuf->st_mode = S_IFDIR | 0755; + else + stbuf->st_mode = S_IFREG | 0755; + + stbuf->st_ino = (ino_t)inode->ino; + stbuf->st_nlink = inode->link_count; + stbuf->st_uid = getuid(); + stbuf->st_gid = getgid(); + + if (lte) { + if (lte->resource_location == RESOURCE_IN_STAGING_FILE) { + wimlib_assert(lte->staging_file_name); + struct stat native_stat; + if (stat(lte->staging_file_name, &native_stat) != 0) { + DEBUG("Failed to stat `%s': %m", + lte->staging_file_name); + return -errno; + } + stbuf->st_size = native_stat.st_size; + } else { + stbuf->st_size = wim_resource_size(lte); + } + } else { + stbuf->st_size = 0; + } + + stbuf->st_atime = wim_timestamp_to_unix(inode->last_access_time); + stbuf->st_mtime = wim_timestamp_to_unix(inode->last_write_time); + stbuf->st_ctime = wim_timestamp_to_unix(inode->creation_time); + stbuf->st_blocks = (stbuf->st_size + 511) / 512; + return 0; +} + /* Creates a new staging file and returns its file descriptor opened for * writing. * -- 2.43.0