Runtime disbale of lazy loading. Fix problem where resize was breading rename shadowing
[yaffs2.git] / yaffs_guts.c
index 2acfb8e031b4e83f18b1bb03d1a28d25f8ba14a1..74b73ddefc3d36c351b25b8b3041380c703d3ee7 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 const char *yaffs_guts_c_version =
  */
 
 const char *yaffs_guts_c_version =
-    "$Id: yaffs_guts.c,v 1.89 2009-09-09 00:56:53 charles Exp $";
+    "$Id: yaffs_guts.c,v 1.91 2009-10-15 00:45:46 charles Exp $";
 
 #include "yportenv.h"
 
 
 #include "yportenv.h"
 
@@ -2466,6 +2466,8 @@ int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName,
        yaffs_Object *obj = NULL;
        yaffs_Object *existingTarget = NULL;
        int force = 0;
        yaffs_Object *obj = NULL;
        yaffs_Object *existingTarget = NULL;
        int force = 0;
+       int result;
+       yaffs_Device *dev;
 
 
        if (!oldDir || oldDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
 
 
        if (!oldDir || oldDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
@@ -2473,6 +2475,8 @@ int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName,
        if (!newDir || newDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
                YBUG();
 
        if (!newDir || newDir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
                YBUG();
 
+       dev = oldDir->myDev;
+
 #ifdef CONFIG_YAFFS_CASE_INSENSITIVE
        /* Special case for case insemsitive systems (eg. WinCE).
         * While look-up is case insensitive, the name isn't.
 #ifdef CONFIG_YAFFS_CASE_INSENSITIVE
        /* Special case for case insemsitive systems (eg. WinCE).
         * While look-up is case insensitive, the name isn't.
@@ -2482,7 +2486,7 @@ int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName,
                force = 1;
 #endif
 
                force = 1;
 #endif
 
-       else if (yaffs_strlen(newName) > YAFFS_MAX_NAME_LENGTH)
+       if(yaffs_strlen(newName) > YAFFS_MAX_NAME_LENGTH)
                /* ENAMETOOLONG */
                return YAFFS_FAIL;
 
                /* ENAMETOOLONG */
                return YAFFS_FAIL;
 
@@ -2500,17 +2504,26 @@ int yaffs_RenameObject(yaffs_Object *oldDir, const YCHAR *oldName,
                        return YAFFS_FAIL;      /* EEXIST or ENOTEMPTY */
                } else if (existingTarget && existingTarget != obj) {
                        /* Nuke the target first, using shadowing,
                        return YAFFS_FAIL;      /* EEXIST or ENOTEMPTY */
                } else if (existingTarget && existingTarget != obj) {
                        /* Nuke the target first, using shadowing,
-                        * but only if it isn't the same object
+                        * but only if it isn't the same object.
+                        *
+                        * Note we must disable gc otherwise it can mess up the shadowing.
+                        *
                         */
                         */
+                       dev->isDoingGC=1;
                        yaffs_ChangeObjectName(obj, newDir, newName, force,
                                                existingTarget->objectId);
                        yaffs_ChangeObjectName(obj, newDir, newName, force,
                                                existingTarget->objectId);
+                       existingTarget->isShadowed = 1;
                        yaffs_UnlinkObject(existingTarget);
                        yaffs_UnlinkObject(existingTarget);
+                       dev->isDoingGC=0;
                }
                }
+
+               result = yaffs_ChangeObjectName(obj, newDir, newName, 1, 0);
+
                yaffs_UpdateParent(oldDir);
                if(newDir != oldDir)
                        yaffs_UpdateParent(newDir);
                yaffs_UpdateParent(oldDir);
                if(newDir != oldDir)
                        yaffs_UpdateParent(newDir);
-
-               return yaffs_ChangeObjectName(obj, newDir, newName, 1, 0);
+               
+               return result;
        }
        return YAFFS_FAIL;
 }
        }
        return YAFFS_FAIL;
 }
@@ -5031,11 +5044,13 @@ int yaffs_ResizeFile(yaffs_Object *in, loff_t newSize)
        }
 
 
        }
 
 
