+// SoftDeleteWorker scans backwards through the tnode tree and soft deletes all the chunks in the file.
+// All soft deleting does is increment the block's softdelete count and pulls the chunk out
+// of the tnode.
+// THus, essentially this is the same as DeleteWorker except that the chunks are soft deleted.
+//
+static int yaffs_SoftDeleteWorker(yaffs_Object *in, yaffs_Tnode *tn, __u32 level, int chunkOffset)
+{
+ int i;
+ int chunkInInode;
+ int theChunk;
+ yaffs_BlockInfo *theBlock;
+ yaffs_Tags tags;
+ int found;
+ int chunkDeleted;
+ int allDone = 1;
+
+
+ if(tn)
+ {
+ if(level > 0)
+ {
+
+ for(i = YAFFS_NTNODES_INTERNAL -1; allDone && i >= 0; i--)
+ {
+ if(tn->internal[i])
+ {
+ allDone = yaffs_SoftDeleteWorker(in,tn->internal[i],level - 1,
+ (chunkOffset << YAFFS_TNODES_INTERNAL_BITS ) + i);
+ if(allDone)
+ {
+ yaffs_FreeTnode(in->myDev,tn->internal[i]);
+ tn->internal[i] = NULL;
+ }
+ else
+ {
+ //Hoosterman... how could this happen.
+ }
+ }
+ }
+ return (allDone) ? 1 : 0;
+ }
+ else if(level == 0)
+ {
+
+ for(i = YAFFS_NTNODES_LEVEL0 -1; i >=0; i--)
+ {
+ if(tn->level0[i])
+ {
+ // Note this does not find the real chunk, only the chunk group.
+ // We make an assumption that a chunk group is niot larger than a block.
+ theChunk = (tn->level0[i] << in->myDev->chunkGroupBits);
+ T(YAFFS_TRACE_SCAN,(TSTR("soft delete tch %d cgb %d chunk %d" TENDSTR),
+ tn->level0[i],in->myDev->chunkGroupBits,theChunk));
+
+ theBlock = yaffs_GetBlockInfo(in->myDev, theChunk/in->myDev->nChunksPerBlock);
+ if(theBlock)
+ {
+ theBlock->softDeletions++;
+ }
+ tn->level0[i] = 0;
+ }
+
+ }
+ return 1;
+
+ }
+
+ }
+
+ return 1;
+
+}
+
+
+
+static void yaffs_SoftDeleteFile(yaffs_Object *obj)
+{
+ if(obj->deleted &&
+ obj->variantType == YAFFS_OBJECT_TYPE_FILE &&
+ !obj->softDeleted)
+ {
+ if(obj->nDataChunks <= 0)
+ {
+ // Empty file, just delete it immediately
+ yaffs_FreeTnode(obj->myDev,obj->variant.fileVariant.top);
+ obj->variant.fileVariant.top = NULL;
+ T(YAFFS_TRACE_TRACING,(TSTR("yaffs: Deleting empty file %d" TENDSTR),obj->objectId));
+ yaffs_DoGenericObjectDeletion(obj);
+ }
+ else
+ {
+ yaffs_SoftDeleteWorker(obj, obj->variant.fileVariant.top, obj->variant.fileVariant.topLevel, 0);
+ obj->softDeleted = 1;
+ }
+ }
+}
+
+