changeset 4:7c71bd83802d

*** empty log message ***
author charles <charles>
date Tue, 16 Nov 2004 02:36:15 +0000
parents edf9670c020e
children b59cdc4cfd98
files direct/Makefile direct/yaffs_packedtags.c direct/yaffs_packedtags.h yaffs_guts.c yaffs_guts.h yaffs_packedtags.c yaffs_packedtags.h yportenv.h
diffstat 8 files changed, 184 insertions(+), 281 deletions(-) [+]
line wrap: on
line diff
--- a/direct/Makefile
+++ b/direct/Makefile
@@ -10,9 +10,9 @@
 #
 # NB Warning this Makefile does not include header dependencies.
 #
-# $Id: Makefile,v 1.3 2004-11-03 09:16:47 charles Exp $
+# $Id: Makefile,v 1.4 2004-11-16 02:36:15 charles Exp $
 
-CFLAGS =    -Wall -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM -DYAFFS2_DEFINES -g
+CFLAGS =    -Wall -DCONFIG_YAFFS_DIRECT -DCONFIG_YAFFS_SHORT_NAMES_IN_RAM -DCONFIG_YAFFS_YAFFS2 -g
 #CFLAGS+=   -Wshadow -Wpointer-arith -Wwrite-strings -Wstrict-prototypes -Wmissing-declarations
 #CFLAGS+=   -Wmissing-prototypes -Wredundant-decls -Wnested-externs -Winline
 
@@ -23,7 +23,7 @@ BOOTTESTOBJS = bootldtst.o yboot.o yaffs
 
 ALLOBJS =  dtest.o nand_ecc.o yaffscfg.o yaffs_fileem.o yaffsfs.o yaffs_ramdisk.o bootldtst.o yboot.o 
 
-SYMLINKS = devextras.h yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffsinterface.h yportenv.h yaffs_tagscompat.c yaffs_tagscompat.h
+SYMLINKS = devextras.h yaffs_ecc.c yaffs_ecc.h yaffs_guts.c yaffs_guts.h yaffsinterface.h yportenv.h yaffs_tagscompat.c yaffs_tagscompat.h yaffs_packedtags.c yaffs_packedtags.h
 
 #all: directtest2k boottest
 
deleted file mode 100644
--- a/direct/yaffs_packedtags.c
+++ /dev/null
@@ -1,42 +0,0 @@
-#include "yaffs_packedtags.h"
-#include <string.h>
-
-void yaffs_PackTags(yaffs_PackedTags *pt, yaffs_ExtendedTags *t)
-{
-	pt->chunkId = t->chunkId;
-	pt->serialNumber = t->serialNumber;
-	pt->byteCount = t->byteCount;
-	pt->objectId = t->objectId;
-	pt->ecc = 0;
-	pt->deleted = (t->chunkDeleted) ? 0 : 1;
-	pt->unusedStuff = 0;
-	pt->shouldBeFF = 0xFFFFFFFF;
-	
-}
-
-void yaffs_UnpackTags(yaffs_ExtendedTags *t, yaffs_PackedTags *pt)
-{
-	static __u8 allFF[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff};
-	
-	if(memcmp(allFF,pt,sizeof(yaffs_PackedTags)))
-	{
-		t->blockBad = 0;
-		if(pt->shouldBeFF != 0xFFFFFFFF)
-		{
-			t->blockBad = 1;
-		}
-		t->chunkUsed = 1;
-		t->objectId = pt->objectId;
-		t->chunkId = pt->chunkId;
-		t->byteCount = pt->byteCount;
-		t->eccResult = 	YAFFS_ECC_RESULT_NO_ERROR;
-		t->chunkDeleted = (pt->deleted) ? 0 : 1;
-		t->serialNumber = pt->serialNumber;
-	}
-	else
-	{
-		memset(t,0,sizeof(yaffs_ExtendedTags));
-		
-	}
-}
-
deleted file mode 100644
--- a/direct/yaffs_packedtags.h
+++ /dev/null
@@ -1,24 +0,0 @@
-
-#ifndef __YAFFS_PACKEDTAGS_H__
-#define __YAFFS_PACKEDTAGS_H__
-
-#include "yaffs_guts.h"
-
-typedef struct
-{   
-	unsigned chunkId:20;
-    unsigned serialNumber:2;
-    unsigned byteCount:10;
-    unsigned objectId:18;
-    unsigned ecc:12;
-    unsigned deleted:1;
-    unsigned unusedStuff:1;
-    unsigned shouldBeFF;
-
-} yaffs_PackedTags;
-
-void yaffs_PackTags(yaffs_PackedTags *pt, yaffs_ExtendedTags *t);
-void yaffs_UnpackTags(yaffs_ExtendedTags *t, yaffs_PackedTags *pt);
-#endif
-
-
--- a/yaffs_guts.c
+++ b/yaffs_guts.c
@@ -13,7 +13,7 @@
  */
  //yaffs_guts.c
 
