]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
badblocks: Add the -B option which forces the use of buffered I/O
authorTheodore Ts'o <tytso@mit.edu>
Thu, 17 Feb 2011 04:40:46 +0000 (23:40 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 18 Feb 2011 06:16:02 +0000 (01:16 -0500)
If for some reason direct I/O does not work correctly, force the use
of buffered I/O.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
misc/badblocks.8.in
misc/badblocks.c

index f256c0eed124dbbea1a8f9a181727c3efc197df9..a5042e07c76d8f91ddbe1f50909b10b232968c8f 100644 (file)
@@ -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)
index 585e8aaedc1605f516a390074a38128d7fa08cf0..a656e376771672971840d6c0177636026d546205 100644 (file)
@@ -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;