blob: ac2a4c422e3249bc79d2130ccab3e26e094cd014 [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
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010055void jffs2_truncate_fragtree(struct jffs2_sb_info *c, struct rb_root *list, uint32_t size)
56{
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)
77 return;
78
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000079 /*
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010080 * If the last fragment starts at the RAM page boundary, it is
81 * REF_PRISTINE irrespective of its size.
82 */
83 frag = frag_last(list);
Artem B. Bityutskiyf0507532005-08-22 10:07:12 +010084 if (frag->node && (frag->ofs & (PAGE_CACHE_SIZE - 1)) == 0) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010085 dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n",
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000086 frag->ofs, frag->ofs + frag->size);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +010087 frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE;
88 }
Artem B. Bityutskiy1e900972005-07-31 09:20:48 +010089}
90
Adrian Bunk90a18fa2006-07-06 22:37:43 +020091static void jffs2_obsolete_node_frag(struct jffs2_sb_info *c,
92 struct jffs2_node_frag *this)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +010094 if (this->node) {
95 this->node->frags--;
96 if (!this->node->frags) {
97 /* The node has no valid frags left. It's totally obsoleted */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +010098 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) obsolete\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +010099 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100100 jffs2_mark_node_obsolete(c, this->node->raw);
101 jffs2_free_full_dnode(this->node);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100102 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100103 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 +0100104 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 +0100105 mark_ref_normal(this->node->raw);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100106 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000107
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100108 }
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100109 jffs2_free_node_frag(this);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100110}
111
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100112static void jffs2_fragtree_insert(struct jffs2_node_frag *newfrag, struct jffs2_node_frag *base)
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100113{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100114 struct rb_node *parent = &base->rb;
115 struct rb_node **link = &parent;
116
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100117 dbg_fragtree2("insert frag (0x%04x-0x%04x)\n", newfrag->ofs, newfrag->ofs + newfrag->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100118
119 while (*link) {
120 parent = *link;
121 base = rb_entry(parent, struct jffs2_node_frag, rb);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000122
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100123 if (newfrag->ofs > base->ofs)
124 link = &base->rb.rb_right;
125 else if (newfrag->ofs < base->ofs)
126 link = &base->rb.rb_left;
127 else {
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100128 JFFS2_ERROR("duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100129 BUG();
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100130 }
131 }
132
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100133 rb_link_node(&newfrag->rb, &base->rb, link);
Artem B. Bityutskiydae62272005-07-15 11:13:57 +0100134}
135
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100136/*
137 * Allocate and initializes a new fragment.
138 */
Arjan van de Ven858119e2006-01-14 13:20:43 -0800139static 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 +0100140{
141 struct jffs2_node_frag *newfrag;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000142
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100143 newfrag = jffs2_alloc_node_frag();
144 if (likely(newfrag)) {
145 newfrag->ofs = ofs;
146 newfrag->size = size;
147 newfrag->node = fn;
148 } else {
149 JFFS2_ERROR("cannot allocate a jffs2_node_frag object\n");
150 }
151
152 return newfrag;
153}
154
155/*
156 * Called when there is no overlapping fragment exist. Inserts a hole before the new
157 * fragment and inserts the new fragment to the fragtree.
158 */
159static int no_overlapping_node(struct jffs2_sb_info *c, struct rb_root *root,
160 struct jffs2_node_frag *newfrag,
161 struct jffs2_node_frag *this, uint32_t lastend)
162{
163 if (lastend < newfrag->node->ofs) {
164 /* put a hole in before the new fragment */
165 struct jffs2_node_frag *holefrag;
166
167 holefrag= new_fragment(NULL, lastend, newfrag->node->ofs - lastend);
168 if (unlikely(!holefrag)) {
169 jffs2_free_node_frag(newfrag);
170 return -ENOMEM;
171 }
172
173 if (this) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000174 /* By definition, the 'this' node has no right-hand child,
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100175 because there are no frags with offset greater than it.
176 So that's where we want to put the hole */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100177 dbg_fragtree2("add hole frag %#04x-%#04x on the right of the new frag.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100178 holefrag->ofs, holefrag->ofs + holefrag->size);
179 rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right);
180 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100181 dbg_fragtree2("Add hole frag %#04x-%#04x to the root of the tree.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100182 holefrag->ofs, holefrag->ofs + holefrag->size);
183 rb_link_node(&holefrag->rb, NULL, &root->rb_node);
184 }
185 rb_insert_color(&holefrag->rb, root);
186 this = holefrag;
187 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000188
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100189 if (this) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000190 /* By definition, the 'this' node has no right-hand child,
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100191 because there are no frags with offset greater than it.
192 So that's where we want to put new fragment */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100193 dbg_fragtree2("add the new node at the right\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000194 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100195 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100196 dbg_fragtree2("insert the new node at the root of the tree\n");
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100197 rb_link_node(&newfrag->rb, NULL, &root->rb_node);
198 }
199 rb_insert_color(&newfrag->rb, root);
200
201 return 0;
202}
203
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100204/* Doesn't set inode->i_size */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100205static 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 -0700206{
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100207 struct jffs2_node_frag *this;
208 uint32_t lastend;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100210 /* Skip all the nodes which are completed before this one starts */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100211 this = jffs2_lookup_node_frag(root, newfrag->node->ofs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100213 if (this) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100214 dbg_fragtree2("lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100215 this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100216 lastend = this->ofs + this->size;
217 } else {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100218 dbg_fragtree2("lookup gave no frag\n");
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100219 lastend = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000221
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100222 /* See if we ran off the end of the fragtree */
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100223 if (lastend <= newfrag->ofs) {
224 /* We did */
225
226 /* Check if 'this' node was on the same page as the new node.
227 If so, both 'this' and the new node get marked REF_NORMAL so
228 the GC can take a look.
229 */
230 if (lastend && (lastend-1) >> PAGE_CACHE_SHIFT == newfrag->ofs >> PAGE_CACHE_SHIFT) {
231 if (this->node)
232 mark_ref_normal(this->node->raw);
233 mark_ref_normal(newfrag->node->raw);
234 }
235
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100236 return no_overlapping_node(c, root, newfrag, this, lastend);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100237 }
238
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100239 if (this->node)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100240 dbg_fragtree2("dealing with frag %u-%u, phys %#08x(%d).\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100241 this->ofs, this->ofs + this->size,
242 ref_offset(this->node->raw), ref_flags(this->node->raw));
243 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100244 dbg_fragtree2("dealing with hole frag %u-%u.\n",
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100245 this->ofs, this->ofs + this->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100246
247 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes,
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000248 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100249 */
250 if (newfrag->ofs > this->ofs) {
251 /* This node isn't completely obsoleted. The start of it remains valid */
252
253 /* Mark the new node and the partially covered node REF_NORMAL -- let
254 the GC take a look at them */
255 mark_ref_normal(newfrag->node->raw);
256 if (this->node)
257 mark_ref_normal(this->node->raw);
258
259 if (this->ofs + this->size > newfrag->ofs + newfrag->size) {
260 /* The new node splits 'this' frag into two */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100261 struct jffs2_node_frag *newfrag2;
262
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100263 if (this->node)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100264 dbg_fragtree2("split old frag 0x%04x-0x%04x, phys 0x%08x\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100265 this->ofs, this->ofs+this->size, ref_offset(this->node->raw));
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000266 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100267 dbg_fragtree2("split old hole frag 0x%04x-0x%04x\n",
Artem B. Bityutskiy8d5df402005-08-17 15:13:48 +0100268 this->ofs, this->ofs+this->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000269
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100270 /* New second frag pointing to this's node */
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100271 newfrag2 = new_fragment(this->node, newfrag->ofs + newfrag->size,
272 this->ofs + this->size - newfrag->ofs - newfrag->size);
273 if (unlikely(!newfrag2))
274 return -ENOMEM;
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100275 if (this->node)
276 this->node->frags++;
277
278 /* Adjust size of original 'this' */
279 this->size = newfrag->ofs - this->ofs;
280
281 /* Now, we know there's no node with offset
282 greater than this->ofs but smaller than
283 newfrag2->ofs or newfrag->ofs, for obvious
284 reasons. So we can do a tree insert from
285 'this' to insert newfrag, and a tree insert
286 from newfrag to insert newfrag2. */
287 jffs2_fragtree_insert(newfrag, this);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100288 rb_insert_color(&newfrag->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000289
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100290 jffs2_fragtree_insert(newfrag2, newfrag);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100291 rb_insert_color(&newfrag2->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000292
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100293 return 0;
294 }
295 /* New node just reduces 'this' frag in size, doesn't split it */
296 this->size = newfrag->ofs - this->ofs;
297
298 /* Again, we know it lives down here in the tree */
299 jffs2_fragtree_insert(newfrag, this);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100300 rb_insert_color(&newfrag->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100301 } else {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000302 /* New frag starts at the same point as 'this' used to. Replace
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100303 it in the tree without doing a delete and insertion */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100304 dbg_fragtree2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100305 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000306
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100307 rb_replace_node(&this->rb, &newfrag->rb, root);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000308
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100309 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) {
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100310 dbg_fragtree2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100311 jffs2_obsolete_node_frag(c, this);
312 } else {
313 this->ofs += newfrag->size;
314 this->size -= newfrag->size;
315
316 jffs2_fragtree_insert(this, newfrag);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100317 rb_insert_color(&this->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100318 return 0;
319 }
320 }
321 /* OK, now we have newfrag added in the correct place in the tree, but
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000322 frag_next(newfrag) may be a fragment which is overlapped by it
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100323 */
324 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) {
325 /* 'this' frag is obsoleted completely. */
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100326 dbg_fragtree2("obsoleting node frag %p (%x-%x) and removing from tree\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100327 this, this->ofs, this->ofs+this->size);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100328 rb_erase(&this->rb, root);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100329 jffs2_obsolete_node_frag(c, this);
330 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000331 /* Now we're pointing at the first frag which isn't totally obsoleted by
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100332 the new frag */
333
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100334 if (!this || newfrag->ofs + newfrag->size == this->ofs)
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100335 return 0;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100336
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100337 /* Still some overlap but we don't need to move it in the tree */
338 this->size = (this->ofs + this->size) - (newfrag->ofs + newfrag->size);
339 this->ofs = newfrag->ofs + newfrag->size;
340
341 /* And mark them REF_NORMAL so the GC takes a look at them */
342 if (this->node)
343 mark_ref_normal(this->node->raw);
344 mark_ref_normal(newfrag->node->raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000349/*
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100350 * Given an inode, probably with existing tree of fragments, add the new node
351 * to the fragment tree.
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100352 */
353int jffs2_add_full_dnode_to_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f, struct jffs2_full_dnode *fn)
354{
355 int ret;
356 struct jffs2_node_frag *newfrag;
357
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100358 if (unlikely(!fn->size))
359 return 0;
360
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100361 newfrag = new_fragment(fn, fn->ofs, fn->size);
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100362 if (unlikely(!newfrag))
363 return -ENOMEM;
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100364 newfrag->node->frags = 1;
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100365
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100366 dbg_fragtree("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100367 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000368
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100369 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag);
370 if (unlikely(ret))
371 return ret;
372
373 /* If we now share a page with other nodes, mark either previous
374 or next node REF_NORMAL, as appropriate. */
375 if (newfrag->ofs & (PAGE_CACHE_SIZE-1)) {
376 struct jffs2_node_frag *prev = frag_prev(newfrag);
377
378 mark_ref_normal(fn->raw);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000379 /* If we don't start at zero there's _always_ a previous */
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100380 if (prev->node)
381 mark_ref_normal(prev->node->raw);
382 }
383
384 if ((newfrag->ofs+newfrag->size) & (PAGE_CACHE_SIZE-1)) {
385 struct jffs2_node_frag *next = frag_next(newfrag);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000386
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100387 if (next) {
388 mark_ref_normal(fn->raw);
389 if (next->node)
390 mark_ref_normal(next->node->raw);
391 }
392 }
393 jffs2_dbg_fragtree_paranoia_check_nolock(f);
Artem B. Bityutskiy1e0da3c2005-08-01 13:05:22 +0100394
Artem B. Bityutskiyf97117d2005-07-27 15:46:14 +0100395 return 0;
396}
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state)
399{
400 spin_lock(&c->inocache_lock);
401 ic->state = state;
402 wake_up(&c->inocache_wq);
403 spin_unlock(&c->inocache_lock);
404}
405
406/* During mount, this needs no locking. During normal operation, its
407 callers want to do other stuff while still holding the inocache_lock.
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000408 Rather than introducing special case get_ino_cache functions or
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 callbacks, we just let the caller do the locking itself. */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411struct jffs2_inode_cache *jffs2_get_ino_cache(struct jffs2_sb_info *c, uint32_t ino)
412{
413 struct jffs2_inode_cache *ret;
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 ret = c->inocache_list[ino % INOCACHE_HASHSIZE];
416 while (ret && ret->ino < ino) {
417 ret = ret->next;
418 }
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000419
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 if (ret && ret->ino != ino)
421 ret = NULL;
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return ret;
424}
425
426void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new)
427{
428 struct jffs2_inode_cache **prev;
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200429
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 spin_lock(&c->inocache_lock);
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200431 if (!new->ino)
432 new->ino = ++c->highest_ino;
433
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100434 dbg_inocache("add %p (ino #%u)\n", new, new->ino);
Thomas Gleixner7d27c812005-05-22 21:47:19 +0200435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 prev = &c->inocache_list[new->ino % INOCACHE_HASHSIZE];
437
438 while ((*prev) && (*prev)->ino < new->ino) {
439 prev = &(*prev)->next;
440 }
441 new->next = *prev;
442 *prev = new;
443
444 spin_unlock(&c->inocache_lock);
445}
446
447void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old)
448{
449 struct jffs2_inode_cache **prev;
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100450
KaiGai Kohei355ed4e2006-06-24 09:15:36 +0900451#ifdef CONFIG_JFFS2_FS_XATTR
452 BUG_ON(old->xref);
453#endif
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100454 dbg_inocache("del %p (ino #%u)\n", old, old->ino);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 spin_lock(&c->inocache_lock);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE];
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000458
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 while ((*prev) && (*prev)->ino < old->ino) {
460 prev = &(*prev)->next;
461 }
462 if ((*prev) == old) {
463 *prev = old->next;
464 }
465
David Woodhouse67e345d2005-02-27 23:01:36 +0000466 /* Free it now unless it's in READING or CLEARING state, which
467 are the transitions upon read_inode() and clear_inode(). The
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000468 rest of the time we know nobody else is looking at it, and
David Woodhouse67e345d2005-02-27 23:01:36 +0000469 if it's held by read_inode() or clear_inode() they'll free it
470 for themselves. */
471 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING)
472 jffs2_free_inode_cache(old);
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 spin_unlock(&c->inocache_lock);
475}
476
477void jffs2_free_ino_caches(struct jffs2_sb_info *c)
478{
479 int i;
480 struct jffs2_inode_cache *this, *next;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 for (i=0; i<INOCACHE_HASHSIZE; i++) {
483 this = c->inocache_list[i];
484 while (this) {
485 next = this->next;
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +0900486 jffs2_xattr_free_inode(c, this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 jffs2_free_inode_cache(this);
488 this = next;
489 }
490 c->inocache_list[i] = NULL;
491 }
492}
493
494void jffs2_free_raw_node_refs(struct jffs2_sb_info *c)
495{
496 int i;
497 struct jffs2_raw_node_ref *this, *next;
498
499 for (i=0; i<c->nr_blocks; i++) {
500 this = c->blocks[i].first_node;
David Woodhouse2f785402006-05-24 02:04:45 +0100501 while (this) {
David Woodhouse9bfeb692006-05-26 21:19:05 +0100502 if (this[REFS_PER_BLOCK].flash_offset == REF_LINK_NODE)
503 next = this[REFS_PER_BLOCK].next_in_ino;
504 else
505 next = NULL;
506
507 jffs2_free_refblock(this);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 this = next;
509 }
510 c->blocks[i].first_node = c->blocks[i].last_node = NULL;
511 }
512}
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514struct jffs2_node_frag *jffs2_lookup_node_frag(struct rb_root *fragtree, uint32_t offset)
515{
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000516 /* The common case in lookup is that there will be a node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 which precisely matches. So we go looking for that first */
518 struct rb_node *next;
519 struct jffs2_node_frag *prev = NULL;
520 struct jffs2_node_frag *frag = NULL;
521
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100522 dbg_fragtree2("root %p, offset %d\n", fragtree, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 next = fragtree->rb_node;
525
526 while(next) {
527 frag = rb_entry(next, struct jffs2_node_frag, rb);
528
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 if (frag->ofs + frag->size <= offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 /* Remember the closest smaller match on the way down */
531 if (!prev || frag->ofs > prev->ofs)
532 prev = frag;
533 next = frag->rb.rb_right;
534 } else if (frag->ofs > offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 next = frag->rb.rb_left;
536 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 return frag;
538 }
539 }
540
541 /* Exact match not found. Go back up looking at each parent,
542 and return the closest smaller one */
543
544 if (prev)
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100545 dbg_fragtree2("no match. Returning frag %#04x-%#04x, closest previous\n",
Artem B. Bityutskiye0d60132005-07-28 15:46:43 +0100546 prev->ofs, prev->ofs+prev->size);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000547 else
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100548 dbg_fragtree2("returning NULL, empty fragtree\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 return prev;
551}
552
553/* Pass 'c' argument to indicate that nodes should be marked obsolete as
554 they're killed. */
555void jffs2_kill_fragtree(struct rb_root *root, struct jffs2_sb_info *c)
556{
557 struct jffs2_node_frag *frag;
558 struct jffs2_node_frag *parent;
559
560 if (!root->rb_node)
561 return;
562
Artem B. Bityutskiy733802d2005-09-22 12:25:00 +0100563 dbg_fragtree("killing\n");
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 frag = (rb_entry(root->rb_node, struct jffs2_node_frag, rb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 while(frag) {
567 if (frag->rb.rb_left) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 frag = frag_left(frag);
569 continue;
570 }
571 if (frag->rb.rb_right) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572 frag = frag_right(frag);
573 continue;
574 }
575
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 if (frag->node && !(--frag->node->frags)) {
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000577 /* Not a hole, and it's the final remaining frag
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 of this node. Free the node */
579 if (c)
580 jffs2_mark_node_obsolete(c, frag->node->raw);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000581
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 jffs2_free_full_dnode(frag->node);
583 }
584 parent = frag_parent(frag);
585 if (parent) {
586 if (frag_left(parent) == frag)
587 parent->rb.rb_left = NULL;
Thomas Gleixner182ec4e2005-11-07 11:16:07 +0000588 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589 parent->rb.rb_right = NULL;
590 }
591
592 jffs2_free_node_frag(frag);
593 frag = parent;
594
595 cond_resched();
596 }
597}
David Woodhousef1f96712006-05-20 19:45:26 +0100598
David Woodhouse2f785402006-05-24 02:04:45 +0100599struct jffs2_raw_node_ref *jffs2_link_node_ref(struct jffs2_sb_info *c,
600 struct jffs2_eraseblock *jeb,
601 uint32_t ofs, uint32_t len,
602 struct jffs2_inode_cache *ic)
David Woodhousef1f96712006-05-20 19:45:26 +0100603{
David Woodhouse2f785402006-05-24 02:04:45 +0100604 struct jffs2_raw_node_ref *ref;
605
David Woodhouse9bfeb692006-05-26 21:19:05 +0100606 BUG_ON(!jeb->allocated_refs);
607 jeb->allocated_refs--;
608
609 ref = jeb->last_node;
610
611 dbg_noderef("Last node at %p is (%08x,%p)\n", ref, ref->flash_offset,
612 ref->next_in_ino);
613
614 while (ref->flash_offset != REF_EMPTY_NODE) {
615 if (ref->flash_offset == REF_LINK_NODE)
616 ref = ref->next_in_ino;
617 else
618 ref++;
David Woodhouse2f785402006-05-24 02:04:45 +0100619 }
620
David Woodhouse9bfeb692006-05-26 21:19:05 +0100621 dbg_noderef("New ref is %p (%08x becomes %08x,%p) len 0x%x\n", ref,
622 ref->flash_offset, ofs, ref->next_in_ino, len);
623
David Woodhouse2f785402006-05-24 02:04:45 +0100624 ref->flash_offset = ofs;
625
David Woodhouse9bfeb692006-05-26 21:19:05 +0100626 if (!jeb->first_node) {
David Woodhousef1f96712006-05-20 19:45:26 +0100627 jeb->first_node = ref;
David Woodhouse9bfeb692006-05-26 21:19:05 +0100628 BUG_ON(ref_offset(ref) != jeb->offset);
629 } else if (unlikely(ref_offset(ref) != jeb->offset + c->sector_size - jeb->free_size)) {
630 uint32_t last_len = ref_totlen(c, jeb, jeb->last_node);
631
632 JFFS2_ERROR("Adding new ref %p at (0x%08x-0x%08x) not immediately after previous (0x%08x-0x%08x)\n",
633 ref, ref_offset(ref), ref_offset(ref)+len,
634 ref_offset(jeb->last_node),
635 ref_offset(jeb->last_node)+last_len);
636 BUG();
David Woodhouseca89a512006-05-21 13:29:11 +0100637 }
David Woodhousef1f96712006-05-20 19:45:26 +0100638 jeb->last_node = ref;
639
David Woodhousefcb75782006-05-22 15:23:10 +0100640 if (ic) {
641 ref->next_in_ino = ic->nodes;
642 ic->nodes = ref;
643 } else {
644 ref->next_in_ino = NULL;
645 }
646
David Woodhousef1f96712006-05-20 19:45:26 +0100647 switch(ref_flags(ref)) {
648 case REF_UNCHECKED:
649 c->unchecked_size += len;
650 jeb->unchecked_size += len;
651 break;
652
653 case REF_NORMAL:
654 case REF_PRISTINE:
655 c->used_size += len;
656 jeb->used_size += len;
657 break;
658
659 case REF_OBSOLETE:
660 c->dirty_size += len;
David Woodhouse3b796732006-05-22 12:15:47 +0100661 jeb->dirty_size += len;
David Woodhousef1f96712006-05-20 19:45:26 +0100662 break;
663 }
664 c->free_size -= len;
665 jeb->free_size -= len;
666
David Woodhouseca89a512006-05-21 13:29:11 +0100667#ifdef TEST_TOTLEN
668 /* Set (and test) __totlen field... for now */
669 ref->__totlen = len;
670 ref_totlen(c, jeb, ref);
671#endif
David Woodhouse2f785402006-05-24 02:04:45 +0100672 return ref;
David Woodhousef1f96712006-05-20 19:45:26 +0100673}
David Woodhouse68270992006-05-21 03:46:05 +0100674
David Woodhouse2f785402006-05-24 02:04:45 +0100675/* No locking, no reservation of 'ref'. Do not use on a live file system */
David Woodhouse68270992006-05-21 03:46:05 +0100676int jffs2_scan_dirty_space(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
677 uint32_t size)
678{
David Woodhouseca89a512006-05-21 13:29:11 +0100679 if (!size)
680 return 0;
David Woodhouse9bfeb692006-05-26 21:19:05 +0100681 if (unlikely(size > jeb->free_size)) {
682 printk(KERN_CRIT "Dirty space 0x%x larger then free_size 0x%x (wasted 0x%x)\n",
683 size, jeb->free_size, jeb->wasted_size);
David Woodhouseca89a512006-05-21 13:29:11 +0100684 BUG();
685 }
David Woodhouse9bfeb692006-05-26 21:19:05 +0100686 /* REF_EMPTY_NODE is !obsolete, so that works OK */
David Woodhouse2ebf09c2006-05-28 22:13:25 +0100687 if (jeb->last_node && ref_obsolete(jeb->last_node)) {
David Woodhouseca89a512006-05-21 13:29:11 +0100688#ifdef TEST_TOTLEN
689 jeb->last_node->__totlen += size;
690#endif
691 c->dirty_size += size;
692 c->free_size -= size;
693 jeb->dirty_size += size;
694 jeb->free_size -= size;
695 } else {
David Woodhouse2f785402006-05-24 02:04:45 +0100696 uint32_t ofs = jeb->offset + c->sector_size - jeb->free_size;
697 ofs |= REF_OBSOLETE;
David Woodhouseca89a512006-05-21 13:29:11 +0100698
David Woodhouse2f785402006-05-24 02:04:45 +0100699 jffs2_link_node_ref(c, jeb, ofs, size, NULL);
David Woodhouseca89a512006-05-21 13:29:11 +0100700 }
David Woodhouse68270992006-05-21 03:46:05 +0100701
702 return 0;
703}
David Woodhouseca89a512006-05-21 13:29:11 +0100704
705/* Calculate totlen from surrounding nodes or eraseblock */
706static inline uint32_t __ref_totlen(struct jffs2_sb_info *c,
707 struct jffs2_eraseblock *jeb,
708 struct jffs2_raw_node_ref *ref)
709{
710 uint32_t ref_end;
David Woodhouse99988f72006-05-24 09:04:17 +0100711 struct jffs2_raw_node_ref *next_ref = ref_next(ref);
David Woodhouseca89a512006-05-21 13:29:11 +0100712
David Woodhouse99988f72006-05-24 09:04:17 +0100713 if (next_ref)
714 ref_end = ref_offset(next_ref);
David Woodhouseca89a512006-05-21 13:29:11 +0100715 else {
716 if (!jeb)
717 jeb = &c->blocks[ref->flash_offset / c->sector_size];
718
719 /* Last node in block. Use free_space */
David Woodhouse9bfeb692006-05-26 21:19:05 +0100720 if (unlikely(ref != jeb->last_node)) {
David Woodhouseca89a512006-05-21 13:29:11 +0100721 printk(KERN_CRIT "ref %p @0x%08x is not jeb->last_node (%p @0x%08x)\n",
722 ref, ref_offset(ref), jeb->last_node, jeb->last_node?ref_offset(jeb->last_node):0);
723 BUG();
724 }
725 ref_end = jeb->offset + c->sector_size - jeb->free_size;
726 }
727 return ref_end - ref_offset(ref);
728}
729
730uint32_t __jffs2_ref_totlen(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb,
731 struct jffs2_raw_node_ref *ref)
732{
733 uint32_t ret;
734
David Woodhouseca89a512006-05-21 13:29:11 +0100735 ret = __ref_totlen(c, jeb, ref);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100736
David Woodhouseca89a512006-05-21 13:29:11 +0100737#ifdef TEST_TOTLEN
David Woodhouse9bfeb692006-05-26 21:19:05 +0100738 if (unlikely(ret != ref->__totlen)) {
739 if (!jeb)
740 jeb = &c->blocks[ref->flash_offset / c->sector_size];
741
David Woodhouseca89a512006-05-21 13:29:11 +0100742 printk(KERN_CRIT "Totlen for ref at %p (0x%08x-0x%08x) miscalculated as 0x%x instead of %x\n",
743 ref, ref_offset(ref), ref_offset(ref)+ref->__totlen,
744 ret, ref->__totlen);
David Woodhouse99988f72006-05-24 09:04:17 +0100745 if (ref_next(ref)) {
746 printk(KERN_CRIT "next %p (0x%08x-0x%08x)\n", ref_next(ref), ref_offset(ref_next(ref)),
747 ref_offset(ref_next(ref))+ref->__totlen);
David Woodhouseca89a512006-05-21 13:29:11 +0100748 } else
David Woodhouse99988f72006-05-24 09:04:17 +0100749 printk(KERN_CRIT "No next ref. jeb->last_node is %p\n", jeb->last_node);
David Woodhouseca89a512006-05-21 13:29:11 +0100750
751 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 +0100752
David Woodhouseca89a512006-05-21 13:29:11 +0100753#if defined(JFFS2_DBG_DUMPS) || defined(JFFS2_DBG_PARANOIA_CHECKS)
754 __jffs2_dbg_dump_node_refs_nolock(c, jeb);
755#endif
David Woodhouse9bfeb692006-05-26 21:19:05 +0100756
David Woodhouseca89a512006-05-21 13:29:11 +0100757 WARN_ON(1);
David Woodhouse9bfeb692006-05-26 21:19:05 +0100758
759 ret = ref->__totlen;
David Woodhouseca89a512006-05-21 13:29:11 +0100760 }
761#endif /* TEST_TOTLEN */
762 return ret;
763}