@@ -324,7 +324,9 @@ static void print_usage(int ret)
fprintf(stderr, "\t-s|--sectorsize SIZE min block allocation (may not mountable by current kernel)\n");
fprintf(stderr, "\t-r|--rootdir DIR the source directory\n");
fprintf(stderr, "\t-K|--nodiscard do not perform whole device TRIM\n");
- fprintf(stderr, "\t-O|--features LIST comma separated list of filesystem features, use '-O list-all' to list features\n");
+ fprintf(stderr, "\t-O|--features LIST comma separated list of filesystem features\n");
+ fprintf(stderr, "\t use '-O list-all' to list features\n");
+ fprintf(stderr, "\t use '-O comp=<x.y>|<x.y.z>' x.y.z is the minimum kernel version to be supported\n");
fprintf(stderr, "\t-U|--uuid UUID specify the filesystem UUID\n");
fprintf(stderr, "\t-q|--quiet no messages except errors\n");
fprintf(stderr, "\t-V|--version print the mkfs.btrfs version and exit\n");
@@ -1439,7 +1441,24 @@ int main(int ac, char **av)
case 'O': {
char *orig = strdup(optarg);
char *tmp = orig;
-
+ char *tok;
+
+ tok = strtok(tmp, "=");
+ if (!strcmp(tok, "comp")) {
+ tok = strtok(NULL, "=");
+ if (!tok) {
+ fprintf(stderr,
+ "Provide a version for 'comp=' option, ref to 'mkfs.btrfs -O list-all'\n");
+ exit(1);
+ }
+ if (btrfs_features_allowed_by_version(tok, &features) < 0) {
+ fprintf(stderr, "Wrong version format: '%s'\n", tok);
+ exit(1);
+ }
+ features &= BTRFS_MKFS_DEFAULT_FEATURES;
+ goto cont;
+ }
+ tmp = orig;
tmp = btrfs_parse_fs_features(tmp, &features);
if (tmp) {
fprintf(stderr,
@@ -1448,6 +1467,7 @@ int main(int ac, char **av)
free(orig);
exit(1);
}
+cont:
free(orig);
if (features & BTRFS_FEATURE_LIST_ALL) {
btrfs_list_all_fs_features(0);
This provides default feature set by version, for mkfs.btrfs through the new option '-O comp=<x.y>|<x.y.z>', where x.y.z is the minimum kernel version that should be supported. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- mkfs.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-)