yaffs: Fix issue with look-up off null names
authorCharles Manning <cdhmanning@gmail.com>
Thu, 26 Jul 2012 00:15:16 +0000 (12:15 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Thu, 26 Jul 2012 00:15:16 +0000 (12:15 +1200)
Null names can happen if object headers are lost. The object gets named
"objnnn" where nnn is the object id.

We could therefore get the names, but the look-up was not working properly.

This fixes the issue so long as short names are enabled.

Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/basic-test/dtest.c
yaffs_guts.c

index 9f2d2e6..3cd13ab 100644 (file)
@@ -3042,6 +3042,70 @@ void large_file_test(const char *mountpt)
 }
 
 
+int  mk_dir(const char *mp, const char *name)
+{
+       char full_name[100];
+
+       sprintf(full_name, "%s/%s", mp, name);
+
+       return yaffs_mkdir(full_name, S_IREAD| S_IWRITE);
+}
+
+int  mk_file(const char *mp, const char *name)
+{
+       char full_name[100];
+       int h;
+
+       sprintf(full_name, "%s/%s", mp, name);
+
+       h = yaffs_open(full_name, O_RDWR | O_CREAT | O_TRUNC, S_IREAD| S_IWRITE);
+
+       yaffs_write(h, name, strlen(name));
+
+       yaffs_close(h);
+       return 0;
+}
+
+void xx_test(const char *mountpt)
+{
+       char xx_buffer[1000];
+
+       yaffs_start_up();
+
+       yaffs_format(mountpt,0,0,0);
+
+       yaffs_mount(mountpt);
+       printf("mounted\n");
+       dumpDir(mountpt);
+
+       printf("create files\n");
+
+       mk_dir(mountpt, "foo");
+       mk_file(mountpt, "foo/f1");
+       mk_file(mountpt, "foo/f2");
+       mk_file(mountpt, "foo/f3");
+       mk_file(mountpt, "foo/f4");
+       dump_directory_tree(mountpt);
+
+       printf("unmount and remount\n");
+
+       /* Unmount/remount */
+       yaffs_unmount(mountpt);
+       yaffs_mount(mountpt);
+       dump_directory_tree(mountpt);
+}
+
+void yy_test(const char *mountpt)
+{
+       char xx_buffer[1000];
+
+       yaffs_start_up();
+
+       yaffs_mount(mountpt);
+       dump_directory_tree(mountpt);
+}
+
+
 void readdir_test(const char *mountpt)
 {
        char xx_buffer[1000];
@@ -3176,7 +3240,7 @@ int main(int argc, char *argv[])
         //basic_utime_test("/yaffs2");
 
 
-       format_test("/yaffs2");
+       //format_test("/yaffs2");
 
        //max_files_test("/yaffs2");
 
@@ -3188,6 +3252,9 @@ int main(int argc, char *argv[])
         //basic_utime_test("/yaffs2");
         //case_insensitive_test("/yaffs2");
 
+        yy_test("/yaffs2");
+
+
         return 0;
 
 }
index b67055a..9c296e2 100644 (file)
@@ -40,7 +40,8 @@
 static int yaffs_wr_data_obj(struct yaffs_obj *in, int inode_chunk,
                             const u8 *buffer, int n_bytes, int use_reserve);
 
-
+static void yaffs_fix_null_name(struct yaffs_obj *obj, YCHAR *name,
+                               int buffer_size);
 
 /* Function to calculate chunk and offset */
 
@@ -647,15 +648,21 @@ static u16 yaffs_calc_name_sum(const YCHAR *name)
        return sum;
 }
 
+
 void yaffs_set_obj_name(struct yaffs_obj *obj, const YCHAR * name)
 {
        memset(obj->short_name, 0, sizeof(obj->short_name));
-       if (name &&
+
+       if (name && !name[0]) {
+               yaffs_fix_null_name(obj, obj->short_name,
+                               YAFFS_SHORT_NAME_LENGTH);
+               name = obj->short_name;
+       } else if (name &&
                strnlen(name, YAFFS_SHORT_NAME_LENGTH + 1) <=
-               YAFFS_SHORT_NAME_LENGTH)
+               YAFFS_SHORT_NAME_LENGTH)  {
                strcpy(obj->short_name, name);
-       else
-               obj->short_name[0] = _Y('\0');
+       }
+
        obj->sum = yaffs_calc_name_sum(name);
 }