Commit 1c979645 authored by David Woodhouse's avatar David Woodhouse

[JFFS2] Simplify and clean up jffs2_add_tn_to_tree() some more.

Fixing at least a couple more bugs in the process.
Signed-off-by: default avatarDavid Woodhouse <dwmw2@infradead.org>
parent fcf3cafb
...@@ -240,20 +240,16 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c, ...@@ -240,20 +240,16 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
/* Find the earliest node which _may_ be relevant to this one */ /* Find the earliest node which _may_ be relevant to this one */
this = jffs2_lookup_tn(&rii->tn_root, tn->fn->ofs); this = jffs2_lookup_tn(&rii->tn_root, tn->fn->ofs);
if (!this) { if (this) {
/* First addition to empty tree. $DEITY how I love the easy cases */
rb_link_node(&tn->rb, NULL, &rii->tn_root.rb_node);
rb_insert_color(&tn->rb, &rii->tn_root);
dbg_readinode("keep new frag\n");
return 0;
}
/* If the node is coincident with another at a lower address, /* If the node is coincident with another at a lower address,
back up until the other node is found. It may be relevant */ back up until the other node is found. It may be relevant */
while (tn->overlapped) while (this->overlapped)
tn = tn_prev(tn); this = tn_prev(this);
/* First node should never be marked overlapped */
BUG_ON(!this);
dbg_readinode("'this' found %#04x-%#04x (%s)\n", this->fn->ofs, this->fn->ofs + this->fn->size, this->fn ? "data" : "hole"); dbg_readinode("'this' found %#04x-%#04x (%s)\n", this->fn->ofs, this->fn->ofs + this->fn->size, this->fn ? "data" : "hole");
}
while (this) { while (this) {
if (this->fn->ofs > fn_end) if (this->fn->ofs > fn_end)
...@@ -288,7 +284,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c, ...@@ -288,7 +284,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
return 0; return 0;
} }
/* ... and is good. Kill 'this' and any subsequent nodes which are also overlapped */ /* ... and is good. Kill 'this' and any subsequent nodes which are also overlapped */
while (this && this->fn->ofs + this->fn->size < fn_end) { while (this && this->fn->ofs + this->fn->size <= fn_end) {
struct jffs2_tmp_dnode_info *next = tn_next(this); struct jffs2_tmp_dnode_info *next = tn_next(this);
if (this->version < tn->version) { if (this->version < tn->version) {
tn_erase(this, &rii->tn_root); tn_erase(this, &rii->tn_root);
...@@ -300,7 +296,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c, ...@@ -300,7 +296,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
this = next; this = next;
} }
dbg_readinode("Done killing overlapped nodes\n"); dbg_readinode("Done killing overlapped nodes\n");
break; continue;
} }
if (this->version > tn->version && if (this->version > tn->version &&
this->fn->ofs <= tn->fn->ofs && this->fn->ofs <= tn->fn->ofs &&
...@@ -326,7 +322,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c, ...@@ -326,7 +322,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
{ {
struct rb_node *parent; struct rb_node *parent;
struct rb_node **link = &rii->tn_root.rb_node; struct rb_node **link = &rii->tn_root.rb_node;
struct jffs2_tmp_dnode_info *insert_point; struct jffs2_tmp_dnode_info *insert_point = NULL;
while (*link) { while (*link) {
parent = *link; parent = *link;
...@@ -343,7 +339,6 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c, ...@@ -343,7 +339,6 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
rb_insert_color(&tn->rb, &rii->tn_root); rb_insert_color(&tn->rb, &rii->tn_root);
} }
calc_overlaps:
/* If there's anything behind that overlaps us, note it */ /* If there's anything behind that overlaps us, note it */
this = tn_prev(tn); this = tn_prev(tn);
if (this) { if (this) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment