yaffs direct: Prevent yaffs_start_up being called twice.
authorCharles Manning <cdhmanning@gmail.com>
Wed, 18 Jan 2012 01:43:13 +0000 (14:43 +1300)
committerCharles Manning <cdhmanning@gmail.com>
Wed, 18 Jan 2012 01:43:13 +0000 (14:43 +1300)
It is OK to add more devices on the fly, but the yaffs_start_up function
memsets the device back to 0 which nukes the list head and breaks the list.

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

index 0a54bd4..3535423 100644 (file)
@@ -2797,6 +2797,18 @@ void max_files_test(const char *mountpt)
 
 }
 
+void start_twice(const char *mountpt)
+{
+         printf("About to do first yaffs_start\n");
+         yaffs_start_up();
+         printf("started\n");
+         printf("First mount returns %d\n", yaffs_mount(mountpt));
+         printf("About to do second yaffs_start\n");
+         yaffs_start_up();
+         printf("started\n");
+         printf("Second mount returns %d\n", yaffs_mount(mountpt));
+}
+
 int random_seed;
 int simulate_power_failure;
 
@@ -2864,7 +2876,9 @@ int main(int argc, char *argv[])
         // link_follow_test("/yaffs2");
         //basic_utime_test("/yaffs2");
 
-        max_files_test("/yaffs2");
+        //max_files_test("/yaffs2");
+        
+        start_twice("/yaffs2");
 
 
         return 0;
index 441ee05..b857479 100644 (file)
 
 #include <errno.h>
 
-unsigned yaffs_trace_mask = 
+unsigned yaffs_trace_mask =
 
-       YAFFS_TRACE_SCAN |  
+       YAFFS_TRACE_SCAN |
        YAFFS_TRACE_GC |
-       YAFFS_TRACE_ERASE | 
-       YAFFS_TRACE_ERROR | 
-       YAFFS_TRACE_TRACING | 
-       YAFFS_TRACE_ALLOCATE | 
+       YAFFS_TRACE_ERASE |
+       YAFFS_TRACE_ERROR |
+       YAFFS_TRACE_TRACING |
+       YAFFS_TRACE_ALLOCATE |
        YAFFS_TRACE_BAD_BLOCKS |
-       YAFFS_TRACE_VERIFY | 
-       
+       YAFFS_TRACE_VERIFY |
+
        0;
-        
+
 
 
 // Configuration
@@ -58,10 +58,16 @@ struct yaffs_dev m18_1Dev;
 
 int yaffs_start_up(void)
 {
+       static int start_up_called = 0;
+
+       if(start_up_called)
+               return;
+       start_up_called = 1;
+
        // Stuff to configure YAFFS
        // Stuff to initialise anything special (eg lock semaphore).
        yaffsfs_OSInitialisation();
-       
+
        // Set up devices
        // /ram1   ram, yaffs1
        memset(&ram1Dev,0,sizeof(ram1Dev));
@@ -70,7 +76,7 @@ int yaffs_start_up(void)
        ram1Dev.param.chunks_per_block = 32;
        ram1Dev.param.n_reserved_blocks = 2; // Set this smaller for RAM
        ram1Dev.param.start_block = 0; // Can use block 0
-       ram1Dev.param.end_block = 127; // Last block in 2MB.    
+       ram1Dev.param.end_block = 127; // Last block in 2MB.
        //ram1Dev.param.use_nand_ecc = 1;
        ram1Dev.param.n_caches = 0;     // Disable caching on this device.
        ram1Dev.driver_context = (void *) 0;    // Used to identify the device in fstat.
@@ -78,7 +84,7 @@ int yaffs_start_up(void)
        ram1Dev.param.read_chunk_tags_fn = yramdisk_rd_chunk;
        ram1Dev.param.erase_fn = yramdisk_erase;
        ram1Dev.param.initialise_flash_fn = yramdisk_initialise;
-       
+
        yaffs_add_device(&ram1Dev);
 
        // /M18-1 yaffs1 on M18 nor sim
@@ -130,7 +136,7 @@ int yaffs_start_up(void)
        yaffs_add_device(&flashDev);
 
 // todo        yaffs_initialise(yaffsfs_config);
-       
+
        return 0;
 }
 
index 2668b22..37d6cae 100644 (file)
@@ -2720,6 +2720,14 @@ int yaffs_inodecount(const YCHAR *path)
 
 void yaffs_add_device(struct yaffs_dev *dev)
 {
+       struct list_head *cfg;
+       /* First check that the device is not in the list. */
+
+       list_for_each(cfg, &yaffsfs_deviceList){
+               if(dev == list_entry(cfg, struct yaffs_dev, dev_list))
+                       return;
+       }
+
        dev->is_mounted = 0;
        dev->param.remove_obj_fn = yaffsfs_RemoveObjectCallback;