blob: 4bf86088b3ae397c18125fcc74e78eabaa02bea7 [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) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010035 dbg_dentlist("Eep! Marking new dirent node is 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 {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010040 dbg_dentlist("marking old dirent \"%s\", ino #%u bsolete\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;
43 jffs2_mark_node_obsolete(c, ((*prev)->raw));
44 jffs2_free_full_dirent(*prev);
45 *prev = new;
46 }
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +010047 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 }
49 prev = &((*prev)->next);
50 }
51 new->next = *prev;
52 *prev = new;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053}
54
David Woodhouse61c4b232007-04-25 17:04:23 +010055uint32_t jffs2_truncate_fragtree(struct jffs2_sb_info *c, struct rb_root *list, uint32_t size)
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010056{
57 struct jffs2_node_frag *frag = jffs2_lookup_node_frag(list, size);
58
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010059 dbg_fragtree("truncating fragtree to 0x%08x bytes\n", size);
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010060
61 /* We know frag->ofs <= size. That's what lookup does for us */
62 if (frag && frag->ofs != size) {
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010063 if (frag->ofs+frag->size > size) {
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010064 frag->size = size - frag->ofs;
65 }
66 frag = frag_next(frag);
67 }
68 while (frag && frag->ofs >= size) {
69 struct jffs2_node_frag *next = frag_next(frag);
70
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010071 frag_erase(frag, list);
72 jffs2_obsolete_node_frag(c, frag);
73 frag = next;
74 }
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010075
76 if (size == 0)
David Woodhouse61c4b232007-04-25 17:04:23 +010077 return 0;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010078
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010079 frag = frag_last(list);
David Woodhouse61c4b232007-04-25 17:04:23 +010080
81 /* Sanity check for truncation to longer than we started with... */
82 if (!frag)
83 return 0;
84 if (frag->ofs + frag->size < size)
85 return frag->ofs + frag->size;
86
87 /* If the last fragment starts at the RAM page boundary, it is
88 * REF_PRISTINE irrespective of its size. */
Artem B. Bityutskiyf0507532005-08-22 10:07:12 +010089 if (frag->node && (frag->ofs & (PAGE_CACHE_SIZE - 1)) == 0) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010090 dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n",
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000091 frag->ofs, frag->ofs + frag->size);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010092 frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE;
93 }
David Woodhouse61c4b232007-04-25 17:04:23 +010094 return size;
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010095}
96
Adrian Bunk90a18fa2006-07-06 22:37:43 +020097static void jffs2_obsolete_node_frag(struct jffs2_sb_info *c,
98 struct jffs2_node_frag *this)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100100 if (this->node) {
101 this->node->frags--;
102 if (!this->node->frags) {
103 /* The node has no valid frags left. It's totally obsoleted */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100104 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) obsolete\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100105 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100106 jffs2_mark_node_obsolete(c, this->node->raw);
107 jffs2_free_full_dnode(this->node);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100108 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100109 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 +0100110 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 +0100111 mark_ref_normal(this->node->raw);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100112 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000113
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100114 }
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100115 jffs2_free_node_frag(this);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100116}
117
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100118static void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_node_frag *base)
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100119{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100120 struct rb_node *parent = &base->rb;
121 struct rb_node **link = &parent;
122
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100123 dbg_fragtree2("insert frag (0x%04x-0x%04x)\n", newfrag->ofs, newfrag->ofs + newfrag->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100124
125 while (*link) {
126 parent = *link;
127 base = rb_entry(parent, struct jffs2_node_frag, rb);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000128
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100129 if (newfrag->ofs > base->ofs)
130 link = &base->rb.rb_right;
131 else if (newfrag->ofs < base->ofs)
132 link = &base->rb.rb_left;
133 else {
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100134 JFFS2_ERROR("duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100135 BUG();
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100136 }
137 }
138
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100139 rb_link_node(&newfrag->rb, &base->rb, link);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100140}
141
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100142/*
143 * Allocate and initializes a new fragment.
144 */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800145static 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 +0100146{
147 struct jffs2_node_frag *newfrag;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000148
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100149 newfrag = jffs2_alloc_node_frag();
150 if (likely(newfrag)) {
151 newfrag->ofs = ofs;
152 newfrag->size = size;
153 newfrag->node = fn;
154 } else {
155 JFFS2_ERROR("cannot allocate a jffs2_node_frag object\n");
156 }
157
158 return newfrag;
159}
160
161/*
162 * Called when there is no overlapping fragment exist. Inserts a hole before the new
163 * fragment and inserts the new fragment to the fragtree.
164 */
165static int no_overlapping_node(struct jffs2_sb_info *c, struct rb_root *root,
166 struct jffs2_node_frag *newfrag,
167 struct jffs2_node_frag *this, uint32_t lastend)
168{
169 if (lastend < newfrag->node->ofs) {
170 /* put a hole in before the new fragment */
171 struct jffs2_node_frag *holefrag;
172
173 holefrag= new_fragment(NULL, lastend, newfrag->node->ofs - lastend);
174 if (unlikely(!holefrag)) {
175 jffs2_free_node_frag(newfrag);
176 return -ENOMEM;
177 }
178
179 if (this) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000180 /* By definition, the 'this' node has no right-hand child,
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100181 because there are no frags with offset greater than it.
182 So that's where we want to put the hole */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100183 dbg_fragtree2("add hole frag %#04x-%#04x on the right of the new frag.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100184 holefrag->ofs, holefrag->ofs + holefrag->size);
185 rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right);
186 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100187 dbg_fragtree2("Add hole frag %#04x-%#04x to the root of the tree.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100188 holefrag->ofs, holefrag->ofs + holefrag->size);
189 rb_link_node(&holefrag->rb, NULL, &root->rb_node);
190 }
191 rb_insert_color(&holefrag->rb, root);
192 this = holefrag;
193 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000194
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100195 if (this) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000196 /* By definition, the 'this' node has no right-hand child,
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100197 because there are no frags with offset greater than it.
198 So that's where we want to put new fragment */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100199 dbg_fragtree2("add the new node at the right\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000200 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100201 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100202 dbg_fragtree2("insert the new node at the root of the tree\n");
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100203 rb_link_node(&newfrag->rb, NULL, &root->rb_node);
204 }
205 rb_insert_color(&newfrag->rb, root);
206
207 return 0;
208}
209
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100210/* Doesn't set inode->i_size */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100211static 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 -0700212{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100213 struct jffs2_node_frag *this;
214 uint32_t lastend;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100216 /* Skip all the nodes which are completed before this one starts */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100217 this = jffs2_lookup_node_frag(root, newfrag->node->ofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100219 if (this) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100220 dbg_fragtree2("lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100221 this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100222 lastend = this->ofs + this->size;
223 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100224 dbg_fragtree2("lookup gave no frag\n");
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100225 lastend = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000227
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100228 /* See if we ran off the end of the fragtree */
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100229 if (lastend <= newfrag->ofs) {
230 /* We did */
231
232 /* Check if 'this' node was on the same page as the new node.
233 If so, both 'this' and the new node get marked REF_NORMAL so
234 the GC can take a look.
235 */
236 if (lastend && (lastend-1) >> PAGE_CACHE_SHIFT == newfrag->ofs >> PAGE_CACHE_SHIFT) {
237 if (this->node)
238 mark_ref_normal(this->node->raw);
239 mark_ref_normal(newfrag->node->raw);
240 }
241
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100242 return no_overlapping_node(c, root, newfrag, this, lastend);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100243 }
244
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100245 if (this->node)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100246 dbg_fragtree2("dealing with frag %u-%u, phys %#08x(%d).\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100247 this->ofs, this->ofs + this->size,
248 ref_offset(this->node->raw), ref_flags(this->node->raw));
249 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100250 dbg_fragtree2("dealing with hole frag %u-%u.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100251 this->ofs, this->ofs + this->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100252
253 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes,
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000254 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100255 */
256 if (newfrag->ofs > this->ofs) {
257 /* This node isn't completely obsoleted. The start of it remains valid */
258
259 /* Mark the new node and the partially covered node REF_NORMAL -- let
260 the GC take a look at them */
261 mark_ref_normal(newfrag->node->raw);
262 if (this->node)
263 mark_ref_normal(this->node->raw);
264
265 if (this->ofs + this->size > newfrag->ofs + newfrag->size) {
266 /* The new node splits 'this' frag into two */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100267 struct jffs2_node_frag *newfrag2;
268
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100269 if (this->node)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100270 dbg_fragtree2("split old frag 0x%04x-0x%04x, phys 0x%08x\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100271 this->ofs, this->ofs+this->size, ref_offset(this->node->raw));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000272 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100273 dbg_fragtree2("split old hole frag 0x%04x-0x%04x\n",
Artem B. Bityutskiy8d5df402005-08-17 15:13:48 +0100274 this->ofs, this->ofs+this->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000275
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100276 /* New second frag pointing to this's node */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100277 newfrag2 = new_fragment(this->node, newfrag->ofs + newfrag->size,
278 this->ofs + this->size - newfrag->ofs - newfrag->size);
279 if (unlikely(!newfrag2))
280 return -ENOMEM;
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100281 if (this->node)
282 this->node->frags++;
283
284 /* Adjust size of original 'this' */
285 this->size = newfrag->ofs - this->ofs;
286
287 /* Now, we know there's no node with offset
288 greater than this->ofs but smaller than
289 newfrag2->ofs or newfrag->ofs, for obvious
290 reasons. So we can do a tree insert from
291 'this' to insert newfrag, and a tree insert
292 from newfrag to insert newfrag2. */
293 jffs2_fragtree_insert(newfrag, this);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100294 rb_insert_color(&newfrag->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000295
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100296 jffs2_fragtree_insert(newfrag2, newfrag);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100297 rb_insert_color(&newfrag2->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000298
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100299 return 0;
300 }
301 /* New node just reduces 'this' frag in size, doesn't split it */
302 this->size = newfrag->ofs - this->ofs;
303
304 /* Again, we know it lives down here in the tree */
305 jffs2_fragtree_insert(newfrag, this);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100306 rb_insert_color(&newfrag->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100307 } else {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000308 /* New frag starts at the same point as 'this' used to. Replace
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100309 it in the tree without doing a delete and insertion */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100310 dbg_fragtree2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100311 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000312
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100313 rb_replace_node(&this->rb, &newfrag->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000314
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100315 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100316 dbg_fragtree2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100317 jffs2_obsolete_node_frag(c, this);
318 } else {
319 this->ofs += newfrag->size;
320 this->size -= newfrag->size;
321
322 jffs2_fragtree_insert(this, newfrag);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100323 rb_insert_color(&this->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100324 return 0;
325 }
326 }
327 /* OK, now we have newfrag added in the correct place in the tree, but
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000328 frag_next(newfrag) may be a fragment which is overlapped by it
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100329 */
330 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) {
331 /* 'this' frag is obsoleted completely. */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100332 dbg_fragtree2("obsoleting node frag %p (%x-%x) and removing from tree\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100333 this, this->ofs, this->ofs+this->size);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100334 rb_erase(&this->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100335 jffs2_obsolete_node_frag(c, this);
336 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000337 /* Now we're pointing at the first frag which isn't totally obsoleted by
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100338 the new frag */
339
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100340 if (!this || newfrag->ofs + newfrag->size == this->ofs)
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100341 return 0;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100342
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100343 /* Still some overlap but we don't need to move it in the tree */
344 this->size = (this->ofs + this->size) - (newfrag->ofs + newfrag->size);
345 this->ofs = newfrag->ofs + newfrag->size;
346
347 /* And mark them REF_NORMAL so the GC takes a look at them */
348 if (this->node)
349 mark_ref_normal(this->node->raw);
350 mark_ref_normal(newfrag->node->raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
352 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353}
354
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000355/*
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100356 * Given an inode, probably with existing tree of fragments, add the new node
357 * to the fragment tree.
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100358 */
359int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn)
360{
361 int ret;
362 struct jffs2_node_frag *newfrag;
363
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100364 if (unlikely(!fn->size))
365 return 0;
366
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100367 newfrag = new_fragment(fn, fn->ofs, fn->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100368 if (unlikely(!newfrag))
369 return -ENOMEM;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100370 newfrag->node->frags = 1;
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100371
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100372 dbg_fragtree("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100373 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000374
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100375 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag);
376 if (unlikely(ret))
377 return ret;
378
379 /* If we now share a page with other nodes, mark either previous
380 or next node REF_NORMAL, as appropriate. */
381 if (newfrag->ofs & (PAGE_CACHE_SIZE-1)) {
382 struct jffs2_node_frag *prev = frag_prev(newfrag);
383
384 mark_ref_normal(fn->raw);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000385 /* If we don't start at zero there's _always_ a previous */
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100386 if (prev->node)
387 mark_ref_normal(prev->node->raw);
388 }
389
390 if ((newfrag->ofs+newfrag->size) & (PAGE_CACHE_SIZE-1)) {
391 struct jffs2_node_frag *next = frag_next(newfrag);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000392
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100393 if (next) {
394 mark_ref_normal(fn->raw);
395 if (next->node)
396 mark_ref_normal(next->node->raw);
397 }
398 }
399 jffs2_dbg_fragtree_paranoia_check_nolock(f);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100400
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100401 return 0;
402}
403
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state)
405{
406 spin_lock(&c->inocache_lock);
407 ic->state = state;
408 wake_up(&c->inocache_wq);
409 spin_unlock(&c->inocache_lock);
410}
411
412/* During mount, this needs no locking. During normal operation, its
413 callers want to do other stuff while still holding the inocache_lock.
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000414 Rather than introducing special case get_ino_cache functions or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 callbacks, we just let the caller do the locking itself. */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino)
418{
419 struct jffs2_inode_cache *ret;
420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 ret = c->inocache_list[ino % INOCACHE_HASHSIZE];
422 while (ret && ret->ino < ino) {
423 ret = ret->next;
424 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000425
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 if (ret && ret->ino != ino)
427 ret = NULL;
428
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 return ret;
430}
431
432void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new)
433{
434 struct jffs2_inode_cache **prev;
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 spin_lock(&c->inocache_lock);
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200437 if (!new->ino)
438 new->ino = ++c->highest_ino;
439
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100440 dbg_inocache("add %p (ino #%u)\n", new, new->ino);
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 prev = &c->inocache_list[new->ino % INOCACHE_HASHSIZE];
443
444 while ((*prev) && (*prev)->ino < new->ino) {
445 prev = &(*prev)->next;
446 }
447 new->next = *prev;
448 *prev = new;
449
450 spin_unlock(&c->inocache_lock);
451}
452
453void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
454{
455 struct jffs2_inode_cache **prev;
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100456
KaiGai Kohei355ed4e2006-06-24 09:15:36 +0900457#ifdef CONFIG_JFFS2_FS_XATTR
458 BUG_ON(old->xref);
459#endif
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100460 dbg_inocache("del %p (ino #%u)\n", old, old->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 spin_lock(&c->inocache_lock);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000462
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE];
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 while ((*prev) && (*prev)->ino < old->ino) {
466 prev = &(*prev)->next;
467 }
468 if ((*prev) == old) {
469 *prev = old->next;
470 }
471
David Woodhouse67e345d2005-02-27 23:01:36 +0000472 /* Free it now unless it's in READING or CLEARING state, which
473 are the transitions upon read_inode() and clear_inode(). The
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000474 rest of the time we know nobody else is looking at it, and
David Woodhouse67e345d2005-02-27 23:01:36 +0000475 if it's held by read_inode() or clear_inode() they'll free it
476 for themselves. */
477 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING)
478 jffs2_free_inode_cache(old);
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 spin_unlock(&c->inocache_lock);
481}
482
483void jffs2_free_ino_caches(struct jffs2_sb_info *c)
484{
485 int i;
486 struct jffs2_inode_cache *this, *next;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 for (i=0; i<INOCACHE_HASHSIZE; i++) {
489 this = c->inocache_list[i];
490 while (this) {
491 next = this->next;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900492 jffs2_xattr_free_inode(c, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 jffs2_free_inode_cache(this);
494 this = next;
495 }
496 c->inocache_list[i] = NULL;
497 }
498}
499
500void jffs2_free_raw_node_refs(struct jffs2_sb_info *c)
501{
502 int i;
503 struct jffs2_raw_node_ref *this, *next;
504
505 for (i=0; i<c->nr_blocks; i++) {
506 this = c->blocks[i].first_node;
David Woodhouse2f785402006-05-24 02:04:45 +0100507 while (this) {
David Woodhouse9bfeb692006-05-26 21:19:05 +0100508 if (this[REFS_PER_BLOCK].flash_offset == REF_LINK_NODE)
509 next = this[REFS_PER_BLOCK].next_in_ino;
510 else
511 next = NULL;
512
513 jffs2_free_refblock(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 this = next;
515 }
516 c->blocks[i].first_node = c->blocks[i].last_node = NULL;
517 }
518}
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset)
521{
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000522 /* The common case in lookup is that there will be a node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 which precisely matches. So we go looking for that first */
524 struct rb_node *next;
525 struct jffs2_node_frag *prev = NULL;
526 struct jffs2_node_frag *frag = NULL;
527
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100528 dbg_fragtree2("root %p, offset %d\n", fragtree, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
530 next = fragtree->rb_node;
531
532 while(next) {
533 frag = rb_entry(next, struct jffs2_node_frag, rb);
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 if (frag->ofs + frag->size <= offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 /* Remember the closest smaller match on the way down */
537 if (!prev || frag->ofs > prev->ofs)
538 prev = frag;
539 next = frag->rb.rb_right;
540 } else if (frag->ofs > offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 next = frag->rb.rb_left;
542 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return frag;
544 }
545 }
546
547 /* Exact match not found. Go back up looking at each parent,
548 and return the closest smaller one */
549
550 if (prev)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100551 dbg_fragtree2("no match. Returning frag %#04x-%#04x, closest previous\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100552 prev->ofs, prev->ofs+prev->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000553 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100554 dbg_fragtree2("returning NULL, empty fragtree\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 return prev;
557}
558
559/* Pass 'c' argument to indicate that nodes should be marked obsolete as
560 they're killed. */
561void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
562{
563 struct jffs2_node_frag *frag;
564 struct jffs2_node_frag *parent;
565
566 if (!root->rb_node)
567 return;
568
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100569 dbg_fragtree("killing\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 while(frag) {
573 if (frag->rb.rb_left) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 frag = frag_left(frag);
575 continue;
576 }
577 if (frag->rb.rb_right) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 frag = frag_right(frag);
579 continue;
580 }
581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 if (frag->node && !(--frag->node->frags)) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000583 /* Not a hole, and it's the final remaining frag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 of this node. Free the node */
585 if (c)
586 jffs2_mark_node_obsolete(c, frag->node->raw);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000587
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588 jffs2_free_full_dnode(frag->node);
589 }
590 parent = frag_parent(frag);
591 if (parent) {
592 if (frag_left(parent) == frag)
593 parent->rb.rb_left = NULL;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000594 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 parent->rb.rb_right = NULL;
596 }
597
598 jffs2_free_node_frag(frag);
599 frag = parent;
600
601 cond_resched();
602 }
603}
David Woodhousef1f96712006-05-20 19:45:26 +0100604
David Woodhouse2f785402006-05-24 02:04:45 +0100605struct jffs2_raw_node_ref *jffs2_link_node_ref(struct jffs2_sb_info *c,
606 struct jffs2_eraseblock *jeb,
607 uint32_t ofs, uint32_t len,
608 struct jffs2_inode_cache *ic)
David Woodhousef1f96712006-05-20 19:45:26 +0100609{
David Woodhouse2f785402006-05-24 02:04:45 +0100610 struct jffs2_raw_node_ref *ref;
611
David Woodhouse9bfeb692006-05-26 21:19:05 +0100612 BUG_ON(!jeb->allocated_refs);
613 jeb->allocated_refs--;
614
615 ref = jeb->last_node;
616
617 dbg_noderef("Last node at %p is (%08x,%p)\n", ref, ref->flash_offset,
618 ref->next_in_ino);
619
620 while (ref->flash_offset != REF_EMPTY_NODE) {
621 if (ref->flash_offset == REF_LINK_NODE)
622 ref = ref->next_in_ino;
623 else
624 ref++;
David Woodhouse2f785402006-05-24 02:04:45 +0100625 }
626
David Woodhouse9bfeb692006-05-26 21:19:05 +0100627 dbg_noderef("New ref is %p (%08x becomes %08x,%p) len 0x%x\n", ref,
628 ref->flash_offset, ofs, ref->next_in_ino, len);
629
David Woodhouse2f785402006-05-24 02:04:45 +0100630 ref->flash_offset = ofs;
631
David Woodhouse9bfeb692006-05-26 21:19:05 +0100632 if (!jeb->first_node) {
David Woodhousef1f96712006-05-20 19:45:26 +0100633 jeb->first_node = ref;
David Woodhouse9bfeb692006-05-26 21:19:05 +0100634 BUG_ON(ref_offset(ref) != jeb->offset);
635 } else if (unlikely(ref_offset(ref) != jeb->offset + c->sector_size - jeb->free_size)) {
636 uint32_t last_len = ref_totlen(c, jeb, jeb->last_node);
637
638 JFFS2_ERROR("Adding new ref %p at (0x%08x-0x%08x) not immediately after previous (0x%08x-0x%08x)\n",
639 ref, ref_offset(ref), ref_offset(ref)+len,
640 ref_offset(jeb->last_node),
641 ref_offset(jeb->last_node)+last_len);
642 BUG();
David Woodhouseca89a512006-05-21 13:29:11 +0100643 }
David Woodhousef1f96712006-05-20 19:45:26 +0100644 jeb->last_node = ref;
645
David Woodhousefcb75782006-05-22 15:23:10 +0100646 if (ic) {
647 ref->next_in_ino = ic->nodes;
648 ic->nodes = ref;
649 } else {
650 ref->next_in_ino = NULL;
651 }
652
David Woodhousef1f96712006-05-20 19:45:26 +0100653 switch(ref_flags(ref)) {
654 case REF_UNCHECKED:
655 c->unchecked_size += len;
656 jeb->unchecked_size += len;
657 break;
658
659 case REF_NORMAL:
660 case REF_PRISTINE:
661 c->used_size += len;
662 jeb->used_size += len;
663 break;
664
665 case REF_OBSOLETE:
666 c->dirty_size += len;
David Woodhouse3b796732006-05-22 12:15:47 +0100667 jeb->dirty_size += len;
David Woodhousef1f96712006-05-20 19:45:26 +0100668 break;
669 }
670 c->free_size -= len;
671 jeb->free_size -= len;
672
David Woodhouseca89a512006-05-21 13:29:11 +0100673#ifdef TEST_TOTLEN
674 /* Set (and test) __totlen field... for now */
675 ref->__totlen = len;
676 ref_totlen(c, jeb, ref);
677#endif
David Woodhouse2f785402006-05-24 02:04:45 +0100678 return ref;
David Woodhousef1f96712006-05-20 19:45:26 +0100679}
David Woodhouse68270992006-05-21 03:46:05 +0100680
David Woodhouse2f785402006-05-24 02:04:45 +0100681/* No locking, no reservation of 'ref'. Do not use on a live file system */
David Woodhouse68270992006-05-21 03:46:05 +0100682int jffs2_scan_dirty_space(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
683 uint32_t size)
684{
David Woodhouseca89a512006-05-21 13:29:11 +0100685 if (!size)
686 return 0;
David Woodhouse9bfeb692006-05-26 21:19:05 +0100687 if (unlikely(size > jeb->free_size)) {
688 printk(KERN_CRIT "Dirty space 0x%x larger then free_size 0x%x (wasted 0x%x)\n",
689 size, jeb->free_size, jeb->wasted_size);
David Woodhouseca89a512006-05-21 13:29:11 +0100690 BUG();
691 }
David Woodhouse9bfeb692006-05-26 21:19:05 +0100692 /* REF_EMPTY_NODE is !obsolete, so that works OK */
David Woodhouse2ebf09c2006-05-28 22:13:25 +0100693 if (jeb->last_node && ref_obsolete(jeb->last_node)) {
David Woodhouseca89a512006-05-21 13:29:11 +0100694#ifdef TEST_TOTLEN
695 jeb->last_node->__totlen += size;
696#endif
697 c->dirty_size += size;
698 c->free_size -= size;
699 jeb->dirty_size += size;
700 jeb->free_size -= size;
701 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100702 uint32_t ofs = jeb->offset + c->sector_size - jeb->free_size;
703 ofs |= REF_OBSOLETE;
David Woodhouseca89a512006-05-21 13:29:11 +0100704
David Woodhouse2f785402006-05-24 02:04:45 +0100705 jffs2_link_node_ref(c, jeb, ofs, size, NULL);
David Woodhouseca89a512006-05-21 13:29:11 +0100706 }
David Woodhouse68270992006-05-21 03:46:05 +0100707
708 return 0;
709}
David Woodhouseca89a512006-05-21 13:29:11 +0100710
711/* Calculate totlen from surrounding nodes or eraseblock */
712static inline uint32_t __ref_totlen(struct jffs2_sb_info *c,
713 struct jffs2_eraseblock *jeb,
714 struct jffs2_raw_node_ref *ref)
715{
716 uint32_t ref_end;
David Woodhouse99988f72006-05-24 09:04:17 +0100717 struct jffs2_raw_node_ref *next_ref = ref_next(ref);
David Woodhouseca89a512006-05-21 13:29:11 +0100718
David Woodhouse99988f72006-05-24 09:04:17 +0100719 if (next_ref)
720 ref_end = ref_offset(next_ref);
David Woodhouseca89a512006-05-21 13:29:11 +0100721 else {
722 if (!jeb)
723 jeb = &c->blocks[ref->flash_offset / c->sector_size];
724
725 /* Last node in block. Use free_space */
David Woodhouse9bfeb692006-05-26 21:19:05 +0100726 if (unlikely(ref != jeb->last_node)) {
David Woodhouseca89a512006-05-21 13:29:11 +0100727 printk(KERN_CRIT "ref %p @0x%08x is not jeb->last_node (%p @0x%08x)\n",
728 ref, ref_offset(ref), jeb->last_node, jeb->last_node?ref_offset(jeb->last_node):0);
729 BUG();
730 }
731 ref_end = jeb->offset + c->sector_size - jeb->free_size;
732 }
733 return ref_end - ref_offset(ref);
734}
735
736uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
737 struct jffs2_raw_node_ref *ref)
738{
739 uint32_t ret;
740
David Woodhouseca89a512006-05-21 13:29:11 +0100741 ret = __ref_totlen(c, jeb, ref);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100742
David Woodhouseca89a512006-05-21 13:29:11 +0100743#ifdef TEST_TOTLEN
David Woodhouse9bfeb692006-05-26 21:19:05 +0100744 if (unlikely(ret != ref->__totlen)) {
745 if (!jeb)
746 jeb = &c->blocks[ref->flash_offset / c->sector_size];
747
David Woodhouseca89a512006-05-21 13:29:11 +0100748 printk(KERN_CRIT "Totlen for ref at %p (0x%08x-0x%08x) miscalculated as 0x%x instead of %x\n",
749 ref, ref_offset(ref), ref_offset(ref)+ref->__totlen,
750 ret, ref->__totlen);
David Woodhouse99988f72006-05-24 09:04:17 +0100751 if (ref_next(ref)) {
752 printk(KERN_CRIT "next %p (0x%08x-0x%08x)\n", ref_next(ref), ref_offset(ref_next(ref)),
753 ref_offset(ref_next(ref))+ref->__totlen);
David Woodhouseca89a512006-05-21 13:29:11 +0100754 } else
David Woodhouse99988f72006-05-24 09:04:17 +0100755 printk(KERN_CRIT "No next ref. jeb->last_node is %p\n", jeb->last_node);
David Woodhouseca89a512006-05-21 13:29:11 +0100756
757 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 +0100758
David Woodhouseca89a512006-05-21 13:29:11 +0100759#if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
760 __jffs2_dbg_dump_node_refs_nolock(c, jeb);
761#endif
David Woodhouse9bfeb692006-05-26 21:19:05 +0100762
David Woodhouseca89a512006-05-21 13:29:11 +0100763 WARN_ON(1);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100764
765 ret = ref->__totlen;
David Woodhouseca89a512006-05-21 13:29:11 +0100766 }
767#endif /* TEST_TOTLEN */
768 return ret;
769}