diff mbox

Btrfs-progs: ftw_add_entry_size: Round up file size to sectorsize

Message ID 1450173720-25543-1-git-send-email-chandan@linux.vnet.ibm.com (mailing list archive)
State Accepted
Headers show

Commit Message

Chandan Rajendra Dec. 15, 2015, 10:02 a.m. UTC
ftw_add_entry_size() assumes 4k as the block size of the underlying filesystem
and hence the file sizes computed is incorrect for non-4k sectorsized
filesystems. Fix this by rounding up file sizes to sectorsize.

Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>
---
 mkfs.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

David Sterba Dec. 18, 2015, 6:01 p.m. UTC | #1
On Tue, Dec 15, 2015 at 03:32:00PM +0530, Chandan Rajendra wrote:
> ftw_add_entry_size() assumes 4k as the block size of the underlying filesystem
> and hence the file sizes computed is incorrect for non-4k sectorsized
> filesystems. Fix this by rounding up file sizes to sectorsize.
> 
> Signed-off-by: Chandan Rajendra <chandan@linux.vnet.ibm.com>

Applied, thanks.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/mkfs.c b/mkfs.c
index c58ab2f..88c2289 100644
--- a/mkfs.c
+++ b/mkfs.c
@@ -1031,16 +1031,15 @@  out:
  * This ignores symlinks with unreadable targets and subdirs that can't
  * be read.  It's a best-effort to give a rough estimate of the size of
  * a subdir.  It doesn't guarantee that prepopulating btrfs from this
- * tree won't still run out of space. 
- *
- * The rounding up to 4096 is questionable.  Previous code used du -B 4096.
+ * tree won't still run out of space.
  */
 static u64 global_total_size;
+static u64 fs_block_size;
 static int ftw_add_entry_size(const char *fpath, const struct stat *st,
 			      int type)
 {
 	if (type == FTW_F || type == FTW_D)
-		global_total_size += round_up(st->st_size, 4096);
+		global_total_size += round_up(st->st_size, fs_block_size);
 
 	return 0;
 }
@@ -1060,6 +1059,7 @@  static u64 size_sourcedir(char *dir_name, u64 sectorsize,
 			allocated_meta_size / default_chunk_size;
 
 	global_total_size = 0;
+	fs_block_size = sectorsize;
 	ret = ftw(dir_name, ftw_add_entry_size, 10);
 	dir_size = global_total_size;
 	if (ret < 0) {