-const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.1 2004-11-03 08:14:07 charles Exp $";
+const char *yaffs_guts_c_version="$Id: yaffs_guts.c,v 1.2 2004-11-16 02:36:15 charles Exp $";
 
 #include "yportenv.h"
 
@@ -1194,7 +1194,7 @@ static void yaffs_SoftDeleteChunk(yaffs_
 
 	yaffs_BlockInfo *theBlock;					
 	
-	T(YAFFS_TRACE_DELETE,(TSTR("soft delete chunk %d" TENDSTR),chunk));
+	T(YAFFS_TRACE_DELETION,(TSTR("soft delete chunk %d" TENDSTR),chunk));
 						
 	theBlock =	yaffs_GetBlockInfo(dev,  chunk/dev->nChunksPerBlock);
 	if(theBlock)
@@ -1529,6 +1529,16 @@ static void yaffs_FreeObject(yaffs_Objec
 
 	yaffs_Device *dev = tn->myDev;
 	
+#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);
 	
 	// Link into the free list.
@@ -1539,6 +1549,19 @@ static void yaffs_FreeObject(yaffs_Objec
 
 
 
+#ifdef __KERNEL__
+
+void yaffs_HandleDeferedFree(yaffs_Object *obj)
+{
+	if(obj->deferedFree)
+	{
+	   yaffs_FreeObject(obj);
+	}
+}
+
+#endif
+
+
 
 static void yaffs_DeinitialiseObjects(yaffs_Device *dev)
 {
@@ -1723,11 +1746,7 @@ yaffs_Object *yaffs_CreateNewObject(yaff
 
 #else
 
-#if defined(CONFIG_KERNEL_2_5)
-		theObject->st_atime = theObject->st_mtime =	theObject->st_ctime = CURRENT_TIME.tv_sec;		
-#else
-		theObject->st_atime = theObject->st_mtime =	theObject->st_ctime = CURRENT_TIME;		
-#endif
+		theObject->st_atime = theObject->st_mtime = theObject->st_ctime = Y_CURRENT_TIME;		
 #endif
 		switch(type)
 		{
@@ -1831,11 +1850,8 @@ yaffs_Object *yaffs_MknodObject( yaffs_O
 		in->win_ctime[1] = in->win_mtime[1] = in->win_atime[1];
 		
 #else
-#if defined(CONFIG_KERNEL_2_5)
-		in->st_atime = in->st_mtime = in->st_ctime = CURRENT_TIME.tv_sec;
-#else
-		in->st_atime = in->st_mtime = in->st_ctime = CURRENT_TIME;
-#endif
+		in->st_atime = in->st_mtime = in->st_ctime = Y_CURRENT_TIME;
+
 		in->st_rdev  = rdev;
 		in->st_uid   = uid;
 		in->st_gid   = gid;
@@ -1974,7 +1990,7 @@ int yaffs_RenameObject(yaffs_Object *old
 	int force = 0;
 	
 #ifdef CONFIG_YAFFS_CASE_INSENSITIVE
-	// Special case for WinCE.
+	// Special case for case insemsitive systems (eg. WinCE).
 	// While look-up is case insensitive, the name isn't.
 	// THerefore we might want to change x.txt to X.txt
 	if(oldDir == newDir && yaffs_strcmp(oldName,newName) == 0)
@@ -2719,7 +2735,7 @@ int yaffs_CheckGarbageCollection(yaffs_D
 {
 	int block;
 	int aggressive; 
-	int gcOk;
+	int gcOk = YAFFS_OK;
 	int maxTries = 0;
 	
 	//yaffs_DoUnlinkedFileDeletion(dev);
@@ -4168,11 +4184,9 @@ int yaffs_FlushFile(yaffs_Object *in, in
 #ifdef CONFIG_YAFFS_WINCE
 			yfsd_WinFileTimeNow(in->win_mtime);
 #else
-#if defined(CONFIG_KERNEL_2_5)
-			in->st_mtime = CURRENT_TIME.tv_sec;
-#else
-			in->st_mtime = CURRENT_TIME;
-#endif
+
+			in->st_mtime = Y_CURRENT_TIME;
+
 #endif
 		}
 
@@ -5183,15 +5197,9 @@ int yaffs_SetAttributes(yaffs_Object *ob
 	if(valid & ATTR_UID) obj->st_uid = attr->ia_uid;
 	if(valid & ATTR_GID) obj->st_gid = attr->ia_gid;
 	
-#if defined(CONFIG_KERNEL_2_5)
-	if(valid & ATTR_ATIME) obj->st_atime = attr->ia_atime.tv_sec;
-	if(valid & ATTR_CTIME) obj->st_ctime = attr->ia_ctime.tv_sec;
-	if(valid & ATTR_MTIME) obj->st_mtime = attr->ia_mtime.tv_sec;
-#else
-	if(valid & ATTR_ATIME) obj->st_atime = attr->ia_atime;
-	if(valid & ATTR_CTIME) obj->st_ctime = attr->ia_ctime;
-	if(valid & ATTR_MTIME) obj->st_mtime = attr->ia_mtime;
-#endif
+	if(valid & ATTR_ATIME) obj->st_atime = Y_TIME_CONVERT(attr->ia_atime);
+	if(valid & ATTR_CTIME) obj->st_ctime = Y_TIME_CONVERT(attr->ia_ctime);
+	if(valid & ATTR_MTIME) obj->st_mtime = Y_TIME_CONVERT(attr->ia_mtime);
 	
 	if(valid & ATTR_SIZE) yaffs_ResizeFile(obj,attr->ia_size);
 	
@@ -5208,15 +5216,10 @@ int yaffs_GetAttributes(yaffs_Object *ob
 	attr->ia_uid = obj->st_uid;		valid |= ATTR_UID;
 	attr->ia_gid = obj->st_gid;		valid |= ATTR_GID;
 	
-#if defined(CONFIG_KERNEL_2_5)
-	attr->ia_atime.tv_sec = obj->st_atime;	valid |= ATTR_ATIME;
-	attr->ia_ctime.tv_sec = obj->st_ctime;	valid |= ATTR_CTIME;
-	attr->ia_mtime.tv_sec = obj->st_mtime;	valid |= ATTR_MTIME;
-#else	
-	attr->ia_atime = obj->st_atime;	valid |= ATTR_ATIME;
-	attr->ia_ctime = obj->st_ctime;	valid |= ATTR_CTIME;
-	attr->ia_mtime = obj->st_mtime;	valid |= ATTR_MTIME;
-#endif	
+	Y_TIME_CONVERT(attr->ia_atime)= obj->st_atime;	valid |= ATTR_ATIME;
+	Y_TIME_CONVERT(attr->ia_ctime) = obj->st_ctime;	valid |= ATTR_CTIME;
+	Y_TIME_CONVERT(attr->ia_mtime) = obj->st_mtime;	valid |= ATTR_MTIME;
+
 	attr->ia_size = yaffs_GetFileSize(obj); valid |= ATTR_SIZE;
 	
 	attr->ia_valid = valid;
@@ -5279,6 +5282,8 @@ int yaffs_CheckDevFunctions(const yaffs_
 	if(!dev->eraseBlockInNAND ||
 	   !dev->initialiseNAND) return 0;
 
+#ifdef CONFIG_YAFFS_YAFFS2
+
 	// Can use the "with tags" style interface for yaffs1 or yaffs2
 	if(dev->writeChunkWithTagsToNAND &&
 	   dev->readChunkWithTagsFromNAND &&
@@ -5286,6 +5291,7 @@ int yaffs_CheckDevFunctions(const yaffs_
 	   !dev->readChunkFromNAND &&
 	   dev->markNANDBlockBad &&
 	   dev->queryNANDBlock)	return 1;
+#endif
 
 	// Can use the "spare" style interface for yaffs1
 	if(!dev->isYaffs2 &&
--- 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.1 2004-11-03 08:14:07 charles Exp $
+ * $Id: yaffs_guts.h,v 1.2 2004-11-16 02:36:15 charles Exp $
  */
 
 #ifndef __YAFFS_GUTS_H__
@@ -103,7 +103,7 @@ typedef struct
 	int dirty;	
 	int nBytes;	// Only valid if the cache is dirty
 	int locked; // Can't push out or flush while locked..
-#ifdef YAFFS2_DEFINES
+#ifdef CONFIG_YAFFS_YAFFS2
 	__u8 *data;
 #else
 	__u8 data[YAFFS_BYTES_PER_CHUNK];
@@ -197,16 +197,14 @@ struct yaffs_NANDSpare {
 
 typedef enum {
 	YAFFS_BLOCK_STATE_UNKNOWN	= 0,
-#ifndef YAFFS2_DEFINES
+
 	YAFFS_BLOCK_STATE_SCANNING,
-#else
 	YAFFS_BLOCK_STATE_NEEDS_SCANNING,// The block might have something on it (ie it is allocating or full, perhaps empty)
 									// but it needs to be scanned to determine its true state.
 									// This state is only valid during yaffs_Scan.
 									// NB We tolerate empty because the pre-scanner might be incapable of deciding
 									// However, if this state is returned on a YAFFS2 device, then we expect a sequence number
 									
-#endif	
 	YAFFS_BLOCK_STATE_EMPTY,		// This block is empty
 	
 	YAFFS_BLOCK_STATE_ALLOCATING,	// This block is partially allocated. 
@@ -232,12 +230,12 @@ typedef enum {
 typedef struct
 {
 
-	int   softDeletions:8;  // number of soft deleted pages
+    int   softDeletions:8;  // number of soft deleted pages
     int   pagesInUse:8;		// number of pages in use
     __u32 blockState:4; 	// One of the above block states
     __u32 needsRetiring:1;	// Data has failed on this block, need to get valid data off
     						// and retire the block.
-#ifndef CONFIG_YAFFS_NO_YAFFS2
+#ifdef CONFIG_YAFFS_YAFFS2
 	__u32 hasShrinkHeader:1;// This block has at least one object header that does a shrink
 	__u32 sequenceNumber;	// block sequence number for yaffs2
 #endif
@@ -386,6 +384,10 @@ struct  yaffs_ObjectStruct
 							// object might be created before the data
 							// is available (ie. file data records appear before the header).
 	__u8 serial;			// serial number of chunk in NAND. Store here so we don't have to
+
+	__u8  deferedFree: 1;		// For Linux kernel. Object is removed from NAND, but still in the inode cache.
+					// Free of object is defered.
+
 							// read back the old one to update.
 	__u16 sum;				// sum of the name to speed searching
 	
@@ -438,6 +440,7 @@ struct  yaffs_ObjectStruct
 
 #ifdef __KERNEL__
 	struct inode *myInode;
+
 #endif
 
 
@@ -503,17 +506,15 @@ struct yaffs_DeviceStruct
 
 	// NAND access functions (Must be set before calling YAFFS)
 	
-#ifndef CONFIG_YAFFS_NO_YAFFS1
+
 	int (*writeChunkToNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, const __u8 *data, const yaffs_Spare *spare);
 	int (*readChunkFromNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare);
-//	int (*eraseBlockInNAND)(struct yaffs_DeviceStruct *dev,int blockInNAND);	
-//	int (*initialiseNAND)(struct yaffs_DeviceStruct *dev);
-#endif
-#ifndef CONFIG_YAFFS_NO_YAFFS2
+	int (*eraseBlockInNAND)(struct yaffs_DeviceStruct *dev,int blockInNAND);	
+	int (*initialiseNAND)(struct yaffs_DeviceStruct *dev);
+
+#ifdef CONFIG_YAFFS_YAFFS2
 	int (*writeChunkWithTagsToNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, const __u8 *data, yaffs_ExtendedTags *tags);
 	int (*readChunkWithTagsFromNAND)(struct yaffs_DeviceStruct *dev,int chunkInNAND, __u8 *data, yaffs_ExtendedTags *tags);
-	int (*eraseBlockInNAND)(struct yaffs_DeviceStruct *dev,int blockInNAND);	
-	int (*initialiseNAND)(struct yaffs_DeviceStruct *dev);
 	int (*markNANDBlockBad)(struct yaffs_DeviceStruct *dev, int blockNo);
 	int (*queryNANDBlock)(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_BlockState *state, int *sequenceNumber);
 #endif
@@ -703,6 +704,13 @@ yaffs_Object *yaffs_LostNFound(yaffs_Dev
 void  yfsd_WinFileTimeNow(__u32 target[2]);
 #endif
 
+#ifdef __KERNEL__
+
+void yaffs_HandleDeferedFree(yaffs_Object *obj);
+#endif
+
+
+
 
 // Debug dump 
 int yaffs_DumpObject(yaffs_Object *obj);
new file mode 100644
--- /dev/null
+++ b/yaffs_packedtags.c
@@ -0,0 +1,42 @@
+#include "yaffs_packedtags.h"
+#include "yportenv.h"
+
+void yaffs_PackTags(yaffs_PackedTags *pt, yaffs_ExtendedTags *t)
+{
+	pt->chunkId = t->chunkId;
+	pt->serialNumber = t->serialNumber;
+	pt->byteCount = t->byteCount;
+	pt->objectId = t->objectId;
+	pt->ecc = 0;
+	pt->deleted = (t->chunkDeleted) ? 0 : 1;
+	pt->unusedStuff = 0;
+	pt->shouldBeFF = 0xFFFFFFFF;
+	
+}
+
+void yaffs_UnpackTags(yaffs_ExtendedTags *t, yaffs_PackedTags *pt)
+{
+	static const __u8 allFF[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff};
+	
+	if(memcmp(allFF,pt,sizeof(yaffs_PackedTags)))
+	{
+		t->blockBad = 0;
+		if(pt->shouldBeFF != 0xFFFFFFFF)
+		{
+			t->blockBad = 1;
+		}
+		t->chunkUsed = 1;
+		t->objectId = pt->objectId;
+		t->chunkId = pt->chunkId;
+		t->byteCount = pt->byteCount;
+		t->eccResult = 	YAFFS_ECC_RESULT_NO_ERROR;
+		t->chunkDeleted = (pt->deleted) ? 0 : 1;
+		t->serialNumber = pt->serialNumber;
+	}
+	else
+	{
+		memset(t,0,sizeof(yaffs_ExtendedTags));
+		
+	}
+}
+
new file mode 100644
--- /dev/null
+++ b/yaffs_packedtags.h
@@ -0,0 +1,24 @@
+
+#ifndef __YAFFS_PACKEDTAGS_H__
+#define __YAFFS_PACKEDTAGS_H__
+
+#include "yaffs_guts.h"
+
+typedef struct
+{   
+	unsigned chunkId:20;
+    unsigned serialNumber:2;
+    unsigned byteCount:10;
+    unsigned objectId:18;
+    unsigned ecc:12;
+    unsigned deleted:1;
+    unsigned unusedStuff:1;
+    unsigned shouldBeFF;
+
+} yaffs_PackedTags;
+
+void yaffs_PackTags(yaffs_PackedTags *pt, yaffs_ExtendedTags *t);
+void yaffs_UnpackTags(yaffs_ExtendedTags *t, yaffs_PackedTags *pt);
+#endif
+
+
--- a/yportenv.h
+++ b/yportenv.h
@@ -15,7 +15,7 @@
  *
  * Note: Only YAFFS headers are LGPL, YAFFS C code is covered by GPL.
  *
- * $Id: yportenv.h,v 1.2 2004-11-03 08:35:48 charles Exp $
+ * $Id: yportenv.h,v 1.3 2004-11-16 02:36:15 charles Exp $
  *
  */
  
@@ -25,76 +25,7 @@
 
 #if defined CONFIG_YAFFS_WINCE
 
-// CONFIG_YAFFS_WINCE
-#include "stdlib.h"
-#include "stdio.h"
-#include "string.h"
-
-#define Y_INLINE
-
-#define CONFIG_YAFFS_CASE_INSENSITIVE
-#define CONFIG_YAFFS_UNICODE
-
-#define YMALLOC(x) malloc(x)
-#define YFREE(x)   free(x)
-
-
-#define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s))
-#define YALERT(s) YINFO(s)
-
-#include <windows.h>
-
-#define YPRINTF(x)	RETAILMSG(1,x)
-
-// Always pass the sum compare to overcome the case insensitivity issue
-#define yaffs_SumCompare(x,y) ((x) == (y))
-
-#ifdef CONFIG_YAFFS_UNICODE
-#define YCHAR					WCHAR
-#define YUCHAR					WCHAR
-#define	_Y(a)					L##a
-#define yaffs_toupper(a)		towupper(a)
-#define yaffs_strcmp(a,b)		_wcsicmp(a,b)
-#define yaffs_strcpy(a,b)		wcscpy(a,b)
-#define yaffs_strncpy(a,b,c)	wcsncpy(a,b,c)
-#define yaffs_strlen(s)			wcslen(s)
-#define yaffs_sprintf			swprintf
-#else
-#define YCHAR					CHAR
-#define YUCHAR					UCHAR
-#define _Y(a)					a
-#define	yaffs_toupper(a)		toupper(a)
-#define yaffs_strcmp(a,b)		_stricmp(a,b)
-#define yaffs_strcpy(a,b)		strcpy(a,b)
-#define yaffs_strncpy(a,b,c)	strncpy(a,b,c)
-#define yaffs_strlen(s)			strlen(s)
-#define yaffs_sprintf			sprintf
-#endif
-
-#define YAFFS_LOSTNFOUND_NAME		_Y("Lost Clusters")
-#define YAFFS_LOSTNFOUND_PREFIX		_Y("OBJ")
-
-
-#define u_char unsigned char
-#define loff_t int
-#define S_IFDIR						04000
-
-#define S_ISFIFO(x) 0
-#define S_ISCHR(x) 0
-#define S_ISBLK(x) 0
-#define S_ISSOCK(x) 0
-
-extern unsigned yfsd_U32FileTimeNow(void);
-
-#define CURRENT_TIME				 yfsd_U32FileTimeNow()
-#define YAFFS_ROOT_MODE				FILE_ATTRIBUTE_ARCHIVE
-#define YAFFS_LOSTNFOUND_MODE		FILE_ATTRIBUTE_HIDDEN
-
-
-#define TENDSTR L"\r\n"
-#define TSTR(x) TEXT(x)
-#define TOUT(x) RETAILMSG(1, x)
-
+#include "ywinceenv.h"
 
 #elif  defined __KERNEL__
 
@@ -102,12 +33,21 @@ extern unsigned yfsd_U32FileTimeNow(void
 
 // Linux kernel
 #include "linux/kernel.h"
+#include "linux/version.h"
 #include "linux/mm.h"
 #include "linux/string.h"
 #include "linux/slab.h"
 
-#define Y_INLINE
+#define YCHAR char
+#define YUCHAR unsigned char
+#define _Y(x)     x
+#define yaffs_strcpy(a,b)    strcpy(a,b)
+#define yaffs_strncpy(a,b,c) strncpy(a,b,c)
+#define yaffs_strlen(s)	     strlen(s)
+#define yaffs_sprintf	     sprintf
+#define yaffs_toupper(a)     toupper(a)
 
+#define Y_INLINE inline
 
 #define YAFFS_LOSTNFOUND_NAME		"lost+found"
 #define YAFFS_LOSTNFOUND_PREFIX		"obj"
@@ -119,17 +59,16 @@ extern unsigned yfsd_U32FileTimeNow(void
 #define YAFFS_ROOT_MODE				0666
 #define YAFFS_LOSTNFOUND_MODE		0666
 
+#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
+#define Y_CURRENT_TIME CURRENT_TIME.tv_sec
+#define Y_TIME_CONVERT(x) (x).tv_sec
+#else
+#define Y_CURRENT_TIME CURRENT_TIME
+#define Y_TIME_CONVERT(x) (x)
+#endif
 
 #define yaffs_SumCompare(x,y) ((x) == (y))
-#define YCHAR					char
-#define YUCHAR					unsigned char
-#define _Y(a)					a
-#define	yaffs_toupper(a)		toupper(a)
-#define yaffs_strcmp(a,b)		strcmp(a,b)
-#define yaffs_strcpy(a,b)		strcpy(a,b)
-#define yaffs_strncpy(a,b,c)	strncpy(a,b,c)
-#define yaffs_strlen(s)			strlen(s)
-#define yaffs_sprintf			sprintf
+#define yaffs_strcmp(a,b) strcmp(a,b)
 
 #define TENDSTR "\n"
 #define TSTR(x) KERN_DEBUG x
@@ -139,46 +78,7 @@ extern unsigned yfsd_U32FileTimeNow(void
 #elif defined CONFIG_YAFFS_DIRECT
 
 // Direct interface
-
-#include "stdlib.h"
-#include "stdio.h"
-#include "string.h"
-
-#define Y_INLINE
-
-#define YMALLOC(x) malloc(x)
-#define YFREE(x)   free(x)
-
-
-//#define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s))
-//#define YALERT(s) YINFO(s)
-
-
-#define TENDSTR "\n"
-#define TSTR(x) x
-#define TOUT(p) printf p
-
-
-#define YAFFS_LOSTNFOUND_NAME		"lost+found"
-#define YAFFS_LOSTNFOUND_PREFIX		"obj"
-//#define YPRINTF(x) printf x
-
-#include "yaffscfg.h"
-
-#define CURRENT_TIME yaffsfs_CurrentTime()
-#define YAFFS_ROOT_MODE				0666
-#define YAFFS_LOSTNFOUND_MODE		0666
-
-#define yaffs_SumCompare(x,y) ((x) == (y))
-#define YCHAR					char
-#define YUCHAR					unsigned char
-#define _Y(a)					a
-#define	yaffs_toupper(a)		toupper(a)
-#define yaffs_strcmp(a,b)		strcmp(a,b)
-#define yaffs_strcpy(a,b)		strcpy(a,b)
-#define yaffs_strncpy(a,b,c)	strncpy(a,b,c)
-#define yaffs_strlen(s)			strlen(s)
-#define yaffs_sprintf			sprintf
+#include "ydirectenv.h"
 
 #elif defined CONFIG_YAFFS_UTIL
 
@@ -188,11 +88,22 @@ extern unsigned yfsd_U32FileTimeNow(void
 #include "stdio.h"
 #include "string.h"
 
+#include "devextras.h"
+
 #define YMALLOC(x) malloc(x)
 #define YFREE(x)   free(x)
 
-#define Y_INLINE
 
+#define YCHAR char
+#define YUCHAR unsigned char
+#define _Y(x)     x
+#define yaffs_strcpy(a,b)    strcpy(a,b)
+#define yaffs_strncpy(a,b,c) strncpy(a,b,c)
+#define yaffs_strlen(s)	     strlen(s)
+#define yaffs_sprintf	     sprintf
+#define yaffs_toupper(a)     toupper(a)
+
+#define Y_INLINE inline
 
 //#define YINFO(s) YPRINTF(( __FILE__ " %d %s\n",__LINE__,s))
 //#define YALERT(s) YINFO(s)
@@ -208,20 +119,11 @@ extern unsigned yfsd_U32FileTimeNow(void
 //#define YPRINTF(x) printf x
 
 
-#define CURRENT_TIME 0
 #define YAFFS_ROOT_MODE				0666
 #define YAFFS_LOSTNFOUND_MODE		0666
 
 #define yaffs_SumCompare(x,y) ((x) == (y))
-#define YCHAR					char
-#define YUCHAR					unsigned char
-#define _Y(a)					a
-#define	yaffs_toupper(a)		toupper(a)
-#define yaffs_strcmp(a,b)		strcmp(a,b)
-#define yaffs_strcpy(a,b)		strcpy(a,b)
-#define yaffs_strncpy(a,b,c)	strncpy(a,b,c)
-#define yaffs_strlen(s)			strlen(s)
-#define yaffs_sprintf			sprintf
+#define yaffs_strcmp(a,b) strcmp(a,b)
 
 #else
 // Should have specified a configuration type
@@ -232,42 +134,29 @@ extern unsigned yfsd_U32FileTimeNow(void
 
 extern unsigned yaffs_traceMask;
 
-#define YAFFS_TRACE_ERROR		0x0001
-#define YAFFS_TRACE_OS			0x0002
-#define YAFFS_TRACE_ALLOCATE	0x0004
-#define YAFFS_TRACE_SCAN		0x0008
-#define YAFFS_TRACE_BAD_BLOCKS	0x0010
-#define YAFFS_TRACE_ERASE		0x0020
-#define YAFFS_TRACE_GC			0x0040
-#define YAFFS_TRACE_DELETION	0x0080
-#define YAFFS_TRACE_TRACING		0x0100
-#define YAFFS_TRACE_ALWAYS		0x0200
-#define YAFFS_TRACE_WRITE		0x0400
-#define YAFFS_TRACE_BUFFERS		0x0800
-#define YAFFS_TRACE_NANDACCESS		0x1000
-#define YAFFS_TRACE_DELETE		0x2000
-#define YAFFS_TRACE_GC_DETAIL		0x4000
-#define YAFFS_TRACE_BUG			0x800000
+#define YAFFS_TRACE_ERROR		0x00000001
+#define YAFFS_TRACE_OS			0x00000002
+#define YAFFS_TRACE_ALLOCATE		0x00000004
+#define YAFFS_TRACE_SCAN		0x00000008
+#define YAFFS_TRACE_BAD_BLOCKS		0x00000010
+#define YAFFS_TRACE_ERASE		0x00000020
+#define YAFFS_TRACE_GC			0x00000040
+#define YAFFS_TRACE_WRITE		0x00000080
+#define YAFFS_TRACE_TRACING		0x00000100
+#define YAFFS_TRACE_DELETION		0x00000200
+#define YAFFS_TRACE_BUFFERS		0x00000400
+#define YAFFS_TRACE_NANDACCESS		0x00000800
+#define YAFFS_TRACE_GC_DETAIL		0x00001000
+#define YAFFS_TRACE_ALWAYS		0x40000000
+#define YAFFS_TRACE_BUG			0x80000000
 
 #define T(mask,p) do{ if((mask) & (yaffs_traceMask | YAFFS_TRACE_ERROR)) TOUT(p);} while(0) 
 
-//#undef YINFO
 
-
-//#define YINFO(s) YPRINTF((KERN_DEBUG __FILE__ " %d %s\n",__LINE__,s))
-//#define YALERT(s) YINFO(s)
-#ifdef CONFIG_YAFFS_WINCE
-#define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: %s %d" TENDSTR),TEXT(__FILE__),__LINE__))
-#else
+#ifndef CONFIG_YAFFS_WINCE
 #define YBUG() T(YAFFS_TRACE_BUG,(TSTR("==>> yaffs bug: " __FILE__ " %d" TENDSTR),__LINE__))
 #endif
 
-#ifndef YCHAR
-#define YCHAR char
 #endif
 
-#ifndef YUCHAR 
-#define YUCHAR unsigned char
-#endif
 
-#endif