From ddc0558522ec4a25d3f12f1d0d83c81a6bb7996a Mon Sep 17 00:00:00 2001 From: Charles Manning Date: Mon, 8 Nov 2010 17:15:52 +1300 Subject: [PATCH] yaffs direct: Clean ups fixing stuff caught by Timthy's tests Some error codes were not being set correctly. Fixed them. More to follow... Signed-off-by: Charles Manning --- direct/yaffsfs.c | 31 +++++++++++++++++-------------- direct/yaffsfs.h | 6 ++++-- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 3f18f7b..41d37f4 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -67,14 +67,14 @@ static yaffsfs_Inode yaffsfs_inode[YAFFSFS_N_HANDLES]; static yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES]; static int yaffsfs_handlesInitialised; -unsigned int yaffs_trace_mask; -int yaffs_set_trace(unsigned int tm) +unsigned yaffs_set_trace(unsigned tm) { - return yaffs_trace_mask=tm; + yaffs_trace_mask = tm; + return yaffs_trace_mask; } -unsigned int yaffs_get_trace(void) +unsigned yaffs_get_trace(void) { return yaffs_trace_mask; } @@ -304,12 +304,12 @@ int yaffsfs_CheckNameLength(const char *name) { int retVal = 0; - new_nameLength = yaffs_strnlen(newname,YAFFS_MAX_NAME_LENGTH+1); + int nameLength = yaffs_strnlen(name,YAFFS_MAX_NAME_LENGTH+1); - if(new_nameLength == 0){ + if(nameLength == 0){ yaffsfs_SetError(-ENOENT); retVal = -1; - } else if (new_nameLength > YAFFS_MAX_NAME_LENGTH){ + } else if (nameLength > YAFFS_MAX_NAME_LENGTH){ yaffsfs_SetError(-ENAMETOOLONG); retVal = -1; } @@ -1021,13 +1021,14 @@ int yaffs_truncate(const YCHAR *path,off_t new_size) else if(obj->variant_type != YAFFS_OBJECT_TYPE_FILE) yaffsfs_SetError(-EISDIR); else if(obj->my_dev->read_only) + yaffsfs_SetError(-EACCES); + else if(new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE) yaffsfs_SetError(-EINVAL); else result = yaffs_resize_file(obj,new_size); yaffsfs_Unlock(); - return (result) ? 0 : -1; } @@ -1045,13 +1046,14 @@ int yaffs_ftruncate(int fd, off_t new_size) /* bad handle */ yaffsfs_SetError(-EBADF); else if(obj->my_dev->read_only) + yaffsfs_SetError(-EACCES); + else if( new_size < 0 || new_size > YAFFS_MAX_FILE_SIZE) yaffsfs_SetError(-EINVAL); else /* resize the file */ result = yaffs_resize_file(obj,new_size); yaffsfs_Unlock(); - return (result) ? 0 : -1; } @@ -1165,8 +1167,7 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath) yaffsfs_SetError(-EINVAL); rename_allowed = 0; } else if(olddir->my_dev != newdir->my_dev) { - /* oops must be on same device */ - /* todo error */ + /* Rename must be on same device */ yaffsfs_SetError(-EXDEV); rename_allowed = 0; } else if(obj && obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) { @@ -1655,6 +1656,11 @@ int yaffs_access(const YCHAR *path, int amode) int retval = 0; + if(amode & ~(R_OK | W_OK | X_OK)){ + yaffsfs_SetError(-EINVAL); + return -1; + } + yaffsfs_Lock(); obj = yaffsfs_FindObject(NULL,path,0,1); @@ -2269,7 +2275,6 @@ int yaffs_readlink(const YCHAR *path, YCHAR *buf, int bufsiz) struct yaffs_obj *obj = NULL; int retVal; - yaffsfs_Lock(); obj = yaffsfs_FindObject(NULL,path,0,1); @@ -2296,8 +2301,6 @@ int yaffs_link(const YCHAR *oldpath, const YCHAR *newpath) struct yaffs_obj *obj = NULL; struct yaffs_obj *target = NULL; int retVal = 0; - int new_nameLength = 0; - yaffsfs_Lock(); diff --git a/direct/yaffsfs.h b/direct/yaffsfs.h index e9e40f9..6eb30ef 100644 --- a/direct/yaffsfs.h +++ b/direct/yaffsfs.h @@ -35,6 +35,8 @@ #define NAME_MAX 256 #endif +#define YAFFS_MAX_FILE_SIZE (0x7FFFFFFF) + struct yaffs_dirent{ long d_ino; /* inode number */ @@ -180,8 +182,8 @@ void * yaffs_getdev(const YCHAR *path); int yaffs_dump_dev(const YCHAR *path); /* Trace control functions */ -int yaffs_set_trace(unsigned int tm); -unsigned int yaffs_get_trace(void); +unsigned yaffs_set_trace(unsigned tm); +unsigned yaffs_get_trace(void); #endif -- 2.30.2