summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@nbd.name>2020-04-09 13:19:08 +0200
committerFelix Fietkau <nbd@nbd.name>2020-04-09 14:17:00 +0200
commitc80f7002114f65dc40895c9064c077d9631b8f6e (patch)
tree5a53f631980c68a6854d314f13956148f706241a
parent830441d790d67147dc9d9bca4a9d3d4a7228e367 (diff)
downloadfstools-c80f7002114f65dc40895c9064c077d9631b8f6e.tar.gz
libfstools/mtd: attempt to read from OOB data if empty space is found
When using jffs2 on NAND flash, it stores its magic in the OOB data on newly erased blocks. This change fixes identifying the filesystem type. Signed-off-by: Felix Fietkau <nbd@nbd.name>
-rw-r--r--libfstools/mtd.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/libfstools/mtd.c b/libfstools/mtd.c
index 77c71ee..c5dce50 100644
--- a/libfstools/mtd.c
+++ b/libfstools/mtd.c
@@ -187,7 +187,6 @@ static int mtd_volume_identify(struct volume *v)
{
struct mtd_volume *p = container_of(v, struct mtd_volume, v);;
__u32 deadc0de;
- __u16 jffs2;
size_t sz;
if (mtd_volume_load(p)) {
@@ -202,6 +201,16 @@ static int mtd_volume_identify(struct volume *v)
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;
@@ -210,10 +219,9 @@ static int mtd_volume_identify(struct volume *v)
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;