mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2024-11-30 23:54:10 +08:00
btrfs-progs: mkfs: new option to specify checksum type
Add an option to mkfs to specify which checksum algorithm will be used for the filesystem. Currently only crc32c is supported. The option name is -c, presumably one of the comonly used options so it gets the lowercase option. Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
ed33908b44
commit
56198f3a9d
@ -135,7 +135,7 @@ static int setup_temp_super(int fd, struct btrfs_mkfs_config *cfg,
|
||||
super->__unused_leafsize = cpu_to_le32(cfg->nodesize);
|
||||
btrfs_set_super_nodesize(super, cfg->nodesize);
|
||||
btrfs_set_super_stripesize(super, cfg->stripesize);
|
||||
btrfs_set_super_csum_type(super, BTRFS_CSUM_TYPE_CRC32);
|
||||
btrfs_set_super_csum_type(super, cfg->csum_type);
|
||||
btrfs_set_super_chunk_root(super, chunk_bytenr);
|
||||
btrfs_set_super_cache_generation(super, -1);
|
||||
btrfs_set_super_incompat_flags(super, cfg->features);
|
||||
|
@ -202,7 +202,7 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
||||
super.__unused_leafsize = cpu_to_le32(cfg->nodesize);
|
||||
btrfs_set_super_nodesize(&super, cfg->nodesize);
|
||||
btrfs_set_super_stripesize(&super, cfg->stripesize);
|
||||
btrfs_set_super_csum_type(&super, BTRFS_CSUM_TYPE_CRC32);
|
||||
btrfs_set_super_csum_type(&super, cfg->csum_type);
|
||||
btrfs_set_super_chunk_root_generation(&super, 1);
|
||||
btrfs_set_super_cache_generation(&super, -1);
|
||||
btrfs_set_super_incompat_flags(&super, cfg->features);
|
||||
|
25
mkfs/main.c
25
mkfs/main.c
@ -341,6 +341,8 @@ static void print_usage(int ret)
|
||||
printf("\t-m|--metadata PROFILE metadata profile, values like for data profile\n");
|
||||
printf("\t-M|--mixed mix metadata and data together\n");
|
||||
printf(" features:\n");
|
||||
printf("\t--csum TYPE\n");
|
||||
printf("\t--checksum TYPE checksum algorithm to use (default: crc32c)\n");
|
||||
printf("\t-n|--nodesize SIZE size of btree nodes\n");
|
||||
printf("\t-s|--sectorsize SIZE data block size (may not be mountable by current kernel)\n");
|
||||
printf("\t-O|--features LIST comma separated list of filesystem features (use '-O list-all' to list features)\n");
|
||||
@ -386,6 +388,18 @@ static u64 parse_profile(const char *s)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static enum btrfs_csum_type parse_csum_type(const char *s)
|
||||
{
|
||||
if (strcasecmp(s, "crc32c") == 0) {
|
||||
return BTRFS_CSUM_TYPE_CRC32;
|
||||
} else {
|
||||
error("unknown csum type %s", s);
|
||||
exit(1);
|
||||
}
|
||||
/* not reached */
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char *parse_label(const char *input)
|
||||
{
|
||||
int len = strlen(input);
|
||||
@ -832,15 +846,20 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
|
||||
u64 features = BTRFS_MKFS_DEFAULT_FEATURES;
|
||||
struct mkfs_allocation allocation = { 0 };
|
||||
struct btrfs_mkfs_config mkfs_cfg;
|
||||
enum btrfs_csum_type csum_type = BTRFS_CSUM_TYPE_CRC32;
|
||||
|
||||
crc32c_optimization_init();
|
||||
|
||||
while(1) {
|
||||
int c;
|
||||
enum { GETOPT_VAL_SHRINK = 257 };
|
||||
enum { GETOPT_VAL_SHRINK = 257, GETOPT_VAL_CHECKSUM };
|
||||
static const struct option long_options[] = {
|
||||
{ "alloc-start", required_argument, NULL, 'A'},
|
||||
{ "byte-count", required_argument, NULL, 'b' },
|
||||
{ "csum", required_argument, NULL,
|
||||
GETOPT_VAL_CHECKSUM },
|
||||
{ "checksum", required_argument, NULL,
|
||||
GETOPT_VAL_CHECKSUM },
|
||||
{ "force", no_argument, NULL, 'f' },
|
||||
{ "leafsize", required_argument, NULL, 'l' },
|
||||
{ "label", required_argument, NULL, 'L'},
|
||||
@ -938,6 +957,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
|
||||
case GETOPT_VAL_SHRINK:
|
||||
shrink_rootdir = true;
|
||||
break;
|
||||
case GETOPT_VAL_CHECKSUM:
|
||||
csum_type = parse_csum_type(optarg);
|
||||
break;
|
||||
case GETOPT_VAL_HELP:
|
||||
default:
|
||||
print_usage(c != GETOPT_VAL_HELP);
|
||||
@ -1177,6 +1199,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
|
||||
mkfs_cfg.sectorsize = sectorsize;
|
||||
mkfs_cfg.stripesize = stripesize;
|
||||
mkfs_cfg.features = features;
|
||||
mkfs_cfg.csum_type = csum_type;
|
||||
|
||||
ret = make_btrfs(fd, &mkfs_cfg);
|
||||
if (ret) {
|
||||
|
Loading…
Reference in New Issue
Block a user