Whamcloud - gitweb
badblocks.c (main): Open the device as O_RDWR if possible, since
authorTheodore Ts'o <tytso@mit.edu>
Wed, 2 Jan 2002 19:15:35 +0000 (14:15 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Wed, 2 Jan 2002 19:15:35 +0000 (14:15 -0500)
fsync() isn't guaranteed to work if the filesystem is
opened read-only.

misc/ChangeLog
misc/badblocks.c

index a1fc259..0e1a038 100644 (file)
@@ -1,3 +1,9 @@
+2002-01-02  Theodore Tso  <tytso@valinux.com>
+
+       * badblocks.c (main): Open the device as O_RDWR if possible, since
+               fsync() isn't guaranteed to work if the filesystem is
+               opened read-only.
+
 2001-12-26  Theodore Tso  <tytso@valinux.com>
 
        * tune2fs.8.in, tune2fs.c (parse_tune2fs_options, main): Add
index 8de08f7..b057f8a 100644 (file)
@@ -761,17 +761,21 @@ int main (int argc, char ** argv)
        if (w_flag)
                check_mount(device_name);
        
-       dev = open (device_name, w_flag ? O_RDWR : O_RDONLY);
-       if (dev == -1)
-       {
+       dev = open (device_name, O_RDWR);
+       if ((dev == -1) && ((errno == EPERM) || (errno == EACCES)) &&
+           (w_flag == 0))
+               dev = open(device_name, O_RDONLY);
+       if (dev == -1) {
                com_err (program_name, errno, _("while trying to open %s"),
                         device_name);
                exit (1);
        }
        if (host_device_name) {
-               host_dev = open (host_device_name, O_RDONLY);
-               if (host_dev == -1)
-               {
+               host_dev = open (host_device_name, O_RDWR);
+               if ((host_dev == -1) &&
+                   ((errno == EPERM) || (errno == EACCES)))
+                       host_dev = open(host_device_name, O_RDONLY);
+               if (host_dev == -1) {
                        com_err (program_name, errno,
                                 _("while trying to open %s"),
                                 host_device_name);