yaffs direct: Fix EROFS handling in some functions.
[yaffs2.git] / yaffs_guts.c
index 53c2ff6349360266ee2302d00259e32b5bbb47a6..c56e060ef5bc384e231eadb49bd484991d221492 100644 (file)
@@ -604,12 +604,10 @@ static u16 yaffs_calc_name_sum(const YCHAR * name)
 
 void yaffs_set_obj_name(struct yaffs_obj *obj, const YCHAR * name)
 {
-#ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM
-       memset(obj->short_name, 0,
-              sizeof(YCHAR) * (YAFFS_SHORT_NAME_LENGTH + 1));
-       if (name
-           && yaffs_strnlen(name,
-                            YAFFS_SHORT_NAME_LENGTH + 1) <=
+#ifndef CONFIG_YAFFS_NO_SHORT_NAMES
+       memset(obj->short_name, 0, sizeof(obj->short_name));
+       if (name && 
+               yaffs_strnlen(name, YAFFS_SHORT_NAME_LENGTH + 1) <=
            YAFFS_SHORT_NAME_LENGTH)
                yaffs_strcpy(obj->short_name, name);
        else
@@ -1622,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)
 {
@@ -1643,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
 
@@ -1652,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.
@@ -3801,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)
@@ -4540,7 +4547,7 @@ int yaffs_get_obj_name(struct yaffs_obj *obj, YCHAR * name, int buffer_size)
        if (obj->obj_id == YAFFS_OBJECTID_LOSTNFOUND) {
                yaffs_strncpy(name, YAFFS_LOSTNFOUND_NAME, buffer_size - 1);
        }
-#ifdef CONFIG_YAFFS_SHORT_NAMES_IN_RAM
+#ifndef CONFIG_YAFFS_NO_SHORT_NAMES
        else if (obj->short_name[0]) {
                yaffs_strcpy(name, obj->short_name);
        }
@@ -5060,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)));