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 29a9209..76a397c 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 *newobj = NULL;
        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);
+       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.
@@ -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(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);
index 1bc6d51..c56e060 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);
-               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.
@@ -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)
index 2c2ec76..307eba2 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);
 
+int yaffs_is_non_empty_dir(struct yaffs_obj *obj);
 #endif