#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);
#endif
+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;
+#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 *
jffs_build_begin(struct jffs_control *c, int unit)
fmc->min_free_size = fmc->sector_size << 2;
fmc->mtd = mtd;
fmc->c = c;
- fmc->head = 0;
- fmc->tail = 0;
- fmc->head_extra = 0;
- fmc->tail_extra = 0;
+ fmc->head = NULL;
+ fmc->tail = NULL;
+ fmc->head_extra = NULL;
+ fmc->tail_extra = NULL;
init_MUTEX(&fmc->biglock);
return fmc;
}
fmc->head->prev = fmc->tail_extra;
fmc->head = fmc->head_extra;
}
- fmc->head_extra = 0; /* These two instructions should be omitted. */
- fmc->tail_extra = 0;
+ fmc->head_extra = NULL; /* These two instructions should be omitted. */
+ fmc->tail_extra = NULL;
D3(jffs_print_fmcontrol(fmc));
}
jffs_cleanup_fmcontrol(struct jffs_fmcontrol *fmc)
{
if (fmc) {
- struct jffs_fm *cur;
struct jffs_fm *next = fmc->head;
-
- while ((cur = next)) {
+ while (next) {
+ struct jffs_fm *cur = next;
next = next->next;
jffs_free_fm(cur);
}
D2(printk("jffs_fmalloc(): fmc = 0x%p, size = %d, "
"node = 0x%p\n", fmc, size, node));
- *result = 0;
+ *result = NULL;
if (!(fm = jffs_alloc_fm())) {
D(printk("jffs_fmalloc(): kmalloc() failed! (fm)\n"));
}
DJM(no_jffs_node_ref++);
fm->nodes->node = node;
- fm->nodes->next = 0;
+ fm->nodes->next = NULL;
if (fmc->tail) {
fm->offset = fmc->tail->offset + fmc->tail->size;
if (fm->offset == fmc->flash_size) {
else {
fm->offset = fmc->tail->offset + fmc->tail->size;
fm->size = free_chunk_size1;
- fm->nodes = 0;
+ fm->nodes = NULL;
fmc->free_size -= fm->size;
fmc->dirty_size += fm->size; /* Changed by simonk. This seemingly fixes a
bug that caused infinite garbage collection.
*/
}
- fm->next = 0;
+ fm->next = NULL;
if (!fmc->head) {
- fm->prev = 0;
+ fm->prev = NULL;
fmc->head = fm;
fmc->tail = fm;
}
ASSERT(if (!fmc || !fm || !fm->nodes) {
printk(KERN_ERR "jffs_fmfree(): fmc: 0x%p, fm: 0x%p, "
"fm->nodes: 0x%p\n",
- fmc, fm, (fm ? fm->nodes : 0));
+ fmc, fm, (fm ? fm->nodes : NULL));
return -1;
});
/* Find the reference to the node that is going to be removed
and remove it. */
- for (ref = fm->nodes, prev = 0; ref; ref = ref->next) {
+ for (ref = fm->nodes, prev = NULL; ref; ref = ref->next) {
if (ref->node == node) {
if (prev) {
prev->next = ref->next;
if (!(fm = jffs_alloc_fm())) {
D(printk("jffs_fmalloced(0x%p, %u, %u, 0x%p): failed!\n",
fmc, offset, size, node));
- return 0;
+ return NULL;
}
fm->offset = offset;
fm->size = size;
- fm->prev = 0;
- fm->next = 0;
- fm->nodes = 0;
+ fm->prev = NULL;
+ fm->next = NULL;
+ fm->nodes = NULL;
if (node) {
/* `node' exists and it should be associated with the
jffs_fm structure `fm'. */
GFP_KERNEL))) {
D(printk("jffs_fmalloced(): !fm->nodes\n"));
jffs_free_fm(fm);
- return 0;
+ return NULL;
}
DJM(no_jffs_node_ref++);
fm->nodes->node = node;
- fm->nodes->next = 0;
+ fm->nodes->next = NULL;
fmc->used_size += size;
fmc->free_size -= size;
}
if (fm->nodes) {
kfree(fm->nodes);
DJM(no_jffs_node_ref--);
- fm->nodes = 0;
+ fm->nodes = NULL;
}
fmc->used_size -= fm->size;
if (fm == fmc->tail) {
__u32 pos = 0;
if (size == 0) {
- return 0;
+ return NULL;
}
ASSERT(if (!fmc) {
printk(KERN_ERR "jffs_cut_node(): fmc == NULL\n");
- return 0;
+ return NULL;
});
fm = fmc->head;
break;
}
else {
- fm = 0;
+ fm = NULL;
break;
}
}
erased_size -= fm->size;
del = fm;
fm = fm->next;
- fm->prev = 0;
+ fm->prev = NULL;
fmc->head = fm;
jffs_free_fm(del);
}
{
struct jffs_fm *fm;
struct jffs_node_ref *nref;
- struct jffs_node *node = 0;
+ struct jffs_node *node = NULL;
ASSERT(if (!fmc) {
printk(KERN_ERR "jffs_get_oldest_node(): fmc == NULL\n");
- return 0;
+ return NULL;
});
for (fm = fmc->head; fm && !fm->nodes; fm = fm->next);
if (!fm) {
- return 0;
+ return NULL;
}
/* The oldest node is the last one in the reference list. This list
/* check if it's possible to erase the wanted range, and if not, return
* the range that IS erasable, or a negative error code.
*/
-long
+static long
jffs_flash_erasable_size(struct mtd_info *mtd, __u32 offset, __u32 size)
{
u_long ssize;
return (ret >= 0 ? ret : 0);
}
-struct jffs_fm *jffs_alloc_fm(void)
+static struct jffs_fm *jffs_alloc_fm(void)
{
struct jffs_fm *fm;
return fm;
}
-void jffs_free_fm(struct jffs_fm *n)
+static void jffs_free_fm(struct jffs_fm *n)
{
kmem_cache_free(fm_cache,n);
DJM(no_jffs_fm--);
{
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"));
-}
-
-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"));
-}