yaffs First round of name changes
[yaffs2.git] / yaffs_mtdif1.c
index 990e0fb7673801a3fd439f27163b118b9db5100c..70876bc34bb3283226b314ef50510871237ec791 100644 (file)
@@ -2,7 +2,7 @@
  * 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
@@ -27,7 +27,8 @@
 #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"
@@ -37,8 +38,6 @@
 /* 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
@@ -92,7 +91,7 @@ static struct nand_ecclayout nand_oob_16 = {
 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;
@@ -104,7 +103,7 @@ int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev,
        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
@@ -136,9 +135,9 @@ int nandmtd1_WriteChunkWithTagsToNAND(yaffs_Device *dev,
 
        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;
 }
@@ -170,7 +169,7 @@ static int rettags(yaffs_ExtendedTags *etags, int eccResult, int retval)
 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;
@@ -197,9 +196,9 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
         */
        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) {
@@ -225,7 +224,7 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
 
        /* 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);
        }
@@ -238,12 +237,12 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
        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 */
@@ -261,10 +260,10 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
        }
 
        /* 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 */
@@ -281,11 +280,11 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
  */
 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;
@@ -302,9 +301,9 @@ static int nandmtd1_TestPrerequists(struct mtd_info *mtd)
        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;
@@ -322,8 +321,8 @@ static int nandmtd1_TestPrerequists(struct mtd_info *mtd)
 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;
@@ -339,8 +338,8 @@ int nandmtd1_QueryNANDBlock(struct yaffs_DeviceStruct *dev, int blockNo,
        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 */