*/
const char *yaffs_guts_c_version =
- "$Id: yaffs_guts.c,v 1.99 2009-12-14 22:03:05 charles Exp $";
+ "$Id: yaffs_guts.c,v 1.106 2010-01-11 04:06:46 charles Exp $";
#include "yportenv.h"
+#include "yaffs_trace.h"
#include "yaffsinterface.h"
#include "yaffs_guts.h"
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));
+ (TSTR("Verifying object header tags %p obj %p oh %p"TENDSTR),
+ tags, obj, oh));
return;
}
dev->freeTnodes = NULL;
dev->nFreeTnodes = 0;
+ dev->nTnodesCreated = 0;
}
static void yaffs_InitialiseTnodes(yaffs_Device *dev)
* level 0 tnode entries must be zeroed out.
* Could also use this for file deletion, but that's probably better handled
* by a special case.
+ *
+ * This function is recursive. For levels > 0 the function is called again on
+ * any sub-tree. For level == 0 we just check if the sub-tree has data.
+ * If there is no data in a subtree then it is pruned.
*/
static yaffs_Tnode *yaffs_PruneWorker(yaffs_Device *dev, yaffs_Tnode *tn,
if (tn) {
hasData = 0;
- for (i = 0; i < YAFFS_NTNODES_INTERNAL; i++) {
- if (tn->internal[i] && level > 0) {
- tn->internal[i] =
- yaffs_PruneWorker(dev, tn->internal[i],
- level - 1,
- (i == 0) ? del0 : 1);
+ if(level > 0){
+ for (i = 0; i < YAFFS_NTNODES_INTERNAL; i++) {
+ if (tn->internal[i]) {
+ tn->internal[i] =
+ yaffs_PruneWorker(dev, tn->internal[i],
+ level - 1,
+ (i == 0) ? del0 : 1);
+ }
+
+ if (tn->internal[i])
+ hasData++;
}
+ } else {
+ int tnodeSize;
+ __u32 *map = (__u32 *)tn;
+ tnodeSize = (dev->tnodeWidth * YAFFS_NTNODES_LEVEL0)/8;
- if (tn->internal[i])
- hasData++;
- }
+ if (tnodeSize < sizeof(yaffs_Tnode))
+ tnodeSize = sizeof(yaffs_Tnode);
+ tnodeSize /= sizeof(__u32);
+
+ for(i = 0; !hasData && i < tnodeSize; i++){
+ if(map[i])
+ hasData++;
+ }
+ }
if (hasData == 0 && del0) {
/* Free and return NULL */
{
yaffs_Device *dev = tn->myDev;
-#ifdef __KERNEL__
T(YAFFS_TRACE_OS, (TSTR("FreeObject %p inode %p"TENDSTR), tn, tn->myInode));
-#endif
if (tn->parent)
YBUG();
YBUG();
-#ifdef __KERNEL__
if (tn->myInode) {
/* We're still hooked up to a cached inode.
* Don't delete now, but mark for later deletion
tn->deferedFree = 1;
return;
}
-#endif
yaffs_UnhashObject(tn);
dev->freeObjects = NULL;
dev->nFreeObjects = 0;
+ dev->nObjectsCreated = 0;
}
static void yaffs_InitialiseObjects(yaffs_Device *dev)
cp.structType = sizeof(cp);
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.hdrChunk, (unsigned) obj));
+ TSTR("Checkpoint write object %d parent %d type %d chunk %d obj addr %p" TENDSTR),
+ cp.objectId, cp.parentId, cp.variantType, cp.hdrChunk, obj));
ok = (yaffs_CheckpointWrite(dev, &cp, sizeof(cp)) == sizeof(cp));
ok = (yaffs_CheckpointRead(dev, &cp, sizeof(cp)) == sizeof(cp));
if (cp.structType != sizeof(cp)) {
T(YAFFS_TRACE_CHECKPOINT, (TSTR("struct size %d instead of %d ok %d"TENDSTR),
- cp.structType, sizeof(cp), ok));
+ cp.structType, (int)sizeof(cp), ok));
ok = 0;
}
int retVal;
int immediateDeletion = 0;
-#ifdef __KERNEL__
if (!in->myInode)
immediateDeletion = 1;
-#else
- if (in->inUse <= 0)
- immediateDeletion = 1;
-#endif
if (immediateDeletion) {
retVal =
int immediateDeletion = 0;
-#ifdef __KERNEL__
if (!obj->myInode)
immediateDeletion = 1;
-#else
- if (obj->inUse <= 0)
- immediateDeletion = 1;
-#endif
if(obj)
yaffs_UpdateParent(obj->parent);
* Instead, we do the following:
* - Select a hardlink.
* - Unhook it from the hard links
- * - Unhook it from its parent directory (so that the rename can work)
+ * - Move it from its parent directory (so that the rename can work)
* - Rename the object to the hardlink's name.
* - Delete the hardlink
*/
yaffs_Object *hl;
+ yaffs_Object *parent;
int retVal;
YCHAR name[YAFFS_MAX_NAME_LENGTH + 1];
hl = ylist_entry(obj->hardLinks.next, yaffs_Object, hardLinks);
+ yaffs_GetObjectName(hl, name, YAFFS_MAX_NAME_LENGTH + 1);
+ parent = hl->parent;
+
ylist_del_init(&hl->hardLinks);
- ylist_del_init(&hl->siblings);
- yaffs_GetObjectName(hl, name, YAFFS_MAX_NAME_LENGTH + 1);
+ yaffs_AddObjectToDirectory(obj->myDev->unlinkedDir, hl);
- retVal = yaffs_ChangeObjectName(obj, hl->parent, name, 0, 0);
+ retVal = yaffs_ChangeObjectName(obj,parent, name, 0, 0);
if (retVal == YAFFS_OK)
retVal = yaffs_DoGenericObjectDeletion(hl);
do { \
if (sizeof(structure) != syze) { \
T(YAFFS_TRACE_ALWAYS, (TSTR("%s should be %d but is %d\n" TENDSTR),\
- name, syze, sizeof(structure))); \
+ name, syze, (int) sizeof(structure))); \
return YAFFS_FAIL; \
} \
} while (0)
/* yaffs_CheckStruct(yaffs_TagsUnion,8,"yaffs_TagsUnion"); */
/* yaffs_CheckStruct(yaffs_Spare,16,"yaffs_Spare"); */
#ifndef CONFIG_YAFFS_TNODE_LIST_DEBUG
- yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode");
+/* yaffs_CheckStruct(yaffs_Tnode, 2 * YAFFS_NTNODES_LEVEL0, "yaffs_Tnode"); */
#endif
#ifndef CONFIG_YAFFS_WINCE
yaffs_CheckStruct(yaffs_ObjectHeader, 512, "yaffs_ObjectHeader");