If f2fs is mounted as ro, we can do fsck.f2fs.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
need_fix = 1;
}
}
- if (need_fix) {
+ if (need_fix && !config.ro) {
u64 ssa_blk;
int ret2;
need_fix = 1;
}
}
- if (need_fix) {
+ if (need_fix && !config.ro) {
u64 ssa_blk;
int ret2;
nid, i_links);
}
}
- if (need_fix) {
+ if (need_fix && !config.ro) {
/* drop extent information to avoid potential wrong access */
node_blk->i.i_ext.len = 0;
ret = dev_write_block(node_blk, ni->blk_addr);
FIX_MSG("[0x%x] dn.addr[%d] = 0", nid, idx);
}
}
- if (need_fix) {
+ if (need_fix && !config.ro) {
ret = dev_write_block(node_blk, ni->blk_addr);
ASSERT(ret >= 0);
}
de_blk->dentry, de_blk->filename,
NR_DENTRY_IN_BLOCK, last_blk, encrypted);
- if (dentries < 0) {
+ if (dentries < 0 && !config.ro) {
ret = dev_write_block(de_blk, blk_addr);
ASSERT(ret >= 0);
DBG(1, "[%3d] Dentry Block [0x%x] Fixed hash_codes\n\n",
else if (ret)
ASSERT_MSG("[0x%x] wrong orphan inode", ino);
}
- if (config.fix_on && entry_count != new_entry_count) {
+ if (!config.ro && config.fix_on &&
+ entry_count != new_entry_count) {
new_blk->entry_count = cpu_to_le32(new_entry_count);
ret = dev_write_block(new_blk, start_blk + i);
ASSERT(ret >= 0);
}
/* fix global metadata */
- if (force || (config.bug_on && config.fix_on)) {
+ if (force || (config.bug_on && config.fix_on && !config.ro)) {
fix_hard_links(sbi);
fix_nat_entries(sbi);
rewrite_sit_area_bitmap(sbi);
f2fs_parse_options(argc, argv);
- if (f2fs_dev_is_umounted(&config) < 0)
- return -1;
+ if (f2fs_dev_is_umounted(&config) < 0) {
+ if (!config.ro) {
+ MSG(0, "\tError: Not available on mounted device!\n");
+ return -1;
+ }
+
+ /* allow ro-mounted partition */
+ MSG(0, "Info: Check FS only due to RO\n");
+ config.fix_on = 0;
+ config.auto_fix = 0;
+ }
/* Get device */
if (f2fs_get_device_info(&config) < 0)
f2fs_do_umount(sbi);
out:
if (config.func == FSCK && config.bug_on) {
- if (config.fix_on == 0 && config.auto_fix == 0) {
+ if (!config.ro && config.fix_on == 0 && config.auto_fix == 0) {
char ans[255] = {0};
retry:
printf("Do you want to fix this partition? [Y/N] ");
int fix_on;
int bug_on;
int auto_fix;
+ int ro;
__le32 feature; /* defined features */
} __attribute__((packed));
c->vol_label = "";
c->device_name = NULL;
c->trim = 1;
+ 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)
{
FILE *file = NULL;
struct mntent *mnt = NULL;
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;
struct stat st_buf;
int ret = 0;
- 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;
}
* 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;
}
f2fs_show_info();
- if (f2fs_dev_is_umounted(&config) < 0)
+ if (f2fs_dev_is_umounted(&config) < 0) {
+ MSG(0, "\tError: Not available on mounted device!\n");
return -1;
+ }
if (f2fs_get_device_info(&config) < 0)
return -1;