rendered paste body/* * Filename: reread_partition_table.c * Purpose: re-read partition table on Linux * Authors: grml-team (grml.org), (c) Michael Prokop <mika@grml.org> * Bug-Reports: see http://grml.org/bugs/ * License: This file is licensed under the GPL v2. * Latest change: Die Sep 05 23:10:16 CEST 2006 [mika] *******************************************************************************/#include <fcntl.h>#include <linux/fs.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <sys/ioctl.h>#include <sys/types.h>#include <unistd.h>void usage(){ printf("Usage: reread_partition_table <device>\n");}int reread_partition_table(char *dev){ int fd; sync(); if ((fd = open(dev, O_RDONLY)) < 0) { perror("error opening device"); return(1); } if (ioctl(fd, BLKRRPART) < 0) { perror("unable to reload partition table"); return(1); } else { printf("successfully reread partition table\n"); return(0); }}void main(int argc, char** argv){ if (getuid() != 0){ printf("Error: reread_partition_table requires root permissions\n"); exit(1); } if (strncmp(argv[1], "/dev/", 5) != 0){ printf("Invalid argument.\n"); usage(); exit(1); } if (argc < 2) { usage(); exit(1); } else reread_partition_table(argv[1]);}/* END OF FILE ****************************************************************/