[<prev] [next>] [day] [month] [year] [list]
Date: Fri, 10 Oct 2008 17:17:43 -0500
From: Eric Sandeen <sandeen@...hat.com>
To: ext4 development <linux-ext4@...r.kernel.org>
Subject: [PATCH] e2fsprogs: check for read-only devices before starting fsck
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@...hat.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))
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Powered by blists - more mailing lists