return;
close(p->fd);
- p->fd = 0;
+ p->fd = -1;
}
static int mtd_volume_load(struct mtd_volume *p)
struct mtd_info_user mtdInfo;
struct erase_info_user mtdLockInfo;
- if (p->fd) {
- lseek(p->fd, 0, SEEK_SET);
- return 0;
- }
+ if (p->fd >= 0)
+ return (lseek(p->fd, 0, SEEK_SET) == -1);
if (!p->chr)
return -1;
p->fd = mtd_open(p->chr, 0);
if (p->fd < 0) {
- p->fd = 0;
ULOG_ERR("Could not open mtd device: %s\n", p->chr);
return -1;
}
v->name = strdup(name);
v->drv = &mtd_driver;
p->idx = atoi(idx);
+ p->fd = -1;
snprintf(buffer, sizeof(buffer), "/dev/mtdblock%s", idx);
v->blk = strdup(buffer);
{
struct mtd_volume *p = container_of(v, struct mtd_volume, v);;
__u32 deadc0de;
- __u16 jffs2;
size_t sz;
if (mtd_volume_load(p)) {
sz = read(p->fd, &deadc0de, sizeof(deadc0de));
if (sz != sizeof(deadc0de)) {
- ULOG_ERR("reading %s failed: %s\n", v->name, strerror(errno));
+ ULOG_ERR("reading %s failed: %m\n", v->name);
return -1;
}
+ if (deadc0de == ~0) {
+ struct mtd_oob_buf oob = {
+ .start = 0,
+ .length = sizeof(deadc0de),
+ .ptr = (void *)&deadc0de,
+ };
+
+ ioctl(p->fd, MEMREADOOB, &oob);
+ }
+
if (deadc0de == __be32_to_cpu(0x4f575254))
return FS_SNAPSHOT;
return FS_DEADCODE;
}
- jffs2 = __be16_to_cpu(deadc0de >> 16);
- if (jffs2 == 0x1985) {
+ if (__be16_to_cpu(deadc0de) == 0x1985 ||
+ __be16_to_cpu(deadc0de >> 16) == 0x1985)
return FS_JFFS2;
- }
if (v->type == UBIVOLUME && deadc0de == 0xffffffff) {
return FS_JFFS2;
ret = ioctl(p->fd, MEMGETINFO, &mtdinfo);
if (ret) {
- ULOG_ERR("ioctl(%d, MEMGETINFO) failed: %s\n", p->fd, strerror(errno));
+ ULOG_ERR("ioctl(%d, MEMGETINFO) failed: %m\n", p->fd);
} else {
struct erase_info_user mtdlock;
static struct driver mtd_driver = {
.name = "mtd",
+ .priority = 10,
.find = mtd_volume_find,
.init = mtd_volume_init,
.erase = mtd_volume_erase,