blob: 0abed6ff1984f8c0b6746f4b023b6cd8bd14f9d9 [file] [log] [blame]
Denys Vlasenkoac47a002017-04-11 19:17:59 +02001/* vi: set sw=4 ts=4: */
2/*
3 * Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
4 *
5 * Licensed under GPLv2, see file LICENSE in this source tree.
6 */
7//config:config PARTPROBE
Denys Vlasenkob097a842018-12-28 03:20:17 +01008//config: bool "partprobe (3.5 kb)"
Denys Vlasenkoac47a002017-04-11 19:17:59 +02009//config: default y
10//config: select PLATFORM_LINUX
11//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020012//config: Ask kernel to rescan partition table.
Denys Vlasenkoac47a002017-04-11 19:17:59 +020013
Denys Vlasenko9c49d6e2017-08-05 01:46:39 +020014//applet:IF_PARTPROBE(APPLET_NOEXEC(partprobe, partprobe, BB_DIR_USR_SBIN, BB_SUID_DROP, partprobe))
Denys Vlasenkoac47a002017-04-11 19:17:59 +020015
16//kbuild:lib-$(CONFIG_PARTPROBE) += partprobe.o
17
18#include <linux/fs.h>
19#include "libbb.h"
20#ifndef BLKRRPART
21# define BLKRRPART _IO(0x12,95)
22#endif
23
24//usage:#define partprobe_trivial_usage
25//usage: "DEVICE..."
26//usage:#define partprobe_full_usage "\n\n"
27//usage: "Ask kernel to rescan partition table"
28//
29// partprobe (GNU parted) 3.2:
30// -d, --dry-run Don't update the kernel
31// -s, --summary Show a summary of devices and their partitions
32
33int partprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
34int partprobe_main(int argc UNUSED_PARAM, char **argv)
35{
36 getopt32(argv, "");
37 argv += optind;
38
39 /* "partprobe" with no arguments just does nothing */
40
41 while (*argv) {
42 int fd = xopen(*argv, O_RDONLY);
43 /*
44 * Newer versions of parted scan partition tables themselves and
45 * use BLKPG ioctl (BLKPG_DEL_PARTITION / BLKPG_ADD_PARTITION)
46 * since this way kernel does not need to know
47 * partition table formats.
48 * We use good old BLKRRPART:
49 */
50 ioctl_or_perror_and_die(fd, BLKRRPART, NULL, "%s", *argv);
51 close(fd);
52 argv++;
53 }
54
55 return EXIT_SUCCESS;
56}