*/
const char *yaffs_guts_c_version =
- "$Id: yaffs_guts.c,v 1.23 2005-11-07 07:19:34 charles Exp $";
+ "$Id: yaffs_guts.c,v 1.30 2006-03-01 08:14:32 charles Exp $";
#include "yportenv.h"
static Y_INLINE int yaffs_HashFunction(int n)
{
+ n = abs(n);
return (n % YAFFS_NOBJECT_BUCKETS);
}
static int yaffs_CreateTnodes(yaffs_Device * dev, int nTnodes)
{
int i;
+ int tnodeSize;
yaffs_Tnode *newTnodes;
+ __u8 *mem;
+ yaffs_Tnode *curr;
+ yaffs_Tnode *next;
yaffs_TnodeList *tnl;
if (nTnodes < 1)
return YAFFS_OK;
+
+ /* 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;
/* make these things */
- newTnodes = YMALLOC(nTnodes * sizeof(yaffs_Tnode));
+ newTnodes = YMALLOC(nTnodes * tnodeSize);
+ mem = (__u8 *)newTnodes;
if (!newTnodes) {
T(YAFFS_TRACE_ERROR,
}
/* Hook them into the free list */
+#if 0
for (i = 0; i < nTnodes - 1; i++) {
newTnodes[i].internal[0] = &newTnodes[i + 1];
#ifdef CONFIG_YAFFS_TNODE_LIST_DEBUG
newTnodes[nTnodes - 1].internal[YAFFS_NTNODES_INTERNAL] = (void *)1;
#endif
dev->freeTnodes = newTnodes;
+#else
+ /* New hookup for wide tnodes */
+ for(i = 0; i < nTnodes -1; i++) {
+ curr = (yaffs_Tnode *) &mem[i * tnodeSize];
+ next = (yaffs_Tnode *) &mem[(i+1) * tnodeSize];
+ curr->internal[0] = next;
+ }
+
+ curr = (yaffs_Tnode *) &mem[(nTnodes - 1) * tnodeSize];
+ curr->internal[0] = dev->freeTnodes;
+ dev->freeTnodes = (yaffs_Tnode *)mem;
+
+#endif
+
+
dev->nFreeTnodes += nTnodes;
dev->nTnodesCreated += nTnodes;
dev->freeTnodes = dev->freeTnodes->internal[0];
dev->nFreeTnodes--;
/* zero out */
- memset(tn, 0, sizeof(yaffs_Tnode));
+ memset(tn, 0, (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8);
}
return tn;
}
+
+void yaffs_PutLevel0Tnode(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos, unsigned val)
+{
+ __u32 *map = (__u32 *)tn;
+ __u32 bitInMap;
+ __u32 bitInWord;
+ __u32 wordInMap;
+ __u32 mask;
+
+ pos &= YAFFS_TNODES_LEVEL0_MASK;
+ val >>= dev->chunkGroupBits;
+
+ bitInMap = pos * dev->tnodeWidth;
+ wordInMap = bitInMap /32;
+ bitInWord = bitInMap & (32 -1);
+
+ mask = dev->tnodeMask << bitInWord;
+
+ map[wordInMap] &= ~mask;
+ map[wordInMap] |= (mask & (val << bitInWord));
+
+ if(dev->tnodeWidth > (32-bitInWord)) {
+ bitInWord = (32 - bitInWord);
+ wordInMap++;;
+ mask = dev->tnodeMask >> (/*dev->tnodeWidth -*/ bitInWord);
+ map[wordInMap] &= ~mask;
+ map[wordInMap] |= (mask & (val >> bitInWord));
+ }
+}
+
+__u32 yaffs_GetChunkGroupBase(yaffs_Device *dev, yaffs_Tnode *tn, unsigned pos)
+{
+ __u32 *map = (__u32 *)tn;
+ __u32 bitInMap;
+ __u32 bitInWord;
+ __u32 wordInMap;
+ __u32 val;
+
+ pos &= YAFFS_TNODES_LEVEL0_MASK;
+
+ bitInMap = pos * dev->tnodeWidth;
+ wordInMap = bitInMap /32;
+ bitInWord = bitInMap & (32 -1);
+
+ val = map[wordInMap] >> bitInWord;
+
+ if(dev->tnodeWidth > (32-bitInWord)) {
+ bitInWord = (32 - bitInWord);
+ wordInMap++;;
+ val |= (map[wordInMap] << bitInWord);
+ }
+
+ val &= dev->tnodeMask;
+ val <<= dev->chunkGroupBits;
+
+ return val;
+}
+
/* ------------------- End of individual tnode manipulation -----------------*/
/* ---------Functions to manipulate the look-up tree (made up of tnodes) ------
for (i = YAFFS_NTNODES_LEVEL0 - 1; i >= 0 && !hitLimit;
i--) {
- if (tn->level0[i]) {
+ theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
+ if (theChunk) {
chunkInInode =
(chunkOffset <<
YAFFS_TNODES_LEVEL0_BITS) + i;
- theChunk =
- tn->level0[i] << dev->
- chunkGroupBits;
-
foundChunk =
yaffs_FindChunkInGroup(dev,
theChunk,
}
- tn->level0[i] = 0;
+ yaffs_PutLevel0Tnode(dev,tn,i,0);
}
}
} else if (level == 0) {
for (i = YAFFS_NTNODES_LEVEL0 - 1; i >= 0; i--) {
- if (tn->level0[i]) {
+ theChunk = yaffs_GetChunkGroupBase(dev,tn,i);
+ if (theChunk) {
/* Note this does not find the real chunk, only the chunk group.
* We make an assumption that a chunk group is not larger than
* a block.
*/
- theChunk =
- (tn->level0[i] << dev->
- chunkGroupBits);
-
yaffs_SoftDeleteChunk(dev, theChunk);
- tn->level0[i] = 0;
+ yaffs_PutLevel0Tnode(dev,tn,i,0);
}
}
("yaffs: About to finally delete object %d"
TENDSTR), object->objectId));
yaffs_DoGenericObjectDeletion(object);
+ object->myDev->nDeletedFiles--;
}
}
tn = yaffs_FindLevel0Tnode(dev, &in->variant.fileVariant, chunkInInode);
if (tn) {
- theChunk =
- tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] <<
- dev->chunkGroupBits;
+ theChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode);
retVal =
yaffs_FindChunkInGroup(dev, theChunk, tags, in->objectId,
if (tn) {
- theChunk =
- tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] << dev->
- chunkGroupBits;
+ theChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode);
retVal =
yaffs_FindChunkInGroup(dev, theChunk, tags, in->objectId,
/* Delete the entry in the filestructure (if found) */
if (retVal != -1) {
- tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] = 0;
+ yaffs_PutLevel0Tnode(dev,tn,chunkInInode,0);
}
} else {
/*T(("No level 0 found for %d\n", chunkInInode)); */
if (tn) {
- theChunk =
- tn->level0[chunk & YAFFS_TNODES_LEVEL0_MASK] << in->
- myDev->chunkGroupBits;
+ theChunk = yaffs_GetChunkGroupBase(dev,tn,chunk);
if (yaffs_CheckChunkBits
(dev, theChunk / dev->nChunksPerBlock,
return YAFFS_FAIL;
}
- existingChunk = tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK];
+ existingChunk = yaffs_GetChunkGroupBase(dev,tn,chunkInInode);
if (inScan != 0) {
/* If we're scanning then we need to test for duplicates
in->nDataChunks++;
}
- tn->level0[chunkInInode & YAFFS_TNODES_LEVEL0_MASK] =
- (chunkInNAND >> dev->chunkGroupBits);
+ yaffs_PutLevel0Tnode(dev,tn,chunkInInode,chunkInNAND);
return YAFFS_OK;
}
return YAFFS_OK;
}
+static void yaffs_CheckObjectDetailsLoaded(yaffs_Object *in)
+{
+ __u8 *chunkData;
+ yaffs_ObjectHeader *oh;
+ yaffs_Device *dev = in->myDev;
+
+ if(in->lazyLoaded){
+ in->lazyLoaded = 0;
+ chunkData = yaffs_GetTempBuffer(dev, __LINE__);
+
+ yaffs_ReadChunkWithTagsFromNAND(dev,in->chunkId,chunkData,NULL);
+ oh = (yaffs_ObjectHeader *) chunkData;
+
+ in->yst_mode = oh->yst_mode;
+#ifdef CONFIG_YAFFS_WINCE
+ in->win_atime[0] = oh->win_atime[0];
+ in->win_ctime[0] = oh->win_ctime[0];
+ in->win_mtime[0] = oh->win_mtime[0];
+ in->win_atime[1] = oh->win_atime[1];
+ in->win_ctime[1] = oh->win_ctime[1];
+ in->win_mtime[1] = oh->win_mtime[1];
+#else
+ in->yst_uid = oh->yst_uid;
+ in->yst_gid = oh->yst_gid;
+ in->yst_atime = oh->yst_atime;
+ in->yst_mtime = oh->yst_mtime;
+ in->yst_ctime = oh->yst_ctime;
+ in->yst_rdev = oh->yst_rdev;
+
+#endif
+ yaffs_SetObjectName(in, oh->name);
+
+ if(in->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
+ in->variant.symLinkVariant.alias =
+ yaffs_CloneString(oh->alias);
+
+ yaffs_ReleaseTempBuffer(dev,chunkData, __LINE__);
+ }
+}
+
static int yaffs_ScanBackwards(yaffs_Device * dev)
{
yaffs_ExtendedTags tags;
yaffs_Object *in;
yaffs_Object *parent;
int nBlocks = dev->internalEndBlock - dev->internalStartBlock + 1;
-
+ int itsUnlinked;
__u8 *chunkData;
+
+ int fileSize;
+ int isShrink;
+ int equivalentObjectId;
+
yaffs_BlockIndex *blockIndex = NULL;
tags.extraObjectType);
}
- if (!in || !in->valid) {
+ if (!in ||
+#ifdef CONFIG_YAFFS_DISABLE_LAZY_LOAD
+ !in->valid ||
+#endif
+ tags.extraShadows ||
+ (!in->valid &&
+ (tags.objectId == YAFFS_OBJECTID_ROOT ||
+ tags.objectId == YAFFS_OBJECTID_LOSTNFOUND))
+ ) {
/* If we don't have valid info then we need to read the chunk
* TODO In future we can probably defer reading the chunk and
* we first have to suck out resize info if it is a file.
*/
- if ((in->variantType ==
- YAFFS_OBJECT_TYPE_FILE) && ((oh
- &&
- oh->
- type
- ==
- YAFFS_OBJECT_TYPE_FILE)
- ||
- (tags.
- extraHeaderInfoAvailable
- &&
- tags.
- extraObjectType
- ==
- YAFFS_OBJECT_TYPE_FILE))
+ if ((in->variantType == YAFFS_OBJECT_TYPE_FILE) &&
+ ((oh &&
+ oh-> type == YAFFS_OBJECT_TYPE_FILE)||
+ (tags.extraHeaderInfoAvailable &&
+ tags.extraObjectType == YAFFS_OBJECT_TYPE_FILE))
) {
__u32 thisSize =
(oh) ? oh->fileSize : tags.
YAFFS_OBJECTID_LOSTNFOUND)) {
/* We only load some info, don't fiddle with directory structure */
in->valid = 1;
- in->variantType = oh->type;
+
+ if(oh) {
+ in->variantType = oh->type;
- in->yst_mode = oh->yst_mode;
+ in->yst_mode = oh->yst_mode;
#ifdef CONFIG_YAFFS_WINCE
- in->win_atime[0] = oh->win_atime[0];
- in->win_ctime[0] = oh->win_ctime[0];
- in->win_mtime[0] = oh->win_mtime[0];
- in->win_atime[1] = oh->win_atime[1];
- in->win_ctime[1] = oh->win_ctime[1];
- in->win_mtime[1] = oh->win_mtime[1];
+ in->win_atime[0] = oh->win_atime[0];
+ in->win_ctime[0] = oh->win_ctime[0];
+ in->win_mtime[0] = oh->win_mtime[0];
+ in->win_atime[1] = oh->win_atime[1];
+ in->win_ctime[1] = oh->win_ctime[1];
+ in->win_mtime[1] = oh->win_mtime[1];
#else
- in->yst_uid = oh->yst_uid;
- in->yst_gid = oh->yst_gid;
- in->yst_atime = oh->yst_atime;
- in->yst_mtime = oh->yst_mtime;
- in->yst_ctime = oh->yst_ctime;
- in->yst_rdev = oh->yst_rdev;
+ in->yst_uid = oh->yst_uid;
+ in->yst_gid = oh->yst_gid;
+ in->yst_atime = oh->yst_atime;
+ in->yst_mtime = oh->yst_mtime;
+ in->yst_ctime = oh->yst_ctime;
+ in->yst_rdev = oh->yst_rdev;
+
#endif
+ } else {
+ in->variantType = tags.extraObjectType;
+ in->lazyLoaded = 1;
+ }
+
in->chunkId = chunk;
} else if (!in->valid) {
/* we need to load this info */
in->valid = 1;
- in->variantType = oh->type;
+ in->chunkId = chunk;
+
+ if(oh) {
+ in->variantType = oh->type;
- in->yst_mode = oh->yst_mode;
+ in->yst_mode = oh->yst_mode;
#ifdef CONFIG_YAFFS_WINCE
- in->win_atime[0] = oh->win_atime[0];
- in->win_ctime[0] = oh->win_ctime[0];
- in->win_mtime[0] = oh->win_mtime[0];
- in->win_atime[1] = oh->win_atime[1];
- in->win_ctime[1] = oh->win_ctime[1];
- in->win_mtime[1] = oh->win_mtime[1];
+ in->win_atime[0] = oh->win_atime[0];
+ in->win_ctime[0] = oh->win_ctime[0];
+ in->win_mtime[0] = oh->win_mtime[0];
+ in->win_atime[1] = oh->win_atime[1];
+ in->win_ctime[1] = oh->win_ctime[1];
+ in->win_mtime[1] = oh->win_mtime[1];
#else
- in->yst_uid = oh->yst_uid;
- in->yst_gid = oh->yst_gid;
- in->yst_atime = oh->yst_atime;
- in->yst_mtime = oh->yst_mtime;
- in->yst_ctime = oh->yst_ctime;
- in->yst_rdev = oh->yst_rdev;
+ in->yst_uid = oh->yst_uid;
+ in->yst_gid = oh->yst_gid;
+ in->yst_atime = oh->yst_atime;
+ in->yst_mtime = oh->yst_mtime;
+ in->yst_ctime = oh->yst_ctime;
+ in->yst_rdev = oh->yst_rdev;
#endif
- in->chunkId = chunk;
- if (oh->shadowsObject > 0) {
- yaffs_HandleShadowedObject(dev,
+ if (oh->shadowsObject > 0)
+ yaffs_HandleShadowedObject(dev,
oh->
shadowsObject,
1);
+
+
+ yaffs_SetObjectName(in, oh->name);
+ parent =
+ yaffs_FindOrCreateObjectByNumber
+ (dev, oh->parentObjectId,
+ YAFFS_OBJECT_TYPE_DIRECTORY);
+
+ fileSize = oh->fileSize;
+ isShrink = oh->isShrink;
+ equivalentObjectId = oh->equivalentObjectId;
+
}
+ else {
+ in->variantType = tags.extraObjectType;
+ parent =
+ yaffs_FindOrCreateObjectByNumber
+ (dev, tags.extraParentObjectId,
+ YAFFS_OBJECT_TYPE_DIRECTORY);
+ fileSize = tags.extraFileLength;
+ isShrink = tags.extraIsShrinkHeader;
+ equivalentObjectId = tags.extraEquivalentObjectId;
+ in->lazyLoaded = 1;
- yaffs_SetObjectName(in, oh->name);
+ }
in->dirty = 0;
/* directory stuff...
* hook up to parent
*/
- parent =
- yaffs_FindOrCreateObjectByNumber
- (dev, oh->parentObjectId,
- YAFFS_OBJECT_TYPE_DIRECTORY);
if (parent->variantType ==
YAFFS_OBJECT_TYPE_UNKNOWN) {
/* Set up as a directory */
yaffs_AddObjectToDirectory(parent, in);
- if ((parent == dev->deletedDir ||
- parent == dev->unlinkedDir)) {
- /* If it is unlinked at start up then it wants deleting */
- in->deleted = 1;
- }
+ itsUnlinked = (parent == dev->deletedDir) ||
+ (parent == dev->unlinkedDir);
- if (oh->isShrink) {
+ if (isShrink) {
/* Mark the block as having a shrinkHeader */
bi->hasShrinkHeader = 1;
}
case YAFFS_OBJECT_TYPE_FILE:
if (in->variant.fileVariant.
- scannedFileSize <
- oh->fileSize) {
+ scannedFileSize < fileSize) {
/* This covers the case where the file size is greater
* than where the data is
* This will happen if the file is resized to be larger
* than its current data extents.
*/
- in->variant.fileVariant.fileSize =
- oh->fileSize;
+ in->variant.fileVariant.fileSize = fileSize;
in->variant.fileVariant.scannedFileSize =
in->variant.fileVariant.fileSize;
}
- if (oh->isShrink &&
- in->variant.fileVariant.shrinkSize >
- oh->fileSize) {
- in->variant.fileVariant.shrinkSize =
- oh->fileSize;
+ if (isShrink &&
+ in->variant.fileVariant.shrinkSize > fileSize) {
+ in->variant.fileVariant.shrinkSize = fileSize;
}
break;
case YAFFS_OBJECT_TYPE_HARDLINK:
- in->variant.hardLinkVariant.equivalentObjectId =
- oh->equivalentObjectId;
- in->hardLinks.next =
+ if(!itsUnlinked) {
+ in->variant.hardLinkVariant.equivalentObjectId =
+ equivalentObjectId;
+ in->hardLinks.next =
(struct list_head *) hardList;
- hardList = in;
+ hardList = in;
+ }
break;
case YAFFS_OBJECT_TYPE_DIRECTORY:
/* Do nothing */
/* Do nothing */
break;
case YAFFS_OBJECT_TYPE_SYMLINK:
- in->variant.symLinkVariant.
- alias =
+ if(oh)
+ in->variant.symLinkVariant.alias =
yaffs_CloneString(oh->
alias);
break;
list_for_each(i, &directory->variant.directoryVariant.children) {
if (i) {
l = list_entry(i, yaffs_Object, siblings);
+
+ yaffs_CheckObjectDetailsLoaded(l);
/* Special case for lost-n-found */
if (l->objectId == YAFFS_OBJECTID_LOSTNFOUND) {
int yaffs_GetObjectName(yaffs_Object * obj, YCHAR * name, int buffSize)
{
memset(name, 0, buffSize * sizeof(YCHAR));
+
+ yaffs_CheckObjectDetailsLoaded(obj);
if (obj->objectId == YAFFS_OBJECTID_LOSTNFOUND) {
yaffs_strncpy(name, YAFFS_LOSTNFOUND_NAME, buffSize - 1);
if (extraBits > 0)
bits++;
-
- /* Level0 Tnodes are 16 bits, so if the bitwidth of the
+
+ /* 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 */
+ if(bits & 1)
+ bits++;
+ if(bits < 16)
+ dev->tnodeWidth = 16;
+ else
+ dev->tnodeWidth = bits;
+ }
+ else
+ dev->tnodeWidth = 16;
+
+ dev->tnodeMask = (1<<dev->tnodeWidth)-1;
+
+ /* 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
*/
- if (bits <= 16) {
+
+ if (bits <= dev->tnodeWidth)
dev->chunkGroupBits = 0;
- } else {
- dev->chunkGroupBits = bits - 16;
- }
+ else
+ dev->chunkGroupBits = bits - dev->tnodeWidth;
+
dev->chunkGroupSize = 1 << dev->chunkGroupBits;
nFree = yaffs_CountFreeChunks(dev);
#endif
+ nFree += dev->nDeletedFiles;
+
/* Now count the number of dirty chunks in the cache and subtract those */
{