blob: b86c78d178c60a3af10f6ae4c688d6acce8f8dbf [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
Joe Perches5a528952012-02-15 15:56:45 -080012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel.h>
15#include <linux/sched.h>
16#include <linux/fs.h>
17#include <linux/mtd/mtd.h>
18#include <linux/rbtree.h>
19#include <linux/crc32.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/pagemap.h>
21#include "nodelist.h"
22
Adrian Bunk90a18fa2006-07-06 22:37:43 +020023static void jffs2_obsolete_node_frag(struct jffs2_sb_info *c,
24 struct jffs2_node_frag *this);
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list)
27{
28 struct jffs2_full_dirent **prev = list;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000029
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010030 dbg_dentlist("add dirent \"%s\", ino #%u\n", new->name, new->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32 while ((*prev) && (*prev)->nhash <= new->nhash) {
33 if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) {
34 /* Duplicate. Free one */
35 if (new->version < (*prev)->version) {
David Woodhouse15953582007-11-01 16:25:56 -040036 dbg_dentlist("Eep! Marking new dirent node obsolete, old is \"%s\", ino #%u\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +010037 (*prev)->name, (*prev)->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 jffs2_mark_node_obsolete(c, new->raw);
39 jffs2_free_full_dirent(new);
40 } else {
David Woodhouse15953582007-11-01 16:25:56 -040041 dbg_dentlist("marking old dirent \"%s\", ino #%u obsolete\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +010042 (*prev)->name, (*prev)->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 new->next = (*prev)->next;
David Woodhouse15953582007-11-01 16:25:56 -040044 /* It may have been a 'placeholder' deletion dirent,
45 if jffs2_can_mark_obsolete() (see jffs2_do_unlink()) */
46 if ((*prev)->raw)
47 jffs2_mark_node_obsolete(c, ((*prev)->raw));
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 jffs2_free_full_dirent(*prev);
49 *prev = new;
50 }
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +010051 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 }
53 prev = &((*prev)->next);
54 }
55 new->next = *prev;
56 *prev = new;
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
David Woodhouse61c4b232007-04-25 17:04:23 +010059uint32_t jffs2_truncate_fragtree(struct jffs2_sb_info *c, struct rb_root *list, uint32_t size)
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010060{
61 struct jffs2_node_frag *frag = jffs2_lookup_node_frag(list, size);
62
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010063 dbg_fragtree("truncating fragtree to 0x%08x bytes\n", size);
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010064
65 /* We know frag->ofs <= size. That's what lookup does for us */
66 if (frag && frag->ofs != size) {
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010067 if (frag->ofs+frag->size > size) {
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010068 frag->size = size - frag->ofs;
69 }
70 frag = frag_next(frag);
71 }
72 while (frag && frag->ofs >= size) {
73 struct jffs2_node_frag *next = frag_next(frag);
74
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010075 frag_erase(frag, list);
76 jffs2_obsolete_node_frag(c, frag);
77 frag = next;
78 }
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010079
80 if (size == 0)
David Woodhouse61c4b232007-04-25 17:04:23 +010081 return 0;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010082
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010083 frag = frag_last(list);
David Woodhouse61c4b232007-04-25 17:04:23 +010084
85 /* Sanity check for truncation to longer than we started with... */
86 if (!frag)
87 return 0;
88 if (frag->ofs + frag->size < size)
89 return frag->ofs + frag->size;
90
91 /* If the last fragment starts at the RAM page boundary, it is
92 * REF_PRISTINE irrespective of its size. */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +030093 if (frag->node && (frag->ofs & (PAGE_SIZE - 1)) == 0) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010094 dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n",
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000095 frag->ofs, frag->ofs + frag->size);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010096 frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE;
97 }
David Woodhouse61c4b232007-04-25 17:04:23 +010098 return size;
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010099}
100
Adrian Bunk90a18fa2006-07-06 22:37:43 +0200101static void jffs2_obsolete_node_frag(struct jffs2_sb_info *c,
102 struct jffs2_node_frag *this)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100104 if (this->node) {
105 this->node->frags--;
106 if (!this->node->frags) {
107 /* The node has no valid frags left. It's totally obsoleted */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100108 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) obsolete\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100109 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100110 jffs2_mark_node_obsolete(c, this->node->raw);
111 jffs2_free_full_dnode(this->node);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100112 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100113 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 +0100114 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 +0100115 mark_ref_normal(this->node->raw);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100116 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000117
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100118 }
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100119 jffs2_free_node_frag(this);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100120}
121
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100122static void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_node_frag *base)
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100123{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100124 struct rb_node *parent = &base->rb;
125 struct rb_node **link = &parent;
126
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100127 dbg_fragtree2("insert frag (0x%04x-0x%04x)\n", newfrag->ofs, newfrag->ofs + newfrag->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100128
129 while (*link) {
130 parent = *link;
131 base = rb_entry(parent, struct jffs2_node_frag, rb);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000132
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100133 if (newfrag->ofs > base->ofs)
134 link = &base->rb.rb_right;
135 else if (newfrag->ofs < base->ofs)
136 link = &base->rb.rb_left;
137 else {
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100138 JFFS2_ERROR("duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100139 BUG();
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100140 }
141 }
142
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100143 rb_link_node(&newfrag->rb, &base->rb, link);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100144}
145
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100146/*
147 * Allocate and initializes a new fragment.
148 */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800149static 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 +0100150{
151 struct jffs2_node_frag *newfrag;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000152
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100153 newfrag = jffs2_alloc_node_frag();
154 if (likely(newfrag)) {
155 newfrag->ofs = ofs;
156 newfrag->size = size;
157 newfrag->node = fn;
158 } else {
159 JFFS2_ERROR("cannot allocate a jffs2_node_frag object\n");
160 }
161
162 return newfrag;
163}
164
165/*
166 * Called when there is no overlapping fragment exist. Inserts a hole before the new
167 * fragment and inserts the new fragment to the fragtree.
168 */
169static int no_overlapping_node(struct jffs2_sb_info *c, struct rb_root *root,
170 struct jffs2_node_frag *newfrag,
171 struct jffs2_node_frag *this, uint32_t lastend)
172{
173 if (lastend < newfrag->node->ofs) {
174 /* put a hole in before the new fragment */
175 struct jffs2_node_frag *holefrag;
176
177 holefrag= new_fragment(NULL, lastend, newfrag->node->ofs - lastend);
178 if (unlikely(!holefrag)) {
179 jffs2_free_node_frag(newfrag);
180 return -ENOMEM;
181 }
182
183 if (this) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000184 /* By definition, the 'this' node has no right-hand child,
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100185 because there are no frags with offset greater than it.
186 So that's where we want to put the hole */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100187 dbg_fragtree2("add hole frag %#04x-%#04x on the right of the new frag.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100188 holefrag->ofs, holefrag->ofs + holefrag->size);
189 rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right);
190 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100191 dbg_fragtree2("Add hole frag %#04x-%#04x to the root of the tree.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100192 holefrag->ofs, holefrag->ofs + holefrag->size);
193 rb_link_node(&holefrag->rb, NULL, &root->rb_node);
194 }
195 rb_insert_color(&holefrag->rb, root);
196 this = holefrag;
197 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000198
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100199 if (this) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000200 /* By definition, the 'this' node has no right-hand child,
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100201 because there are no frags with offset greater than it.
202 So that's where we want to put new fragment */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100203 dbg_fragtree2("add the new node at the right\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000204 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100205 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100206 dbg_fragtree2("insert the new node at the root of the tree\n");
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100207 rb_link_node(&newfrag->rb, NULL, &root->rb_node);
208 }
209 rb_insert_color(&newfrag->rb, root);
210
211 return 0;
212}
213
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100214/* Doesn't set inode->i_size */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100215static 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 -0700216{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100217 struct jffs2_node_frag *this;
218 uint32_t lastend;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100220 /* Skip all the nodes which are completed before this one starts */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100221 this = jffs2_lookup_node_frag(root, newfrag->node->ofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100223 if (this) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100224 dbg_fragtree2("lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100225 this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100226 lastend = this->ofs + this->size;
227 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100228 dbg_fragtree2("lookup gave no frag\n");
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100229 lastend = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000231
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100232 /* See if we ran off the end of the fragtree */
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100233 if (lastend <= newfrag->ofs) {
234 /* We did */
235
236 /* Check if 'this' node was on the same page as the new node.
237 If so, both 'this' and the new node get marked REF_NORMAL so
238 the GC can take a look.
239 */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300240 if (lastend && (lastend-1) >> PAGE_SHIFT == newfrag->ofs >> PAGE_SHIFT) {
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100241 if (this->node)
242 mark_ref_normal(this->node->raw);
243 mark_ref_normal(newfrag->node->raw);
244 }
245
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100246 return no_overlapping_node(c, root, newfrag, this, lastend);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100247 }
248
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100249 if (this->node)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100250 dbg_fragtree2("dealing with frag %u-%u, phys %#08x(%d).\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100251 this->ofs, this->ofs + this->size,
252 ref_offset(this->node->raw), ref_flags(this->node->raw));
253 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100254 dbg_fragtree2("dealing with hole frag %u-%u.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100255 this->ofs, this->ofs + this->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100256
257 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes,
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000258 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100259 */
260 if (newfrag->ofs > this->ofs) {
261 /* This node isn't completely obsoleted. The start of it remains valid */
262
263 /* Mark the new node and the partially covered node REF_NORMAL -- let
264 the GC take a look at them */
265 mark_ref_normal(newfrag->node->raw);
266 if (this->node)
267 mark_ref_normal(this->node->raw);
268
269 if (this->ofs + this->size > newfrag->ofs + newfrag->size) {
270 /* The new node splits 'this' frag into two */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100271 struct jffs2_node_frag *newfrag2;
272
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100273 if (this->node)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100274 dbg_fragtree2("split old frag 0x%04x-0x%04x, phys 0x%08x\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100275 this->ofs, this->ofs+this->size, ref_offset(this->node->raw));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000276 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100277 dbg_fragtree2("split old hole frag 0x%04x-0x%04x\n",
Artem B. Bityutskiy8d5df402005-08-17 15:13:48 +0100278 this->ofs, this->ofs+this->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000279
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100280 /* New second frag pointing to this's node */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100281 newfrag2 = new_fragment(this->node, newfrag->ofs + newfrag->size,
282 this->ofs + this->size - newfrag->ofs - newfrag->size);
283 if (unlikely(!newfrag2))
284 return -ENOMEM;
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100285 if (this->node)
286 this->node->frags++;
287
288 /* Adjust size of original 'this' */
289 this->size = newfrag->ofs - this->ofs;
290
291 /* Now, we know there's no node with offset
292 greater than this->ofs but smaller than
293 newfrag2->ofs or newfrag->ofs, for obvious
294 reasons. So we can do a tree insert from
295 'this' to insert newfrag, and a tree insert
296 from newfrag to insert newfrag2. */
297 jffs2_fragtree_insert(newfrag, this);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100298 rb_insert_color(&newfrag->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000299
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100300 jffs2_fragtree_insert(newfrag2, newfrag);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100301 rb_insert_color(&newfrag2->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000302
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100303 return 0;
304 }
305 /* New node just reduces 'this' frag in size, doesn't split it */
306 this->size = newfrag->ofs - this->ofs;
307
308 /* Again, we know it lives down here in the tree */
309 jffs2_fragtree_insert(newfrag, this);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100310 rb_insert_color(&newfrag->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100311 } else {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000312 /* New frag starts at the same point as 'this' used to. Replace
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100313 it in the tree without doing a delete and insertion */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100314 dbg_fragtree2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100315 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000316
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100317 rb_replace_node(&this->rb, &newfrag->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000318
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100319 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100320 dbg_fragtree2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100321 jffs2_obsolete_node_frag(c, this);
322 } else {
323 this->ofs += newfrag->size;
324 this->size -= newfrag->size;
325
326 jffs2_fragtree_insert(this, newfrag);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100327 rb_insert_color(&this->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100328 return 0;
329 }
330 }
331 /* OK, now we have newfrag added in the correct place in the tree, but
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000332 frag_next(newfrag) may be a fragment which is overlapped by it
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100333 */
334 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) {
335 /* 'this' frag is obsoleted completely. */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100336 dbg_fragtree2("obsoleting node frag %p (%x-%x) and removing from tree\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100337 this, this->ofs, this->ofs+this->size);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100338 rb_erase(&this->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100339 jffs2_obsolete_node_frag(c, this);
340 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000341 /* Now we're pointing at the first frag which isn't totally obsoleted by
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100342 the new frag */
343
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100344 if (!this || newfrag->ofs + newfrag->size == this->ofs)
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100345 return 0;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100346
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100347 /* Still some overlap but we don't need to move it in the tree */
348 this->size = (this->ofs + this->size) - (newfrag->ofs + newfrag->size);
349 this->ofs = newfrag->ofs + newfrag->size;
350
351 /* And mark them REF_NORMAL so the GC takes a look at them */
352 if (this->node)
353 mark_ref_normal(this->node->raw);
354 mark_ref_normal(newfrag->node->raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
356 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000359/*
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100360 * Given an inode, probably with existing tree of fragments, add the new node
361 * to the fragment tree.
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100362 */
363int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn)
364{
365 int ret;
366 struct jffs2_node_frag *newfrag;
367
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100368 if (unlikely(!fn->size))
369 return 0;
370
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100371 newfrag = new_fragment(fn, fn->ofs, fn->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100372 if (unlikely(!newfrag))
373 return -ENOMEM;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100374 newfrag->node->frags = 1;
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100375
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100376 dbg_fragtree("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100377 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000378
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100379 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag);
380 if (unlikely(ret))
381 return ret;
382
383 /* If we now share a page with other nodes, mark either previous
384 or next node REF_NORMAL, as appropriate. */
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300385 if (newfrag->ofs & (PAGE_SIZE-1)) {
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100386 struct jffs2_node_frag *prev = frag_prev(newfrag);
387
388 mark_ref_normal(fn->raw);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000389 /* If we don't start at zero there's _always_ a previous */
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100390 if (prev->node)
391 mark_ref_normal(prev->node->raw);
392 }
393
Kirill A. Shutemov09cbfea2016-04-01 15:29:47 +0300394 if ((newfrag->ofs+newfrag->size) & (PAGE_SIZE-1)) {
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100395 struct jffs2_node_frag *next = frag_next(newfrag);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000396
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100397 if (next) {
398 mark_ref_normal(fn->raw);
399 if (next->node)
400 mark_ref_normal(next->node->raw);
401 }
402 }
403 jffs2_dbg_fragtree_paranoia_check_nolock(f);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100404
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100405 return 0;
406}
407
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state)
409{
410 spin_lock(&c->inocache_lock);
411 ic->state = state;
412 wake_up(&c->inocache_wq);
413 spin_unlock(&c->inocache_lock);
414}
415
416/* During mount, this needs no locking. During normal operation, its
417 callers want to do other stuff while still holding the inocache_lock.
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000418 Rather than introducing special case get_ino_cache functions or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 callbacks, we just let the caller do the locking itself. */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino)
422{
423 struct jffs2_inode_cache *ret;
424
Daniel Drake65e5a0e2010-10-07 19:14:02 +0100425 ret = c->inocache_list[ino % c->inocache_hashsize];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 while (ret && ret->ino < ino) {
427 ret = ret->next;
428 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 if (ret && ret->ino != ino)
431 ret = NULL;
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 return ret;
434}
435
436void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new)
437{
438 struct jffs2_inode_cache **prev;
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 spin_lock(&c->inocache_lock);
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200441 if (!new->ino)
442 new->ino = ++c->highest_ino;
443
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100444 dbg_inocache("add %p (ino #%u)\n", new, new->ino);
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200445
Daniel Drake65e5a0e2010-10-07 19:14:02 +0100446 prev = &c->inocache_list[new->ino % c->inocache_hashsize];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 while ((*prev) && (*prev)->ino < new->ino) {
449 prev = &(*prev)->next;
450 }
451 new->next = *prev;
452 *prev = new;
453
454 spin_unlock(&c->inocache_lock);
455}
456
457void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
458{
459 struct jffs2_inode_cache **prev;
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100460
KaiGai Kohei355ed4e2006-06-24 09:15:36 +0900461#ifdef CONFIG_JFFS2_FS_XATTR
462 BUG_ON(old->xref);
463#endif
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100464 dbg_inocache("del %p (ino #%u)\n", old, old->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 spin_lock(&c->inocache_lock);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000466
Daniel Drake65e5a0e2010-10-07 19:14:02 +0100467 prev = &c->inocache_list[old->ino % c->inocache_hashsize];
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 while ((*prev) && (*prev)->ino < old->ino) {
470 prev = &(*prev)->next;
471 }
472 if ((*prev) == old) {
473 *prev = old->next;
474 }
475
David Woodhouse67e345d2005-02-27 23:01:36 +0000476 /* Free it now unless it's in READING or CLEARING state, which
477 are the transitions upon read_inode() and clear_inode(). The
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000478 rest of the time we know nobody else is looking at it, and
David Woodhouse67e345d2005-02-27 23:01:36 +0000479 if it's held by read_inode() or clear_inode() they'll free it
480 for themselves. */
481 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING)
482 jffs2_free_inode_cache(old);
483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484 spin_unlock(&c->inocache_lock);
485}
486
487void jffs2_free_ino_caches(struct jffs2_sb_info *c)
488{
489 int i;
490 struct jffs2_inode_cache *this, *next;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000491
Daniel Drake65e5a0e2010-10-07 19:14:02 +0100492 for (i=0; i < c->inocache_hashsize; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 this = c->inocache_list[i];
494 while (this) {
495 next = this->next;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900496 jffs2_xattr_free_inode(c, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 jffs2_free_inode_cache(this);
498 this = next;
499 }
500 c->inocache_list[i] = NULL;
501 }
502}
503
504void jffs2_free_raw_node_refs(struct jffs2_sb_info *c)
505{
506 int i;
507 struct jffs2_raw_node_ref *this, *next;
508
509 for (i=0; i<c->nr_blocks; i++) {
510 this = c->blocks[i].first_node;
David Woodhouse2f785402006-05-24 02:04:45 +0100511 while (this) {
David Woodhouse9bfeb692006-05-26 21:19:05 +0100512 if (this[REFS_PER_BLOCK].flash_offset == REF_LINK_NODE)
513 next = this[REFS_PER_BLOCK].next_in_ino;
514 else
515 next = NULL;
516
517 jffs2_free_refblock(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 this = next;
519 }
520 c->blocks[i].first_node = c->blocks[i].last_node = NULL;
521 }
522}
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset)
525{
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000526 /* The common case in lookup is that there will be a node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 which precisely matches. So we go looking for that first */
528 struct rb_node *next;
529 struct jffs2_node_frag *prev = NULL;
530 struct jffs2_node_frag *frag = NULL;
531
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100532 dbg_fragtree2("root %p, offset %d\n", fragtree, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
534 next = fragtree->rb_node;
535
536 while(next) {
537 frag = rb_entry(next, struct jffs2_node_frag, rb);
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 if (frag->ofs + frag->size <= offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 /* Remember the closest smaller match on the way down */
541 if (!prev || frag->ofs > prev->ofs)
542 prev = frag;
543 next = frag->rb.rb_right;
544 } else if (frag->ofs > offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 next = frag->rb.rb_left;
546 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 return frag;
548 }
549 }
550
551 /* Exact match not found. Go back up looking at each parent,
552 and return the closest smaller one */
553
554 if (prev)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100555 dbg_fragtree2("no match. Returning frag %#04x-%#04x, closest previous\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100556 prev->ofs, prev->ofs+prev->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000557 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100558 dbg_fragtree2("returning NULL, empty fragtree\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return prev;
561}
562
563/* Pass 'c' argument to indicate that nodes should be marked obsolete as
564 they're killed. */
565void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
566{
Cody P Schafere8bbeeb2014-01-23 15:56:11 -0800567 struct jffs2_node_frag *frag, *next;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100569 dbg_fragtree("killing\n");
Cody P Schafere8bbeeb2014-01-23 15:56:11 -0800570 rbtree_postorder_for_each_entry_safe(frag, next, root, rb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (frag->node && !(--frag->node->frags)) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000572 /* Not a hole, and it's the final remaining frag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 of this node. Free the node */
574 if (c)
575 jffs2_mark_node_obsolete(c, frag->node->raw);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 jffs2_free_full_dnode(frag->node);
578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
580 jffs2_free_node_frag(frag);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 cond_resched();
582 }
583}
David Woodhousef1f96712006-05-20 19:45:26 +0100584
David Woodhouse2f785402006-05-24 02:04:45 +0100585struct jffs2_raw_node_ref *jffs2_link_node_ref(struct jffs2_sb_info *c,
586 struct jffs2_eraseblock *jeb,
587 uint32_t ofs, uint32_t len,
588 struct jffs2_inode_cache *ic)
David Woodhousef1f96712006-05-20 19:45:26 +0100589{
David Woodhouse2f785402006-05-24 02:04:45 +0100590 struct jffs2_raw_node_ref *ref;
591
David Woodhouse9bfeb692006-05-26 21:19:05 +0100592 BUG_ON(!jeb->allocated_refs);
593 jeb->allocated_refs--;
594
595 ref = jeb->last_node;
596
597 dbg_noderef("Last node at %p is (%08x,%p)\n", ref, ref->flash_offset,
598 ref->next_in_ino);
599
600 while (ref->flash_offset != REF_EMPTY_NODE) {
601 if (ref->flash_offset == REF_LINK_NODE)
602 ref = ref->next_in_ino;
603 else
604 ref++;
David Woodhouse2f785402006-05-24 02:04:45 +0100605 }
606
David Woodhouse9bfeb692006-05-26 21:19:05 +0100607 dbg_noderef("New ref is %p (%08x becomes %08x,%p) len 0x%x\n", ref,
608 ref->flash_offset, ofs, ref->next_in_ino, len);
609
David Woodhouse2f785402006-05-24 02:04:45 +0100610 ref->flash_offset = ofs;
611
David Woodhouse9bfeb692006-05-26 21:19:05 +0100612 if (!jeb->first_node) {
David Woodhousef1f96712006-05-20 19:45:26 +0100613 jeb->first_node = ref;
David Woodhouse9bfeb692006-05-26 21:19:05 +0100614 BUG_ON(ref_offset(ref) != jeb->offset);
615 } else if (unlikely(ref_offset(ref) != jeb->offset + c->sector_size - jeb->free_size)) {
616 uint32_t last_len = ref_totlen(c, jeb, jeb->last_node);
617
618 JFFS2_ERROR("Adding new ref %p at (0x%08x-0x%08x) not immediately after previous (0x%08x-0x%08x)\n",
619 ref, ref_offset(ref), ref_offset(ref)+len,
620 ref_offset(jeb->last_node),
621 ref_offset(jeb->last_node)+last_len);
622 BUG();
David Woodhouseca89a512006-05-21 13:29:11 +0100623 }
David Woodhousef1f96712006-05-20 19:45:26 +0100624 jeb->last_node = ref;
625
David Woodhousefcb75782006-05-22 15:23:10 +0100626 if (ic) {
627 ref->next_in_ino = ic->nodes;
628 ic->nodes = ref;
629 } else {
630 ref->next_in_ino = NULL;
631 }
632
David Woodhousef1f96712006-05-20 19:45:26 +0100633 switch(ref_flags(ref)) {
634 case REF_UNCHECKED:
635 c->unchecked_size += len;
636 jeb->unchecked_size += len;
637 break;
638
639 case REF_NORMAL:
640 case REF_PRISTINE:
641 c->used_size += len;
642 jeb->used_size += len;
643 break;
644
645 case REF_OBSOLETE:
646 c->dirty_size += len;
David Woodhouse3b796732006-05-22 12:15:47 +0100647 jeb->dirty_size += len;
David Woodhousef1f96712006-05-20 19:45:26 +0100648 break;
649 }
650 c->free_size -= len;
651 jeb->free_size -= len;
652
David Woodhouseca89a512006-05-21 13:29:11 +0100653#ifdef TEST_TOTLEN
654 /* Set (and test) __totlen field... for now */
655 ref->__totlen = len;
656 ref_totlen(c, jeb, ref);
657#endif
David Woodhouse2f785402006-05-24 02:04:45 +0100658 return ref;
David Woodhousef1f96712006-05-20 19:45:26 +0100659}
David Woodhouse68270992006-05-21 03:46:05 +0100660
David Woodhouse2f785402006-05-24 02:04:45 +0100661/* No locking, no reservation of 'ref'. Do not use on a live file system */
David Woodhouse68270992006-05-21 03:46:05 +0100662int jffs2_scan_dirty_space(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
663 uint32_t size)
664{
David Woodhouseca89a512006-05-21 13:29:11 +0100665 if (!size)
666 return 0;
David Woodhouse9bfeb692006-05-26 21:19:05 +0100667 if (unlikely(size > jeb->free_size)) {
Joe Perchesda320f02012-02-15 15:56:44 -0800668 pr_crit("Dirty space 0x%x larger then free_size 0x%x (wasted 0x%x)\n",
669 size, jeb->free_size, jeb->wasted_size);
David Woodhouseca89a512006-05-21 13:29:11 +0100670 BUG();
671 }
David Woodhouse9bfeb692006-05-26 21:19:05 +0100672 /* REF_EMPTY_NODE is !obsolete, so that works OK */
David Woodhouse2ebf09c2006-05-28 22:13:25 +0100673 if (jeb->last_node && ref_obsolete(jeb->last_node)) {
David Woodhouseca89a512006-05-21 13:29:11 +0100674#ifdef TEST_TOTLEN
675 jeb->last_node->__totlen += size;
676#endif
677 c->dirty_size += size;
678 c->free_size -= size;
679 jeb->dirty_size += size;
680 jeb->free_size -= size;
681 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100682 uint32_t ofs = jeb->offset + c->sector_size - jeb->free_size;
683 ofs |= REF_OBSOLETE;
David Woodhouseca89a512006-05-21 13:29:11 +0100684
David Woodhouse2f785402006-05-24 02:04:45 +0100685 jffs2_link_node_ref(c, jeb, ofs, size, NULL);
David Woodhouseca89a512006-05-21 13:29:11 +0100686 }
David Woodhouse68270992006-05-21 03:46:05 +0100687
688 return 0;
689}
David Woodhouseca89a512006-05-21 13:29:11 +0100690
691/* Calculate totlen from surrounding nodes or eraseblock */
692static inline uint32_t __ref_totlen(struct jffs2_sb_info *c,
693 struct jffs2_eraseblock *jeb,
694 struct jffs2_raw_node_ref *ref)
695{
696 uint32_t ref_end;
David Woodhouse99988f72006-05-24 09:04:17 +0100697 struct jffs2_raw_node_ref *next_ref = ref_next(ref);
David Woodhouseca89a512006-05-21 13:29:11 +0100698
David Woodhouse99988f72006-05-24 09:04:17 +0100699 if (next_ref)
700 ref_end = ref_offset(next_ref);
David Woodhouseca89a512006-05-21 13:29:11 +0100701 else {
702 if (!jeb)
703 jeb = &c->blocks[ref->flash_offset / c->sector_size];
704
705 /* Last node in block. Use free_space */
David Woodhouse9bfeb692006-05-26 21:19:05 +0100706 if (unlikely(ref != jeb->last_node)) {
Joe Perchesda320f02012-02-15 15:56:44 -0800707 pr_crit("ref %p @0x%08x is not jeb->last_node (%p @0x%08x)\n",
708 ref, ref_offset(ref), jeb->last_node,
709 jeb->last_node ?
710 ref_offset(jeb->last_node) : 0);
David Woodhouseca89a512006-05-21 13:29:11 +0100711 BUG();
712 }
713 ref_end = jeb->offset + c->sector_size - jeb->free_size;
714 }
715 return ref_end - ref_offset(ref);
716}
717
718uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
719 struct jffs2_raw_node_ref *ref)
720{
721 uint32_t ret;
722
David Woodhouseca89a512006-05-21 13:29:11 +0100723 ret = __ref_totlen(c, jeb, ref);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100724
David Woodhouseca89a512006-05-21 13:29:11 +0100725#ifdef TEST_TOTLEN
David Woodhouse9bfeb692006-05-26 21:19:05 +0100726 if (unlikely(ret != ref->__totlen)) {
727 if (!jeb)
728 jeb = &c->blocks[ref->flash_offset / c->sector_size];
729
Joe Perchesda320f02012-02-15 15:56:44 -0800730 pr_crit("Totlen for ref at %p (0x%08x-0x%08x) miscalculated as 0x%x instead of %x\n",
731 ref, ref_offset(ref), ref_offset(ref) + ref->__totlen,
732 ret, ref->__totlen);
David Woodhouse99988f72006-05-24 09:04:17 +0100733 if (ref_next(ref)) {
Joe Perchesda320f02012-02-15 15:56:44 -0800734 pr_crit("next %p (0x%08x-0x%08x)\n",
735 ref_next(ref), ref_offset(ref_next(ref)),
736 ref_offset(ref_next(ref)) + ref->__totlen);
David Woodhouseca89a512006-05-21 13:29:11 +0100737 } else
Joe Perchesda320f02012-02-15 15:56:44 -0800738 pr_crit("No next ref. jeb->last_node is %p\n",
739 jeb->last_node);
David Woodhouseca89a512006-05-21 13:29:11 +0100740
Joe Perchesda320f02012-02-15 15:56:44 -0800741 pr_crit("jeb->wasted_size %x, dirty_size %x, used_size %x, free_size %x\n",
742 jeb->wasted_size, jeb->dirty_size, jeb->used_size,
743 jeb->free_size);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100744
David Woodhouseca89a512006-05-21 13:29:11 +0100745#if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
746 __jffs2_dbg_dump_node_refs_nolock(c, jeb);
747#endif
David Woodhouse9bfeb692006-05-26 21:19:05 +0100748
David Woodhouseca89a512006-05-21 13:29:11 +0100749 WARN_ON(1);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100750
751 ret = ref->__totlen;
David Woodhouseca89a512006-05-21 13:29:11 +0100752 }
753#endif /* TEST_TOTLEN */
754 return ret;
755}