5 #include <sys/reboot.h>
7 #include <cutils/android_reboot.h>
8 #include <cutils/partition_utils.h>
10 const char *mkfs
= "/system/bin/make_ext4fs";
12 int setup_fs(const char *blockdev
)
14 char buf
[256], path
[128];
19 /* we might be looking at an indirect reference */
20 n
= readlink(blockdev
, path
, sizeof(path
) - 1);
23 if (!memcmp(path
, "/dev/block/", 11))
27 if (strchr(blockdev
,'/')) {
28 fprintf(stderr
,"not a block device name: %s\n", blockdev
);
32 snprintf(buf
, sizeof(buf
), "/sys/fs/ext4/%s", blockdev
);
33 if (access(buf
, F_OK
) == 0) {
34 fprintf(stderr
,"device %s already has a filesystem\n", blockdev
);
37 snprintf(buf
, sizeof(buf
), "/dev/block/%s", blockdev
);
39 if (!partition_wiped(buf
)) {
40 fprintf(stderr
,"device %s not wiped, probably encrypted, not wiping\n", blockdev
);
44 fprintf(stderr
,"+++\n");
48 fprintf(stderr
,"error: setup_fs: fork failed\n");
52 execl(mkfs
, mkfs
, buf
, NULL
);
56 while ((pid
=waitpid(-1, &status
, 0)) != child
) {
58 fprintf(stderr
, "error: setup_fs: waitpid failed!\n");
63 fprintf(stderr
,"---\n");
68 int main(int argc
, char **argv
)
73 if (strlen(argv
[1]) < 128)
74 need_reboot
|= setup_fs(argv
[1]);
80 fprintf(stderr
,"REBOOT!\n");
81 android_reboot(ANDROID_RB_RESTART
, 0, 0);