Mercurial > yaffs-ecoscentric
annotate yaffs_tagscompat.c @ 352:88c898910859
Change locking to allow reentry during readdir
| author | charles |
|---|---|
| date | Wed, 11 Nov 2009 02:11:13 +0000 |
| parents | 1e8f7df58d5e |
| children |
| rev | line source |
|---|---|
| 0 | 1 /* |
| 174 | 2 * YAFFS: Yet Another Flash File System. A NAND-flash specific file system. |
| 0 | 3 * |
| 174 | 4 * Copyright (C) 2002-2007 Aleph One Ltd. |
| 5 * for Toby Churchill Ltd and Brightstar Engineering | |
| 0 | 6 * |
| 7 * Created by Charles Manning <charles@aleph1.co.uk> | |
| 8 * | |
| 9 * This program is free software; you can redistribute it and/or modify | |
| 10 * it under the terms of the GNU General Public License version 2 as | |
| 11 * published by the Free Software Foundation. | |
| 12 */ | |
| 13 | |
| 14 #include "yaffs_guts.h" | |
| 15 #include "yaffs_tagscompat.h" | |
| 16 #include "yaffs_ecc.h" | |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
17 #include "yaffs_getblockinfo.h" |
| 0 | 18 |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
19 static void yaffs_HandleReadDataError(yaffs_Device *dev, int chunkInNAND); |
|
47
216765645976
If kernel/config.h is included in yportenv.h, then yportenv.h must be
marty
parents:
10
diff
changeset
|
20 #ifdef NOTYET |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
21 static void yaffs_CheckWrittenBlock(yaffs_Device *dev, int chunkInNAND); |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
22 static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
23 const __u8 *data, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
24 const yaffs_Spare *spare); |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
25 static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
26 const yaffs_Spare *spare); |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
27 static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND); |
|
47
216765645976
If kernel/config.h is included in yportenv.h, then yportenv.h must be
marty
parents:
10
diff
changeset
|
28 #endif |
| 0 | 29 |
| 79 | 30 static const char yaffs_countBitsTable[256] = { |
| 31 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, | |
| 32 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | |
| 33 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | |
| 34 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 35 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | |
| 36 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 37 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 38 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | |
| 39 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, | |
| 40 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 41 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 42 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | |
| 43 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, | |
| 44 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | |
| 45 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, | |
| 46 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8 | |
| 0 | 47 }; |
| 48 | |
| 185 | 49 int yaffs_CountBits(__u8 x) |
| 0 | 50 { |
| 51 int retVal; | |
| 52 retVal = yaffs_countBitsTable[x]; | |
| 53 return retVal; | |
| 54 } | |
| 55 | |
| 79 | 56 /********** Tags ECC calculations *********/ |
| 0 | 57 |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
58 void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare) |
| 0 | 59 { |
| 79 | 60 yaffs_ECCCalculate(data, spare->ecc1); |
| 61 yaffs_ECCCalculate(&data[256], spare->ecc2); | |
| 0 | 62 } |
| 63 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
64 void yaffs_CalcTagsECC(yaffs_Tags *tags) |
| 0 | 65 { |
| 79 | 66 /* Calculate an ecc */ |
| 0 | 67 |
| 79 | 68 unsigned char *b = ((yaffs_TagsUnion *) tags)->asBytes; |
| 69 unsigned i, j; | |
| 70 unsigned ecc = 0; | |
| 0 | 71 unsigned bit = 0; |
| 72 | |
| 73 tags->ecc = 0; | |
| 74 | |
| 79 | 75 for (i = 0; i < 8; i++) { |
| 76 for (j = 1; j & 0xff; j <<= 1) { | |
| 0 | 77 bit++; |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
78 if (b[i] & j) |
| 0 | 79 ecc ^= bit; |
| 80 } | |
| 81 } | |
| 82 | |
| 83 tags->ecc = ecc; | |
| 84 | |
| 85 } | |
| 86 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
87 int yaffs_CheckECCOnTags(yaffs_Tags *tags) |
| 0 | 88 { |
| 89 unsigned ecc = tags->ecc; | |
| 90 | |
| 91 yaffs_CalcTagsECC(tags); | |
| 92 | |
| 93 ecc ^= tags->ecc; | |
| 79 | 94 |
| 95 if (ecc && ecc <= 64) { | |
| 96 /* TODO: Handle the failure better. Retire? */ | |
| 97 unsigned char *b = ((yaffs_TagsUnion *) tags)->asBytes; | |
| 0 | 98 |
| 99 ecc--; | |
| 100 | |
| 101 b[ecc / 8] ^= (1 << (ecc & 7)); | |
| 102 | |
| 79 | 103 /* Now recvalc the ecc */ |
| 0 | 104 yaffs_CalcTagsECC(tags); |
| 105 | |
| 79 | 106 return 1; /* recovered error */ |
| 107 } else if (ecc) { | |
| 108 /* Wierd ecc failure value */ | |
| 109 /* TODO Need to do somethiong here */ | |
| 110 return -1; /* unrecovered error */ | |
| 0 | 111 } |
| 112 | |
| 113 return 0; | |
| 114 } | |
| 115 | |
| 79 | 116 /********** Tags **********/ |
| 0 | 117 |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
118 static void yaffs_LoadTagsIntoSpare(yaffs_Spare *sparePtr, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
119 yaffs_Tags *tagsPtr) |
| 0 | 120 { |
| 79 | 121 yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr; |
| 0 | 122 |
| 123 yaffs_CalcTagsECC(tagsPtr); | |
| 79 | 124 |
| 0 | 125 sparePtr->tagByte0 = tu->asBytes[0]; |
| 126 sparePtr->tagByte1 = tu->asBytes[1]; | |
| 127 sparePtr->tagByte2 = tu->asBytes[2]; | |
| 128 sparePtr->tagByte3 = tu->asBytes[3]; | |
| 129 sparePtr->tagByte4 = tu->asBytes[4]; | |
| 130 sparePtr->tagByte5 = tu->asBytes[5]; | |
| 131 sparePtr->tagByte6 = tu->asBytes[6]; | |
| 132 sparePtr->tagByte7 = tu->asBytes[7]; | |
| 133 } | |
| 134 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
135 static void yaffs_GetTagsFromSpare(yaffs_Device *dev, yaffs_Spare *sparePtr, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
136 yaffs_Tags *tagsPtr) |
| 0 | 137 { |
| 79 | 138 yaffs_TagsUnion *tu = (yaffs_TagsUnion *) tagsPtr; |
| 0 | 139 int result; |
| 140 | |
| 79 | 141 tu->asBytes[0] = sparePtr->tagByte0; |
| 142 tu->asBytes[1] = sparePtr->tagByte1; | |
| 143 tu->asBytes[2] = sparePtr->tagByte2; | |
| 144 tu->asBytes[3] = sparePtr->tagByte3; | |
| 145 tu->asBytes[4] = sparePtr->tagByte4; | |
| 146 tu->asBytes[5] = sparePtr->tagByte5; | |
| 147 tu->asBytes[6] = sparePtr->tagByte6; | |
| 148 tu->asBytes[7] = sparePtr->tagByte7; | |
| 149 | |
| 150 result = yaffs_CheckECCOnTags(tagsPtr); | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
151 if (result > 0) |
| 0 | 152 dev->tagsEccFixed++; |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
153 else if (result < 0) |
| 0 | 154 dev->tagsEccUnfixed++; |
| 155 } | |
| 156 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
157 static void yaffs_SpareInitialise(yaffs_Spare *spare) |
| 0 | 158 { |
| 79 | 159 memset(spare, 0xFF, sizeof(yaffs_Spare)); |
| 0 | 160 } |
| 161 | |
| 79 | 162 static int yaffs_WriteChunkToNAND(struct yaffs_DeviceStruct *dev, |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
163 int chunkInNAND, const __u8 *data, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
164 yaffs_Spare *spare) |
| 0 | 165 { |
| 79 | 166 if (chunkInNAND < dev->startBlock * dev->nChunksPerBlock) { |
| 167 T(YAFFS_TRACE_ERROR, | |
| 168 (TSTR("**>> yaffs chunk %d is not valid" TENDSTR), | |
| 169 chunkInNAND)); | |
| 0 | 170 return YAFFS_FAIL; |
| 171 } | |
| 172 | |
| 79 | 173 return dev->writeChunkToNAND(dev, chunkInNAND, data, spare); |
| 0 | 174 } |
| 175 | |
| 176 static int yaffs_ReadChunkFromNAND(struct yaffs_DeviceStruct *dev, | |
| 79 | 177 int chunkInNAND, |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
178 __u8 *data, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
179 yaffs_Spare *spare, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
180 yaffs_ECCResult *eccResult, |
| 79 | 181 int doErrorCorrection) |
| 0 | 182 { |
| 183 int retVal; | |
| 184 yaffs_Spare localSpare; | |
| 185 | |
| 79 | 186 if (!spare && data) { |
| 187 /* If we don't have a real spare, then we use a local one. */ | |
| 188 /* Need this for the calculation of the ecc */ | |
| 0 | 189 spare = &localSpare; |
| 190 } | |
| 79 | 191 |
| 192 if (!dev->useNANDECC) { | |
| 193 retVal = dev->readChunkFromNAND(dev, chunkInNAND, data, spare); | |
| 194 if (data && doErrorCorrection) { | |
| 195 /* Do ECC correction */ | |
| 196 /* Todo handle any errors */ | |
| 197 int eccResult1, eccResult2; | |
| 198 __u8 calcEcc[3]; | |
| 0 | 199 |
| 79 | 200 yaffs_ECCCalculate(data, calcEcc); |
| 201 eccResult1 = | |
| 202 yaffs_ECCCorrect(data, spare->ecc1, calcEcc); | |
| 203 yaffs_ECCCalculate(&data[256], calcEcc); | |
| 204 eccResult2 = | |
| 205 yaffs_ECCCorrect(&data[256], spare->ecc2, calcEcc); | |
| 0 | 206 |
| 79 | 207 if (eccResult1 > 0) { |
| 208 T(YAFFS_TRACE_ERROR, | |
| 209 (TSTR | |
| 89 | 210 ("**>>yaffs ecc error fix performed on chunk %d:0" |
| 79 | 211 TENDSTR), chunkInNAND)); |
| 0 | 212 dev->eccFixed++; |
| 79 | 213 } else if (eccResult1 < 0) { |
| 214 T(YAFFS_TRACE_ERROR, | |
| 215 (TSTR | |
| 89 | 216 ("**>>yaffs ecc error unfixed on chunk %d:0" |
| 79 | 217 TENDSTR), chunkInNAND)); |
| 0 | 218 dev->eccUnfixed++; |
| 219 } | |
| 220 | |
| 79 | 221 if (eccResult2 > 0) { |
| 222 T(YAFFS_TRACE_ERROR, | |
| 223 (TSTR | |
| 89 | 224 ("**>>yaffs ecc error fix performed on chunk %d:1" |
| 79 | 225 TENDSTR), chunkInNAND)); |
| 0 | 226 dev->eccFixed++; |
| 79 | 227 } else if (eccResult2 < 0) { |
| 228 T(YAFFS_TRACE_ERROR, | |
| 229 (TSTR | |
| 89 | 230 ("**>>yaffs ecc error unfixed on chunk %d:1" |
| 79 | 231 TENDSTR), chunkInNAND)); |
| 0 | 232 dev->eccUnfixed++; |
| 233 } | |
| 234 | |
| 79 | 235 if (eccResult1 || eccResult2) { |
| 236 /* We had a data problem on this page */ | |
| 237 yaffs_HandleReadDataError(dev, chunkInNAND); | |
| 0 | 238 } |
| 79 | 239 |
| 240 if (eccResult1 < 0 || eccResult2 < 0) | |
| 0 | 241 *eccResult = YAFFS_ECC_RESULT_UNFIXED; |
| 79 | 242 else if (eccResult1 > 0 || eccResult2 > 0) |
| 0 | 243 *eccResult = YAFFS_ECC_RESULT_FIXED; |
| 244 else | |
| 245 *eccResult = YAFFS_ECC_RESULT_NO_ERROR; | |
| 246 } | |
| 79 | 247 } else { |
| 248 /* Must allocate enough memory for spare+2*sizeof(int) */ | |
| 249 /* for ecc results from device. */ | |
| 250 struct yaffs_NANDSpare nspare; | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
251 |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
252 memset(&nspare, 0, sizeof(nspare)); |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
253 |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
254 retVal = dev->readChunkFromNAND(dev, chunkInNAND, data, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
255 (yaffs_Spare *) &nspare); |
| 79 | 256 memcpy(spare, &nspare, sizeof(yaffs_Spare)); |
| 257 if (data && doErrorCorrection) { | |
| 258 if (nspare.eccres1 > 0) { | |
| 259 T(YAFFS_TRACE_ERROR, | |
| 260 (TSTR | |
| 89 | 261 ("**>>mtd ecc error fix performed on chunk %d:0" |
| 79 | 262 TENDSTR), chunkInNAND)); |
| 263 } else if (nspare.eccres1 < 0) { | |
| 264 T(YAFFS_TRACE_ERROR, | |
| 265 (TSTR | |
| 89 | 266 ("**>>mtd ecc error unfixed on chunk %d:0" |
| 79 | 267 TENDSTR), chunkInNAND)); |
| 0 | 268 } |
| 269 | |
| 79 | 270 if (nspare.eccres2 > 0) { |
| 271 T(YAFFS_TRACE_ERROR, | |
| 272 (TSTR | |
| 89 | 273 ("**>>mtd ecc error fix performed on chunk %d:1" |
| 79 | 274 TENDSTR), chunkInNAND)); |
| 275 } else if (nspare.eccres2 < 0) { | |
| 276 T(YAFFS_TRACE_ERROR, | |
| 277 (TSTR | |
| 89 | 278 ("**>>mtd ecc error unfixed on chunk %d:1" |
| 79 | 279 TENDSTR), chunkInNAND)); |
| 0 | 280 } |
| 281 | |
| 79 | 282 if (nspare.eccres1 || nspare.eccres2) { |
| 283 /* We had a data problem on this page */ | |
| 284 yaffs_HandleReadDataError(dev, chunkInNAND); | |
| 0 | 285 } |
| 79 | 286 |
| 287 if (nspare.eccres1 < 0 || nspare.eccres2 < 0) | |
| 0 | 288 *eccResult = YAFFS_ECC_RESULT_UNFIXED; |
| 79 | 289 else if (nspare.eccres1 > 0 || nspare.eccres2 > 0) |
| 0 | 290 *eccResult = YAFFS_ECC_RESULT_FIXED; |
| 291 else | |
| 292 *eccResult = YAFFS_ECC_RESULT_NO_ERROR; | |
| 293 | |
| 294 } | |
| 295 } | |
| 296 return retVal; | |
| 297 } | |
| 298 | |
|
47
216765645976
If kernel/config.h is included in yportenv.h, then yportenv.h must be
marty
parents:
10
diff
changeset
|
299 #ifdef NOTYET |
| 79 | 300 static int yaffs_CheckChunkErased(struct yaffs_DeviceStruct *dev, |
| 301 int chunkInNAND) | |
| 0 | 302 { |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
303 static int init; |
| 0 | 304 static __u8 cmpbuf[YAFFS_BYTES_PER_CHUNK]; |
| 305 static __u8 data[YAFFS_BYTES_PER_CHUNK]; | |
| 79 | 306 /* Might as well always allocate the larger size for */ |
| 307 /* dev->useNANDECC == true; */ | |
| 0 | 308 static __u8 spare[sizeof(struct yaffs_NANDSpare)]; |
| 309 | |
| 79 | 310 dev->readChunkFromNAND(dev, chunkInNAND, data, (yaffs_Spare *) spare); |
| 0 | 311 |
| 79 | 312 if (!init) { |
| 313 memset(cmpbuf, 0xff, YAFFS_BYTES_PER_CHUNK); | |
| 0 | 314 init = 1; |
| 315 } | |
| 316 | |
| 79 | 317 if (memcmp(cmpbuf, data, YAFFS_BYTES_PER_CHUNK)) |
| 318 return YAFFS_FAIL; | |
| 319 if (memcmp(cmpbuf, spare, 16)) | |
| 320 return YAFFS_FAIL; | |
| 0 | 321 |
| 322 return YAFFS_OK; | |
| 323 | |
| 324 } | |
|
47
216765645976
If kernel/config.h is included in yportenv.h, then yportenv.h must be
marty
parents:
10
diff
changeset
|
325 #endif |
| 0 | 326 |
| 79 | 327 /* |
| 328 * Functions for robustisizing | |
| 329 */ | |
| 0 | 330 |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
331 static void yaffs_HandleReadDataError(yaffs_Device *dev, int chunkInNAND) |
| 0 | 332 { |
| 79 | 333 int blockInNAND = chunkInNAND / dev->nChunksPerBlock; |
| 0 | 334 |
| 79 | 335 /* Mark the block for retirement */ |
| 215 | 336 yaffs_GetBlockInfo(dev, blockInNAND + dev->blockOffset)->needsRetiring = 1; |
| 79 | 337 T(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS, |
| 338 (TSTR("**>>Block %d marked for retirement" TENDSTR), blockInNAND)); | |
| 0 | 339 |
| 79 | 340 /* TODO: |
| 341 * Just do a garbage collection on the affected block | |
| 342 * then retire the block | |
| 343 * NB recursion | |
| 344 */ | |
| 0 | 345 } |
| 346 | |
|
47
216765645976
If kernel/config.h is included in yportenv.h, then yportenv.h must be
marty
parents:
10
diff
changeset
|
347 #ifdef NOTYET |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
348 static void yaffs_CheckWrittenBlock(yaffs_Device *dev, int chunkInNAND) |
| 0 | 349 { |
| 350 } | |
| 351 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
352 static void yaffs_HandleWriteChunkOk(yaffs_Device *dev, int chunkInNAND, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
353 const __u8 *data, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
354 const yaffs_Spare *spare) |
| 0 | 355 { |
| 356 } | |
| 357 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
358 static void yaffs_HandleUpdateChunk(yaffs_Device *dev, int chunkInNAND, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
359 const yaffs_Spare *spare) |
| 0 | 360 { |
| 361 } | |
| 362 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
363 static void yaffs_HandleWriteChunkError(yaffs_Device *dev, int chunkInNAND) |
| 0 | 364 { |
| 79 | 365 int blockInNAND = chunkInNAND / dev->nChunksPerBlock; |
| 0 | 366 |
| 79 | 367 /* Mark the block for retirement */ |
| 368 yaffs_GetBlockInfo(dev, blockInNAND)->needsRetiring = 1; | |
| 369 /* Delete the chunk */ | |
| 370 yaffs_DeleteChunk(dev, chunkInNAND, 1, __LINE__); | |
| 0 | 371 } |
| 372 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
373 static int yaffs_VerifyCompare(const __u8 *d0, const __u8 *d1, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
374 const yaffs_Spare *s0, const yaffs_Spare *s1) |
| 0 | 375 { |
| 376 | |
| 79 | 377 if (memcmp(d0, d1, YAFFS_BYTES_PER_CHUNK) != 0 || |
| 378 s0->tagByte0 != s1->tagByte0 || | |
| 379 s0->tagByte1 != s1->tagByte1 || | |
| 380 s0->tagByte2 != s1->tagByte2 || | |
| 381 s0->tagByte3 != s1->tagByte3 || | |
| 382 s0->tagByte4 != s1->tagByte4 || | |
| 383 s0->tagByte5 != s1->tagByte5 || | |
| 384 s0->tagByte6 != s1->tagByte6 || | |
| 385 s0->tagByte7 != s1->tagByte7 || | |
| 386 s0->ecc1[0] != s1->ecc1[0] || | |
| 387 s0->ecc1[1] != s1->ecc1[1] || | |
| 388 s0->ecc1[2] != s1->ecc1[2] || | |
| 389 s0->ecc2[0] != s1->ecc2[0] || | |
| 390 s0->ecc2[1] != s1->ecc2[1] || s0->ecc2[2] != s1->ecc2[2]) { | |
| 391 return 0; | |
| 392 } | |
| 0 | 393 |
| 394 return 1; | |
| 395 } | |
| 79 | 396 #endif /* NOTYET */ |
| 0 | 397 |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
398 int yaffs_TagsCompatabilityWriteChunkWithTagsToNAND(yaffs_Device *dev, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
399 int chunkInNAND, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
400 const __u8 *data, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
401 const yaffs_ExtendedTags *eTags) |
| 0 | 402 { |
| 403 yaffs_Spare spare; | |
| 79 | 404 yaffs_Tags tags; |
| 405 | |
| 0 | 406 yaffs_SpareInitialise(&spare); |
| 79 | 407 |
| 285 | 408 if (eTags->chunkDeleted) |
| 0 | 409 spare.pageStatus = 0; |
| 285 | 410 else { |
| 0 | 411 tags.objectId = eTags->objectId; |
| 412 tags.chunkId = eTags->chunkId; | |
| 231 | 413 |
| 414 tags.byteCountLSB = eTags->byteCount & 0x3ff; | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
415 |
| 285 | 416 if (dev->nDataBytesPerChunk >= 1024) |
| 231 | 417 tags.byteCountMSB = (eTags->byteCount >> 10) & 3; |
| 285 | 418 else |
| 231 | 419 tags.byteCountMSB = 3; |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
420 |
| 231 | 421 |
| 0 | 422 tags.serialNumber = eTags->serialNumber; |
| 10 | 423 |
| 285 | 424 if (!dev->useNANDECC && data) |
| 79 | 425 yaffs_CalcECC(data, &spare); |
| 285 | 426 |
| 79 | 427 yaffs_LoadTagsIntoSpare(&spare, &tags); |
| 428 | |
| 0 | 429 } |
| 79 | 430 |
| 431 return yaffs_WriteChunkToNAND(dev, chunkInNAND, data, &spare); | |
| 0 | 432 } |
| 433 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
434 int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device *dev, |
| 79 | 435 int chunkInNAND, |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
436 __u8 *data, |
|
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
437 yaffs_ExtendedTags *eTags) |
| 0 | 438 { |
| 439 | |
| 440 yaffs_Spare spare; | |
| 441 yaffs_Tags tags; | |
| 221 | 442 yaffs_ECCResult eccResult = YAFFS_ECC_RESULT_UNKNOWN; |
| 79 | 443 |
| 444 static yaffs_Spare spareFF; | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
445 static int init; |
| 79 | 446 |
| 447 if (!init) { | |
| 448 memset(&spareFF, 0xFF, sizeof(spareFF)); | |
| 449 init = 1; | |
| 450 } | |
| 451 | |
| 452 if (yaffs_ReadChunkFromNAND | |
| 453 (dev, chunkInNAND, data, &spare, &eccResult, 1)) { | |
| 454 /* eTags may be NULL */ | |
| 10 | 455 if (eTags) { |
| 456 | |
| 79 | 457 int deleted = |
| 458 (yaffs_CountBits(spare.pageStatus) < 7) ? 1 : 0; | |
| 459 | |
| 460 eTags->chunkDeleted = deleted; | |
| 461 eTags->eccResult = eccResult; | |
| 462 eTags->blockBad = 0; /* We're reading it */ | |
| 463 /* therefore it is not a bad block */ | |
| 464 eTags->chunkUsed = | |
| 465 (memcmp(&spareFF, &spare, sizeof(spareFF)) != | |
| 466 0) ? 1 : 0; | |
|
103
154a27183762
Subject: [Yaffs] Avoid tagsEccUnfixed stats bump on mounting partially usedblock
marty
parents:
89
diff
changeset
|
467 |
|
154a27183762
Subject: [Yaffs] Avoid tagsEccUnfixed stats bump on mounting partially usedblock
marty
parents:
89
diff
changeset
|
468 if (eTags->chunkUsed) { |
|
154a27183762
Subject: [Yaffs] Avoid tagsEccUnfixed stats bump on mounting partially usedblock
marty
parents:
89
diff
changeset
|
469 yaffs_GetTagsFromSpare(dev, &spare, &tags); |
|
154a27183762
Subject: [Yaffs] Avoid tagsEccUnfixed stats bump on mounting partially usedblock
marty
parents:
89
diff
changeset
|
470 |
|
154a27183762
Subject: [Yaffs] Avoid tagsEccUnfixed stats bump on mounting partially usedblock
marty
parents:
89
diff
changeset
|
471 eTags->objectId = tags.objectId; |
|
154a27183762
Subject: [Yaffs] Avoid tagsEccUnfixed stats bump on mounting partially usedblock
marty
parents:
89
diff
changeset
|
472 eTags->chunkId = tags.chunkId; |
| 231 | 473 eTags->byteCount = tags.byteCountLSB; |
| 474 | |
|
282
c8620405d086
Major whitespace/style changes to match Linux checkpatch.pl code style
wookey
parents:
231
diff
changeset
|
475 if (dev->nDataBytesPerChunk >= 1024) |
| 231 | 476 eTags->byteCount |= (((unsigned) tags.byteCountMSB) << 10); |
| 477 | |
|
103
154a27183762
Subject: [Yaffs] Avoid tagsEccUnfixed stats bump on mounting partially usedblock
marty
parents:
89
diff
changeset
|
478 eTags->serialNumber = tags.serialNumber; |
|
154a27183762
Subject: [Yaffs] Avoid tagsEccUnfixed stats bump on mounting partially usedblock
marty
parents:
89
diff
changeset
|
479 } |
| 10 | 480 } |
| 79 | 481 |
| 482 return YAFFS_OK; | |
| 483 } else { | |
| 0 | 484 return YAFFS_FAIL; |
| 485 } | |
| 486 } | |
| 487 | |
| 79 | 488 int yaffs_TagsCompatabilityMarkNANDBlockBad(struct yaffs_DeviceStruct *dev, |
| 489 int blockInNAND) | |
| 0 | 490 { |
| 491 | |
| 492 yaffs_Spare spare; | |
| 493 | |
| 79 | 494 memset(&spare, 0xff, sizeof(yaffs_Spare)); |
| 0 | 495 |
|
75
fc6de03bdd07
Change bad block marker to Y to identify YAFFS-marked bad blocks
charles
parents:
74
diff
changeset
|
496 spare.blockStatus = 'Y'; |
| 0 | 497 |
| 79 | 498 yaffs_WriteChunkToNAND(dev, blockInNAND * dev->nChunksPerBlock, NULL, |
| 499 &spare); | |
| 500 yaffs_WriteChunkToNAND(dev, blockInNAND * dev->nChunksPerBlock + 1, | |
| 501 NULL, &spare); | |
| 502 | |
| 0 | 503 return YAFFS_OK; |
| 79 | 504 |
| 0 | 505 } |
| 506 | |
| 79 | 507 int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, |
|
211
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
508 int blockNo, |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
509 yaffs_BlockState *state, |
|
fad21fd1971d
Check in inband tags, some extra yaffs direct functions and some other changes
charles
parents:
185
diff
changeset
|
510 __u32 *sequenceNumber) |
| 0 | 511 { |
| 79 | 512 |
| 513 yaffs_Spare spare0, spare1; | |
| 514 static yaffs_Spare spareFF; | |
| 515 static int init; | |
| 516 yaffs_ECCResult dummy; | |
| 517 | |
| 518 if (!init) { | |
| 519 memset(&spareFF, 0xFF, sizeof(spareFF)); | |
| 520 init = 1; | |
| 521 } | |
| 522 | |
| 523 *sequenceNumber = 0; | |
| 0 | 524 |
| 79 | 525 yaffs_ReadChunkFromNAND(dev, blockNo * dev->nChunksPerBlock, NULL, |
| 526 &spare0, &dummy, 1); | |
| 527 yaffs_ReadChunkFromNAND(dev, blockNo * dev->nChunksPerBlock + 1, NULL, | |
| 528 &spare1, &dummy, 1); | |
| 529 | |
| 530 if (yaffs_CountBits(spare0.blockStatus & spare1.blockStatus) < 7) | |
| 531 *state = YAFFS_BLOCK_STATE_DEAD; | |
| 532 else if (memcmp(&spareFF, &spare0, sizeof(spareFF)) == 0) | |
| 533 *state = YAFFS_BLOCK_STATE_EMPTY; | |
| 534 else | |
| 535 *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; | |
| 536 | |
| 537 return YAFFS_OK; | |
| 0 | 538 } |
