int yaffs_TagsCompatabilityQueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_BlockState * state, int *sequenceNumber) { yaffs_Spare spare0, spare1; static yaffs_Spare spareFF; static int init; yaffs_ECCResult dummy; if (!init) { memset(&spareFF, 0xFF, sizeof(spareFF)); init = 1; } *sequenceNumber = 0; yaffs_ReadChunkFromNAND(dev, blockNo * dev->nChunksPerBlock, NULL, &spare0, &dummy, 1); yaffs_ReadChunkFromNAND(dev, blockNo * dev->nChunksPerBlock + 1, NULL, &spare1, &dummy, 1); if (yaffs_CountBits(spare0.blockStatus & spare1.blockStatus) < 7) *state = YAFFS_BLOCK_STATE_DEAD; else if (memcmp(&spareFF, &spare0, sizeof(spareFF)) == 0) *state = YAFFS_BLOCK_STATE_EMPTY; else *state = YAFFS_BLOCK_STATE_NEEDS_SCANNING; return YAFFS_OK; }
int yaffs_TagsCompatabilityReadChunkWithTagsFromNAND(yaffs_Device * dev, int chunkInNAND, __u8 * data, yaffs_ExtendedTags * eTags) { #ifdef DEBUG_YAFFS2 printk("yaffs_TagsCompatabilityReadChunkWithTagsFromNAND\n"); #endif yaffs_Spare spare; yaffs_Tags tags; yaffs_ECCResult eccResult; static yaffs_Spare spareFF; static int init; if (!init) { memset(&spareFF, 0xFF, sizeof(spareFF)); init = 1; } if (yaffs_ReadChunkFromNAND (dev, chunkInNAND, data, &spare, &eccResult, 1)) { /* eTags may be NULL */ if (eTags) { int deleted = (yaffs_CountBits(spare.pageStatus) < 7) ? 1 : 0; eTags->chunkDeleted = deleted; eTags->eccResult = eccResult; eTags->blockBad = 0; /* We're reading it */ /* therefore it is not a bad block */ eTags->chunkUsed = (memcmp(&spareFF, &spare, sizeof(spareFF)) != 0) ? 1 : 0; if (eTags->chunkUsed) { yaffs_GetTagsFromSpare(dev, &spare, &tags); eTags->objectId = tags.objectId; eTags->chunkId = tags.chunkId; eTags->byteCount = tags.byteCount; eTags->serialNumber = tags.serialNumber; } } return YAFFS_OK; } else { return YAFFS_FAIL; } }
/* Read a chunk (page) from NAND. * * Caller expects ExtendedTags data to be usable even on error; that is, * all members except eccResult and blockBad are zeroed. * * - Check ECC results for data (if applicable) * - Check for blank/erased block (return empty ExtendedTags if blank) * - Check the PackedTags1 mini-ECC (correct if necessary/possible) * - Convert PackedTags1 to ExtendedTags * - Update eccResult and blockBad members to refect state. * * Returns YAFFS_OK or YAFFS_FAIL. */ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 * data, yaffs_ExtendedTags * etags) { struct mtd_info * mtd = dev->genericDevice; int chunkBytes = dev->nDataBytesPerChunk; loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; int eccres = YAFFS_ECC_RESULT_NO_ERROR; struct mtd_oob_ops ops; yaffs_PackedTags1 pt1; int retval; int deleted; dev->nPageReads++; memset(&ops, 0, sizeof(ops)); ops.mode = MTD_OOB_AUTO; ops.len = (data) ? chunkBytes : 0; ops.ooblen = YTAG1_SIZE; ops.datbuf = data; ops.oobbuf = (__u8 *)&pt1; #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,20)) /* In MTD 2.6.18 to 2.6.19 nand_base.c:nand_do_read_oob() has a bug; * help it out with ops.len = ops.ooblen when ops.datbuf == NULL. */ ops.len = (ops.datbuf) ? ops.len : ops.ooblen; #endif /* Read page and oob using MTD. * Check status and determine ECC result. */ retval = mtd->read_oob(mtd, addr, &ops); if (retval) { yaffs_trace(YAFFS_TRACE_MTD, "read_oob failed, chunk %d, mtd error %d\n", chunkInNAND, retval); } switch (retval) { case 0: /* no error */ break; case -EUCLEAN: /* MTD's ECC fixed the data */ eccres = YAFFS_ECC_RESULT_FIXED; dev->eccFixed++; break; case -EBADMSG: /* MTD's ECC could not fix the data */ dev->eccUnfixed++; /* fall into... */ default: rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); etags->blockBad = (mtd->block_isbad)(mtd, addr); return YAFFS_FAIL; } /* Check for a blank/erased chunk. */ if (yaffs_CheckFF((__u8 *)&pt1, 8)) { /* when blank, upper layers want eccResult to be <= NO_ERROR */ return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); } #ifndef CONFIG_YAFFS_9BYTE_TAGS /* Read deleted status (bit) then return it to it's non-deleted * state before performing tags mini-ECC check. pt1.deleted is * inverted. */ deleted = !pt1.deleted; pt1.deleted = 1; #else deleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); #endif /* Check the packed tags mini-ECC and correct if necessary/possible. */ retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); switch (retval) { case 0: /* no tags error, use MTD result */ break; case 1: /* recovered tags-ECC error */ dev->tagsEccFixed++; if (eccres == YAFFS_ECC_RESULT_NO_ERROR) eccres = YAFFS_ECC_RESULT_FIXED; break; default: /* unrecovered tags-ECC error */ dev->tagsEccUnfixed++; return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL); } /* Unpack the tags to extended form and set ECC result. * [set shouldBeFF just to keep yaffs_UnpackTags1 happy] */ pt1.shouldBeFF = 0xFFFFFFFF; yaffs_UnpackTags1(etags, &pt1); etags->eccResult = eccres; /* Set deleted state */ etags->chunkDeleted = deleted; return YAFFS_OK; }
int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev, int chunkInNAND, __u8 *data, yaffs_ExtendedTags *etags) { struct mtd_info *mtd = dev->genericDevice; int chunkBytes = dev->nDataBytesPerChunk; loff_t addr = ((loff_t)chunkInNAND) * chunkBytes; int eccres = YAFFS_ECC_RESULT_NO_ERROR; struct mtd_oob_ops ops; yaffs_PackedTags1 pt1; int retval; int deleted; memset(&ops, 0, sizeof(ops)); ops.mode = MTD_OOB_AUTO; ops.len = (data) ? chunkBytes : 0; ops.ooblen = YTAG1_SIZE; ops.datbuf = data; ops.oobbuf = (__u8 *)&pt1; #if (MTD_VERSION_CODE < MTD_VERSION(2, 6, 20)) ops.len = (ops.datbuf) ? ops.len : ops.ooblen; #endif retval = mtd->read_oob(mtd, addr, &ops); if (retval) { yaffs_trace(YAFFS_TRACE_MTD, "read_oob failed, chunk %d, mtd error %d\n", chunkInNAND, retval); } switch (retval) { case 0: break; case -EUCLEAN: eccres = YAFFS_ECC_RESULT_FIXED; dev->eccFixed++; break; case -EBADMSG: dev->eccUnfixed++; default: rettags(etags, YAFFS_ECC_RESULT_UNFIXED, 0); etags->blockBad = (mtd->block_isbad)(mtd, addr); return YAFFS_FAIL; } if (yaffs_CheckFF((__u8 *)&pt1, 8)) { return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK); } #ifndef CONFIG_YAFFS_9BYTE_TAGS deleted = !pt1.deleted; pt1.deleted = 1; #else deleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7); #endif retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1); switch (retval) { case 0: break; case 1: dev->tagsEccFixed++; if (eccres == YAFFS_ECC_RESULT_NO_ERROR) eccres = YAFFS_ECC_RESULT_FIXED; break; default: dev->tagsEccUnfixed++; return rettags(etags, YAFFS_ECC_RESULT_UNFIXED, YAFFS_FAIL); } pt1.shouldBeFF = 0xFFFFFFFF; yaffs_UnpackTags1(etags, &pt1); etags->eccResult = eccres; etags->chunkDeleted = deleted; return YAFFS_OK; }