block: support builtin fstab config
[project/fstools.git] / libfstools / overlay.c
index 06d0bfd..9e830a1 100644 (file)
@@ -143,9 +143,8 @@ handle_whiteout(const char *dir)
 }
 
 int
-jffs2_switch(int argc, char **argv)
+jffs2_switch(struct volume *v)
 {
-       struct volume *v;
        char *mp;
        int ret = -1;
 
@@ -157,8 +156,7 @@ jffs2_switch(int argc, char **argv)
                return ret;
        }
 
-       v = volume_find("rootfs_data");
-       mp = find_mount_point(v->blk, NULL);
+       mp = find_mount_point(v->blk, 0);
        if (mp) {
                fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp);
                return -1;
@@ -187,29 +185,40 @@ jffs2_switch(int argc, char **argv)
                        ret = -1;
                }
                break;
-       }
 
+       case FS_UBIFS:
+               ret = overlay_mount(v, "ubifs");
+               if (ret)
+                       break;
+               if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) {
+                       fprintf(stderr, "switching to ubifs failed\n");
+                       ret = -1;
+               }
+               break;
+       }
        return ret;
 }
 
-static int overlay_mount_fs(void)
+static int overlay_mount_fs(struct volume *v)
 {
-       struct volume *v;
+       char *fstype;
 
        if (mkdir("/tmp/overlay", 0755)) {
                fprintf(stderr, "failed to mkdir /tmp/overlay: %s\n", strerror(errno));
                return -1;
        }
 
-       v = volume_find("rootfs_data");
-       if (!v) {
-               fprintf(stderr, "rootfs_data does not exist\n");
-               return -1;
+       fstype = "jffs2";
+
+       switch (volume_identify(v)) {
+       case FS_UBIFS:
+               fstype = "ubifs";
+               break;
        }
 
-       if (mount(v->blk, "/tmp/overlay", "jffs2", MS_NOATIME, NULL)) {
-               fprintf(stderr, "failed to mount -t jffs2 %s /tmp/overlay: %s\n",
-                               v->blk, strerror(errno));
+       if (mount(v->blk, "/tmp/overlay", fstype, MS_NOATIME, NULL)) {
+               fprintf(stderr, "failed to mount -t %s %s /tmp/overlay: %s\n",
+                               fstype, v->blk, strerror(errno));
                return -1;
        }
 
@@ -218,21 +227,20 @@ static int overlay_mount_fs(void)
        return -1;
 }
 
-int mount_overlay(void)
+int mount_overlay(struct volume *v)
 {
-       struct volume *v = volume_find("rootfs_data");;
        char *mp;
 
        if (!v)
                return -1;
 
-       mp = find_mount_point(v->blk, NULL);
+       mp = find_mount_point(v->blk, 0);
        if (mp) {
                fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp);
                return -1;
        }
 
-       overlay_mount_fs();
+       overlay_mount_fs(v);
 
        extroot_prefix = "/tmp/overlay";
        if (!mount_extroot()) {
@@ -240,7 +248,7 @@ int mount_overlay(void)
                return 0;
        }
 
-       fprintf(stderr, "switching to jffs2\n");
+       fprintf(stderr, "switching to overlay\n");
        if (mount_move("/tmp", "", "/overlay") || fopivot("/overlay", "/rom")) {
                fprintf(stderr, "switching to jffs2 failed - fallback to ramoverlay\n");
                return ramoverlay();