summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sumrall <ksumrall@android.com>2011-06-03 14:38:27 -0700
committerKen Sumrall <ksumrall@android.com>2011-06-03 14:38:27 -0700
commit337847a149d956ed6d5990f84006f7340475f715 (patch)
tree2d33f7a3e74b144744132e12de6a2703753550c7
parent67bf7cb2c7487b2a93af8e2d9903842e8fe51f69 (diff)
downloadextras-337847a149d956ed6d5990f84006f7340475f715.tar.gz
Move the setup_fs program from device/samsung/crespo to ext4_utils.
Prime also uses this, so it's no longer crespo specfic. Change-Id: Idd35ee85599717a06902f696a73e5a4bd6522ac6
-rw-r--r--ext4_utils/Android.mk7
-rw-r--r--ext4_utils/setup_fs.c79
2 files changed, 86 insertions, 0 deletions
diff --git a/ext4_utils/Android.mk b/ext4_utils/Android.mk
index 417c839e..2a5fca78 100644
--- a/ext4_utils/Android.mk
+++ b/ext4_utils/Android.mk
@@ -98,6 +98,13 @@ LOCAL_MODULE := simg2img
include $(BUILD_EXECUTABLE)
include $(CLEAR_VARS)
+LOCAL_SRC_FILES := setup_fs.c
+LOCAL_MODULE := setup_fs
+LOCAL_MODULE_TAGS := optional
+LOCAL_SHARED_LIBRARIES += libcutils
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
LOCAL_MODULE := mkuserimg.sh
LOCAL_SRC_FILES := mkuserimg.sh
diff --git a/ext4_utils/setup_fs.c b/ext4_utils/setup_fs.c
new file mode 100644
index 00000000..380c0df8
--- /dev/null
+++ b/ext4_utils/setup_fs.c
@@ -0,0 +1,79 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/reboot.h>
+#include <sys/wait.h>
+#include <cutils/android_reboot.h>
+#include <cutils/partition_utils.h>
+
+const char *mkfs = "/system/bin/make_ext4fs";
+
+int setup_fs(const char *blockdev)
+{
+ char buf[256], path[128];
+ pid_t child;
+ int status, n;
+
+ /* we might be looking at an indirect reference */
+ n = readlink(blockdev, path, sizeof(path) - 1);
+ if (n > 0) {
+ path[n] = 0;
+ if (!memcmp(path, "/dev/block/", 11))
+ blockdev = path + 11;
+ }
+
+ if (strchr(blockdev,'/')) {
+ fprintf(stderr,"not a block device name: %s\n", blockdev);
+ return 0;
+ }
+
+ 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);
+
+ if (!partition_wiped(buf)) {
+ fprintf(stderr,"device %s not wiped, probably encrypted, not wiping\n", blockdev);
+ return 0;
+ }
+
+ 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]) < 128)
+ need_reboot |= setup_fs(argv[1]);
+ argv++;
+ argc--;
+ }
+
+ if (need_reboot) {
+ fprintf(stderr,"REBOOT!\n");
+ android_reboot(ANDROID_RB_RESTART, 0, 0);
+ exit(-1);
+ }
+ return 0;
+}