On Wed, Jan 29, 2020 at 12:58:29AM -0800, Omar Sandoval wrote: > From: Omar Sandoval <osandov@xxxxxx> > > Signed-off-by: Omar Sandoval <osandov@xxxxxx> > --- And this patch would be better to send to/cc linux-xfs@xxxxxxxxxxxxxxx to get xfsprogs maintainers/developers review. > io/link.c | 24 ++++++++++++++++++++---- > man/man8/xfs_io.8 | 9 ++++++++- > 2 files changed, 28 insertions(+), 5 deletions(-) > > diff --git a/io/link.c b/io/link.c > index f4f4b139..3fc3e24d 100644 > --- a/io/link.c > +++ b/io/link.c > @@ -12,6 +12,9 @@ > #ifndef AT_EMPTY_PATH > #define AT_EMPTY_PATH 0x1000 > #endif > +#ifndef AT_LINK_REPLACE > +#define AT_LINK_REPLACE 0x10000 > +#endif > > static cmdinfo_t flink_cmd; > > @@ -22,6 +25,7 @@ flink_help(void) > "\n" > "link the open file descriptor to the supplied filename\n" > "\n" > +" -f -- overwrite the target filename if it exists (AT_LINK_REPLACE)\n" > "\n")); > } > > @@ -30,10 +34,22 @@ flink_f( > int argc, > char **argv) > { > - if (argc != 2) > + int flags = AT_EMPTY_PATH; > + int c; > + > + while ((c = getopt(argc, argv, "f")) != EOF) { > + switch (c) { > + case 'f': > + flags |= AT_LINK_REPLACE; > + break; > + default: > + return command_usage(&flink_cmd); > + } > + } > + if (optind != argc - 1) > return command_usage(&flink_cmd); > > - if (linkat(file->fd, "", AT_FDCWD, argv[1], AT_EMPTY_PATH) < 0) { > + if (linkat(file->fd, "", AT_FDCWD, argv[optind], flags) < 0) { > perror("flink"); > return 0; > } > @@ -46,9 +62,9 @@ flink_init(void) > flink_cmd.name = "flink"; > flink_cmd.cfunc = flink_f; > flink_cmd.argmin = 1; > - flink_cmd.argmax = 1; > + flink_cmd.argmax = -1; > flink_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK | CMD_FLAG_ONESHOT; > - flink_cmd.args = _("filename"); > + flink_cmd.args = _("[-f] filename"); > flink_cmd.oneline = > _("link the open file descriptor to the supplied filename"); > flink_cmd.help = flink_help; > diff --git a/man/man8/xfs_io.8 b/man/man8/xfs_io.8 > index c69b295d..f79b3a59 100644 > --- a/man/man8/xfs_io.8 > +++ b/man/man8/xfs_io.8 > @@ -807,8 +807,15 @@ for the full list) is available via the > .B help > command. > .TP > -.BI "flink " path > +.BI "flink [ \-f ]" " path" > Link the currently open file descriptor into the filesystem namespace. > +.RS 1.0i > +.PD 0 > +.TP 0.4i > +.B \-f > +overwrite the target path if it exists (AT_LINK_REPLACE). > +.PD > +.RE > .TP > .BR stat " [ " \-v "|" \-r " ]" > Selected statistics from > -- > 2.25.0 >