return YAFFS_FAIL;
}
+
+/* Note:
+ * If old_name is NULL then we take old_dir as the object to be renamed.
+ */
int yaffs_rename_obj(struct yaffs_obj *old_dir, const YCHAR * old_name,
struct yaffs_obj *new_dir, const YCHAR * new_name)
{
* While look-up is case insensitive, the name isn't.
* Therefore we might want to change x.txt to X.txt
*/
- if (old_dir == new_dir && yaffs_strcmp(old_name, new_name) == 0)
+ if (old_dir == new_dir &&
+ old_name && new_name &&
+ yaffs_strcmp(old_name, new_name) == 0)
force = 1;
#endif
/* ENAMETOOLONG */
return YAFFS_FAIL;
- obj = yaffs_find_by_name(old_dir, old_name);
+ if(old_name)
+ obj = yaffs_find_by_name(old_dir, old_name);
+ else{
+ obj = old_dir;
+ old_dir = obj->parent;
+ }
+
if (obj && obj->rename_allowed) {
/* 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.
}
}
-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)
if (dev->param.is_yaffs2) {
if (yaffs2_checkpt_restore(dev)) {
yaffs_check_obj_details_loaded(dev->root_dir);
- T(YAFFS_TRACE_ALWAYS,
+ T(YAFFS_TRACE_CHECKPOINT | YAFFS_TRACE_MOUNT,
(TSTR
("yaffs: restored from checkpoint"
TENDSTR)));