Initialise device properly when doing a format.
authorCharles Manning <cdhmanning@gmail.com>
Thu, 11 Jul 2013 05:33:53 +0000 (17:33 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Thu, 11 Jul 2013 05:33:53 +0000 (17:33 +1200)
Signed-off-by: Charles Manning <cdhmanning@gmail.com>
direct/test-framework/basic-tests/dtest.c
direct/yaffsfs.c
yaffs_guts.c
yaffs_guts.h

index 665071b..a6a8c9d 100644 (file)
@@ -3199,7 +3199,6 @@ void readdir_test(const char *mountpt)
 
        yaffs_unmount(mountpt);
 
-
 }
 
 void format_test(const char *mountpt)
@@ -3209,21 +3208,25 @@ void format_test(const char *mountpt)
        yaffs_start_up();
 
        ret = yaffs_format(mountpt, 0, 0, 0);
-       printf("yaffs_format(...,0, 0, 0) of unmounted returned %d\n", ret);
+       printf("yaffs_format(...,0, 0, 0) of unmounted returned %d."
+               " Should return 0\n\n\n", ret);
 
        yaffs_mount(mountpt);
 
        ret = yaffs_format(mountpt, 0, 0, 0);
-       printf("yaffs_format(...,0, 0, 0) of mounted returned %d\n", ret);
+       printf("yaffs_format(...,0, 0, 0) of mounted returned %d."
+               " Should return -1 (busy)\n\n\n", ret);
 
        ret = yaffs_format(mountpt, 1, 0, 0);
-       printf("yaffs_format(...,1, 0, 0) of mounted returned %d\n", ret);
+       printf("yaffs_format(...,1, 0, 0) of mounted returned %d."
+               " Should return 0.\n\n\n", ret);
 
        ret = yaffs_mount(mountpt);
-       printf("mount should return 0 returned %d\n", ret);
+       printf("mount should return 0 returned %d\n\n\n", ret);
 
        ret = yaffs_format(mountpt, 1, 0, 1);
-       printf("yaffs_format(...,1, 0, 1) of mounted returned %d\n", ret);
+       printf("yaffs_format(...,1, 0, 1) of mounted returned %d."
+               " Should return 0.\n\n\n", ret);
 
        ret = yaffs_mount(mountpt);
        printf("mount should return -1 returned %d\n", ret);
@@ -3380,7 +3383,9 @@ int main(int argc, char *argv[])
         //yy_test("/nand");
         //dir_rename_test("/nand");
 
-       dir_fd_test("/nand");
+       //dir_fd_test("/nand");
+
+       format_test("/nand");
 
         return 0;
 
index 2cb8db9..331590b 100644 (file)
@@ -2888,6 +2888,8 @@ void yaffs_add_device(struct yaffs_dev *dev)
                INIT_LIST_HEAD(&dev->dev_list);
 
        list_add(&dev->dev_list, &yaffsfs_deviceList);
+
+
 }
 
 void yaffs_remove_device(struct yaffs_dev *dev)
index ed5a005..3672e8d 100644 (file)
@@ -4602,9 +4602,7 @@ int yaffs_guts_ll_init(struct yaffs_dev *dev)
 {
 
 
-       yaffs_trace(YAFFS_TRACE_TRACING, "yaffs: yaffs_guts_initialise()");
-
-       /* Check stuff that must be set */
+       yaffs_trace(YAFFS_TRACE_TRACING, "yaffs: yaffs_ll_init()");
 
        if (!dev) {
                yaffs_trace(YAFFS_TRACE_ALWAYS,
@@ -4613,10 +4611,8 @@ int yaffs_guts_ll_init(struct yaffs_dev *dev)
                return YAFFS_FAIL;
        }
 
-       if (dev->is_mounted) {
-               yaffs_trace(YAFFS_TRACE_ALWAYS, "device already mounted");
-               return YAFFS_FAIL;
-       }
+       if (dev->ll_init)
+               return YAFFS_OK;
 
        dev->internal_start_block = dev->param.start_block;
        dev->internal_end_block = dev->param.end_block;
@@ -4673,6 +4669,33 @@ int yaffs_guts_ll_init(struct yaffs_dev *dev)
                return YAFFS_FAIL;
        }
 
+       if (yaffs_init_nand(dev) != YAFFS_OK) {
+               yaffs_trace(YAFFS_TRACE_ALWAYS, "InitialiseNAND failed");
+               return YAFFS_FAIL;
+       }
+
+       return YAFFS_OK;
+}
+
+
+int yaffs_format_dev(struct yaffs_dev *dev)
+{
+       int i;
+       enum yaffs_block_state state;
+       u32 dummy;
+
+       if(yaffs_guts_ll_init(dev) != YAFFS_OK)
+               return YAFFS_FAIL;
+
+       if(dev->is_mounted)
+               return YAFFS_FAIL;
+
+       for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) {
+               yaffs_query_init_block_state(dev, i, &state, &dummy);
+               if (state != YAFFS_BLOCK_STATE_DEAD)
+                       yaffs_erase_block(dev, i);
+       }
+
        return YAFFS_OK;
 }
 
@@ -4686,9 +4709,8 @@ int yaffs_guts_initialise(struct yaffs_dev *dev)
        if(yaffs_guts_ll_init(dev) != YAFFS_OK)
                return YAFFS_FAIL;
 
-
-       if (yaffs_init_nand(dev) != YAFFS_OK) {
-               yaffs_trace(YAFFS_TRACE_ALWAYS, "InitialiseNAND failed");
+       if (dev->is_mounted) {
+               yaffs_trace(YAFFS_TRACE_ALWAYS, "device already mounted");
                return YAFFS_FAIL;
        }
 
@@ -5015,40 +5037,6 @@ int yaffs_get_n_free_chunks(struct yaffs_dev *dev)
 }
 
 
-int yaffs_format_dev(struct yaffs_dev *dev)
-{
-       int i;
-       enum yaffs_block_state state;
-       u32 dummy;
-
-       if(dev->is_mounted)
-               return YAFFS_FAIL;
-
-       /*
-       * The runtime variables might not have been set up,
-       * so set up what we need.
-       */
-       dev->internal_start_block = dev->param.start_block;
-       dev->internal_end_block = dev->param.end_block;
-       dev->block_offset = 0;
-       dev->chunk_offset = 0;
-
-       if (dev->param.start_block == 0) {
-               dev->internal_start_block = dev->param.start_block + 1;
-               dev->internal_end_block = dev->param.end_block + 1;
-               dev->block_offset = 1;
-               dev->chunk_offset = dev->param.chunks_per_block;
-       }
-
-       for (i = dev->internal_start_block; i <= dev->internal_end_block; i++) {
-               yaffs_query_init_block_state(dev, i, &state, &dummy);
-               if (state != YAFFS_BLOCK_STATE_DEAD)
-                       yaffs_erase_block(dev, i);
-       }
-
-       return YAFFS_OK;
-}
-
 
 /*
  * Marshalling functions to get loff_t file sizes into and out of
index 2225fb2..fef4fc7 100644 (file)
@@ -637,6 +637,7 @@ struct yaffs_dev {
 
        struct list_head dev_list;
 
+       int ll_init;
        /* Runtime parameters. Set up by YAFFS. */
        int data_bytes_per_chunk;