linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHSET v2 0/3] xfsprogs: random fixes for 6.2
@ 2023-03-01 16:05 Darrick J. Wong
  2023-03-01 16:05 ` [PATCH 1/3] mkfs: check dirent names when reading protofile Darrick J. Wong
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Darrick J. Wong @ 2023-03-01 16:05 UTC (permalink / raw)
  To: djwong, cem; +Cc: linux-xfs, daan.j.demeyer

Hi all,

This is a rollup of the remaining random fixes I've collected for
xfsprogs 6.2.  First, we now check for invalid dirent names in the
protofile rather than let mkfs spit out a corrupt filesystem.

Second, we add some -p options so that one can specify a protofile in
the configuration file, and then make it so that users can turn on
substituting slashes for spaces in the dirent names in the protofile.

If you're going to start using this mess, you probably ought to just
pull from my git trees, which are linked below.

This is an extraordinary way to destroy everything.  Enjoy!
Comments and questions are, as always, welcome.

--D

xfsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/xfsprogs-dev.git/log/?h=xfsprogs-fixes-6.2
---
 man/man8/mkfs.xfs.8.in |   32 +++++++++++++++++++--
 mkfs/proto.c           |   37 +++++++++++++++++++++++--
 mkfs/proto.h           |    3 +-
 mkfs/xfs_mkfs.c        |   72 +++++++++++++++++++++++++++++++++++++++++++-----
 4 files changed, 129 insertions(+), 15 deletions(-)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] mkfs: check dirent names when reading protofile
  2023-03-01 16:05 [PATCHSET v2 0/3] xfsprogs: random fixes for 6.2 Darrick J. Wong
@ 2023-03-01 16:05 ` Darrick J. Wong
  2023-03-03 10:45   ` Carlos Maiolino
  2023-03-01 16:05 ` [PATCH 2/3] mkfs: use suboption processing for -p Darrick J. Wong
  2023-03-01 16:05 ` [PATCH 3/3] mkfs: substitute slashes with spaces in protofiles Darrick J. Wong
  2 siblings, 1 reply; 7+ messages in thread
From: Darrick J. Wong @ 2023-03-01 16:05 UTC (permalink / raw)
  To: djwong, cem; +Cc: linux-xfs, daan.j.demeyer

From: Darrick J. Wong <djwong@kernel.org>

The protofile parser in mkfs does not check directory entry names when
populating the filesystem.  The libxfs directory code doesn't check them
either, since they depend on the Linux VFS to sanitize incoming names.
If someone puts a slash in the first (name) column in the protofile,
this results in a successful format and xfs_repair -n immediately
complains.

Screen the names that are being read from the protofile.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 mkfs/proto.c |    6 ++++++
 1 file changed, 6 insertions(+)


diff --git a/mkfs/proto.c b/mkfs/proto.c
index 68ecdbf3632..7e3fc1b8134 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -326,6 +326,12 @@ newdirent(
 	int	error;
 	int	rsv;
 
+	if (!libxfs_dir2_namecheck(name->name, name->len)) {
+		fprintf(stderr, _("%.*s: invalid directory entry name\n"),
+				name->len, name->name);
+		exit(1);
+	}
+
 	rsv = XFS_DIRENTER_SPACE_RES(mp, name->len);
 
 	error = -libxfs_dir_createname(tp, pip, name, inum, rsv);


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] mkfs: use suboption processing for -p
  2023-03-01 16:05 [PATCHSET v2 0/3] xfsprogs: random fixes for 6.2 Darrick J. Wong
  2023-03-01 16:05 ` [PATCH 1/3] mkfs: check dirent names when reading protofile Darrick J. Wong
