<p>Hello list,</p>
<p>Using kernel 3.2, ubifs failed to mount a fs properly due to a corrupt empty space encoutered while replaying the journal. Please notice the bitflip occurring in the supposedly empty space shown in the log below. The storage medium is an SLC NAND flash.</p>

<p>The stack dump shown below shows that replay_log_leb() was behind the call to ubifs_scan(), and could not deal with the -EUCLEAN error returned. ubifs_scan() returned this error because it detected the corrupt empty space.</p>

<div>The fs was unmounted cleanly, resulting in no need for fs recovery to happen during the mount (need_recovery=0). Therefore the recovery of the log_leb in question couldn't be performed, causing the mount to abort. This problem was also seen in the following thread: <a href="http://lists.infradead.org/pipermail/linux-mtd/2009-March/024953.html">http://lists.infradead.org/pipermail/linux-mtd/2009-March/024953.html</a> with a NOR flash</div>

<div> </div>
<div>I applied the attached patch and the fs was successfully mounted giving the fs a second life.</div>
<p>My main questions are:<br>1) What should be the expected behavior of ubifs in this case? <br>2) Is there a systematic way to recover from a situation like that?<br>3) Is the usage of this patch safe?<br>4) Any suggestions?</p>

<p>Thank you,</p>
<p>Gabriel Matni</p>
<p>Kernel log when attempting to mount the file system (2 UBI volumes on mtd12 each having a ubifs):</p>
<p><5>[   68.901714] UBI: attaching mtd12 to ubi12<br><5>[   68.905773] UBI: physical eraseblock size:   131072 bytes (128 KiB)<br><5>[   68.912640] UBI: logical eraseblock size:    126976 bytes<br><5>[   68.918070] UBI: smallest flash I/O unit:    2048<br>
<5>[   68.923217] UBI: VID header offset:          2048 (aligned 2048)<br><5>[   68.929255] UBI: data offset:                4096<br><5>[   69.853538] UBI: max. sequence number:       52629<br><5>[   69.906701] UBI: attached mtd12 to ubi12<br>
<5>[   69.911170] UBI: MTD device name:            ""<br><5>[   69.916702] UBI: MTD device size:            192 MiB<br><5>[   69.922134] UBI: number of good PEBs:        1528<br><5>[   69.926871] UBI: number of bad PEBs:         8<br>
<5>[   69.931756] UBI: number of corrupted PEBs:   0<br><5>[   69.936239] UBI: max. allowed volumes:       128<br><5>[   69.941285] UBI: wear-leveling threshold:    4096<br><5>[   69.946023] UBI: number of internal volumes: 1<br>
<5>[   69.950900] UBI: number of user volumes:     2<br><5>[   69.955378] UBI: available PEBs:             0<br><5>[   69.960254] UBI: total number of reserved PEBs: 1528<br><5>[   69.965253] UBI: number of PEBs reserved for bad PEB handling: 30<br>
<5>[   69.971786] UBI: max/mean erase counter: 165/36<br><5>[   69.976348] UBI: image sequence number:  1271161585<br><5>[   69.981721] UBI: background thread "ubi_bgt12d" started, PID 891<br><3>[   70.085510] UBIFS error (pid 893): ubifs_scan: corrupt empty space at LEB 5:3775<br>
<3>[   70.093329] UBIFS error (pid 893): ubifs_scanned_corruption: corruption at LEB 5:3775<br><7>[   70.101696] 00000000: ffffffef ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff  ................................<br>
<7>[   70.101847] 00000020: ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff  ................................<br>etc...<br><3>[   70.144549] UBIFS error (pid 893): ubifs_scan: LEB 5 scanning failed<br>
<5>[   70.445773] UBI: mtd12 is detached from ubi12</p>
<div><br>Stack dump at the location of interest (inside ubifs_scan):</div>
<div><br><4>[   60.988112] [<c000c29c>] (dump_backtrace+0x0/0x114) from [<c0234460>] (dump_stack+0x18/0x1c)<br><4>[   60.996995]  r7:c613a000 r6:00000ebf r5:0001e140 r4:c8be7ebf<br><4>[   61.003266] [<c0234448>] (dump_stack+0x0/0x1c) from [<c00f3fd4>] (ubifs_scan+0x334/0x3a0)<br>
<4>[   61.011959] [<c00f3ca0>] (ubifs_scan+0x0/0x3a0) from [<c00f417c>] (replay_log_leb+0x94/0x7e8)<br><4>[   61.021016] [<c00f40e8>] (replay_log_leb+0x0/0x7e8) from [<c00f5aa0>] (ubifs_replay_journal+0x198/0x398)<br>
<4>[   61.031029] [<c00f5908>] (ubifs_replay_journal+0x0/0x398) from [<c00e802c>] (ubifs_fill_super+0xbdc/0x1854)<br><4>[   61.041283] [<c00e7450>] (ubifs_fill_super+0x0/0x1854) from [<c00e9138>] (ubifs_mount+0x494/0x564)<br>
<4>[   61.050769] [<c00e8ca4>] (ubifs_mount+0x0/0x564) from [<c00816cc>] (mount_fs+0x14/0x40)<br></div>