summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko2017-04-11 19:17:59 +0200
committerDenys Vlasenko2017-04-11 19:17:59 +0200
commitac47a00e2ec398b04c3141cd3434a6e4b95740b1 (patch)
treef209d50c984c9ed59b9ebaf114119076ef65412a
parent1bc0bd13b5bdeb352db5261c1eec229fe4eb1651 (diff)
downloadbusybox-ac47a00e2ec398b04c3141cd3434a6e4b95740b1.zip
busybox-ac47a00e2ec398b04c3141cd3434a6e4b95740b1.tar.gz
partprobe: new applet
function old new delta partprobe_main - 79 +79 packed_usage 31485 31511 +26 applet_names 2608 2618 +10 applet_main 1512 1516 +4 applet_install_loc 189 190 +1 ------------------------------------------------------------------------------ (add/remove: 2/0 grow/shrink: 4/0 up/down: 120/0) Total: 120 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/partprobe.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/miscutils/partprobe.c b/miscutils/partprobe.c
new file mode 100644
index 0000000..3883159
--- /dev/null
+++ b/miscutils/partprobe.c
@@ -0,0 +1,56 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Copyright (C) 2017 Denys Vlasenko <vda.linux@googlemail.com>
+ *
+ * Licensed under GPLv2, see file LICENSE in this source tree.
+ */
+//config:config PARTPROBE
+//config: bool "partprobe"
+//config: default y
+//config: select PLATFORM_LINUX
+//config: help
+//config: Ask kernel to rescan partition table.
+
+//applet:IF_PARTPROBE(APPLET(partprobe, BB_DIR_USR_SBIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_PARTPROBE) += partprobe.o
+
+#include <linux/fs.h>
+#include "libbb.h"
+#ifndef BLKRRPART
+# define BLKRRPART _IO(0x12,95)
+#endif
+
+//usage:#define partprobe_trivial_usage
+//usage: "DEVICE..."
+//usage:#define partprobe_full_usage "\n\n"
+//usage: "Ask kernel to rescan partition table"
+//
+// partprobe (GNU parted) 3.2:
+// -d, --dry-run Don't update the kernel
+// -s, --summary Show a summary of devices and their partitions
+
+int partprobe_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int partprobe_main(int argc UNUSED_PARAM, char **argv)
+{
+ getopt32(argv, "");
+ argv += optind;
+
+ /* "partprobe" with no arguments just does nothing */
+
+ while (*argv) {
+ int fd = xopen(*argv, O_RDONLY);
+ /*
+ * Newer versions of parted scan partition tables themselves and
+ * use BLKPG ioctl (BLKPG_DEL_PARTITION / BLKPG_ADD_PARTITION)
+ * since this way kernel does not need to know
+ * partition table formats.
+ * We use good old BLKRRPART:
+ */
+ ioctl_or_perror_and_die(fd, BLKRRPART, NULL, "%s", *argv);
+ close(fd);
+ argv++;
+ }
+
+ return EXIT_SUCCESS;
+}