@ 2023-03-01 16:05 ` Darrick J. Wong
  2023-03-03 11:16   ` Carlos Maiolino
  2023-03-01 16:05 ` [PATCH 3/3] mkfs: substitute slashes with spaces in protofiles Darrick J. Wong
  2 siblings, 1 reply; 7+ messages in thread
From: Darrick J. Wong @ 2023-03-01 16:05 UTC (permalink / raw)
  To: djwong, cem; +Cc: linux-xfs, daan.j.demeyer

From: Darrick J. Wong <djwong@kernel.org>

Use suboption processing for -p so that we can add a few behavioral
variants to protofiles in the next patch.  As a side effect of this
change, one can now provide the path to a protofile in the config
file:

[proto]
file=/tmp/protofile

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 man/man8/mkfs.xfs.8.in |   26 ++++++++++++++++++----
 mkfs/xfs_mkfs.c        |   58 ++++++++++++++++++++++++++++++++++++++++++------
 2 files changed, 73 insertions(+), 11 deletions(-)


diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in
index 211e7b0c7b8..e1ca40e5da6 100644
--- a/man/man8/mkfs.xfs.8.in
+++ b/man/man8/mkfs.xfs.8.in
@@ -28,7 +28,7 @@ mkfs.xfs \- construct an XFS filesystem
 .I naming_options
 ] [
 .B \-p
-.I protofile
+.I protofile_options
 ] [
 .B \-q
 ] [
@@ -834,12 +834,29 @@ When CRCs are enabled (the default), the ftype functionality is always
 enabled, and cannot be turned off.
 .IP
 In other words, this option is only tunable on the deprecated V4 format.
-.IP
 .RE
+.PP
+.PD 0
 .TP
-.BI \-p " protofile"
+.BI \-p " protofile_options"
+.TP
+.BI "Section Name: " [proto]
+.PD
+These options specify the protofile parameters for populating the filesystem.
+The valid
+.I protofile_options
+are:
+.RS 1.2i
+.TP
+.BI [file=] protofile
+The
+.B file=
+prefix is not required for this CLI argument for legacy reasons.
+If specified as a config file directive, the prefix is required.
+
 If the optional
-.BI \-p " protofile"
+.PD
+.I protofile
 argument is given,
 .B mkfs.xfs
 uses
@@ -979,6 +996,7 @@ in the directory. A scan of the protofile is
 always terminated with the dollar (
 .B $
 ) token.
+.RE
 .TP
 .B \-q
 Quiet option. Normally
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index e219ec166da..4248e6ec344 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -113,6 +113,11 @@ enum {
 	N_MAX_OPTS,
 };
 
+enum {
+	P_FILE = 0,
+	P_MAX_OPTS,
+};
+
 enum {
 	R_EXTSIZE = 0,
 	R_SIZE,
@@ -641,6 +646,21 @@ static struct opt_params nopts = {
 	},
 };
 
+static struct opt_params popts = {
+	.name = 'p',
+	.ini_section = "proto",
+	.subopts = {
+		[P_FILE] = "file",
+		[P_MAX_OPTS] = NULL,
+	},
+	.subopt_params = {
+		{ .index = P_FILE,
+		  .conflicts = { { NULL, LAST_CONFLICT } },
+		  .defaultval = SUBOPT_NEEDS_VAL,
+		},
+	},
+};
+
 static struct opt_params ropts = {
 	.name = 'r',
 	.ini_section = "realtime",
@@ -841,6 +861,7 @@ struct cli_params {
 	int	blocksize;
 
 	char	*cfgfile;
+	char	*protofile;
 
 	/* parameters that depend on sector/block size being validated. */
 	char	*dsize;
@@ -1750,6 +1771,33 @@ naming_opts_parser(
 	return 0;
 }
 
+static int
+proto_opts_parser(
+	struct opt_params	*opts,
+	int			subopt,
+	const char		*value,
+	struct cli_params	*cli)
+{
+	switch (subopt) {
+	case P_FILE:
+		fallthrough;
+	default:
+		if (cli->protofile) {
+			if (subopt < 0)
+				subopt = P_FILE;
+			respec(opts->name, opts->subopts, subopt);
+		}
+		cli->protofile = strdup(value);
+		if (!cli->protofile) {
+			fprintf(stderr,
+ _("Out of memory while saving protofile option.\n"));
+			exit(1);
+		}
+		break;
+	}
+	return 0;
+}
+
 static int
 rtdev_opts_parser(
 	struct opt_params	*opts,
@@ -1813,6 +1861,7 @@ static struct subopts {
 	{ &lopts, log_opts_parser },
 	{ &mopts, meta_opts_parser },
 	{ &nopts, naming_opts_parser },
+	{ &popts, proto_opts_parser },
 	{ &ropts, rtdev_opts_parser },
 	{ &sopts, sector_opts_parser },
 	{ NULL, NULL },
@@ -4013,7 +4062,6 @@ main(
 	int			discard = 1;
 	int			force_overwrite = 0;
 	int			quiet = 0;
-	char			*protofile = NULL;
 	char			*protostring = NULL;
 	int			worst_freelist = 0;
 
@@ -4119,6 +4167,7 @@ main(
 		case 'l':
 		case 'm':
 		case 'n':
+		case 'p':
 		case 'r':
 		case 's':
 			parse_subopts(c, optarg, &cli);
@@ -4134,11 +4183,6 @@ main(
 		case 'K':
 			discard = 0;
 			break;
-		case 'p':
-			if (protofile)
-				respec('p', NULL, 0);
-			protofile = optarg;
-			break;
 		case 'q':
 			quiet = 1;
 			break;
@@ -4165,7 +4209,7 @@ main(
 	 */
 	cfgfile_parse(&cli);
 
-	protostring = setup_proto(protofile);
+	protostring = setup_proto(cli.protofile);
 
 	/*
 	 * Extract as much of the valid config as we can from the CLI input


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] mkfs: substitute slashes with spaces in protofiles
  2023-03-01 16:05 [PATCHSET v2 0/3] xfsprogs: random fixes for 6.2 Darrick J. Wong
  2023-03-01 16:05 ` [PATCH 1/3] mkfs: check dirent names when reading protofile Darrick J. Wong
  2023-03-01 16:05 ` [PATCH 2/3] mkfs: use suboption processing for -p Darrick J. Wong
@ 2023-03-01 16:05 ` Darrick J. Wong
  2023-03-03 11:31   ` Carlos Maiolino
  2 siblings, 1 reply; 7+ messages in thread
From: Darrick J. Wong @ 2023-03-01 16:05 UTC (permalink / raw)
  To: djwong, cem; +Cc: linux-xfs, daan.j.demeyer

From: Darrick J. Wong <djwong@kernel.org>

A user requested the ability to specify directory entry names in a
protofile that have spaces in them.  The protofile format itself does
not allow spaces (yay 1973-era protofiles!) but it does allow slashes.
Slashes aren't allowed in directory entry names, so we'll permit this
one gross hack.  After this, the protofile:

/
0 0
d--775 1000 1000
: Descending path /code/t/fstests
 get/isk.sh   ---775 1000 1000 /code/t/fstests/getdisk.sh
$

Will produce "get isk.h" in the root directory when used thusly:

# mkfs.xfs -p slashes_are_spaces=1,/tmp/protofile -f /dev/sda

Requested-by: Daan De Meyer <daan.j.demeyer@gmail.com>
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 man/man8/mkfs.xfs.8.in |    6 ++++++
 mkfs/proto.c           |   31 +++++++++++++++++++++++++++++--
 mkfs/proto.h           |    3 ++-
 mkfs/xfs_mkfs.c        |   14 +++++++++++++-
 4 files changed, 50 insertions(+), 4 deletions(-)


diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in
index e1ca40e5da6..49e64d47ae4 100644
--- a/man/man8/mkfs.xfs.8.in
+++ b/man/man8/mkfs.xfs.8.in
@@ -996,6 +996,12 @@ in the directory. A scan of the protofile is
 always terminated with the dollar (
 .B $
 ) token.
+.TP
+.BI slashes_are_spaces= value
+If set to 1, slashes ("/") in the first token of each line of the protofile
+are converted to spaces.
+This enables the creation of a filesystem containing filenames with spaces.
+By default, this is set to 0.
 .RE
 .TP
 .B \-q
diff --git a/mkfs/proto.c b/mkfs/proto.c
index 7e3fc1b8134..ea31cfe5cfc 100644
--- a/mkfs/proto.c
+++ b/mkfs/proto.c
@@ -21,6 +21,7 @@ static int newfile(xfs_trans_t *tp, xfs_inode_t *ip, int symlink, int logit,
 static char *newregfile(char **pp, int *len);
 static void rtinit(xfs_mount_t *mp);
 static long filesize(int fd);
+static int slashes_are_spaces;
 
 /*
  * Use this for block reservations needed for mkfs's conditions
@@ -171,6 +172,30 @@ getstr(
 	return NULL;
 }
 
+/* Extract directory entry name from a protofile. */
+static char *
+getdirentname(
+	char	**pp)
+{
+	char	*p = getstr(pp);
+	char	*c = p;
+
+	if (!p)
+		return NULL;
+
+	if (!slashes_are_spaces)
+		return p;
+
+	/* Replace slash with space because slashes aren't allowed. */
+	while (*c) {
+		if (*c == '/')
+			*c = ' ';
+		c++;
+	}
+
+	return p;
+}
+
 static void
 rsvfile(
 	xfs_mount_t	*mp,
@@ -586,7 +611,7 @@ parseproto(
 			rtinit(mp);
 		tp = NULL;
 		for (;;) {
-			name = getstr(pp);
+			name = getdirentname(pp);
 			if (!name)
 				break;
 			if (strcmp(name, "$") == 0)
@@ -612,8 +637,10 @@ void
 parse_proto(
 	xfs_mount_t	*mp,
 	struct fsxattr	*fsx,
-	char		**pp)
+	char		**pp,
+	int		proto_slashes_are_spaces)
 {
+	slashes_are_spaces = proto_slashes_are_spaces;
 	parseproto(mp, NULL, fsx, pp, NULL);
 }
 
diff --git a/mkfs/proto.h b/mkfs/proto.h
index 3c4010afd19..be1ceb45421 100644
--- a/mkfs/proto.h
+++ b/mkfs/proto.h
@@ -7,7 +7,8 @@
 #define MKFS_PROTO_H_
 
 char *setup_proto(char *fname);
-void parse_proto(struct xfs_mount *mp, struct fsxattr *fsx, char **pp);
+void parse_proto(struct xfs_mount *mp, struct fsxattr *fsx, char **pp,
+		int proto_slashes_are_spaces);
 void res_failed(int err);
 
 #endif /* MKFS_PROTO_H_ */
diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
index 4248e6ec344..4399bf3792f 100644
--- a/mkfs/xfs_mkfs.c
+++ b/mkfs/xfs_mkfs.c
@@ -115,6 +115,7 @@ enum {
 
 enum {
 	P_FILE = 0,
+	P_SLASHES,
 	P_MAX_OPTS,
 };
 
@@ -651,6 +652,7 @@ static struct opt_params popts = {
 	.ini_section = "proto",
 	.subopts = {
 		[P_FILE] = "file",
+		[P_SLASHES] = "slashes_are_spaces",
 		[P_MAX_OPTS] = NULL,
 	},
 	.subopt_params = {
@@ -658,6 +660,12 @@ static struct opt_params popts = {
 		  .conflicts = { { NULL, LAST_CONFLICT } },
 		  .defaultval = SUBOPT_NEEDS_VAL,
 		},
+		{ .index = P_SLASHES,
+		  .conflicts = { { NULL, LAST_CONFLICT } },
+		  .minval = 0,
+		  .maxval = 1,
+		  .defaultval = 1,
+		},
 	},
 };
 
@@ -881,6 +889,7 @@ struct cli_params {
 	int	loginternal;
 	int	lsunit;
 	int	is_supported;
+	int	proto_slashes_are_spaces;
 
 	/* parameters where 0 is not a valid value */
 	int64_t	agcount;
@@ -1779,6 +1788,9 @@ proto_opts_parser(
 	struct cli_params	*cli)
 {
 	switch (subopt) {
+	case P_SLASHES:
+		cli->proto_slashes_are_spaces = getnum(value, opts, subopt);
+		break;
 	case P_FILE:
 		fallthrough;
 	default:
@@ -4368,7 +4380,7 @@ main(
 	/*
 	 * Allocate the root inode and anything else in the proto file.
 	 */
-	parse_proto(mp, &cli.fsx, &protostring);
+	parse_proto(mp, &cli.fsx, &protostring, cli.proto_slashes_are_spaces);
 
 	/*
 	 * Protect ourselves against possible stupidity


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] mkfs: check dirent names when reading protofile
  2023-03-01 16:05 ` [PATCH 1/3] mkfs: check dirent names when reading protofile Darrick J. Wong
