fsck.f2fs: support a readonly filesystem
If f2fs is mounted as ro, we can do fsck.f2fs.
Change-Id: If20a055242824fd94110bcde12988ddc019a4011
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index c42620b..f0a8861 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -365,9 +365,11 @@
c->device_name = NULL;
c->trim = 1;
c->bytes_reserved = 0;
+ c->ro = 0;
}
-static int is_mounted(const char *mpt, const char *device)
+static int is_mounted(struct f2fs_configuration *c,
+ const char *mpt, const char *device)
{
#ifdef __linux__
FILE *file = NULL;
@@ -378,8 +380,11 @@
return 0;
while ((mnt = getmntent(file)) != NULL) {
- if (!strcmp(device, mnt->mnt_fsname))
+ if (!strcmp(device, mnt->mnt_fsname)) {
+ if (hasmntopt(mnt, MNTOPT_RO))
+ config.ro = 1;
break;
+ }
}
endmntent(file);
return mnt ? 1 : 0;
@@ -395,9 +400,9 @@
int ret = 0;
#ifdef __linux__
- ret = is_mounted(MOUNTED, c->device_name);
+ ret = is_mounted(c, MOUNTED, c->device_name);
if (ret) {
- MSG(0, "\tError: Not available on mounted device!\n");
+ MSG(0, "Info: Mounted device!\n");
return -1;
}
#endif
@@ -406,9 +411,9 @@
* if failed due to /etc/mtab file not present
* try with /proc/mounts.
*/
- ret = is_mounted("/proc/mounts", c->device_name);
+ ret = is_mounted(c, "/proc/mounts", c->device_name);
if (ret) {
- MSG(0, "\tError: Not available on mounted device!\n");
+ MSG(0, "Info: Mounted device!\n");
return -1;
}