yaffs direct: Fix error for attempting to rename over a non-empty directory
authorCharles Manning <cdhmanning@gmail.com>
Wed, 24 Nov 2010 00:50:04 +0000 (13:50 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Wed, 24 Nov 2010 00:50:04 +0000 (13:50 +1300)
Now produces -ENOTEMPTY.

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

index 29a920930013ad4f51334fcb294305e291b01fbe..76a397cf6a06e803dc7d9673c009b76c3b4a5674 100644 (file)
@@ -1314,6 +1314,7 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
        struct yaffs_obj *olddir = NULL;
        struct yaffs_obj *newdir = NULL;
        struct yaffs_obj *obj = NULL;
        struct yaffs_obj *olddir = NULL;
        struct yaffs_obj *newdir = NULL;
        struct yaffs_obj *obj = NULL;
+       struct yaffs_obj *newobj = NULL;
        YCHAR *oldname;
        YCHAR *newname;
        int result= YAFFS_FAIL;
        YCHAR *oldname;
        YCHAR *newname;
        int result= YAFFS_FAIL;
@@ -1340,6 +1341,7 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
        olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0,&notOldDir);
        newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0,&notNewDir);
        obj = yaffsfs_FindObject(NULL,oldPath,0,0,NULL,NULL);
        olddir = yaffsfs_FindDirectory(NULL,oldPath,&oldname,0,&notOldDir);
        newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0,&notNewDir);
        obj = yaffsfs_FindObject(NULL,oldPath,0,0,NULL,NULL);
+       newobj = yaffsfs_FindObject(NULL,newPath,0,0,NULL,NULL);
 
        /* If the object being renamed is a directory and the 
         * path ended with a "/" then the olddir == obj.
 
        /* If the object being renamed is a directory and the 
         * path ended with a "/" then the olddir == obj.
@@ -1362,6 +1364,9 @@ int yaffs_rename(const YCHAR *oldPath, const YCHAR *newPath)
        } else if(obj->my_dev->read_only){
                yaffsfs_SetError(-EROFS);
                rename_allowed = 0;
        } else if(obj->my_dev->read_only){
                yaffsfs_SetError(-EROFS);
                rename_allowed = 0;
+       } else if(yaffs_is_non_empty_dir(newobj)){
+               yaffsfs_SetError(-ENOTEMPTY);
+               rename_allowed = 0;
        } else if(olddir->my_dev != newdir->my_dev) {
                /* Rename must be on same device */
                yaffsfs_SetError(-EXDEV);
        } else if(olddir->my_dev != newdir->my_dev) {
                /* Rename must be on same device */
                yaffsfs_SetError(-EXDEV);
index 1bc6d51be66714e253e572ffac34ffc7bf3aebd1..c56e060ef5bc384e231eadb49bd484991d221492 100644 (file)
@@ -1669,12 +1669,8 @@ int yaffs_rename_obj(struct yaffs_obj *old_dir, const YCHAR * old_name,
                /* Now do the handling for an existing target, if there is one */
 
                existing_target = yaffs_find_by_name(new_dir, new_name);
                /* Now do the handling for an existing target, if there is one */
 
                existing_target = yaffs_find_by_name(new_dir, new_name);
-               if (existing_target &&
-                   existing_target->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY
-                   && !list_empty(&existing_target->variant.dir_variant.
-                                  children)) {
-                       /* There is a target that is a non-empty directory, so we fail */
-                       return YAFFS_FAIL;      /* EEXIST or ENOTEMPTY */
+               if (yaffs_is_non_empty_dir(existing_target)){
+                       return YAFFS_FAIL;      /* ENOTEMPTY */
                } else if (existing_target && existing_target != obj) {
                        /* Nuke the target first, using shadowing,
                         * but only if it isn't the same object.
                } else if (existing_target && existing_target != obj) {
                        /* Nuke the target first, using shadowing,
                         * but only if it isn't the same object.
@@ -3811,10 +3807,11 @@ int yaffs_del_file(struct yaffs_obj *in)
        }
 }
 
        }
 }
 
-static int yaffs_is_non_empty_dir(struct yaffs_obj *obj)
+int yaffs_is_non_empty_dir(struct yaffs_obj *obj)
 {
 {
-       return (obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) &&
-           !(list_empty(&obj->variant.dir_variant.children));
+       return (obj &&
+               obj->variant_type == YAFFS_OBJECT_TYPE_DIRECTORY) &&
+               !(list_empty(&obj->variant.dir_variant.children));
 }
 
 static int yaffs_del_dir(struct yaffs_obj *obj)
 }
 
 static int yaffs_del_dir(struct yaffs_obj *obj)
index 2c2ec765c6365e1bdf52125741f404a7b01f131a..307eba28676f5c2360668c64c2477c8804624edc 100644 (file)
@@ -911,4 +911,5 @@ struct yaffs_tnode *yaffs_find_tnode_0(struct yaffs_dev *dev,
 u32 yaffs_get_group_base(struct yaffs_dev *dev, struct yaffs_tnode *tn,
                         unsigned pos);
 
 u32 yaffs_get_group_base(struct yaffs_dev *dev, struct yaffs_tnode *tn,
                         unsigned pos);
 
+int yaffs_is_non_empty_dir(struct yaffs_obj *obj);
 #endif
 #endif