aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorDavid Woodhouse <dwmw2@infradead.org>2007-05-07 19:19:54 -0400
committerDavid Woodhouse <dwmw2@infradead.org>2007-05-07 19:19:54 -0400
commit1c97964520503c60aa91680d4b525236c2885a36 (patch)
tree098110a567287266a62cdd0c800fa63ac6bdb206 /fs
parentfcf3cafb3e7e7750f4876571492594c3a4854ee5 (diff)
[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: David Woodhouse <dwmw2@infradead.org>
Diffstat (limited to 'fs')
-rw-r--r--fs/jffs2/readinode.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c
index bd31d4956c6d..4884d5edfe65 100644
--- a/fs/jffs2/readinode.c
+++ b/fs/jffs2/readinode.c
@@ -240,20 +240,16 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
240 240
241 /* Find the earliest node which _may_ be relevant to this one */ 241 /* Find the earliest node which _may_ be relevant to this one */
242 this = jffs2_lookup_tn(&rii->tn_root, tn->fn->ofs); 242 this = jffs2_lookup_tn(&rii->tn_root, tn->fn->ofs);
243 if (!this) { 243 if (this) {
244 /* First addition to empty tree. $DEITY how I love the easy cases */ 244 /* If the node is coincident with another at a lower address,
245 rb_link_node(&tn->rb, NULL, &rii->tn_root.rb_node); 245 back up until the other node is found. It may be relevant */
246 rb_insert_color(&tn->rb, &rii->tn_root); 246 while (this->overlapped)
247 dbg_readinode("keep new frag\n"); 247 this = tn_prev(this);
248 return 0;
249 }
250
251 /* If the node is coincident with another at a lower address,
252 back up until the other node is found. It may be relevant */
253 while (tn->overlapped)
254 tn = tn_prev(tn);
255 248
256 dbg_readinode("'this' found %#04x-%#04x (%s)\n", this->fn->ofs, this->fn->ofs + this->fn->size, this->fn ? "data" : "hole"); 249 /* First node should never be marked overlapped */
250 BUG_ON(!this);
251 dbg_readinode("'this' found %#04x-%#04x (%s)\n", this->fn->ofs, this->fn->ofs + this->fn->size, this->fn ? "data" : "hole");
252 }
257 253
258 while (this) { 254 while (this) {
259 if (this->fn->ofs > fn_end) 255 if (this->fn->ofs > fn_end)
@@ -288,7 +284,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
288 return 0; 284 return 0;
289 } 285 }
290 /* ... and is good. Kill 'this' and any subsequent nodes which are also overlapped */ 286 /* ... and is good. Kill 'this' and any subsequent nodes which are also overlapped */
291 while (this && this->fn->ofs + this->fn->size < fn_end) { 287 while (this && this->fn->ofs + this->fn->size <= fn_end) {
292 struct jffs2_tmp_dnode_info *next = tn_next(this); 288 struct jffs2_tmp_dnode_info *next = tn_next(this);
293 if (this->version < tn->version) { 289 if (this->version < tn->version) {
294 tn_erase(this, &rii->tn_root); 290 tn_erase(this, &rii->tn_root);
@@ -300,7 +296,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
300 this = next; 296 this = next;
301 } 297 }
302 dbg_readinode("Done killing overlapped nodes\n"); 298 dbg_readinode("Done killing overlapped nodes\n");
303 break; 299 continue;
304 } 300 }
305 if (this->version > tn->version && 301 if (this->version > tn->version &&
306 this->fn->ofs <= tn->fn->ofs && 302 this->fn->ofs <= tn->fn->ofs &&
@@ -326,7 +322,7 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
326 { 322 {
327 struct rb_node *parent; 323 struct rb_node *parent;
328 struct rb_node **link = &rii->tn_root.rb_node; 324 struct rb_node **link = &rii->tn_root.rb_node;
329 struct jffs2_tmp_dnode_info *insert_point; 325 struct jffs2_tmp_dnode_info *insert_point = NULL;
330 326
331 while (*link) { 327 while (*link) {
332 parent = *link; 328 parent = *link;
@@ -343,7 +339,6 @@ static int jffs2_add_tn_to_tree(struct jffs2_sb_info *c,
343 rb_insert_color(&tn->rb, &rii->tn_root); 339 rb_insert_color(&tn->rb, &rii->tn_root);
344 } 340 }
345 341
346 calc_overlaps:
347 /* If there's anything behind that overlaps us, note it */ 342 /* If there's anything behind that overlaps us, note it */
348 this = tn_prev(tn); 343 this = tn_prev(tn);
349 if (this) { 344 if (this) {