]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/link.c
xfs_io: make various commands one-shot only
[thirdparty/xfsprogs-dev.git] / io / link.c
1 /*
2 * Copyright (c) 2014 Christoph Hellwig.
3 * All Rights Reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 #include "command.h"
20 #include "input.h"
21 #include "init.h"
22 #include "io.h"
23
24 #ifndef AT_EMPTY_PATH
25 #define AT_EMPTY_PATH 0x1000
26 #endif
27
28 static cmdinfo_t flink_cmd;
29
30 static void
31 flink_help(void)
32 {
33 printf(_(
34 "\n"
35 "link the open file descriptor to the supplied filename\n"
36 "\n"
37 "\n"));
38 }
39
40 static int
41 flink_f(
42 int argc,
43 char **argv)
44 {
45 if (argc != 2)
46 return command_usage(&flink_cmd);
47
48 if (linkat(file->fd, "", AT_FDCWD, argv[1], AT_EMPTY_PATH) < 0) {
49 perror("flink");
50 return 0;
51 }
52 return 0;
53 }
54
55 void
56 flink_init(void)
57 {
58 flink_cmd.name = "flink";
59 flink_cmd.cfunc = flink_f;
60 flink_cmd.argmin = 1;
61 flink_cmd.argmax = 1;
62 flink_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK | CMD_FLAG_ONESHOT;
63 flink_cmd.args = _("filename");
64 flink_cmd.oneline =
65 _("link the open file descriptor to the supplied filename");
66 flink_cmd.help = flink_help;
67
68 add_command(&flink_cmd);
69 }