- __u8 *buffer = yaffs_GetTempBuffer(dev, __LINE__);
-
- yaffs_VerifyBlock(dev, bi, block);
-
- maxCopies = (wholeBlock) ? dev->param.nChunksPerBlock : 5;
- oldChunk = block * dev->param.nChunksPerBlock + dev->gcChunk;
-
- for (/* init already done */;
- retVal == YAFFS_OK &&
- dev->gcChunk < dev->param.nChunksPerBlock &&
- (bi->blockState == YAFFS_BLOCK_STATE_COLLECTING) &&
- maxCopies > 0;
- dev->gcChunk++, oldChunk++) {
- if (yaffs_CheckChunkBit(dev, block, dev->gcChunk)) {
-
- /* This page is in use and might need to be copied off */
-
- maxCopies--;
-
- markNAND = 1;
-
- yaffs_InitialiseTags(&tags);
-
- yaffs_ReadChunkWithTagsFromNAND(dev, oldChunk,
- buffer, &tags);
-
- object =
- yaffs_FindObjectByNumber(dev,
- tags.objectId);
-
- T(YAFFS_TRACE_GC_DETAIL,
- (TSTR
- ("Collecting chunk in block %d, %d %d %d " TENDSTR),
- dev->gcChunk, tags.objectId, tags.chunkId,
- tags.byteCount));
-
- if (object && !yaffs_SkipVerification(dev)) {
- if (tags.chunkId == 0)
- matchingChunk = object->hdrChunk;
- else if (object->softDeleted)
- matchingChunk = oldChunk; /* Defeat the test */
- else
- matchingChunk = yaffs_FindChunkInFile(object, tags.chunkId, NULL);
-
- if (oldChunk != matchingChunk)
- T(YAFFS_TRACE_ERROR,
- (TSTR("gc: page in gc mismatch: %d %d %d %d"TENDSTR),
- oldChunk, matchingChunk, tags.objectId, tags.chunkId));
-
- }
-
- if (!object) {
- T(YAFFS_TRACE_ERROR,
- (TSTR
- ("page %d in gc has no object: %d %d %d "
- TENDSTR), oldChunk,
- tags.objectId, tags.chunkId, tags.byteCount));
- }
-
- if (object &&
- object->deleted &&
- object->softDeleted &&
- tags.chunkId != 0) {
- /* Data chunk in a soft deleted file, throw it away
- * It's a soft deleted data chunk,
- * No need to copy this, just forget about it and
- * fix up the object.
- */
-
- /* Free chunks already includes softdeleted chunks.
- * How ever this chunk is going to soon be really deleted
- * which will increment free chunks.
- * We have to decrement free chunks so this works out properly.
- */
- dev->nFreeChunks--;
-
- object->nDataChunks--;
-
- if (object->nDataChunks <= 0) {
- /* remeber to clean up the object */
- dev->gcCleanupList[cleanups] =
- tags.objectId;
- cleanups++;
- }
- markNAND = 0;
- } else if (0) {
- /* Todo object && object->deleted && object->nDataChunks == 0 */
- /* Deleted object header with no data chunks.
- * Can be discarded and the file deleted.
- */
- object->hdrChunk = 0;
- yaffs_FreeTnode(object->myDev,
- object->variant.
- fileVariant.top);
- object->variant.fileVariant.top = NULL;
- yaffs_DoGenericObjectDeletion(object);
-
- } else if (object) {
- /* It's either a data chunk in a live file or
- * an ObjectHeader, so we're interested in it.
- * NB Need to keep the ObjectHeaders of deleted files
- * until the whole file has been deleted off
- */
- tags.serialNumber++;
-
- dev->nGCCopies++;
-
- if (tags.chunkId == 0) {
- /* It is an object Id,
- * We need to nuke the shrinkheader flags first
- * Also need to clean up shadowing.
- * We no longer want the shrinkHeader flag since its work is done
- * and if it is left in place it will mess up scanning.
- */
-
- yaffs_ObjectHeader *oh;
- oh = (yaffs_ObjectHeader *)buffer;
-
- oh->isShrink = 0;
- tags.extraIsShrinkHeader = 0;
-
- oh->shadowsObject = 0;
- oh->inbandShadowsObject = 0;
- tags.extraShadows = 0;
-
- /* Update file size */
- if(object->variantType == YAFFS_OBJECT_TYPE_FILE){
- oh->fileSize = object->variant.fileVariant.fileSize;
- tags.extraFileLength = oh->fileSize;
- }
-
- yaffs_VerifyObjectHeader(object, oh, &tags, 1);
- newChunk =
- yaffs_WriteNewChunkWithTagsToNAND(dev,(__u8 *) oh, &tags, 1);
- } else
- newChunk =
- yaffs_WriteNewChunkWithTagsToNAND(dev, buffer, &tags, 1);
-
- if (newChunk < 0) {
- retVal = YAFFS_FAIL;
- } else {
-
- /* Ok, now fix up the Tnodes etc. */
-
- if (tags.chunkId == 0) {
- /* It's a header */
- object->hdrChunk = newChunk;
- object->serial = tags.serialNumber;
- } else {
- /* It's a data chunk */
- int ok;
- ok = yaffs_PutChunkIntoFile
- (object,
- tags.chunkId,
- newChunk, 0);
- }
- }
- }
-
- if (retVal == YAFFS_OK)
- yaffs_DeleteChunk(dev, oldChunk, markNAND, __LINE__);
-
- }
- }