diff mbox

[1/2,v2] debugfs: fixup the hard-coded buffer length in dump_file

Message ID 1357043415-24668-2-git-send-email-wenqing.lz@taobao.com
State Superseded, archived
Headers show

Commit Message

Zheng Liu Jan. 1, 2013, 12:30 p.m. UTC
From: Zheng Liu <wenqing.lz@taobao.com>

For dumping a sparse file, a buffer needs to be allocated, and length is equal
to block size.  So we can't define a hard-coded length due to the block size
might be 1k, 2k, or 4k.  Now we malloc this buffer to fix the hard-coded length.

CC: George Spelvin <linux@horizon.com>
CC: "Theodore Ts'o" <tytso@mit.edu>
Signed-off-by: Zheng Liu <wenqing.lz@taobao.com>
---
 debugfs/dump.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

Comments

Theodore Ts'o Jan. 1, 2013, 8:14 p.m. UTC | #1
On Tue, Jan 01, 2013 at 08:30:14PM +0800, Zheng Liu wrote:
> +	retval = ext2fs_get_array(1, blocksize, &buf);

Thanks, applied.  I did make one change to the above line:

	retval = ext2fs_get_mem(blocksize, &buf);

							- 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
diff mbox

Patch

diff --git a/debugfs/dump.c b/debugfs/dump.c
index a15a0b7..5b2289c 100644
--- a/debugfs/dump.c
+++ b/debugfs/dump.c
@@ -105,10 +105,10 @@  static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
 {
 	errcode_t retval;
 	struct ext2_inode	inode;
-	char 		buf[8192];
+	char		*buf = 0;
 	ext2_file_t	e2_file;
 	int		nbytes;
-	unsigned int	got;
+	unsigned int	got, blocksize = current_fs->blocksize;
 
 	if (debugfs_read_inode(ino, &inode, cmdname))
 		return;
@@ -118,8 +118,13 @@  static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
 		com_err(cmdname, retval, "while opening ext2 file");
 		return;
 	}
+	retval = ext2fs_get_array(1, blocksize, &buf);
+	if (retval) {
+		com_err(cmdname, retval, "while allocating memory");
+		return;
+	}
 	while (1) {
-		retval = ext2fs_file_read(e2_file, buf, sizeof(buf), &got);
+		retval = ext2fs_file_read(e2_file, buf, blocksize, &got);
 		if (retval)
 			com_err(cmdname, retval, "while reading ext2 file");
 		if (got == 0)
@@ -128,6 +133,8 @@  static void dump_file(const char *cmdname, ext2_ino_t ino, int fd,
 		if ((unsigned) nbytes != got)
 			com_err(cmdname, errno, "while writing file");
 	}
+	if (buf)
+		ext2fs_free_mem(&buf);
 	retval = ext2fs_file_close(e2_file);
 	if (retval) {
 		com_err(cmdname, retval, "while closing ext2 file");