blob: 87c6f555e1a0a696ee2fe52e57c9b3978bc8716f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
David Woodhousec00c3102007-04-25 14:16:47 +01004 * Copyright © 2001-2007 Red Hat, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
12#include <linux/kernel.h>
13#include <linux/sched.h>
14#include <linux/fs.h>
15#include <linux/mtd/mtd.h>
16#include <linux/rbtree.h>
17#include <linux/crc32.h>
18#include <linux/slab.h>
19#include <linux/pagemap.h>
20#include "nodelist.h"
21
Adrian Bunk90a18fa2006-07-06 22:37:43 +020022static void jffs2_obsolete_node_frag(struct jffs2_sb_info *c,
23 struct jffs2_node_frag *this);
24
Linus Torvalds1da177e2005-04-16 15:20:36 -070025void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list)
26{
27 struct jffs2_full_dirent **prev = list;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000028
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010029 dbg_dentlist("add dirent \"%s\", ino #%u\n", new->name, new->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
31 while ((*prev) && (*prev)->nhash <= new->nhash) {
32 if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) {
33 /* Duplicate. Free one */
34 if (new->version < (*prev)->version) {
David Woodhouse15953582007-11-01 16:25:56 -040035 dbg_dentlist("Eep! Marking new dirent node obsolete, old is \"%s\", ino #%u\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +010036 (*prev)->name, (*prev)->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 jffs2_mark_node_obsolete(c, new->raw);
38 jffs2_free_full_dirent(new);
39 } else {
David Woodhouse15953582007-11-01 16:25:56 -040040 dbg_dentlist("marking old dirent \"%s\", ino #%u obsolete\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +010041 (*prev)->name, (*prev)->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 new->next = (*prev)->next;
David Woodhouse15953582007-11-01 16:25:56 -040043 /* It may have been a 'placeholder' deletion dirent,
44 if jffs2_can_mark_obsolete() (see jffs2_do_unlink()) */
45 if ((*prev)->raw)
46 jffs2_mark_node_obsolete(c, ((*prev)->raw));
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 jffs2_free_full_dirent(*prev);
48 *prev = new;
49 }
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +010050 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 }
52 prev = &((*prev)->next);
53 }
54 new->next = *prev;
55 *prev = new;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}
57
David Woodhouse61c4b232007-04-25 17:04:23 +010058uint32_t jffs2_truncate_fragtree(struct jffs2_sb_info *c, struct rb_root *list, uint32_t size)
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010059{
60 struct jffs2_node_frag *frag = jffs2_lookup_node_frag(list, size);
61
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010062 dbg_fragtree("truncating fragtree to 0x%08x bytes\n", size);
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010063
64 /* We know frag->ofs <= size. That's what lookup does for us */
65 if (frag && frag->ofs != size) {
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010066 if (frag->ofs+frag->size > size) {
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010067 frag->size = size - frag->ofs;
68 }
69 frag = frag_next(frag);
70 }
71 while (frag && frag->ofs >= size) {
72 struct jffs2_node_frag *next = frag_next(frag);
73
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010074 frag_erase(frag, list);
75 jffs2_obsolete_node_frag(c, frag);
76 frag = next;
77 }
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010078
79 if (size == 0)
David Woodhouse61c4b232007-04-25 17:04:23 +010080 return 0;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010081
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010082 frag = frag_last(list);
David Woodhouse61c4b232007-04-25 17:04:23 +010083
84 /* Sanity check for truncation to longer than we started with... */
85 if (!frag)
86 return 0;
87 if (frag->ofs + frag->size < size)
88 return frag->ofs + frag->size;
89
90 /* If the last fragment starts at the RAM page boundary, it is
91 * REF_PRISTINE irrespective of its size. */
Artem B. Bityutskiyf0507532005-08-22 10:07:12 +010092 if (frag->node && (frag->ofs & (PAGE_CACHE_SIZE - 1)) == 0) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010093 dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n",
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000094 frag->ofs, frag->ofs + frag->size);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010095 frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE;
96 }
David Woodhouse61c4b232007-04-25 17:04:23 +010097 return size;
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010098}
99
Adrian Bunk90a18fa2006-07-06 22:37:43 +0200100static void jffs2_obsolete_node_frag(struct jffs2_sb_info *c,
101 struct jffs2_node_frag *this)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100103 if (this->node) {
104 this->node->frags--;
105 if (!this->node->frags) {
106 /* The node has no valid frags left. It's totally obsoleted */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100107 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) obsolete\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100108 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100109 jffs2_mark_node_obsolete(c, this->node->raw);
110 jffs2_free_full_dnode(this->node);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100111 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100112 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) REF_NORMAL. frags is %d\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100113 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size, this->node->frags);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100114 mark_ref_normal(this->node->raw);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100115 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000116
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100117 }
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100118 jffs2_free_node_frag(this);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100119}
120
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100121static void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_node_frag *base)
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100122{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100123 struct rb_node *parent = &base->rb;
124 struct rb_node **link = &parent;
125
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100126 dbg_fragtree2("insert frag (0x%04x-0x%04x)\n", newfrag->ofs, newfrag->ofs + newfrag->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100127
128 while (*link) {
129 parent = *link;
130 base = rb_entry(parent, struct jffs2_node_frag, rb);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000131
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100132 if (newfrag->ofs > base->ofs)
133 link = &base->rb.rb_right;
134 else if (newfrag->ofs < base->ofs)
135 link = &base->rb.rb_left;
136 else {
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100137 JFFS2_ERROR("duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100138 BUG();
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100139 }
140 }
141
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100142 rb_link_node(&newfrag->rb, &base->rb, link);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100143}
144
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100145/*
146 * Allocate and initializes a new fragment.
147 */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800148static struct jffs2_node_frag * new_fragment(struct jffs2_full_dnode *fn, uint32_t ofs, uint32_t size)
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100149{
150 struct jffs2_node_frag *newfrag;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000151
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100152 newfrag = jffs2_alloc_node_frag();
153 if (likely(newfrag)) {
154 newfrag->ofs = ofs;
155 newfrag->size = size;
156 newfrag->node = fn;
157 } else {
158 JFFS2_ERROR("cannot allocate a jffs2_node_frag object\n");
159 }
160
161 return newfrag;
162}
163
164/*
165 * Called when there is no overlapping fragment exist. Inserts a hole before the new
166 * fragment and inserts the new fragment to the fragtree.
167 */
168static int no_overlapping_node(struct jffs2_sb_info *c, struct rb_root *root,
169 struct jffs2_node_frag *newfrag,
170 struct jffs2_node_frag *this, uint32_t lastend)
171{
172 if (lastend < newfrag->node->ofs) {
173 /* put a hole in before the new fragment */
174 struct jffs2_node_frag *holefrag;
175
176 holefrag= new_fragment(NULL, lastend, newfrag->node->ofs - lastend);
177 if (unlikely(!holefrag)) {
178 jffs2_free_node_frag(newfrag);
179 return -ENOMEM;
180 }
181
182 if (this) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000183 /* By definition, the 'this' node has no right-hand child,
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100184 because there are no frags with offset greater than it.
185 So that's where we want to put the hole */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100186 dbg_fragtree2("add hole frag %#04x-%#04x on the right of the new frag.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100187 holefrag->ofs, holefrag->ofs + holefrag->size);
188 rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right);
189 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100190 dbg_fragtree2("Add hole frag %#04x-%#04x to the root of the tree.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100191 holefrag->ofs, holefrag->ofs + holefrag->size);
192 rb_link_node(&holefrag->rb, NULL, &root->rb_node);
193 }
194 rb_insert_color(&holefrag->rb, root);
195 this = holefrag;
196 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000197
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100198 if (this) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000199 /* By definition, the 'this' node has no right-hand child,
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100200 because there are no frags with offset greater than it.
201 So that's where we want to put new fragment */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100202 dbg_fragtree2("add the new node at the right\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000203 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100204 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100205 dbg_fragtree2("insert the new node at the root of the tree\n");
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100206 rb_link_node(&newfrag->rb, NULL, &root->rb_node);
207 }
208 rb_insert_color(&newfrag->rb, root);
209
210 return 0;
211}
212
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100213/* Doesn't set inode->i_size */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100214static int jffs2_add_frag_to_fragtree(struct jffs2_sb_info *c, struct rb_root *root, struct jffs2_node_frag *newfrag)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100216 struct jffs2_node_frag *this;
217 uint32_t lastend;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100219 /* Skip all the nodes which are completed before this one starts */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100220 this = jffs2_lookup_node_frag(root, newfrag->node->ofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100222 if (this) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100223 dbg_fragtree2("lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100224 this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100225 lastend = this->ofs + this->size;
226 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100227 dbg_fragtree2("lookup gave no frag\n");
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100228 lastend = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000230
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100231 /* See if we ran off the end of the fragtree */
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100232 if (lastend <= newfrag->ofs) {
233 /* We did */
234
235 /* Check if 'this' node was on the same page as the new node.
236 If so, both 'this' and the new node get marked REF_NORMAL so
237 the GC can take a look.
238 */
239 if (lastend && (lastend-1) >> PAGE_CACHE_SHIFT == newfrag->ofs >> PAGE_CACHE_SHIFT) {
240 if (this->node)
241 mark_ref_normal(this->node->raw);
242 mark_ref_normal(newfrag->node->raw);
243 }
244
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100245 return no_overlapping_node(c, root, newfrag, this, lastend);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100246 }
247
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100248 if (this->node)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100249 dbg_fragtree2("dealing with frag %u-%u, phys %#08x(%d).\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100250 this->ofs, this->ofs + this->size,
251 ref_offset(this->node->raw), ref_flags(this->node->raw));
252 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100253 dbg_fragtree2("dealing with hole frag %u-%u.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100254 this->ofs, this->ofs + this->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100255
256 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes,
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000257 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100258 */
259 if (newfrag->ofs > this->ofs) {
260 /* This node isn't completely obsoleted. The start of it remains valid */
261
262 /* Mark the new node and the partially covered node REF_NORMAL -- let
263 the GC take a look at them */
264 mark_ref_normal(newfrag->node->raw);
265 if (this->node)
266 mark_ref_normal(this->node->raw);
267
268 if (this->ofs + this->size > newfrag->ofs + newfrag->size) {
269 /* The new node splits 'this' frag into two */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100270 struct jffs2_node_frag *newfrag2;
271
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100272 if (this->node)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100273 dbg_fragtree2("split old frag 0x%04x-0x%04x, phys 0x%08x\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100274 this->ofs, this->ofs+this->size, ref_offset(this->node->raw));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000275 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100276 dbg_fragtree2("split old hole frag 0x%04x-0x%04x\n",
Artem B. Bityutskiy8d5df402005-08-17 15:13:48 +0100277 this->ofs, this->ofs+this->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000278
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100279 /* New second frag pointing to this's node */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100280 newfrag2 = new_fragment(this->node, newfrag->ofs + newfrag->size,
281 this->ofs + this->size - newfrag->ofs - newfrag->size);
282 if (unlikely(!newfrag2))
283 return -ENOMEM;
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100284 if (this->node)
285 this->node->frags++;
286
287 /* Adjust size of original 'this' */
288 this->size = newfrag->ofs - this->ofs;
289
290 /* Now, we know there's no node with offset
291 greater than this->ofs but smaller than
292 newfrag2->ofs or newfrag->ofs, for obvious
293 reasons. So we can do a tree insert from
294 'this' to insert newfrag, and a tree insert
295 from newfrag to insert newfrag2. */
296 jffs2_fragtree_insert(newfrag, this);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100297 rb_insert_color(&newfrag->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000298
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100299 jffs2_fragtree_insert(newfrag2, newfrag);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100300 rb_insert_color(&newfrag2->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000301
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100302 return 0;
303 }
304 /* New node just reduces 'this' frag in size, doesn't split it */
305 this->size = newfrag->ofs - this->ofs;
306
307 /* Again, we know it lives down here in the tree */
308 jffs2_fragtree_insert(newfrag, this);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100309 rb_insert_color(&newfrag->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100310 } else {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000311 /* New frag starts at the same point as 'this' used to. Replace
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100312 it in the tree without doing a delete and insertion */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100313 dbg_fragtree2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100314 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000315
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100316 rb_replace_node(&this->rb, &newfrag->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000317
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100318 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100319 dbg_fragtree2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100320 jffs2_obsolete_node_frag(c, this);
321 } else {
322 this->ofs += newfrag->size;
323 this->size -= newfrag->size;
324
325 jffs2_fragtree_insert(this, newfrag);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100326 rb_insert_color(&this->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100327 return 0;
328 }
329 }
330 /* OK, now we have newfrag added in the correct place in the tree, but
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000331 frag_next(newfrag) may be a fragment which is overlapped by it
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100332 */
333 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) {
334 /* 'this' frag is obsoleted completely. */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100335 dbg_fragtree2("obsoleting node frag %p (%x-%x) and removing from tree\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100336 this, this->ofs, this->ofs+this->size);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100337 rb_erase(&this->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100338 jffs2_obsolete_node_frag(c, this);
339 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000340 /* Now we're pointing at the first frag which isn't totally obsoleted by
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100341 the new frag */
342
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100343 if (!this || newfrag->ofs + newfrag->size == this->ofs)
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100344 return 0;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100345
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100346 /* Still some overlap but we don't need to move it in the tree */
347 this->size = (this->ofs + this->size) - (newfrag->ofs + newfrag->size);
348 this->ofs = newfrag->ofs + newfrag->size;
349
350 /* And mark them REF_NORMAL so the GC takes a look at them */
351 if (this->node)
352 mark_ref_normal(this->node->raw);
353 mark_ref_normal(newfrag->node->raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000358/*
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100359 * Given an inode, probably with existing tree of fragments, add the new node
360 * to the fragment tree.
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100361 */
362int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn)
363{
364 int ret;
365 struct jffs2_node_frag *newfrag;
366
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100367 if (unlikely(!fn->size))
368 return 0;
369
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100370 newfrag = new_fragment(fn, fn->ofs, fn->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100371 if (unlikely(!newfrag))
372 return -ENOMEM;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100373 newfrag->node->frags = 1;
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100374
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100375 dbg_fragtree("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100376 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000377
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100378 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag);
379 if (unlikely(ret))
380 return ret;
381
382 /* If we now share a page with other nodes, mark either previous
383 or next node REF_NORMAL, as appropriate. */
384 if (newfrag->ofs & (PAGE_CACHE_SIZE-1)) {
385 struct jffs2_node_frag *prev = frag_prev(newfrag);
386
387 mark_ref_normal(fn->raw);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000388 /* If we don't start at zero there's _always_ a previous */
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100389 if (prev->node)
390 mark_ref_normal(prev->node->raw);
391 }
392
393 if ((newfrag->ofs+newfrag->size) & (PAGE_CACHE_SIZE-1)) {
394 struct jffs2_node_frag *next = frag_next(newfrag);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000395
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100396 if (next) {
397 mark_ref_normal(fn->raw);
398 if (next->node)
399 mark_ref_normal(next->node->raw);
400 }
401 }
402 jffs2_dbg_fragtree_paranoia_check_nolock(f);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100403
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100404 return 0;
405}
406
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state)
408{
409 spin_lock(&c->inocache_lock);
410 ic->state = state;
411 wake_up(&c->inocache_wq);
412 spin_unlock(&c->inocache_lock);
413}
414
415/* During mount, this needs no locking. During normal operation, its
416 callers want to do other stuff while still holding the inocache_lock.
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000417 Rather than introducing special case get_ino_cache functions or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 callbacks, we just let the caller do the locking itself. */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino)
421{
422 struct jffs2_inode_cache *ret;
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 ret = c->inocache_list[ino % INOCACHE_HASHSIZE];
425 while (ret && ret->ino < ino) {
426 ret = ret->next;
427 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 if (ret && ret->ino != ino)
430 ret = NULL;
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 return ret;
433}
434
435void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new)
436{
437 struct jffs2_inode_cache **prev;
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 spin_lock(&c->inocache_lock);
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200440 if (!new->ino)
441 new->ino = ++c->highest_ino;
442
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100443 dbg_inocache("add %p (ino #%u)\n", new, new->ino);
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200444
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 prev = &c->inocache_list[new->ino % INOCACHE_HASHSIZE];
446
447 while ((*prev) && (*prev)->ino < new->ino) {
448 prev = &(*prev)->next;
449 }
450 new->next = *prev;
451 *prev = new;
452
453 spin_unlock(&c->inocache_lock);
454}
455
456void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
457{
458 struct jffs2_inode_cache **prev;
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100459
KaiGai Kohei355ed4e2006-06-24 09:15:36 +0900460#ifdef CONFIG_JFFS2_FS_XATTR
461 BUG_ON(old->xref);
462#endif
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100463 dbg_inocache("del %p (ino #%u)\n", old, old->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 spin_lock(&c->inocache_lock);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000465
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE];
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000467
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 while ((*prev) && (*prev)->ino < old->ino) {
469 prev = &(*prev)->next;
470 }
471 if ((*prev) == old) {
472 *prev = old->next;
473 }
474
David Woodhouse67e345d2005-02-27 23:01:36 +0000475 /* Free it now unless it's in READING or CLEARING state, which
476 are the transitions upon read_inode() and clear_inode(). The
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000477 rest of the time we know nobody else is looking at it, and
David Woodhouse67e345d2005-02-27 23:01:36 +0000478 if it's held by read_inode() or clear_inode() they'll free it
479 for themselves. */
480 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING)
481 jffs2_free_inode_cache(old);
482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 spin_unlock(&c->inocache_lock);
484}
485
486void jffs2_free_ino_caches(struct jffs2_sb_info *c)
487{
488 int i;
489 struct jffs2_inode_cache *this, *next;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 for (i=0; i<INOCACHE_HASHSIZE; i++) {
492 this = c->inocache_list[i];
493 while (this) {
494 next = this->next;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900495 jffs2_xattr_free_inode(c, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 jffs2_free_inode_cache(this);
497 this = next;
498 }
499 c->inocache_list[i] = NULL;
500 }
501}
502
503void jffs2_free_raw_node_refs(struct jffs2_sb_info *c)
504{
505 int i;
506 struct jffs2_raw_node_ref *this, *next;
507
508 for (i=0; i<c->nr_blocks; i++) {
509 this = c->blocks[i].first_node;
David Woodhouse2f785402006-05-24 02:04:45 +0100510 while (this) {
David Woodhouse9bfeb692006-05-26 21:19:05 +0100511 if (this[REFS_PER_BLOCK].flash_offset == REF_LINK_NODE)
512 next = this[REFS_PER_BLOCK].next_in_ino;
513 else
514 next = NULL;
515
516 jffs2_free_refblock(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 this = next;
518 }
519 c->blocks[i].first_node = c->blocks[i].last_node = NULL;
520 }
521}
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset)
524{
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000525 /* The common case in lookup is that there will be a node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 which precisely matches. So we go looking for that first */
527 struct rb_node *next;
528 struct jffs2_node_frag *prev = NULL;
529 struct jffs2_node_frag *frag = NULL;
530
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100531 dbg_fragtree2("root %p, offset %d\n", fragtree, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 next = fragtree->rb_node;
534
535 while(next) {
536 frag = rb_entry(next, struct jffs2_node_frag, rb);
537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 if (frag->ofs + frag->size <= offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 /* Remember the closest smaller match on the way down */
540 if (!prev || frag->ofs > prev->ofs)
541 prev = frag;
542 next = frag->rb.rb_right;
543 } else if (frag->ofs > offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 next = frag->rb.rb_left;
545 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return frag;
547 }
548 }
549
550 /* Exact match not found. Go back up looking at each parent,
551 and return the closest smaller one */
552
553 if (prev)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100554 dbg_fragtree2("no match. Returning frag %#04x-%#04x, closest previous\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100555 prev->ofs, prev->ofs+prev->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000556 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100557 dbg_fragtree2("returning NULL, empty fragtree\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 return prev;
560}
561
562/* Pass 'c' argument to indicate that nodes should be marked obsolete as
563 they're killed. */
564void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
565{
566 struct jffs2_node_frag *frag;
567 struct jffs2_node_frag *parent;
568
569 if (!root->rb_node)
570 return;
571
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100572 dbg_fragtree("killing\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000573
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 while(frag) {
576 if (frag->rb.rb_left) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 frag = frag_left(frag);
578 continue;
579 }
580 if (frag->rb.rb_right) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 frag = frag_right(frag);
582 continue;
583 }
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 if (frag->node && !(--frag->node->frags)) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000586 /* Not a hole, and it's the final remaining frag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 of this node. Free the node */
588 if (c)
589 jffs2_mark_node_obsolete(c, frag->node->raw);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 jffs2_free_full_dnode(frag->node);
592 }
593 parent = frag_parent(frag);
594 if (parent) {
595 if (frag_left(parent) == frag)
596 parent->rb.rb_left = NULL;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000597 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 parent->rb.rb_right = NULL;
599 }
600
601 jffs2_free_node_frag(frag);
602 frag = parent;
603
604 cond_resched();
605 }
606}
David Woodhousef1f96712006-05-20 19:45:26 +0100607
David Woodhouse2f785402006-05-24 02:04:45 +0100608struct jffs2_raw_node_ref *jffs2_link_node_ref(struct jffs2_sb_info *c,
609 struct jffs2_eraseblock *jeb,
610 uint32_t ofs, uint32_t len,
611 struct jffs2_inode_cache *ic)
David Woodhousef1f96712006-05-20 19:45:26 +0100612{
David Woodhouse2f785402006-05-24 02:04:45 +0100613 struct jffs2_raw_node_ref *ref;
614
David Woodhouse9bfeb692006-05-26 21:19:05 +0100615 BUG_ON(!jeb->allocated_refs);
616 jeb->allocated_refs--;
617
618 ref = jeb->last_node;
619
620 dbg_noderef("Last node at %p is (%08x,%p)\n", ref, ref->flash_offset,
621 ref->next_in_ino);
622
623 while (ref->flash_offset != REF_EMPTY_NODE) {
624 if (ref->flash_offset == REF_LINK_NODE)
625 ref = ref->next_in_ino;
626 else
627 ref++;
David Woodhouse2f785402006-05-24 02:04:45 +0100628 }
629
David Woodhouse9bfeb692006-05-26 21:19:05 +0100630 dbg_noderef("New ref is %p (%08x becomes %08x,%p) len 0x%x\n", ref,
631 ref->flash_offset, ofs, ref->next_in_ino, len);
632
David Woodhouse2f785402006-05-24 02:04:45 +0100633 ref->flash_offset = ofs;
634
David Woodhouse9bfeb692006-05-26 21:19:05 +0100635 if (!jeb->first_node) {
David Woodhousef1f96712006-05-20 19:45:26 +0100636 jeb->first_node = ref;
David Woodhouse9bfeb692006-05-26 21:19:05 +0100637 BUG_ON(ref_offset(ref) != jeb->offset);
638 } else if (unlikely(ref_offset(ref) != jeb->offset + c->sector_size - jeb->free_size)) {
639 uint32_t last_len = ref_totlen(c, jeb, jeb->last_node);
640
641 JFFS2_ERROR("Adding new ref %p at (0x%08x-0x%08x) not immediately after previous (0x%08x-0x%08x)\n",
642 ref, ref_offset(ref), ref_offset(ref)+len,
643 ref_offset(jeb->last_node),
644 ref_offset(jeb->last_node)+last_len);
645 BUG();
David Woodhouseca89a512006-05-21 13:29:11 +0100646 }
David Woodhousef1f96712006-05-20 19:45:26 +0100647 jeb->last_node = ref;
648
David Woodhousefcb75782006-05-22 15:23:10 +0100649 if (ic) {
650 ref->next_in_ino = ic->nodes;
651 ic->nodes = ref;
652 } else {
653 ref->next_in_ino = NULL;
654 }
655
David Woodhousef1f96712006-05-20 19:45:26 +0100656 switch(ref_flags(ref)) {
657 case REF_UNCHECKED:
658 c->unchecked_size += len;
659 jeb->unchecked_size += len;
660 break;
661
662 case REF_NORMAL:
663 case REF_PRISTINE:
664 c->used_size += len;
665 jeb->used_size += len;
666 break;
667
668 case REF_OBSOLETE:
669 c->dirty_size += len;
David Woodhouse3b796732006-05-22 12:15:47 +0100670 jeb->dirty_size += len;
David Woodhousef1f96712006-05-20 19:45:26 +0100671 break;
672 }
673 c->free_size -= len;
674 jeb->free_size -= len;
675
David Woodhouseca89a512006-05-21 13:29:11 +0100676#ifdef TEST_TOTLEN
677 /* Set (and test) __totlen field... for now */
678 ref->__totlen = len;
679 ref_totlen(c, jeb, ref);
680#endif
David Woodhouse2f785402006-05-24 02:04:45 +0100681 return ref;
David Woodhousef1f96712006-05-20 19:45:26 +0100682}
David Woodhouse68270992006-05-21 03:46:05 +0100683
David Woodhouse2f785402006-05-24 02:04:45 +0100684/* No locking, no reservation of 'ref'. Do not use on a live file system */
David Woodhouse68270992006-05-21 03:46:05 +0100685int jffs2_scan_dirty_space(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
686 uint32_t size)
687{
David Woodhouseca89a512006-05-21 13:29:11 +0100688 if (!size)
689 return 0;
David Woodhouse9bfeb692006-05-26 21:19:05 +0100690 if (unlikely(size > jeb->free_size)) {
691 printk(KERN_CRIT "Dirty space 0x%x larger then free_size 0x%x (wasted 0x%x)\n",
692 size, jeb->free_size, jeb->wasted_size);
David Woodhouseca89a512006-05-21 13:29:11 +0100693 BUG();
694 }
David Woodhouse9bfeb692006-05-26 21:19:05 +0100695 /* REF_EMPTY_NODE is !obsolete, so that works OK */
David Woodhouse2ebf09c2006-05-28 22:13:25 +0100696 if (jeb->last_node && ref_obsolete(jeb->last_node)) {
David Woodhouseca89a512006-05-21 13:29:11 +0100697#ifdef TEST_TOTLEN
698 jeb->last_node->__totlen += size;
699#endif
700 c->dirty_size += size;
701 c->free_size -= size;
702 jeb->dirty_size += size;
703 jeb->free_size -= size;
704 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100705 uint32_t ofs = jeb->offset + c->sector_size - jeb->free_size;
706 ofs |= REF_OBSOLETE;
David Woodhouseca89a512006-05-21 13:29:11 +0100707
David Woodhouse2f785402006-05-24 02:04:45 +0100708 jffs2_link_node_ref(c, jeb, ofs, size, NULL);
David Woodhouseca89a512006-05-21 13:29:11 +0100709 }
David Woodhouse68270992006-05-21 03:46:05 +0100710
711 return 0;
712}
David Woodhouseca89a512006-05-21 13:29:11 +0100713
714/* Calculate totlen from surrounding nodes or eraseblock */
715static inline uint32_t __ref_totlen(struct jffs2_sb_info *c,
716 struct jffs2_eraseblock *jeb,
717 struct jffs2_raw_node_ref *ref)
718{
719 uint32_t ref_end;
David Woodhouse99988f72006-05-24 09:04:17 +0100720 struct jffs2_raw_node_ref *next_ref = ref_next(ref);
David Woodhouseca89a512006-05-21 13:29:11 +0100721
David Woodhouse99988f72006-05-24 09:04:17 +0100722 if (next_ref)
723 ref_end = ref_offset(next_ref);
David Woodhouseca89a512006-05-21 13:29:11 +0100724 else {
725 if (!jeb)
726 jeb = &c->blocks[ref->flash_offset / c->sector_size];
727
728 /* Last node in block. Use free_space */
David Woodhouse9bfeb692006-05-26 21:19:05 +0100729 if (unlikely(ref != jeb->last_node)) {
David Woodhouseca89a512006-05-21 13:29:11 +0100730 printk(KERN_CRIT "ref %p @0x%08x is not jeb->last_node (%p @0x%08x)\n",
731 ref, ref_offset(ref), jeb->last_node, jeb->last_node?ref_offset(jeb->last_node):0);
732 BUG();
733 }
734 ref_end = jeb->offset + c->sector_size - jeb->free_size;
735 }
736 return ref_end - ref_offset(ref);
737}
738
739uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
740 struct jffs2_raw_node_ref *ref)
741{
742 uint32_t ret;
743
David Woodhouseca89a512006-05-21 13:29:11 +0100744 ret = __ref_totlen(c, jeb, ref);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100745
David Woodhouseca89a512006-05-21 13:29:11 +0100746#ifdef TEST_TOTLEN
David Woodhouse9bfeb692006-05-26 21:19:05 +0100747 if (unlikely(ret != ref->__totlen)) {
748 if (!jeb)
749 jeb = &c->blocks[ref->flash_offset / c->sector_size];
750
David Woodhouseca89a512006-05-21 13:29:11 +0100751 printk(KERN_CRIT "Totlen for ref at %p (0x%08x-0x%08x) miscalculated as 0x%x instead of %x\n",
752 ref, ref_offset(ref), ref_offset(ref)+ref->__totlen,
753 ret, ref->__totlen);
David Woodhouse99988f72006-05-24 09:04:17 +0100754 if (ref_next(ref)) {
755 printk(KERN_CRIT "next %p (0x%08x-0x%08x)\n", ref_next(ref), ref_offset(ref_next(ref)),
756 ref_offset(ref_next(ref))+ref->__totlen);
David Woodhouseca89a512006-05-21 13:29:11 +0100757 } else
David Woodhouse99988f72006-05-24 09:04:17 +0100758 printk(KERN_CRIT "No next ref. jeb->last_node is %p\n", jeb->last_node);
David Woodhouseca89a512006-05-21 13:29:11 +0100759
760 printk(KERN_CRIT "jeb->wasted_size %x, dirty_size %x, used_size %x, free_size %x\n", jeb->wasted_size, jeb->dirty_size, jeb->used_size, jeb->free_size);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100761
David Woodhouseca89a512006-05-21 13:29:11 +0100762#if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
763 __jffs2_dbg_dump_node_refs_nolock(c, jeb);
764#endif
David Woodhouse9bfeb692006-05-26 21:19:05 +0100765
David Woodhouseca89a512006-05-21 13:29:11 +0100766 WARN_ON(1);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100767
768 ret = ref->__totlen;
David Woodhouseca89a512006-05-21 13:29:11 +0100769 }
770#endif /* TEST_TOTLEN */
771 return ret;
772}