]> err.no Git - linux-2.6/blobdiff - fs/jffs2/readinode.c
[PATCH] swap: swap unsigned int consistency
[linux-2.6] / fs / jffs2 / readinode.c
index ef552477c813f4d5a126f64c25a7fd3c320dca0b..5b2a83599d73c6649130c161293505384e60e114 100644 (file)
@@ -7,7 +7,7 @@
  *
  * For licensing information, see the file 'LICENCE' in this directory.
  *
- * $Id: readinode.c,v 1.119 2005/03/01 10:34:03 dedekind Exp $
+ * $Id: readinode.c,v 1.125 2005/07/10 13:13:55 dedekind Exp $
  *
  */
 
@@ -151,6 +151,9 @@ int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_in
 
        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))
+               return 0;
+
        newfrag = jffs2_alloc_node_frag();
        if (unlikely(!newfrag))
                return -ENOMEM;
@@ -158,11 +161,6 @@ int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_in
        D2(printk(KERN_DEBUG "adding node %04x-%04x @0x%08x on flash, newfrag *%p\n",
                  fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag));
        
-       if (unlikely(!fn->size)) {
-               jffs2_free_node_frag(newfrag);
-               return 0;
-       }
-
        newfrag->ofs = fn->ofs;
        newfrag->size = fn->size;
        newfrag->node = fn;
@@ -500,7 +498,9 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
                                        struct jffs2_inode_info *f,
                                        struct jffs2_raw_inode *latest_node)
 {
-       struct jffs2_tmp_dnode_info *tn_list, *tn;
+       struct jffs2_tmp_dnode_info *tn = NULL;
+       struct rb_root tn_list;
+       struct rb_node *rb, *repl_rb;
        struct jffs2_full_dirent *fd_list;
        struct jffs2_full_dnode *fn = NULL;
        uint32_t crc;
@@ -522,9 +522,10 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
        }
        f->dents = fd_list;
 
-       while (tn_list) {
-               tn = tn_list;
+       rb = rb_first(&tn_list);
 
+       while (rb) {
+               tn = rb_entry(rb, struct jffs2_tmp_dnode_info, rb);
                fn = tn->fn;
 
                if (f->metadata) {
@@ -556,7 +557,29 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
                        mdata_ver = tn->version;
                }
        next_tn:
-               tn_list = tn->next;
+               BUG_ON(rb->rb_left);
+               if (rb->rb_parent && rb->rb_parent->rb_left == rb) {
+                       /* We were then left-hand child of our parent. We need
+                          to move our own right-hand child into our place. */
+                       repl_rb = rb->rb_right;
+                       if (repl_rb)
+                               repl_rb->rb_parent = rb->rb_parent;
+               } else
+                       repl_rb = NULL;
+
+               rb = rb_next(rb);
+
+               /* Remove the spent tn from the tree; don't bother rebalancing
+                  but put our right-hand child in our own place. */
+               if (tn->rb.rb_parent) {
+                       if (tn->rb.rb_parent->rb_left == &tn->rb)
+                               tn->rb.rb_parent->rb_left = repl_rb;
+                       else if (tn->rb.rb_parent->rb_right == &tn->rb)
+                               tn->rb.rb_parent->rb_right = repl_rb;
+                       else BUG();
+               } else if (tn->rb.rb_right)
+                       tn->rb.rb_right->rb_parent = NULL;
+
                jffs2_free_tmp_dnode_info(tn);
        }
        D1(jffs2_sanitycheck_fragtree(f));