4 #include <sys/reboot.h>
8 #include <cutils/android_reboot.h>
9 #include <cutils/partition_utils.h>
11 const char *mkfs = "/system/bin/make_ext4fs";
13 int setup_fs(const char *blockdev)
15 char buf[256], path[128];
20 /* we might be looking at an indirect reference */
21 n = readlink(blockdev, path, sizeof(path) - 1);
24 if (!memcmp(path, "/dev/block/", 11))
28 if (strchr(blockdev,'/')) {
29 fprintf(stderr,"not a block device name: %s\n", blockdev);
33 snprintf(buf, sizeof(buf), "/sys/fs/ext4/%s", blockdev);
34 if (access(buf, F_OK) == 0) {
35 fprintf(stderr,"device %s already has a filesystem\n", blockdev);
38 snprintf(buf, sizeof(buf), "/dev/block/%s", blockdev);
40 if (!partition_wiped(buf)) {
41 fprintf(stderr,"device %s not wiped, probably encrypted, not wiping\n", blockdev);
45 fprintf(stderr,"+++\n");
49 fprintf(stderr,"error: setup_fs: fork failed\n");
53 execl(mkfs, mkfs, buf, NULL);
57 while ((pid=waitpid(-1, &status, 0)) != child) {
59 fprintf(stderr, "error: setup_fs: waitpid failed!\n");
64 fprintf(stderr,"---\n");
69 int main(int argc, char **argv)
74 if (strlen(argv[1]) < 128)
75 need_reboot |= setup_fs(argv[1]);
81 fprintf(stderr,"REBOOT!\n");
82 android_reboot(ANDROID_RB_RESTART, 0, 0);