diff options
author | Bertold Van den Bergh <vandenbergh@bertold.org> | 2014-05-25 20:49:51 -0500 |
---|---|---|
committer | Bertold Van den Bergh <vandenbergh@bertold.org> | 2014-05-25 20:49:51 -0500 |
commit | 7cb7cca7f5759c6921d68a384fd838e01ce446e0 (patch) | |
tree | 835f4d616c2ba9715d70e4c0bfc4dcdb5070ed21 /toys | |
parent | 1c806ca536dc938f949546b28974db79ae85941f (diff) | |
download | toybox-7cb7cca7f5759c6921d68a384fd838e01ce446e0.tar.gz |
I have attached a patch adding a program that allows re-reading the partition table. This is often used on embedded systems booting from SD/USB devices that need to resize partitions on first boot.
Diffstat (limited to 'toys')
-rw-r--r-- | toys/pending/partprobe.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/toys/pending/partprobe.c b/toys/pending/partprobe.c new file mode 100644 index 00000000..2fe3bd53 --- /dev/null +++ b/toys/pending/partprobe.c @@ -0,0 +1,51 @@ +/* partprobe.c - Tell the kernel about partition table changes + * + * Copyright 2014 Bertold Van den Bergh <vandenbergh@bertold.org> + * + * see http://man7.org/linux/man-pages/man8/partprobe.8.html + +USE_PARTPROBE(NEWTOY(partprobe, NULL, TOYFLAG_SBIN)) + +config PARTPROBE + bool "partprobe" + default n + help + partprobe - Tell the kernel about partition table changes + + usage: partprobe [devices...] + + Asks the kernel to re-read the partition table on the specified + devices. +*/ + +#include "toys.h" + +void update_device(char* path) +{ + int sd_fd = open(path, 0); + + if(sd_fd < 0){ + perror_msg("Unable to open %s", path); + return; + } + + if(ioctl(sd_fd, BLKRRPART, NULL) < 0) + perror_msg("ioctl (BLKRRPART) failed, old layout still used"); + + close(sd_fd); +} + +void partprobe_main(void) +{ + char** opt; + if(*toys.optargs == NULL){ + printf("No devices specified.\n"); + exit(EXIT_FAILURE); + } + + for (opt = toys.optargs; *opt; opt++) { + update_device(*opt); + } + + exit(EXIT_SUCCESS); +} |