small nftl fix

Peter Kundrat
2000-10-04T02:48:04Z

[-- Attachment #1: Type: text/plain, Size: 1164 bytes --]

Greetings,

When writing to an empty fs on nftl, I always got garbled partition table.
Looking at the nftl.c, there seems to be a problem with overwriting media header
(which seems to be at the FirstPhysicalEUN).

So the patch simply skips first two units (i'd like to know if magic constant 2
is fine (i got it from nftl_format.c)).

Except for that there is a smal fix for LEVEL3 debug eliminating the dump of
"unrecognised partitions" (it was not very syslog friendly anyways).

Last part is about setting LastFreeEUN after the scanning loop .. which didnt
make sense to me .. (it is not correct before the loop either - for the
case of no empty blocks, but seems better :).
Anyways its quite late now, so i may have missed something.

Another problem is the fact, that VirtualUnitTable and ReplUnitTable are
allocated for NumEraseUnits, but are indexed with absolute EUN numbers ..

Also WriteInh seems to be set to 0x1 on all my units (formatted by m-sys utils),
but the code checks for 0xffffffff .. is that value in specification ?

Thats for tonight, more later,

pkx

PS: is it possible to obtain specifications for DOC devices resp. nftl layout ?

[-- Attachment #2: first-eun-pkx.patch --]
[-- Type: text/plain, Size: 2804 bytes --]

--- nftl.c.orig Sun Oct 1 11:52:19 2000
+++ nftl.c Wed Oct 4 03:46:17 2000
@@ -237,10 +237,11 @@
nftl->lastEUN = le16_to_cpu(nftl->MediaHdr.NumEraseUnits) +
le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN) - 1;
nftl->numfreeEUNs = 0;
+ nftl->LastFreeEUN = le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN)+2;

/* Scan each physical Erase Unit for validity and to find the
Virtual Erase Unit Chain to which it belongs */
- for (i = le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN); i <= nftl->lastEUN; i++) {
+ for (i = le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN)+2; i <= nftl->lastEUN; i++) {
union nftl_uci uci;
unsigned long ofs;
size_t retlen;
@@ -277,6 +278,10 @@
nftl->VirtualUnitTable[i] = le16_to_cpu(uci.a.VirtUnitNum);
nftl->ReplUnitTable[i] = le16_to_cpu(uci.a.ReplUnitNum);

+ if (nftl->ReplUnitTable[i] < le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN)+2)
+ printk(KERN_WARNING "EUN %d: is replaced by HDR EUN (%x)\n", i,
+ le16_to_cpu(uci.a.ReplUnitNum));
+
/* if (!(VUN & 0x8000) && VUN < (arraybounds)).. optimises to: */
if (le16_to_cpu(uci.a.VirtUnitNum) < nftl->numvunits)
nftl->EUNtable[le16_to_cpu(uci.a.VirtUnitNum) & 0x7fff] = i;
@@ -288,7 +293,6 @@
}
}
NFTLs[firstfree] = nftl;
- nftl->LastFreeEUN = le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN);

#ifdef PSYCHO_DEBUG
for (i=0; i < 10/* nftl->numvunits*/; i++) {
@@ -377,17 +381,24 @@
}
if (!strncmp(hdr.DataOrgID, "ANAND", 6)) {
DEBUG(MTD_DEBUG_LEVEL2, "Valid NFTL partition at ofs 0x%lx\n", ofs);
+ DEBUG(MTD_DEBUG_LEVEL2,"Erase Units: %d, FirstPhysicalEUN: %d, FormattedSize: %d, UnitSizeFactor: 0x%0x\n",
+ hdr.NumEraseUnits, hdr.FirstPhysicalEUN,
+ hdr.FormattedSize, hdr.UnitSizeFactor);
NFTL_setup(mtd, ofs, &hdr);
- } else {
- DEBUG(MTD_DEBUG_LEVEL3,"No valid NFTL Partition at ofs 0x%lx\n", ofs);
- for (i = 0; i < 6; i++) {
- DEBUG(MTD_DEBUG_LEVEL3,"%x, ", hdr.DataOrgID[i]);
- }
+ } /* else {
+ DEBUG(MTD_DEBUG_LEVEL3,
+ "No valid NFTL Partition at ofs 0x%lx"
+ ", DataOrgId %02.2x,%02.2x,%02.2x,%02.2x,%02.2x,%02.2x (%6.6s)\n",
+ ofs, hdr.DataOrgID[0], hdr.DataOrgID[1], hdr.DataOrgID[2],
+ hdr.DataOrgID[4], hdr.DataOrgID[5], hdr.DataOrgID[6],
+ hdr.DataOrgID);
+
DEBUG(MTD_DEBUG_LEVEL3," = %s\n", hdr.DataOrgID);
DEBUG(MTD_DEBUG_LEVEL3,"%d, %d, %d, %d\n",
hdr.NumEraseUnits, hdr.FirstPhysicalEUN,
hdr.FormattedSize, hdr.UnitSizeFactor);
}
+ */
}
return;
}
@@ -430,7 +441,7 @@
}

if (++pot > nftl->lastEUN)
- pot = le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN);
+ pot = le16_to_cpu(nftl->MediaHdr.FirstPhysicalEUN)+2;

if (!silly--) {
printk("Tell Dave he fucked up. LastFreeEUN = %d, "