2 * Filename: reread_partition_table.c
3 * Purpose: re-read partition table on Linux
4 * Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org>
5 * Bug-Reports: see http://grml.org/bugs/
6 * License: This file is licensed under the GPL v2.
7 * Latest change: Die Sep 05 23:13:57 CEST 2006 [mika]
8 *******************************************************************************/
10 // diet gcc -s -Os -o reread_partition_table reread_partition_table.c
17 #include <sys/ioctl.h>
18 #include <sys/types.h>
23 printf("Usage: reread_partition_table <device>\n");
26 int reread_partition_table(char *dev)
32 if ((fd = open(dev, O_RDONLY)) < 0) {
33 perror("error opening device");
37 if (ioctl(fd, BLKRRPART) < 0) {
38 perror("unable to reload partition table");
42 printf("successfully reread partition table\n");
47 int main(int argc, char** argv)
50 printf("Error: reread_partition_table requires root permissions\n");
59 if (strncmp(argv[1], "/dev/", 5) != 0) {
60 printf("Invalid argument.\n");
64 reread_partition_table(argv[1]);
69 /* END OF FILE ****************************************************************/