Lines Matching +full:x +full:- +full:size
2 * JFFS2 -- Journalling Flash File System, Version 2.
4 * Copyright © 2001-2007 Red Hat, Inc.
30 dbg_dentlist("add dirent \"%s\", ino #%u\n", new->name, new->ino); in jffs2_add_fd_to_list()
32 while ((*prev) && (*prev)->nhash <= new->nhash) { in jffs2_add_fd_to_list()
33 if ((*prev)->nhash == new->nhash && !strcmp((*prev)->name, new->name)) { in jffs2_add_fd_to_list()
35 if (new->version < (*prev)->version) { in jffs2_add_fd_to_list()
37 (*prev)->name, (*prev)->ino); in jffs2_add_fd_to_list()
38 jffs2_mark_node_obsolete(c, new->raw); in jffs2_add_fd_to_list()
42 (*prev)->name, (*prev)->ino); in jffs2_add_fd_to_list()
43 new->next = (*prev)->next; in jffs2_add_fd_to_list()
46 if ((*prev)->raw) in jffs2_add_fd_to_list()
47 jffs2_mark_node_obsolete(c, ((*prev)->raw)); in jffs2_add_fd_to_list()
53 prev = &((*prev)->next); in jffs2_add_fd_to_list()
55 new->next = *prev; in jffs2_add_fd_to_list()
59 uint32_t jffs2_truncate_fragtree(struct jffs2_sb_info *c, struct rb_root *list, uint32_t size) in jffs2_truncate_fragtree() argument
61 struct jffs2_node_frag *frag = jffs2_lookup_node_frag(list, size); in jffs2_truncate_fragtree()
63 dbg_fragtree("truncating fragtree to 0x%08x bytes\n", size); in jffs2_truncate_fragtree()
65 /* We know frag->ofs <= size. That's what lookup does for us */ in jffs2_truncate_fragtree()
66 if (frag && frag->ofs != size) { in jffs2_truncate_fragtree()
67 if (frag->ofs+frag->size > size) { in jffs2_truncate_fragtree()
68 frag->size = size - frag->ofs; in jffs2_truncate_fragtree()
72 while (frag && frag->ofs >= size) { in jffs2_truncate_fragtree()
80 if (size == 0) in jffs2_truncate_fragtree()
88 if (frag->ofs + frag->size < size) in jffs2_truncate_fragtree()
89 return frag->ofs + frag->size; in jffs2_truncate_fragtree()
92 * REF_PRISTINE irrespective of its size. */ in jffs2_truncate_fragtree()
93 if (frag->node && (frag->ofs & (PAGE_SIZE - 1)) == 0) { in jffs2_truncate_fragtree()
94 dbg_fragtree2("marking the last fragment 0x%08x-0x%08x REF_PRISTINE.\n", in jffs2_truncate_fragtree()
95 frag->ofs, frag->ofs + frag->size); in jffs2_truncate_fragtree()
96 frag->node->raw->flash_offset = ref_offset(frag->node->raw) | REF_PRISTINE; in jffs2_truncate_fragtree()
98 return size; in jffs2_truncate_fragtree()
104 if (this->node) { in jffs2_obsolete_node_frag()
105 this->node->frags--; in jffs2_obsolete_node_frag()
106 if (!this->node->frags) { in jffs2_obsolete_node_frag()
108 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) obsolete\n", in jffs2_obsolete_node_frag()
109 ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size); in jffs2_obsolete_node_frag()
110 jffs2_mark_node_obsolete(c, this->node->raw); in jffs2_obsolete_node_frag()
111 jffs2_free_full_dnode(this->node); in jffs2_obsolete_node_frag()
113 dbg_fragtree2("marking old node @0x%08x (0x%04x-0x%04x) REF_NORMAL. frags is %d\n", in jffs2_obsolete_node_frag()
114 …ref_offset(this->node->raw), this->node->ofs, this->node->ofs+this->node->size, this->node->frags); in jffs2_obsolete_node_frag()
115 mark_ref_normal(this->node->raw); in jffs2_obsolete_node_frag()
124 struct rb_node *parent = &base->rb; in jffs2_fragtree_insert()
127 dbg_fragtree2("insert frag (0x%04x-0x%04x)\n", newfrag->ofs, newfrag->ofs + newfrag->size); in jffs2_fragtree_insert()
133 if (newfrag->ofs > base->ofs) in jffs2_fragtree_insert()
134 link = &base->rb.rb_right; in jffs2_fragtree_insert()
135 else if (newfrag->ofs < base->ofs) in jffs2_fragtree_insert()
136 link = &base->rb.rb_left; in jffs2_fragtree_insert()
138 JFFS2_ERROR("duplicate frag at %08x (%p,%p)\n", newfrag->ofs, newfrag, base); in jffs2_fragtree_insert()
143 rb_link_node(&newfrag->rb, &base->rb, link); in jffs2_fragtree_insert()
149 …tic struct jffs2_node_frag * new_fragment(struct jffs2_full_dnode *fn, uint32_t ofs, uint32_t size) in new_fragment() argument
155 newfrag->ofs = ofs; in new_fragment()
156 newfrag->size = size; in new_fragment()
157 newfrag->node = fn; in new_fragment()
173 if (lastend < newfrag->node->ofs) { in no_overlapping_node()
177 holefrag= new_fragment(NULL, lastend, newfrag->node->ofs - lastend); in no_overlapping_node()
180 return -ENOMEM; in no_overlapping_node()
184 /* By definition, the 'this' node has no right-hand child, in no_overlapping_node()
187 dbg_fragtree2("add hole frag %#04x-%#04x on the right of the new frag.\n", in no_overlapping_node()
188 holefrag->ofs, holefrag->ofs + holefrag->size); in no_overlapping_node()
189 rb_link_node(&holefrag->rb, &this->rb, &this->rb.rb_right); in no_overlapping_node()
191 dbg_fragtree2("Add hole frag %#04x-%#04x to the root of the tree.\n", in no_overlapping_node()
192 holefrag->ofs, holefrag->ofs + holefrag->size); in no_overlapping_node()
193 rb_link_node(&holefrag->rb, NULL, &root->rb_node); in no_overlapping_node()
195 rb_insert_color(&holefrag->rb, root); in no_overlapping_node()
200 /* By definition, the 'this' node has no right-hand child, in no_overlapping_node()
204 rb_link_node(&newfrag->rb, &this->rb, &this->rb.rb_right); in no_overlapping_node()
207 rb_link_node(&newfrag->rb, NULL, &root->rb_node); in no_overlapping_node()
209 rb_insert_color(&newfrag->rb, root); in no_overlapping_node()
214 /* Doesn't set inode->i_size */
221 this = jffs2_lookup_node_frag(root, newfrag->node->ofs); in jffs2_add_frag_to_fragtree()
224 dbg_fragtree2("lookup gave frag 0x%04x-0x%04x; phys 0x%08x (*%p)\n", in jffs2_add_frag_to_fragtree()
225 this->ofs, this->ofs+this->size, this->node?(ref_offset(this->node->raw)):0xffffffff, this); in jffs2_add_frag_to_fragtree()
226 lastend = this->ofs + this->size; in jffs2_add_frag_to_fragtree()
233 if (lastend <= newfrag->ofs) { in jffs2_add_frag_to_fragtree()
240 if (lastend && (lastend-1) >> PAGE_SHIFT == newfrag->ofs >> PAGE_SHIFT) { in jffs2_add_frag_to_fragtree()
241 if (this->node) in jffs2_add_frag_to_fragtree()
242 mark_ref_normal(this->node->raw); in jffs2_add_frag_to_fragtree()
243 mark_ref_normal(newfrag->node->raw); in jffs2_add_frag_to_fragtree()
249 if (this->node) in jffs2_add_frag_to_fragtree()
250 dbg_fragtree2("dealing with frag %u-%u, phys %#08x(%d).\n", in jffs2_add_frag_to_fragtree()
251 this->ofs, this->ofs + this->size, in jffs2_add_frag_to_fragtree()
252 ref_offset(this->node->raw), ref_flags(this->node->raw)); in jffs2_add_frag_to_fragtree()
254 dbg_fragtree2("dealing with hole frag %u-%u.\n", in jffs2_add_frag_to_fragtree()
255 this->ofs, this->ofs + this->size); in jffs2_add_frag_to_fragtree()
257 /* OK. 'this' is pointing at the first frag that newfrag->ofs at least partially obsoletes, in jffs2_add_frag_to_fragtree()
258 * - i.e. newfrag->ofs < this->ofs+this->size && newfrag->ofs >= this->ofs in jffs2_add_frag_to_fragtree()
260 if (newfrag->ofs > this->ofs) { in jffs2_add_frag_to_fragtree()
263 /* Mark the new node and the partially covered node REF_NORMAL -- let in jffs2_add_frag_to_fragtree()
265 mark_ref_normal(newfrag->node->raw); in jffs2_add_frag_to_fragtree()
266 if (this->node) in jffs2_add_frag_to_fragtree()
267 mark_ref_normal(this->node->raw); in jffs2_add_frag_to_fragtree()
269 if (this->ofs + this->size > newfrag->ofs + newfrag->size) { in jffs2_add_frag_to_fragtree()
273 if (this->node) in jffs2_add_frag_to_fragtree()
274 dbg_fragtree2("split old frag 0x%04x-0x%04x, phys 0x%08x\n", in jffs2_add_frag_to_fragtree()
275 this->ofs, this->ofs+this->size, ref_offset(this->node->raw)); in jffs2_add_frag_to_fragtree()
277 dbg_fragtree2("split old hole frag 0x%04x-0x%04x\n", in jffs2_add_frag_to_fragtree()
278 this->ofs, this->ofs+this->size); in jffs2_add_frag_to_fragtree()
281 newfrag2 = new_fragment(this->node, newfrag->ofs + newfrag->size, in jffs2_add_frag_to_fragtree()
282 this->ofs + this->size - newfrag->ofs - newfrag->size); in jffs2_add_frag_to_fragtree()
284 return -ENOMEM; in jffs2_add_frag_to_fragtree()
285 if (this->node) in jffs2_add_frag_to_fragtree()
286 this->node->frags++; in jffs2_add_frag_to_fragtree()
288 /* Adjust size of original 'this' */ in jffs2_add_frag_to_fragtree()
289 this->size = newfrag->ofs - this->ofs; in jffs2_add_frag_to_fragtree()
292 greater than this->ofs but smaller than in jffs2_add_frag_to_fragtree()
293 newfrag2->ofs or newfrag->ofs, for obvious in jffs2_add_frag_to_fragtree()
298 rb_insert_color(&newfrag->rb, root); in jffs2_add_frag_to_fragtree()
301 rb_insert_color(&newfrag2->rb, root); in jffs2_add_frag_to_fragtree()
305 /* New node just reduces 'this' frag in size, doesn't split it */ in jffs2_add_frag_to_fragtree()
306 this->size = newfrag->ofs - this->ofs; in jffs2_add_frag_to_fragtree()
310 rb_insert_color(&newfrag->rb, root); in jffs2_add_frag_to_fragtree()
314 dbg_fragtree2("inserting newfrag (*%p),%d-%d in before 'this' (*%p),%d-%d\n", in jffs2_add_frag_to_fragtree()
315 newfrag, newfrag->ofs, newfrag->ofs+newfrag->size, this, this->ofs, this->ofs+this->size); in jffs2_add_frag_to_fragtree()
317 rb_replace_node(&this->rb, &newfrag->rb, root); in jffs2_add_frag_to_fragtree()
319 if (newfrag->ofs + newfrag->size >= this->ofs+this->size) { in jffs2_add_frag_to_fragtree()
320 dbg_fragtree2("obsoleting node frag %p (%x-%x)\n", this, this->ofs, this->ofs+this->size); in jffs2_add_frag_to_fragtree()
323 this->ofs += newfrag->size; in jffs2_add_frag_to_fragtree()
324 this->size -= newfrag->size; in jffs2_add_frag_to_fragtree()
327 rb_insert_color(&this->rb, root); in jffs2_add_frag_to_fragtree()
334 while ((this = frag_next(newfrag)) && newfrag->ofs + newfrag->size >= this->ofs + this->size) { in jffs2_add_frag_to_fragtree()
336 dbg_fragtree2("obsoleting node frag %p (%x-%x) and removing from tree\n", in jffs2_add_frag_to_fragtree()
337 this, this->ofs, this->ofs+this->size); in jffs2_add_frag_to_fragtree()
338 rb_erase(&this->rb, root); in jffs2_add_frag_to_fragtree()
344 if (!this || newfrag->ofs + newfrag->size == this->ofs) in jffs2_add_frag_to_fragtree()
348 this->size = (this->ofs + this->size) - (newfrag->ofs + newfrag->size); in jffs2_add_frag_to_fragtree()
349 this->ofs = newfrag->ofs + newfrag->size; in jffs2_add_frag_to_fragtree()
352 if (this->node) in jffs2_add_frag_to_fragtree()
353 mark_ref_normal(this->node->raw); in jffs2_add_frag_to_fragtree()
354 mark_ref_normal(newfrag->node->raw); in jffs2_add_frag_to_fragtree()
368 if (unlikely(!fn->size)) in jffs2_add_full_dnode_to_inode()
371 newfrag = new_fragment(fn, fn->ofs, fn->size); in jffs2_add_full_dnode_to_inode()
373 return -ENOMEM; in jffs2_add_full_dnode_to_inode()
374 newfrag->node->frags = 1; in jffs2_add_full_dnode_to_inode()
376 dbg_fragtree("adding node %#04x-%#04x @0x%08x on flash, newfrag *%p\n", in jffs2_add_full_dnode_to_inode()
377 fn->ofs, fn->ofs+fn->size, ref_offset(fn->raw), newfrag); in jffs2_add_full_dnode_to_inode()
379 ret = jffs2_add_frag_to_fragtree(c, &f->fragtree, newfrag); in jffs2_add_full_dnode_to_inode()
385 if (newfrag->ofs & (PAGE_SIZE-1)) { in jffs2_add_full_dnode_to_inode()
388 mark_ref_normal(fn->raw); in jffs2_add_full_dnode_to_inode()
390 if (prev->node) in jffs2_add_full_dnode_to_inode()
391 mark_ref_normal(prev->node->raw); in jffs2_add_full_dnode_to_inode()
394 if ((newfrag->ofs+newfrag->size) & (PAGE_SIZE-1)) { in jffs2_add_full_dnode_to_inode()
398 mark_ref_normal(fn->raw); in jffs2_add_full_dnode_to_inode()
399 if (next->node) in jffs2_add_full_dnode_to_inode()
400 mark_ref_normal(next->node->raw); in jffs2_add_full_dnode_to_inode()
410 spin_lock(&c->inocache_lock); in jffs2_set_inocache_state()
411 ic->state = state; in jffs2_set_inocache_state()
412 wake_up(&c->inocache_wq); in jffs2_set_inocache_state()
413 spin_unlock(&c->inocache_lock); in jffs2_set_inocache_state()
425 ret = c->inocache_list[ino % c->inocache_hashsize]; in jffs2_get_ino_cache()
426 while (ret && ret->ino < ino) { in jffs2_get_ino_cache()
427 ret = ret->next; in jffs2_get_ino_cache()
430 if (ret && ret->ino != ino) in jffs2_get_ino_cache()
440 spin_lock(&c->inocache_lock); in jffs2_add_ino_cache()
441 if (!new->ino) in jffs2_add_ino_cache()
442 new->ino = ++c->highest_ino; in jffs2_add_ino_cache()
444 dbg_inocache("add %p (ino #%u)\n", new, new->ino); in jffs2_add_ino_cache()
446 prev = &c->inocache_list[new->ino % c->inocache_hashsize]; in jffs2_add_ino_cache()
448 while ((*prev) && (*prev)->ino < new->ino) { in jffs2_add_ino_cache()
449 prev = &(*prev)->next; in jffs2_add_ino_cache()
451 new->next = *prev; in jffs2_add_ino_cache()
454 spin_unlock(&c->inocache_lock); in jffs2_add_ino_cache()
462 BUG_ON(old->xref); in jffs2_del_ino_cache()
464 dbg_inocache("del %p (ino #%u)\n", old, old->ino); in jffs2_del_ino_cache()
465 spin_lock(&c->inocache_lock); in jffs2_del_ino_cache()
467 prev = &c->inocache_list[old->ino % c->inocache_hashsize]; in jffs2_del_ino_cache()
469 while ((*prev) && (*prev)->ino < old->ino) { in jffs2_del_ino_cache()
470 prev = &(*prev)->next; in jffs2_del_ino_cache()
473 *prev = old->next; in jffs2_del_ino_cache()
481 if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING) in jffs2_del_ino_cache()
484 spin_unlock(&c->inocache_lock); in jffs2_del_ino_cache()
492 for (i=0; i < c->inocache_hashsize; i++) { in jffs2_free_ino_caches()
493 this = c->inocache_list[i]; in jffs2_free_ino_caches()
495 next = this->next; in jffs2_free_ino_caches()
500 c->inocache_list[i] = NULL; in jffs2_free_ino_caches()
509 for (i=0; i<c->nr_blocks; i++) { in jffs2_free_raw_node_refs()
510 this = c->blocks[i].first_node; in jffs2_free_raw_node_refs()
520 c->blocks[i].first_node = c->blocks[i].last_node = NULL; in jffs2_free_raw_node_refs()
534 next = fragtree->rb_node; in jffs2_lookup_node_frag()
539 if (frag->ofs + frag->size <= offset) { in jffs2_lookup_node_frag()
541 if (!prev || frag->ofs > prev->ofs) in jffs2_lookup_node_frag()
543 next = frag->rb.rb_right; in jffs2_lookup_node_frag()
544 } else if (frag->ofs > offset) { in jffs2_lookup_node_frag()
545 next = frag->rb.rb_left; in jffs2_lookup_node_frag()
555 dbg_fragtree2("no match. Returning frag %#04x-%#04x, closest previous\n", in jffs2_lookup_node_frag()
556 prev->ofs, prev->ofs+prev->size); in jffs2_lookup_node_frag()
571 if (frag->node && !(--frag->node->frags)) { in jffs2_kill_fragtree()
575 jffs2_mark_node_obsolete(c, frag->node->raw); in jffs2_kill_fragtree()
577 jffs2_free_full_dnode(frag->node); in jffs2_kill_fragtree()
592 BUG_ON(!jeb->allocated_refs); in jffs2_link_node_ref()
593 jeb->allocated_refs--; in jffs2_link_node_ref()
595 ref = jeb->last_node; in jffs2_link_node_ref()
597 dbg_noderef("Last node at %p is (%08x,%p)\n", ref, ref->flash_offset, in jffs2_link_node_ref()
598 ref->next_in_ino); in jffs2_link_node_ref()
600 while (ref->flash_offset != REF_EMPTY_NODE) { in jffs2_link_node_ref()
601 if (ref->flash_offset == REF_LINK_NODE) in jffs2_link_node_ref()
602 ref = ref->next_in_ino; in jffs2_link_node_ref()
607 dbg_noderef("New ref is %p (%08x becomes %08x,%p) len 0x%x\n", ref, in jffs2_link_node_ref()
608 ref->flash_offset, ofs, ref->next_in_ino, len); in jffs2_link_node_ref()
610 ref->flash_offset = ofs; in jffs2_link_node_ref()
612 if (!jeb->first_node) { in jffs2_link_node_ref()
613 jeb->first_node = ref; in jffs2_link_node_ref()
614 BUG_ON(ref_offset(ref) != jeb->offset); in jffs2_link_node_ref()
615 } else if (unlikely(ref_offset(ref) != jeb->offset + c->sector_size - jeb->free_size)) { in jffs2_link_node_ref()
616 uint32_t last_len = ref_totlen(c, jeb, jeb->last_node); in jffs2_link_node_ref()
618 …JFFS2_ERROR("Adding new ref %p at (0x%08x-0x%08x) not immediately after previous (0x%08x-0x%08x)\n… in jffs2_link_node_ref()
620 ref_offset(jeb->last_node), in jffs2_link_node_ref()
621 ref_offset(jeb->last_node)+last_len); in jffs2_link_node_ref()
624 jeb->last_node = ref; in jffs2_link_node_ref()
627 ref->next_in_ino = ic->nodes; in jffs2_link_node_ref()
628 ic->nodes = ref; in jffs2_link_node_ref()
630 ref->next_in_ino = NULL; in jffs2_link_node_ref()
635 c->unchecked_size += len; in jffs2_link_node_ref()
636 jeb->unchecked_size += len; in jffs2_link_node_ref()
641 c->used_size += len; in jffs2_link_node_ref()
642 jeb->used_size += len; in jffs2_link_node_ref()
646 c->dirty_size += len; in jffs2_link_node_ref()
647 jeb->dirty_size += len; in jffs2_link_node_ref()
650 c->free_size -= len; in jffs2_link_node_ref()
651 jeb->free_size -= len; in jffs2_link_node_ref()
655 ref->__totlen = len; in jffs2_link_node_ref()
663 uint32_t size) in jffs2_scan_dirty_space() argument
665 if (!size) in jffs2_scan_dirty_space()
667 if (unlikely(size > jeb->free_size)) { in jffs2_scan_dirty_space()
668 pr_crit("Dirty space 0x%x larger then free_size 0x%x (wasted 0x%x)\n", in jffs2_scan_dirty_space()
669 size, jeb->free_size, jeb->wasted_size); in jffs2_scan_dirty_space()
673 if (jeb->last_node && ref_obsolete(jeb->last_node)) { in jffs2_scan_dirty_space()
675 jeb->last_node->__totlen += size; in jffs2_scan_dirty_space()
677 c->dirty_size += size; in jffs2_scan_dirty_space()
678 c->free_size -= size; in jffs2_scan_dirty_space()
679 jeb->dirty_size += size; in jffs2_scan_dirty_space()
680 jeb->free_size -= size; in jffs2_scan_dirty_space()
682 uint32_t ofs = jeb->offset + c->sector_size - jeb->free_size; in jffs2_scan_dirty_space()
685 jffs2_link_node_ref(c, jeb, ofs, size, NULL); in jffs2_scan_dirty_space()
703 jeb = &c->blocks[ref->flash_offset / c->sector_size]; in __ref_totlen()
706 if (unlikely(ref != jeb->last_node)) { in __ref_totlen()
707 pr_crit("ref %p @0x%08x is not jeb->last_node (%p @0x%08x)\n", in __ref_totlen()
708 ref, ref_offset(ref), jeb->last_node, in __ref_totlen()
709 jeb->last_node ? in __ref_totlen()
710 ref_offset(jeb->last_node) : 0); in __ref_totlen()
713 ref_end = jeb->offset + c->sector_size - jeb->free_size; in __ref_totlen()
715 return ref_end - ref_offset(ref); in __ref_totlen()
726 if (unlikely(ret != ref->__totlen)) { in __jffs2_ref_totlen()
728 jeb = &c->blocks[ref->flash_offset / c->sector_size]; in __jffs2_ref_totlen()
730 pr_crit("Totlen for ref at %p (0x%08x-0x%08x) miscalculated as 0x%x instead of %x\n", in __jffs2_ref_totlen()
731 ref, ref_offset(ref), ref_offset(ref) + ref->__totlen, in __jffs2_ref_totlen()
732 ret, ref->__totlen); in __jffs2_ref_totlen()
734 pr_crit("next %p (0x%08x-0x%08x)\n", in __jffs2_ref_totlen()
736 ref_offset(ref_next(ref)) + ref->__totlen); in __jffs2_ref_totlen()
738 pr_crit("No next ref. jeb->last_node is %p\n", in __jffs2_ref_totlen()
739 jeb->last_node); in __jffs2_ref_totlen()
741 pr_crit("jeb->wasted_size %x, dirty_size %x, used_size %x, free_size %x\n", in __jffs2_ref_totlen()
742 jeb->wasted_size, jeb->dirty_size, jeb->used_size, in __jffs2_ref_totlen()
743 jeb->free_size); in __jffs2_ref_totlen()
751 ret = ref->__totlen; in __jffs2_ref_totlen()