From: Eric Sandeen <sandeen@redhat.com>
To: ext4 development <linux-ext4@vger.kernel.org>
Subject: [PATCH] e2fsprogs: check for read-only devices before starting fsck
Date: Fri, 10 Oct 2008 17:17:43 -0500 [thread overview]
Message-ID: <48EFD487.5070105@redhat.com> (raw)
When we open a device on linux, test whether it is writable
right away, rather than trying to proceed and clean up when
writes start failing.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
---
Index: e2fsprogs/lib/ext2fs/unix_io.c
===================================================================
--- e2fsprogs.orig/lib/ext2fs/unix_io.c
+++ e2fsprogs/lib/ext2fs/unix_io.c
@@ -30,6 +30,7 @@
#include <time.h>
#ifdef __linux__
#include <sys/utsname.h>
+#include <linux/fs.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
@@ -454,6 +455,21 @@ static errcode_t unix_open(const char *n
}
#ifdef __linux__
+ if (flags & IO_FLAG_RW) {
+ int error;
+ int readonly = 0;
+
+ /* Is the block device actually writable? */
+ error = ioctl(data->dev, BLKROGET, &readonly);
+ if (!error && readonly) {
+ close(data->dev);
+ retval = EPERM;
+ goto cleanup;
+ }
+ }
+#endif
+
+#ifdef __linux__
#undef RLIM_INFINITY
#if (defined(__alpha__) || ((defined(__sparc__) || defined(__mips__)) && (SIZEOF_LONG == 4)))
#define RLIM_INFINITY ((unsigned long)(~0UL>>1))
reply other threads:[~2008-10-10 22:17 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48EFD487.5070105@redhat.com \
--to=sandeen@redhat.com \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.