Patchwork [v2] misc: Use unsigned long long for file block count in filefrag

login
register
mail settings
Submitter Vitaliy Filippov
Date Feb. 23, 2014, 9:08 a.m.
Message ID <20140223162614.4FEF347E837@yourcmc.ru>
Download mbox | patch
Permalink /patch/323341/
State Accepted
Headers show

Comments

Vitaliy Filippov - Feb. 23, 2014, 9:08 a.m.
This patch fixes incorrect reporting of file block count on 32-bit platforms.

Signed-off-by: Vitaliy Filippov <vitalif@yourcmc.ru>
---
 misc/filefrag.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
Theodore Ts'o - May 26, 2014, 4:11 p.m.
On Sun, Feb 23, 2014 at 01:08:47PM +0400, Vitaliy Filippov wrote:
> This patch fixes incorrect reporting of file block count on 32-bit platforms.
> 
> Signed-off-by: Vitaliy Filippov <vitalif@yourcmc.ru>

Applied, thanks.  (Apologies for the delay.)

	 	  	     	     - Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/misc/filefrag.c b/misc/filefrag.c
index a050a22..74e9306 100644
--- a/misc/filefrag.c
+++ b/misc/filefrag.c
@@ -337,7 +337,7 @@  static void frag_report(const char *filename)
 	ext2fs_struct_stat st;
 	int		blk_shift;
 	long		fd;
-	unsigned long	numblocks;
+	unsigned long long	numblocks;
 	int		data_blocks_per_cyl = 1;
 	int		num_extents = 1, expected = ~0;
 	int		is_ext2 = 0;
@@ -409,13 +409,17 @@  static void frag_report(const char *filename)
 	if (width > logical_width)
 		logical_width = width;
 	if (verbose)
-		printf("File size of %s is %llu (%lu block%s of %d bytes)\n",
+		printf("File size of %s is %llu (%llu block%s of %d bytes)\n",
 		       filename, (unsigned long long)st.st_size,
 		       numblocks * fsinfo.f_bsize >> blk_shift,
 		       numblocks == 1 ? "" : "s", 1 << blk_shift);
 
 	if (force_bmap ||
 	    filefrag_fiemap(fd, blk_shift, &num_extents, &st) != 0) {
+		if (numblocks > (unsigned long)-1L) {
+			fprintf(stderr, "%s: File too big to use FIBMAP\n", filename);
+			goto out_close;
+		}
 		expected = filefrag_fibmap(fd, blk_shift, &num_extents,
 					   &st, numblocks, is_ext2);
 		if (expected < 0) {