X-Git-Url: https://yaffs.net/gitweb/?a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=db51171405c6c881a8cd0d91b0e84a2c1fa4e8b1;hb=9b9fd2ac90990fed4990feec36ab1ec55fc78926;hp=fc68b969e017c9a82af5b66452f95cfdfae87408;hpb=f792554ed6d0b514dfb040097033417d8e41f420;p=yaffs2.git diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index fc68b96..db51171 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) @@ -246,7 +248,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 +575,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 @@ -1628,7 +1639,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) @@ -1651,6 +1665,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; @@ -1661,6 +1683,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){ @@ -1702,7 +1727,7 @@ int yaffs_sync(const YCHAR *path) yaffs_FlushEntireDeviceCache(dev); yaffs_CheckpointSave(dev); - + retVal = 0; } else /* todo error - not mounted. */