e2fsprogs: check for read-only devices before starting fsck
PATCH 1/1 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 <[email protected]>
---
lib/ext2fs/unix_io.c +16 -0
@@ -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))