aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZheng Liu <wenqing.lz@taobao.com>2013-01-01 20:30:14 +0800
committerTheodore Ts'o <tytso@mit.edu>2013-01-01 15:12:14 -0500
commitd3b4de412c7710b7d5f05774dedd1e298d2c750b (patch)
tree81aca93e194283533ad23d9083e003d0dc197f75
parentcc5f27eb387fb2e33b4d83caca89a0471bf09863 (diff)
downloade2fsprogs-d3b4de412c7710b7d5f05774dedd1e298d2c750b.tar.gz
e2fsprogs-d3b4de412c7710b7d5f05774dedd1e298d2c750b.tar.xz
e2fsprogs-d3b4de412c7710b7d5f05774dedd1e298d2c750b.zip
debugfs: fixup the hard-coded buffer length in dump_file
Allocate the block buffer in dump_file() instead of assuming that the block size is no more than 8k. CC: George Spelvin <linux@horizon.com> Signed-off-by: Zheng Liu <wenqing.lz@taobao.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
-rw-r--r--debugfs/dump.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/debugfs/dump.c b/debugfs/dump.c
index a15a0b73..9409ab65 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_mem(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");