]>
Commit | Line | Data |
---|---|---|
959ef981 | 1 | // SPDX-License-Identifier: GPL-2.0 |
48ec2905 DC |
2 | /* |
3 | * Copyright (c) 2012 Red Hat, Inc | |
4 | * All Rights Reserved. | |
48ec2905 DC |
5 | */ |
6 | ||
7 | #include "libxfs.h" | |
8 | #include "command.h" | |
9 | #include "input.h" | |
10 | #include "init.h" | |
cccf6abc | 11 | #include "path.h" |
48ec2905 DC |
12 | #include "space.h" |
13 | ||
14 | char *progname; | |
15 | int exitcode; | |
16 | ||
17 | void | |
18 | usage(void) | |
19 | { | |
20 | fprintf(stderr, | |
21 | _("Usage: %s [-c cmd] file\n"), | |
22 | progname); | |
23 | exit(1); | |
24 | } | |
25 | ||
26 | static void | |
27 | init_commands(void) | |
28 | { | |
29 | print_init(); | |
30 | help_init(); | |
6719d622 | 31 | info_init(); |
c98132d1 | 32 | prealloc_init(); |
48ec2905 | 33 | quit_init(); |
c6e8a429 | 34 | trim_init(); |
cccf6abc | 35 | freesp_init(); |
48ec2905 DC |
36 | } |
37 | ||
38 | static int | |
39 | init_args_command( | |
40 | int index) | |
41 | { | |
42 | if (index >= filecount) | |
43 | return 0; | |
44 | file = &filetable[index++]; | |
45 | return index; | |
46 | } | |
47 | ||
48 | static int | |
49 | init_check_command( | |
50 | const cmdinfo_t *ct) | |
51 | { | |
52 | if (!(ct->flags & CMD_FLAG_ONESHOT)) | |
53 | return 0; | |
54 | return 1; | |
55 | } | |
56 | ||
57 | void | |
58 | init( | |
59 | int argc, | |
60 | char **argv) | |
61 | { | |
62 | int c; | |
63 | xfs_fsop_geom_t geometry = { 0 }; | |
cccf6abc | 64 | struct fs_path fsp; |
48ec2905 DC |
65 | |
66 | progname = basename(argv[0]); | |
67 | setlocale(LC_ALL, ""); | |
68 | bindtextdomain(PACKAGE, LOCALEDIR); | |
69 | textdomain(PACKAGE); | |
70 | ||
cccf6abc | 71 | fs_table_initialise(0, NULL, 0, NULL); |
3fda24ed | 72 | while ((c = getopt(argc, argv, "c:p:V")) != EOF) { |
48ec2905 DC |
73 | switch (c) { |
74 | case 'c': | |
75 | add_user_command(optarg); | |
76 | break; | |
3fda24ed DW |
77 | case 'p': |
78 | progname = optarg; | |
79 | break; | |
48ec2905 DC |
80 | case 'V': |
81 | printf(_("%s version %s\n"), progname, VERSION); | |
82 | exit(0); | |
83 | default: | |
84 | usage(); | |
85 | } | |
86 | } | |
87 | ||
88 | if (optind != argc - 1) | |
89 | usage(); | |
90 | ||
cccf6abc | 91 | if ((c = openfile(argv[optind], &geometry, &fsp)) < 0) |
48ec2905 DC |
92 | exit(1); |
93 | if (!platform_test_xfs_fd(c)) | |
94 | printf(_("Not an XFS filesystem!\n")); | |
cccf6abc | 95 | if (addfile(argv[optind], c, &geometry, &fsp) < 0) |
48ec2905 DC |
96 | exit(1); |
97 | ||
98 | init_commands(); | |
99 | add_command_iterator(init_args_command); | |
100 | add_check_command(init_check_command); | |
101 | } | |
102 | ||
103 | int | |
104 | main( | |
105 | int argc, | |
106 | char **argv) | |
107 | { | |
108 | init(argc, argv); | |
109 | command_loop(); | |
110 | return exitcode; | |
111 | } |