fix jffs2reset on ubifs overlay
authorDaniel Golle <daniel@makrotopia.org>
Sat, 21 Jun 2014 20:07:26 +0000 (22:07 +0200)
committerDaniel Golle <daniel@makrotopia.org>
Sat, 21 Jun 2014 22:20:11 +0000 (00:20 +0200)
change find_mount_point parameter to match either all or only
jffs2 and ubifs, which are typically used on embedded mtd devices.
For now, find_mount_point was used without the fstype parameter
except for a single occurance in jffs2reset. There it is desireable
to apply the same logic as previously hard-coded to jffs2 also in the
case of a ubifs overlay, so firstboot aka. factory-reset works as
expected.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
jffs2reset.c
libfstools/find.c
libfstools/jffs2.c
libfstools/libfstools.h
libfstools/overlay.c

index 122e03b..5684872 100644 (file)
@@ -84,7 +84,7 @@ jffs2_reset(int argc, char **argv)
                return -1;
        }
 
                return -1;
        }
 
-       mp = find_mount_point(v->blk, "jffs2");
+       mp = find_mount_point(v->blk, 1);
        if (mp) {
                fprintf(stderr, "%s is mounted as %s, only erasing files\n", v->blk, mp);
                foreachdir(mp, handle_rmdir);
        if (mp) {
                fprintf(stderr, "%s is mounted as %s, only erasing files\n", v->blk, mp);
                foreachdir(mp, handle_rmdir);
index 71548f5..d9df173 100644 (file)
@@ -73,7 +73,7 @@ find_mount(char *mp)
 }
 
 char*
 }
 
 char*
-find_mount_point(char *block, char *fs)
+find_mount_point(char *block, int mtd_only)
 {
        FILE *fp = fopen("/proc/mounts", "r");
        static char line[256];
 {
        FILE *fp = fopen("/proc/mounts", "r");
        static char line[256];
@@ -96,7 +96,9 @@ find_mount_point(char *block, char *fs)
                        *t = '\0';
                        t++;
 
                        *t = '\0';
                        t++;
 
-                       if (fs && strncmp(t, fs, strlen(fs))) {
+                       if (mtd_only &&
+                           strncmp(t, "jffs2", 6) &&
+                           strncmp(t, "ubifs", 6)) {
                                fclose(fp);
                                fprintf(stderr, "block is mounted with wrong fs\n");
                                return NULL;
                                fclose(fp);
                                fprintf(stderr, "block is mounted with wrong fs\n");
                                return NULL;
index 0da9f2f..134e09d 100644 (file)
@@ -172,7 +172,7 @@ jffs2_switch(int argc, char **argv)
        }
 
        v = volume_find("rootfs_data");
        }
 
        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;
        if (mp) {
                fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp);
                return -1;
@@ -240,7 +240,7 @@ int mount_overlay(void)
        if (!v)
                return -1;
 
        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;
        if (mp) {
                fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp);
                return -1;
index f9cafbd..70220c2 100644 (file)
@@ -37,7 +37,7 @@ extern int ramoverlay(void);
 
 extern int find_overlay_mount(char *overlay);
 extern char* find_mount(char *mp);
 
 extern int find_overlay_mount(char *overlay);
 extern char* find_mount(char *mp);
-extern char* find_mount_point(char *block, char *fs);
+extern char* find_mount_point(char *block, int mtd_only);
 extern int find_filesystem(char *fs);
 extern int find_mtd_block(char *name, char *part, int plen);
 extern int find_mtd_char(char *name, char *part, int plen);
 extern int find_filesystem(char *fs);
 extern int find_mtd_block(char *name, char *part, int plen);
 extern int find_mtd_char(char *name, char *part, int plen);
index ae0ead3..dc350b5 100644 (file)
@@ -158,7 +158,7 @@ jffs2_switch(int argc, char **argv)
        }
 
        v = volume_find("rootfs_data");
        }
 
        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;
        if (mp) {
                fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp);
                return -1;
@@ -244,7 +244,7 @@ int mount_overlay(void)
        if (!v)
                return -1;
 
        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;
        if (mp) {
                fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp);
                return -1;