@@ -443,6 +443,7 @@ static const char * const mkfs_usage[] = {
443443 OPTLINE ("-u|--subvol TYPE:SUBDIR" , "create SUBDIR as subvolume rather than normal directory, can be specified multiple times" ),
444444 OPTLINE ("--shrink" , "(with --rootdir) shrink the filled filesystem to minimal size" ),
445445 OPTLINE ("-K|--nodiscard" , "do not perform whole device TRIM" ),
446+ OPTLINE ("--compress ALGO[:LEVEL]" , "compression algorithm and level to use; ALGO can be no (default), zlib" ),
446447 OPTLINE ("-f|--force" , "force overwrite of existing filesystem" ),
447448 "General:" ,
448449 OPTLINE ("-q|--quiet" , "no messages except errors" ),
@@ -1058,6 +1059,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
10581059 char * source_dir = NULL ;
10591060 struct rootdir_subvol * rds ;
10601061 bool has_default_subvol = false;
1062+ enum btrfs_compression_type compression = BTRFS_COMPRESS_NONE ;
1063+ u64 compression_level = 0 ;
10611064 LIST_HEAD (subvols );
10621065
10631066 cpu_detect_flags ();
@@ -1072,6 +1075,7 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
10721075 GETOPT_VAL_CHECKSUM ,
10731076 GETOPT_VAL_GLOBAL_ROOTS ,
10741077 GETOPT_VAL_DEVICE_UUID ,
1078+ GETOPT_VAL_COMPRESS ,
10751079 };
10761080 static const struct option long_options [] = {
10771081 { "byte-count" , required_argument , NULL , 'b' },
@@ -1099,6 +1103,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
10991103 { "quiet" , 0 , NULL , 'q' },
11001104 { "verbose" , 0 , NULL , 'v' },
11011105 { "shrink" , no_argument , NULL , GETOPT_VAL_SHRINK },
1106+ { "compress" , required_argument , NULL ,
1107+ GETOPT_VAL_COMPRESS },
11021108#if EXPERIMENTAL
11031109 { "param" , required_argument , NULL , GETOPT_VAL_PARAM },
11041110 { "num-global-roots" , required_argument , NULL , GETOPT_VAL_GLOBAL_ROOTS },
@@ -1272,6 +1278,38 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
12721278 case 'q' :
12731279 bconf_be_quiet ();
12741280 break ;
1281+ case GETOPT_VAL_COMPRESS : {
1282+ char * colon ;
1283+ size_t type_size ;
1284+
1285+ if (!strcmp (optarg , "no" )) {
1286+ compression = BTRFS_COMPRESS_NONE ;
1287+ break ;
1288+ }
1289+
1290+ colon = strstr (optarg , ":" );
1291+
1292+ if (colon )
1293+ type_size = colon - optarg ;
1294+ else
1295+ type_size = strlen (optarg );
1296+
1297+ if (!strncmp (optarg , "zlib" , type_size )) {
1298+ compression = BTRFS_COMPRESS_ZLIB ;
1299+ } else {
1300+ error ("unrecognized compression type %s" ,
1301+ optarg );
1302+ ret = 1 ;
1303+ goto error ;
1304+ }
1305+
1306+ if (colon )
1307+ compression_level = arg_strtou64 (colon + 1 );
1308+ else
1309+ compression_level = 0 ;
1310+
1311+ break ;
1312+ }
12751313 case GETOPT_VAL_DEVICE_UUID :
12761314 strncpy_null (dev_uuid , optarg , BTRFS_UUID_UNPARSED_SIZE );
12771315 break ;
@@ -1953,7 +1991,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
19531991 }
19541992
19551993 ret = btrfs_mkfs_fill_dir (trans , source_dir , root ,
1956- & subvols );
1994+ & subvols , compression ,
1995+ compression_level );
19571996 if (ret ) {
19581997 error ("error while filling filesystem: %d" , ret );
19591998 btrfs_abort_transaction (trans , ret );
0 commit comments