aboutsummaryrefslogtreecommitdiffstats
path: root/fs/jffs2/nodelist.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2005-11-07 06:16:07 -0500
committerThomas Gleixner <tglx@mtd.linutronix.de>2005-11-07 08:18:56 -0500
commit182ec4eee397543101a6db8906ed88727d3f7e53 (patch)
tree0f6dd2c52697123702bdf0c3a7143537f947b060 /fs/jffs2/nodelist.c
parent97894cda5773e59bd13e87b72077751099419a9f (diff)
[JFFS2] Clean up trailing white spaces
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Diffstat (limited to 'fs/jffs2/nodelist.c')
-rw-r--r--fs/jffs2/nodelist.c170
1 files changed, 85 insertions, 85 deletions
diff --git a/fs/jffs2/nodelist.c b/fs/jffs2/nodelist.c
index 80fe8feffb4d..c79eebb8ab32 100644
--- a/fs/jffs2/nodelist.c
+++ b/fs/jffs2/nodelist.c
@@ -7,7 +7,7 @@
7 * 7 *
8 * For licensing information, see the file 'LICENCE' in this directory. 8 * For licensing information, see the file 'LICENCE' in this directory.
9 * 9 *
10 * $Id: nodelist.c,v 1.114 2005/09/21 13:28:35 dedekind Exp $ 10 * $Id: nodelist.c,v 1.115 2005/11/07 11:14:40 gleixner Exp $
11 * 11 *
12 */ 12 */
13 13
@@ -24,7 +24,7 @@
24void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list) 24void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list)
25{ 25{
26 struct jffs2_full_dirent **prev = list; 26 struct jffs2_full_dirent **prev = list;
27 27
28 dbg_dentlist("add dirent \"%s\", ino #%u\n", new->name, new->ino); 28 dbg_dentlist("add dirent \"%s\", ino #%u\n", new->name, new->ino);
29 29
30 while ((*prev) && (*prev)->nhash <= new->nhash) { 30 while ((*prev) && (*prev)->nhash <= new->nhash) {
@@ -75,14 +75,14 @@ void jffs2_truncate_fragtree(struct jffs2_sb_info *c, struct rb_root *list, uint
75 if (size == 0) 75 if (size == 0)
76 return; 76 return;
77 77
78 /* 78 /*
79 * If the last fragment starts at the RAM page boundary, it is 79 * If the last fragment starts at the RAM page boundary, it is
80 * REF_PRISTINE irrespective of its size. 80 * REF_PRISTINE irrespective of its size.
81 */ 81 */
82 frag = frag_last(list); 82 frag = frag_last(list);
83 if (frag->node && (frag->ofs & (PAGE_CACHE_SIZE - 1)) == 0) { 83 if (frag->node && (frag->ofs & (PAGE_CACHE_SIZE - 1)) == 0) {
84 dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n", 84 dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n",
85 frag->ofs, frag->ofs + frag->size); 85 frag->ofs, frag->ofs + frag->size);
86 frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE; 86 frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE;
87 } 87 }
88} 88}
@@ -102,7 +102,7 @@ void jffs2_obsolete_node_frag(struct jffs2_sb_info *c, struct jffs2_node_frag *t
102 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size, this->node->frags); 102 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size, this->node->frags);
103 mark_ref_normal(this->node->raw); 103 mark_ref_normal(this->node->raw);
104 } 104 }
105 105
106 } 106 }
107 jffs2_free_node_frag(this); 107 jffs2_free_node_frag(this);
108} 108}
@@ -117,7 +117,7 @@ static void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_
117 while (*link) { 117 while (*link) {
118 parent = *link; 118 parent = *link;
119 base = rb_entry(parent, struct jffs2_node_frag, rb); 119 base = rb_entry(parent, struct jffs2_node_frag, rb);
120 120
121 if (newfrag->ofs > base->ofs) 121 if (newfrag->ofs > base->ofs)
122 link = &base->rb.rb_right; 122 link = &base->rb.rb_right;
123 else if (newfrag->ofs < base->ofs) 123 else if (newfrag->ofs < base->ofs)
@@ -137,7 +137,7 @@ static void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_
137static inline struct jffs2_node_frag * new_fragment(struct jffs2_full_dnode *fn, uint32_t ofs, uint32_t size) 137static inline struct jffs2_node_frag * new_fragment(struct jffs2_full_dnode *fn, uint32_t ofs, uint32_t size)
138{ 138{
139 struct jffs2_node_frag *newfrag; 139 struct jffs2_node_frag *newfrag;
140 140
141 newfrag = jffs2_alloc_node_frag(); 141 newfrag = jffs2_alloc_node_frag();
142 if (likely(newfrag)) { 142 if (likely(newfrag)) {
143 newfrag->ofs = ofs; 143 newfrag->ofs = ofs;
@@ -169,7 +169,7 @@ static int no_overlapping_node(struct jffs2_sb_info *c, struct rb_root *root,
169 } 169 }
170 170
171 if (this) { 171 if (this) {
172 /* By definition, the 'this' node has no right-hand child, 172 /* By definition, the 'this' node has no right-hand child,
173 because there are no frags with offset greater than it. 173 because there are no frags with offset greater than it.
174 So that's where we want to put the hole */ 174 So that's where we want to put the hole */
175 dbg_fragtree2("add hole frag %#04x-%#04x on the right of the new frag.\n", 175 dbg_fragtree2("add hole frag %#04x-%#04x on the right of the new frag.\n",
@@ -183,13 +183,13 @@ static int no_overlapping_node(struct jffs2_sb_info *c, struct rb_root *root,
183 rb_insert_color(&holefrag->rb, root); 183 rb_insert_color(&holefrag->rb, root);
184 this = holefrag; 184 this = holefrag;
185 } 185 }
186 186
187 if (this) { 187 if (this) {
188 /* By definition, the 'this' node has no right-hand child, 188 /* By definition, the 'this' node has no right-hand child,
189 because there are no frags with offset greater than it. 189 because there are no frags with offset greater than it.
190 So that's where we want to put new fragment */ 190 So that's where we want to put new fragment */
191 dbg_fragtree2("add the new node at the right\n"); 191 dbg_fragtree2("add the new node at the right\n");
192 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right); 192 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
193 } else { 193 } else {
194 dbg_fragtree2("insert the new node at the root of the tree\n"); 194 dbg_fragtree2("insert the new node at the root of the tree\n");
195 rb_link_node(&newfrag->rb, NULL, &root->rb_node); 195 rb_link_node(&newfrag->rb, NULL, &root->rb_node);
@@ -216,7 +216,7 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
216 dbg_fragtree2("lookup gave no frag\n"); 216 dbg_fragtree2("lookup gave no frag\n");
217 lastend = 0; 217 lastend = 0;
218 } 218 }
219 219
220 /* See if we ran off the end of the fragtree */ 220 /* See if we ran off the end of the fragtree */
221 if (lastend <= newfrag->ofs) { 221 if (lastend <= newfrag->ofs) {
222 /* We did */ 222 /* We did */
@@ -243,7 +243,7 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
243 this->ofs, this->ofs + this->size); 243 this->ofs, this->ofs + this->size);
244 244
245 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes, 245 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes,
246 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs 246 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs
247 */ 247 */
248 if (newfrag->ofs > this->ofs) { 248 if (newfrag->ofs > this->ofs) {
249 /* This node isn't completely obsoleted. The start of it remains valid */ 249 /* This node isn't completely obsoleted. The start of it remains valid */
@@ -261,10 +261,10 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
261 if (this->node) 261 if (this->node)
262 dbg_fragtree2("split old frag 0x%04x-0x%04x, phys 0x%08x\n", 262 dbg_fragtree2("split old frag 0x%04x-0x%04x, phys 0x%08x\n",
263 this->ofs, this->ofs+this->size, ref_offset(this->node->raw)); 263 this->ofs, this->ofs+this->size, ref_offset(this->node->raw));
264 else 264 else
265 dbg_fragtree2("split old hole frag 0x%04x-0x%04x\n", 265 dbg_fragtree2("split old hole frag 0x%04x-0x%04x\n",
266 this->ofs, this->ofs+this->size); 266 this->ofs, this->ofs+this->size);
267 267
268 /* New second frag pointing to this's node */ 268 /* New second frag pointing to this's node */
269 newfrag2 = new_fragment(this->node, newfrag->ofs + newfrag->size, 269 newfrag2 = new_fragment(this->node, newfrag->ofs + newfrag->size,
270 this->ofs + this->size - newfrag->ofs - newfrag->size); 270 this->ofs + this->size - newfrag->ofs - newfrag->size);
@@ -284,10 +284,10 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
284 from newfrag to insert newfrag2. */ 284 from newfrag to insert newfrag2. */
285 jffs2_fragtree_insert(newfrag, this); 285 jffs2_fragtree_insert(newfrag, this);
286 rb_insert_color(&newfrag->rb, root); 286 rb_insert_color(&newfrag->rb, root);
287 287
288 jffs2_fragtree_insert(newfrag2, newfrag); 288 jffs2_fragtree_insert(newfrag2, newfrag);
289 rb_insert_color(&newfrag2->rb, root); 289 rb_insert_color(&newfrag2->rb, root);
290 290
291 return 0; 291 return 0;
292 } 292 }
293 /* New node just reduces 'this' frag in size, doesn't split it */ 293 /* New node just reduces 'this' frag in size, doesn't split it */
@@ -297,13 +297,13 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
297 jffs2_fragtree_insert(newfrag, this); 297 jffs2_fragtree_insert(newfrag, this);
298 rb_insert_color(&newfrag->rb, root); 298 rb_insert_color(&newfrag->rb, root);
299 } else { 299 } else {
300 /* New frag starts at the same point as 'this' used to. Replace 300 /* New frag starts at the same point as 'this' used to. Replace
301 it in the tree without doing a delete and insertion */ 301 it in the tree without doing a delete and insertion */
302 dbg_fragtree2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n", 302 dbg_fragtree2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n",
303 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size); 303 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size);
304 304
305 rb_replace_node(&this->rb, &newfrag->rb, root); 305 rb_replace_node(&this->rb, &newfrag->rb, root);
306 306
307 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) { 307 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) {
308 dbg_fragtree2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size); 308 dbg_fragtree2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size);
309 jffs2_obsolete_node_frag(c, this); 309 jffs2_obsolete_node_frag(c, this);
@@ -317,7 +317,7 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
317 } 317 }
318 } 318 }
319 /* OK, now we have newfrag added in the correct place in the tree, but 319 /* OK, now we have newfrag added in the correct place in the tree, but
320 frag_next(newfrag) may be a fragment which is overlapped by it 320 frag_next(newfrag) may be a fragment which is overlapped by it
321 */ 321 */
322 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) { 322 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) {
323 /* 'this' frag is obsoleted completely. */ 323 /* 'this' frag is obsoleted completely. */
@@ -326,7 +326,7 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
326 rb_erase(&this->rb, root); 326 rb_erase(&this->rb, root);
327 jffs2_obsolete_node_frag(c, this); 327 jffs2_obsolete_node_frag(c, this);
328 } 328 }
329 /* Now we're pointing at the first frag which isn't totally obsoleted by 329 /* Now we're pointing at the first frag which isn't totally obsoleted by
330 the new frag */ 330 the new frag */
331 331
332 if (!this || newfrag->ofs + newfrag->size == this->ofs) 332 if (!this || newfrag->ofs + newfrag->size == this->ofs)
@@ -344,7 +344,7 @@ static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *r
344 return 0; 344 return 0;
345} 345}
346 346
347/* 347/*
348 * Given an inode, probably with existing tree of fragments, add the new node 348 * Given an inode, probably with existing tree of fragments, add the new node
349 * to the fragment tree. 349 * to the fragment tree.
350 */ 350 */
@@ -363,7 +363,7 @@ int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_in
363 363
364 dbg_fragtree("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n", 364 dbg_fragtree("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n",
365 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag); 365 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag);
366 366
367 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag); 367 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag);
368 if (unlikely(ret)) 368 if (unlikely(ret))
369 return ret; 369 return ret;
@@ -374,14 +374,14 @@ int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_in
374 struct jffs2_node_frag *prev = frag_prev(newfrag); 374 struct jffs2_node_frag *prev = frag_prev(newfrag);
375 375
376 mark_ref_normal(fn->raw); 376 mark_ref_normal(fn->raw);
377 /* If we don't start at zero there's _always_ a previous */ 377 /* If we don't start at zero there's _always_ a previous */
378 if (prev->node) 378 if (prev->node)
379 mark_ref_normal(prev->node->raw); 379 mark_ref_normal(prev->node->raw);
380 } 380 }
381 381
382 if ((newfrag->ofs+newfrag->size) & (PAGE_CACHE_SIZE-1)) { 382 if ((newfrag->ofs+newfrag->size) & (PAGE_CACHE_SIZE-1)) {
383 struct jffs2_node_frag *next = frag_next(newfrag); 383 struct jffs2_node_frag *next = frag_next(newfrag);
384 384
385 if (next) { 385 if (next) {
386 mark_ref_normal(fn->raw); 386 mark_ref_normal(fn->raw);
387 if (next->node) 387 if (next->node)
@@ -412,7 +412,7 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
412 412
413 if (!jffs2_is_writebuffered(c)) 413 if (!jffs2_is_writebuffered(c))
414 goto adj_acc; 414 goto adj_acc;
415 415
416 /* Calculate how many bytes were already checked */ 416 /* Calculate how many bytes were already checked */
417 ofs = ref_offset(ref) + sizeof(struct jffs2_raw_inode); 417 ofs = ref_offset(ref) + sizeof(struct jffs2_raw_inode);
418 len = ofs % c->wbuf_pagesize; 418 len = ofs % c->wbuf_pagesize;
@@ -424,13 +424,13 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
424 ref_offset(ref), tn->csize, ofs); 424 ref_offset(ref), tn->csize, ofs);
425 goto adj_acc; 425 goto adj_acc;
426 } 426 }
427 427
428 ofs += len; 428 ofs += len;
429 len = tn->csize - len; 429 len = tn->csize - len;
430 430
431 dbg_readinode("check node at %#08x, data length %u, partial CRC %#08x, correct CRC %#08x, data starts at %#08x, start checking from %#08x - %u bytes.\n", 431 dbg_readinode("check node at %#08x, data length %u, partial CRC %#08x, correct CRC %#08x, data starts at %#08x, start checking from %#08x - %u bytes.\n",
432 ref_offset(ref), tn->csize, tn->partial_crc, tn->data_crc, ofs - len, ofs, len); 432 ref_offset(ref), tn->csize, tn->partial_crc, tn->data_crc, ofs - len, ofs, len);
433 433
434#ifndef __ECOS 434#ifndef __ECOS
435 /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(), 435 /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(),
436 * adding and jffs2_flash_read_end() interface. */ 436 * adding and jffs2_flash_read_end() interface. */
@@ -445,12 +445,12 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
445 pointed = 1; /* succefully pointed to device */ 445 pointed = 1; /* succefully pointed to device */
446 } 446 }
447#endif 447#endif
448 448
449 if (!pointed) { 449 if (!pointed) {
450 buffer = kmalloc(len, GFP_KERNEL); 450 buffer = kmalloc(len, GFP_KERNEL);
451 if (unlikely(!buffer)) 451 if (unlikely(!buffer))
452 return -ENOMEM; 452 return -ENOMEM;
453 453
454 /* TODO: this is very frequent pattern, make it a separate 454 /* TODO: this is very frequent pattern, make it a separate
455 * routine */ 455 * routine */
456 err = jffs2_flash_read(c, ofs, len, &retlen, buffer); 456 err = jffs2_flash_read(c, ofs, len, &retlen, buffer);
@@ -458,7 +458,7 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info
458 JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err); 458 JFFS2_ERROR("can not read %d bytes from 0x%08x, error code: %d.\n", len, ofs, err);
459 goto free_out; 459 goto free_out;
460 } 460 }
461 461
462 if (retlen != len) { 462 if (retlen != len) {
463 JFFS2_ERROR("short read at %#08x: %d instead of %d.\n", ofs, retlen, len); 463 JFFS2_ERROR("short read at %#08x: %d instead of %d.\n", ofs, retlen, len);
464 err = -EIO; 464 err = -EIO;
@@ -485,7 +485,7 @@ adj_acc:
485 jeb = &c->blocks[ref->flash_offset / c->sector_size]; 485 jeb = &c->blocks[ref->flash_offset / c->sector_size];
486 len = ref_totlen(c, jeb, ref); 486 len = ref_totlen(c, jeb, ref);
487 487
488 /* 488 /*
489 * Mark the node as having been checked and fix the 489 * Mark the node as having been checked and fix the
490 * accounting accordingly. 490 * accounting accordingly.
491 */ 491 */
@@ -516,13 +516,13 @@ free_out:
516static inline int check_node(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_tmp_dnode_info *tn) 516static inline int check_node(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_tmp_dnode_info *tn)
517{ 517{
518 int ret; 518 int ret;
519 519
520 BUG_ON(ref_obsolete(tn->fn->raw)); 520 BUG_ON(ref_obsolete(tn->fn->raw));
521 521
522 /* We only check the data CRC of unchecked nodes */ 522 /* We only check the data CRC of unchecked nodes */
523 if (ref_flags(tn->fn->raw) != REF_UNCHECKED) 523 if (ref_flags(tn->fn->raw) != REF_UNCHECKED)
524 return 0; 524 return 0;
525 525
526 dbg_fragtree2("check node %#04x-%#04x, phys offs %#08x.\n", 526 dbg_fragtree2("check node %#04x-%#04x, phys offs %#08x.\n",
527 tn->fn->ofs, tn->fn->ofs + tn->fn->size, ref_offset(tn->fn->raw)); 527 tn->fn->ofs, tn->fn->ofs + tn->fn->size, ref_offset(tn->fn->raw));
528 528
@@ -538,7 +538,7 @@ static inline int check_node(struct jffs2_sb_info *c, struct jffs2_inode_info *f
538 return ret; 538 return ret;
539} 539}
540 540
541/* 541/*
542 * Helper function for jffs2_add_older_frag_to_fragtree(). 542 * Helper function for jffs2_add_older_frag_to_fragtree().
543 * 543 *
544 * Called when the new fragment that is being inserted 544 * Called when the new fragment that is being inserted
@@ -551,31 +551,31 @@ static int split_hole(struct jffs2_sb_info *c, struct rb_root *root,
551 newfrag->ofs, newfrag->ofs + newfrag->size, hole->ofs, hole->ofs + hole->size); 551 newfrag->ofs, newfrag->ofs + newfrag->size, hole->ofs, hole->ofs + hole->size);
552 552
553 if (hole->ofs == newfrag->ofs) { 553 if (hole->ofs == newfrag->ofs) {
554 /* 554 /*
555 * Well, the new fragment actually starts at the same offset as 555 * Well, the new fragment actually starts at the same offset as
556 * the hole. 556 * the hole.
557 */ 557 */
558 if (hole->ofs + hole->size > newfrag->ofs + newfrag->size) { 558 if (hole->ofs + hole->size > newfrag->ofs + newfrag->size) {
559 /* 559 /*
560 * We replace the overlapped left part of the hole by 560 * We replace the overlapped left part of the hole by
561 * the new node. 561 * the new node.
562 */ 562 */
563 563
564 dbg_fragtree2("insert fragment %#04x-%#04x and cut the left part of the hole\n", 564 dbg_fragtree2("insert fragment %#04x-%#04x and cut the left part of the hole\n",
565 newfrag->ofs, newfrag->ofs + newfrag->size); 565 newfrag->ofs, newfrag->ofs + newfrag->size);
566 rb_replace_node(&hole->rb, &newfrag->rb, root); 566 rb_replace_node(&hole->rb, &newfrag->rb, root);
567 567
568 hole->ofs += newfrag->size; 568 hole->ofs += newfrag->size;
569 hole->size -= newfrag->size; 569 hole->size -= newfrag->size;
570 570
571 /* 571 /*
572 * We know that 'hole' should be the right hand 572 * We know that 'hole' should be the right hand
573 * fragment. 573 * fragment.
574 */ 574 */
575 jffs2_fragtree_insert(hole, newfrag); 575 jffs2_fragtree_insert(hole, newfrag);
576 rb_insert_color(&hole->rb, root); 576 rb_insert_color(&hole->rb, root);
577 } else { 577 } else {
578 /* 578 /*
579 * Ah, the new fragment is of the same size as the hole. 579 * Ah, the new fragment is of the same size as the hole.
580 * Relace the hole by it. 580 * Relace the hole by it.
581 */ 581 */
@@ -586,7 +586,7 @@ static int split_hole(struct jffs2_sb_info *c, struct rb_root *root,
586 } 586 }
587 } else { 587 } else {
588 /* The new fragment lefts some hole space at the left */ 588 /* The new fragment lefts some hole space at the left */
589 589
590 struct jffs2_node_frag * newfrag2 = NULL; 590 struct jffs2_node_frag * newfrag2 = NULL;
591 591
592 if (hole->ofs + hole->size > newfrag->ofs + newfrag->size) { 592 if (hole->ofs + hole->size > newfrag->ofs + newfrag->size) {
@@ -606,7 +606,7 @@ static int split_hole(struct jffs2_sb_info *c, struct rb_root *root,
606 606
607 jffs2_fragtree_insert(newfrag, hole); 607 jffs2_fragtree_insert(newfrag, hole);
608 rb_insert_color(&newfrag->rb, root); 608 rb_insert_color(&newfrag->rb, root);
609 609
610 if (newfrag2) { 610 if (newfrag2) {
611 dbg_fragtree2("left the hole %#04x-%#04x at the right\n", 611 dbg_fragtree2("left the hole %#04x-%#04x at the right\n",
612 newfrag2->ofs, newfrag2->ofs + newfrag2->size); 612 newfrag2->ofs, newfrag2->ofs + newfrag2->size);
@@ -654,18 +654,18 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
654 lastend = this->ofs + this->size; 654 lastend = this->ofs + this->size;
655 else 655 else
656 lastend = 0; 656 lastend = 0;
657 657
658 /* Detect the preliminary type of node */ 658 /* Detect the preliminary type of node */
659 if (fn->size >= PAGE_CACHE_SIZE) 659 if (fn->size >= PAGE_CACHE_SIZE)
660 ref_flag = REF_PRISTINE; 660 ref_flag = REF_PRISTINE;
661 else 661 else
662 ref_flag = REF_NORMAL; 662 ref_flag = REF_NORMAL;
663 663
664 /* See if we ran off the end of the root */ 664 /* See if we ran off the end of the root */
665 if (lastend <= fn_ofs) { 665 if (lastend <= fn_ofs) {
666 /* We did */ 666 /* We did */
667 667
668 /* 668 /*
669 * We are going to insert the new node into the 669 * We are going to insert the new node into the
670 * fragment tree, so check it. 670 * fragment tree, so check it.
671 */ 671 */
@@ -691,21 +691,21 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
691 fn->frags = 0; 691 fn->frags = 0;
692 692
693 while (1) { 693 while (1) {
694 /* 694 /*
695 * Here we have: 695 * Here we have:
696 * fn_ofs < this->ofs + this->size && fn_ofs >= this->ofs. 696 * fn_ofs < this->ofs + this->size && fn_ofs >= this->ofs.
697 * 697 *
698 * Remember, 'this' has higher version, any non-hole node 698 * Remember, 'this' has higher version, any non-hole node
699 * which is already in the fragtree is newer then the newly 699 * which is already in the fragtree is newer then the newly
700 * inserted. 700 * inserted.
701 */ 701 */
702 if (!this->node) { 702 if (!this->node) {
703 /* 703 /*
704 * 'this' is the hole fragment, so at least the 704 * 'this' is the hole fragment, so at least the
705 * beginning of the new fragment is valid. 705 * beginning of the new fragment is valid.
706 */ 706 */
707 707
708 /* 708 /*
709 * We are going to insert the new node into the 709 * We are going to insert the new node into the
710 * fragment tree, so check it. 710 * fragment tree, so check it.
711 */ 711 */
@@ -715,7 +715,7 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
715 return err; 715 return err;
716 checked = 1; 716 checked = 1;
717 } 717 }
718 718
719 if (this->ofs + this->size >= fn_ofs + fn_size) { 719 if (this->ofs + this->size >= fn_ofs + fn_size) {
720 /* We split the hole on two parts */ 720 /* We split the hole on two parts */
721 721
@@ -730,7 +730,7 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
730 goto out_ok; 730 goto out_ok;
731 } 731 }
732 732
733 /* 733 /*
734 * The beginning of the new fragment is valid since it 734 * The beginning of the new fragment is valid since it
735 * overlaps the hole node. 735 * overlaps the hole node.
736 */ 736 */
@@ -742,9 +742,9 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
742 this->ofs + this->size - fn_ofs); 742 this->ofs + this->size - fn_ofs);
743 if (unlikely(!newfrag)) 743 if (unlikely(!newfrag))
744 return -ENOMEM; 744 return -ENOMEM;
745 745
746 if (fn_ofs == this->ofs) { 746 if (fn_ofs == this->ofs) {
747 /* 747 /*
748 * The new node starts at the same offset as 748 * The new node starts at the same offset as
749 * the hole and supersieds the hole. 749 * the hole and supersieds the hole.
750 */ 750 */
@@ -754,21 +754,21 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
754 rb_replace_node(&this->rb, &newfrag->rb, root); 754 rb_replace_node(&this->rb, &newfrag->rb, root);
755 jffs2_free_node_frag(this); 755 jffs2_free_node_frag(this);
756 } else { 756 } else {
757 /* 757 /*
758 * The hole becomes shorter as its right part 758 * The hole becomes shorter as its right part
759 * is supersieded by the new fragment. 759 * is supersieded by the new fragment.
760 */ 760 */
761 dbg_fragtree2("reduce size of hole %#04x-%#04x to %#04x-%#04x\n", 761 dbg_fragtree2("reduce size of hole %#04x-%#04x to %#04x-%#04x\n",
762 this->ofs, this->ofs + this->size, this->ofs, this->ofs + this->size - newfrag->size); 762 this->ofs, this->ofs + this->size, this->ofs, this->ofs + this->size - newfrag->size);
763 763
764 dbg_fragtree2("add new fragment %#04x-%#04x, refcnt %d\n", fn_ofs, 764 dbg_fragtree2("add new fragment %#04x-%#04x, refcnt %d\n", fn_ofs,
765 fn_ofs + this->ofs + this->size - fn_ofs, fn->frags); 765 fn_ofs + this->ofs + this->size - fn_ofs, fn->frags);
766 766
767 this->size -= newfrag->size; 767 this->size -= newfrag->size;
768 jffs2_fragtree_insert(newfrag, this); 768 jffs2_fragtree_insert(newfrag, this);
769 rb_insert_color(&newfrag->rb, root); 769 rb_insert_color(&newfrag->rb, root);
770 } 770 }
771 771
772 fn_ofs += newfrag->size; 772 fn_ofs += newfrag->size;
773 fn_size -= newfrag->size; 773 fn_size -= newfrag->size;
774 this = rb_entry(rb_next(&newfrag->rb), 774 this = rb_entry(rb_next(&newfrag->rb),
@@ -778,7 +778,7 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
778 this->ofs, this->ofs + this->size, this->node ? "(data)" : "(hole)"); 778 this->ofs, this->ofs + this->size, this->node ? "(data)" : "(hole)");
779 } 779 }
780 780
781 /* 781 /*
782 * 'This' node is not the hole so it obsoletes the new fragment 782 * 'This' node is not the hole so it obsoletes the new fragment
783 * either fully or partially. 783 * either fully or partially.
784 */ 784 */
@@ -791,19 +791,19 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
791 goto out_ok; 791 goto out_ok;
792 } else { 792 } else {
793 struct jffs2_node_frag *new_this; 793 struct jffs2_node_frag *new_this;
794 794
795 /* 'This' node obsoletes the beginning of the new node */ 795 /* 'This' node obsoletes the beginning of the new node */
796 dbg_fragtree2("the beginning %#04x-%#04x is obsolete\n", fn_ofs, this->ofs + this->size); 796 dbg_fragtree2("the beginning %#04x-%#04x is obsolete\n", fn_ofs, this->ofs + this->size);
797 797
798 ref_flag = REF_NORMAL; 798 ref_flag = REF_NORMAL;
799 799
800 fn_size -= this->ofs + this->size - fn_ofs; 800 fn_size -= this->ofs + this->size - fn_ofs;
801 fn_ofs = this->ofs + this->size; 801 fn_ofs = this->ofs + this->size;
802 dbg_fragtree2("now considering %#04x-%#04x\n", fn_ofs, fn_ofs + fn_size); 802 dbg_fragtree2("now considering %#04x-%#04x\n", fn_ofs, fn_ofs + fn_size);
803 803
804 new_this = rb_entry(rb_next(&this->rb), struct jffs2_node_frag, rb); 804 new_this = rb_entry(rb_next(&this->rb), struct jffs2_node_frag, rb);
805 if (!new_this) { 805 if (!new_this) {
806 /* 806 /*
807 * There is no next fragment. Add the rest of 807 * There is no next fragment. Add the rest of
808 * the new node as the right-hand child. 808 * the new node as the right-hand child.
809 */ 809 */
@@ -813,7 +813,7 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
813 return err; 813 return err;
814 checked = 1; 814 checked = 1;
815 } 815 }
816 816
817 fn->frags += 1; 817 fn->frags += 1;
818 newfrag = new_fragment(fn, fn_ofs, fn_size); 818 newfrag = new_fragment(fn, fn_ofs, fn_size);
819 if (unlikely(!newfrag)) 819 if (unlikely(!newfrag))
@@ -821,7 +821,7 @@ int jffs2_add_older_frag_to_fragtree(struct jffs2_sb_info *c, struct jffs2_inode
821 821
822 dbg_fragtree2("there are no more fragments, insert %#04x-%#04x\n", 822 dbg_fragtree2("there are no more fragments, insert %#04x-%#04x\n",
823 newfrag->ofs, newfrag->ofs + newfrag->size); 823 newfrag->ofs, newfrag->ofs + newfrag->size);
824 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right); 824 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
825 rb_insert_color(&newfrag->rb, root); 825 rb_insert_color(&newfrag->rb, root);
826 goto out_ok; 826 goto out_ok;
827 } else { 827 } else {
@@ -862,9 +862,9 @@ void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache
862 862
863/* During mount, this needs no locking. During normal operation, its 863/* During mount, this needs no locking. During normal operation, its
864 callers want to do other stuff while still holding the inocache_lock. 864 callers want to do other stuff while still holding the inocache_lock.
865 Rather than introducing special case get_ino_cache functions or 865 Rather than introducing special case get_ino_cache functions or
866 callbacks, we just let the caller do the locking itself. */ 866 callbacks, we just let the caller do the locking itself. */
867 867
868struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino) 868struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino)
869{ 869{
870 struct jffs2_inode_cache *ret; 870 struct jffs2_inode_cache *ret;
@@ -873,7 +873,7 @@ struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t
873 while (ret && ret->ino < ino) { 873 while (ret && ret->ino < ino) {
874 ret = ret->next; 874 ret = ret->next;
875 } 875 }
876 876
877 if (ret && ret->ino != ino) 877 if (ret && ret->ino != ino)
878 ret = NULL; 878 ret = NULL;
879 879
@@ -907,9 +907,9 @@ void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
907 907
908 dbg_inocache("del %p (ino #%u)\n", old, old->ino); 908 dbg_inocache("del %p (ino #%u)\n", old, old->ino);
909 spin_lock(&c->inocache_lock); 909 spin_lock(&c->inocache_lock);
910 910
911 prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE]; 911 prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE];
912 912
913 while ((*prev) && (*prev)->ino < old->ino) { 913 while ((*prev) && (*prev)->ino < old->ino) {
914 prev = &(*prev)->next; 914 prev = &(*prev)->next;
915 } 915 }
@@ -919,7 +919,7 @@ void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
919 919
920 /* Free it now unless it's in READING or CLEARING state, which 920 /* Free it now unless it's in READING or CLEARING state, which
921 are the transitions upon read_inode() and clear_inode(). The 921 are the transitions upon read_inode() and clear_inode(). The
922 rest of the time we know nobody else is looking at it, and 922 rest of the time we know nobody else is looking at it, and
923 if it's held by read_inode() or clear_inode() they'll free it 923 if it's held by read_inode() or clear_inode() they'll free it
924 for themselves. */ 924 for themselves. */
925 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING) 925 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING)
@@ -932,7 +932,7 @@ void jffs2_free_ino_caches(struct jffs2_sb_info *c)
932{ 932{
933 int i; 933 int i;
934 struct jffs2_inode_cache *this, *next; 934 struct jffs2_inode_cache *this, *next;
935 935
936 for (i=0; i<INOCACHE_HASHSIZE; i++) { 936 for (i=0; i<INOCACHE_HASHSIZE; i++) {
937 this = c->inocache_list[i]; 937 this = c->inocache_list[i];
938 while (this) { 938 while (this) {
@@ -959,10 +959,10 @@ void jffs2_free_raw_node_refs(struct jffs2_sb_info *c)
959 c->blocks[i].first_node = c->blocks[i].last_node = NULL; 959 c->blocks[i].first_node = c->blocks[i].last_node = NULL;
960 } 960 }
961} 961}
962 962
963struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset) 963struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset)
964{ 964{
965 /* The common case in lookup is that there will be a node 965 /* The common case in lookup is that there will be a node
966 which precisely matches. So we go looking for that first */ 966 which precisely matches. So we go looking for that first */
967 struct rb_node *next; 967 struct rb_node *next;
968 struct jffs2_node_frag *prev = NULL; 968 struct jffs2_node_frag *prev = NULL;
@@ -993,9 +993,9 @@ struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_
993 if (prev) 993 if (prev)
994 dbg_fragtree2("no match. Returning frag %#04x-%#04x, closest previous\n", 994 dbg_fragtree2("no match. Returning frag %#04x-%#04x, closest previous\n",
995 prev->ofs, prev->ofs+prev->size); 995 prev->ofs, prev->ofs+prev->size);
996 else 996 else
997 dbg_fragtree2("returning NULL, empty fragtree\n"); 997 dbg_fragtree2("returning NULL, empty fragtree\n");
998 998
999 return prev; 999 return prev;
1000} 1000}
1001 1001
@@ -1010,7 +1010,7 @@ void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
1010 return; 1010 return;
1011 1011
1012 dbg_fragtree("killing\n"); 1012 dbg_fragtree("killing\n");
1013 1013
1014 frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb)); 1014 frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb));
1015 while(frag) { 1015 while(frag) {
1016 if (frag->rb.rb_left) { 1016 if (frag->rb.rb_left) {
@@ -1023,18 +1023,18 @@ void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
1023 } 1023 }
1024 1024
1025 if (frag->node && !(--frag->node->frags)) { 1025 if (frag->node && !(--frag->node->frags)) {
1026 /* Not a hole, and it's the final remaining frag 1026 /* Not a hole, and it's the final remaining frag
1027 of this node. Free the node */ 1027 of this node. Free the node */
1028 if (c) 1028 if (c)
1029 jffs2_mark_node_obsolete(c, frag->node->raw); 1029 jffs2_mark_node_obsolete(c, frag->node->raw);
1030 1030
1031 jffs2_free_full_dnode(frag->node); 1031 jffs2_free_full_dnode(frag->node);
1032 } 1032 }
1033 parent = frag_parent(frag); 1033 parent = frag_parent(frag);
1034 if (parent) { 1034 if (parent) {
1035 if (frag_left(parent) == frag) 1035 if (frag_left(parent) == frag)
1036 parent->rb.rb_left = NULL; 1036 parent->rb.rb_left = NULL;
1037 else 1037 else
1038 parent->rb.rb_right = NULL; 1038 parent->rb.rb_right = NULL;
1039 } 1039 }
1040 1040