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