X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=ec7ccf5c8b3ef2325bf30d24e4b4ebd72b520402;hb=b3c672d0ac3a2ef90d28f76c81f4eecbeb3b542f;hp=ff7f459f4d31f61cb554deba4ae2cf685a71a03b;hpb=c668bb26fb948b3dba6a6000ac2334d833e67a80;p=yaffs%2F.git diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index ff7f459..ec7ccf5 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -25,7 +25,7 @@ #endif -const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.4 2003-02-24 23:49:29 charles Exp $"; +const char *yaffsfs_c_version="$Id: yaffsfs.c,v 1.7 2004-11-21 23:33:30 charles Exp $"; // configurationList is the list of devices that are supported static yaffsfs_DeviceConfiguration *yaffsfs_configurationList; @@ -180,7 +180,7 @@ static yaffs_Device *yaffsfs_FindDevice(const char *path, char **restOfPath) p++; leftOver++; } - if(!*p) + if(!*p && (!*leftOver || *leftOver == '/')) { // Matched prefix *restOfPath = (char *)leftOver; @@ -439,7 +439,8 @@ int yaffs_open(const char *path, int oflag, int mode) } else { - } yaffsfs_SetError(-ENOTDIR); + yaffsfs_SetError(-ENOTDIR); + } } if(obj && !openDenied) @@ -738,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); }