This patch add -O features for fsck.f2fs in order to tune the feature bits.
Currently, it supports -O encrypt only.
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
extern void write_curseg_info(struct f2fs_sb_info *);
extern int find_next_free_block(struct f2fs_sb_info *, u64 *, int, int);
extern void write_checkpoint(struct f2fs_sb_info *);
+extern void write_superblock(struct f2fs_super_block *);
extern void update_data_blkaddr(struct f2fs_sb_info *, nid_t, u16, block_t);
extern void update_nat_blkaddr(struct f2fs_sb_info *, nid_t, nid_t, block_t);
extern struct sparse_file *f2fs_sparse_file;
#endif
+INIT_FEATURE_TABLE;
+
static char *absolute_path(const char *file)
{
char *ret;
MSG(0, " -d debug level [default:0]\n");
MSG(0, " -f check/fix entire partition\n");
MSG(0, " -g add default options\n");
+ MSG(0, " -O feature1[feature2,feature3,...] e.g. \"encrypt\"\n");
MSG(0, " -p preen mode [default:0 the same as -a [0|1]]\n");
MSG(0, " -S sparse_mode\n");
MSG(0, " -t show directory tree\n");
}
if (!strcmp("fsck.f2fs", prog)) {
- const char *option_string = ":ad:fg:p:q:StyV";
+ const char *option_string = ":ad:fg:O:p:q:StyV";
int opt = 0;
struct option long_opt[] = {
{"dry-run", no_argument, 0, 1},
if (!strcmp(optarg, "android"))
c.defset = CONF_ANDROID;
break;
+ case 'O':
+ if (parse_feature(feature_table, optarg))
+ fsck_usage();
+ break;
case 'p':
/* preen mode has different levels:
* 0: default level, the same as -a
ASSERT(ret >= 0);
}
+void write_superblock(struct f2fs_super_block *new_sb)
+{
+ int index, ret;
+ u_int8_t *buf;
+
+ buf = calloc(BLOCK_SZ, 1);
+
+ memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
+ for (index = 0; index < 2; index++) {
+ ret = dev_write_block(buf, index);
+ ASSERT(ret >= 0);
+ }
+ free(buf);
+ DBG(0, "Info: Done to rebuild superblock\n");
+}
+
void build_nat_area_bitmap(struct f2fs_sb_info *sbi)
{
struct curseg_info *curseg = CURSEG_I(sbi, CURSEG_HOT_DATA);
return 0;
}
+static void tune_sb_features(struct f2fs_sb_info *sbi)
+{
+ int sb_changed = 0;
+ struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
+
+ if (!(sb->feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) &&
+ c.feature & cpu_to_le32(F2FS_FEATURE_ENCRYPT)) {
+ sb->feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
+ MSG(0, "Info: Set Encryption feature\n");
+ sb_changed = 1;
+ }
+ /* TODO: quota needs to allocate inode numbers */
+
+ c.feature = sb->feature;
+ if (!sb_changed)
+ return;
+
+ write_superblock(sb);
+}
+
int f2fs_do_mount(struct f2fs_sb_info *sbi)
{
struct f2fs_checkpoint *cp = NULL;
}
c.bug_on = 0;
- c.feature = sb->feature;
+
+ tune_sb_features(sbi);
/* precompute checksum seed for metadata */
if (c.feature & cpu_to_le32(F2FS_FEATURE_INODE_CHKSUM))
DBG(0, "Info: Done to rebuild checkpoint blocks\n");
}
-static void rebuild_superblock(struct f2fs_super_block *new_sb)
-{
- int index, ret;
- u_int8_t *buf;
-
- buf = calloc(BLOCK_SZ, 1);
-
- memcpy(buf + F2FS_SUPER_OFFSET, new_sb, sizeof(*new_sb));
- for (index = 0; index < 2; index++) {
- ret = dev_write_block(buf, index);
- ASSERT(ret >= 0);
- }
- free(buf);
- DBG(0, "Info: Done to rebuild superblock\n");
-}
-
int f2fs_resize(struct f2fs_sb_info *sbi)
{
struct f2fs_super_block *sb = F2FS_RAW_SUPER(sbi);
migrate_nat(sbi, new_sb);
migrate_sit(sbi, new_sb, offset_seg);
rebuild_checkpoint(sbi, new_sb, offset_seg);
- rebuild_superblock(new_sb);
+ write_superblock(new_sb);
return 0;
}