summaryrefslogtreecommitdiffhomepage
path: root/miscutils/partprobe.c
blob: 2c12a7d204ce51cbac7d742069411c4bc83cc4e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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 (3.6 kb)"
//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;
}