X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=b709d93fed1edf91332a66f756b3db6bae7ef813;hp=9fc4417eb958954b448558eb4b45a294332c520b;hb=5e008044bbb82598c2ae8ddd7bab78c955b6d2b0;hpb=4a700fe570d217c2c5df87070db7c2652bc0eaaf diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 9fc4417..b709d93 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -62,21 +62,23 @@ typedef struct{ static yaffsfs_Inode yaffsfs_inode[YAFFSFS_N_HANDLES]; static yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES]; +static int yaffsfs_handlesInitialised; /* * yaffsfs_InitHandle * Inilitalise handle management on start-up. */ -static int yaffsfs_InitHandles(void) +static void yaffsfs_InitHandles(void) { int i; + if(yaffsfs_handlesInitialised) + return; + memset(yaffsfs_inode,0,sizeof(yaffsfs_inode)); memset(yaffsfs_handle,0,sizeof(yaffsfs_handle)); for(i = 0; i < YAFFSFS_N_HANDLES; i++) yaffsfs_handle[i].inodeId = -1; - - return 0; } yaffsfs_Handle *yaffsfs_GetHandlePointer(int h) @@ -108,31 +110,46 @@ yaffs_Object *yaffsfs_GetHandleObject(int handle) } /* - * yaffsfs_GetInodeIdForObject - * Grab an inode entry when opening a new inode. + * yaffsfs_FindInodeIdForObject + * Find the inode entry for an object, if it exists. */ -static int yaffsfs_GetInodeIdForObject(yaffs_Object *obj) +static int yaffsfs_FindInodeIdForObject(yaffs_Object *obj) { int i; int ret = -1; - yaffsfs_Inode *in = NULL; if(obj) obj = yaffs_GetEquivalentObject(obj); - /* Look for it. If we can't find it then make one */ + /* Look for it in open inode table*/ for(i = 0; i < YAFFSFS_N_HANDLES && ret < 0; i++){ if(yaffsfs_inode[i].iObj == obj) ret = i; } + return ret; +} + +/* + * yaffsfs_GetInodeIdForObject + * Grab an inode entry when opening a new inode. + */ +static int yaffsfs_GetInodeIdForObject(yaffs_Object *obj) +{ + int i; + int ret; + yaffsfs_Inode *in = NULL; + + if(obj) + obj = yaffs_GetEquivalentObject(obj); + + ret = yaffsfs_FindInodeIdForObject(obj); for(i = 0; i < YAFFSFS_N_HANDLES && ret < 0; i++){ if(!yaffsfs_inode[i].iObj) ret = i; } - - + if(ret>=0){ in = &yaffsfs_inode[ret]; if(!in->iObj) @@ -145,6 +162,17 @@ static int yaffsfs_GetInodeIdForObject(yaffs_Object *obj) return ret; } + +static int yaffsfs_CountHandles(yaffs_Object *obj) +{ + int i = yaffsfs_FindInodeIdForObject(obj); + + if(i >= 0) + return yaffsfs_inode[i].count; + else + return 0; +} + static void yaffsfs_ReleaseInode(yaffsfs_Inode *in) { yaffs_Object *obj; @@ -246,7 +274,7 @@ int yaffsfs_Match(YCHAR a, YCHAR b) int yaffsfs_IsPathDivider(YCHAR ch) { - YCHAR *str = YAFFS_PATH_DIVIDERS; + const YCHAR *str = YAFFS_PATH_DIVIDERS; while(*str){ if(*str == ch) @@ -573,12 +601,21 @@ int yaffs_open(const YCHAR *path, int oflag, int mode) if(obj) obj = yaffs_GetEquivalentObject(obj); - if(obj && obj->variantType != YAFFS_OBJECT_TYPE_FILE) + if(obj && + obj->variantType != YAFFS_OBJECT_TYPE_FILE && + obj->variantType != YAFFS_OBJECT_TYPE_DIRECTORY) obj = NULL; if(obj){ - /* The file already exists */ + /* The file already exists or it might be a directory */ + + /* If it is a directory then we can't open it as a file */ + if(obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){ + openDenied = 1; + yaffsfs_SetError(-EISDIR); + errorReported = 1; + } /* Open should fail if O_CREAT and O_EXCL are specified since * the file exists @@ -1186,7 +1223,7 @@ int yaffs_fstat(int fd, struct yaffs_stat *buf) return retVal; } - +#ifndef CONFIG_YAFFS_WINCE /* xattrib functions */ @@ -1440,6 +1477,7 @@ int yaffs_fremovexattr(int fd, const char *name) return retVal; } +#endif #ifdef CONFIG_YAFFS_WINCE int yaffs_get_wince_times(int fd, unsigned *wctime, unsigned *watime, unsigned *wmtime) @@ -1627,7 +1665,10 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode) yaffsfs_Lock(); parent = yaffsfs_FindDirectory(NULL,path,&name,0); - if(parent && parent->myDev->readOnly){ + if(parent && yaffs_strnlen(name,5) == 0){ + /* Trying to make the root itself */ + yaffsfs_SetError(-EEXIST); + } else if(parent && parent->myDev->readOnly){ yaffsfs_SetError(-EINVAL); } else { if(parent) @@ -1650,6 +1691,14 @@ int yaffs_mkdir(const YCHAR *path, mode_t mode) return retVal; } +void * yaffs_getdev(const YCHAR *path) +{ + yaffs_Device *dev=NULL; + YCHAR *dummy; + dev = yaffsfs_FindDevice(path,&dummy); + return (void *)dev; +} + int yaffs_mount2(const YCHAR *path,int readOnly) { int retVal=-1; @@ -1660,6 +1709,9 @@ int yaffs_mount2(const YCHAR *path,int readOnly) T(YAFFS_TRACE_ALWAYS,(TSTR("yaffs: Mounting %s" TENDSTR),path)); yaffsfs_Lock(); + + yaffsfs_InitHandles(); + dev = yaffsfs_FindDevice(path,&dummy); if(dev){ if(!dev->isMounted){ @@ -1701,7 +1753,7 @@ int yaffs_sync(const YCHAR *path) yaffs_FlushEntireDeviceCache(dev); yaffs_CheckpointSave(dev); - + retVal = 0; } else /* todo error - not mounted. */ @@ -2197,6 +2249,23 @@ int yaffs_mknod(const YCHAR *pathname, mode_t mode, dev_t dev) return -1; } + + +/* + * yaffs_n_handles() + * Returns number of handles attached to the object + */ +int yaffs_n_handles(const YCHAR *path) +{ + yaffs_Object *obj; + + obj = yaffsfs_FindObject(NULL,path,0); + if(obj) + obj = yaffs_GetEquivalentObject(obj); + + return yaffsfs_CountHandles(obj); +} + int yaffs_DumpDevStruct(const YCHAR *path) { #if 0