fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / fs / jffs / jffs_fm.c
index 0cab8da..5a95fbd 100644 (file)
  *
  */
 #include <linux/slab.h>
+#include <linux/err.h>
 #include <linux/blkdev.h>
 #include <linux/jffs.h>
 #include "jffs_fm.h"
+#include "intrep.h"
 
 #if defined(JFFS_MARK_OBSOLETE) && JFFS_MARK_OBSOLETE
 static int jffs_mark_obsolete(struct jffs_fmcontrol *fmc, __u32 fm_offset);
@@ -28,8 +30,62 @@ static int jffs_mark_obsolete(struct jffs_fmcontrol *fmc, __u32 fm_offset);
 static struct jffs_fm *jffs_alloc_fm(void);
 static void jffs_free_fm(struct jffs_fm *n);
 
-extern kmem_cache_t     *fm_cache;
-extern kmem_cache_t     *node_cache;
+extern struct kmem_cache     *fm_cache;
+extern struct kmem_cache     *node_cache;
+
+#if CONFIG_JFFS_FS_VERBOSE > 0
+void
+jffs_print_fmcontrol(struct jffs_fmcontrol *fmc)
+{
+       D(printk("struct jffs_fmcontrol: 0x%p\n", fmc));
+       D(printk("{\n"));
+       D(printk("        %u, /* flash_size  */\n", fmc->flash_size));
+       D(printk("        %u, /* used_size  */\n", fmc->used_size));
+       D(printk("        %u, /* dirty_size  */\n", fmc->dirty_size));
+       D(printk("        %u, /* free_size  */\n", fmc->free_size));
+       D(printk("        %u, /* sector_size  */\n", fmc->sector_size));
+       D(printk("        %u, /* min_free_size  */\n", fmc->min_free_size));
+       D(printk("        %u, /* max_chunk_size  */\n", fmc->max_chunk_size));
+       D(printk("        0x%p, /* mtd  */\n", fmc->mtd));
+       D(printk("        0x%p, /* head  */    "
+                "(head->offset = 0x%08x)\n",
+                fmc->head, (fmc->head ? fmc->head->offset : 0)));
+       D(printk("        0x%p, /* tail  */    "
+                "(tail->offset + tail->size = 0x%08x)\n",
+                fmc->tail,
+                (fmc->tail ? fmc->tail->offset + fmc->tail->size : 0)));
+       D(printk("        0x%p, /* head_extra  */\n", fmc->head_extra));
+       D(printk("        0x%p, /* tail_extra  */\n", fmc->tail_extra));
+       D(printk("}\n"));
+}
+#endif  /*  CONFIG_JFFS_FS_VERBOSE > 0  */
+
+#if CONFIG_JFFS_FS_VERBOSE > 2
+static void
+jffs_print_fm(struct jffs_fm *fm)
+{
+       D(printk("struct jffs_fm: 0x%p\n", fm));
+       D(printk("{\n"));
+       D(printk("       0x%08x, /* offset  */\n", fm->offset));
+       D(printk("       %u, /* size  */\n", fm->size));
+       D(printk("       0x%p, /* prev  */\n", fm->prev));
+       D(printk("       0x%p, /* next  */\n", fm->next));
+       D(printk("       0x%p, /* nodes  */\n", fm->nodes));
+       D(printk("}\n"));
+}
+#endif  /*  CONFIG_JFFS_FS_VERBOSE > 2  */
+
+#if 0
+void
+jffs_print_node_ref(struct jffs_node_ref *ref)
+{
+       D(printk("struct jffs_node_ref: 0x%p\n", ref));
+       D(printk("{\n"));
+       D(printk("       0x%p, /* node  */\n", ref->node));
+       D(printk("       0x%p, /* next  */\n", ref->next));
+       D(printk("}\n"));
+}
+#endif  /*  0  */
 
 /* This function creates a new shiny flash memory control structure.  */
 struct jffs_fmcontrol *
@@ -39,8 +95,7 @@ jffs_build_begin(struct jffs_control *c, int unit)
        struct mtd_info *mtd;
        
        D3(printk("jffs_build_begin()\n"));
