]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - io/link.c
xfs_io: add support for flink
[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 <xfs/xfs.h>
20 #include <xfs/command.h>
21 #include <xfs/input.h>
22 #include "init.h"
23 #include "io.h"
24
25 #ifndef AT_EMPTY_PATH
26 #define AT_EMPTY_PATH 0x1000
27 #endif
28
29 static cmdinfo_t flink_cmd;
30
31 static void
32 flink_help(void)
33 {
34 printf(_(
35 "\n"
36 "link the open file descriptor to the supplied filename\n"
37 "\n"
38 "\n"));
39 }
40
41 static int
42 flink_f(
43 int argc,
44 char **argv)
45 {
46 if (argc != 2)
47 return command_usage(&flink_cmd);
48
49 if (linkat(file->fd, "", AT_FDCWD, argv[1], AT_EMPTY_PATH) < 0) {
50 perror("flink");
51 return 0;
52 }
53 return 0;
54 }
55
56 void
57 flink_init(void)
58 {
59 flink_cmd.name = "flink";
60 flink_cmd.cfunc = flink_f;
61 flink_cmd.argmin = 1;
62 flink_cmd.argmax = 1;
63 flink_cmd.flags = CMD_NOMAP_OK | CMD_FOREIGN_OK;
64 flink_cmd.args = _("filename");
65 flink_cmd.oneline =
66 _("link the open file descriptor to the supplied filename");
67 flink_cmd.help = flink_help;
68
69 add_command(&flink_cmd);
70 }