X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs2.git;a=blobdiff_plain;f=direct%2Fyaffsfs.c;h=f95c19906ac7f6cde771177700eacab25e7d01e9;hp=191ac8d520d0cf39d7897634d81be5bfa8462d03;hb=41573908f821bcb40750e7c069ea8f5178f630e5;hpb=f43976eda35065890e7cf0a008e9518158eb71d6 diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 191ac8d..f95c199 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -31,7 +31,7 @@ #define YAFFSFS_RW_SIZE (1<variant_type == YAFFS_OBJECT_TYPE_SYMLINK){ YCHAR *alias = obj->variant.symlink_variant.alias; if(yaffsfs_IsPathDivider(*alias)) /* Starts with a /, need to scan from root up */ - obj = yaffsfs_FindObject(NULL,alias,symDepth++); + obj = yaffsfs_FindObject(NULL,alias,symDepth++,1); else /* Relative to here, so use the parent of the symlink as a start */ - obj = yaffsfs_FindObject(obj->parent,alias,symDepth++); + obj = yaffsfs_FindObject(obj->parent,alias,symDepth++,1); } return obj; } @@ -500,9 +503,7 @@ static yaffs_obj_t *yaffsfs_DoFindDirectory(yaffs_obj_t *startDir, else{ dir = yaffs_find_by_name(dir,str); - while(dir && dir->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) - dir = yaffsfs_FollowLink(dir,symDepth); - + dir = yaffsfs_FollowLink(dir,symDepth); if(dir && dir->variant_type != YAFFS_OBJECT_TYPE_DIRECTORY) dir = NULL; @@ -522,17 +523,23 @@ static yaffs_obj_t *yaffsfs_FindDirectory(yaffs_obj_t *relativeDirectory, /* * yaffsfs_FindObject turns a path for an existing object into the object */ -static yaffs_obj_t *yaffsfs_FindObject(yaffs_obj_t *relativeDirectory, const YCHAR *path,int symDepth) +static yaffs_obj_t *yaffsfs_FindObject(yaffs_obj_t *relativeDirectory, const YCHAR *path,int symDepth, int getEquiv) { yaffs_obj_t *dir; + yaffs_obj_t *obj; YCHAR *name; dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth); if(dir && *name) - return yaffs_find_by_name(dir,name); + obj = yaffs_find_by_name(dir,name); + else + obj = dir; - return dir; + if(getEquiv) + obj = yaffs_get_equivalent_obj(obj); + + return obj; } @@ -570,7 +577,7 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing) yaffs_obj_t *dir = NULL; YCHAR *name; int handle = -1; - yaffsfs_Handle *h = NULL; + yaffsfs_Handle *yh = NULL; int openDenied = 0; int symDepth = 0; int errorReported = 0; @@ -600,16 +607,12 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing) if(handle >= 0){ - h = yaffsfs_GetHandlePointer(handle); + yh = yaffsfs_GetHandlePointer(handle); /* try to find the exisiting object */ - obj = yaffsfs_FindObject(NULL,path,0); - - if(obj && obj->variant_type == YAFFS_OBJECT_TYPE_SYMLINK) - obj = yaffsfs_FollowLink(obj,symDepth++); + obj = yaffsfs_FindObject(NULL,path,0,1); - if(obj) - obj = yaffs_get_equivalent_obj(obj); + obj = yaffsfs_FollowLink(obj,symDepth++); if(obj && obj->variant_type != YAFFS_OBJECT_TYPE_FILE && @@ -651,24 +654,24 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing) /* Check sharing of an existing object. */ { - yaffsfs_Handle *h; + yaffsfs_Handle *hx; int i; sharedReadAllowed = 1; sharedWriteAllowed = 1; alreadyReading = 0; alreadyWriting = 0; for( i = 0; i < YAFFSFS_N_HANDLES; i++){ - h = &yaffsfs_handle[i]; - if(h->useCount > 0 && - h->inodeId >= 0 && - yaffsfs_inode[h->inodeId].iObj == obj){ - if(!h->shareRead) + hx = &yaffsfs_handle[i]; + if(hx->useCount > 0 && + hx->inodeId >= 0 && + yaffsfs_inode[hx->inodeId].iObj == obj){ + if(!hx->shareRead) sharedReadAllowed = 0; - if(!h->shareWrite) + if(!hx->shareWrite) sharedWriteAllowed = 0; - if(h->reading) + if(hx->reading) alreadyReading = 1; - if(h->writing) + if(hx->writing) alreadyWriting = 0; } } @@ -710,18 +713,18 @@ int yaffs_open_sharing(const YCHAR *path, int oflag, int mode, int sharing) */ } - h->inodeId = inodeId; - h->reading = (oflag & (O_RDONLY | O_RDWR)) ? 1 : 0; - h->writing = (oflag & (O_WRONLY | O_RDWR)) ? 1 : 0; - h->append = (oflag & O_APPEND) ? 1 : 0; - h->position = 0; - h->shareRead = shareRead; - h->shareWrite = shareWrite; + yh->inodeId = inodeId; + yh->reading = (oflag & (O_RDONLY | O_RDWR)) ? 1 : 0; + yh->writing = (oflag & (O_WRONLY | O_RDWR)) ? 1 : 0; + yh->append = (oflag & O_APPEND) ? 1 : 0; + yh->position = 0; + yh->shareRead = shareRead; + yh->shareWrite = shareWrite; /* Hook inode to object */ obj->my_inode = (void*) &yaffsfs_inode[inodeId]; - if((oflag & O_TRUNC) && h->writing) + if((oflag & O_TRUNC) && yh->writing) yaffs_resize_file(obj,0); } else { yaffsfs_PutHandle(handle); @@ -995,9 +998,7 @@ int yaffs_truncate(const YCHAR *path,off_t new_size) yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); - if(obj) - obj = yaffs_get_equivalent_obj(obj); + obj = yaffsfs_FindObject(NULL,path,0,1); if(!obj) yaffsfs_SetError(-ENOENT); @@ -1089,7 +1090,7 @@ int yaffsfs_DoUnlink(const YCHAR *path,int isDirectory) yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + obj = yaffsfs_FindObject(NULL,path,0,0); dir = yaffsfs_FindDirectory(NULL,path,&name,0); if(!dir) yaffsfs_SetError(-ENOTDIR); @@ -1140,7 +1141,7 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0); newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0); - obj = yaffsfs_FindObject(NULL,oldPath,0); + obj = yaffsfs_FindObject(NULL,oldPath,0,0); if(!olddir || !newdir || !obj) { /* bad file */ @@ -1185,8 +1186,7 @@ static int yaffsfs_DoStat(yaffs_obj_t *obj,struct yaffs_stat *buf) { int retVal = -1; - if(obj) - obj = yaffs_get_equivalent_obj(obj); + obj = yaffs_get_equivalent_obj(obj); if(obj && buf){ buf->st_dev = (int)obj->my_dev->os_context; @@ -1231,7 +1231,8 @@ static int yaffsfs_DoStatOrLStat(const YCHAR *path, struct yaffs_stat *buf,int d int retVal = -1; yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + + obj = yaffsfs_FindObject(NULL,path,0,1); if(!doLStat && obj) obj = yaffsfs_FollowLink(obj,0); @@ -1289,7 +1290,8 @@ static int yaffs_do_setxattr(const YCHAR *path, const char *name, const void *da int retVal = -1; yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + + obj = yaffsfs_FindObject(NULL,path,0,1); if(follow) obj = yaffsfs_FollowLink(obj,0); @@ -1353,7 +1355,8 @@ static int yaffs_do_getxattr(const YCHAR *path, const char *name, void *data, in int retVal = -1; yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + + obj = yaffsfs_FindObject(NULL,path,0,1); if(follow) obj = yaffsfs_FollowLink(obj,0); @@ -1416,7 +1419,8 @@ static int yaffs_do_listxattr(const YCHAR *path, char *data, int size, int follo int retVal = -1; yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + + obj = yaffsfs_FindObject(NULL,path,0,1); if(follow) obj = yaffsfs_FollowLink(obj,0); @@ -1478,7 +1482,8 @@ static int yaffs_do_removexattr(const YCHAR *path, const char *name, int follow) int retVal = -1; yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + + obj = yaffsfs_FindObject(NULL,path,0,1); if(follow) obj = yaffsfs_FollowLink(obj,0); @@ -1637,7 +1642,8 @@ int yaffs_access(const YCHAR *path, int amode) int retval = 0; yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + + obj = yaffsfs_FindObject(NULL,path,0,1); if(obj) { int access_ok = 1; @@ -1673,7 +1679,8 @@ int yaffs_chmod(const YCHAR *path, mode_t mode) int retVal = -1; yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + + obj = yaffsfs_FindObject(NULL,path,0,1); if(!obj) yaffsfs_SetError(-ENOENT); @@ -2088,7 +2095,7 @@ yaffs_DIR *yaffs_opendir(const YCHAR *dirname) yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,dirname,0); + obj = yaffsfs_FindObject(NULL,dirname,0,1); if(obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY){ @@ -2216,7 +2223,7 @@ int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz) yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,path,0); + obj = yaffsfs_FindObject(NULL,path,0,1); if(!obj) { yaffsfs_SetError(-ENOENT); @@ -2245,8 +2252,8 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath) yaffsfs_Lock(); - obj = yaffsfs_FindObject(NULL,oldpath,0); - target = yaffsfs_FindObject(NULL,newpath,0); + obj = yaffsfs_FindObject(NULL,oldpath,0,1); + target = yaffsfs_FindObject(NULL,newpath,0,0); if(!obj) { yaffsfs_SetError(-ENOENT); @@ -2314,9 +2321,7 @@ int yaffs_n_handles(const YCHAR *path) { yaffs_obj_t *obj; - obj = yaffsfs_FindObject(NULL,path,0); - if(obj) - obj = yaffs_get_equivalent_obj(obj); + obj = yaffsfs_FindObject(NULL,path,0,1); return yaffsfs_CountHandles(obj); }