* [PATCH] e2fsprogs: check for read-only devices before starting fsck
@ 2008-10-10 22:17 Eric Sandeen
0 siblings, 0 replies; only message in thread
From: Eric Sandeen @ 2008-10-10 22:17 UTC (permalink / raw)
To: ext4 development
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))
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-10-10 22:17 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-10 22:17 [PATCH] e2fsprogs: check for read-only devices before starting fsck Eric Sandeen
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.