* [PATCH] f2fs-tools: add -g to give default options
@ 2018-04-19 18:34 Jaegeuk Kim
2018-04-23 3:53 ` Chao Yu
0 siblings, 1 reply; 2+ messages in thread
From: Jaegeuk Kim @ 2018-04-19 18:34 UTC (permalink / raw)
To: linux-f2fs-devel; +Cc: Jaegeuk Kim
This patch adds -g option to set default options for specific environment.
I added it for android as a example.
# mkfs.f2fs -g android $dev
: gives "-d1 -f -O encrypt -O quota -w 4096"
# fsck.f2fs -g android $dev
: gives "-a"
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
---
fsck/main.c | 31 ++++++++++++++++++++++++++++++-
include/f2fs_fs.h | 6 ++++++
mkfs/f2fs_format_main.c | 26 +++++++++++++++++++++++++-
3 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/fsck/main.c b/fsck/main.c
index ca3b789..9256d21 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -53,6 +53,7 @@ void fsck_usage()
MSG(0, " -a check/fix potential corruption, reported by f2fs\n");
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, " -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");
@@ -145,6 +146,20 @@ static void error_out(char *prog)
MSG(0, "\nWrong program.\n");
}
+static void __add_fsck_options(void)
+{
+ /* -a */
+ c.auto_fix = 1;
+}
+
+static void add_default_options(void)
+{
+ switch (c.defset) {
+ case CONF_ANDROID:
+ __add_fsck_options();
+ }
+}
+
void f2fs_parse_options(int argc, char *argv[])
{
int option = 0;
@@ -165,7 +180,7 @@ void f2fs_parse_options(int argc, char *argv[])
}
if (!strcmp("fsck.f2fs", prog)) {
- const char *option_string = ":ad:fp:q:StyV";
+ const char *option_string = ":ad:fg:p:q:StyV";
int opt = 0;
struct option long_opt[] = {
{"dry-run", no_argument, 0, 1},
@@ -184,6 +199,10 @@ void f2fs_parse_options(int argc, char *argv[])
c.auto_fix = 1;
MSG(0, "Info: Fix the reported corruption.\n");
break;
+ case 'g':
+ if (!strcmp(optarg, "android"))
+ c.defset = CONF_ANDROID;
+ break;
case 'p':
/* preen mode has different levels:
* 0: default level, the same as -a
@@ -284,6 +303,14 @@ void f2fs_parse_options(int argc, char *argv[])
MSG(0, "Info: Debug level = %d\n",
c.dbg_lv);
break;
+ case 'g':
+ if (!strcmp(optarg, "android")) {
+ c.defset = CONF_ANDROID;
+ MSG(0, "Info: Set conf for android\n");
+ break;
+ }
+ err = EWRONG_OPT;
+ break;
case 'i':
if (strncmp(optarg, "0x", 2))
ret = sscanf(optarg, "%d",
@@ -496,6 +523,8 @@ void f2fs_parse_options(int argc, char *argv[])
}
}
+ add_default_options();
+
if (optind >= argc) {
MSG(0, "\tError: Device not specified\n");
error_out(prog);
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index cbfdab5..54ac1c8 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -303,6 +303,11 @@ enum f2fs_config_func {
SLOAD,
};
+enum default_set {
+ CONF_NONE = 0,
+ CONF_ANDROID,
+};
+
struct device_info {
char *path;
int32_t fd;
@@ -361,6 +366,7 @@ struct f2fs_configuration {
void *private;
int dry_run;
int fix_on;
+ int defset;
int bug_on;
int auto_fix;
int preen_mode;
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 7dd4054..4e39fbd 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -65,6 +65,7 @@ static void mkfs_usage()
MSG(0, " -e [cold file ext list] e.g. \"mp3,gif,mov\"\n");
MSG(0, " -E [hot file ext list] e.g. \"db\"\n");
MSG(0, " -f force overwrite the exist filesystem\n");
+ MSG(0, " -g add default options\n");
MSG(0, " -i extended node bitmap, node ratio is 20%% by default\n");
MSG(0, " -l label\n");
MSG(0, " -m support zoned block device [default:0]\n");
@@ -98,6 +99,9 @@ static void f2fs_show_info()
if (c.vol_label)
MSG(0, "Info: Label = %s\n", c.vol_label);
MSG(0, "Info: Trim is %s\n", c.trim ? "enabled": "disabled");
+
+ if (c.defset == CONF_ANDROID)
+ MSG(0, "Info: Set conf for android\n");
}
static inline u32 feature_map(char *feature)
@@ -146,9 +150,23 @@ static void parse_feature(const char *features)
free(buf);
}
+static void add_default_options(void)
+{
+ switch (c.defset) {
+ case CONF_ANDROID:
+ /* -d1 -f -O encrypt -O quota -w 4096 */
+ c.dbg_lv = 1;
+ force_overwrite = 1;
+ c.feature |= cpu_to_le32(F2FS_FEATURE_ENCRYPT);
+ c.feature |= cpu_to_le32(F2FS_FEATURE_QUOTA_INO);
+ c.wanted_sector_size = 4096;
+ break;
+ }
+}
+
static void f2fs_parse_options(int argc, char *argv[])
{
- static const char *option_string = "qa:c:d:e:E:il:mo:O:s:S:z:t:fw:V";
+ static const char *option_string = "qa:c:d:e:E:g:il:mo:O:s:S:z:t:fw:V";
int32_t option=0;
while ((option = getopt(argc,argv,option_string)) != EOF) {
@@ -181,6 +199,10 @@ static void f2fs_parse_options(int argc, char *argv[])
case 'E':
c.extension_list[1] = strdup(optarg);
break;
+ case 'g':
+ if (!strcmp(optarg, "android"))
+ c.defset = CONF_ANDROID;
+ break;
case 'i':
c.large_nat_bitmap = 1;
break;
@@ -231,6 +253,8 @@ static void f2fs_parse_options(int argc, char *argv[])
}
}
+ add_default_options();
+
if (!(c.feature & cpu_to_le32(F2FS_FEATURE_EXTRA_ATTR))) {
if (c.feature & cpu_to_le32(F2FS_FEATURE_PRJQUOTA)) {
MSG(0, "\tInfo: project quota feature should always been"
--
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] f2fs-tools: add -g to give default options
2018-04-19 18:34 [PATCH] f2fs-tools: add -g to give default options Jaegeuk Kim
@ 2018-04-23 3:53 ` Chao Yu
0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2018-04-23 3:53 UTC (permalink / raw)
To: Jaegeuk Kim, linux-f2fs-devel
On 2018/4/20 2:34, Jaegeuk Kim wrote:
> This patch adds -g option to set default options for specific environment.
> I added it for android as a example.
>
> # mkfs.f2fs -g android $dev
> : gives "-d1 -f -O encrypt -O quota -w 4096"
>
> # fsck.f2fs -g android $dev
> : gives "-a"
>
> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Reviewed-by: Chao Yu <yuchao0@huawei.com>
Thanks,
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-04-23 3:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-19 18:34 [PATCH] f2fs-tools: add -g to give default options Jaegeuk Kim
2018-04-23 3:53 ` Chao Yu
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).