@@ -555,7 +555,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
555555 int ret ;
556556
557557 if (!options )
558- return 0 ;
558+ goto default_check ;
559559
560560 while ((p = strsep (& options , "," )) != NULL ) {
561561 int token ;
@@ -1090,6 +1090,7 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
10901090 return - EINVAL ;
10911091 }
10921092 }
1093+ default_check :
10931094#ifdef CONFIG_QUOTA
10941095 if (f2fs_check_quota_options (sbi ))
10951096 return - EINVAL ;
@@ -1162,6 +1163,11 @@ static int parse_options(struct super_block *sb, char *options, bool is_remount)
11621163 */
11631164 if (F2FS_OPTION (sbi ).active_logs != NR_CURSEG_TYPE )
11641165 F2FS_OPTION (sbi ).whint_mode = WHINT_MODE_OFF ;
1166+
1167+ if (f2fs_sb_has_readonly (sbi ) && !f2fs_readonly (sbi -> sb )) {
1168+ f2fs_err (sbi , "Allow to mount readonly mode only" );
1169+ return - EROFS ;
1170+ }
11651171 return 0 ;
11661172}
11671173
@@ -1819,7 +1825,11 @@ static int f2fs_show_options(struct seq_file *seq, struct dentry *root)
18191825static void default_options (struct f2fs_sb_info * sbi )
18201826{
18211827 /* init some FS parameters */
1822- F2FS_OPTION (sbi ).active_logs = NR_CURSEG_PERSIST_TYPE ;
1828+ if (f2fs_sb_has_readonly (sbi ))
1829+ F2FS_OPTION (sbi ).active_logs = NR_CURSEG_RO_TYPE ;
1830+ else
1831+ F2FS_OPTION (sbi ).active_logs = NR_CURSEG_PERSIST_TYPE ;
1832+
18231833 F2FS_OPTION (sbi ).inline_xattr_size = DEFAULT_INLINE_XATTR_ADDRS ;
18241834 F2FS_OPTION (sbi ).whint_mode = WHINT_MODE_OFF ;
18251835 F2FS_OPTION (sbi ).alloc_mode = ALLOC_MODE_DEFAULT ;
@@ -2004,6 +2014,11 @@ static int f2fs_remount(struct super_block *sb, int *flags, char *data)
20042014 if (f2fs_readonly (sb ) && (* flags & SB_RDONLY ))
20052015 goto skip ;
20062016
2017+ if (f2fs_sb_has_readonly (sbi ) && !(* flags & SB_RDONLY )) {
2018+ err = - EROFS ;
2019+ goto restore_opts ;
2020+ }
2021+
20072022#ifdef CONFIG_QUOTA
20082023 if (!f2fs_readonly (sb ) && (* flags & SB_RDONLY )) {
20092024 err = dquot_suspend (sb , -1 );
@@ -3137,14 +3152,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
31373152 ovp_segments = le32_to_cpu (ckpt -> overprov_segment_count );
31383153 reserved_segments = le32_to_cpu (ckpt -> rsvd_segment_count );
31393154
3140- if (unlikely (fsmeta < F2FS_MIN_META_SEGMENTS ||
3155+ if (!f2fs_sb_has_readonly (sbi ) &&
3156+ unlikely (fsmeta < F2FS_MIN_META_SEGMENTS ||
31413157 ovp_segments == 0 || reserved_segments == 0 )) {
31423158 f2fs_err (sbi , "Wrong layout: check mkfs.f2fs version" );
31433159 return 1 ;
31443160 }
3145-
31463161 user_block_count = le64_to_cpu (ckpt -> user_block_count );
3147- segment_count_main = le32_to_cpu (raw_super -> segment_count_main );
3162+ segment_count_main = le32_to_cpu (raw_super -> segment_count_main ) +
3163+ (f2fs_sb_has_readonly (sbi ) ? 1 : 0 );
31483164 log_blocks_per_seg = le32_to_cpu (raw_super -> log_blocks_per_seg );
31493165 if (!user_block_count || user_block_count >=
31503166 segment_count_main << log_blocks_per_seg ) {
@@ -3175,6 +3191,10 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
31753191 if (le32_to_cpu (ckpt -> cur_node_segno [i ]) >= main_segs ||
31763192 le16_to_cpu (ckpt -> cur_node_blkoff [i ]) >= blocks_per_seg )
31773193 return 1 ;
3194+
3195+ if (f2fs_sb_has_readonly (sbi ))
3196+ goto check_data ;
3197+
31783198 for (j = i + 1 ; j < NR_CURSEG_NODE_TYPE ; j ++ ) {
31793199 if (le32_to_cpu (ckpt -> cur_node_segno [i ]) ==
31803200 le32_to_cpu (ckpt -> cur_node_segno [j ])) {
@@ -3185,10 +3205,15 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
31853205 }
31863206 }
31873207 }
3208+ check_data :
31883209 for (i = 0 ; i < NR_CURSEG_DATA_TYPE ; i ++ ) {
31893210 if (le32_to_cpu (ckpt -> cur_data_segno [i ]) >= main_segs ||
31903211 le16_to_cpu (ckpt -> cur_data_blkoff [i ]) >= blocks_per_seg )
31913212 return 1 ;
3213+
3214+ if (f2fs_sb_has_readonly (sbi ))
3215+ goto skip_cross ;
3216+
31923217 for (j = i + 1 ; j < NR_CURSEG_DATA_TYPE ; j ++ ) {
31933218 if (le32_to_cpu (ckpt -> cur_data_segno [i ]) ==
31943219 le32_to_cpu (ckpt -> cur_data_segno [j ])) {
@@ -3210,7 +3235,7 @@ int f2fs_sanity_check_ckpt(struct f2fs_sb_info *sbi)
32103235 }
32113236 }
32123237 }
3213-
3238+ skip_cross :
32143239 sit_bitmap_size = le32_to_cpu (ckpt -> sit_ver_bitmap_bytesize );
32153240 nat_bitmap_size = le32_to_cpu (ckpt -> nat_ver_bitmap_bytesize );
32163241
0 commit comments