From e53e8fb00970fc74163b822e65d4e1156adac770 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Wed, 16 Feb 2011 23:40:46 -0500 Subject: [PATCH] badblocks: Add the -B option which forces the use of buffered I/O If for some reason direct I/O does not work correctly, force the use of buffered I/O. Signed-off-by: "Theodore Ts'o" --- misc/badblocks.8.in | 5 ++++- misc/badblocks.c | 13 +++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/misc/badblocks.8.in b/misc/badblocks.8.in index f256c0e..a5042e0 100644 --- a/misc/badblocks.8.in +++ b/misc/badblocks.8.in @@ -5,7 +5,7 @@ badblocks \- search a device for bad blocks .SH SYNOPSIS .B badblocks [ -.B \-svwnf +.B \-svwnfBX ] [ .B \-b @@ -195,6 +195,9 @@ This option may not be combined with the .B \-n option, as they are mutually exclusive. .TP +.B \-B +Use buffered I/O and do not use Direct I/O, even if it is available. +.TP .B \-X Internal flag only to be used by .BR e2fsck (8) diff --git a/misc/badblocks.c b/misc/badblocks.c index 585e8aa..a656e37 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -74,6 +74,7 @@ static int t_flag = 0; /* number of test patterns */ static int t_max = 0; /* allocated test patterns */ static unsigned int *t_patts = NULL; /* test patterns */ static int current_O_DIRECT = 0; /* Current status of O_DIRECT flag */ +static int use_buffered_io = 0; static int exclusive_ok = 0; static unsigned int max_bb = 0; /* Abort test if more than this number of bad blocks has been encountered */ static unsigned int d_flag = 0; /* delay factor between reads */ @@ -268,7 +269,8 @@ static void set_o_direct(int dev, unsigned char *buffer, size_t size, int new_flag = O_DIRECT; int flag; - if ((((unsigned long) buffer & (sys_page_size - 1)) != 0) || + if ((use_buffered_io != 0) || + (((unsigned long) buffer & (sys_page_size - 1)) != 0) || ((size & (sys_page_size - 1)) != 0) || ((offset & (O_DIRECT_SIZE - 1)) != 0)) new_flag = 0; @@ -432,6 +434,10 @@ static void flush_bufs(void) { errcode_t retval; +#ifdef O_DIRECT + if (!use_buffered_io) + return; +#endif retval = ext2fs_sync_device(host_dev, 1); if (retval) com_err(program_name, retval, _("during ext2fs_sync_device")); @@ -1027,7 +1033,7 @@ int main (int argc, char ** argv) if (argc && *argv) program_name = *argv; - while ((c = getopt (argc, argv, "b:d:e:fi:o:svwnc:p:h:t:X")) != EOF) { + while ((c = getopt (argc, argv, "b:d:e:fi:o:svwnc:p:h:t:BX")) != EOF) { switch (c) { case 'b': block_size = parse_uint(optarg, "block size"); @@ -1100,6 +1106,9 @@ int main (int argc, char ** argv) t_patts[t_flag++] = pattern; } break; + case 'B': + use_buffered_io = 1; + break; case 'X': exclusive_ok++; break; -- 1.8.3.1