#define YAFFSFS_RW_SIZE (1<<YAFFSFS_RW_SHIFT)
/* Some forward references */
-static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path, int symDepth);
+static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path, int symDepth, int getEquiv);
static void yaffsfs_RemoveObjectCallback(yaffs_Object *obj);
unsigned int yaffs_wr_attempts;
static yaffs_Object *yaffsfs_FollowLink(yaffs_Object *obj,int symDepth)
{
+ if(obj)
+ obj = yaffs_GetEquivalentObject(obj);
+
while(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK){
YCHAR *alias = obj->variant.symLinkVariant.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;
}
else{
dir = yaffs_FindObjectByName(dir,str);
- while(dir && dir->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
- dir = yaffsfs_FollowLink(dir,symDepth);
+ dir = yaffsfs_FollowLink(dir,symDepth);
if(dir && dir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
/*
* yaffsfs_FindObject turns a path for an existing object into the object
*/
-static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path,int symDepth)
+static yaffs_Object *yaffsfs_FindObject(yaffs_Object *relativeDirectory, const YCHAR *path,int symDepth,int getEquiv)
{
yaffs_Object *dir;
+ yaffs_Object *obj;
YCHAR *name;
dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth);
if(dir && *name)
- return yaffs_FindObjectByName(dir,name);
+ obj = yaffs_FindObjectByName(dir,name);
+ else
+ obj = dir;
+ if(getEquiv)
+ obj = yaffs_GetEquivalentObject(obj);
- return dir;
+ return obj;
}
yaffs_Object *dir = NULL;
YCHAR *name;
int handle = -1;
- yaffsfs_Handle *h = NULL;
+ yaffsfs_Handle *yh = NULL;
int openDenied = 0;
int symDepth = 0;
int errorReported = 0;
if(handle >= 0){
- h = yaffsfs_GetHandlePointer(handle);
+ yh = yaffsfs_GetHandlePointer(handle);
/* try to find the exisiting object */
- obj = yaffsfs_FindObject(NULL,path,0);
+ obj = yaffsfs_FindObject(NULL,path,0,1);
- if(obj && obj->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
- obj = yaffsfs_FollowLink(obj,symDepth++);
-
- if(obj)
- obj = yaffs_GetEquivalentObject(obj);
+ obj = yaffsfs_FollowLink(obj,symDepth++);
if(obj &&
obj->variantType != YAFFS_OBJECT_TYPE_FILE &&
/* 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;
}
}
*/
}
- 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->myInode = (void*) &yaffsfs_inode[inodeId];
- if((oflag & O_TRUNC) && h->writing)
+ if((oflag & O_TRUNC) && yh->writing)
yaffs_ResizeFile(obj,0);
} else {
yaffsfs_PutHandle(handle);
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0);
- if(obj)
- obj = yaffs_GetEquivalentObject(obj);
+ obj = yaffsfs_FindObject(NULL,path,0,1);
if(!obj)
yaffsfs_SetError(-ENOENT);
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);
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 */
{
int retVal = -1;
- if(obj)
- obj = yaffs_GetEquivalentObject(obj);
+ obj = yaffs_GetEquivalentObject(obj);
if(obj && buf){
buf->st_dev = (int)obj->myDev->osContext;
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);
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);
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);
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);
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);
int retval = 0;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0);
+
+ obj = yaffsfs_FindObject(NULL,path,0,1);
if(obj) {
int access_ok = 1;
int retVal = -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0);
+
+ obj = yaffsfs_FindObject(NULL,path,0,1);
if(!obj)
yaffsfs_SetError(-ENOENT);
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,dirname,0);
+ obj = yaffsfs_FindObject(NULL,dirname,0,1);
if(obj && obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY){
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0);
+ obj = yaffsfs_FindObject(NULL,path,0,1);
if(!obj) {
yaffsfs_SetError(-ENOENT);
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);
{
yaffs_Object *obj;
- obj = yaffsfs_FindObject(NULL,path,0);
- if(obj)
- obj = yaffs_GetEquivalentObject(obj);
+ obj = yaffsfs_FindObject(NULL,path,0,1);
return yaffsfs_CountHandles(obj);
}
+int yaffs_get_error(void)
+{
+ return yaffsfs_GetLastError();
+}
+
int yaffs_DumpDevStruct(const YCHAR *path)
{
#if 0