]> git.sur5r.net Git - u-boot/blobdiff - fs/jffs2/jffs2_1pass.c
arm: support Thumb-1 with CONFIG_SYS_THUMB_BUILD
[u-boot] / fs / jffs2 / jffs2_1pass.c
index f488537c9f1d1f858b9db868913196ae13db2090..64f55425df53e6ac9e1e6f7075bb860e49065716 100644 (file)
@@ -545,49 +545,19 @@ static struct b_node *
 insert_node(struct b_list *list, u32 offset)
 {
        struct b_node *new;
-#ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
-       struct b_node *b, *prev;
-#endif
 
        if (!(new = add_node(list))) {
                putstr("add_node failed!\r\n");
                return NULL;
        }
        new->offset = offset;
+       new->next = NULL;
 
-#ifdef CONFIG_SYS_JFFS2_SORT_FRAGMENTS
-       if (list->listTail != NULL && list->listCompare(new, list->listTail))
-               prev = list->listTail;
-       else if (list->listLast != NULL && list->listCompare(new, list->listLast))
-               prev = list->listLast;
+       if (list->listTail != NULL)
+               list->listTail->next = new;
        else
-               prev = NULL;
-
-       for (b = (prev ? prev->next : list->listHead);
-            b != NULL && list->listCompare(new, b);
-            prev = b, b = b->next) {
-               list->listLoops++;
-       }
-       if (b != NULL)
-               list->listLast = prev;
-
-       if (b != NULL) {
-               new->next = b;
-               if (prev != NULL)
-                       prev->next = new;
-               else
-                       list->listHead = new;
-       } else
-#endif
-       {
-               new->next = (struct b_node *) NULL;
-               if (list->listTail != NULL) {
-                       list->listTail->next = new;
-                       list->listTail = new;
-               } else {
-                       list->listTail = list->listHead = new;
-               }
-       }
+               list->listHead = new;
+       list->listTail = new;
 
        return new;
 }
@@ -1480,7 +1450,7 @@ dump_dirents(struct b_lists *pL)
 }
 #endif
 
-#define DEFAULT_EMPTY_SCAN_SIZE        4096
+#define DEFAULT_EMPTY_SCAN_SIZE        256
 
 static inline uint32_t EMPTY_SCAN_SIZE(uint32_t sector_size)
 {
@@ -1528,6 +1498,8 @@ jffs2_1pass_build_lists(struct part_info * part)
                uint32_t sumlen;
                int ret;
 #endif
+               /* Indicates a sector with a CLEANMARKER was found */
+               int clean_sector = 0;
 
                /* Set buf_size to maximum length */
                buf_size = DEFAULT_EMPTY_SCAN_SIZE;
@@ -1652,6 +1624,14 @@ jffs2_1pass_build_lists(struct part_info * part)
                                        ofs += 4;
                                }
                                /* Ran off end. */
+                               /*
+                                * If this sector had a clean marker at the
+                                * beginning, and immediately following this
+                                * have been a bunch of FF bytes, treat the
+                                * entire sector as empty.
+                                */
+                               if (clean_sector)
+                                       break;
 
                                /* See how much more there is to read in this
                                 * eraseblock...
@@ -1673,6 +1653,11 @@ jffs2_1pass_build_lists(struct part_info * part)
                                buf_ofs = ofs;
                                goto more_empty;
                        }
+                       /*
+                        * Found something not erased in the sector, so reset
+                        * the 'clean_sector' flag.
+                        */
+                       clean_sector = 0;
                        if (node->magic != JFFS2_MAGIC_BITMASK ||
                                        !hdr_crc(node)) {
                                ofs += 4;
@@ -1754,6 +1739,16 @@ jffs2_1pass_build_lists(struct part_info * part)
                                                "%d != %zu\n",
                                                node->totlen,
                                                sizeof(struct jffs2_unknown_node));
+                               if ((node->totlen ==
+                                    sizeof(struct jffs2_unknown_node)) &&
+                                   (ofs == sector_ofs)) {
+                                       /*
+                                        * Found a CLEANMARKER at the beginning
+                                        * of the sector. It's in the correct
+                                        * place with correct size and CRC.
+                                        */
+                                       clean_sector = 1;
+                               }
                                break;
                        case JFFS2_NODETYPE_PADDING:
                                if (node->totlen < sizeof(struct jffs2_unknown_node))
@@ -1775,6 +1770,13 @@ jffs2_1pass_build_lists(struct part_info * part)
        }
 
        free(buf);
+#if defined(CONFIG_SYS_JFFS2_SORT_FRAGMENTS)
+       /*
+        * Sort the lists.
+        */
+       sort_list(&pL->frag);
+       sort_list(&pL->dir);
+#endif
        putstr("\b\b done.\r\n");               /* close off the dots */
 
        /* We don't care if malloc failed - then each read operation will