* to the given number
* Note we don't try to cater for all possible numbers and this does not have to
* be hellishly efficient.
*/
* to the given number
* Note we don't try to cater for all possible numbers and this does not have to
* be hellishly efficient.
*/
for (i = 0; buf && i < YAFFS_N_TEMP_BUFFERS; i++) {
dev->tempBuffer[i].line = 0; /* not in use */
dev->tempBuffer[i].buffer = buf =
YMALLOC_DMA(dev->nDataBytesPerChunk);
}
for (i = 0; buf && i < YAFFS_N_TEMP_BUFFERS; i++) {
dev->tempBuffer[i].line = 0; /* not in use */
dev->tempBuffer[i].buffer = buf =
YMALLOC_DMA(dev->nDataBytesPerChunk);
}
static Y_INLINE void yaffs_SetChunkBit(yaffs_Device * dev, int blk, int chunk)
{
__u8 *blkBits = yaffs_BlockBits(dev, blk);
static Y_INLINE void yaffs_SetChunkBit(yaffs_Device * dev, int blk, int chunk)
{
__u8 *blkBits = yaffs_BlockBits(dev, blk);
yaffs_VerifyChunkBitId(dev,blk,chunk);
blkBits[chunk / 8] |= (1 << (chunk & 7));
yaffs_VerifyChunkBitId(dev,blk,chunk);
blkBits[chunk / 8] |= (1 << (chunk & 7));
static int yaffs_SkipVerification(yaffs_Device *dev)
{
return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY | YAFFS_TRACE_VERIFY_FULL));
static int yaffs_SkipVerification(yaffs_Device *dev)
{
return !(yaffs_traceMask & (YAFFS_TRACE_VERIFY | YAFFS_TRACE_VERIFY_FULL));
/* Report illegal runtime states */
if(bi->blockState <0 || bi->blockState >= YAFFS_NUMBER_OF_BLOCK_STATES)
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has undefined state %d"TENDSTR),n,bi->blockState));
/* Report illegal runtime states */
if(bi->blockState <0 || bi->blockState >= YAFFS_NUMBER_OF_BLOCK_STATES)
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has undefined state %d"TENDSTR),n,bi->blockState));
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has bad run-state %s"TENDSTR),
n,blockStateName[bi->blockState]));
}
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has bad run-state %s"TENDSTR),
n,blockStateName[bi->blockState]));
}
if(bi->pagesInUse < 0 || bi->pagesInUse > dev->nChunksPerBlock ||
bi->softDeletions < 0 || bi->softDeletions > dev->nChunksPerBlock ||
actuallyUsed < 0 || actuallyUsed > dev->nChunksPerBlock)
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has illegal values pagesInUsed %d softDeletions %d"TENDSTR),
n,bi->pagesInUse,bi->softDeletions));
if(bi->pagesInUse < 0 || bi->pagesInUse > dev->nChunksPerBlock ||
bi->softDeletions < 0 || bi->softDeletions > dev->nChunksPerBlock ||
actuallyUsed < 0 || actuallyUsed > dev->nChunksPerBlock)
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has illegal values pagesInUsed %d softDeletions %d"TENDSTR),
n,bi->pagesInUse,bi->softDeletions));
/* Check chunk bitmap legal */
inUse = yaffs_CountChunkBits(dev,n);
if(inUse != bi->pagesInUse)
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has inconsistent values pagesInUse %d counted chunk bits %d"TENDSTR),
n,bi->pagesInUse,inUse));
/* Check chunk bitmap legal */
inUse = yaffs_CountChunkBits(dev,n);
if(inUse != bi->pagesInUse)
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has inconsistent values pagesInUse %d counted chunk bits %d"TENDSTR),
n,bi->pagesInUse,inUse));
(bi->blockState == YAFFS_BLOCK_STATE_ALLOCATING || bi->blockState == YAFFS_BLOCK_STATE_FULL) &&
(bi->sequenceNumber < YAFFS_LOWEST_SEQUENCE_NUMBER || bi->sequenceNumber > 10000000 ))
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has suspect sequence number of %d"TENDSTR),
n,bi->sequenceNumber));
(bi->blockState == YAFFS_BLOCK_STATE_ALLOCATING || bi->blockState == YAFFS_BLOCK_STATE_FULL) &&
(bi->sequenceNumber < YAFFS_LOWEST_SEQUENCE_NUMBER || bi->sequenceNumber > 10000000 ))
T(YAFFS_TRACE_VERIFY,(TSTR("Block %d has suspect sequence number of %d"TENDSTR),
n,bi->sequenceNumber));
}
static void yaffs_VerifyCollectedBlock(yaffs_Device *dev,yaffs_BlockInfo *bi,int n)
{
yaffs_VerifyBlock(dev,bi,n);
}
static void yaffs_VerifyCollectedBlock(yaffs_Device *dev,yaffs_BlockInfo *bi,int n)
{
yaffs_VerifyBlock(dev,bi,n);
/* After collection the block should be in the erased state */
/* TODO: This will need to change if we do partial gc */
/* After collection the block should be in the erased state */
/* TODO: This will need to change if we do partial gc */
if(bi->blockState != YAFFS_BLOCK_STATE_EMPTY){
T(YAFFS_TRACE_ERROR,(TSTR("Block %d is in state %d after gc, should be erased"TENDSTR),
n,bi->blockState));
if(bi->blockState != YAFFS_BLOCK_STATE_EMPTY){
T(YAFFS_TRACE_ERROR,(TSTR("Block %d is in state %d after gc, should be erased"TENDSTR),
n,bi->blockState));
if(yaffs_SkipVerification(dev))
return;
memset(nBlocksPerState,0,sizeof(nBlocksPerState));
if(yaffs_SkipVerification(dev))
return;
memset(nBlocksPerState,0,sizeof(nBlocksPerState));
for(i = dev->internalStartBlock; i <= dev->internalEndBlock; i++){
yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,i);
yaffs_VerifyBlock(dev,bi,i);
for(i = dev->internalStartBlock; i <= dev->internalEndBlock; i++){
yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev,i);
yaffs_VerifyBlock(dev,bi,i);
T(YAFFS_TRACE_VERIFY,(TSTR(""TENDSTR)));
T(YAFFS_TRACE_VERIFY,(TSTR("Block summary"TENDSTR)));
T(YAFFS_TRACE_VERIFY,(TSTR(""TENDSTR)));
T(YAFFS_TRACE_VERIFY,(TSTR("Block summary"TENDSTR)));
T(YAFFS_TRACE_VERIFY,(TSTR("%d blocks have illegal states"TENDSTR),nIllegalBlockStates));
if(nBlocksPerState[YAFFS_BLOCK_STATE_ALLOCATING] > 1)
T(YAFFS_TRACE_VERIFY,(TSTR("Too many allocating blocks"TENDSTR)));
T(YAFFS_TRACE_VERIFY,(TSTR("%d blocks have illegal states"TENDSTR),nIllegalBlockStates));
if(nBlocksPerState[YAFFS_BLOCK_STATE_ALLOCATING] > 1)
T(YAFFS_TRACE_VERIFY,(TSTR("Too many allocating blocks"TENDSTR)));
T(YAFFS_TRACE_VERIFY,
(TSTR("%s %d blocks"TENDSTR),
blockStateName[i],nBlocksPerState[i]));
T(YAFFS_TRACE_VERIFY,
(TSTR("%s %d blocks"TENDSTR),
blockStateName[i],nBlocksPerState[i]));
if(dev->blocksInCheckpoint != nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT])
T(YAFFS_TRACE_VERIFY,
(TSTR("Checkpoint block count wrong dev %d count %d"TENDSTR),
dev->blocksInCheckpoint, nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT]));
if(dev->blocksInCheckpoint != nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT])
T(YAFFS_TRACE_VERIFY,
(TSTR("Checkpoint block count wrong dev %d count %d"TENDSTR),
dev->blocksInCheckpoint, nBlocksPerState[YAFFS_BLOCK_STATE_CHECKPOINT]));
if(dev->nErasedBlocks != nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY])
T(YAFFS_TRACE_VERIFY,
(TSTR("Erased block count wrong dev %d count %d"TENDSTR),
dev->nErasedBlocks, nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY]));
if(dev->nErasedBlocks != nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY])
T(YAFFS_TRACE_VERIFY,
(TSTR("Erased block count wrong dev %d count %d"TENDSTR),
dev->nErasedBlocks, nBlocksPerState[YAFFS_BLOCK_STATE_EMPTY]));
if(nBlocksPerState[YAFFS_BLOCK_STATE_COLLECTING] > 1)
T(YAFFS_TRACE_VERIFY,
(TSTR("Too many collecting blocks %d (max is 1)"TENDSTR),
if(nBlocksPerState[YAFFS_BLOCK_STATE_COLLECTING] > 1)
T(YAFFS_TRACE_VERIFY,
(TSTR("Too many collecting blocks %d (max is 1)"TENDSTR),
if(!(tags && obj && oh)){
T(YAFFS_TRACE_VERIFY,
(TSTR("Verifying object header tags %x obj %x oh %x"TENDSTR),
(__u32)tags,(__u32)obj,(__u32)oh));
return;
}
if(!(tags && obj && oh)){
T(YAFFS_TRACE_VERIFY,
(TSTR("Verifying object header tags %x obj %x oh %x"TENDSTR),
(__u32)tags,(__u32)obj,(__u32)oh));
return;
}
if(parentCheck && tags->objectId > 1 && !obj->parent)
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d header mismatch parentId %d obj->parent is NULL"TENDSTR),
tags->objectId, oh->parentObjectId));
if(parentCheck && tags->objectId > 1 && !obj->parent)
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d header mismatch parentId %d obj->parent is NULL"TENDSTR),
tags->objectId, oh->parentObjectId));
(oh->parentObjectId != YAFFS_OBJECTID_UNLINKED ||
obj->parent->objectId != YAFFS_OBJECTID_DELETED))
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d header mismatch parentId %d parentObjectId %d"TENDSTR),
tags->objectId, oh->parentObjectId, obj->parent->objectId));
(oh->parentObjectId != YAFFS_OBJECTID_UNLINKED ||
obj->parent->objectId != YAFFS_OBJECTID_DELETED))
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d header mismatch parentId %d parentObjectId %d"TENDSTR),
tags->objectId, oh->parentObjectId, obj->parent->objectId));
if(tags->objectId > 1 && oh->name[0] == 0) /* Null name */
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d header name is NULL"TENDSTR),
if(tags->objectId > 1 && oh->name[0] == 0) /* Null name */
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d header name is NULL"TENDSTR),
for(i = 0; i < YAFFS_NTNODES_LEVEL0; i++){
__u32 theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
for(i = 0; i < YAFFS_NTNODES_LEVEL0; i++){
__u32 theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
if(theChunk > 0){
/* T(~0,(TSTR("verifying (%d:%d) %d"TENDSTR),tags.objectId,tags.chunkId,theChunk)); */
yaffs_ReadChunkWithTagsFromNAND(dev,theChunk,NULL, &tags);
if(theChunk > 0){
/* T(~0,(TSTR("verifying (%d:%d) %d"TENDSTR),tags.objectId,tags.chunkId,theChunk)); */
yaffs_ReadChunkWithTagsFromNAND(dev,theChunk,NULL, &tags);
/* Check file size is consistent with tnode depth */
lastChunk = obj->variant.fileVariant.fileSize / dev->nDataBytesPerChunk + 1;
x = lastChunk >> YAFFS_TNODES_LEVEL0_BITS;
/* Check file size is consistent with tnode depth */
lastChunk = obj->variant.fileVariant.fileSize / dev->nDataBytesPerChunk + 1;
x = lastChunk >> YAFFS_TNODES_LEVEL0_BITS;
if(requiredTallness > actualTallness )
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d had tnode tallness %d, needs to be %d"TENDSTR),
obj->objectId,actualTallness, requiredTallness));
if(requiredTallness > actualTallness )
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d had tnode tallness %d, needs to be %d"TENDSTR),
obj->objectId,actualTallness, requiredTallness));
* We do this by scanning through the tnode tree and
* checking the tags for every chunk match.
*/
if(yaffs_SkipNANDVerification(dev))
return;
* We do this by scanning through the tnode tree and
* checking the tags for every chunk match.
*/
if(yaffs_SkipNANDVerification(dev))
return;
for(i = 1; i <= lastChunk; i++){
tn = yaffs_FindLevel0Tnode(dev, &obj->variant.fileVariant,i);
for(i = 1; i <= lastChunk; i++){
tn = yaffs_FindLevel0Tnode(dev, &obj->variant.fileVariant,i);
chunkMin = dev->internalStartBlock * dev->nChunksPerBlock;
chunkMax = (dev->internalEndBlock+1) * dev->nChunksPerBlock - 1;
chunkMin = dev->internalStartBlock * dev->nChunksPerBlock;
chunkMax = (dev->internalEndBlock+1) * dev->nChunksPerBlock - 1;
- chunkIsLive = chunkIdOk &&
- yaffs_CheckChunkBit(dev,
+ chunkIsLive = chunkIdOk &&
+ yaffs_CheckChunkBit(dev,
obj->chunkId / dev->nChunksPerBlock,
obj->chunkId % dev->nChunksPerBlock);
obj->chunkId / dev->nChunksPerBlock,
obj->chunkId % dev->nChunksPerBlock);
(!chunkIdOk || !chunkIsLive)) {
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d has chunkId %d %s %s"TENDSTR),
(!chunkIdOk || !chunkIsLive)) {
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d has chunkId %d %s %s"TENDSTR),
chunkIdOk ? "" : ",out of range",
chunkIsLive || !chunkIdOk ? "" : ",marked as deleted"));
}
chunkIdOk ? "" : ",out of range",
chunkIsLive || !chunkIdOk ? "" : ",marked as deleted"));
}
if(chunkIdOk && chunkIsLive &&!yaffs_SkipNANDVerification(dev)) {
yaffs_ExtendedTags tags;
yaffs_ObjectHeader *oh;
__u8 *buffer = yaffs_GetTempBuffer(dev,__LINE__);
if(chunkIdOk && chunkIsLive &&!yaffs_SkipNANDVerification(dev)) {
yaffs_ExtendedTags tags;
yaffs_ObjectHeader *oh;
__u8 *buffer = yaffs_GetTempBuffer(dev,__LINE__);
yaffs_ReadChunkWithTagsFromNAND(dev, obj->chunkId,buffer, &tags);
yaffs_ReadChunkWithTagsFromNAND(dev, obj->chunkId,buffer, &tags);
yaffs_VerifyObjectHeader(obj,oh,&tags,1);
yaffs_VerifyObjectHeader(obj,oh,&tags,1);
/* Verify it has a parent */
if(obj && !obj->fake &&
(!obj->parent || obj->parent->myDev != dev)){
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d has parent pointer %p which does not look like an object"TENDSTR),
/* Verify it has a parent */
if(obj && !obj->fake &&
(!obj->parent || obj->parent->myDev != dev)){
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d has parent pointer %p which does not look like an object"TENDSTR),
/* Verify parent is a directory */
if(obj->parent && obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY){
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d's parent is not a directory (type %d)"TENDSTR),
/* Verify parent is a directory */
if(obj->parent && obj->parent->variantType != YAFFS_OBJECT_TYPE_DIRECTORY){
T(YAFFS_TRACE_VERIFY,
(TSTR("Obj %d's parent is not a directory (type %d)"TENDSTR),
for(i = 0; i < YAFFS_NOBJECT_BUCKETS; i++){
list_for_each(lh, &dev->objectBucket[i].list) {
if (lh) {
for(i = 0; i < YAFFS_NOBJECT_BUCKETS; i++){
list_for_each(lh, &dev->objectBucket[i].list) {
if (lh) {
int yaffs_CheckFF(__u8 * buffer, int nBytes)
{
/* Horrible, slow implementation */
int yaffs_CheckFF(__u8 * buffer, int nBytes)
{
/* Horrible, slow implementation */
int result;
result = yaffs_ReadChunkWithTagsFromNAND(dev, chunkInNAND, data, &tags);
int result;
result = yaffs_ReadChunkWithTagsFromNAND(dev, chunkInNAND, data, &tags);
if (!yaffs_CheckFF(data, dev->nDataBytesPerChunk) || tags.chunkUsed) {
T(YAFFS_TRACE_NANDACCESS,
if (!yaffs_CheckFF(data, dev->nDataBytesPerChunk) || tags.chunkUsed) {
T(YAFFS_TRACE_NANDACCESS,
static void yaffs_RetireBlock(yaffs_Device * dev, int blockInNAND)
{
yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND);
yaffs_InvalidateCheckpoint(dev);
static void yaffs_RetireBlock(yaffs_Device * dev, int blockInNAND)
{
yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND);
yaffs_InvalidateCheckpoint(dev);
yaffs_MarkBlockBad(dev, blockInNAND);
bi->blockState = YAFFS_BLOCK_STATE_DEAD;
yaffs_MarkBlockBad(dev, blockInNAND);
bi->blockState = YAFFS_BLOCK_STATE_DEAD;
static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND,
const __u8 * data,
const yaffs_ExtendedTags * tags)
static void yaffs_HandleWriteChunkOk(yaffs_Device * dev, int chunkInNAND,
const __u8 * data,
const yaffs_ExtendedTags * tags)
if(bi->chunkErrorStrikes > 3){
bi->needsRetiring = 1; /* Too many stikes, so retire this */
T(YAFFS_TRACE_ALWAYS, (TSTR("yaffs: Block struck out" TENDSTR)));
}
if(bi->chunkErrorStrikes > 3){
bi->needsRetiring = 1; /* Too many stikes, so retire this */
T(YAFFS_TRACE_ALWAYS, (TSTR("yaffs: Block struck out" TENDSTR)));
}
yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND);
yaffs_HandleChunkError(dev,bi);
yaffs_BlockInfo *bi = yaffs_GetBlockInfo(dev, blockInNAND);
yaffs_HandleChunkError(dev,bi);
if(erasedOk ) {
/* Was an actual write failure, so mark the block for retirement */
bi->needsRetiring = 1;
T(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS,
(TSTR("**>> Block %d needs retiring" TENDSTR), blockInNAND));
if(erasedOk ) {
/* Was an actual write failure, so mark the block for retirement */
bi->needsRetiring = 1;
T(YAFFS_TRACE_ERROR | YAFFS_TRACE_BAD_BLOCKS,
(TSTR("**>> Block %d needs retiring" TENDSTR), blockInNAND));
/* Delete the chunk */
yaffs_DeleteChunk(dev, chunkInNAND, 1, __LINE__);
}
/* Delete the chunk */
yaffs_DeleteChunk(dev, chunkInNAND, 1, __LINE__);
}
/* yaffs_CreateTnodes creates a bunch more tnodes and
* adds them to the tnode free list.
* Don't use this function directly
/* yaffs_CreateTnodes creates a bunch more tnodes and
* adds them to the tnode free list.
* Don't use this function directly
/* Calculate the tnode size in bytes for variable width tnode support.
* Must be a multiple of 32-bits */
tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
/* Calculate the tnode size in bytes for variable width tnode support.
* Must be a multiple of 32-bits */
tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
curr = (yaffs_Tnode *) &mem[(nTnodes - 1) * tnodeSize];
curr->internal[0] = dev->freeTnodes;
dev->freeTnodes = (yaffs_Tnode *)mem;
curr = (yaffs_Tnode *) &mem[(nTnodes - 1) * tnodeSize];
curr->internal[0] = dev->freeTnodes;
dev->freeTnodes = (yaffs_Tnode *)mem;
* NB If we can't add this to the management list it isn't fatal
* but it just means we can't free this bunch of tnodes later.
*/
* NB If we can't add this to the management list it isn't fatal
* but it just means we can't free this bunch of tnodes later.
*/
bitInMap = pos * dev->tnodeWidth;
wordInMap = bitInMap /32;
bitInWord = bitInMap & (32 -1);
bitInMap = pos * dev->tnodeWidth;
wordInMap = bitInMap /32;
bitInWord = bitInMap & (32 -1);
bitInMap = pos * dev->tnodeWidth;
wordInMap = bitInMap /32;
bitInWord = bitInMap & (32 -1);
bitInMap = pos * dev->tnodeWidth;
wordInMap = bitInMap /32;
bitInWord = bitInMap & (32 -1);
if(dev->tnodeWidth > (32-bitInWord)) {
bitInWord = (32 - bitInWord);
wordInMap++;;
val |= (map[wordInMap] << bitInWord);
}
if(dev->tnodeWidth > (32-bitInWord)) {
bitInWord = (32 - bitInWord);
wordInMap++;;
val |= (map[wordInMap] << bitInWord);
}
* If the tn argument is NULL, then a fresh tnode will be added otherwise the specified tn will
* be plugged into the ttree.
*/
* If the tn argument is NULL, then a fresh tnode will be added otherwise the specified tn will
* be plugged into the ttree.
*/
static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device * dev,
yaffs_FileStructure * fStruct,
__u32 chunkId,
static yaffs_Tnode *yaffs_AddOrFindLevel0Tnode(yaffs_Device * dev,
yaffs_FileStructure * fStruct,
__u32 chunkId,
if (requiredTallness > fStruct->topLevel) {
/* Not tall enough,gotta make the tree taller */
for (i = fStruct->topLevel; i < requiredTallness; i++) {
if (requiredTallness > fStruct->topLevel) {
/* Not tall enough,gotta make the tree taller */
for (i = fStruct->topLevel; i < requiredTallness; i++) {
if(tn->internal[x])
yaffs_FreeTnode(dev,tn->internal[x]);
tn->internal[x] = passedTn;
if(tn->internal[x])
yaffs_FreeTnode(dev,tn->internal[x]);
tn->internal[x] = passedTn;
} else if(!tn->internal[x]) {
/* Don't have one, none passed in */
tn->internal[x] = yaffs_GetTnode(dev);
}
}
} else if(!tn->internal[x]) {
/* Don't have one, none passed in */
tn->internal[x] = yaffs_GetTnode(dev);
}
}
/* DeleteWorker scans backwards through the tnode tree and deletes all the
* chunks and tnodes in the file
/* DeleteWorker scans backwards through the tnode tree and deletes all the
* chunks and tnodes in the file
static int yaffs_SoftDeleteWorker(yaffs_Object * in, yaffs_Tnode * tn,
__u32 level, int chunkOffset)
{
static int yaffs_SoftDeleteWorker(yaffs_Object * in, yaffs_Tnode * tn,
__u32 level, int chunkOffset)
{
theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
if (theChunk) {
/* Note this does not find the real chunk, only the chunk group.
theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
if (theChunk) {
/* Note this does not find the real chunk, only the chunk group.
/* Now we have a tree with all the non-zero branches NULL but the height
* is the same as it was.
* Let's see if we can trim internal tnodes to shorten the tree.
/* Now we have a tree with all the non-zero branches NULL but the height
* is the same as it was.
* Let's see if we can trim internal tnodes to shorten the tree.
/* Hook them into the free list */
for (i = 0; i < nObjects - 1; i++) {
newObjects[i].siblings.next =
/* Hook them into the free list */
for (i = 0; i < nObjects - 1; i++) {
newObjects[i].siblings.next =
* aliasString only has meaning for a sumlink.
* rdev only has meaning for devices (a subset of special objects)
*/
* aliasString only has meaning for a sumlink.
* rdev only has meaning for devices (a subset of special objects)
*/
equivalentObject->objectId;
list_add(&in->hardLinks, &equivalentObject->hardLinks);
break;
equivalentObject->objectId;
list_add(&in->hardLinks, &equivalentObject->hardLinks);
break;
case YAFFS_OBJECT_TYPE_DIRECTORY:
case YAFFS_OBJECT_TYPE_SPECIAL:
case YAFFS_OBJECT_TYPE_UNKNOWN:
case YAFFS_OBJECT_TYPE_DIRECTORY:
case YAFFS_OBJECT_TYPE_SPECIAL:
case YAFFS_OBJECT_TYPE_UNKNOWN:
/* TODO: Do we need this different handling for YAFFS2 and YAFFS1?? */
if (obj->myDev->isYaffs2) {
unlinkOp = (newDir == obj->myDev->unlinkedDir);
/* TODO: Do we need this different handling for YAFFS2 and YAFFS1?? */
if (obj->myDev->isYaffs2) {
unlinkOp = (newDir == obj->myDev->unlinkedDir);
/* There is a target that is a non-empty directory, so we fail */
return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */
} else if (existingTarget && existingTarget != obj) {
/* There is a target that is a non-empty directory, so we fail */
return YAFFS_FAIL; /* EEXIST or ENOTEMPTY */
} else if (existingTarget && existingTarget != obj) {
* but only if it isn't the same object
*/
yaffs_ChangeObjectName(obj, newDir, newName, force,
* but only if it isn't the same object
*/
yaffs_ChangeObjectName(obj, newDir, newName, force,
static int yaffs_InitialiseBlocks(yaffs_Device * dev)
{
int nBlocks = dev->internalEndBlock - dev->internalStartBlock + 1;
static int yaffs_InitialiseBlocks(yaffs_Device * dev)
{
int nBlocks = dev->internalEndBlock - dev->internalStartBlock + 1;
dev->allocationBlock = -1; /* force it to get a new one */
/* If the first allocation strategy fails, thry the alternate one */
dev->allocationBlock = -1; /* force it to get a new one */
/* If the first allocation strategy fails, thry the alternate one */
/* Set up dynamic blockinfo stuff. */
dev->chunkBitmapStride = (dev->nChunksPerBlock + 7) / 8; /* round up bytes */
dev->chunkBits = YMALLOC(dev->chunkBitmapStride * nBlocks);
/* Set up dynamic blockinfo stuff. */
dev->chunkBitmapStride = (dev->nChunksPerBlock + 7) / 8; /* round up bytes */
dev->chunkBits = YMALLOC(dev->chunkBitmapStride * nBlocks);
if (dev->blockInfo && dev->chunkBits) {
memset(dev->blockInfo, 0, nBlocks * sizeof(yaffs_BlockInfo));
memset(dev->chunkBits, 0, dev->chunkBitmapStride * nBlocks);
if (dev->blockInfo && dev->chunkBits) {
memset(dev->blockInfo, 0, nBlocks * sizeof(yaffs_BlockInfo));
memset(dev->chunkBits, 0, dev->chunkBitmapStride * nBlocks);
/* First let's see if we need to grab a prioritised block */
if(dev->hasPendingPrioritisedGCs){
for(i = dev->internalStartBlock; i < dev->internalEndBlock && !prioritised; i++){
bi = yaffs_GetBlockInfo(dev, i);
//yaffs_VerifyBlock(dev,bi,i);
/* First let's see if we need to grab a prioritised block */
if(dev->hasPendingPrioritisedGCs){
for(i = dev->internalStartBlock; i < dev->internalEndBlock && !prioritised; i++){
bi = yaffs_GetBlockInfo(dev, i);
//yaffs_VerifyBlock(dev,bi,i);
if(!pendingPrioritisedExist) /* None found, so we can clear this */
dev->hasPendingPrioritisedGCs = 0;
}
if(!pendingPrioritisedExist) /* None found, so we can clear this */
dev->hasPendingPrioritisedGCs = 0;
}
/* If the block is still healthy erase it and mark as clean.
* If the block has had a data failure, then retire it.
*/
/* If the block is still healthy erase it and mark as clean.
* If the block has had a data failure, then retire it.
*/
T(YAFFS_TRACE_GC | YAFFS_TRACE_ERASE,
(TSTR("yaffs_BlockBecameDirty block %d state %d %s"TENDSTR),
blockNo, bi->blockState, (bi->needsRetiring) ? "needs retiring" : ""));
T(YAFFS_TRACE_GC | YAFFS_TRACE_ERASE,
(TSTR("yaffs_BlockBecameDirty block %d state %d %s"TENDSTR),
blockNo, bi->blockState, (bi->needsRetiring) ? "needs retiring" : ""));
((yaffs_traceMask & YAFFS_TRACE_ERASE) || !yaffs_SkipVerification(dev))) {
int i;
for (i = 0; i < dev->nChunksPerBlock; i++) {
((yaffs_traceMask & YAFFS_TRACE_ERASE) || !yaffs_SkipVerification(dev))) {
int i;
for (i = 0; i < dev->nChunksPerBlock; i++) {
yaffs_VerifyBlock(dev,bi,block);
for (chunkInBlock = 0, oldChunk = block * dev->nChunksPerBlock;
yaffs_VerifyBlock(dev,bi,block);
for (chunkInBlock = 0, oldChunk = block * dev->nChunksPerBlock;
("Collecting page %d, %d %d %d " TENDSTR),
chunkInBlock, tags.objectId, tags.chunkId,
tags.byteCount));
("Collecting page %d, %d %d %d " TENDSTR),
chunkInBlock, tags.objectId, tags.chunkId,
tags.byteCount));
matchingChunk = oldChunk; /* Defeat the test */
else
matchingChunk = yaffs_FindChunkInFile(object,tags.chunkId,NULL);
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(oldChunk != matchingChunk)
T(YAFFS_TRACE_ERROR,
(TSTR("gc: page in gc mismatch: %d %d %d %d"TENDSTR),
oldChunk,matchingChunk,tags.objectId, tags.chunkId));
&& tags.chunkId != 0) {
/* Data chunk in a deleted file, throw it away
* It's a soft deleted data chunk,
&& tags.chunkId != 0) {
/* Data chunk in a deleted file, throw it away
* It's a soft deleted data chunk,
yaffs_VerifyObjectHeader(object,oh,&tags,1);
}
yaffs_VerifyObjectHeader(object,oh,&tags,1);
}
/* This loop should pass the first time.
* We'll only see looping here if the erase of the collected block fails.
*/
do {
maxTries++;
/* This loop should pass the first time.
* We'll only see looping here if the erase of the collected block fails.
*/
do {
maxTries++;
checkpointBlockAdjust = (dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint);
if(checkpointBlockAdjust < 0)
checkpointBlockAdjust = 0;
checkpointBlockAdjust = (dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint);
if(checkpointBlockAdjust < 0)
checkpointBlockAdjust = 0;
static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode,
int chunkInNAND, int inScan)
{
static int yaffs_PutChunkIntoFile(yaffs_Object * in, int chunkInInode,
int chunkInNAND, int inScan)
{
- /* NB inScan is zero unless scanning.
- * For forward scanning, inScan is > 0;
+ /* NB inScan is zero unless scanning.
+ * For forward scanning, inScan is > 0;
* happen when the power fails during a write, then only one
* chunk should ever be affected.
*
* happen when the power fails during a write, then only one
* chunk should ever be affected.
*
(TSTR("Chunk %d not found zero instead" TENDSTR),
chunkInNAND));
/* get sane (zero) data if you read a hole */
(TSTR("Chunk %d not found zero instead" TENDSTR),
chunkInNAND));
/* get sane (zero) data if you read a hole */
yaffs_strcpy(oldName,"silly old name");
if (!in->fake || force) {
yaffs_strcpy(oldName,"silly old name");
if (!in->fake || force) {
yaffs_VerifyObjectHeader(in,oh,&oldTags,0);
yaffs_VerifyObjectHeader(in,oh,&oldTags,0);
/*------------------------ Short Operations Cache ----------------------------------------
* In many situations where there is no high level buffering (eg WinCE) a lot of
/*------------------------ Short Operations Cache ----------------------------------------
* In many situations where there is no high level buffering (eg WinCE) a lot of
for(i = 0; i < nCaches; i++){
cache = &dev->srCache[i];
if (cache->object == obj &&
cache->dirty)
return 1;
}
for(i = 0; i < nCaches; i++){
cache = &dev->srCache[i];
if (cache->object == obj &&
cache->dirty)
return 1;
}
* Then look for the least recently used non-dirty one.
* Then look for the least recently used dirty one...., flush and look again.
*/
* Then look for the least recently used non-dirty one.
* Then look for the least recently used dirty one...., flush and look again.
*/
static int yaffs_WriteCheckpointValidityMarker(yaffs_Device *dev,int head)
{
yaffs_CheckpointValidity cp;
static int yaffs_WriteCheckpointValidityMarker(yaffs_Device *dev,int head)
{
yaffs_CheckpointValidity cp;
cp.structType = sizeof(cp);
cp.magic = YAFFS_MAGIC;
cp.version = YAFFS_CHECKPOINT_VERSION;
cp.head = (head) ? 1 : 0;
cp.structType = sizeof(cp);
cp.magic = YAFFS_MAGIC;
cp.version = YAFFS_CHECKPOINT_VERSION;
cp.head = (head) ? 1 : 0;
yaffs_Device *dev)
{
cp->nErasedBlocks = dev->nErasedBlocks;
cp->allocationBlock = dev->allocationBlock;
cp->allocationPage = dev->allocationPage;
cp->nFreeChunks = dev->nFreeChunks;
yaffs_Device *dev)
{
cp->nErasedBlocks = dev->nErasedBlocks;
cp->allocationBlock = dev->allocationBlock;
cp->allocationPage = dev->allocationPage;
cp->nFreeChunks = dev->nFreeChunks;
cp->nDeletedFiles = dev->nDeletedFiles;
cp->nUnlinkedFiles = dev->nUnlinkedFiles;
cp->nBackgroundDeletions = dev->nBackgroundDeletions;
cp->sequenceNumber = dev->sequenceNumber;
cp->oldestDirtySequence = dev->oldestDirtySequence;
cp->nDeletedFiles = dev->nDeletedFiles;
cp->nUnlinkedFiles = dev->nUnlinkedFiles;
cp->nBackgroundDeletions = dev->nBackgroundDeletions;
cp->sequenceNumber = dev->sequenceNumber;
cp->oldestDirtySequence = dev->oldestDirtySequence;
dev->allocationBlock = cp->allocationBlock;
dev->allocationPage = cp->allocationPage;
dev->nFreeChunks = cp->nFreeChunks;
dev->allocationBlock = cp->allocationBlock;
dev->allocationPage = cp->allocationPage;
dev->nFreeChunks = cp->nFreeChunks;
dev->nDeletedFiles = cp->nDeletedFiles;
dev->nUnlinkedFiles = cp->nUnlinkedFiles;
dev->nBackgroundDeletions = cp->nBackgroundDeletions;
dev->nDeletedFiles = cp->nDeletedFiles;
dev->nUnlinkedFiles = cp->nUnlinkedFiles;
dev->nBackgroundDeletions = cp->nBackgroundDeletions;
/* Write device runtime values*/
yaffs_DeviceToCheckpointDevice(&cp,dev);
cp.structType = sizeof(cp);
/* Write device runtime values*/
yaffs_DeviceToCheckpointDevice(&cp,dev);
cp.structType = sizeof(cp);
/* Write block info */
if(ok) {
nBytes = nBlocks * sizeof(yaffs_BlockInfo);
ok = (yaffs_CheckpointWrite(dev,dev->blockInfo,nBytes) == nBytes);
}
/* Write block info */
if(ok) {
nBytes = nBlocks * sizeof(yaffs_BlockInfo);
ok = (yaffs_CheckpointWrite(dev,dev->blockInfo,nBytes) == nBytes);
}
if(ok) {
nBytes = nBlocks * dev->chunkBitmapStride;
ok = (yaffs_CheckpointWrite(dev,dev->chunkBits,nBytes) == nBytes);
if(ok) {
nBytes = nBlocks * dev->chunkBitmapStride;
ok = (yaffs_CheckpointWrite(dev,dev->chunkBits,nBytes) == nBytes);
cp->objectId = obj->objectId;
cp->parentId = (obj->parent) ? obj->parent->objectId : 0;
cp->chunkId = obj->chunkId;
cp->objectId = obj->objectId;
cp->parentId = (obj->parent) ? obj->parent->objectId : 0;
cp->chunkId = obj->chunkId;
cp->deleted = obj->deleted;
cp->softDeleted = obj->softDeleted;
cp->unlinked = obj->unlinked;
cp->deleted = obj->deleted;
cp->softDeleted = obj->softDeleted;
cp->unlinked = obj->unlinked;
cp->unlinkAllowed = obj->unlinkAllowed;
cp->serial = obj->serial;
cp->nDataChunks = obj->nDataChunks;
cp->unlinkAllowed = obj->unlinkAllowed;
cp->serial = obj->serial;
cp->nDataChunks = obj->nDataChunks;
if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
cp->fileSizeOrEquivalentObjectId = obj->variant.fileVariant.fileSize;
else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK)
if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
cp->fileSizeOrEquivalentObjectId = obj->variant.fileVariant.fileSize;
else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK)
obj->deleted = cp->deleted;
obj->softDeleted = cp->softDeleted;
obj->unlinked = cp->unlinked;
obj->deleted = cp->deleted;
obj->softDeleted = cp->softDeleted;
obj->unlinked = cp->unlinked;
obj->unlinkAllowed = cp->unlinkAllowed;
obj->serial = cp->serial;
obj->nDataChunks = cp->nDataChunks;
obj->unlinkAllowed = cp->unlinkAllowed;
obj->serial = cp->serial;
obj->nDataChunks = cp->nDataChunks;
if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
obj->variant.fileVariant.fileSize = cp->fileSizeOrEquivalentObjectId;
else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK)
obj->variant.hardLinkVariant.equivalentObjectId = cp->fileSizeOrEquivalentObjectId;
if(obj->variantType == YAFFS_OBJECT_TYPE_FILE)
obj->variant.fileVariant.fileSize = cp->fileSizeOrEquivalentObjectId;
else if(obj->variantType == YAFFS_OBJECT_TYPE_HARDLINK)
obj->variant.hardLinkVariant.equivalentObjectId = cp->fileSizeOrEquivalentObjectId;
if(obj->variantType == YAFFS_OBJECT_TYPE_FILE){
ok = yaffs_CheckpointTnodeWorker(obj,
obj->variant.fileVariant.top,
obj->variant.fileVariant.topLevel,
0);
if(ok)
if(obj->variantType == YAFFS_OBJECT_TYPE_FILE){
ok = yaffs_CheckpointTnodeWorker(obj,
obj->variant.fileVariant.top,
obj->variant.fileVariant.topLevel,
0);
if(ok)
/* printf("read tnode at %d\n",baseChunk); */
tn = yaffs_GetTnodeRaw(dev);
if(tn)
/* printf("read tnode at %d\n",baseChunk); */
tn = yaffs_GetTnodeRaw(dev);
if(tn)
}
T(YAFFS_TRACE_CHECKPOINT,(
TSTR("Checkpoint read tnodes %d records, last %d. ok %d" TENDSTR),
nread,baseChunk,ok));
}
T(YAFFS_TRACE_CHECKPOINT,(
TSTR("Checkpoint read tnodes %d records, last %d. ok %d" TENDSTR),
nread,baseChunk,ok));
/* Iterate through the objects in each hash entry,
* dumping them to the checkpointing stream.
*/
/* Iterate through the objects in each hash entry,
* dumping them to the checkpointing stream.
*/
for(i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++){
list_for_each(lh, &dev->objectBucket[i].list) {
if (lh) {
for(i = 0; ok && i < YAFFS_NOBJECT_BUCKETS; i++){
list_for_each(lh, &dev->objectBucket[i].list) {
if (lh) {
T(YAFFS_TRACE_CHECKPOINT,(
TSTR("Checkpoint write object %d parent %d type %d chunk %d obj addr %x" TENDSTR),
cp.objectId,cp.parentId,cp.variantType,cp.chunkId,(unsigned) obj));
T(YAFFS_TRACE_CHECKPOINT,(
TSTR("Checkpoint write object %d parent %d type %d chunk %d obj addr %x" TENDSTR),
cp.objectId,cp.parentId,cp.variantType,cp.chunkId,(unsigned) obj));
/* Dump end of list */
memset(&cp,0xFF,sizeof(yaffs_CheckpointObject));
cp.structType = sizeof(cp);
/* Dump end of list */
memset(&cp,0xFF,sizeof(yaffs_CheckpointObject));
cp.structType = sizeof(cp);
while(ok && !done) {
ok = (yaffs_CheckpointRead(dev,&cp,sizeof(cp)) == sizeof(cp));
if(cp.structType != sizeof(cp)) {
while(ok && !done) {
ok = (yaffs_CheckpointRead(dev,&cp,sizeof(cp)) == sizeof(cp));
if(cp.structType != sizeof(cp)) {
T(YAFFS_TRACE_CHECKPOINT,(TSTR("Checkpoint read object %d parent %d type %d chunk %d " TENDSTR),
cp.objectId,cp.parentId,cp.variantType,cp.chunkId));
T(YAFFS_TRACE_CHECKPOINT,(TSTR("Checkpoint read object %d parent %d type %d chunk %d " TENDSTR),
cp.objectId,cp.parentId,cp.variantType,cp.chunkId));
if(dev->skipCheckpointWrite || !dev->isYaffs2){
T(YAFFS_TRACE_CHECKPOINT,(TSTR("skipping checkpoint write" TENDSTR)));
ok = 0;
}
if(dev->skipCheckpointWrite || !dev->isYaffs2){
T(YAFFS_TRACE_CHECKPOINT,(TSTR("skipping checkpoint write" TENDSTR)));
ok = 0;
}
if(ok){
T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint validity" TENDSTR)));
ok = yaffs_WriteCheckpointValidityMarker(dev,1);
if(ok){
T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint validity" TENDSTR)));
ok = yaffs_WriteCheckpointValidityMarker(dev,1);
T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint validity" TENDSTR)));
ok = yaffs_WriteCheckpointValidityMarker(dev,0);
}
T(YAFFS_TRACE_CHECKPOINT,(TSTR("write checkpoint validity" TENDSTR)));
ok = yaffs_WriteCheckpointValidityMarker(dev,0);
}
if(dev->skipCheckpointRead || !dev->isYaffs2){
T(YAFFS_TRACE_CHECKPOINT,(TSTR("skipping checkpoint read" TENDSTR)));
ok = 0;
}
if(dev->skipCheckpointRead || !dev->isYaffs2){
T(YAFFS_TRACE_CHECKPOINT,(TSTR("skipping checkpoint read" TENDSTR)));
ok = 0;
}
ok = yaffs_ReadCheckpointObjects(dev);
}
if(ok){
T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint validity" TENDSTR)));
ok = yaffs_ReadCheckpointValidityMarker(dev,0);
}
ok = yaffs_ReadCheckpointObjects(dev);
}
if(ok){
T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint validity" TENDSTR)));
ok = yaffs_ReadCheckpointValidityMarker(dev,0);
}
if(ok){
ok = yaffs_ReadCheckpointSum(dev);
T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint checksum %d" TENDSTR),ok));
if(ok){
ok = yaffs_ReadCheckpointSum(dev);
T(YAFFS_TRACE_CHECKPOINT,(TSTR("read checkpoint checksum %d" TENDSTR),ok));
T(YAFFS_TRACE_ALWAYS,(TSTR("save exit: isCheckpointed %d"TENDSTR),dev->isCheckpointed));
return dev->isCheckpointed;
T(YAFFS_TRACE_ALWAYS,(TSTR("save exit: isCheckpointed %d"TENDSTR),dev->isCheckpointed));
return dev->isCheckpointed;
yaffs_ChunkCache *cache;
/* If we can't find the data in the cache, then load the cache */
cache = yaffs_FindChunkCache(in, chunk);
yaffs_ChunkCache *cache;
/* If we can't find the data in the cache, then load the cache */
cache = yaffs_FindChunkCache(in, chunk);
!cache->dirty &&
!yaffs_CheckSpaceForAllocation(in->myDev)){
/* Drop the cache if it was a read cache item and
* no space check has been made for it.
!cache->dirty &&
!yaffs_CheckSpaceForAllocation(in->myDev)){
/* Drop the cache if it was a read cache item and
* no space check has been made for it.
yaffs_Device *dev = in->myDev;
yaffs_AddrToChunk(dev, newSize, &newFullChunks, &newSizeOfPartialChunk);
yaffs_Device *dev = in->myDev;
yaffs_AddrToChunk(dev, newSize, &newFullChunks, &newSizeOfPartialChunk);
__u8 *localBuffer = yaffs_GetTempBuffer(dev, __LINE__);
/* Got to read and rewrite the last chunk with its new size and zero pad */
__u8 *localBuffer = yaffs_GetTempBuffer(dev, __LINE__);
/* Got to read and rewrite the last chunk with its new size and zero pad */
/* Write a new object header.
* show we've shrunk the file, if need be
* Do this only if the file is not in the deleted directories.
/* Write a new object header.
* show we've shrunk the file, if need be
* Do this only if the file is not in the deleted directories.
T(YAFFS_TRACE_SCAN,
(TSTR("yaffs_Scan starts intstartblk %d intendblk %d..." TENDSTR),
dev->internalStartBlock, dev->internalEndBlock));
T(YAFFS_TRACE_SCAN,
(TSTR("yaffs_Scan starts intstartblk %d intendblk %d..." TENDSTR),
dev->internalStartBlock, dev->internalEndBlock));
/*T((" %d %d deleted\n",blk,c)); */
} else if (!tags.chunkUsed) {
/* An unassigned chunk in the block
/*T((" %d %d deleted\n",blk,c)); */
} else if (!tags.chunkUsed) {
/* An unassigned chunk in the block
if(!yaffs_PutChunkIntoFile(in, tags.chunkId, chunk,1))
alloc_failed = 1;
}
if(!yaffs_PutChunkIntoFile(in, tags.chunkId, chunk,1))
alloc_failed = 1;
}
tags.objectId);
if (in && in->variantType != oh->type) {
/* This should not happen, but somehow
tags.objectId);
if (in && in->variantType != oh->type) {
/* This should not happen, but somehow
if (in && oh->shadowsObject > 0) {
yaffs_HandleShadowedObject(dev,
oh->
if (in && oh->shadowsObject > 0) {
yaffs_HandleShadowedObject(dev,
oh->
* Since we might scan a hardlink before its equivalent object is scanned
* we put them all in a list.
* After scanning is complete, we should have all the objects, so we run through this
* Since we might scan a hardlink before its equivalent object is scanned
* we put them all in a list.
* After scanning is complete, we should have all the objects, so we run through this
in->variant.symLinkVariant.alias =
yaffs_CloneString(oh->alias);
if(!in->variant.symLinkVariant.alias)
in->variant.symLinkVariant.alias =
yaffs_CloneString(oh->alias);
if(!in->variant.symLinkVariant.alias)
/* Ok, we've done all the scanning.
* Fix up the hard link chains.
/* Ok, we've done all the scanning.
* Fix up the hard link chains.
chunkData = yaffs_GetTempBuffer(dev, __LINE__);
result = yaffs_ReadChunkWithTagsFromNAND(dev,in->chunkId,chunkData,&tags);
chunkData = yaffs_GetTempBuffer(dev, __LINE__);
result = yaffs_ReadChunkWithTagsFromNAND(dev,in->chunkId,chunkData,&tags);
in->yst_mtime = oh->yst_mtime;
in->yst_ctime = oh->yst_ctime;
in->yst_rdev = oh->yst_rdev;
in->yst_mtime = oh->yst_mtime;
in->yst_ctime = oh->yst_ctime;
in->yst_rdev = oh->yst_rdev;
if(in->variantType == YAFFS_OBJECT_TYPE_SYMLINK){
in->variant.symLinkVariant.alias =
yaffs_CloneString(oh->alias);
if(!in->variant.symLinkVariant.alias)
alloc_failed = 1; /* Not returned to caller */
}
if(in->variantType == YAFFS_OBJECT_TYPE_SYMLINK){
in->variant.symLinkVariant.alias =
yaffs_CloneString(oh->alias);
if(!in->variant.symLinkVariant.alias)
alloc_failed = 1; /* Not returned to caller */
}
dev->sequenceNumber = YAFFS_LOWEST_SEQUENCE_NUMBER;
blockIndex = YMALLOC(nBlocks * sizeof(yaffs_BlockIndex));
dev->sequenceNumber = YAFFS_LOWEST_SEQUENCE_NUMBER;
blockIndex = YMALLOC(nBlocks * sizeof(yaffs_BlockIndex));
chunkData = yaffs_GetTempBuffer(dev, __LINE__);
/* Scan all the blocks to determine their state */
chunkData = yaffs_GetTempBuffer(dev, __LINE__);
/* Scan all the blocks to determine their state */
if(bi->sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA)
bi->blockState = state = YAFFS_BLOCK_STATE_CHECKPOINT;
if(bi->sequenceNumber == YAFFS_SEQUENCE_CHECKPOINT_DATA)
bi->blockState = state = YAFFS_BLOCK_STATE_CHECKPOINT;
T(YAFFS_TRACE_SCAN_DEBUG,
(TSTR("Block scanning block %d state %d seq %d" TENDSTR), blk,
state, sequenceNumber));
T(YAFFS_TRACE_SCAN_DEBUG,
(TSTR("Block scanning block %d state %d seq %d" TENDSTR), blk,
state, sequenceNumber));
} else if (state == YAFFS_BLOCK_STATE_DEAD) {
T(YAFFS_TRACE_BAD_BLOCKS,
(TSTR("block %d is bad" TENDSTR), blk));
} else if (state == YAFFS_BLOCK_STATE_DEAD) {
T(YAFFS_TRACE_BAD_BLOCKS,
(TSTR("block %d is bad" TENDSTR), blk));
blk = blockIndex[blockIterator].block;
bi = yaffs_GetBlockInfo(dev, blk);
blk = blockIndex[blockIterator].block;
bi = yaffs_GetBlockInfo(dev, blk);
!alloc_failed && c >= 0 &&
(state == YAFFS_BLOCK_STATE_NEEDS_SCANNING ||
state == YAFFS_BLOCK_STATE_ALLOCATING); c--) {
!alloc_failed && c >= 0 &&
(state == YAFFS_BLOCK_STATE_NEEDS_SCANNING ||
state == YAFFS_BLOCK_STATE_ALLOCATING); c--) {
chunk = blk * dev->nChunksPerBlock + c;
result = yaffs_ReadChunkWithTagsFromNAND(dev, chunk, NULL,
chunk = blk * dev->nChunksPerBlock + c;
result = yaffs_ReadChunkWithTagsFromNAND(dev, chunk, NULL,
* it is a chunk that was skipped due to failing the erased
* check. Just skip it so that it can be deleted.
* But, more typically, We get here when this is an unallocated
* it is a chunk that was skipped due to failing the erased
* check. Just skip it so that it can be deleted.
* But, more typically, We get here when this is an unallocated
* this is the one being allocated from
*/
if(foundChunksInBlock)
{
/* This is a chunk that was skipped due to failing the erased check */
* this is the one being allocated from
*/
if(foundChunksInBlock)
{
/* This is a chunk that was skipped due to failing the erased check */
} else if (c == 0) {
/* We're looking at the first chunk in the block so the block is unused */
state = YAFFS_BLOCK_STATE_EMPTY;
} else if (c == 0) {
/* We're looking at the first chunk in the block so the block is unused */
state = YAFFS_BLOCK_STATE_EMPTY;
state == YAFFS_BLOCK_STATE_ALLOCATING) {
if(dev->sequenceNumber == bi->sequenceNumber) {
/* this is the block being allocated from */
state == YAFFS_BLOCK_STATE_ALLOCATING) {
if(dev->sequenceNumber == bi->sequenceNumber) {
/* this is the block being allocated from */
}
else {
/* This is a partially written block that is not
* the current allocation block. This block must have
* had a write failure, so set up for retirement.
*/
}
else {
/* This is a partially written block that is not
* the current allocation block. This block must have
* had a write failure, so set up for retirement.
*/
} else if (tags.chunkId > 0) {
/* chunkId > 0 so it is a data chunk... */
unsigned int endpos;
__u32 chunkBase =
(tags.chunkId - 1) * dev->nDataBytesPerChunk;
} else if (tags.chunkId > 0) {
/* chunkId > 0 so it is a data chunk... */
unsigned int endpos;
__u32 chunkBase =
(tags.chunkId - 1) * dev->nDataBytesPerChunk;
* seen an object header yet. Stop this practice once we find an object header.
*/
endpos =
(tags.chunkId -
1) * dev->nDataBytesPerChunk +
tags.byteCount;
* seen an object header yet. Stop this practice once we find an object header.
*/
endpos =
(tags.chunkId -
1) * dev->nDataBytesPerChunk +
tags.byteCount;
oh-> type == YAFFS_OBJECT_TYPE_FILE)||
(tags.extraHeaderInfoAvailable &&
tags.extraObjectType == YAFFS_OBJECT_TYPE_FILE))
oh-> type == YAFFS_OBJECT_TYPE_FILE)||
(tags.extraHeaderInfoAvailable &&
tags.extraObjectType == YAFFS_OBJECT_TYPE_FILE))
YAFFS_OBJECTID_LOSTNFOUND)) {
/* We only load some info, don't fiddle with directory structure */
in->valid = 1;
YAFFS_OBJECTID_LOSTNFOUND)) {
/* We only load some info, don't fiddle with directory structure */
in->valid = 1;
in->yst_mtime = oh->yst_mtime;
in->yst_ctime = oh->yst_ctime;
in->yst_rdev = oh->yst_rdev;
in->yst_mtime = oh->yst_mtime;
in->yst_ctime = oh->yst_ctime;
in->yst_rdev = oh->yst_rdev;
* Since we might scan a hardlink before its equivalent object is scanned
* we put them all in a list.
* After scanning is complete, we should have all the objects, so we run
* Since we might scan a hardlink before its equivalent object is scanned
* we put them all in a list.
* After scanning is complete, we should have all the objects, so we run
/* Ok, we've done all the scanning.
* Fix up the hard link chains.
/* Ok, we've done all the scanning.
* Fix up the hard link chains.
list_for_each(i, &directory->variant.directoryVariant.children) {
if (i) {
l = list_entry(i, yaffs_Object, siblings);
list_for_each(i, &directory->variant.directoryVariant.children) {
if (i) {
l = list_entry(i, yaffs_Object, siblings);
int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize)
{
memset(name, 0, buffSize * sizeof(YCHAR));
int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize)
{
memset(name, 0, buffSize * sizeof(YCHAR));
static int yaffs_CreateInitialDirectories(yaffs_Device *dev)
{
/* Initialise the unlinked, deleted, root and lost and found directories */
static int yaffs_CreateInitialDirectories(yaffs_Device *dev)
{
/* Initialise the unlinked, deleted, root and lost and found directories */
dev->lostNFoundDir = dev->rootDir = NULL;
dev->unlinkedDir = dev->deletedDir = NULL;
dev->unlinkedDir =
yaffs_CreateFakeDirectory(dev, YAFFS_OBJECTID_UNLINKED, S_IFDIR);
dev->lostNFoundDir = dev->rootDir = NULL;
dev->unlinkedDir = dev->deletedDir = NULL;
dev->unlinkedDir =
yaffs_CreateFakeDirectory(dev, YAFFS_OBJECTID_UNLINKED, S_IFDIR);
dev->lostNFoundDir =
yaffs_CreateFakeDirectory(dev, YAFFS_OBJECTID_LOSTNFOUND,
YAFFS_LOSTNFOUND_MODE | S_IFDIR);
dev->lostNFoundDir =
yaffs_CreateFakeDirectory(dev, YAFFS_OBJECTID_LOSTNFOUND,
YAFFS_LOSTNFOUND_MODE | S_IFDIR);
if(dev->lostNFoundDir && dev->rootDir && dev->unlinkedDir && dev->deletedDir){
yaffs_AddObjectToDirectory(dev->rootDir, dev->lostNFoundDir);
return YAFFS_OK;
}
if(dev->lostNFoundDir && dev->rootDir && dev->unlinkedDir && dev->deletedDir){
yaffs_AddObjectToDirectory(dev->rootDir, dev->lostNFoundDir);
return YAFFS_OK;
}
- if ((dev->isYaffs2 && dev->nDataBytesPerChunk < 1024) ||
- (!dev->isYaffs2 && dev->nDataBytesPerChunk != 512) ||
- dev->nChunksPerBlock < 2 ||
- dev->nReservedBlocks < 2 ||
- dev->internalStartBlock <= 0 ||
- dev->internalEndBlock <= 0 ||
+ if ((dev->isYaffs2 && dev->nDataBytesPerChunk < 1024) ||
+ (!dev->isYaffs2 && dev->nDataBytesPerChunk != 512) ||
+ dev->nChunksPerBlock < 2 ||
+ dev->nReservedBlocks < 2 ||
+ dev->internalStartBlock <= 0 ||
+ dev->internalEndBlock <= 0 ||
/* Set up tnode width if wide tnodes are enabled. */
if(!dev->wideTnodesDisabled){
/* bits must be even so that we end up with 32-bit words */
/* Set up tnode width if wide tnodes are enabled. */
if(!dev->wideTnodesDisabled){
/* bits must be even so that we end up with 32-bit words */
/* Level0 Tnodes are 16 bits or wider (if wide tnodes are enabled),
* so if the bitwidth of the
* chunk range we're using is greater than 16 we need
* to figure out chunk shift and chunkGroupSize
*/
/* Level0 Tnodes are 16 bits or wider (if wide tnodes are enabled),
* so if the bitwidth of the
* chunk range we're using is greater than 16 we need
* to figure out chunk shift and chunkGroupSize
*/
for (i = 0; i < dev->nShortOpCaches && buf; i++) {
dev->srCache[i].object = NULL;
dev->srCache[i].lastUse = 0;
for (i = 0; i < dev->nShortOpCaches && buf; i++) {
dev->srCache[i].object = NULL;
dev->srCache[i].lastUse = 0;
*/
yaffs_DeinitialiseBlocks(dev);
yaffs_DeinitialiseTnodes(dev);
yaffs_DeinitialiseObjects(dev);
*/
yaffs_DeinitialiseBlocks(dev);
yaffs_DeinitialiseTnodes(dev);
yaffs_DeinitialiseObjects(dev);
/* Now we figure out how much to reserve for the checkpoint and report that... */
blocksForCheckpoint = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint;
if(blocksForCheckpoint < 0)
blocksForCheckpoint = 0;
/* Now we figure out how much to reserve for the checkpoint and report that... */
blocksForCheckpoint = dev->nCheckpointReservedBlocks - dev->blocksInCheckpoint;
if(blocksForCheckpoint < 0)
blocksForCheckpoint = 0;