Denys Vlasenko | ac47a00 | 2017-04-11 19:17:59 +0200 | [diff] [blame] | 1 | /* 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 Vlasenko | b097a84 | 2018-12-28 03:20:17 +0100 | [diff] [blame] | 8 | //config: bool "partprobe (3.5 kb)" |
Denys Vlasenko | ac47a00 | 2017-04-11 19:17:59 +0200 | [diff] [blame] | 9 | //config: default y |
Denys Vlasenko | ac47a00 | 2017-04-11 19:17:59 +0200 | [diff] [blame] | 10 | //config: help |
Denys Vlasenko | 72089cf | 2017-07-21 09:50:55 +0200 | [diff] [blame] | 11 | //config: Ask kernel to rescan partition table. |
Denys Vlasenko | ac47a00 | 2017-04-11 19:17:59 +0200 | [diff] [blame] | 12 | |
Denys Vlasenko | 9c49d6e | 2017-08-05 01:46:39 +0200 | [diff] [blame] | 13 | //applet:IF_PARTPROBE(APPLET_NOEXEC(partprobe, partprobe, BB_DIR_USR_SBIN, BB_SUID_DROP, partprobe)) |
Denys Vlasenko | ac47a00 | 2017-04-11 19:17:59 +0200 | [diff] [blame] | 14 | |
| 15 | //kbuild:lib-$(CONFIG_PARTPROBE) += partprobe.o |
| 16 | |
| 17 | #include <linux/fs.h> |
| 18 | #include "libbb.h" |
| 19 | #ifndef BLKRRPART |
| 20 | # define BLKRRPART _IO(0x12,95) |
| 21 | #endif |
| 22 | |
| 23 | //usage:#define partprobe_trivial_usage |
| 24 | //usage: "DEVICE..." |
| 25 | //usage:#define partprobe_full_usage "\n\n" |
| 26 | //usage: "Ask kernel to rescan partition table" |
| 27 | // |
| 28 | // partprobe (GNU parted) 3.2: |
| 29 | // -d, --dry-run Don't update the kernel |
| 30 | // -s, --summary Show a summary of devices and their partitions |
| 31 | |
| 32 | int partprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 33 | int partprobe_main(int argc UNUSED_PARAM, char **argv) |
| 34 | { |
| 35 | getopt32(argv, ""); |
| 36 | argv += optind; |
| 37 | |
| 38 | /* "partprobe" with no arguments just does nothing */ |
| 39 | |
| 40 | while (*argv) { |
| 41 | int fd = xopen(*argv, O_RDONLY); |
| 42 | /* |
| 43 | * Newer versions of parted scan partition tables themselves and |
| 44 | * use BLKPG ioctl (BLKPG_DEL_PARTITION / BLKPG_ADD_PARTITION) |
| 45 | * since this way kernel does not need to know |
| 46 | * partition table formats. |
| 47 | * We use good old BLKRRPART: |
| 48 | */ |
| 49 | ioctl_or_perror_and_die(fd, BLKRRPART, NULL, "%s", *argv); |
| 50 | close(fd); |
| 51 | argv++; |
| 52 | } |
| 53 | |
| 54 | return EXIT_SUCCESS; |
| 55 | } |