11 static void __attribute__((__noreturn__
)) usage(void)
14 fputs(USAGE_HEADER
, out
);
15 fprintf(out
, _(" %s <disk device> <partition number> <start> <length>\n"),
16 program_invocation_short_name
);
18 fputs(USAGE_SEPARATOR
, out
);
19 fputs(_("Tell the kernel about the existence of a specified partition.\n"), out
);
21 fputs(USAGE_OPTIONS
, out
);
22 printf(USAGE_HELP_OPTIONS(16));
23 printf(USAGE_MAN_TAIL("addpart(8)"));
27 int main(int argc
, char **argv
)
31 static const struct option longopts
[] = {
32 {"help", no_argument
, NULL
, 'h'},
33 {"version", no_argument
, NULL
, 'V'},
37 setlocale(LC_ALL
, "");
38 bindtextdomain(PACKAGE
, LOCALEDIR
);
41 while ((c
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
44 print_version(EXIT_SUCCESS
);
48 errtryhelp(EXIT_FAILURE
);
52 warnx(_("not enough arguments"));
53 errtryhelp(EXIT_FAILURE
);
56 if ((fd
= open(argv
[1], O_RDONLY
)) < 0)
57 err(EXIT_FAILURE
, _("cannot open %s"), argv
[1]);
59 if (partx_add_partition(fd
,
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"))))
63 err(EXIT_FAILURE
, _("failed to add partition"));