#include <fcntl.h>
#include "../fs-state.h"
-#include "../lib/mtd.h"
+#include "../driver/volume.h"
#define SWITCH_JFFS2 "/tmp/.switch_jffs2"
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)) {
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;
}
static int
jffs2_reset(int argc, char **argv)
{
- char mtd[32];
+ struct volume *v;
char *mp;
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;
}
- 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;
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;
}
int
jffs2_switch(int argc, char **argv)
{
- char mtd[32];
+ struct volume *v;
char *mp;
int ret = -1;
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 */
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")) {