-       /* Write a new object header.
+       /* Write a new object header to reflect the resize.
         * show we've shrunk the file, if need be
         * show we've shrunk the file, if need be
-        * Do this only if the file is not in the deleted directories.
+        * Do this only if the file is not in the deleted directories
+        * and is not shadowed.
         */
        if (in->parent &&
         */
        if (in->parent &&
+           !in->isShadowed &&
            in->parent->objectId != YAFFS_OBJECTID_UNLINKED &&
            in->parent->objectId != YAFFS_OBJECTID_DELETED)
                yaffs_UpdateObjectHeader(in, NULL, 0,
            in->parent->objectId != YAFFS_OBJECTID_UNLINKED &&
            in->parent->objectId != YAFFS_OBJECTID_DELETED)
                yaffs_UpdateObjectHeader(in, NULL, 0,
@@ -5060,23 +5075,27 @@ loff_t yaffs_GetFileSize(yaffs_Object *obj)
 
 
 
 
 
 
-int yaffs_FlushFile(yaffs_Object *in, int updateTime)
+int yaffs_FlushFile(yaffs_Object *in, int updateTime, int dataSync)
 {
        int retVal;
        if (in->dirty) {
                yaffs_FlushFilesChunkCache(in);
 {
        int retVal;
        if (in->dirty) {
                yaffs_FlushFilesChunkCache(in);
-               if (updateTime) {
+               if(dataSync) /* Only sync data */
+                       retVal=YAFFS_OK;
+               else {
+                       if (updateTime) {
 #ifdef CONFIG_YAFFS_WINCE
 #ifdef CONFIG_YAFFS_WINCE
-                       yfsd_WinFileTimeNow(in->win_mtime);
+                               yfsd_WinFileTimeNow(in->win_mtime);
 #else
 
 #else
 
-                       in->yst_mtime = Y_CURRENT_TIME;
+                               in->yst_mtime = Y_CURRENT_TIME;
 
 #endif
 
 #endif
-               }
+                       }
 
 
-               retVal = (yaffs_UpdateObjectHeader(in, NULL, 0, 0, 0) >=
-                       0) ? YAFFS_OK : YAFFS_FAIL;
+                       retVal = (yaffs_UpdateObjectHeader(in, NULL, 0, 0, 0) >=
+                               0) ? YAFFS_OK : YAFFS_FAIL;
+               }
        } else {
                retVal = YAFFS_OK;
        }
        } else {
                retVal = YAFFS_OK;
        }
@@ -5346,7 +5365,8 @@ static void yaffs_HandleShadowedObject(yaffs_Device *dev, int objId,
                /* Handle YAFFS2 case (backward scanning)
                 * If the shadowed object exists then ignore.
                 */
                /* Handle YAFFS2 case (backward scanning)
                 * If the shadowed object exists then ignore.
                 */
-               if (yaffs_FindObjectByNumber(dev, objId))
+               obj = yaffs_FindObjectByNumber(dev, objId);
+               if(obj)
                        return;
        }
 
                        return;
        }
 
@@ -5358,6 +5378,7 @@ static void yaffs_HandleShadowedObject(yaffs_Device *dev, int objId,
                                             YAFFS_OBJECT_TYPE_FILE);
        if (!obj)
                return;
                                             YAFFS_OBJECT_TYPE_FILE);
        if (!obj)
                return;
+       obj->isShadowed = 1;
        yaffs_AddObjectToDirectory(dev->unlinkedDir, obj);
        obj->variant.fileVariant.shrinkSize = 0;
        obj->valid = 1;         /* So that we don't read any other info for this file */
        yaffs_AddObjectToDirectory(dev->unlinkedDir, obj);
        obj->variant.fileVariant.shrinkSize = 0;
        obj->valid = 1;         /* So that we don't read any other info for this file */
@@ -6275,9 +6296,7 @@ static int yaffs_ScanBackwards(yaffs_Device *dev)
                                }
 
                                if (!in ||
                                }
 
                                if (!in ||
-#ifdef CONFIG_YAFFS_DISABLE_LAZY_LOAD
-                                   !in->valid ||
-#endif
+                                   (!in->valid && dev->disableLazyLoad) ||
                                    tags.extraShadows ||
                                    (!in->valid &&
                                    (tags.objectId == YAFFS_OBJECTID_ROOT ||
                                    tags.extraShadows ||
                                    (!in->valid &&
                                    (tags.objectId == YAFFS_OBJECTID_ROOT ||