]>
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 | |
6e1eda6f | 11 | static void __attribute__((__noreturn__)) usage(void) |
74a782e2 | 12 | { |
6e1eda6f | 13 | FILE *out = stdout; |
79113020 SK |
14 | fputs(USAGE_HEADER, out); |
15 | fprintf(out, _(" %s <disk device> <partition number> <start> <length>\n"), | |
16 | program_invocation_short_name); | |
451dbcfa BS |
17 | |
18 | fputs(USAGE_SEPARATOR, out); | |
19 | fputs(_("Tell the kernel about the existence of a specified partition.\n"), out); | |
20 | ||
79113020 | 21 | fputs(USAGE_OPTIONS, out); |
f45f3ec3 RM |
22 | printf(USAGE_HELP_OPTIONS(16)); |
23 | printf(USAGE_MAN_TAIL("addpart(8)")); | |
6e1eda6f | 24 | exit(EXIT_SUCCESS); |
79113020 SK |
25 | } |
26 | ||
27 | int main(int argc, char **argv) | |
28 | { | |
29 | int c, fd; | |
30 | ||
31 | static const struct option longopts[] = { | |
87918040 SK |
32 | {"help", no_argument, NULL, 'h'}, |
33 | {"version", no_argument, NULL, 'V'}, | |
34 | {NULL, 0, NULL, 0}, | |
79113020 SK |
35 | }; |
36 | ||
37 | setlocale(LC_ALL, ""); | |
38 | bindtextdomain(PACKAGE, LOCALEDIR); | |
39 | textdomain(PACKAGE); | |
40 | ||
41 | while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) | |
42 | switch (c) { | |
43 | case 'V': | |
2c308875 | 44 | print_version(EXIT_SUCCESS); |
79113020 | 45 | case 'h': |
6e1eda6f | 46 | usage(); |
79113020 | 47 | default: |
677ec86c | 48 | errtryhelp(EXIT_FAILURE); |
79113020 SK |
49 | } |
50 | ||
6e1eda6f RM |
51 | if (argc != 5) { |
52 | warnx(_("not enough arguments")); | |
53 | errtryhelp(EXIT_FAILURE); | |
54 | } | |
0392dcf9 | 55 | |
79113020 | 56 | if ((fd = open(argv[1], O_RDONLY)) < 0) |
289dcc90 | 57 | err(EXIT_FAILURE, _("cannot open %s"), argv[1]); |
79113020 SK |
58 | |
59 | if (partx_add_partition(fd, | |
659e5f5b KZ |
60 | strtou32_or_err(argv[2], _("invalid partition number argument")), |
61 | strtou64_or_err(argv[3], _("invalid start argument")), | |
62 | strtou64_or_err(argv[4], _("invalid length argument")))) | |
0392dcf9 | 63 | err(EXIT_FAILURE, _("failed to add partition")); |
79113020 SK |
64 | |
65 | return EXIT_SUCCESS; | |
7eda085c | 66 | } |