yaffs2: Make checkpoint block scanning skip bad blocks.
authorCharles Manning <cdhmanning@gmail.com>
Mon, 21 May 2012 00:34:47 +0000 (12:34 +1200)
committerCharles Manning <cdhmanning@gmail.com>
Mon, 21 May 2012 00:34:47 +0000 (12:34 +1200)
Bad blocks were being used by checkpointing which would screw up
the checkpoint scanning.

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

index 8af524f..e3abe0f 100644 (file)
@@ -3046,34 +3046,36 @@ void readdir_test(const char *mountpt)
        int i;
        int handle;
        char fullname[100];
-       
+
        yaffs_DIR *dirs[100];
-       
+
 
        yaffs_trace_mask = 0;
 
        yaffs_start_up();
 
        yaffs_mount(mountpt);
-       
+
        for(i = 0; i < 100; i++) {
                 dirs[i] = yaffs_opendir(mountpt);
                 printf("%2d %p,", i, dirs[i]);
        }
-       
+
        printf("\n");
-       
+
        for(i = 0; i < 100; i++) {
                 if(dirs[i])
                          yaffs_closedir(dirs[i]);
        }
-       
-       
+
+
        for(i = 0; i < 100; i++) {
                 dirs[i] = yaffs_opendir(mountpt);
                 printf("%2d %p,", i, dirs[i]);
        }
-       
+
+       yaffs_unmount(mountpt);
+
 
 }
 
index 997a618..918c382 100644 (file)
@@ -108,25 +108,32 @@ static void yaffs2_checkpt_find_block(struct yaffs_dev *dev)
                     i++) {
                        int chunk = i * dev->param.chunks_per_block;
                        int realigned_chunk = chunk - dev->chunk_offset;
+                       enum yaffs_block_state state;
+                       u32 seq;
 
                        dev->param.read_chunk_tags_fn(dev, realigned_chunk,
                                                      NULL, &tags);
                        yaffs_trace(YAFFS_TRACE_CHECKPOINT,
-                               "find next checkpt block: search: block %d oid %d seq %d eccr %d",
-                               i, tags.obj_id, tags.seq_number,
+                               "find next checkpt block: search: block %d state %d oid %d seq %d eccr %d",
+                               i, (int) state,
+                               tags.obj_id, tags.seq_number,
                                tags.ecc_result);
 
-                       if (tags.seq_number == YAFFS_SEQUENCE_CHECKPOINT_DATA) {
-                               /* Right kind of block */
-                               dev->checkpt_next_block = tags.obj_id;
-                               dev->checkpt_cur_block = i;
-                               dev->checkpt_block_list[dev->
-                                                       blocks_in_checkpt] = i;
-                               dev->blocks_in_checkpt++;
-                               yaffs_trace(YAFFS_TRACE_CHECKPOINT,
-                                       "found checkpt block %d", i);
-                               return;
-                       }
+                       if (tags.seq_number != YAFFS_SEQUENCE_CHECKPOINT_DATA)
+                               continue;
+
+                       dev->param.query_block_fn(dev, i, &state, &seq);
+                       if (state == YAFFS_BLOCK_STATE_DEAD)
+                               continue;
+
+                       /* Right kind of block */
+                       dev->checkpt_next_block = tags.obj_id;
+                       dev->checkpt_cur_block = i;
+                       dev->checkpt_block_list[dev->blocks_in_checkpt] = i;
+                       dev->blocks_in_checkpt++;
+                       yaffs_trace(YAFFS_TRACE_CHECKPOINT,
+                               "found checkpt block %d", i);
+                       return;
                }
 
        yaffs_trace(YAFFS_TRACE_CHECKPOINT, "found no more checkpt blocks");