@ 2023-03-03 10:45   ` Carlos Maiolino
  0 siblings, 0 replies; 7+ messages in thread
From: Carlos Maiolino @ 2023-03-03 10:45 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, daan.j.demeyer

On Wed, Mar 01, 2023 at 08:05:34AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> The protofile parser in mkfs does not check directory entry names when
> populating the filesystem.  The libxfs directory code doesn't check them
> either, since they depend on the Linux VFS to sanitize incoming names.
> If someone puts a slash in the first (name) column in the protofile,
> this results in a successful format and xfs_repair -n immediately
> complains.
> 
> Screen the names that are being read from the protofile.

Looks good
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>
> ---
>  mkfs/proto.c |    6 ++++++
>  1 file changed, 6 insertions(+)
> 
> 
> diff --git a/mkfs/proto.c b/mkfs/proto.c
> index 68ecdbf3632..7e3fc1b8134 100644
> --- a/mkfs/proto.c
> +++ b/mkfs/proto.c
> @@ -326,6 +326,12 @@ newdirent(
>  	int	error;
>  	int	rsv;
> 
> +	if (!libxfs_dir2_namecheck(name->name, name->len)) {
> +		fprintf(stderr, _("%.*s: invalid directory entry name\n"),
> +				name->len, name->name);
> +		exit(1);
> +	}
> +
>  	rsv = XFS_DIRENTER_SPACE_RES(mp, name->len);
> 
>  	error = -libxfs_dir_createname(tp, pip, name, inum, rsv);
> 

-- 
Carlos Maiolino

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] mkfs: use suboption processing for -p
  2023-03-01 16:05 ` [PATCH 2/3] mkfs: use suboption processing for -p Darrick J. Wong
