hwmon: add TI ads7871 a/d converter driver
[safe/jmp/linux-2.6] / fs / jffs2 / debug.c
index 0947284..ec35384 100644 (file)
@@ -1,21 +1,21 @@
 /*
  * JFFS2 -- Journalling Flash File System, Version 2.
  *
- * Copyright (C) 2001-2003 Red Hat, Inc.
+ * Copyright © 2001-2007 Red Hat, Inc.
  *
  * Created by David Woodhouse <dwmw2@infradead.org>
  *
  * For licensing information, see the file 'LICENCE' in this directory.
  *
- * $Id: debug.c,v 1.11 2005/09/21 13:28:35 dedekind Exp $
- *
  */
+
 #include <linux/kernel.h>
 #include <linux/types.h>
 #include <linux/pagemap.h>
 #include <linux/crc32.h>
 #include <linux/jffs2.h>
 #include <linux/mtd/mtd.h>
+#include <linux/slab.h>
 #include "nodelist.h"
 #include "debug.h"
 
@@ -63,11 +63,11 @@ __jffs2_dbg_acct_sanity_check(struct jffs2_sb_info *c,
 void
 __jffs2_dbg_fragtree_paranoia_check(struct jffs2_inode_info *f)
 {
-       down(&f->sem);
+       mutex_lock(&f->sem);
        __jffs2_dbg_fragtree_paranoia_check_nolock(f);
-       up(&f->sem);
+       mutex_unlock(&f->sem);
 }
-       
+
 void
 __jffs2_dbg_fragtree_paranoia_check_nolock(struct jffs2_inode_info *f)
 {
@@ -154,6 +154,139 @@ __jffs2_dbg_prewrite_paranoia_check(struct jffs2_sb_info *c,
        kfree(buf);
 }
 
+void __jffs2_dbg_superblock_counts(struct jffs2_sb_info *c)
+{
+       struct jffs2_eraseblock *jeb;
+       uint32_t free = 0, dirty = 0, used = 0, wasted = 0,
+               erasing = 0, bad = 0, unchecked = 0;
+       int nr_counted = 0;
+       int dump = 0;
+
+       if (c->gcblock) {
+               nr_counted++;
+               free += c->gcblock->free_size;
+               dirty += c->gcblock->dirty_size;
+               used += c->gcblock->used_size;
+               wasted += c->gcblock->wasted_size;
+               unchecked += c->gcblock->unchecked_size;
+       }
+       if (c->nextblock) {
+               nr_counted++;
+               free += c->nextblock->free_size;
+               dirty += c->nextblock->dirty_size;
+               used += c->nextblock->used_size;
+               wasted += c->nextblock->wasted_size;
+               unchecked += c->nextblock->unchecked_size;
+       }
+       list_for_each_entry(jeb, &c->clean_list, list) {
+               nr_counted++;
+               free += jeb->free_size;
+               dirty += jeb->dirty_size;
+               used += jeb->used_size;
+               wasted += jeb->wasted_size;
+               unchecked += jeb->unchecked_size;
+       }
+       list_for_each_entry(jeb, &c->very_dirty_list, list) {
+               nr_counted++;
+               free += jeb->free_size;
+               dirty += jeb->dirty_size;
+               used += jeb->used_size;
+               wasted += jeb->wasted_size;
+               unchecked += jeb->unchecked_size;
+       }
+       list_for_each_entry(jeb, &c->dirty_list, list) {
+               nr_counted++;
+               free += jeb->free_size;
+               dirty += jeb->dirty_size;
+               used += jeb->used_size;
+               wasted += jeb->wasted_size;
+               unchecked += jeb->unchecked_size;
+       }
+       list_for_each_entry(jeb, &c->erasable_list, list) {
+               nr_counted++;
+               free += jeb->free_size;
+               dirty += jeb->dirty_size;
+               used += jeb->used_size;
+               wasted += jeb->wasted_size;
+               unchecked += jeb->unchecked_size;
+       }
+       list_for_each_entry(jeb, &c->erasable_pending_wbuf_list, list) {
+               nr_counted++;
+               free += jeb->free_size;
+               dirty += jeb->dirty_size;
+               used += jeb->used_size;
+               wasted += jeb->wasted_size;
+               unchecked += jeb->unchecked_size;
+       }
+       list_for_each_entry(jeb, &c->erase_pending_list, list) {
+               nr_counted++;
+               free += jeb->free_size;
+               dirty += jeb->dirty_size;
+               used += jeb->used_size;
+               wasted += jeb->wasted_size;
+               unchecked += jeb->unchecked_size;
+       }
+       list_for_each_entry(jeb, &c->free_list, list) {
+               nr_counted++;
+               free += jeb->free_size;
+               dirty += jeb->dirty_size;
+               used += jeb->used_size;
+               wasted += jeb->wasted_size;
+               unchecked += jeb->unchecked_size;
+       }
+       list_for_each_entry(jeb, &c->bad_used_list, list) {
+               nr_counted++;
+               free += jeb->free_size;
+               dirty += jeb->dirty_size;
+               used += jeb->used_size;
+               wasted += jeb->wasted_size;
+               unchecked += jeb->unchecked_size;
+       }
+
+       list_for_each_entry(jeb, &c->erasing_list, list) {
+               nr_counted++;
+               erasing += c->sector_size;
+       }
+       list_for_each_entry(jeb, &c->erase_checking_list, list) {
+               nr_counted++;
+               erasing += c->sector_size;
+       }
+       list_for_each_entry(jeb, &c->erase_complete_list, list) {
+               nr_counted++;
+               erasing += c->sector_size;
+       }
+       list_for_each_entry(jeb, &c->bad_list, list) {
+               nr_counted++;
+               bad += c->sector_size;
+       }
+
+#define check(sz) \
+       if (sz != c->sz##_size) {                       \
+               printk(KERN_WARNING #sz "_size mismatch counted 0x%x, c->" #sz "_size 0x%x\n", \
+                      sz, c->sz##_size);               \
+               dump = 1;                               \
+       }
+       check(free);
+       check(dirty);
+       check(used);
+       check(wasted);
+       check(unchecked);
+       check(bad);
+       check(erasing);
+#undef check
+
+       if (nr_counted != c->nr_blocks) {
+               printk(KERN_WARNING "%s counted only 0x%x blocks of 0x%x. Where are the others?\n",
+                      __func__, nr_counted, c->nr_blocks);
+               dump = 1;
+       }
+
+       if (dump) {
+               __jffs2_dbg_dump_block_lists_nolock(c);
+               BUG();
+       }
+}
+
 /*
  * Check the space accounting and node_ref list correctness for the JFFS2 erasable block 'jeb'.
  */
@@ -165,7 +298,7 @@ __jffs2_dbg_acct_paranoia_check(struct jffs2_sb_info *c,
        __jffs2_dbg_acct_paranoia_check_nolock(c, jeb);
        spin_unlock(&c->erase_completion_lock);
 }
-       
+
 void
 __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
                                       struct jffs2_eraseblock *jeb)
@@ -178,8 +311,8 @@ __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
        while (ref2) {
                uint32_t totlen = ref_totlen(c, jeb, ref2);
 
-               if (ref2->flash_offset < jeb->offset ||
-                               ref2->flash_offset > jeb->offset + c->sector_size) {
+               if (ref_offset(ref2) < jeb->offset ||
+                               ref_offset(ref2) > jeb->offset + c->sector_size) {
                        JFFS2_ERROR("node_ref %#08x shouldn't be in block at %#08x.\n",
                                ref_offset(ref2), jeb->offset);
                        goto error;
@@ -192,13 +325,13 @@ __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
                else
                        my_dirty_size += totlen;
 
-               if ((!ref2->next_phys) != (ref2 == jeb->last_node)) {
-                       JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next_phys at %#08x (mem %p), last_node is at %#08x (mem %p).\n",
-                               ref_offset(ref2), ref2, ref_offset(ref2->next_phys), ref2->next_phys,
-                               ref_offset(jeb->last_node), jeb->last_node);
+               if ((!ref_next(ref2)) != (ref2 == jeb->last_node)) {
+                       JFFS2_ERROR("node_ref for node at %#08x (mem %p) has next at %#08x (mem %p), last_node is at %#08x (mem %p).\n",
+                                   ref_offset(ref2), ref2, ref_offset(ref_next(ref2)), ref_next(ref2),
+                                   ref_offset(jeb->last_node), jeb->last_node);
                        goto error;
                }
-               ref2 = ref2->next_phys;
+               ref2 = ref_next(ref2);
        }
 
        if (my_used_size != jeb->used_size) {
@@ -230,6 +363,9 @@ __jffs2_dbg_acct_paranoia_check_nolock(struct jffs2_sb_info *c,
        }
 #endif
 
+       if (!(c->flags & (JFFS2_SB_FLAG_BUILDING|JFFS2_SB_FLAG_SCANNING)))
+               __jffs2_dbg_superblock_counts(c);
+
        return;
 
 error:
@@ -237,7 +373,7 @@ error:
        __jffs2_dbg_dump_jeb_nolock(jeb);
        __jffs2_dbg_dump_block_lists_nolock(c);
        BUG();
-       
+
 }
 #endif /* JFFS2_DBG_PARANOIA_CHECKS */
 
@@ -268,9 +404,12 @@ __jffs2_dbg_dump_node_refs_nolock(struct jffs2_sb_info *c,
        }
 
        printk(JFFS2_DBG);
-       for (ref = jeb->first_node; ; ref = ref->next_phys) {
-               printk("%#08x(%#x)", ref_offset(ref), ref->__totlen);
-               if (ref->next_phys)
+       for (ref = jeb->first_node; ; ref = ref_next(ref)) {
+               printk("%#08x", ref_offset(ref));
+#ifdef TEST_TOTLEN
+               printk("(%x)", ref->__totlen);
+#endif
+               if (ref_next(ref))
                        printk("->");
                else
                        break;
@@ -321,7 +460,7 @@ void
 __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
 {
        printk(JFFS2_DBG_MSG_PREFIX " dump JFFS2 blocks lists:\n");
-       
+
        printk(JFFS2_DBG "flash_size: %#08x\n",         c->flash_size);
        printk(JFFS2_DBG "used_size: %#08x\n",          c->used_size);
        printk(JFFS2_DBG "dirty_size: %#08x\n",         c->dirty_size);
@@ -448,6 +587,21 @@ __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
                        }
                }
        }
+       if (list_empty(&c->erase_checking_list)) {
+               printk(JFFS2_DBG "erase_checking_list: empty\n");
+       } else {
+               struct list_head *this;
+
+               list_for_each(this, &c->erase_checking_list) {
+                       struct jffs2_eraseblock *jeb = list_entry(this, struct jffs2_eraseblock, list);
+
+                       if (!(jeb->used_size == 0 && jeb->dirty_size == 0 && jeb->wasted_size == 0)) {
+                               printk(JFFS2_DBG "erase_checking_list: %#08x (used %#08x, dirty %#08x, wasted %#08x, unchecked %#08x, free %#08x)\n",
+                                       jeb->offset, jeb->used_size, jeb->dirty_size, jeb->wasted_size,
+                                       jeb->unchecked_size, jeb->free_size);
+                       }
+               }
+       }
 
        if (list_empty(&c->erase_pending_list)) {
                printk(JFFS2_DBG "erase_pending_list: empty\n");
@@ -533,9 +687,9 @@ __jffs2_dbg_dump_block_lists_nolock(struct jffs2_sb_info *c)
 void
 __jffs2_dbg_dump_fragtree(struct jffs2_inode_info *f)
 {
-       down(&f->sem);
+       mutex_lock(&f->sem);
        jffs2_dbg_dump_fragtree_nolock(f);
-       up(&f->sem);
+       mutex_unlock(&f->sem);
 }
 
 void
@@ -577,15 +731,15 @@ __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs)
 {
        int skip;
        int i;
-       
+
        printk(JFFS2_DBG_MSG_PREFIX " dump from offset %#08x to offset %#08x (%x bytes).\n",
                offs, offs + len, len);
        i = skip = offs % JFFS2_BUFDUMP_BYTES_PER_LINE;
        offs = offs & ~(JFFS2_BUFDUMP_BYTES_PER_LINE - 1);
-       
+
        if (skip != 0)
                printk(JFFS2_DBG "%#08x: ", offs);
-       
+
        while (skip--)
                printk("   ");
 
@@ -598,7 +752,7 @@ __jffs2_dbg_dump_buffer(unsigned char *buf, int len, uint32_t offs)
                }
 
                printk("%02x ", buf[i]);
-               
+
                i += 1;
        }
 
@@ -616,7 +770,7 @@ __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs)
        size_t retlen;
        uint32_t crc;
        int ret;
-       
+
        printk(JFFS2_DBG_MSG_PREFIX " dump node at offset %#08x.\n", ofs);
 
        ret = jffs2_flash_read(c, ofs, len, &retlen, (unsigned char *)&node);
@@ -630,13 +784,13 @@ __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs)
        printk(JFFS2_DBG "nodetype:\t%#04x\n", je16_to_cpu(node.u.nodetype));
        printk(JFFS2_DBG "totlen:\t%#08x\n", je32_to_cpu(node.u.totlen));
        printk(JFFS2_DBG "hdr_crc:\t%#08x\n", je32_to_cpu(node.u.hdr_crc));
-       
+
        crc = crc32(0, &node.u, sizeof(node.u) - 4);
        if (crc != je32_to_cpu(node.u.hdr_crc)) {
                JFFS2_ERROR("wrong common header CRC.\n");
                return;
        }
-       
+
        if (je16_to_cpu(node.u.magic) != JFFS2_MAGIC_BITMASK &&
                je16_to_cpu(node.u.magic) != JFFS2_OLD_MAGIC_BITMASK)
        {
@@ -668,7 +822,7 @@ __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs)
                printk(JFFS2_DBG "data_crc:\t%#08x\n", je32_to_cpu(node.i.data_crc));
                printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.i.node_crc));
 
-               crc = crc32(0, &node.i, sizeof(node.i) - 8); 
+               crc = crc32(0, &node.i, sizeof(node.i) - 8);
                if (crc != je32_to_cpu(node.i.node_crc)) {
                        JFFS2_ERROR("wrong node header CRC.\n");
                        return;
@@ -686,11 +840,11 @@ __jffs2_dbg_dump_node(struct jffs2_sb_info *c, uint32_t ofs)
                printk(JFFS2_DBG "type:\t%#02x\n", node.d.type);
                printk(JFFS2_DBG "node_crc:\t%#08x\n", je32_to_cpu(node.d.node_crc));
                printk(JFFS2_DBG "name_crc:\t%#08x\n", je32_to_cpu(node.d.name_crc));
-               
+
                node.d.name[node.d.nsize] = '\0';
                printk(JFFS2_DBG "name:\t\"%s\"\n", node.d.name);
 
-               crc = crc32(0, &node.d, sizeof(node.d) - 8); 
+               crc = crc32(0, &node.d, sizeof(node.d) - 8);
                if (crc != je32_to_cpu(node.d.node_crc)) {
                        JFFS2_ERROR("wrong node header CRC.\n");
                        return;