Add a `-P` flag to populate a newly created filesystem from a directory. This flag will be mutually exclusive with the `-p` prototype flag. Signed-off-by: Luca Di Maio <luca.dimaio1@xxxxxxxxx> --- mkfs/xfs_mkfs.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c index f5556fc..44a8d73 100644 --- a/mkfs/xfs_mkfs.c +++ b/mkfs/xfs_mkfs.c @@ -14,6 +14,7 @@ #include "libfrog/dahashselftest.h" #include "libfrog/fsproperties.h" #include "proto.h" +#include "populate.h" #include <ini.h> #define TERABYTES(count, blog) ((uint64_t)(count) << (40 - (blog))) @@ -1022,6 +1023,7 @@ struct cli_params { char *cfgfile; char *protofile; + char *directory; enum fsprop_autofsck autofsck; @@ -1170,6 +1172,7 @@ usage( void ) /* naming */ [-n size=num,version=2|ci,ftype=0|1,parent=0|1]]\n\ /* no-op info only */ [-N]\n\ /* prototype file */ [-p fname]\n\ +/* populate */ [-P directory]\n\ /* quiet */ [-q]\n\ /* realtime subvol */ [-r extsize=num,size=num,rtdev=xxx,rgcount=n,rgsize=n,\n\ concurrency=num]\n\ @@ -5110,7 +5113,7 @@ main( memcpy(&cli.sb_feat, &dft.sb_feat, sizeof(cli.sb_feat)); memcpy(&cli.fsx, &dft.fsx, sizeof(cli.fsx)); - while ((c = getopt_long(argc, argv, "b:c:d:i:l:L:m:n:KNp:qr:s:CfV", + while ((c = getopt_long(argc, argv, "b:c:d:i:l:L:P:m:n:KNp:qr:s:CfV", long_options, &option_index)) != EOF) { switch (c) { case 0: @@ -5136,6 +5139,9 @@ main( illegal(optarg, "L"); cfg.label = optarg; break; + case 'P': + cli.directory = optarg; + break; case 'N': dry_run = 1; break; @@ -5334,9 +5340,20 @@ main( initialise_ag_freespace(mp, agno, worst_freelist); /* - * Allocate the root inode and anything else in the proto file. + * Allocate the root inode and anything else in the proto file or source + * directory. + * Both functions will allocate the root inode, so we use them mutually. */ - parse_proto(mp, &cli.fsx, &protostring, cli.proto_slashes_are_spaces); + if (cli.protofile && cli.directory) { + fprintf(stderr, + _("%s: error: specifying both -P and -p is not supported\n"), + progname); + exit(1); + } + if (!cli.directory) + parse_proto(mp, &cli.fsx, &protostring, cli.proto_slashes_are_spaces); + else + populate_from_dir(mp, NULL, &cli.fsx, cli.directory); /* * Protect ourselves against possible stupidity -- 2.49.0