yaffs Some changes to direct/timothy_tests/quick_tests
[yaffs2.git] / yaffs_guts.c
index 110a3c2f778b18ed81c28630453505e1c311a467..c56e060ef5bc384e231eadb49bd484991d221492 100644 (file)
@@ -1620,6 +1620,10 @@ static int yaffs_change_obj_name(struct yaffs_obj *obj,
        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)
 {
@@ -1641,7 +1645,9 @@ int yaffs_rename_obj(struct yaffs_obj *old_dir, const YCHAR * old_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
 
@@ -1650,19 +1656,21 @@ int yaffs_rename_obj(struct yaffs_obj *old_dir, const YCHAR * old_name,
                /* 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.
@@ -3799,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)
@@ -5058,7 +5067,7 @@ int yaffs_guts_initialise(struct yaffs_dev *dev)
                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)));