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