From: Theodore Ts'o Date: Wed, 2 Jan 2002 19:15:35 +0000 (-0500) Subject: badblocks.c (main): Open the device as O_RDWR if possible, since X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=5493a27dc1138d2e30193b80217a0127d247af1e;p=tools%2Fe2fsprogs.git 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. --- diff --git a/misc/ChangeLog b/misc/ChangeLog index a1fc259..0e1a038 100644 --- a/misc/ChangeLog +++ b/misc/ChangeLog @@ -1,3 +1,9 @@ +2002-01-02 Theodore Tso + + * 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 * tune2fs.8.in, tune2fs.c (parse_tune2fs_options, main): Add diff --git a/misc/badblocks.c b/misc/badblocks.c index 8de08f7..b057f8a 100644 --- a/misc/badblocks.c +++ b/misc/badblocks.c @@ -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);