* YAFFS: Yet another FFS. A NAND-flash specific file system.
* yaffs_mtdif1.c NAND mtd interface functions for small-page NAND.
*
- * Copyright (C) 2002 Aleph One Ltd.
+ * Copyright (C) 2002-2010 Aleph One Ltd.
* for Toby Churchill Ltd and Brightstar Engineering
*
* This program is free software; you can redistribute it and/or modify
#include "yaffs_trace.h"
#include "yaffs_guts.h"
#include "yaffs_packedtags1.h"
-#include "yaffs_tagscompat.h" /* for yaffs_CalcTagsECC */
+#include "yaffs_tagscompat.h" /* for yaffs_calc_tags_ecc */
+#include "yaffs_linux.h"
#include "linux/kernel.h"
#include "linux/version.h"
/* Don't compile this module if we don't have MTD's mtd_oob_ops interface */
#if (MTD_VERSION_CODE > MTD_VERSION(2, 6, 17))
-const char *yaffs_mtdif1_c_version = "$Id: yaffs_mtdif1.c,v 1.12 2010-01-11 04:06:46 charles Exp $";
-
#ifndef CONFIG_YAFFS_9BYTE_TAGS
# define YTAG1_SIZE 8
#else
int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev,
int chunkInNAND, const __u8 *data, const yaffs_ExtendedTags *etags)
{
- struct mtd_info *mtd = dev->genericDevice;
+ struct mtd_info *mtd = yaffs_dev_to_mtd(dev);
int chunkBytes = dev->nDataBytesPerChunk;
loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
struct mtd_oob_ops ops;
compile_time_assertion(sizeof(yaffs_Tags) == 8);
yaffs_PackTags1(&pt1, etags);
- yaffs_CalcTagsECC((yaffs_Tags *)&pt1);
+ yaffs_calc_tags_ecc((yaffs_Tags *)&pt1);
/* When deleting a chunk, the upper layer provides only skeletal
* etags, one with chunkDeleted set. However, we need to update the
retval = mtd->write_oob(mtd, addr, &ops);
if (retval) {
- yaffs_trace(YAFFS_TRACE_MTD,
- "write_oob failed, chunk %d, mtd error %d\n",
- chunkInNAND, retval);
+ T(YAFFS_TRACE_MTD,
+ (TSTR("write_oob failed, chunk %d, mtd error %d"TENDSTR),
+ chunkInNAND, retval));
}
return retval ? YAFFS_FAIL : YAFFS_OK;
}
int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
int chunkInNAND, __u8 *data, yaffs_ExtendedTags *etags)
{
- struct mtd_info *mtd = dev->genericDevice;
+ struct mtd_info *mtd = yaffs_dev_to_mtd(dev);
int chunkBytes = dev->nDataBytesPerChunk;
loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
int eccres = YAFFS_ECC_RESULT_NO_ERROR;
*/
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);
+ T(YAFFS_TRACE_MTD,
+ (TSTR("read_oob failed, chunk %d, mtd error %d"TENDSTR),
+ chunkInNAND, retval));
}
switch (retval) {
/* Check for a blank/erased chunk.
*/
- if (yaffs_CheckFF((__u8 *)&pt1, 8)) {
+ if (yaffs_check_ff((__u8 *)&pt1, 8)) {
/* when blank, upper layers want eccResult to be <= NO_ERROR */
return rettags(etags, YAFFS_ECC_RESULT_NO_ERROR, YAFFS_OK);
}
deleted = !pt1.deleted;
pt1.deleted = 1;
#else
- deleted = (yaffs_CountBits(((__u8 *)&pt1)[8]) < 7);
+ deleted = (yaffs_count_bits(((__u8 *)&pt1)[8]) < 7);
#endif
/* Check the packed tags mini-ECC and correct if necessary/possible.
*/
- retval = yaffs_CheckECCOnTags((yaffs_Tags *)&pt1);
+ retval = yaffs_check_tags_ecc((yaffs_Tags *)&pt1);
switch (retval) {
case 0:
/* no tags error, use MTD result */
}
/* Unpack the tags to extended form and set ECC result.
- * [set shouldBeFF just to keep yaffs_UnpackTags1 happy]
+ * [set shouldBeFF just to keep yaffs_unpack_tags1 happy]
*/
pt1.shouldBeFF = 0xFFFFFFFF;
- yaffs_UnpackTags1(etags, &pt1);
+ yaffs_unpack_tags1(etags, &pt1);
etags->eccResult = eccres;
/* Set deleted state */
*/
int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo)
{
- struct mtd_info *mtd = dev->genericDevice;
- int blocksize = dev->nChunksPerBlock * dev->nDataBytesPerChunk;
+ struct mtd_info *mtd = yaffs_dev_to_mtd(dev);
+ int blocksize = dev->param.nChunksPerBlock * dev->nDataBytesPerChunk;
int retval;
- yaffs_trace(YAFFS_TRACE_BAD_BLOCKS, "marking block %d bad\n", blockNo);
+ T(YAFFS_TRACE_BAD_BLOCKS,(TSTR("marking block %d bad"TENDSTR), blockNo));
retval = mtd->block_markbad(mtd, (loff_t)blocksize * blockNo);
return (retval) ? YAFFS_FAIL : YAFFS_OK;
int oobavail = mtd->ecclayout->oobavail;
if (oobavail < YTAG1_SIZE) {
- yaffs_trace(YAFFS_TRACE_ERROR,
- "mtd device has only %d bytes for tags, need %d\n",
- oobavail, YTAG1_SIZE);
+ T(YAFFS_TRACE_ERROR,
+ (TSTR("mtd device has only %d bytes for tags, need %d"TENDSTR),
+ oobavail, YTAG1_SIZE));
return YAFFS_FAIL;
}
return YAFFS_OK;
int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
yaffs_BlockState *pState, __u32 *pSequenceNumber)
{
- struct mtd_info *mtd = dev->genericDevice;
- int chunkNo = blockNo * dev->nChunksPerBlock;
+ struct mtd_info *mtd = yaffs_dev_to_mtd(dev);
+ int chunkNo = blockNo * dev->param.nChunksPerBlock;
loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk;
yaffs_ExtendedTags etags;
int state = YAFFS_BLOCK_STATE_DEAD;
retval = nandmtd1_ReadChunkWithTagsFromNAND(dev, chunkNo, NULL, &etags);
etags.blockBad = (mtd->block_isbad)(mtd, addr);
if (etags.blockBad) {
- yaffs_trace(YAFFS_TRACE_BAD_BLOCKS,
- "block %d is marked bad\n", blockNo);
+ T(YAFFS_TRACE_BAD_BLOCKS,
+ (TSTR("block %d is marked bad"TENDSTR), blockNo));
state = YAFFS_BLOCK_STATE_DEAD;
} else if (etags.eccResult != YAFFS_ECC_RESULT_NO_ERROR) {
/* bad tags, need to look more closely */