@ 2023-03-03 11:16   ` Carlos Maiolino
  0 siblings, 0 replies; 7+ messages in thread
From: Carlos Maiolino @ 2023-03-03 11:16 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, daan.j.demeyer

On Wed, Mar 01, 2023 at 08:05:39AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> Use suboption processing for -p so that we can add a few behavioral
> variants to protofiles in the next patch.  As a side effect of this
> change, one can now provide the path to a protofile in the config
> file:
> 
> [proto]
> file=/tmp/protofile
> 
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Looks good, thanks for updating this!
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>

> ---
>  man/man8/mkfs.xfs.8.in |   26 ++++++++++++++++++----
>  mkfs/xfs_mkfs.c        |   58 ++++++++++++++++++++++++++++++++++++++++++------
>  2 files changed, 73 insertions(+), 11 deletions(-)
> 
> 
> diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in
> index 211e7b0c7b8..e1ca40e5da6 100644
> --- a/man/man8/mkfs.xfs.8.in
> +++ b/man/man8/mkfs.xfs.8.in
> @@ -28,7 +28,7 @@ mkfs.xfs \- construct an XFS filesystem
>  .I naming_options
>  ] [
>  .B \-p
> -.I protofile
> +.I protofile_options
>  ] [
>  .B \-q
>  ] [
> @@ -834,12 +834,29 @@ When CRCs are enabled (the default), the ftype functionality is always
>  enabled, and cannot be turned off.
>  .IP
>  In other words, this option is only tunable on the deprecated V4 format.
> -.IP
>  .RE
> +.PP
> +.PD 0
>  .TP
> -.BI \-p " protofile"
> +.BI \-p " protofile_options"
> +.TP
> +.BI "Section Name: " [proto]
> +.PD
> +These options specify the protofile parameters for populating the filesystem.
> +The valid
> +.I protofile_options
> +are:
> +.RS 1.2i
> +.TP
> +.BI [file=] protofile
> +The
> +.B file=
> +prefix is not required for this CLI argument for legacy reasons.
> +If specified as a config file directive, the prefix is required.
> +
>  If the optional
> -.BI \-p " protofile"
> +.PD
> +.I protofile
>  argument is given,
>  .B mkfs.xfs
>  uses
> @@ -979,6 +996,7 @@ in the directory. A scan of the protofile is
>  always terminated with the dollar (
>  .B $
>  ) token.
> +.RE
>  .TP
>  .B \-q
>  Quiet option. Normally
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index e219ec166da..4248e6ec344 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -113,6 +113,11 @@ enum {
>  	N_MAX_OPTS,
>  };
> 
> +enum {
> +	P_FILE = 0,
> +	P_MAX_OPTS,
> +};
> +
>  enum {
>  	R_EXTSIZE = 0,
>  	R_SIZE,
> @@ -641,6 +646,21 @@ static struct opt_params nopts = {
>  	},
>  };
> 
> +static struct opt_params popts = {
> +	.name = 'p',
> +	.ini_section = "proto",
> +	.subopts = {
> +		[P_FILE] = "file",
> +		[P_MAX_OPTS] = NULL,
> +	},
> +	.subopt_params = {
> +		{ .index = P_FILE,
> +		  .conflicts = { { NULL, LAST_CONFLICT } },
> +		  .defaultval = SUBOPT_NEEDS_VAL,
> +		},
> +	},
> +};
> +
>  static struct opt_params ropts = {
>  	.name = 'r',
>  	.ini_section = "realtime",
> @@ -841,6 +861,7 @@ struct cli_params {
>  	int	blocksize;
> 
>  	char	*cfgfile;
> +	char	*protofile;
> 
>  	/* parameters that depend on sector/block size being validated. */
>  	char	*dsize;
> @@ -1750,6 +1771,33 @@ naming_opts_parser(
>  	return 0;
>  }
> 
> +static int
> +proto_opts_parser(
> +	struct opt_params	*opts,
> +	int			subopt,
> +	const char		*value,
> +	struct cli_params	*cli)
> +{
> +	switch (subopt) {
> +	case P_FILE:
> +		fallthrough;
> +	default:
> +		if (cli->protofile) {
> +			if (subopt < 0)
> +				subopt = P_FILE;
> +			respec(opts->name, opts->subopts, subopt);
> +		}
> +		cli->protofile = strdup(value);
> +		if (!cli->protofile) {
> +			fprintf(stderr,
> + _("Out of memory while saving protofile option.\n"));
> +			exit(1);
> +		}
> +		break;
> +	}
> +	return 0;
> +}
> +
>  static int
>  rtdev_opts_parser(
>  	struct opt_params	*opts,
> @@ -1813,6 +1861,7 @@ static struct subopts {
>  	{ &lopts, log_opts_parser },
>  	{ &mopts, meta_opts_parser },
>  	{ &nopts, naming_opts_parser },
> +	{ &popts, proto_opts_parser },
>  	{ &ropts, rtdev_opts_parser },
>  	{ &sopts, sector_opts_parser },
>  	{ NULL, NULL },
> @@ -4013,7 +4062,6 @@ main(
>  	int			discard = 1;
>  	int			force_overwrite = 0;
>  	int			quiet = 0;
> -	char			*protofile = NULL;
>  	char			*protostring = NULL;
>  	int			worst_freelist = 0;
> 
> @@ -4119,6 +4167,7 @@ main(
>  		case 'l':
>  		case 'm':
>  		case 'n':
> +		case 'p':
>  		case 'r':
>  		case 's':
>  			parse_subopts(c, optarg, &cli);
> @@ -4134,11 +4183,6 @@ main(
>  		case 'K':
>  			discard = 0;
>  			break;
> -		case 'p':
> -			if (protofile)
> -				respec('p', NULL, 0);
> -			protofile = optarg;
> -			break;
>  		case 'q':
>  			quiet = 1;
>  			break;
> @@ -4165,7 +4209,7 @@ main(
>  	 */
>  	cfgfile_parse(&cli);
> 
> -	protostring = setup_proto(protofile);
> +	protostring = setup_proto(cli.protofile);
> 
>  	/*
>  	 * Extract as much of the valid config as we can from the CLI input
> 

-- 
Carlos Maiolino

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 3/3] mkfs: substitute slashes with spaces in protofiles
  2023-03-01 16:05 ` [PATCH 3/3] mkfs: substitute slashes with spaces in protofiles Darrick J. Wong
