When Yaffs code detects problems (e.g. ECC errors) while mounting an MTD partition, it may attempt to rectify them by altering the data stored on the MTD. This operation may break valid Yaffs file systems (e.g. due to OOB layout differences). While writing a file to an MTD is inherently risky as it requires modifying the file system, reading a file from an MTD should not be considered a dangerous operation. Meanwhile, init_mtd_context() always opens the MTD character device in read-write mode, so the file system may be modified even when -r is used. That should not be the case as it breaks user expectations.
Fix by opening the character device in read-only mode when -r is used.
When Yaffs code detects problems (e.g. ECC errors) while mounting an MTD partition, it may attempt to rectify them by altering the data stored on the MTD. This operation may break valid Yaffs file systems (e.g. due to OOB layout differences). While writing a file to an MTD is inherently risky as it requires modifying the file system, reading a file from an MTD should not be considered a dangerous operation. Meanwhile,
init_mtd_context()
always opens the MTD character device in read-write mode, so the file system may be modified even when-r
is used. That should not be the case as it breaks user expectations.Fix by opening the character device in read-only mode when
-r
is used.