yaffs direct: Clean ups fixing stuff caught by Timthy's tests
authorCharles Manning <cdhmanning@gmail.com>
Mon, 8 Nov 2010 04:15:52 +0000 (17:15 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Mon, 8 Nov 2010 04:15:52 +0000 (17:15 +1300)
Some error codes were not being set correctly. Fixed them.

More to follow...

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/yaffsfs.c
direct/yaffsfs.h

index 3f18f7b002b439a3370c74a76b4daa702a6b5c06..41d37f46601f1939e90ea883ec2002b1e348b3d6 100644 (file)
@@ -67,14 +67,14 @@ static yaffsfs_Inode yaffsfs_inode[YAFFSFS_N_HANDLES];
 static yaffsfs_Handle yaffsfs_handle[YAFFSFS_N_HANDLES];
 static int yaffsfs_handlesInitialised;
 
 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;
 }
 {
        return yaffs_trace_mask;
 }
@@ -304,12 +304,12 @@ int yaffsfs_CheckNameLength(const char *name)
 {
        int retVal = 0;         
 
 {
        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;
                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;
        }
                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)
        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();
 
                yaffsfs_SetError(-EINVAL);
        else
                result = yaffs_resize_file(obj,new_size);
 
        yaffsfs_Unlock();
 
-
        return (result) ? 0 : -1;
 }
 
        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)
                /* 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();
 
                yaffsfs_SetError(-EINVAL);
        else
                /* resize the file */
                result = yaffs_resize_file(obj,new_size);
        yaffsfs_Unlock();
 
-
        return (result) ? 0 : -1;
 
 }
        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) {
                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) {
                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;
 
 
        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);
        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;
 
        struct yaffs_obj *obj = NULL;
        int retVal;
 
-
        yaffsfs_Lock();
 
        obj = yaffsfs_FindObject(NULL,path,0,1);
        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;
        struct yaffs_obj *obj = NULL;
        struct yaffs_obj *target = NULL;
        int retVal = 0;
-       int new_nameLength = 0;
-
 
        yaffsfs_Lock();
 
 
        yaffsfs_Lock();
 
index e9e40f96d5837aaa63721d1e94819e40bb6ee1cc..6eb30efca65e38b1609b7c0d6e25dff76b49892d 100644 (file)
@@ -35,6 +35,8 @@
 #define NAME_MAX       256
 #endif
 
 #define NAME_MAX       256
 #endif
 
+#define YAFFS_MAX_FILE_SIZE (0x7FFFFFFF)
+
 
 struct yaffs_dirent{
     long d_ino;                 /* inode number */
 
 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_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
 
 
 #endif