@ 2023-03-03 11:31   ` Carlos Maiolino
  0 siblings, 0 replies; 7+ messages in thread
From: Carlos Maiolino @ 2023-03-03 11:31 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: linux-xfs, daan.j.demeyer

On Wed, Mar 01, 2023 at 08:05:45AM -0800, Darrick J. Wong wrote:
> From: Darrick J. Wong <djwong@kernel.org>
> 
> A user requested the ability to specify directory entry names in a
> protofile that have spaces in them.  The protofile format itself does
> not allow spaces (yay 1973-era protofiles!) but it does allow slashes.
> Slashes aren't allowed in directory entry names, so we'll permit this
> one gross hack.  After this, the protofile:
> 
> /
> 0 0
> d--775 1000 1000
> : Descending path /code/t/fstests
>  get/isk.sh   ---775 1000 1000 /code/t/fstests/getdisk.sh
> $
> 
> Will produce "get isk.h" in the root directory when used thusly:
> 
> # mkfs.xfs -p slashes_are_spaces=1,/tmp/protofile -f /dev/sda
> 
> Requested-by: Daan De Meyer <daan.j.demeyer@gmail.com>
> Signed-off-by: Darrick J. Wong <djwong@kernel.org>

Thanks a lot for having made this change.

Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
> ---
>  man/man8/mkfs.xfs.8.in |    6 ++++++
>  mkfs/proto.c           |   31 +++++++++++++++++++++++++++++--
>  mkfs/proto.h           |    3 ++-
>  mkfs/xfs_mkfs.c        |   14 +++++++++++++-
>  4 files changed, 50 insertions(+), 4 deletions(-)
> 
> 
> diff --git a/man/man8/mkfs.xfs.8.in b/man/man8/mkfs.xfs.8.in
> index e1ca40e5da6..49e64d47ae4 100644
> --- a/man/man8/mkfs.xfs.8.in
> +++ b/man/man8/mkfs.xfs.8.in
> @@ -996,6 +996,12 @@ in the directory. A scan of the protofile is
>  always terminated with the dollar (
>  .B $
>  ) token.
> +.TP
> +.BI slashes_are_spaces= value
> +If set to 1, slashes ("/") in the first token of each line of the protofile
> +are converted to spaces.
> +This enables the creation of a filesystem containing filenames with spaces.
> +By default, this is set to 0.
>  .RE
>  .TP
>  .B \-q
> diff --git a/mkfs/proto.c b/mkfs/proto.c
> index 7e3fc1b8134..ea31cfe5cfc 100644
> --- a/mkfs/proto.c
> +++ b/mkfs/proto.c
> @@ -21,6 +21,7 @@ static int newfile(xfs_trans_t *tp, xfs_inode_t *ip, int symlink, int logit,
>  static char *newregfile(char **pp, int *len);
>  static void rtinit(xfs_mount_t *mp);
>  static long filesize(int fd);
> +static int slashes_are_spaces;
> 
>  /*
>   * Use this for block reservations needed for mkfs's conditions
> @@ -171,6 +172,30 @@ getstr(
>  	return NULL;
>  }
> 
> +/* Extract directory entry name from a protofile. */
> +static char *
> +getdirentname(
> +	char	**pp)
> +{
> +	char	*p = getstr(pp);
> +	char	*c = p;
> +
> +	if (!p)
> +		return NULL;
> +
> +	if (!slashes_are_spaces)
> +		return p;
> +
> +	/* Replace slash with space because slashes aren't allowed. */
> +	while (*c) {
> +		if (*c == '/')
> +			*c = ' ';
> +		c++;
> +	}
> +
> +	return p;
> +}
> +
>  static void
>  rsvfile(
>  	xfs_mount_t	*mp,
> @@ -586,7 +611,7 @@ parseproto(
>  			rtinit(mp);
>  		tp = NULL;
>  		for (;;) {
> -			name = getstr(pp);
> +			name = getdirentname(pp);
>  			if (!name)
>  				break;
>  			if (strcmp(name, "$") == 0)
> @@ -612,8 +637,10 @@ void
>  parse_proto(
>  	xfs_mount_t	*mp,
>  	struct fsxattr	*fsx,
> -	char		**pp)
> +	char		**pp,
> +	int		proto_slashes_are_spaces)
>  {
> +	slashes_are_spaces = proto_slashes_are_spaces;
>  	parseproto(mp, NULL, fsx, pp, NULL);
>  }
> 
> diff --git a/mkfs/proto.h b/mkfs/proto.h
> index 3c4010afd19..be1ceb45421 100644
> --- a/mkfs/proto.h
> +++ b/mkfs/proto.h
> @@ -7,7 +7,8 @@
>  #define MKFS_PROTO_H_
> 
>  char *setup_proto(char *fname);
> -void parse_proto(struct xfs_mount *mp, struct fsxattr *fsx, char **pp);
> +void parse_proto(struct xfs_mount *mp, struct fsxattr *fsx, char **pp,
> +		int proto_slashes_are_spaces);
>  void res_failed(int err);
> 
>  #endif /* MKFS_PROTO_H_ */
> diff --git a/mkfs/xfs_mkfs.c b/mkfs/xfs_mkfs.c
> index 4248e6ec344..4399bf3792f 100644
> --- a/mkfs/xfs_mkfs.c
> +++ b/mkfs/xfs_mkfs.c
> @@ -115,6 +115,7 @@ enum {
> 
>  enum {
>  	P_FILE = 0,
> +	P_SLASHES,
>  	P_MAX_OPTS,
>  };
> 
> @@ -651,6 +652,7 @@ static struct opt_params popts = {
>  	.ini_section = "proto",
>  	.subopts = {
>  		[P_FILE] = "file",
> +		[P_SLASHES] = "slashes_are_spaces",
>  		[P_MAX_OPTS] = NULL,
>  	},
>  	.subopt_params = {
> @@ -658,6 +660,12 @@ static struct opt_params popts = {
>  		  .conflicts = { { NULL, LAST_CONFLICT } },
>  		  .defaultval = SUBOPT_NEEDS_VAL,
>  		},
> +		{ .index = P_SLASHES,
> +		  .conflicts = { { NULL, LAST_CONFLICT } },
> +		  .minval = 0,
> +		  .maxval = 1,
> +		  .defaultval = 1,
> +		},
>  	},
>  };
> 
> @@ -881,6 +889,7 @@ struct cli_params {
>  	int	loginternal;
>  	int	lsunit;
>  	int	is_supported;
> +	int	proto_slashes_are_spaces;
> 
>  	/* parameters where 0 is not a valid value */
>  	int64_t	agcount;
> @@ -1779,6 +1788,9 @@ proto_opts_parser(
>  	struct cli_params	*cli)
>  {
>  	switch (subopt) {
> +	case P_SLASHES:
> +		cli->proto_slashes_are_spaces = getnum(value, opts, subopt);
> +		break;
>  	case P_FILE:
>  		fallthrough;
>  	default:
> @@ -4368,7 +4380,7 @@ main(
>  	/*
>  	 * Allocate the root inode and anything else in the proto file.
>  	 */
> -	parse_proto(mp, &cli.fsx, &protostring);
> +	parse_proto(mp, &cli.fsx, &protostring, cli.proto_slashes_are_spaces);
> 
>  	/*
>  	 * Protect ourselves against possible stupidity
> 

-- 
Carlos Maiolino

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-03-03 11:32 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-01 16:05 [PATCHSET v2 0/3] xfsprogs: random fixes for 6.2 Darrick J. Wong
2023-03-01 16:05 ` [PATCH 1/3] mkfs: check dirent names when reading protofile Darrick J. Wong
2023-03-03 10:45   ` Carlos Maiolino
2023-03-01 16:05 ` [PATCH 2/3] mkfs: use suboption processing for -p Darrick J. Wong
2023-03-03 11:16   ` Carlos Maiolino
2023-03-01 16:05 ` [PATCH 3/3] mkfs: substitute slashes with spaces in protofiles Darrick J. Wong
2023-03-03 11:31   ` Carlos Maiolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).