f2fs-tools: add -g to give default options
PATCH 1/1 f2fs-tools: add -g to give default options
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 <[email protected]>
--- fsck/main.c | 31 ++++++++++++++++++++++++++++++- include/f2fs_fs.h | 6 ++++++ mkfs/f2fs_format_main.c | 26 +++++++++++++++++++++++++- 3 files changed, 61 insertions(+), 2 deletions(-)
fsck/main.c +30 -1
@@ -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);
include/f2fs_fs.h +6 -0
@@ -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;
mkfs/f2fs_format_main.c +25 -1
@@ -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"
Signature · 6 lines
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
Quoted 10 lines · 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 <[email protected]>
Reviewed-by Chao Yu <[email protected]>
Thanks,
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot