]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - spaceman/init.c
xfs_scrub: remove moveon from progress report helpers
[thirdparty/xfsprogs-dev.git] / spaceman / init.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2012 Red Hat, Inc
4 * All Rights Reserved.
5 */
6
7 #include "libxfs.h"
8 #include "libfrog/fsgeom.h"
9 #include "command.h"
10 #include "input.h"
11 #include "init.h"
12 #include "libfrog/paths.h"
13 #include "space.h"
14
15 char *progname;
16 int exitcode;
17
18 static void
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();
32 info_init();
33 prealloc_init();
34 quit_init();
35 trim_init();
36 freesp_init();
37 health_init();
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
59 static void
60 init(
61 int argc,
62 char **argv)
63 {
64 int c;
65 struct xfs_fd xfd = XFS_FD_INIT_EMPTY;
66 struct fs_path fsp;
67
68 progname = basename(argv[0]);
69 setlocale(LC_ALL, "");
70 bindtextdomain(PACKAGE, LOCALEDIR);
71 textdomain(PACKAGE);
72
73 fs_table_initialise(0, NULL, 0, NULL);
74 while ((c = getopt(argc, argv, "c:p:V")) != EOF) {
75 switch (c) {
76 case 'c':
77 add_user_command(optarg);
78 break;
79 case 'p':
80 progname = optarg;
81 break;
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
93 c = openfile(argv[optind], &xfd, &fsp);
94 if (c < 0)
95 exit(1);
96 if (!platform_test_xfs_fd(xfd.fd))
97 printf(_("Not an XFS filesystem!\n"));
98 c = addfile(argv[optind], &xfd, &fsp);
99 if (c < 0)
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 }