1
0
Fork 0

[JFFS2] Debug code clean up - step 5

Replace the D1(printk()) style debugging with the new debug macros

Signed-off-by: Artem B. Bityutskiy <dedekind@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
wifi-calibration
Artem B. Bityutskiy 2005-07-28 15:46:43 +01:00 committed by Thomas Gleixner
parent f97117d153
commit e0d601373b
2 changed files with 117 additions and 143 deletions

View File

@ -7,7 +7,7 @@
* *
* For licensing information, see the file 'LICENCE' in this directory. * For licensing information, see the file 'LICENCE' in this directory.
* *
* $Id: nodelist.c,v 1.101 2005/07/27 14:46:11 dedekind Exp $ * $Id: nodelist.c,v 1.102 2005/07/28 12:45:10 dedekind Exp $
* *
*/ */
@ -24,35 +24,31 @@
void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list) void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list)
{ {
struct jffs2_full_dirent **prev = list; struct jffs2_full_dirent **prev = list;
D1(printk(KERN_DEBUG "jffs2_add_fd_to_list( %p, %p (->%p))\n", new, list, *list));
JFFS2_DBG_DENTLIST("add dirent \"%s\", ino #%u\n", new->name, new->ino);
while ((*prev) && (*prev)->nhash <= new->nhash) { while ((*prev) && (*prev)->nhash <= new->nhash) {
if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) { if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) {
/* Duplicate. Free one */ /* Duplicate. Free one */
if (new->version < (*prev)->version) { if (new->version < (*prev)->version) {
D1(printk(KERN_DEBUG "Eep! Marking new dirent node obsolete\n")); JFFS2_DBG_DENTLIST("Eep! Marking new dirent node is obsolete, old is \"%s\", ino #%u\n",
D1(printk(KERN_DEBUG "New dirent is \"%s\"->ino #%u. Old is \"%s\"->ino #%u\n", new->name, new->ino, (*prev)->name, (*prev)->ino)); (*prev)->name, (*prev)->ino);
jffs2_mark_node_obsolete(c, new->raw); jffs2_mark_node_obsolete(c, new->raw);
jffs2_free_full_dirent(new); jffs2_free_full_dirent(new);
} else { } else {
D1(printk(KERN_DEBUG "Marking old dirent node (ino #%u) obsolete\n", (*prev)->ino)); JFFS2_DBG_DENTLIST("marking old dirent \"%s\", ino #%u bsolete\n",
(*prev)->name, (*prev)->ino);
new->next = (*prev)->next; new->next = (*prev)->next;
jffs2_mark_node_obsolete(c, ((*prev)->raw)); jffs2_mark_node_obsolete(c, ((*prev)->raw));
jffs2_free_full_dirent(*prev); jffs2_free_full_dirent(*prev);
*prev = new; *prev = new;
} }
goto out; return;
} }
prev = &((*prev)->next); prev = &((*prev)->next);
} }
new->next = *prev; new->next = *prev;
*prev = new; *prev = new;
out:
D2(while(*list) {
printk(KERN_DEBUG "Dirent \"%s\" (hash 0x%08x, ino #%u\n", (*list)->name, (*list)->nhash, (*list)->ino);
list = &(*list)->next;
});
} }
void jffs2_obsolete_node_frag(struct jffs2_sb_info *c, struct jffs2_node_frag *this) void jffs2_obsolete_node_frag(struct jffs2_sb_info *c, struct jffs2_node_frag *this)
@ -61,14 +57,13 @@ void jffs2_obsolete_node_frag(struct jffs2_sb_info *c, struct jffs2_node_frag *t
this->node->frags--; this->node->frags--;
if (!this->node->frags) { if (!this->node->frags) {
/* The node has no valid frags left. It's totally obsoleted */ /* The node has no valid frags left. It's totally obsoleted */
D2(printk(KERN_DEBUG "Marking old node @0x%08x (0x%04x-0x%04x) obsolete\n", JFFS2_DBG_FRAGTREE2("marking old node @0x%08x (0x%04x-0x%04x) obsolete\n",
ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size)); ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size);
jffs2_mark_node_obsolete(c, this->node->raw); jffs2_mark_node_obsolete(c, this->node->raw);
jffs2_free_full_dnode(this->node); jffs2_free_full_dnode(this->node);
} else { } else {
D2(printk(KERN_DEBUG "Marking old node @0x%08x (0x%04x-0x%04x) REF_NORMAL. frags is %d\n", JFFS2_DBG_FRAGTREE2("marking old node @0x%08x (0x%04x-0x%04x) REF_NORMAL. frags is %d\n",
ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size, ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size, this->node->frags);
this->node->frags));
mark_ref_normal(this->node->raw); mark_ref_normal(this->node->raw);
} }
@ -81,20 +76,19 @@ static void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_
struct rb_node *parent = &base->rb; struct rb_node *parent = &base->rb;
struct rb_node **link = &parent; struct rb_node **link = &parent;
D2(printk(KERN_DEBUG "jffs2_fragtree_insert(%p; %d-%d, %p)\n", newfrag, JFFS2_DBG_FRAGTREE2("insert frag (0x%04x-0x%04x)\n", newfrag->ofs, newfrag->ofs + newfrag->size);
newfrag->ofs, newfrag->ofs+newfrag->size, base));
while (*link) { while (*link) {
parent = *link; parent = *link;
base = rb_entry(parent, struct jffs2_node_frag, rb); base = rb_entry(parent, struct jffs2_node_frag, rb);
D2(printk(KERN_DEBUG "fragtree_insert considering frag at 0x%x\n", base->ofs)); JFFS2_DBG_FRAGTREE2("considering frag at 0x%08x\n", base->ofs);
if (newfrag->ofs > base->ofs) if (newfrag->ofs > base->ofs)
link = &base->rb.rb_right; link = &base->rb.rb_right;
else if (newfrag->ofs < base->ofs) else if (newfrag->ofs < base->ofs)
link = &base->rb.rb_left; link = &base->rb.rb_left;
else { else {
printk(KERN_CRIT "Duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base); JFFS2_ERROR("duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base);
BUG(); BUG();
} }
} }
@ -112,11 +106,11 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *l
this = jffs2_lookup_node_frag(list, newfrag->node->ofs); this = jffs2_lookup_node_frag(list, newfrag->node->ofs);
if (this) { if (this) {
D2(printk(KERN_DEBUG "j_a_f_d_t_f: Lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n", JFFS2_DBG_FRAGTREE2("lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n",
this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this)); this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this);
lastend = this->ofs + this->size; lastend = this->ofs + this->size;
} else { } else {
D2(printk(KERN_DEBUG "j_a_f_d_t_f: Lookup gave no frag\n")); JFFS2_DBG_FRAGTREE2("lookup gave no frag\n");
lastend = 0; lastend = 0;
} }
@ -148,10 +142,10 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *l
/* By definition, the 'this' node has no right-hand child, /* By definition, the 'this' node has no right-hand child,
because there are no frags with offset greater than it. because there are no frags with offset greater than it.
So that's where we want to put the hole */ So that's where we want to put the hole */
D2(printk(KERN_DEBUG "Adding hole frag (%p) on right of node at (%p)\n", holefrag, this)); JFFS2_DBG_FRAGTREE2("adding hole frag (%p) on right of node at (%p)\n", holefrag, this);
rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right); rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right);
} else { } else {
D2(printk(KERN_DEBUG "Adding hole frag (%p) at root of tree\n", holefrag)); JFFS2_DBG_FRAGTREE2("adding hole frag (%p) at root of tree\n", holefrag);
rb_link_node(&holefrag->rb, NULL, &list->rb_node); rb_link_node(&holefrag->rb, NULL, &list->rb_node);
} }
rb_insert_color(&holefrag->rb, list); rb_insert_color(&holefrag->rb, list);
@ -161,18 +155,18 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *l
/* By definition, the 'this' node has no right-hand child, /* By definition, the 'this' node has no right-hand child,
because there are no frags with offset greater than it. because there are no frags with offset greater than it.
So that's where we want to put new fragment */ So that's where we want to put new fragment */
D2(printk(KERN_DEBUG "Adding new frag (%p) on right of node at (%p)\n", newfrag, this)); JFFS2_DBG_FRAGTREE2("adding new frag (%p) on right of node at (%p)\n", newfrag, this);
rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right); rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
} else { } else {
D2(printk(KERN_DEBUG "Adding new frag (%p) at root of tree\n", newfrag)); JFFS2_DBG_FRAGTREE2("adding new frag (%p) at root of tree\n", newfrag);
rb_link_node(&newfrag->rb, NULL, &list->rb_node); rb_link_node(&newfrag->rb, NULL, &list->rb_node);
} }
rb_insert_color(&newfrag->rb, list); rb_insert_color(&newfrag->rb, list);
return 0; return 0;
} }
D2(printk(KERN_DEBUG "j_a_f_d_t_f: dealing with frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n", JFFS2_DBG_FRAGTREE2("dealing with frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n",
this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this)); this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this);
/* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes, /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes,
* - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs
@ -193,12 +187,12 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *l
jffs2_free_node_frag(newfrag); jffs2_free_node_frag(newfrag);
return -ENOMEM; return -ENOMEM;
} }
D2(printk(KERN_DEBUG "split old frag 0x%04x-0x%04x -->", this->ofs, this->ofs+this->size);
if (this->node) if (this->node)
printk("phys 0x%08x\n", ref_offset(this->node->raw)); JFFS2_DBG_FRAGTREE2("split old frag 0x%04x-0x%04x, phys 0x%08x\n",
this->ofs, this->ofs+this->size, ref_offset(this->node->raw));
else else
printk("hole\n"); JFFS2_DBG_FRAGTREE2("split old hole frag 0x%04x-0x%04x\n",
) this->ofs, this->ofs+this->size, ref_offset(this->node->raw));
/* New second frag pointing to this's node */ /* New second frag pointing to this's node */
newfrag2->ofs = newfrag->ofs + newfrag->size; newfrag2->ofs = newfrag->ofs + newfrag->size;
@ -233,14 +227,13 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *l
} else { } else {
/* New frag starts at the same point as 'this' used to. Replace /* New frag starts at the same point as 'this' used to. Replace
it in the tree without doing a delete and insertion */ it in the tree without doing a delete and insertion */
D2(printk(KERN_DEBUG "Inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n", JFFS2_DBG_FRAGTREE2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n",
newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size);
this, this->ofs, this->ofs+this->size));
rb_replace_node(&this->rb, &newfrag->rb, list); rb_replace_node(&this->rb, &newfrag->rb, list);
if (newfrag->ofs + newfrag->size >= this->ofs+this->size) { if (newfrag->ofs + newfrag->size >= this->ofs+this->size) {
D2(printk(KERN_DEBUG "Obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size)); JFFS2_DBG_FRAGTREE2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size);
jffs2_obsolete_node_frag(c, this); jffs2_obsolete_node_frag(c, this);
} else { } else {
this->ofs += newfrag->size; this->ofs += newfrag->size;
@ -256,7 +249,8 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *l
*/ */
while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) { while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) {
/* 'this' frag is obsoleted completely. */ /* 'this' frag is obsoleted completely. */
D2(printk(KERN_DEBUG "Obsoleting node frag %p (%x-%x) and removing from tree\n", this, this->ofs, this->ofs+this->size)); JFFS2_DBG_FRAGTREE2("obsoleting node frag %p (%x-%x) and removing from tree\n",
this, this->ofs, this->ofs+this->size);
rb_erase(&this->rb, list); rb_erase(&this->rb, list);
jffs2_obsolete_node_frag(c, this); jffs2_obsolete_node_frag(c, this);
} }
@ -286,8 +280,6 @@ int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_in
int ret; int ret;
struct jffs2_node_frag *newfrag; struct jffs2_node_frag *newfrag;
D1(printk(KERN_DEBUG "jffs2_add_full_dnode_to_inode(ino #%u, f %p, fn %p)\n", f->inocache->ino, f, fn));
if (unlikely(!fn->size)) if (unlikely(!fn->size))
return 0; return 0;
@ -295,8 +287,8 @@ int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_in
if (unlikely(!newfrag)) if (unlikely(!newfrag))
return -ENOMEM; return -ENOMEM;
D2(printk(KERN_DEBUG "adding node %04x-%04x @0x%08x on flash, newfrag *%p\n", JFFS2_DBG_FRAGTREE("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n",
fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag)); fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag);
newfrag->ofs = fn->ofs; newfrag->ofs = fn->ofs;
newfrag->size = fn->size; newfrag->size = fn->size;
@ -350,8 +342,6 @@ struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t
{ {
struct jffs2_inode_cache *ret; struct jffs2_inode_cache *ret;
D2(printk(KERN_DEBUG "jffs2_get_ino_cache(): ino %u\n", ino));
ret = c->inocache_list[ino % INOCACHE_HASHSIZE]; ret = c->inocache_list[ino % INOCACHE_HASHSIZE];
while (ret && ret->ino < ino) { while (ret && ret->ino < ino) {
ret = ret->next; ret = ret->next;
@ -360,7 +350,6 @@ struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t
if (ret && ret->ino != ino) if (ret && ret->ino != ino)
ret = NULL; ret = NULL;
D2(printk(KERN_DEBUG "jffs2_get_ino_cache found %p for ino %u\n", ret, ino));
return ret; return ret;
} }
@ -372,7 +361,7 @@ void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new
if (!new->ino) if (!new->ino)
new->ino = ++c->highest_ino; new->ino = ++c->highest_ino;
D2(printk(KERN_DEBUG "jffs2_add_ino_cache: Add %p (ino #%u)\n", new, new->ino)); JFFS2_DBG_INOCACHE("add %p (ino #%u)\n", new, new->ino);
prev = &c->inocache_list[new->ino % INOCACHE_HASHSIZE]; prev = &c->inocache_list[new->ino % INOCACHE_HASHSIZE];
@ -388,7 +377,8 @@ void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new
void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old) void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
{ {
struct jffs2_inode_cache **prev; struct jffs2_inode_cache **prev;
D1(printk(KERN_DEBUG "jffs2_del_ino_cache: Del %p (ino #%u)\n", old, old->ino));
JFFS2_DBG_INOCACHE("del %p (ino #%u)\n", old, old->ino);
spin_lock(&c->inocache_lock); spin_lock(&c->inocache_lock);
prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE]; prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE];
@ -451,29 +441,29 @@ struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_
struct jffs2_node_frag *prev = NULL; struct jffs2_node_frag *prev = NULL;
struct jffs2_node_frag *frag = NULL; struct jffs2_node_frag *frag = NULL;
D2(printk(KERN_DEBUG "jffs2_lookup_node_frag(%p, %d)\n", fragtree, offset)); JFFS2_DBG_FRAGTREE2("root %p, offset %d\n", fragtree, offset);
next = fragtree->rb_node; next = fragtree->rb_node;
while(next) { while(next) {
frag = rb_entry(next, struct jffs2_node_frag, rb); frag = rb_entry(next, struct jffs2_node_frag, rb);
D2(printk(KERN_DEBUG "Considering frag %d-%d (%p). left %p, right %p\n", JFFS2_DBG_FRAGTREE2("considering frag %#04x-%#04x (%p). left %p, right %p\n",
frag->ofs, frag->ofs+frag->size, frag, frag->rb.rb_left, frag->rb.rb_right)); frag->ofs, frag->ofs+frag->size, frag, frag->rb.rb_left, frag->rb.rb_right);
if (frag->ofs + frag->size <= offset) { if (frag->ofs + frag->size <= offset) {
D2(printk(KERN_DEBUG "Going right from frag %d-%d, before the region we care about\n", JFFS2_DBG_FRAGTREE2("going right from frag %#04x-%#04x, before the region we care about\n",
frag->ofs, frag->ofs+frag->size)); frag->ofs, frag->ofs+frag->size);
/* Remember the closest smaller match on the way down */ /* Remember the closest smaller match on the way down */
if (!prev || frag->ofs > prev->ofs) if (!prev || frag->ofs > prev->ofs)
prev = frag; prev = frag;
next = frag->rb.rb_right; next = frag->rb.rb_right;
} else if (frag->ofs > offset) { } else if (frag->ofs > offset) {
D2(printk(KERN_DEBUG "Going left from frag %d-%d, after the region we care about\n", JFFS2_DBG_FRAGTREE2("going left from frag %#04x-%#04x, after the region we care about\n",
frag->ofs, frag->ofs+frag->size)); frag->ofs, frag->ofs+frag->size);
next = frag->rb.rb_left; next = frag->rb.rb_left;
} else { } else {
D2(printk(KERN_DEBUG "Returning frag %d,%d, matched\n", JFFS2_DBG_FRAGTREE2("returning frag %#04x-%#04x, matched\n",
frag->ofs, frag->ofs+frag->size)); frag->ofs, frag->ofs+frag->size);
return frag; return frag;
} }
} }
@ -482,10 +472,10 @@ struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_
and return the closest smaller one */ and return the closest smaller one */
if (prev) if (prev)
D2(printk(KERN_DEBUG "No match. Returning frag %d,%d, closest previous\n", JFFS2_DBG_FRAGTREE2("no match. Returning frag %#04x-%#04x, closest previous\n",
prev->ofs, prev->ofs+prev->size)); prev->ofs, prev->ofs+prev->size);
else else
D2(printk(KERN_DEBUG "Returning NULL, empty fragtree\n")); JFFS2_DBG_FRAGTREE2("returning NULL, empty fragtree\n");
return prev; return prev;
} }
@ -500,25 +490,25 @@ void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
if (!root->rb_node) if (!root->rb_node)
return; return;
JFFS2_DBG_FRAGTREE("killing\n");
frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb)); frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb));
while(frag) { while(frag) {
if (frag->rb.rb_left) { if (frag->rb.rb_left) {
D2(printk(KERN_DEBUG "Going left from frag (%p) %d-%d\n", JFFS2_DBG_FRAGTREE2("going left from frag (%p) %#04x-%#04x\n",
frag, frag->ofs, frag->ofs+frag->size)); frag, frag->ofs, frag->ofs+frag->size);
frag = frag_left(frag); frag = frag_left(frag);
continue; continue;
} }
if (frag->rb.rb_right) { if (frag->rb.rb_right) {
D2(printk(KERN_DEBUG "Going right from frag (%p) %d-%d\n", JFFS2_DBG_FRAGTREE2("going right from frag (%p) %#04x-%#04x\n",
frag, frag->ofs, frag->ofs+frag->size)); frag, frag->ofs, frag->ofs+frag->size);
frag = frag_right(frag); frag = frag_right(frag);
continue; continue;
} }
D2(printk(KERN_DEBUG "jffs2_kill_fragtree: frag at 0x%x-0x%x: node %p, frags %d--\n", JFFS2_DBG_FRAGTREE2("frag %#04x-%#04x: node %p, frags %d\n",
frag->ofs, frag->ofs+frag->size, frag->node, frag->ofs, frag->ofs+frag->size, frag->node, frag->node?frag->node->frags:0);
frag->node?frag->node->frags:0));
if (frag->node && !(--frag->node->frags)) { if (frag->node && !(--frag->node->frags)) {
/* Not a hole, and it's the final remaining frag /* Not a hole, and it's the final remaining frag

View File

@ -7,7 +7,7 @@
* *
* For licensing information, see the file 'LICENCE' in this directory. * For licensing information, see the file 'LICENCE' in this directory.
* *
* $Id: readinode.c,v 1.131 2005/07/27 14:46:11 dedekind Exp $ * $Id: readinode.c,v 1.132 2005/07/28 14:46:40 dedekind Exp $
* *
*/ */
@ -24,12 +24,12 @@ void jffs2_truncate_fragtree (struct jffs2_sb_info *c, struct rb_root *list, uin
{ {
struct jffs2_node_frag *frag = jffs2_lookup_node_frag(list, size); struct jffs2_node_frag *frag = jffs2_lookup_node_frag(list, size);
D1(printk(KERN_DEBUG "Truncating fraglist to 0x%08x bytes\n", size)); JFFS2_DBG_FRAGTREE("truncating fragtree to 0x%08x bytes\n", size);
/* We know frag->ofs <= size. That's what lookup does for us */ /* We know frag->ofs <= size. That's what lookup does for us */
if (frag && frag->ofs != size) { if (frag && frag->ofs != size) {
if (frag->ofs+frag->size >= size) { if (frag->ofs+frag->size >= size) {
D1(printk(KERN_DEBUG "Truncating frag 0x%08x-0x%08x\n", frag->ofs, frag->ofs+frag->size)); JFFS2_DBG_FRAGTREE2("truncating frag 0x%08x-0x%08x\n", frag->ofs, frag->ofs+frag->size);
frag->size = size - frag->ofs; frag->size = size - frag->ofs;
} }
frag = frag_next(frag); frag = frag_next(frag);
@ -37,7 +37,7 @@ void jffs2_truncate_fragtree (struct jffs2_sb_info *c, struct rb_root *list, uin
while (frag && frag->ofs >= size) { while (frag && frag->ofs >= size) {
struct jffs2_node_frag *next = frag_next(frag); struct jffs2_node_frag *next = frag_next(frag);
D1(printk(KERN_DEBUG "Removing frag 0x%08x-0x%08x\n", frag->ofs, frag->ofs+frag->size)); JFFS2_DBG_FRAGTREE("removing frag 0x%08x-0x%08x\n", frag->ofs, frag->ofs+frag->size);
frag_erase(frag, list); frag_erase(frag, list);
jffs2_obsolete_node_frag(c, frag); jffs2_obsolete_node_frag(c, frag);
frag = next; frag = next;
@ -120,7 +120,7 @@ static struct jffs2_raw_node_ref *jffs2_first_valid_node(struct jffs2_raw_node_r
while (ref && ref->next_in_ino) { while (ref && ref->next_in_ino) {
if (!ref_obsolete(ref)) if (!ref_obsolete(ref))
return ref; return ref;
D1(printk(KERN_DEBUG "node at 0x%08x is obsoleted. Ignoring.\n", ref_offset(ref))); JFFS2_DBG_NODEREF("node at 0x%08x is obsoleted. Ignoring.\n", ref_offset(ref));
ref = ref->next_in_ino; ref = ref->next_in_ino;
} }
return NULL; return NULL;
@ -152,7 +152,7 @@ read_direntry(struct jffs2_sb_info *c,
/* Sanity check */ /* Sanity check */
if (unlikely(PAD((rd->nsize + sizeof(*rd))) != PAD(je32_to_cpu(rd->totlen)))) { if (unlikely(PAD((rd->nsize + sizeof(*rd))) != PAD(je32_to_cpu(rd->totlen)))) {
printk(KERN_ERR "Error! Illegal nsize in node at %#08x: nsize %#02x, totlen %#04x\n", JFFS2_ERROR("illegal nsize in node at %#08x: nsize %#02x, totlen %#04x\n",
ref_offset(ref), rd->nsize, je32_to_cpu(rd->totlen)); ref_offset(ref), rd->nsize, je32_to_cpu(rd->totlen));
return 1; return 1;
} }
@ -192,7 +192,7 @@ read_direntry(struct jffs2_sb_info *c,
return -EIO; return -EIO;
if (unlikely(err)) { if (unlikely(err)) {
printk(KERN_WARNING "Read remainder of name: error %d\n", err); JFFS2_ERROR("read remainder of name: error %d\n", err);
jffs2_free_full_dirent(fd); jffs2_free_full_dirent(fd);
return -EIO; return -EIO;
} }
@ -206,8 +206,6 @@ read_direntry(struct jffs2_sb_info *c,
* Wheee. We now have a complete jffs2_full_dirent structure, with * Wheee. We now have a complete jffs2_full_dirent structure, with
* the name in it and everything. Link it into the list * the name in it and everything. Link it into the list
*/ */
D1(printk(KERN_DEBUG "Adding fd \"%s\", ino #%u\n", fd->name, fd->ino));
jffs2_add_fd_to_list(c, fd, fdp); jffs2_add_fd_to_list(c, fd, fdp);
return 0; return 0;
@ -242,7 +240,7 @@ read_dnode(struct jffs2_sb_info *c,
crc = crc32(0, rd, sizeof(*rd) - 8); crc = crc32(0, rd, sizeof(*rd) - 8);
if (unlikely(crc != je32_to_cpu(rd->node_crc))) { if (unlikely(crc != je32_to_cpu(rd->node_crc))) {
printk(KERN_WARNING "Header CRC failed on node at %#08x: read %#08x, calculated %#08x\n", JFFS2_NOTICE("header CRC failed on node at %#08x: read %#08x, calculated %#08x\n",
ref_offset(ref), je32_to_cpu(rd->node_crc), crc); ref_offset(ref), je32_to_cpu(rd->node_crc), crc);
return 1; return 1;
} }
@ -250,11 +248,8 @@ read_dnode(struct jffs2_sb_info *c,
/* Sanity checks */ /* Sanity checks */
if (unlikely(je32_to_cpu(rd->offset) > je32_to_cpu(rd->isize)) || if (unlikely(je32_to_cpu(rd->offset) > je32_to_cpu(rd->isize)) ||
unlikely(PAD(je32_to_cpu(rd->csize) + sizeof(*rd)) != PAD(je32_to_cpu(rd->totlen)))) { unlikely(PAD(je32_to_cpu(rd->csize) + sizeof(*rd)) != PAD(je32_to_cpu(rd->totlen)))) {
printk(KERN_WARNING "Inode corrupted at %#08x, totlen %d, #ino %d, version %d, " JFFS2_WARNING("inode node header CRC is corrupted at %#08x\n", ref_offset(ref));
"isize %d, csize %d, dsize %d \n", __jffs2_dbg_dump_node(c, ref_offset(ref));
ref_offset(ref), je32_to_cpu(rd->totlen), je32_to_cpu(rd->ino),
je32_to_cpu(rd->version), je32_to_cpu(rd->isize),
je32_to_cpu(rd->csize), je32_to_cpu(rd->dsize));
return 1; return 1;
} }
@ -267,11 +262,11 @@ read_dnode(struct jffs2_sb_info *c,
err = c->mtd->point (c->mtd, ref_offset(ref) + sizeof(*rd), je32_to_cpu(rd->csize), err = c->mtd->point (c->mtd, ref_offset(ref) + sizeof(*rd), je32_to_cpu(rd->csize),
&read, &buf); &read, &buf);
if (unlikely(read < je32_to_cpu(rd->csize)) && likely(!err)) { if (unlikely(read < je32_to_cpu(rd->csize)) && likely(!err)) {
D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", read)); JFFS2_ERROR("MTD point returned len too short: 0x%zx\n", read);
c->mtd->unpoint(c->mtd, buf, ref_offset(ref) + sizeof(*rd), c->mtd->unpoint(c->mtd, buf, ref_offset(ref) + sizeof(*rd),
je32_to_cpu(rd->csize)); je32_to_cpu(rd->csize));
} else if (unlikely(err)){ } else if (unlikely(err)){
D1(printk(KERN_DEBUG "MTD point failed %d\n", err)); JFFS2_ERROR("MTD point failed %d\n", err);
} else } else
pointed = 1; /* succefully pointed to device */ pointed = 1; /* succefully pointed to device */
} }
@ -299,8 +294,8 @@ read_dnode(struct jffs2_sb_info *c,
#endif #endif
if (crc != je32_to_cpu(rd->data_crc)) { if (crc != je32_to_cpu(rd->data_crc)) {
printk(KERN_NOTICE "Data CRC failed on node at %#08x: read %#08x, calculated %#08x\n", JFFS2_NOTICE("data CRC failed on node at %#08x: read %#08x, calculated %#08x\n",
ref_offset(ref), je32_to_cpu(rd->data_crc), crc); ref_offset(ref), je32_to_cpu(rd->data_crc), crc);
return 1; return 1;
} }
@ -326,10 +321,10 @@ read_dnode(struct jffs2_sb_info *c,
if ((je32_to_cpu(rd->dsize) >= PAGE_CACHE_SIZE) || if ((je32_to_cpu(rd->dsize) >= PAGE_CACHE_SIZE) ||
( ((je32_to_cpu(rd->offset) & (PAGE_CACHE_SIZE-1))==0) && ( ((je32_to_cpu(rd->offset) & (PAGE_CACHE_SIZE-1))==0) &&
(je32_to_cpu(rd->dsize) + je32_to_cpu(rd->offset) == je32_to_cpu(rd->isize)))) { (je32_to_cpu(rd->dsize) + je32_to_cpu(rd->offset) == je32_to_cpu(rd->isize)))) {
D1(printk(KERN_DEBUG "Marking node at %#08x REF_PRISTINE\n", ref_offset(ref))); JFFS2_DBG_READINODE("marking node at %#08x REF_PRISTINE\n", ref_offset(ref));
ref->flash_offset = ref_offset(ref) | REF_PRISTINE; ref->flash_offset = ref_offset(ref) | REF_PRISTINE;
} else { } else {
D1(printk(KERN_DEBUG "Marking node at %#08x REF_NORMAL\n", ref_offset(ref))); JFFS2_DBG_READINODE("marking node at %#08x REF_NORMAL\n", ref_offset(ref));
ref->flash_offset = ref_offset(ref) | REF_NORMAL; ref->flash_offset = ref_offset(ref) | REF_NORMAL;
} }
spin_unlock(&c->erase_completion_lock); spin_unlock(&c->erase_completion_lock);
@ -337,13 +332,13 @@ read_dnode(struct jffs2_sb_info *c,
tn = jffs2_alloc_tmp_dnode_info(); tn = jffs2_alloc_tmp_dnode_info();
if (!tn) { if (!tn) {
D1(printk(KERN_DEBUG "alloc tn failed\n")); JFFS2_ERROR("alloc tn failed\n");
return -ENOMEM; return -ENOMEM;
} }
tn->fn = jffs2_alloc_full_dnode(); tn->fn = jffs2_alloc_full_dnode();
if (!tn->fn) { if (!tn->fn) {
D1(printk(KERN_DEBUG "alloc fn failed\n")); JFFS2_ERROR("alloc fn failed\n");
jffs2_free_tmp_dnode_info(tn); jffs2_free_tmp_dnode_info(tn);
return -ENOMEM; return -ENOMEM;
} }
@ -359,9 +354,8 @@ read_dnode(struct jffs2_sb_info *c,
else // normal case... else // normal case...
tn->fn->size = je32_to_cpu(rd->dsize); tn->fn->size = je32_to_cpu(rd->dsize);
D1(printk(KERN_DEBUG "dnode @%08x: ver %u, offset %#04x, dsize %#04x\n", JFFS2_DBG_READINODE("dnode @%08x: ver %u, offset %#04x, dsize %#04x\n",
ref_offset(ref), je32_to_cpu(rd->version), ref_offset(ref), je32_to_cpu(rd->version), je32_to_cpu(rd->offset), je32_to_cpu(rd->dsize));
je32_to_cpu(rd->offset), je32_to_cpu(rd->dsize)));
jffs2_add_tn_to_tree(tn, tnp); jffs2_add_tn_to_tree(tn, tnp);
@ -388,37 +382,33 @@ read_unknown(struct jffs2_sb_info *c,
un->nodetype = cpu_to_je16(JFFS2_NODE_ACCURATE | je16_to_cpu(un->nodetype)); un->nodetype = cpu_to_je16(JFFS2_NODE_ACCURATE | je16_to_cpu(un->nodetype));
if (crc32(0, un, sizeof(struct jffs2_unknown_node) - 4) != je32_to_cpu(un->hdr_crc)) { if (crc32(0, un, sizeof(struct jffs2_unknown_node) - 4) != je32_to_cpu(un->hdr_crc)) {
/* Hmmm. This should have been caught at scan time. */ /* Hmmm. This should have been caught at scan time. */
printk(KERN_WARNING "Warning! Node header CRC failed at %#08x. " JFFS2_NOTICE("node header CRC failed at %#08x. But it must have been OK earlier.\n", ref_offset(ref));
"But it must have been OK earlier.\n", ref_offset(ref)); __jffs2_dbg_dump_node(c, ref_offset(ref));
D1(printk(KERN_DEBUG "Node was: { %#04x, %#04x, %#08x, %#08x }\n",
je16_to_cpu(un->magic), je16_to_cpu(un->nodetype),
je32_to_cpu(un->totlen), je32_to_cpu(un->hdr_crc)));
return 1; return 1;
} else { } else {
switch(je16_to_cpu(un->nodetype) & JFFS2_COMPAT_MASK) { switch(je16_to_cpu(un->nodetype) & JFFS2_COMPAT_MASK) {
case JFFS2_FEATURE_INCOMPAT: case JFFS2_FEATURE_INCOMPAT:
printk(KERN_NOTICE "Unknown INCOMPAT nodetype %#04X at %#08x\n", JFFS2_ERROR("unknown INCOMPAT nodetype %#04X at %#08x\n",
je16_to_cpu(un->nodetype), ref_offset(ref)); je16_to_cpu(un->nodetype), ref_offset(ref));
/* EEP */ /* EEP */
BUG(); BUG();
break; break;
case JFFS2_FEATURE_ROCOMPAT: case JFFS2_FEATURE_ROCOMPAT:
printk(KERN_NOTICE "Unknown ROCOMPAT nodetype %#04X at %#08x\n", JFFS2_ERROR("unknown ROCOMPAT nodetype %#04X at %#08x\n",
je16_to_cpu(un->nodetype), ref_offset(ref)); je16_to_cpu(un->nodetype), ref_offset(ref));
BUG_ON(!(c->flags & JFFS2_SB_FLAG_RO)); BUG_ON(!(c->flags & JFFS2_SB_FLAG_RO));
break; break;
case JFFS2_FEATURE_RWCOMPAT_COPY: case JFFS2_FEATURE_RWCOMPAT_COPY:
printk(KERN_NOTICE "Unknown RWCOMPAT_COPY nodetype %#04X at %#08x\n", JFFS2_NOTICE("unknown RWCOMPAT_COPY nodetype %#04X at %#08x\n",
je16_to_cpu(un->nodetype), ref_offset(ref)); je16_to_cpu(un->nodetype), ref_offset(ref));
break; break;
case JFFS2_FEATURE_RWCOMPAT_DELETE: case JFFS2_FEATURE_RWCOMPAT_DELETE:
printk(KERN_NOTICE "Unknown RWCOMPAT_DELETE nodetype %#04X at %#08x\n", JFFS2_NOTICE("unknown RWCOMPAT_DELETE nodetype %#04X at %#08x\n",
je16_to_cpu(un->nodetype), ref_offset(ref)); je16_to_cpu(un->nodetype), ref_offset(ref));
return 1; return 1;
} }
@ -444,14 +434,14 @@ static int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_inf
*mctime_ver = 0; *mctime_ver = 0;
D1(printk(KERN_DEBUG "jffs2_get_inode_nodes(): ino #%u\n", f->inocache->ino)); JFFS2_DBG_READINODE("ino #%u\n", f->inocache->ino);
spin_lock(&c->erase_completion_lock); spin_lock(&c->erase_completion_lock);
valid_ref = jffs2_first_valid_node(f->inocache->nodes); valid_ref = jffs2_first_valid_node(f->inocache->nodes);
if (!valid_ref && (f->inocache->ino != 1)) if (!valid_ref && (f->inocache->ino != 1))
printk(KERN_WARNING "Eep. No valid nodes for ino #%u\n", f->inocache->ino); JFFS2_WARNING("no valid nodes for ino #%u\n", f->inocache->ino);
while (valid_ref) { while (valid_ref) {
/* We can hold a pointer to a non-obsolete node without the spinlock, /* We can hold a pointer to a non-obsolete node without the spinlock,
@ -471,17 +461,17 @@ static int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_inf
min_t(uint32_t, ref_totlen(c, NULL, ref), sizeof(node)), min_t(uint32_t, ref_totlen(c, NULL, ref), sizeof(node)),
&retlen, (void *)&node); &retlen, (void *)&node);
if (err) { if (err) {
printk(KERN_WARNING "error %d reading node at 0x%08x in get_inode_nodes()\n", err, ref_offset(ref)); JFFS2_ERROR("error %d reading node at 0x%08x in get_inode_nodes()\n", err, ref_offset(ref));
goto free_out; goto free_out;
} }
switch (je16_to_cpu(node.u.nodetype)) { switch (je16_to_cpu(node.u.nodetype)) {
case JFFS2_NODETYPE_DIRENT: case JFFS2_NODETYPE_DIRENT:
D1(printk(KERN_DEBUG "Node at %08x (%d) is a dirent node\n", ref_offset(ref), ref_flags(ref))); JFFS2_DBG_READINODE("node at %08x (%d) is a dirent node\n", ref_offset(ref), ref_flags(ref));
if (retlen < sizeof(node.d)) { if (retlen < sizeof(node.d)) {
printk(KERN_WARNING "Warning! Short read dirent at %#08x\n", ref_offset(ref)); JFFS2_ERROR("short read dirent at %#08x\n", ref_offset(ref));
err = -EIO; err = -EIO;
goto free_out; goto free_out;
} }
@ -499,10 +489,10 @@ static int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_inf
break; break;
case JFFS2_NODETYPE_INODE: case JFFS2_NODETYPE_INODE:
D1(printk(KERN_DEBUG "Node at %08x (%d) is a data node\n", ref_offset(ref), ref_flags(ref))); JFFS2_DBG_READINODE("node at %08x (%d) is a data node\n", ref_offset(ref), ref_flags(ref));
if (retlen < sizeof(node.i)) { if (retlen < sizeof(node.i)) {
printk(KERN_WARNING "Warning! Short read dnode at %#08x\n", ref_offset(ref)); JFFS2_ERROR("short read dnode at %#08x\n", ref_offset(ref));
err = -EIO; err = -EIO;
goto free_out; goto free_out;
} }
@ -517,16 +507,15 @@ static int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_inf
if (je32_to_cpu(node.i.version) > *highest_version) if (je32_to_cpu(node.i.version) > *highest_version)
*highest_version = je32_to_cpu(node.i.version); *highest_version = je32_to_cpu(node.i.version);
D1(printk(KERN_DEBUG "version %d, highest_version now %d\n", JFFS2_DBG_READINODE("version %d, highest_version now %d\n",
je32_to_cpu(node.i.version), *highest_version)); je32_to_cpu(node.i.version), *highest_version);
break; break;
default: default:
/* Check we've managed to read at least the common node header */ /* Check we've managed to read at least the common node header */
if (retlen < sizeof(struct jffs2_unknown_node)) { if (retlen < sizeof(struct jffs2_unknown_node)) {
printk(KERN_WARNING "Warning! Short read unknown node at %#08x\n", JFFS2_ERROR("short read unknown node at %#08x\n", ref_offset(ref));
ref_offset(ref));
return -EIO; return -EIO;
} }
@ -568,13 +557,13 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
size_t retlen; size_t retlen;
int ret; int ret;
D1(printk(KERN_DEBUG "jffs2_do_read_inode_internal(): ino #%u nlink is %d\n", f->inocache->ino, f->inocache->nlink)); JFFS2_DBG_READINODE("ino #%u nlink is %d\n", f->inocache->ino, f->inocache->nlink);
/* Grab all nodes relevant to this ino */ /* Grab all nodes relevant to this ino */
ret = jffs2_get_inode_nodes(c, f, &tn_list, &fd_list, &f->highest_version, &latest_mctime, &mctime_ver); ret = jffs2_get_inode_nodes(c, f, &tn_list, &fd_list, &f->highest_version, &latest_mctime, &mctime_ver);
if (ret) { if (ret) {
printk(KERN_CRIT "jffs2_get_inode_nodes() for ino %u returned %d\n", f->inocache->ino, ret); JFFS2_ERROR("cannot read nodes for ino %u, returned error is %d\n", f->inocache->ino, ret);
if (f->inocache->state == INO_STATE_READING) if (f->inocache->state == INO_STATE_READING)
jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT); jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT);
return ret; return ret;
@ -589,7 +578,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
if (f->metadata) { if (f->metadata) {
if (likely(tn->version >= mdata_ver)) { if (likely(tn->version >= mdata_ver)) {
D1(printk(KERN_DEBUG "Obsoleting old metadata at 0x%08x\n", ref_offset(f->metadata->raw))); JFFS2_DBG_READINODE("obsoleting old metadata at 0x%08x\n", ref_offset(f->metadata->raw));
jffs2_mark_node_obsolete(c, f->metadata->raw); jffs2_mark_node_obsolete(c, f->metadata->raw);
jffs2_free_full_dnode(f->metadata); jffs2_free_full_dnode(f->metadata);
f->metadata = NULL; f->metadata = NULL;
@ -597,7 +586,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
mdata_ver = 0; mdata_ver = 0;
} else { } else {
/* This should never happen. */ /* This should never happen. */
printk(KERN_WARNING "Er. New metadata at 0x%08x with ver %d is actually older than previous ver %d at 0x%08x\n", JFFS2_ERROR("Er. New metadata at 0x%08x with ver %d is actually older than previous ver %d at 0x%08x\n",
ref_offset(fn->raw), tn->version, mdata_ver, ref_offset(f->metadata->raw)); ref_offset(fn->raw), tn->version, mdata_ver, ref_offset(f->metadata->raw));
jffs2_mark_node_obsolete(c, fn->raw); jffs2_mark_node_obsolete(c, fn->raw);
jffs2_free_full_dnode(fn); jffs2_free_full_dnode(fn);
@ -611,7 +600,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
jffs2_add_full_dnode_to_inode(c, f, fn); jffs2_add_full_dnode_to_inode(c, f, fn);
} else { } else {
/* Zero-sized node at end of version list. Just a metadata update */ /* Zero-sized node at end of version list. Just a metadata update */
D1(printk(KERN_DEBUG "metadata @%08x: ver %d\n", ref_offset(fn->raw), tn->version)); JFFS2_DBG_READINODE("metadata @%08x: ver %d\n", ref_offset(fn->raw), tn->version);
f->metadata = fn; f->metadata = fn;
mdata_ver = tn->version; mdata_ver = tn->version;
} }
@ -646,13 +635,13 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
if (!fn) { if (!fn) {
/* No data nodes for this inode. */ /* No data nodes for this inode. */
if (f->inocache->ino != 1) { if (f->inocache->ino != 1) {
printk(KERN_WARNING "jffs2_do_read_inode(): No data nodes found for ino #%u\n", f->inocache->ino); JFFS2_WARNING("no data nodes found for ino #%u\n", f->inocache->ino);
if (!fd_list) { if (!fd_list) {
if (f->inocache->state == INO_STATE_READING) if (f->inocache->state == INO_STATE_READING)
jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT); jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT);
return -EIO; return -EIO;
} }
printk(KERN_WARNING "jffs2_do_read_inode(): But it has children so we fake some modes for it\n"); JFFS2_NOTICE("but it has children so we fake some modes for it\n");
} }
latest_node->mode = cpu_to_jemode(S_IFDIR|S_IRUGO|S_IWUSR|S_IXUGO); latest_node->mode = cpu_to_jemode(S_IFDIR|S_IRUGO|S_IWUSR|S_IXUGO);
latest_node->version = cpu_to_je32(0); latest_node->version = cpu_to_je32(0);
@ -667,8 +656,8 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
ret = jffs2_flash_read(c, ref_offset(fn->raw), sizeof(*latest_node), &retlen, (void *)latest_node); ret = jffs2_flash_read(c, ref_offset(fn->raw), sizeof(*latest_node), &retlen, (void *)latest_node);
if (ret || retlen != sizeof(*latest_node)) { if (ret || retlen != sizeof(*latest_node)) {
printk(KERN_NOTICE "MTD read in jffs2_do_read_inode() failed: Returned %d, %zd of %zd bytes read\n", JFFS2_ERROR("failed to read from flash: error %d, %zd of %zd bytes read\n",
ret, retlen, sizeof(*latest_node)); ret, retlen, sizeof(*latest_node));
/* FIXME: If this fails, there seems to be a memory leak. Find it. */ /* FIXME: If this fails, there seems to be a memory leak. Find it. */
up(&f->sem); up(&f->sem);
jffs2_do_clear_inode(c, f); jffs2_do_clear_inode(c, f);
@ -677,7 +666,8 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
crc = crc32(0, latest_node, sizeof(*latest_node)-8); crc = crc32(0, latest_node, sizeof(*latest_node)-8);
if (crc != je32_to_cpu(latest_node->node_crc)) { if (crc != je32_to_cpu(latest_node->node_crc)) {
printk(KERN_NOTICE "CRC failed for read_inode of inode %u at physical location 0x%x\n", f->inocache->ino, ref_offset(fn->raw)); JFFS2_ERROR("CRC failed for read_inode of inode %u at physical location 0x%x\n",
f->inocache->ino, ref_offset(fn->raw));
up(&f->sem); up(&f->sem);
jffs2_do_clear_inode(c, f); jffs2_do_clear_inode(c, f);
return -EIO; return -EIO;
@ -712,9 +702,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
* operation. */ * operation. */
f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL); f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL);
if (!f->target) { if (!f->target) {
printk(KERN_WARNING "Can't allocate %d bytes of memory " JFFS2_ERROR("can't allocate %d bytes of memory for the symlink target path cache\n", je32_to_cpu(latest_node->csize));
"for the symlink target path cache\n",
je32_to_cpu(latest_node->csize));
up(&f->sem); up(&f->sem);
jffs2_do_clear_inode(c, f); jffs2_do_clear_inode(c, f);
return -ENOMEM; return -ENOMEM;
@ -734,8 +722,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
} }
f->target[je32_to_cpu(latest_node->csize)] = '\0'; f->target[je32_to_cpu(latest_node->csize)] = '\0';
D1(printk(KERN_DEBUG "jffs2_do_read_inode(): symlink's target '%s' cached\n", JFFS2_DBG_READINODE("symlink's target '%s' cached\n", f->target);
f->target));
} }
/* fall through... */ /* fall through... */
@ -745,14 +732,14 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
/* Certain inode types should have only one data node, and it's /* Certain inode types should have only one data node, and it's
kept as the metadata node */ kept as the metadata node */
if (f->metadata) { if (f->metadata) {
printk(KERN_WARNING "Argh. Special inode #%u with mode 0%o had metadata node\n", JFFS2_ERROR("Argh. Special inode #%u with mode 0%o had metadata node\n",
f->inocache->ino, jemode_to_cpu(latest_node->mode)); f->inocache->ino, jemode_to_cpu(latest_node->mode));
up(&f->sem); up(&f->sem);
jffs2_do_clear_inode(c, f); jffs2_do_clear_inode(c, f);
return -EIO; return -EIO;
} }
if (!frag_first(&f->fragtree)) { if (!frag_first(&f->fragtree)) {
printk(KERN_WARNING "Argh. Special inode #%u with mode 0%o has no fragments\n", JFFS2_ERROR("Argh. Special inode #%u with mode 0%o has no fragments\n",
f->inocache->ino, jemode_to_cpu(latest_node->mode)); f->inocache->ino, jemode_to_cpu(latest_node->mode));
up(&f->sem); up(&f->sem);
jffs2_do_clear_inode(c, f); jffs2_do_clear_inode(c, f);
@ -760,7 +747,7 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
} }
/* ASSERT: f->fraglist != NULL */ /* ASSERT: f->fraglist != NULL */
if (frag_next(frag_first(&f->fragtree))) { if (frag_next(frag_first(&f->fragtree))) {
printk(KERN_WARNING "Argh. Special inode #%u with mode 0x%x had more than one node\n", JFFS2_ERROR("Argh. Special inode #%u with mode 0x%x had more than one node\n",
f->inocache->ino, jemode_to_cpu(latest_node->mode)); f->inocache->ino, jemode_to_cpu(latest_node->mode));
/* FIXME: Deal with it - check crc32, check for duplicate node, check times and discard the older one */ /* FIXME: Deal with it - check crc32, check for duplicate node, check times and discard the older one */
up(&f->sem); up(&f->sem);
@ -783,14 +770,12 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
uint32_t ino, struct jffs2_raw_inode *latest_node) uint32_t ino, struct jffs2_raw_inode *latest_node)
{ {
D2(printk(KERN_DEBUG "jffs2_do_read_inode(): getting inocache\n")); JFFS2_DBG_READINODE("read inode #%u\n", ino);
retry_inocache: retry_inocache:
spin_lock(&c->inocache_lock); spin_lock(&c->inocache_lock);
f->inocache = jffs2_get_ino_cache(c, ino); f->inocache = jffs2_get_ino_cache(c, ino);
D2(printk(KERN_DEBUG "jffs2_do_read_inode(): Got inocache at %p\n", f->inocache));
if (f->inocache) { if (f->inocache) {
/* Check its state. We may need to wait before we can use it */ /* Check its state. We may need to wait before we can use it */
switch(f->inocache->state) { switch(f->inocache->state) {
@ -804,8 +789,7 @@ int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
/* If it's in either of these states, we need /* If it's in either of these states, we need
to wait for whoever's got it to finish and to wait for whoever's got it to finish and
put it back. */ put it back. */
D1(printk(KERN_DEBUG "jffs2_get_ino_cache_read waiting for ino #%u in state %d\n", JFFS2_DBG_READINODE("waiting for ino #%u in state %d\n", ino, f->inocache->state);
ino, f->inocache->state));
sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock); sleep_on_spinunlock(&c->inocache_wq, &c->inocache_lock);
goto retry_inocache; goto retry_inocache;
@ -814,7 +798,7 @@ int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
/* Eep. This should never happen. It can /* Eep. This should never happen. It can
happen if Linux calls read_inode() again happen if Linux calls read_inode() again
before clear_inode() has finished though. */ before clear_inode() has finished though. */
printk(KERN_WARNING "Eep. Trying to read_inode #%u when it's already in state %d!\n", ino, f->inocache->state); JFFS2_ERROR("Eep. Trying to read_inode #%u when it's already in state %d!\n", ino, f->inocache->state);
/* Fail. That's probably better than allowing it to succeed */ /* Fail. That's probably better than allowing it to succeed */
f->inocache = NULL; f->inocache = NULL;
break; break;
@ -829,10 +813,10 @@ int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
/* Special case - no root inode on medium */ /* Special case - no root inode on medium */
f->inocache = jffs2_alloc_inode_cache(); f->inocache = jffs2_alloc_inode_cache();
if (!f->inocache) { if (!f->inocache) {
printk(KERN_CRIT "jffs2_do_read_inode(): Cannot allocate inocache for root inode\n"); JFFS2_ERROR("cannot allocate inocache for root inode\n");
return -ENOMEM; return -ENOMEM;
} }
D1(printk(KERN_DEBUG "jffs2_do_read_inode(): Creating inocache for root inode\n")); JFFS2_DBG_READINODE("creating inocache for root inode\n");
memset(f->inocache, 0, sizeof(struct jffs2_inode_cache)); memset(f->inocache, 0, sizeof(struct jffs2_inode_cache));
f->inocache->ino = f->inocache->nlink = 1; f->inocache->ino = f->inocache->nlink = 1;
f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache; f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache;
@ -840,7 +824,7 @@ int jffs2_do_read_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f,
jffs2_add_ino_cache(c, f->inocache); jffs2_add_ino_cache(c, f->inocache);
} }
if (!f->inocache) { if (!f->inocache) {
printk(KERN_WARNING "jffs2_do_read_inode() on nonexistent ino %u\n", ino); JFFS2_ERROR("requestied to read an nonexistent ino %u\n", ino);
return -ENOENT; return -ENOENT;
} }