From aa07cb79b0a38d9d8407c5631624ef8534bdde3f Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Sun, 27 Feb 2011 20:09:54 -0500 Subject: [PATCH] mke2fs: If the device supports discard, don't print an error message Check to see if the device supports discard before starting the progress bar, and then printing an error about inappropriate ioctl for device (when creating a file system image to a file, for example). Also, add a function signature in the ext2_io.h header file for io_channel_discard() and fix an extra, uneeded argument in mke2fs's call to that function. Signed-off-by: "Theodore Ts'o" --- lib/ext2fs/ext2_io.h | 3 +++ misc/mke2fs.c | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ext2fs/ext2_io.h b/lib/ext2fs/ext2_io.h index ba97341..e71ada9 100644 --- a/lib/ext2fs/ext2_io.h +++ b/lib/ext2fs/ext2_io.h @@ -117,6 +117,9 @@ extern errcode_t io_channel_read_blk64(io_channel channel, extern errcode_t io_channel_write_blk64(io_channel channel, unsigned long long block, int count, const void *data); +extern errcode_t io_channel_discard(io_channel channel, + unsigned long long block, + unsigned long long count); /* unix_io.c */ extern io_manager unix_io_manager; diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 7866c2c..9798b88 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -2015,6 +2015,10 @@ static int mke2fs_discard_device(ext2_filsys fs) blk64_t cur = 0; int retval = 0; + retval = io_channel_discard(fs->io, 0, 0); + if (retval) + return retval; + count *= (1024 * 1024); count /= fs->blocksize; @@ -2027,7 +2031,7 @@ static int mke2fs_discard_device(ext2_filsys fs) if (cur + count > blocks) count = blocks - cur; - retval = io_channel_discard(fs->io, cur, count, fs->blocksize); + retval = io_channel_discard(fs->io, cur, count); if (retval) break; cur += count; -- 1.8.3.1