Merge branch 'master' of ssh://www.aleph1.co.uk/home/aleph1/git/yaffs2
[yaffs2.git] / yaffs_guts.c
index ff5c963b4dc9ea86eaa0e81929c6abccba6abd6f..d55aa95b91e450758bf54474e047f7766100515f 100644 (file)
 
 #define YAFFS_SMALL_HOLE_THRESHOLD 3
 
 
 #define YAFFS_SMALL_HOLE_THRESHOLD 3
 
+/*
+ * Checkpoints are really no benefit on very small partitions.
+ *
+ * To save space on small partitions don't bother with checkpoints unless
+ * the partition is at least this big.
+ */
+#define YAFFS_CHECKPOINT_MIN_BLOCKS 60
+
 #include "yaffs_ecc.h"
 
 
 #include "yaffs_ecc.h"
 
 
@@ -71,8 +79,6 @@ static int yaffs_UpdateObjectHeader(yaffs_Object *in, const YCHAR *name,
                                int force, int isShrink, int shadows);
 static void yaffs_RemoveObjectFromDirectory(yaffs_Object *obj);
 static int yaffs_CheckStructures(void);
                                int force, int isShrink, int shadows);
 static void yaffs_RemoveObjectFromDirectory(yaffs_Object *obj);
 static int yaffs_CheckStructures(void);
-static int yaffs_DeleteWorker(yaffs_Object *in, yaffs_Tnode *tn, __u32 level,
-                       int chunkOffset, int *limit);
 static int yaffs_DoGenericObjectDeletion(yaffs_Object *in);
 
 static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device *dev, int blockNo);
 static int yaffs_DoGenericObjectDeletion(yaffs_Object *in);
 
 static yaffs_BlockInfo *yaffs_GetBlockInfo(yaffs_Device *dev, int blockNo);
@@ -607,7 +613,8 @@ static void yaffs_VerifyObjectHeader(yaffs_Object *obj, yaffs_ObjectHeader *oh,
 }
 
 
 }
 
 
-
+#if 0
+/* Not being used, but don't want to throw away yet */
 static int yaffs_VerifyTnodeWorker(yaffs_Object *obj, yaffs_Tnode *tn,
                                        __u32 level, int chunkOffset)
 {
 static int yaffs_VerifyTnodeWorker(yaffs_Object *obj, yaffs_Tnode *tn,
                                        __u32 level, int chunkOffset)
 {
@@ -653,6 +660,7 @@ static int yaffs_VerifyTnodeWorker(yaffs_Object *obj, yaffs_Tnode *tn,
 
 }
 
 
 }
 
+#endif
 
 static void yaffs_VerifyFile(yaffs_Object *obj)
 {
 
 static void yaffs_VerifyFile(yaffs_Object *obj)
 {
@@ -1705,9 +1713,10 @@ static int yaffs_FindChunkInGroup(yaffs_Device *dev, int theChunk,
        return -1;
 }
 
        return -1;
 }
 
-
+#if 0
+/* Experimental code not being used yet. Might speed up file deletion */
 /* DeleteWorker scans backwards through the tnode tree and deletes all the
 /* DeleteWorker scans backwards through the tnode tree and deletes all the
- * chunks and tnodes in the file
+ * chunks and tnodes in the file.
  * Returns 1 if the tree was deleted.
  * Returns 0 if it stopped early due to hitting the limit and the delete is incomplete.
  */
  * Returns 1 if the tree was deleted.
  * Returns 0 if it stopped early due to hitting the limit and the delete is incomplete.
  */
@@ -1799,6 +1808,8 @@ static int yaffs_DeleteWorker(yaffs_Object *in, yaffs_Tnode *tn, __u32 level,
 
 }
 
 
 }
 
+#endif
+
 static void yaffs_SoftDeleteChunk(yaffs_Device *dev, int chunk)
 {
        yaffs_BlockInfo *theBlock;
 static void yaffs_SoftDeleteChunk(yaffs_Device *dev, int chunk)
 {
        yaffs_BlockInfo *theBlock;
@@ -2953,10 +2964,17 @@ static int yaffs_FindBlockForAllocation(yaffs_Device *dev)
 
 
 
 
 
 
+static int yaffs_CheckpointRequired(yaffs_Device *dev)
+{
+       int nblocks = dev->internalEndBlock - dev->internalStartBlock + 1 ;
+       return dev->param.isYaffs2 &&
+               !dev->param.skipCheckpointWrite &&
+               (nblocks >= YAFFS_CHECKPOINT_MIN_BLOCKS);
+}
 static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev)
 {
        if (!dev->nCheckpointBlocksRequired &&
 static int yaffs_CalcCheckpointBlocksRequired(yaffs_Device *dev)
 {
        if (!dev->nCheckpointBlocksRequired &&
-          dev->param.isYaffs2) {
+               yaffs_CheckpointRequired(dev)){
                /* Not a valid value so recalculate */
                int nBytes = 0;
                int nBlocks;
                /* Not a valid value so recalculate */
                int nBytes = 0;
                int nBlocks;
@@ -4877,7 +4895,7 @@ static int yaffs_WriteCheckpointData(yaffs_Device *dev)
 {
        int ok = 1;
 
 {
        int ok = 1;
 
-       if (dev->param.skipCheckpointWrite || !dev->param.isYaffs2) {
+       if (!yaffs_CheckpointRequired(dev)) {
                T(YAFFS_TRACE_CHECKPOINT, (TSTR("skipping checkpoint write" TENDSTR)));
                ok = 0;
        }
                T(YAFFS_TRACE_CHECKPOINT, (TSTR("skipping checkpoint write" TENDSTR)));
                ok = 0;
        }