diff options
author | Brian Swetland <swetland@google.com> | 2010-09-15 16:13:20 -0700 |
---|---|---|
committer | Brian Swetland <swetland@google.com> | 2010-09-15 18:00:17 -0700 |
commit | 86304be09a9dca526e4e018163dc55df9096ea14 (patch) | |
tree | d119665be6f2b548acf440863cd757cdbe26adcf /setup_fs.c | |
parent | fc505e57a9e0eefab9121f09761c02a5961637ff (diff) | |
download | device_samsung_crespo-86304be09a9dca526e4e018163dc55df9096ea14.zip device_samsung_crespo-86304be09a9dca526e4e018163dc55df9096ea14.tar.gz device_samsung_crespo-86304be09a9dca526e4e018163dc55df9096ea14.tar.bz2 |
switch over to ext4
- configure build for ext4 images
- add tool to initialize filesystems at boot if need be
- require new bootloader with ext4 partitions
- hope for the best
Change-Id: I9c721384ce139e24ff109971de49ceb5abb40406
Diffstat (limited to 'setup_fs.c')
-rw-r--r-- | setup_fs.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/setup_fs.c b/setup_fs.c new file mode 100644 index 0000000..74a6e71 --- /dev/null +++ b/setup_fs.c @@ -0,0 +1,62 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <sys/reboot.h> +#include <sys/wait.h> + +const char *mkfs = "/system/bin/make_ext4fs"; + +int setup_fs(const char *blockdev) +{ + char buf[128]; + pid_t child; + int status; + + sprintf(buf,"/sys/fs/ext4/%s", blockdev); + if (access(buf, F_OK) == 0) { + fprintf(stderr,"device %s already has a filesystem\n", blockdev); + return 0; + } + sprintf(buf,"/dev/block/%s", blockdev); + + fprintf(stderr,"+++\n"); + + child = fork(); + if (child < 0) { + fprintf(stderr,"error: fork failed\n"); + return 0; + } + if (child == 0) { + execl(mkfs, mkfs, buf, NULL); + exit(-1); + } + + while (waitpid(-1, &status, 0) != child) ; + + fprintf(stderr,"---\n"); + return 1; +} + + +int main(int argc, char **argv) +{ + int need_reboot = 0; + + while (argc > 1) { + if (strlen(argv[1]) > 32) continue; + need_reboot |= setup_fs(argv[1]); + argv++; + argc--; + } + + if (need_reboot) { + sync(); + sync(); + sync(); + fprintf(stderr,"REBOOT!\n"); + reboot(RB_AUTOBOOT); + exit(-1); + } + return 0; +} |