yaffsfs.c
// yaffsfs_FindDirectory
// Parse a path to determine the directory and the name within the directory.
//
// eg. "/data/xx/ff" --> puts name="ff" and returns the directory "/data/xx"
yaffsfs_FindDirectory
Parse a path to determine the directory and the name within the directory.

eg.
yaffsfs_FindDirectory Parse a path to determine the directory and the name within the directory . eg .
static yaffs_Object *yaffsfs_DoFindDirectory(yaffs_Object *startDir,const YCHAR *path,YCHAR **name,int symDepth)
{
	yaffs_Object *dir;
	YCHAR *restOfPath;
	YCHAR str[YAFFS_MAX_NAME_LENGTH+1];
	int i;
	if(symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES)
	{
		return NULL;
	}
	if(startDir)
	{
		dir = startDir;
		restOfPath = (YCHAR *)path;
	}
	else
	{
		dir = yaffsfs_FindRoot(path,&restOfPath);
	}
	while(dir)
	{
		while(yaffsfs_IsPathDivider(*restOfPath))
		{
			restOfPath++; 
		}
		*name = restOfPath;
		i = 0;
		while(*restOfPath && !yaffsfs_IsPathDivider(*restOfPath))
		{
			if (i < YAFFS_MAX_NAME_LENGTH)
			{
				str[i] = *restOfPath;
				str[i+1] = '\0';
				i++;
			}
			restOfPath++;
		}
		if(!*restOfPath)
		{
			return dir;
		}
		else
		{
			if(yaffs_strcmp(str,_Y(".")) == 0)
			{
			}
			else if(yaffs_strcmp(str,_Y("..")) == 0)
			{
				dir = dir->parent;
			}
			else
			{
				dir = yaffs_FindObjectByName(dir,str);
				while(dir && dir->variantType == YAFFS_OBJECT_TYPE_SYMLINK)
				{
					dir = yaffsfs_FollowLink(dir,symDepth);
				}
				if(dir && dir->variantType != YAFFS_OBJECT_TYPE_DIRECTORY)
				{
					dir = NULL;
				}
			}
		}
	}
	return NULL;
}
static yaffs_Object * yaffsfs_DoFindDirectory ( yaffs_Object * startDir , const YCHAR * path , YCHAR * * name , int symDepth ) { yaffs_Object * dir ; YCHAR * restOfPath ; YCHAR str [ YAFFS_MAX_NAME_LENGTH + 1 ] ; int i ; if ( symDepth > YAFFSFS_MAX_SYMLINK_DEREFERENCES ) { return NULL ; } if ( startDir ) { dir = startDir ; restOfPath = ( YCHAR * ) path ; } else { dir = yaffsfs_FindRoot ( path , & restOfPath ) ; } while ( dir ) { while ( yaffsfs_IsPathDivider ( * restOfPath ) ) { restOfPath ++ ; } * name = restOfPath ; i = 0 ; while ( * restOfPath && ! yaffsfs_IsPathDivider ( * restOfPath ) ) { if ( i < YAFFS_MAX_NAME_LENGTH ) { str [ i ] = * restOfPath ; str [ i + 1 ] = ' \0 ' ; i ++ ; } restOfPath ++ ; } if ( ! * restOfPath ) { return dir ; } else { if ( yaffs_strcmp ( str , _Y ( " " ) ) == 0 ) { } else if ( yaffs_strcmp ( str , _Y ( " " ) ) == 0 ) { dir = dir -> parent ; } else { dir = yaffs_FindObjectByName ( dir , str ) ; while ( dir && dir -> variantType == YAFFS_OBJECT_TYPE_SYMLINK ) { dir = yaffsfs_FollowLink ( dir , symDepth ) ; } if ( dir && dir -> variantType != YAFFS_OBJECT_TYPE_DIRECTORY ) { dir = NULL ; } } } } return NULL ; }
yaffsfs_FindDirectory
Parse a path to determine the directory and the name within the directory.
yaffsfs_FindDirectory Parse a path to determine the directory and the name within the directory .
// parse off /. // curve ball: also throw away surplus '/' // eg. "/ram/x////ff" gets treated the same as "/ram/x/ff" // get rid of '/' // got to the end of the string // Do nothing // directory did not exist.