[PATCH] 6/6 fix printf formats and some underlying types for large filesystems

Eric Sandeen <[email protected]> Wed, 16 Aug 2006 15:52:23 -0500
Newsgroups gmane.comp.file-systems.ext2.devel
Message-ID <[email protected]>
There were still some %d's lurking when we print blocks & inodes; also many of the
counters in the e2fsck_struct were signed, and probably need to be unsigned to
avoid overflows.

Signed-off-by: Eric Sandeen <[email protected]>

Index: e2fsprogs-1.39-test/e2fsck/e2fsck.h
===================================================================
--- e2fsprogs-1.39-test.orig/e2fsck/e2fsck.h
+++ e2fsprogs-1.39-test/e2fsck/e2fsck.h
@@ -306,24 +306,24 @@ struct e2fsck_struct {
 	char start_meta[2], stop_meta[2];
 	
 	/* File counts */
-	int fs_directory_count;
-	int fs_regular_count;
-	int fs_blockdev_count;
-	int fs_chardev_count;
-	int fs_links_count;
-	int fs_symlinks_count;
-	int fs_fast_symlinks_count;
-	int fs_fifo_count;
-	int fs_total_count;
-	int fs_badblocks_count;
-	int fs_sockets_count;
-	int fs_ind_count;
-	int fs_dind_count;
-	int fs_tind_count;
-	int fs_fragmented;
-	int large_files;
-	int fs_ext_attr_inodes;
-	int fs_ext_attr_blocks;
+	__u32 fs_directory_count;
+	__u32 fs_regular_count;
+	__u32 fs_blockdev_count;
+	__u32 fs_chardev_count;
+	__u32 fs_links_count;
+	__u32 fs_symlinks_count;
+	__u32 fs_fast_symlinks_count;
+	__u32 fs_fifo_count;
+	__u32 fs_total_count;
+	__u32 fs_badblocks_count;
+	__u32 fs_sockets_count;
+	__u32 fs_ind_count;
+	__u32 fs_dind_count;
+	__u32 fs_tind_count;
+	__u32 fs_fragmented;
+	__u32 large_files;
+	__u32 fs_ext_attr_inodes;
+	__u32 fs_ext_attr_blocks;
 
 	time_t now;
 
Index: e2fsprogs-1.39-test/e2fsck/unix.c
===================================================================
--- e2fsprogs-1.39-test.orig/e2fsck/unix.c
+++ e2fsprogs-1.39-test/e2fsck/unix.c
@@ -98,7 +98,7 @@ static void usage(e2fsck_t ctx)
 static void show_stats(e2fsck_t	ctx)
 {
 	ext2_filsys fs = ctx->fs;
-	int inodes, inodes_used;
+	__u32 inodes, inodes_used;
 	blk_t blocks, blocks_used;
 	int dir_links;
 	int num_files, num_links;
@@ -118,49 +118,49 @@ static void show_stats(e2fsck_t	ctx)
 	frag_percent = (frag_percent + 5) / 10;
 	
 	if (!verbose) {
-		printf(_("%s: %d/%d files (%0d.%d%% non-contiguous), %u/%u blocks\n"),
+		printf(_("%s: %u/%u files (%0d.%d%% non-contiguous), %u/%u blocks\n"),
 		       ctx->device_name, inodes_used, inodes,
 		       frag_percent / 10, frag_percent % 10,
 		       blocks_used, blocks);
 		return;
 	}
-	printf (P_("\n%8d inode used (%d%%)\n", "\n%8d inodes used (%d%%)\n",
+	printf (P_("\n%8u inode used (%u%%)\n", "\n%8u inodes used (%d%%)\n",
 		   inodes_used), inodes_used, 100 * inodes_used / inodes);
-	printf (P_("%8d non-contiguous inode (%0d.%d%%)\n",
-		   "%8d non-contiguous inodes (%0d.%d%%)\n",
+	printf (P_("%8u non-contiguous inode (%0d.%d%%)\n",
+		   "%8u non-contiguous inodes (%0d.%d%%)\n",
 		   ctx->fs_fragmented),
 		ctx->fs_fragmented, frag_percent / 10, frag_percent % 10);
-	printf (_("         # of inodes with ind/dind/tind blocks: %d/%d/%d\n"),
+	printf (_("         # of inodes with ind/dind/tind blocks: %u/%u/%u\n"),
 		ctx->fs_ind_count, ctx->fs_dind_count, ctx->fs_tind_count);
 	printf (P_("%8u block used (%d%%)\n", "%8u blocks used (%d%%)\n",
 		   blocks_used),
 		blocks_used, (int) ((long long) 100 * blocks_used / blocks));
-	printf (P_("%8d bad block\n", "%8d bad blocks\n",
+	printf (P_("%8u bad block\n", "%8u bad blocks\n",
 		   ctx->fs_badblocks_count), ctx->fs_badblocks_count);
-	printf (P_("%8d large file\n", "%8d large files\n",
+	printf (P_("%8u large file\n", "%8u large files\n",
 		   ctx->large_files), ctx->large_files);
-	printf (P_("\n%8d regular file\n", "\n%8d regular files\n",
+	printf (P_("\n%8u regular file\n", "\n%8u regular files\n",
 		   ctx->fs_regular_count), ctx->fs_regular_count);
-	printf (P_("%8d directory\n", "%8d directories\n",
+	printf (P_("%8u directory\n", "%8u directories\n",
 		   ctx->fs_directory_count), ctx->fs_directory_count);
-	printf (P_("%8d character device file\n",
-		   "%8d character device files\n", ctx->fs_chardev_count),
+	printf (P_("%8u character device file\n",
+		   "%8u character device files\n", ctx->fs_chardev_count),
 		ctx->fs_chardev_count);
-	printf (P_("%8d block device file\n", "%8d block device files\n",
+	printf (P_("%8u block device file\n", "%8u block device files\n",
 		   ctx->fs_blockdev_count), ctx->fs_blockdev_count);
 	printf (P_("%8d fifo\n", "%8d fifos\n", ctx->fs_fifo_count),
 		ctx->fs_fifo_count);
-	printf (P_("%8d link\n", "%8d links\n",
+	printf (P_("%8u link\n", "%8u links\n",
 		   ctx->fs_links_count - dir_links),
 		ctx->fs_links_count - dir_links);
-	printf (P_("%8d symbolic link", "%8d symbolic links",
+	printf (P_("%8u symbolic link", "%8u symbolic links",
 		   ctx->fs_symlinks_count), ctx->fs_symlinks_count);
-	printf (P_(" (%d fast symbolic link)\n", " (%d fast symbolic links)\n",
+	printf (P_(" (%u fast symbolic link)\n", " (%u fast symbolic links)\n",
 		   ctx->fs_fast_symlinks_count), ctx->fs_fast_symlinks_count);
-	printf (P_("%8d socket\n", "%8d sockets\n", ctx->fs_sockets_count),
+	printf (P_("%8u socket\n", "%8u sockets\n", ctx->fs_sockets_count),
 		ctx->fs_sockets_count);
 	printf ("--------\n");
-	printf (P_("%8d file\n", "%8d files\n",
+	printf (P_("%8u file\n", "%8u files\n",
 		   ctx->fs_total_count - dir_links),
 		ctx->fs_total_count - dir_links);
 }
@@ -300,7 +300,7 @@ static void check_if_skip(e2fsck_t ctx)
 		fputs(_(", check forced.\n"), stdout);
 		return;
 	}
-	printf(_("%s: clean, %d/%d files, %u/%u blocks"), ctx->device_name,
+	printf(_("%s: clean, %u/%u files, %u/%u blocks"), ctx->device_name,
 	       fs->super->s_inodes_count - fs->super->s_free_inodes_count,
 	       fs->super->s_inodes_count,
 	       fs->super->s_blocks_count - fs->super->s_free_blocks_count,
Index: e2fsprogs-1.39-test/misc/mke2fs.c
===================================================================
--- e2fsprogs-1.39-test.orig/misc/mke2fs.c
+++ e2fsprogs-1.39-test/misc/mke2fs.c
@@ -188,7 +188,7 @@ static void test_disk(ext2_filsys fs, ba
 	errcode_t	retval;
 	char		buf[1024];
 
-	sprintf(buf, "badblocks -b %d -X %s%s%s %d", fs->blocksize,
+	sprintf(buf, "badblocks -b %d -X %s%s%s %u", fs->blocksize,
 		quiet ? "" : "-s ", (cflag > 1) ? "-w " : "",
 		fs->device_name, fs->super->s_blocks_count);
 	if (verbose)
Index: e2fsprogs-1.39-test/e2fsck/emptydir.c
===================================================================
--- e2fsprogs-1.39-test.orig/e2fsck/emptydir.c
+++ e2fsprogs-1.39-test/e2fsck/emptydir.c
@@ -94,7 +94,7 @@ void add_empty_dirblock(empty_dir_info e
 	if (db->ino == 11)
 		return;		/* Inode number 11 is usually lost+found */
 
-	printf(_("Empty directory block %u (#%d) in inode %d\n"),
+	printf(_("Empty directory block %u (#%d) in inode %u\n"),
 	       db->blk, db->blockcnt, db->ino);
 
 	ext2fs_mark_block_bitmap(edi->empty_dir_blocks, db->blk);
Index: e2fsprogs-1.39-test/e2fsck/iscan.c
===================================================================
--- e2fsprogs-1.39-test.orig/e2fsck/iscan.c
+++ e2fsprogs-1.39-test/e2fsck/iscan.c
@@ -98,7 +98,7 @@ int main (int argc, char *argv[])
 	int		exit_value = FSCK_OK;
 	ext2_filsys	fs;
 	ext2_ino_t	ino;
-	int	num_inodes = 0;
+	__u32	num_inodes = 0;
 	struct ext2_inode inode;
 	ext2_inode_scan	scan;
 	
@@ -135,7 +135,7 @@ int main (int argc, char *argv[])
 	}
 	
 	print_resource_track(NULL, &global_rtrack);
-	printf(_("%d inodes scanned.\n"), num_inodes);
+	printf(_("%u inodes scanned.\n"), num_inodes);
 	
 	exit(0);
 }
Index: e2fsprogs-1.39-test/lib/ext2fs/bmove.c
===================================================================
--- e2fsprogs-1.39-test.orig/lib/ext2fs/bmove.c
+++ e2fsprogs-1.39-test/lib/ext2fs/bmove.c
@@ -73,7 +73,7 @@ static int process_block(ext2_filsys fs,
 		ext2fs_mark_block_bitmap(pb->alloc_map, block);
 		ret = BLOCK_CHANGED;
 		if (pb->flags & EXT2_BMOVE_DEBUG)
-			printf("ino=%ld, blockcnt=%lld, %d->%d\n", pb->ino,
+			printf("ino=%ld, blockcnt=%lld, %u->%u\n", pb->ino,
 			       blockcnt, orig, block);
 	}
 	if (pb->add_dir) {
Index: e2fsprogs-1.39-test/lib/ext2fs/getsize.c
===================================================================
--- e2fsprogs-1.39-test.orig/lib/ext2fs/getsize.c
+++ e2fsprogs-1.39-test/lib/ext2fs/getsize.c
@@ -302,7 +302,7 @@ int main(int argc, char **argv)
 			"while calling ext2fs_get_device_size");
 		exit(1);
 	}
-	printf("Device %s has %d 1k blocks.\n", argv[1], blocks);
+	printf("Device %s has %u 1k blocks.\n", argv[1], blocks);
 	exit(0);
 }
 #endif
Index: e2fsprogs-1.39-test/lib/ext2fs/icount.c
===================================================================
--- e2fsprogs-1.39-test.orig/lib/ext2fs/icount.c
+++ e2fsprogs-1.39-test/lib/ext2fs/icount.c
@@ -116,7 +116,7 @@ errcode_t ext2fs_create_icount2(ext2_fil
 	
 	bytes = (size_t) (icount->size * sizeof(struct ext2_icount_el));
 #if 0
-	printf("Icount allocated %d entries, %d bytes.\n",
+	printf("Icount allocated %u entries, %d bytes.\n",
 	       icount->size, bytes);
 #endif
 	retval = ext2fs_get_mem(bytes, &icount->list);
@@ -176,7 +176,7 @@ static struct ext2_icount_el *insert_ico
 		if (new_size < (icount->size + 100))
 			new_size = icount->size + 100;
 #if 0
-		printf("Reallocating icount %d entries...\n", new_size);
+		printf("Reallocating icount %u entries...\n", new_size);
 #endif	
 		retval = ext2fs_resize_mem((size_t) icount->size *
 					   sizeof(struct ext2_icount_el),
Index: e2fsprogs-1.39-test/lib/ext2fs/tst_badblocks.c
===================================================================
--- e2fsprogs-1.39-test.orig/lib/ext2fs/tst_badblocks.c
+++ e2fsprogs-1.39-test/lib/ext2fs/tst_badblocks.c
@@ -103,7 +103,7 @@ static void print_list(badblocks_list bb
 	}
 	ok = i = 1;
 	while (ext2fs_badblocks_list_iterate(iter, &blk)) {
-		printf("%d ", blk);
+		printf("%u ", blk);
 		if (i++ != blk)
 			ok = 0;
 	}
@@ -130,7 +130,7 @@ static void validate_test_seq(badblocks_
 			ok = 0;
 			test_fail++;
 		}
-		printf("\tblock %d is %s --- %s\n", vec[i],
+		printf("\tblock %u is %s --- %s\n", vec[i],
 		       match ? "present" : "absent",
 		       ok ? "OK" : "NOT OK");
 	}
@@ -145,7 +145,7 @@ static void do_test_seq(badblocks_list b
 		case ADD_BLK:
 			ext2fs_badblocks_list_add(bb, vec[i]);
 			match = ext2fs_badblocks_list_test(bb, vec[i]);
-			printf("Adding block %d --- now %s\n", vec[i], 
+			printf("Adding block %u --- now %s\n", vec[i], 
 			       match ? "present" : "absent");
 			if (!match) {
 				printf("FAILURE!\n");
@@ -155,7 +155,7 @@ static void do_test_seq(badblocks_list b
 		case DEL_BLK:
 			ext2fs_badblocks_list_del(bb, vec[i]);
 			match = ext2fs_badblocks_list_test(bb, vec[i]);
-			printf("Removing block %d --- now %s\n", vec[i], 
+			printf("Removing block %u --- now %s\n", vec[i], 
 			       ext2fs_badblocks_list_test(bb, vec[i]) ? 
 			       "present" : "absent");
 			if (match) {
@@ -209,7 +209,7 @@ static void invalid_proc(ext2_filsys fs,
 		printf("Expected invalid block\n");
 		test_expected_fail++;
 	} else {
-		printf("Invalid block #: %d\n", blk);
+		printf("Invalid block #: %u\n", blk);
 		test_fail++;
 	}
 }
Index: e2fsprogs-1.39-test/lib/ext2fs/tst_getsize.c
===================================================================
--- e2fsprogs-1.39-test.orig/lib/ext2fs/tst_getsize.c
+++ e2fsprogs-1.39-test/lib/ext2fs/tst_getsize.c
@@ -39,6 +39,6 @@ int main(int argc, const char *argv[])
 		com_err(argv[0], retval, "while getting device size");
 		exit(1);
 	}
-	printf("%s is device has %d blocks.\n", argv[1], blocks);
+	printf("%s is device has %u blocks.\n", argv[1], blocks);
 	return 0;
 }
Index: e2fsprogs-1.39-test/lib/ext2fs/tst_iscan.c
===================================================================
--- e2fsprogs-1.39-test.orig/lib/ext2fs/tst_iscan.c
+++ e2fsprogs-1.39-test/lib/ext2fs/tst_iscan.c
@@ -175,7 +175,7 @@ static void check_map(void)
 
 	for (i=0; test_vec[i]; i++) {
 		if (ext2fs_test_block_bitmap(touched_map, test_vec[i])) {
-			printf("Bad block was touched --- %d\n", test_vec[i]);
+			printf("Bad block was touched --- %u\n", test_vec[i]);
 			failed++;
 			first_no_comma = 1;
 		}
@@ -199,7 +199,7 @@ static void check_map(void)
 				first = 0;
 			else
 				printf(", ");
-			printf("%d", i);
+			printf("%u", i);
 		}
 	}
 	printf("\n");
Index: e2fsprogs-1.39-test/lib/ext2fs/unix_io.c
===================================================================
--- e2fsprogs-1.39-test.orig/lib/ext2fs/unix_io.c
+++ e2fsprogs-1.39-test/lib/ext2fs/unix_io.c
@@ -170,8 +170,8 @@ static errcode_t raw_read_blk(io_channel
 	size = (count < 0) ? -count : count * channel->block_size;
 	location = ((ext2_loff_t) block * channel->block_size) + data->offset;
 #ifdef DEBUG
-	printf("count=%d, size=%d, block=%d, blk_size=%d, location=%lx\n",
-	 		count, size, block, channel->block_size, location);
+	printf("count=%d, size=%d, block=%lu, blk_size=%d, location=%llx\n",
+	 		count, size, block, channel->block_size, (long long)location);
 #endif
 	if (ext2fs_llseek(data->dev, location, SEEK_SET) != location) {
 		retval = errno ? errno : EXT2_ET_LLSEEK_FAILED;
@@ -553,7 +553,7 @@ static errcode_t unix_read_blk(io_channe
 		/* If it's in the cache, use it! */
 		if ((cache = find_cached_block(data, block, &reuse[0]))) {
 #ifdef DEBUG
-			printf("Using cached block %d\n", block);
+			printf("Using cached block %lu\n", block);
 #endif
 			memcpy(cp, cache->buf, channel->block_size);
 			count--;
@@ -569,7 +569,7 @@ static errcode_t unix_read_blk(io_channe
 			if (find_cached_block(data, block+i, &reuse[i]))
 				break;
 #ifdef DEBUG
-		printf("Reading %d blocks starting at %d\n", i, block);
+		printf("Reading %d blocks starting at %lu\n", i, block);
 #endif
 		if ((retval = raw_read_blk(channel, data, block, i, cp)))
 			return retval;
Index: e2fsprogs-1.39-test/lib/ext2fs/write_bb_file.c
===================================================================
--- e2fsprogs-1.39-test.orig/lib/ext2fs/write_bb_file.c
+++ e2fsprogs-1.39-test/lib/ext2fs/write_bb_file.c
@@ -27,7 +27,7 @@ errcode_t ext2fs_write_bb_FILE(ext2_badb
 		return retval;
 
 	while (ext2fs_badblocks_list_iterate(bb_iter, &blk)) {
-		fprintf(f, "%d\n", blk);
+		fprintf(f, "%u\n", blk);
 	}
 	ext2fs_badblocks_list_iterate_end(bb_iter);
 	return 0;
Index: e2fsprogs-1.39-test/resize/online.c
===================================================================
--- e2fsprogs-1.39-test.orig/resize/online.c
+++ e2fsprogs-1.39-test/resize/online.c
@@ -74,7 +74,7 @@ errcode_t online_resize_fs(ext2_filsys f
 	if (retval)
 		return retval;
 
-	printf(_("Performing an on-line resize of %s to %d (%dk) blocks.\n"), 
+	printf(_("Performing an on-line resize of %s to %u (%dk) blocks.\n"), 
 	       fs->device_name, *new_size, fs->blocksize / 1024);
 
 	size = fs->group_desc_count * sb->s_blocks_per_group + 
@@ -115,7 +115,7 @@ errcode_t online_resize_fs(ext2_filsys f
 		printf("new inode table is at 0x%04x-0x%04x\n", 
 		       input.inode_table,
 		       input.inode_table + new_fs->inode_blocks_per_group-1);
-		printf("new group has %d blocks\n", input.blocks_count);
+		printf("new group has %u blocks\n", input.blocks_count);
 		printf("new group will reserve %d blocks\n", 
 		       input.reserved_blocks);
 		printf("new group has %d free blocks\n", 



-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642