*/
//yaffs_guts.c
-const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.24 2003-04-03 17:58:56 charles Exp $";
+const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.25 2003-05-20 22:30:35 charles Exp $";
#include "yportenv.h"
#include "yaffsinterface.h"
#include "yaffs_guts.h"
-
-
-
#define YAFFS_PASSIVE_GC_CHUNKS 2
+#if 0
+// Use Steven Hill's ECC struff instead
// External functions for ECC on data
void nand_calculate_ecc (const u_char *dat, u_char *ecc_code);
int nand_correct_data (u_char *dat, u_char *read_ecc, u_char *calc_ecc);
-
+#define yaffs_ECCCalculate(data,ecc) nand_calculate_ecc(data,ecc)
+#define yaffs_ECCCorrect(data,read_ecc,calc_ecc) nand_correct_ecc(data,read_ecc,calc_ecc)
+#else
+#include "yaffs_ecc.h"
+#endif
// countBits is a quick way of counting the number of bits in a byte.
// ie. countBits[n] holds the number of 1 bits in a byte with the value n.
int eccResult1,eccResult2;
__u8 calcEcc[3];
- nand_calculate_ecc(data,calcEcc);
- eccResult1 = nand_correct_data (data,spare->ecc1, calcEcc);
- nand_calculate_ecc(&data[256],calcEcc);
- eccResult2 = nand_correct_data (&data[256],spare->ecc2, calcEcc);
+ yaffs_ECCCalculate(data,calcEcc);
+ eccResult1 = yaffs_ECCCorrect (data,spare->ecc1, calcEcc);
+ yaffs_ECCCalculate(&data[256],calcEcc);
+ eccResult2 = yaffs_ECCCorrect(&data[256],spare->ecc2, calcEcc);
if(eccResult1>0)
{
void yaffs_CalcECC(const __u8 *data, yaffs_Spare *spare)
{
- nand_calculate_ecc (data , spare->ecc1);
- nand_calculate_ecc (&data[256] , spare->ecc2);
+ yaffs_ECCCalculate(data , spare->ecc1);
+ yaffs_ECCCalculate(&data[256] , spare->ecc2);
}
void yaffs_CalcTagsECC(yaffs_Tags *tags)
// using yaffs_DeleteChunk
chunkId = yaffs_FindAndDeleteChunkInFile(in,i,NULL);
- if(chunkId <= 0 || chunkId >= (dev->endBlock * 32))
+ if(chunkId < (dev->startBlock * 32) || chunkId >= ((dev->endBlock+1) * 32))
{
//T(("Found daft chunkId %d for %d\n",chunkId,i));
}
int nFree;
int pending;
int b;
+ int nDirtyCacheChunks=0;
yaffs_BlockInfo *blk;
nFree += pending;
+ // Now count the number of dirty chunks in the cache and subtract those
+
+ {
+ int i;
+ for(i = 0; i < dev->nShortOpCaches; i++)
+ {
+ if(dev->srCache[i].dirty) nDirtyCacheChunks++;
+ }
+ }
+
+ nFree -= nDirtyCacheChunks;
+
+ nFree -= ((dev->nReservedBlocks + 1) * dev->nChunksPerBlock);
+
if(nFree < 0) nFree = 0;
return nFree;