/* Some forward references */
static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relativeDirectory,
- const YCHAR *path, int symDepth, int getEquiv);
+ const YCHAR *path,
+ int symDepth, int getEquiv,
+ struct yaffs_obj **dirOut);
+
static void yaffsfs_RemoveObjectCallback(struct yaffs_obj *obj);
unsigned int yaffs_wr_attempts;
if(yaffsfs_IsPathDivider(*alias))
/* Starts with a /, need to scan from root up */
- obj = yaffsfs_FindObject(NULL,alias,symDepth++,1);
+ obj = yaffsfs_FindObject(NULL,alias,symDepth++,1,NULL);
else
/* Relative to here, so use the parent of the symlink as a start */
- obj = yaffsfs_FindObject(obj->parent,alias,symDepth++,1);
+ obj = yaffsfs_FindObject(obj->parent,alias,symDepth++,1,NULL);
}
return obj;
}
/*
* yaffsfs_FindObject turns a path for an existing object into the object
*/
-static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relativeDirectory, const YCHAR *path,int symDepth, int getEquiv)
+static struct yaffs_obj *yaffsfs_FindObject(struct yaffs_obj *relativeDirectory,
+ const YCHAR *path,int symDepth, int getEquiv,
+ struct yaffs_obj **dirOut)
{
struct yaffs_obj *dir;
struct yaffs_obj *obj;
dir = yaffsfs_FindDirectory(relativeDirectory,path,&name,symDepth);
+ if(dirOut)
+ *dirOut = dir;
+
if(dir && *name)
obj = yaffs_find_by_name(dir,name);
else
yh = yaffsfs_GetHandlePointer(handle);
/* try to find the exisiting object */
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1,NULL);
obj = yaffsfs_FollowLink(obj,symDepth++);
int yaffs_truncate(const YCHAR *path,off_t new_size)
{
struct yaffs_obj *obj = NULL;
+ struct yaffs_obj *dir = NULL;
int result = YAFFS_FAIL;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir);
- if(!obj)
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
yaffsfs_SetError(-ENOENT);
else if(obj->variant_type != YAFFS_OBJECT_TYPE_FILE)
yaffsfs_SetError(-EISDIR);
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,0);
+ obj = yaffsfs_FindObject(NULL,path,0,0,NULL);
dir = yaffsfs_FindDirectory(NULL,path,&name,0);
+
if(!dir)
yaffsfs_SetError(-ENOTDIR);
else if(!obj)
olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0);
newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0);
- obj = yaffsfs_FindObject(NULL,oldPath,0,0);
+ obj = yaffsfs_FindObject(NULL,oldPath,0,0,NULL);
- if(!olddir || !newdir || !obj) {
- /* bad file */
- yaffsfs_SetError(-EBADF);
+ if(!olddir || !newdir) {
+ yaffsfs_SetError(-ENOTDIR);
+ rename_allowed = 0;
+ } else if(!obj) {
+ yaffsfs_SetError(-ENOENT);
rename_allowed = 0;
} else if(obj->my_dev->read_only){
- yaffsfs_SetError(-EINVAL);
+ yaffsfs_SetError(-EROFS);
rename_allowed = 0;
} else if(olddir->my_dev != newdir->my_dev) {
/* Rename must be on same device */
xx = xx->parent;
}
if(!rename_allowed)
- yaffsfs_SetError(-EACCES);
+ yaffsfs_SetError(-EINVAL);
}
if(rename_allowed)
static int yaffsfs_DoStatOrLStat(const YCHAR *path, struct yaffs_stat *buf,int doLStat)
{
- struct yaffs_obj *obj;
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
int retVal = -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir);
if(!doLStat && obj)
obj = yaffsfs_FollowLink(obj,0);
- if(obj)
- retVal = yaffsfs_DoStat(obj,buf);
- else
- /* todo error not found */
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
yaffsfs_SetError(-ENOENT);
+ else
+ retVal = yaffsfs_DoStat(obj,buf);
yaffsfs_Unlock();
static int yaffs_do_setxattr(const YCHAR *path, const char *name, const void *data, int size, int flags, int follow)
{
struct yaffs_obj *obj;
+ struct yaffs_obj *dir;
int retVal = -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir);
if(follow)
obj = yaffsfs_FollowLink(obj,0);
- if(obj) {
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
retVal = yaffs_set_xattrib(obj,name,data,size,flags);
if(retVal< 0){
yaffsfs_SetError(retVal);
retVal = -1;
}
- } else
- /* todo error not found */
- yaffsfs_SetError(-ENOENT);
+ }
yaffsfs_Unlock();
yaffsfs_Lock();
obj = yaffsfs_GetHandleObject(fd);
- if(obj) {
+ if(!obj)
+ yaffsfs_SetError(-EBADF);
+ else {
retVal = yaffs_set_xattrib(obj,name,data,size,flags);
if(retVal< 0){
yaffsfs_SetError(retVal);
retVal = -1;
}
- } else
- /* bad handle */
- yaffsfs_SetError(-EBADF);
+ }
yaffsfs_Unlock();
static int yaffs_do_getxattr(const YCHAR *path, const char *name, void *data, int size, int follow)
{
struct yaffs_obj *obj;
+ struct yaffs_obj *dir;
int retVal = -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir);
if(follow)
obj = yaffsfs_FollowLink(obj,0);
- if(obj) {
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
retVal = yaffs_get_xattrib(obj,name,data,size);
if(retVal< 0){
yaffsfs_SetError(retVal);
retVal = -1;
}
- } else
- /* todo error not found */
- yaffsfs_SetError(-ENOENT);
-
+ }
yaffsfs_Unlock();
return retVal;
static int yaffs_do_listxattr(const YCHAR *path, char *data, int size, int follow)
{
- struct yaffs_obj *obj;
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
int retVal = -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1,&dir);
if(follow)
obj = yaffsfs_FollowLink(obj,0);
- if(obj) {
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
retVal = yaffs_list_xattrib(obj, data,size);
if(retVal< 0){
yaffsfs_SetError(retVal);
retVal = -1;
}
- } else
- /* todo error not found */
- yaffsfs_SetError(-ENOENT);
+ }
yaffsfs_Unlock();
static int yaffs_do_removexattr(const YCHAR *path, const char *name, int follow)
{
- struct yaffs_obj *obj;
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
int retVal = -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1, &dir);
if(follow)
obj = yaffsfs_FollowLink(obj,0);
- if(obj) {
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
retVal = yaffs_remove_xattrib(obj,name);
if(retVal< 0){
yaffsfs_SetError(retVal);
retVal = -1;
}
- } else
- /* todo error not found */
- yaffsfs_SetError(-ENOENT);
+ }
yaffsfs_Unlock();
int yaffs_access(const YCHAR *path, int amode)
{
- struct yaffs_obj *obj;
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
int retval = 0;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1, &dir);
- if(obj) {
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
+ yaffsfs_SetError(-ENOENT);
+ else {
int access_ok = 1;
if((amode & R_OK) && !(obj->yst_mode & S_IREAD))
yaffsfs_SetError(-EACCES);
retval = -1;
}
- } else {
- /* todo error not found */
- yaffsfs_SetError(-ENOENT);
- retval = -1;
}
yaffsfs_Unlock();
int yaffs_chmod(const YCHAR *path, mode_t mode)
{
- struct yaffs_obj *obj;
+ struct yaffs_obj *obj=NULL;
+ struct yaffs_obj *dir=NULL;
int retVal = -1;
if(mode & ~(0777)){
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1, &dir);
- if(!obj)
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
yaffsfs_SetError(-ENOENT);
else if(obj->my_dev->read_only)
yaffsfs_SetError(-EROFS);
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,dirname,0,1);
+ obj = yaffsfs_FindObject(NULL,dirname,0,1,NULL);
if(obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY){
int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz)
{
struct yaffs_obj *obj = NULL;
- int retVal;
+ struct yaffs_obj *dir = NULL;
+ int retVal= -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1, &dir);
- if(!obj) {
+ if(!dir)
+ yaffsfs_SetError(-ENOTDIR);
+ else if(!obj)
yaffsfs_SetError(-ENOENT);
- retVal = -1;
- } else if(obj->variant_type != YAFFS_OBJECT_TYPE_SYMLINK) {
+ else if(obj->variant_type != YAFFS_OBJECT_TYPE_SYMLINK)
yaffsfs_SetError(-EINVAL);
- retVal = -1;
- } else {
+ else {
YCHAR *alias = obj->variant.symlink_variant.alias;
memset(buf,0,bufsiz);
yaffs_strncpy(buf,alias,bufsiz - 1);
return retVal;
}
-int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath)
+int yaffs_link(const YCHAR *oldpath, const YCHAR *linkpath)
{
/* Creates a link called newpath to existing oldpath */
struct yaffs_obj *obj = NULL;
- struct yaffs_obj *target = NULL;
- int retVal = 0;
+ struct yaffs_obj *lnk = NULL;
+ int retVal = -1;
yaffsfs_Lock();
- obj = yaffsfs_FindObject(NULL,oldpath,0,1);
- target = yaffsfs_FindObject(NULL,newpath,0,0);
+ obj = yaffsfs_FindObject(NULL,oldpath,0,1,NULL);
+ lnk = yaffsfs_FindObject(NULL,linkpath,0,0,NULL);
- if(!obj) {
+ if(!obj)
yaffsfs_SetError(-ENOENT);
- retVal = -1;
- } else if(obj->my_dev->read_only){
+ else if(obj->my_dev->read_only)
yaffsfs_SetError(-EINVAL);
- retVal= -1;
- } else if(target) {
+ else if(lnk)
yaffsfs_SetError(-EEXIST);
- retVal = -1;
- } else {
+ else {
struct yaffs_obj *newdir = NULL;
struct yaffs_obj *link = NULL;
YCHAR *newname;
- newdir = yaffsfs_FindDirectory(NULL,newpath,&newname,0);
+ newdir = yaffsfs_FindDirectory(NULL,linkpath,&newname,0);
- if(!newdir){
+ if(!newdir)
yaffsfs_SetError(-ENOTDIR);
- retVal = -1;
- }else if(newdir->my_dev != obj->my_dev){
+ else if(newdir->my_dev != obj->my_dev)
yaffsfs_SetError(-EXDEV);
- retVal = -1;
- }
retVal = yaffsfs_CheckNameLength(newname);
{
struct yaffs_obj *obj;
- obj = yaffsfs_FindObject(NULL,path,0,1);
+ obj = yaffsfs_FindObject(NULL,path,0,1,NULL);
return yaffsfs_CountHandles(obj);
}