X-Git-Url: http://git.archive.openwrt.org/?p=project%2Ffstools.git;a=blobdiff_plain;f=backend%2Fjffs2.c;h=09c66cf3dfea2ee10a7b03606aa4d135eed821d8;hp=feb37d2913de3220d579018972c0cb1508f6881a;hb=4e3268f90ae97ccb047c47a78b83bcebeb9593cd;hpb=d292ffc85f48dd9c8774a0860f50397dd2966e7a diff --git a/backend/jffs2.c b/backend/jffs2.c index feb37d2..09c66cf 100644 --- a/backend/jffs2.c +++ b/backend/jffs2.c @@ -28,7 +28,7 @@ #include #include "../fs-state.h" -#include "../lib/mtd.h" +#include "../driver/volume.h" #define SWITCH_JFFS2 "/tmp/.switch_jffs2" @@ -54,41 +54,32 @@ foreachdir(const char *dir, int (*cb)(const char*)) static int jffs2_mount(void) { - char rootfs_data[32]; - int fd; + struct volume *v; if (mkdir("/tmp/overlay", 0755)) { fprintf(stderr, "failed to mkdir /tmp/overlay: %s\n", strerror(errno)); return -1; } - if (find_mtd_block("rootfs_data", rootfs_data, sizeof(rootfs_data))) { + v = volume_find("rootfs_data"); + if (!v) { fprintf(stderr, "rootfs_data does not exist\n"); return -1; } - if (mount(rootfs_data, "/tmp/overlay", "jffs2", MS_NOATIME, NULL)) { - fprintf(stderr, "failed to mount -t jffs2 %s /tmp/overlay: %s\n", rootfs_data, strerror(errno)); + 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)); return -1; } - find_mtd_char("rootfs_data", rootfs_data, sizeof(rootfs_data)); - - fd = mtd_load(rootfs_data); - if (fd > 0) { - int ret = mtd_unlock(fd); - close(fd); - return ret; - } - - return -1; + return volume_init(v); } static int switch2jffs(void) { + struct volume *v = volume_find("rootfs_data"); struct stat s; - char mtd[32]; int ret; if (!stat(SWITCH_JFFS2, &s)) { @@ -96,19 +87,16 @@ switch2jffs(void) return -1; } - if (!find_mtd_block("rootfs_patches", mtd, sizeof(mtd))) - return 0; - - if (find_mtd_block("rootfs_data", mtd, sizeof(mtd))) { + if (!v) { fprintf(stderr, "no rootfs_data was found\n"); return -1; } creat("/tmp/.switch_jffs2", 0600); - ret = mount(mtd, "/rom/overlay", "jffs2", MS_NOATIME, NULL); + ret = mount(v->blk, "/rom/overlay", "jffs2", MS_NOATIME, NULL); unlink("/tmp/.switch_jffs2"); if (ret) { - fprintf(stderr, "failed - mount -t jffs2 %s /rom/overlay: %s\n", mtd, strerror(errno)); + fprintf(stderr, "failed - mount -t jffs2 %s /rom/overlay: %s\n", v->blk, strerror(errno)); return -1; } @@ -210,7 +198,7 @@ handle_rmdir(const char *dir) static int jffs2_reset(int argc, char **argv) { - char mtd[32]; + struct volume *v; char *mp; if (ask_user(argc, argv)) @@ -221,25 +209,20 @@ jffs2_reset(int argc, char **argv) return -1; } - if (find_mtd_block("rootfs_data", mtd, sizeof(mtd))) { + v = volume_find("rootfs_data"); + if (!v) { fprintf(stderr, "no rootfs_data was found\n"); return -1; } - mp = find_mount_point(mtd, "jffs2"); + mp = find_mount_point(v->blk, "jffs2"); if (mp) { - fprintf(stderr, "%s is mounted as %s, only erasing files\n", mtd, mp); + fprintf(stderr, "%s is mounted as %s, only erasing files\n", v->blk, mp); foreachdir(mp, handle_rmdir); mount(mp, "/", NULL, MS_REMOUNT, 0); } else { - int fd; - fprintf(stderr, "%s is not mounted, erasing it\n", mtd); - find_mtd_char("rootfs_data", mtd, sizeof(mtd)); - fd = mtd_load(mtd); - if (fd > 0) { - mtd_erase(fd, 0, mtdsize / erasesize); - close(fd); - } + fprintf(stderr, "%s is not mounted, erasing it\n", v->blk); + volume_erase_all(v); } return 0; @@ -248,31 +231,32 @@ jffs2_reset(int argc, char **argv) static int jffs2_mark(int argc, char **argv) { - FILE *fp; __u32 deadc0de = __cpu_to_be32(0xdeadc0de); - char mtd[32]; + struct volume *v; size_t sz; + int fd; if (ask_user(argc, argv)) return -1; - if (find_mtd_block("rootfs_data", mtd, sizeof(mtd))) { + v = volume_find("rootfs_data"); + if (!v) { fprintf(stderr, "no rootfs_data was found\n"); return -1; } - fp = fopen(mtd, "w"); - fprintf(stderr, "%s - marking with deadc0de\n", mtd); - if (!fp) { - fprintf(stderr, "opening %s failed\n", mtd); + fd = open(v->blk, O_WRONLY); + fprintf(stderr, "%s - marking with deadc0de\n", v->blk); + if (!fd) { + fprintf(stderr, "opening %s failed\n", v->blk); return -1; } - sz = fwrite(&deadc0de, sizeof(deadc0de), 1, fp); - fclose(fp); + sz = write(fd, &deadc0de, sizeof(deadc0de)); + close(fd); if (sz != 1) { - fprintf(stderr, "writing %s failed: %s\n", mtd, strerror(errno)); + fprintf(stderr, "writing %s failed: %s\n", v->blk, strerror(errno)); return -1; } @@ -282,7 +266,7 @@ jffs2_mark(int argc, char **argv) int jffs2_switch(int argc, char **argv) { - char mtd[32]; + struct volume *v; char *mp; int ret = -1; @@ -294,19 +278,14 @@ jffs2_switch(int argc, char **argv) return ret; } - find_mtd_block("rootfs_data", mtd, sizeof(mtd)); - mp = find_mount_point(mtd, NULL); + v = volume_find("rootfs_data"); + mp = find_mount_point(v->blk, NULL); if (mp) { - fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", mtd, mp); + fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp); return -1; } - if (find_mtd_char("rootfs_data", mtd, sizeof(mtd))) { - fprintf(stderr, "no rootfs_data was found\n"); - return ret; - } - - switch (mtd_identify(mtd)) { + switch (volume_identify(v)) { case FS_NONE: fprintf(stderr, "no jffs2 marker found\n"); /* fall through */ @@ -334,51 +313,47 @@ jffs2_switch(int argc, char **argv) return ret; } -static int mtd_mount_jffs2(void) +static int overlay_mount_fs(void) { - char rootfs_data[32]; - int fd; + struct volume *v; if (mkdir("/tmp/overlay", 0755)) { fprintf(stderr, "failed to mkdir /tmp/overlay: %s\n", strerror(errno)); return -1; } - if (find_mtd_block("rootfs_data", rootfs_data, sizeof(rootfs_data))) { + v = volume_find("rootfs_data"); + if (!v) { fprintf(stderr, "rootfs_data does not exist\n"); return -1; } - if (mount(rootfs_data, "/tmp/overlay", "jffs2", MS_NOATIME, NULL)) { - fprintf(stderr, "failed to mount -t jffs2 %s /tmp/overlay: %s\n", rootfs_data, strerror(errno)); + 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)); return -1; } - find_mtd_char("rootfs_data", rootfs_data, sizeof(rootfs_data)); - - fd = mtd_load(rootfs_data); - if (fd) { - int ret = mtd_unlock(fd); - close(fd); - return ret; - } + volume_init(v); return -1; } static int overlay_mount(void) { - char mtd[32]; + struct volume *v = volume_find("rootfs_data");; char *mp; - find_mtd_block("rootfs_data", mtd, sizeof(mtd)); - mp = find_mount_point(mtd, NULL); + if (!v) + return -1; + + mp = find_mount_point(v->blk, NULL); if (mp) { - fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", mtd, mp); + fprintf(stderr, "rootfs_data:%s is already mounted as %s\n", v->blk, mp); return -1; } - mtd_mount_jffs2(); + overlay_mount_fs(); extroot_prefix = "/tmp/overlay"; if (!backend_mount("extroot")) {