#
# 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
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
*/
//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"
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)
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.
+#ifdef __KERNEL__
+
+void yaffs_HandleDeferedFree(yaffs_Object *obj)
+{
+ if(obj->deferedFree)
+ {
+ yaffs_FreeObject(obj);
+ }
+}
+
+#endif
+
+
static void yaffs_DeinitialiseObjects(yaffs_Device *dev)
{
#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)
{
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;
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)
{
int block;
int aggressive;
- int gcOk;
+ int gcOk = YAFFS_OK;
int maxTries = 0;
//yaffs_DoUnlinkedFileDeletion(dev);
#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
}
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);
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;
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 &&
!dev->readChunkFromNAND &&
dev->markNANDBlockBad &&
dev->queryNANDBlock) return 1;
+#endif
// Can use the "spare" style interface for yaffs1
if(!dev->isYaffs2 &&
*
* 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__
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];
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.
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
// 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
#ifdef __KERNEL__
struct inode *myInode;
+
#endif
// 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 (*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);
+
+#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 (*markNANDBlockBad)(struct yaffs_DeviceStruct *dev, int blockNo);
int (*queryNANDBlock)(struct yaffs_DeviceStruct *dev, int blockNo, yaffs_BlockState *state, int *sequenceNumber);
#endif
void yfsd_WinFileTimeNow(__u32 target[2]);
#endif
+#ifdef __KERNEL__
+
+void yaffs_HandleDeferedFree(yaffs_Object *obj);
+#endif
+
+
+
// Debug dump
int yaffs_DumpObject(yaffs_Object *obj);
#include "yaffs_packedtags.h"
-#include <string.h>
+#include "yportenv.h"
void yaffs_PackTags(yaffs_PackedTags *pt, yaffs_ExtendedTags *t)
{
void yaffs_UnpackTags(yaffs_ExtendedTags *t, yaffs_PackedTags *pt)
{
- static __u8 allFF[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff};
+ static const __u8 allFF[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff};
if(memcmp(allFF,pt,sizeof(yaffs_PackedTags)))
{
*
* 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 $
*
*/
#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__
// 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"
#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
#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
#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)
//#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
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