changeset 123:54d5e336b009

Flush entire cache at umount
author charles <charles>
date Wed, 08 Mar 2006 07:59:20 +0000
parents 2b3096daff30
children 95d2677ebc15
files direct/dtest.c direct/yaffsfs.c yaffs_fs.c yaffs_guts.c yaffs_guts.h
diffstat 5 files changed, 75 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/direct/dtest.c
+++ b/direct/dtest.c
@@ -248,6 +248,35 @@ void yaffs_backward_scan_test(const char
 	yaffs_mount(path);
 }
 
+char xxzz[2000];
+
+
+void yaffs_device_flush_test(const char *path)
+{
+	char fn[100];
+	int h;
+	int i;
+	
+	yaffs_StartUp();	
+	
+	yaffs_mount(path);
+	
+	do_some_file_stuff(path);
+	
+	// Open and add some data to a few files
+	for(i = 0; i < 10; i++) {
+	
+		sprintf(fn,"%s/ff%d",path,i);
+
+		h = yaffs_open(fn, O_CREAT | O_RDWR | O_TRUNC, S_IWRITE | S_IREAD);
+		yaffs_write(h,xxzz,2000);
+		yaffs_write(h,xxzz,2000);
+	}
+	yaffs_unmount(path);
+	
+	yaffs_mount(path);
+}
+
 
 
 void short_scan_test(const char *path, int fsize, int niterations)
@@ -1658,7 +1687,9 @@ int main(int argc, char *argv[])
 	
 	//huge_directory_test_on_path("/ram2k");
 	
-	 //yaffs_backward_scan_test("/flash")	;
+	 //yaffs_backward_scan_test("/flash/flash");
+	 yaffs_device_flush_test("/flash/flash");
+
 	 
 	 //scan_pattern_test("/flash",10000,10);
 	//short_scan_test("/flash",40000,200);
@@ -1672,7 +1703,7 @@ int main(int argc, char *argv[])
 	//lookup_test("/flash");
 	//freespace_test("/flash/flash");
 	
-	link_test("/flash/flash");
+	//link_test("/flash/flash");
 	
 	
 	
--- a/direct/yaffsfs.c
+++ b/direct/yaffsfs.c
@@ -25,7 +25,7 @@
 #endif
 
 
-const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.9 2006-03-01 08:18:09 charles Exp $";
+const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.10 2006-03-08 07:59:20 charles Exp $";
 
 // configurationList is the list of devices that are supported
 static yaffsfs_DeviceConfiguration *yaffsfs_configurationList;
@@ -1076,6 +1076,9 @@ int yaffs_unmount(const char *path)
 		{
 			int i;
 			int inUse;
+			
+			yaffs_FlushEntireDeviceCache(dev);
+			
 			for(i = inUse = 0; i < YAFFSFS_N_HANDLES && !inUse; i++)
 			{
 				if(yaffsfs_handle[i].inUse && yaffsfs_handle[i].obj->myDev == dev)
--- a/yaffs_fs.c
+++ b/yaffs_fs.c
@@ -31,7 +31,7 @@
  */
 
 const char *yaffs_fs_c_version =
-    "$Id: yaffs_fs.c,v 1.42 2006-02-08 07:52:51 charles Exp $";
+    "$Id: yaffs_fs.c,v 1.43 2006-03-08 07:59:20 charles Exp $";
 extern const char *yaffs_guts_c_version;
 
 #include <linux/config.h>
@@ -1278,6 +1278,9 @@ static void yaffs_put_super(struct super
 	yaffs_Device *dev = yaffs_SuperToDevice(sb);
 
 	yaffs_GrossLock(dev);
+	
+	yaffs_FlushEntireDeviceCache(dev);
+	
 	if (dev->putSuperFunc) {
 		dev->putSuperFunc(sb);
 	}
--- a/yaffs_guts.c
+++ b/yaffs_guts.c
@@ -13,7 +13,7 @@
  */
 
 const char *yaffs_guts_c_version =
-    "$Id: yaffs_guts.c,v 1.30 2006-03-01 08:14:32 charles Exp $";
+    "$Id: yaffs_guts.c,v 1.31 2006-03-08 07:59:20 charles Exp $";
 
 #include "yportenv.h"
 
@@ -3037,6 +3037,36 @@ static void yaffs_FlushFilesChunkCache(y
 
 }
 
+/*yaffs_FlushEntireDeviceCache(dev)
+ *
+ *
+ */
+
+void yaffs_FlushEntireDeviceCache(yaffs_Device *dev)
+{
+	yaffs_Object *obj;
+	int nCaches = dev->nShortOpCaches;
+	int i;
+	
+	/* Find a dirty object in the cache and flush it...
+	 * until there are no further dirty objects.
+	 */
+	do {
+		obj = NULL;
+		for( i = 0; i < nCaches && !obj; i++) {
+			if (dev->srCache[i].object &&
+			    dev->srCache[i].dirty)
+				obj = dev->srCache[i].object;
+			    
+		}
+		if(obj)
+			yaffs_FlushFilesChunkCache(obj);
+			
+	} while(obj);
+	
+}
+
+
 /* Grab us a cache chunk for use.
  * First look for an empty one. 
  * Then look for the least recently used non-dirty one.
--- a/yaffs_guts.h
+++ b/yaffs_guts.h
@@ -14,7 +14,7 @@
  *
  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
  *
- * $Id: yaffs_guts.h,v 1.19 2006-03-01 08:15:45 charles Exp $
+ * $Id: yaffs_guts.h,v 1.20 2006-03-08 07:59:20 charles Exp $
  */
 
 #ifndef __YAFFS_GUTS_H__
@@ -675,6 +675,8 @@ static Y_INLINE yaffs_BlockInfo *yaffs_G
 int yaffs_GutsInitialise(yaffs_Device * dev);
 void yaffs_Deinitialise(yaffs_Device * dev);
 
+void yaffs_FlushEntireDeviceCache(yaffs_Device *dev);
+
 int yaffs_GetNumberOfFreeChunks(yaffs_Device * dev);
 
 int yaffs_RenameObject(yaffs_Object * oldDir, const YCHAR * oldName,