summaryrefslogtreecommitdiffstats
path: root/setup_fs.c
diff options
context:
space:
mode:
authorKolja Dummann <k.dummann@gmail.com>2011-05-26 23:13:57 +0200
committerKolja Dummann <k.dummann@gmail.com>2011-05-28 18:23:34 +0200
commit163c7a28554f63d61f26391f223adcbbe0cdb2e3 (patch)
tree6b9c361dbbe7a0c3f8ab43ba3362274e16115772 /setup_fs.c
parent32f1062d6f60bf4a38c17413660ae1b4634d740c (diff)
downloaddevice_samsung_aries-common-163c7a28554f63d61f26391f223adcbbe0cdb2e3.zip
device_samsung_aries-common-163c7a28554f63d61f26391f223adcbbe0cdb2e3.tar.gz
device_samsung_aries-common-163c7a28554f63d61f26391f223adcbbe0cdb2e3.tar.bz2
overlay: code dedup, move overlay to aries-common
new update script for radio image fix tethering interface Change-Id: I19583cce1aac14cef01f5ba05b85fb1bfbedb507
Diffstat (limited to 'setup_fs.c')
-rw-r--r--setup_fs.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/setup_fs.c b/setup_fs.c
new file mode 100644
index 0000000..0acf026
--- /dev/null
+++ b/setup_fs.c
@@ -0,0 +1,75 @@
+#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[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);
+
+ 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) {
+ sync();
+ sync();
+ sync();
+ fprintf(stderr,"REBOOT!\n");
+ reboot(RB_AUTOBOOT);
+ exit(-1);
+ }
+ return 0;
+}