]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - spaceman/init.c
xfs_spaceman: print a nicer message when file path isn't on xfs
[thirdparty/xfsprogs-dev.git] / spaceman / init.c
CommitLineData
48ec2905
DC
1/*
2 * Copyright (c) 2012 Red Hat, Inc
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 "libxfs.h"
20#include "command.h"
21#include "input.h"
22#include "init.h"
cccf6abc 23#include "path.h"
48ec2905
DC
24#include "space.h"
25
26char *progname;
27int exitcode;
28
29void
30usage(void)
31{
32 fprintf(stderr,
33 _("Usage: %s [-c cmd] file\n"),
34 progname);
35 exit(1);
36}
37
38static void
39init_commands(void)
40{
41 print_init();
42 help_init();
c98132d1 43 prealloc_init();
48ec2905 44 quit_init();
c6e8a429 45 trim_init();
cccf6abc 46 freesp_init();
48ec2905
DC
47}
48
49static int
50init_args_command(
51 int index)
52{
53 if (index >= filecount)
54 return 0;
55 file = &filetable[index++];
56 return index;
57}
58
59static int
60init_check_command(
61 const cmdinfo_t *ct)
62{
63 if (!(ct->flags & CMD_FLAG_ONESHOT))
64 return 0;
65 return 1;
66}
67
68void
69init(
70 int argc,
71 char **argv)
72{
73 int c;
74 xfs_fsop_geom_t geometry = { 0 };
cccf6abc 75 struct fs_path fsp;
48ec2905
DC
76
77 progname = basename(argv[0]);
78 setlocale(LC_ALL, "");
79 bindtextdomain(PACKAGE, LOCALEDIR);
80 textdomain(PACKAGE);
81
cccf6abc 82 fs_table_initialise(0, NULL, 0, NULL);
48ec2905
DC
83 while ((c = getopt(argc, argv, "c:V")) != EOF) {
84 switch (c) {
85 case 'c':
86 add_user_command(optarg);
87 break;
88 case 'V':
89 printf(_("%s version %s\n"), progname, VERSION);
90 exit(0);
91 default:
92 usage();
93 }
94 }
95
96 if (optind != argc - 1)
97 usage();
98
cccf6abc 99 if ((c = openfile(argv[optind], &geometry, &fsp)) < 0)
48ec2905
DC
100 exit(1);
101 if (!platform_test_xfs_fd(c))
102 printf(_("Not an XFS filesystem!\n"));
cccf6abc 103 if (addfile(argv[optind], c, &geometry, &fsp) < 0)
48ec2905
DC
104 exit(1);
105
106 init_commands();
107 add_command_iterator(init_args_command);
108 add_check_command(init_check_command);
109}
110
111int
112main(
113 int argc,
114 char **argv)
115{
116 init(argc, argv);
117 command_loop();
118 return exitcode;
119}