From 0d62a49dfe174bd70d289f0cf8e97c78585dd359 Mon Sep 17 00:00:00 2001 From: Charles Manning Date: Wed, 24 Nov 2010 13:50:04 +1300 Subject: [PATCH 1/1] yaffs direct: Fix error for attempting to rename over a non-empty directory Now produces -ENOTEMPTY. Signed-off-by: Charles Manning --- direct/yaffsfs.c | 5 +++++ yaffs_guts.c | 15 ++++++--------- yaffs_guts.h | 1 + 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/direct/yaffsfs.c b/direct/yaffsfs.c index 29a9209..76a397c 100644 --- a/direct/yaffsfs.c +++ b/direct/yaffsfs.c @@ -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,¬OldDir); newdir = yaffsfs_FindDirectory(NULL,newPath,&newname,0,¬NewDir); 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); diff --git a/yaffs_guts.c b/yaffs_guts.c index 1bc6d51..c56e060 100644 --- a/yaffs_guts.c +++ b/yaffs_guts.c @@ -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) diff --git a/yaffs_guts.h b/yaffs_guts.h index 2c2ec76..307eba2 100644 --- a/yaffs_guts.h +++ b/yaffs_guts.h @@ -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 -- 2.30.2