]>
Commit | Line | Data |
---|---|---|
9e95aa12 KZ |
1 | /* |
2 | * SPDX-License-Identifier: GPL-2.0-or-later | |
3 | * | |
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. | |
8 | * | |
9 | * Copyright (C) 2012-2023 Karel Zak <kzak@redhat.com> | |
10 | */ | |
04874274 | 11 | #include <getopt.h> |
7eda085c | 12 | #include <stdio.h> |
7eda085c | 13 | #include <stdlib.h> |
6e6a182e KZ |
14 | #include <fcntl.h> |
15 | ||
04874274 SK |
16 | #include "c.h" |
17 | #include "nls.h" | |
6e6a182e | 18 | #include "partx.h" |
04874274 | 19 | #include "strutils.h" |
7eda085c | 20 | |
6e1eda6f | 21 | static void __attribute__((__noreturn__)) usage(void) |
04874274 | 22 | { |
6e1eda6f | 23 | FILE *out = stdout; |
04874274 SK |
24 | fputs(USAGE_HEADER, out); |
25 | fprintf(out, _(" %s <disk device> <partition number>\n"), | |
26 | program_invocation_short_name); | |
451dbcfa BS |
27 | |
28 | fputs(USAGE_SEPARATOR, out); | |
29 | fputs(_("Tell the kernel to forget about a specified partition.\n"), out); | |
30 | ||
04874274 | 31 | fputs(USAGE_OPTIONS, out); |
bad4c729 MY |
32 | fprintf(out, USAGE_HELP_OPTIONS(16)); |
33 | fprintf(out, USAGE_MAN_TAIL("delpart(8)")); | |
6e1eda6f | 34 | exit(EXIT_SUCCESS); |
04874274 SK |
35 | } |
36 | ||
37 | int main(int argc, char **argv) | |
38 | { | |
39 | int c, fd; | |
40 | ||
41 | static const struct option longopts[] = { | |
87918040 SK |
42 | {"help", no_argument, NULL, 'h'}, |
43 | {"version", no_argument, NULL, 'V'}, | |
44 | {NULL, 0, NULL, 0}, | |
04874274 SK |
45 | }; |
46 | ||
47 | setlocale(LC_ALL, ""); | |
48 | bindtextdomain(PACKAGE, LOCALEDIR); | |
49 | textdomain(PACKAGE); | |
50 | ||
51 | while ((c = getopt_long(argc, argv, "Vh", longopts, NULL)) != -1) | |
52 | switch (c) { | |
53 | case 'V': | |
2c308875 | 54 | print_version(EXIT_SUCCESS); |
04874274 | 55 | case 'h': |
6e1eda6f | 56 | usage(); |
04874274 | 57 | default: |
677ec86c | 58 | errtryhelp(EXIT_FAILURE); |
04874274 SK |
59 | } |
60 | ||
6e1eda6f RM |
61 | if (argc != 3) { |
62 | warnx(_("not enough arguments")); | |
63 | errtryhelp(EXIT_FAILURE); | |
64 | } | |
a3ef250e KZ |
65 | |
66 | ||
04874274 | 67 | if ((fd = open(argv[1], O_RDONLY)) < 0) |
289dcc90 | 68 | err(EXIT_FAILURE, _("cannot open %s"), argv[1]); |
04874274 SK |
69 | |
70 | if (partx_del_partition(fd, | |
659e5f5b | 71 | strtou32_or_err(argv[2], _("invalid partition number argument")))) |
a3ef250e | 72 | err(EXIT_FAILURE, _("failed to remove partition")); |
04874274 SK |
73 | |
74 | return EXIT_SUCCESS; | |
7eda085c | 75 | } |