2 * SPDX-License-Identifier: GPL-2.0-or-later
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * Copyright (C) 2012-2023 Karel Zak <kzak@redhat.com>
21 static void __attribute__((__noreturn__
)) usage(void)
24 fputs(USAGE_HEADER
, out
);
25 fprintf(out
, _(" %s <disk device> <partition number> <start> <length>\n"),
26 program_invocation_short_name
);
28 fputs(USAGE_SEPARATOR
, out
);
29 fputs(_("Tell the kernel about the existence of a specified partition.\n"), out
);
31 fputs(USAGE_OPTIONS
, out
);
32 fprintf(out
, USAGE_HELP_OPTIONS(16));
33 fprintf(out
, USAGE_MAN_TAIL("addpart(8)"));
37 int main(int argc
, char **argv
)
41 static const struct option longopts
[] = {
42 {"help", no_argument
, NULL
, 'h'},
43 {"version", no_argument
, NULL
, 'V'},
47 setlocale(LC_ALL
, "");
48 bindtextdomain(PACKAGE
, LOCALEDIR
);
51 while ((c
= getopt_long(argc
, argv
, "Vh", longopts
, NULL
)) != -1)
54 print_version(EXIT_SUCCESS
);
58 errtryhelp(EXIT_FAILURE
);
62 warnx(_("not enough arguments"));
63 errtryhelp(EXIT_FAILURE
);
66 if ((fd
= open(argv
[1], O_RDONLY
)) < 0)
67 err(EXIT_FAILURE
, _("cannot open %s"), argv
[1]);
69 if (partx_add_partition(fd
,
70 strtou32_or_err(argv
[2], _("invalid partition number argument")),
71 strtou64_or_err(argv
[3], _("invalid start argument")),
72 strtou64_or_err(argv
[4], _("invalid length argument"))))
73 err(EXIT_FAILURE
, _("failed to add partition"));