]> git.ipfire.org Git - thirdparty/util-linux.git/blame - disk-utils/delpart.c
wipefs: add --lock and LOCK_BLOCK_DEVICE
[thirdparty/util-linux.git] / disk-utils / delpart.c
CommitLineData
04874274 1#include <getopt.h>
7eda085c 2#include <stdio.h>
7eda085c 3#include <stdlib.h>
6e6a182e
KZ
4#include <fcntl.h>
5
04874274
SK
6#include "c.h"
7#include "nls.h"
6e6a182e 8#include "partx.h"
04874274 9#include "strutils.h"
7eda085c 10
6e1eda6f 11static void __attribute__((__noreturn__)) usage(void)
04874274 12{
6e1eda6f 13 FILE *out = stdout;
04874274
SK
14 fputs(USAGE_HEADER, out);
15 fprintf(out, _(" %s <disk device> <partition number>\n"),
16 program_invocation_short_name);
451dbcfa
BS
17
18 fputs(USAGE_SEPARATOR, out);
19 fputs(_("Tell the kernel to forget about a specified partition.\n"), out);
20
04874274 21 fputs(USAGE_OPTIONS, out);
f45f3ec3
RM
22 printf(USAGE_HELP_OPTIONS(16));
23 printf(USAGE_MAN_TAIL("delpart(8)"));
6e1eda6f 24 exit(EXIT_SUCCESS);
04874274
SK
25}
26
27int 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},
04874274
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);
04874274 45 case 'h':
6e1eda6f 46 usage();
04874274 47 default:
677ec86c 48 errtryhelp(EXIT_FAILURE);
04874274
SK
49 }
50
6e1eda6f
RM
51 if (argc != 3) {
52 warnx(_("not enough arguments"));
53 errtryhelp(EXIT_FAILURE);
54 }
a3ef250e
KZ
55
56
04874274 57 if ((fd = open(argv[1], O_RDONLY)) < 0)
289dcc90 58 err(EXIT_FAILURE, _("cannot open %s"), argv[1]);
04874274
SK
59
60 if (partx_del_partition(fd,
659e5f5b 61 strtou32_or_err(argv[2], _("invalid partition number argument"))))
a3ef250e 62 err(EXIT_FAILURE, _("failed to remove partition"));
04874274
SK
63
64 return EXIT_SUCCESS;
7eda085c 65}