mount_image.c: set st_blocks to compressed size
authorEric Biggers <ebiggers3@gmail.com>
Fri, 1 May 2015 03:45:49 +0000 (22:45 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 1 May 2015 05:05:28 +0000 (00:05 -0500)
NEWS
src/mount_image.c

diff --git a/NEWS b/NEWS
index 644d10f..7645593 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,9 @@ Version 1.8.1-BETA:
        link bytes" image statistics (stored in the WIM XML data) is calculated
        has been slightly changed.
 
+       In mounted WIM images, the disk usage provided for each file (st_blocks)
+       is now the compressed size rather than the uncompressed size.
+
 Version 1.8.0:
        Improved the LZX compressor.  It is now 15-20% faster than before and
        provides a slightly better compression ratio.
index 9d7ddd3..270e617 100644 (file)
@@ -549,6 +549,25 @@ inode_default_unix_mode(const struct wim_inode *inode)
        return inode_unix_file_type(inode) | 0777;
 }
 
+static u64
+blob_size(const struct blob_descriptor *blob)
+{
+       if (!blob)
+               return 0;
+       return blob->size;
+}
+
+static u64
+blob_stored_size(const struct blob_descriptor *blob)
+{
+       if (!blob)
+               return 0;
+       if (blob->blob_location == BLOB_IN_WIM &&
+           blob->size == blob->rdesc->uncompressed_size)
+               return blob->rdesc->size_in_wim;
+       return blob->size;
+}
+
 /*
  * Retrieve standard UNIX metadata ('struct stat') for a WIM inode.
  *
@@ -586,8 +605,7 @@ inode_to_stbuf(const struct wim_inode *inode,
        }
        stbuf->st_ino = inode->i_ino;
        stbuf->st_nlink = inode->i_nlink;
-       if (blob)
-               stbuf->st_size = blob->size;
+       stbuf->st_size = blob_size(blob);
 #ifdef HAVE_STAT_NANOSECOND_PRECISION
        stbuf->st_atim = wim_timestamp_to_timespec(inode->i_last_access_time);
        stbuf->st_mtim = wim_timestamp_to_timespec(inode->i_last_write_time);
@@ -597,7 +615,7 @@ inode_to_stbuf(const struct wim_inode *inode,
        stbuf->st_mtime = wim_timestamp_to_time_t(inode->i_last_write_time);
        stbuf->st_ctime = stbuf->st_mtime;
 #endif
-       stbuf->st_blocks = DIV_ROUND_UP(stbuf->st_size, 512);
+       stbuf->st_blocks = DIV_ROUND_UP(blob_stored_size(blob), 512);
        return 0;
 }
 
@@ -1573,7 +1591,7 @@ wimfs_open(const char *path, struct fuse_file_info *fi)
             (!blob || blob->blob_location != BLOB_IN_STAGING_FILE)) {
                ret = extract_blob_to_staging_dir(inode,
                                                  strm,
-                                                 blob ? blob->size : 0,
+                                                 blob_size(blob),
                                                  ctx);
                if (ret)
                        return ret;