X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=direct%2Fyaffsfs.c;h=207c06930f24226bbb99e925b72919849ea1e58d;hb=a03d8e2c95ff61dd751f629bd7b2f2533fa955e8;hp=d3eae30e1969d664d96b5923a14887677917536f;hpb=4ea0578f8af411adf56fdc1eb4af08f4e36c7eec;p=yaffs%2F.git diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index d3eae30..207c069 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -25,7 +25,7 @@ #endif -const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.1 2003-01-21 03:32:17 charles Exp $"; +const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.6 2003-03-11 09:54:40 charles Exp $"; // configurationList is the list of devices that are supported static yaffsfs_DeviceConfiguration *yaffsfs_configurationList; @@ -348,6 +348,7 @@ int yaffs_open(const char *path, int oflag, int mode) int alreadyExclusive = 0; int openDenied = 0; int symDepth = 0; + int errorReported = 0; int i; @@ -399,6 +400,14 @@ int yaffs_open(const char *path, int oflag, int mode) openDenied = 1; } + // Open should fail if O_CREAT and O_EXCL are specified + if((oflag & O_EXCL) && (oflag & O_CREAT)) + { + openDenied = 1; + yaffsfs_SetError(-EEXIST); + errorReported = 1; + } + // Check file permissions if( (oflag & (O_RDWR | O_WRONLY)) == 0 && // ie O_RDONLY !(obj->st_mode & S_IREAD)) @@ -424,7 +433,14 @@ int yaffs_open(const char *path, int oflag, int mode) { // Let's see if we can create this file dir = yaffsfs_FindDirectory(NULL,path,&name,0); - obj = yaffs_MknodFile(dir,name,mode,0,0); + if(dir) + { + obj = yaffs_MknodFile(dir,name,mode,0,0); + } + else + { + yaffsfs_SetError(-ENOTDIR); + } } if(obj && !openDenied) @@ -447,7 +463,11 @@ int yaffs_open(const char *path, int oflag, int mode) else { yaffsfs_PutHandle(handle); - yaffsfs_SetError(-EACCESS); + if(!errorReported) + { + yaffsfs_SetError(-EACCESS); + errorReported = 1; + } handle = -1; } @@ -540,7 +560,7 @@ int yaffs_read(int fd, void *buf, unsigned int nbyte) } else { - //todo error + nRead = 0; } } @@ -719,27 +739,51 @@ int yaffs_rename(const char *oldPath, const char *newPath) { yaffs_Object *olddir = NULL; yaffs_Object *newdir = NULL; + yaffs_Object *obj = NULL; char *oldname; char *newname; int result= YAFFS_FAIL; + int renameAllowed = 1; yaffsfs_Lock(); olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0); newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0); + obj = yaffsfs_FindObject(NULL,oldPath,0); - if(!olddir || !newdir) + if(!olddir || !newdir || !obj) { - // bad handle - yaffsfs_SetError(-EBADF); + // bad file + yaffsfs_SetError(-EBADF); + renameAllowed = 0; } else if(olddir->myDev != newdir->myDev) { // oops must be on same device // todo error yaffsfs_SetError(-EXDEV); + renameAllowed = 0; } - else + else if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY) + { + // It is a directory, check that it is not being renamed to + // being its own decendent. + // Do this by tracing from the new directory back to the root, checking for obj + + yaffs_Object *xx = newdir; + + while( renameAllowed && xx) + { + if(xx == obj) + { + renameAllowed = 0; + } + xx = xx->parent; + } + if(!renameAllowed) yaffsfs_SetError(-EACCESS); + } + + if(renameAllowed) { result = yaffs_RenameObject(olddir,oldname,newdir,newname); } @@ -1333,5 +1377,6 @@ int yaffs_DumpDevStruct(const char *path) dev->passiveGarbageCollections ); } + return 0; }