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 *******************************************************************************/
9 // diet gcc -s -Os -o reread_partition_table reread_partition_table.c
16 #include <sys/ioctl.h>
17 #include <sys/types.h>
22 printf("Usage: reread_partition_table <device>\n");
25 int reread_partition_table(char *dev)
31 if ((fd = open(dev, O_RDONLY)) < 0) {
32 perror("error opening device");
36 if (ioctl(fd, BLKRRPART) < 0) {
37 perror("unable to reload partition table");
41 printf("successfully reread partition table\n");
46 int main(int argc, char** argv)
49 printf("Error: reread_partition_table requires root permissions\n");
58 if (strncmp(argv[1], "/dev/", 5) != 0) {
59 printf("Invalid argument.\n");
63 reread_partition_table(argv[1]);
68 /* END OF FILE ****************************************************************/