From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@kernel.org>
Subject: [PATCH] fsck.f2fs: add -O features to tune the bits
Date: Thu, 19 Apr 2018 13:54:32 -0700 [thread overview]
Message-ID: <20180419205432.21624-1-jaegeuk@kernel.org> (raw)
This patch add -O features for fsck.f2fs in order to tune the feature bits.
Currently, it supports -O encrypt only.
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fsck/fsck.h | 1 +
fsck/main.c | 9 ++++++++-
fsck/mount.c | 39 ++++++++++++++++++++++++++++++++++++++-
fsck/resize.c | 18 +-----------------
4 files changed, 48 insertions(+), 19 deletions(-)
diff --git a/fsck/fsck.h b/fsck/fsck.h
index 8e133fa..3e13fc6 100644
--- a/fsck/fsck.h
+++ b/fsck/fsck.h
@@ -176,6 +176,7 @@ extern void move_curseg_info(struct f2fs_sb_info *, u64);
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);
diff --git a/fsck/main.c b/fsck/main.c
index 9256d21..c4dd8b1 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -28,6 +28,8 @@ struct f2fs_fsck gfsck;
extern struct sparse_file *f2fs_sparse_file;
#endif
+INIT_FEATURE_TABLE;
+
static char *absolute_path(const char *file)
{
char *ret;
@@ -54,6 +56,7 @@ void fsck_usage()
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");
@@ -180,7 +183,7 @@ void f2fs_parse_options(int argc, char *argv[])
}
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},
@@ -203,6 +206,10 @@ void f2fs_parse_options(int argc, char *argv[])
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
diff --git a/fsck/mount.c b/fsck/mount.c
index e5574c5..b374b46 100644
--- a/fsck/mount.c
+++ b/fsck/mount.c
@@ -2144,6 +2144,22 @@ void write_checkpoint(struct f2fs_sb_info *sbi)
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);
@@ -2314,6 +2330,26 @@ static int check_sector_size(struct f2fs_super_block *sb)
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;
@@ -2365,7 +2401,8 @@ int f2fs_do_mount(struct f2fs_sb_info *sbi)
}
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))
diff --git a/fsck/resize.c b/fsck/resize.c
index 019da71..d285dd7 100644
--- a/fsck/resize.c
+++ b/fsck/resize.c
@@ -569,22 +569,6 @@ static void rebuild_checkpoint(struct f2fs_sb_info *sbi,
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);
@@ -636,6 +620,6 @@ int f2fs_resize(struct f2fs_sb_info *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;
}
--
2.17.0.484.g0c8726318c-goog
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
next reply other threads:[~2018-04-19 20:54 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-19 20:54 Jaegeuk Kim [this message]
2018-04-20 1:46 ` [PATCH] fsck.f2fs: add -O features to tune the bits Junling Zheng
2018-04-20 1:57 ` Chao Yu
2018-04-20 2:52 ` Jaegeuk Kim
2018-04-23 7:32 ` [RFC PATCH] f2fs-tools: introduce tune.f2fs Junling Zheng
2018-04-26 2:10 ` Junling Zheng
2018-04-26 16:13 ` Jaegeuk Kim
2018-04-27 2:32 ` Chao Yu
2018-04-28 2:49 ` Jaegeuk Kim
2018-05-02 2:20 ` Chao Yu
2018-05-04 19:06 ` Jaegeuk Kim
2018-05-07 12:25 ` Chao Yu
2018-04-23 3:55 ` [PATCH] fsck.f2fs: add -O features to tune the bits Chao Yu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180419205432.21624-1-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).