Fix 2 problems: rmdir of non-empty dir, handling 255 char names better
authorcharles <charles>
Tue, 11 Aug 2009 01:28:42 +0000 (01:28 +0000)
committercharles <charles>
Tue, 11 Aug 2009 01:28:42 +0000 (01:28 +0000)
direct/dtest.c
yaffs_guts.c

index 06a190e..f22babd 100644 (file)
@@ -1440,6 +1440,53 @@ void fill_empty_files_test(const char *mountpt)
        
 }
 
+void long_name_test(const char *mountpt)
+{
+       int i;
+       yaffs_StartUp();
+       char fullName[1000];
+       char name[300];
+       int result = 0;
+       
+       int d,f;
+       
+       // Make a 256 byte name
+       memset(name,0,sizeof(name));
+       for(i = 0; i < 256; i++)
+               name[i] = '0' + i % 10;
+               
+       sprintf(fullName,"%s/%s",mountpt,name);
+
+       for(i = 0; i < 1; i++)
+       {
+               yaffs_mount(mountpt);
+               
+               printf("Files at start\n");
+               dumpDir(mountpt);
+               
+               printf("Creating file %s\n",fullName);
+               
+               f = yaffs_open(fullName,O_CREAT | O_RDWR,0);
+               yaffs_close(f);
+               
+               printf("Result %d\n",f);
+                       
+               printf("Files\n");
+               dumpDir(mountpt);
+               
+               printf("Deleting %s\n",fullName);
+               result = yaffs_unlink(fullName);
+               printf("Result %d\n",result);
+               
+               printf("Files\n");
+               
+               dumpDir(mountpt);
+               
+               yaffs_unmount(mountpt);
+       }
+       
+}
+
 
 
 void lookup_test(const char *mountpt)
@@ -2360,7 +2407,8 @@ int main(int argc, char *argv[])
 
        //rename_over_test("//////////////////flash///////////////////yaffs1///////////");
        
-       fill_empty_files_test("/yaffs2/");
+       //fill_empty_files_test("/yaffs2/");
+       long_name_test("/yaffs2");
        
         //scan_pattern_test("/flash",10000,10);
        //short_scan_test("/flash/flash",40000,200);
index 9872305..15b20ac 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 const char *yaffs_guts_c_version =
-    "$Id: yaffs_guts.c,v 1.87 2009-07-29 04:30:24 charles Exp $";
+    "$Id: yaffs_guts.c,v 1.88 2009-08-11 01:28:42 charles Exp $";
 
 #include "yportenv.h"
 
@@ -5172,14 +5172,19 @@ int yaffs_DeleteFile(yaffs_Object *in)
        }
 }
 
-static int yaffs_DeleteDirectory(yaffs_Object *in)
+static int yaffs_IsNonEmptyDirectory(yaffs_Object *obj)
 {
-       /* First check that the directory is empty. */
-       if (ylist_empty(&in->variant.directoryVariant.children))
-               return yaffs_DoGenericObjectDeletion(in);
+       return (obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY) &&
+               !(ylist_empty(&obj->variant.directoryVariant.children));
+}
 
-       return YAFFS_FAIL;
+static int yaffs_DeleteDirectory(yaffs_Object *obj)
+{
+       /* First check that the directory is empty. */
+       if (yaffs_IsNonEmptyDirectory(obj))
+               return YAFFS_FAIL;
 
+       return yaffs_DoGenericObjectDeletion(obj);
 }
 
 static int yaffs_DeleteSymLink(yaffs_Object *in)
@@ -5295,7 +5300,9 @@ static int yaffs_UnlinkWorker(yaffs_Object *obj)
                default:
                        return YAFFS_FAIL;
                }
-       } else
+       } else if(yaffs_IsNonEmptyDirectory(obj))
+               return YAFFS_FAIL;
+       else
                return yaffs_ChangeObjectName(obj, obj->myDev->unlinkedDir,
                                           _Y("unlinked"), 0, 0);
 }
@@ -6811,7 +6818,7 @@ yaffs_Object *yaffs_FindObjectByName(yaffs_Object *directory,
                                 * Do a real check
                                 */
                                yaffs_GetObjectName(l, buffer,
-                                                   YAFFS_MAX_NAME_LENGTH);
+                                                   YAFFS_MAX_NAME_LENGTH + 1);
                                if (yaffs_strncmp(name, buffer, YAFFS_MAX_NAME_LENGTH) == 0)
                                        return l;
                        }
@@ -7060,7 +7067,7 @@ int yaffs_DumpObject(yaffs_Object *obj)
 {
        YCHAR name[257];
 
-       yaffs_GetObjectName(obj, name, 256);
+       yaffs_GetObjectName(obj, name, YAFFS_MAX_NAME_LENGTH + 1);
 
        T(YAFFS_TRACE_ALWAYS,
          (TSTR