yaffs Commiting changes to yaffs_importer.py yaffs_browser.py and yaffs_tester.c
[yaffs2.git] / yaffs_mtdif1.c
index 16171e09ba7b9aa9cdf5a9674fea5d279267737d..b14a2549ca6c51b1f7cd3831002b80598837f320 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
@@ -38,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.13 2010-02-18 01:18:04 charles Exp $";
-
 #ifndef CONFIG_YAFFS_9BYTE_TAGS
 # define YTAG1_SIZE 8
 #else
@@ -93,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 = yaffs_DeviceToContext(dev)->mtd;
+       struct mtd_info *mtd = yaffs_DeviceToMtd(dev);
        int chunkBytes = dev->nDataBytesPerChunk;
        loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
        struct mtd_oob_ops ops;
@@ -137,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;
 }
@@ -171,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 = yaffs_DeviceToContext(dev)->mtd;
+       struct mtd_info *mtd = yaffs_DeviceToMtd(dev);
        int chunkBytes = dev->nDataBytesPerChunk;
        loff_t addr = ((loff_t)chunkInNAND) * chunkBytes;
        int eccres = YAFFS_ECC_RESULT_NO_ERROR;
@@ -198,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) {
@@ -282,11 +280,11 @@ int nandmtd1_ReadChunkWithTagsFromNAND(yaffs_Device *dev,
  */
 int nandmtd1_MarkNANDBlockBad(struct yaffs_DeviceStruct *dev, int blockNo)
 {
-       struct mtd_info *mtd = yaffs_DeviceToContext(dev)->mtd;
+       struct mtd_info *mtd = yaffs_DeviceToMtd(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;
@@ -303,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;
@@ -323,7 +321,7 @@ 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 = yaffs_DeviceToContext(dev)->mtd;
+       struct mtd_info *mtd = yaffs_DeviceToMtd(dev);
        int chunkNo = blockNo * dev->param.nChunksPerBlock;
        loff_t addr = (loff_t)chunkNo * dev->nDataBytesPerChunk;
        yaffs_ExtendedTags etags;
@@ -340,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 */