-       fmc = (struct jffs_fmcontrol *)kmalloc(sizeof(struct jffs_fmcontrol),
-                                              GFP_KERNEL);
+       fmc = kmalloc(sizeof(*fmc), GFP_KERNEL);
        if (!fmc) {
                D(printk("jffs_build_begin(): Allocation of "
                         "struct jffs_fmcontrol failed!\n"));
@@ -50,7 +105,7 @@ jffs_build_begin(struct jffs_control *c, int unit)
 
        mtd = get_mtd_device(NULL, unit);
 
-       if (!mtd) {
+       if (IS_ERR(mtd)) {
                kfree(fmc);
                DJM(no_jffs_fmcontrol--);
                return NULL;
@@ -84,7 +139,7 @@ jffs_build_begin(struct jffs_control *c, int unit)
        fmc->tail = NULL;
        fmc->head_extra = NULL;
        fmc->tail_extra = NULL;
-       init_MUTEX(&fmc->biglock);
+       mutex_init(&fmc->biglock);
        return fmc;
 }
 
@@ -431,8 +486,7 @@ jffs_add_node(struct jffs_node *node)
 
        D3(printk("jffs_add_node(): ino = %u\n", node->ino));
 
-       ref = (struct jffs_node_ref *)kmalloc(sizeof(struct jffs_node_ref),
-                                             GFP_KERNEL);
+       ref = kmalloc(sizeof(*ref), GFP_KERNEL);
        if (!ref)
                return -ENOMEM;
 
@@ -742,54 +796,3 @@ int jffs_get_node_inuse(void)
 {
        return no_jffs_node;
 }
-
-void
-jffs_print_fmcontrol(struct jffs_fmcontrol *fmc)
-{
-       D(printk("struct jffs_fmcontrol: 0x%p\n", fmc));
-       D(printk("{\n"));
-       D(printk("        %u, /* flash_size  */\n", fmc->flash_size));
-       D(printk("        %u, /* used_size  */\n", fmc->used_size));
-       D(printk("        %u, /* dirty_size  */\n", fmc->dirty_size));
-       D(printk("        %u, /* free_size  */\n", fmc->free_size));
-       D(printk("        %u, /* sector_size  */\n", fmc->sector_size));
-       D(printk("        %u, /* min_free_size  */\n", fmc->min_free_size));
-       D(printk("        %u, /* max_chunk_size  */\n", fmc->max_chunk_size));
-       D(printk("        0x%p, /* mtd  */\n", fmc->mtd));
-       D(printk("        0x%p, /* head  */    "
-                "(head->offset = 0x%08x)\n",
-                fmc->head, (fmc->head ? fmc->head->offset : 0)));
-       D(printk("        0x%p, /* tail  */    "
-                "(tail->offset + tail->size = 0x%08x)\n",
-                fmc->tail,
-                (fmc->tail ? fmc->tail->offset + fmc->tail->size : 0)));
-       D(printk("        0x%p, /* head_extra  */\n", fmc->head_extra));
-       D(printk("        0x%p, /* tail_extra  */\n", fmc->tail_extra));
-       D(printk("}\n"));
-}
-
-void
-jffs_print_fm(struct jffs_fm *fm)
-{
-       D(printk("struct jffs_fm: 0x%p\n", fm));
-       D(printk("{\n"));
-       D(printk("       0x%08x, /* offset  */\n", fm->offset));
-       D(printk("       %u, /* size  */\n", fm->size));
-       D(printk("       0x%p, /* prev  */\n", fm->prev));
-       D(printk("       0x%p, /* next  */\n", fm->next));
-       D(printk("       0x%p, /* nodes  */\n", fm->nodes));
-       D(printk("}\n"));
-}
-
-#if 0
-void
-jffs_print_node_ref(struct jffs_node_ref *ref)
-{
-       D(printk("struct jffs_node_ref: 0x%p\n", ref));
-       D(printk("{\n"));
-       D(printk("       0x%p, /* node  */\n", ref->node));
-       D(printk("       0x%p, /* next  */\n", ref->next));
-       D(printk("}\n"));
-}
-#endif  /*  0  */
-