]>
Commit | Line | Data |
---|---|---|
79113020 | 1 | #include <getopt.h> |
7eda085c | 2 | #include <stdio.h> |
7eda085c | 3 | #include <stdlib.h> |
74a782e2 KZ |
4 | #include <fcntl.h> |
5 | ||
79113020 SK |
6 | #include "c.h" |
7 | #include "nls.h" | |
74a782e2 | 8 | #include "partx.h" |
79113020 | 9 | #include "strutils.h" |
7eda085c | 10 | |
79113020 | 11 | static void __attribute__ ((__noreturn__)) usage(FILE * out) |
74a782e2 | 12 | { |
79113020 SK |
13 | fputs(USAGE_HEADER, out); |
14 | fprintf(out, _(" %s <disk device> <partition number> <start> <length>\n"), | |
15 | program_invocation_short_name); | |
16 | fputs(USAGE_OPTIONS, out); | |
17 | fputs(USAGE_HELP, out); | |
18 | fputs(USAGE_VERSION, out); | |
19 | fprintf(out, USAGE_MAN_TAIL("addpart(8)")); | |
20 | exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS); | |
21 | } | |
22 | ||
23 | int main(int argc, char **argv) | |
24 | { | |
25 | int c, fd; | |
26 | ||
27 | static const struct option longopts[] = { | |
28 | {"help", no_argument, 0, 'h'}, | |
29 | {"version", no_argument, 0, 'V'}, | |
30 | {NULL, no_argument, 0, '0'}, | |
31 | }; | |
32 | ||
33 | setlocale(LC_ALL, ""); | |
34 | bindtextdomain(PACKAGE, LOCALEDIR); | |
35 | textdomain(PACKAGE); | |
36 | ||
37 | while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) | |
38 | switch (c) { | |
39 | case 'V': | |
40 | printf(UTIL_LINUX_VERSION); | |
41 | return EXIT_SUCCESS; | |
42 | case 'h': | |
43 | usage(stdout); | |
44 | default: | |
45 | usage(stderr); | |
46 | } | |
47 | ||
48 | if (argc != 5) | |
49 | usage(stderr); | |
0392dcf9 | 50 | |
79113020 | 51 | if ((fd = open(argv[1], O_RDONLY)) < 0) |
0392dcf9 | 52 | err(EXIT_FAILURE, _("%s: open failed"), argv[1]); |
79113020 SK |
53 | |
54 | if (partx_add_partition(fd, | |
659e5f5b KZ |
55 | strtou32_or_err(argv[2], _("invalid partition number argument")), |
56 | strtou64_or_err(argv[3], _("invalid start argument")), | |
57 | strtou64_or_err(argv[4], _("invalid length argument")))) | |
0392dcf9 | 58 | err(EXIT_FAILURE, _("failed to add partition")); |
79113020 SK |
59 | |
60 | return EXIT_SUCCESS; | |
7eda085c | 61 | } |