38 static int get_heap_comp_val(
struct ubifs_lprops *lprops,
int cat)
70 val1 = get_heap_comp_val(lprops, cat);
73 int ppos = (hpos - 1) / 2;
75 val2 = get_heap_comp_val(heap->
arr[ppos], cat);
81 heap->
arr[ppos] = lprops;
102 int val1, val2, val3, cpos;
104 val1 = get_heap_comp_val(lprops, cat);
107 int ppos = (hpos - 1) / 2;
109 val2 = get_heap_comp_val(heap->
arr[ppos], cat);
115 heap->
arr[ppos] = lprops;
120 ppos = (hpos - 1) / 2;
121 val2 = get_heap_comp_val(heap->
arr[ppos], cat);
133 if (cpos >= heap->
cnt)
135 val2 = get_heap_comp_val(heap->
arr[cpos], cat);
138 if (cpos + 1 < heap->
cnt) {
139 val3 = get_heap_comp_val(heap->
arr[cpos + 1],
146 heap->
arr[cpos] = lprops;
153 if (cpos >= heap->
cnt)
155 val3 = get_heap_comp_val(heap->
arr[cpos], cat);
160 heap->
arr[cpos] = lprops;
185 int cpos, val1, val2;
189 cpos = (((
size_t)lprops >> 4) &
b) + b;
194 val1 = get_heap_comp_val(lprops, cat);
195 val2 = get_heap_comp_val(heap->
arr[cpos], cat);
199 lp = heap->
arr[cpos];
204 heap->
arr[cpos] = lprops;
205 move_up_lpt_heap(c, heap, lprops, cat);
213 heap->
arr[lprops->
hpos] = lprops;
214 move_up_lpt_heap(c, heap, lprops, cat);
226 static void remove_from_lpt_heap(
struct ubifs_info *c,
230 int hpos = lprops->
hpos;
236 if (hpos < heap->
cnt) {
239 adjust_lpt_heap(c, heap, heap->
arr[hpos], hpos, cat);
256 static void lpt_heap_replace(
struct ubifs_info *c,
261 int hpos = new_lprops->
hpos;
282 if (add_to_lpt_heap(c, lprops, cat))
305 lprops->
flags |= cat;
318 static void ubifs_remove_from_cat(
struct ubifs_info *c,
325 remove_from_lpt_heap(c, lprops, cat);
365 lpt_heap_replace(c, old_lprops, new_lprops, cat);
371 list_replace(&old_lprops->
list, &new_lprops->
list);
435 if (lprops->
free > 0)
455 if (old_cat == new_cat) {
462 adjust_lpt_heap(c, heap, lprops, lprops->
hpos, new_cat);
464 ubifs_remove_from_cat(c, lprops, old_cat);
485 if (spc < c->dark_wm)
545 dbg_lp(
"LEB %d, free %d, dirty %d, flags %d",
546 lprops->
lnum, free, dirty, flags);
561 if (!is_lprops_dirty(c, lprops)) {
572 c->
lst.taken_empty_lebs -= 1;
578 if (old_spc < c->dead_wm)
579 c->
lst.total_dead -= old_spc;
587 free =
ALIGN(free, 8);
588 c->
lst.total_free += free - lprops->
free;
593 c->
lst.empty_lebs += 1;
595 c->
lst.empty_lebs -= 1;
600 dirty =
ALIGN(dirty, 8);
601 c->
lst.total_dirty += dirty - lprops->
dirty;
609 c->
lst.idx_lebs -= 1;
611 c->
lst.idx_lebs += 1;
619 if (new_spc < c->dead_wm)
620 c->
lst.total_dead += new_spc;
628 c->
lst.taken_empty_lebs += 1;
630 change_category(c, lprops);
664 int flags_set,
int flags_clean,
int idx_gc_cnt)
677 flags = (lp->
flags | flags_set) & ~flags_clean;
683 ubifs_release_lprops(c);
685 ubifs_err(
"cannot change properties of LEB %d, error %d",
703 int flags_set,
int flags_clean)
716 flags = (lp->
flags | flags_set) & ~flags_clean;
722 ubifs_release_lprops(c);
724 ubifs_err(
"cannot update properties of LEB %d, error %d",
749 ubifs_err(
"cannot read properties of LEB %d, error %d",
757 ubifs_release_lprops(c);
779 lprops = heap->
arr[0];
871 if (!dbg_is_chk_gen(c) && !dbg_is_chk_lprops(c))
876 ubifs_err(
"non-empty LEB %d on empty list (free %d dirty %d flags %d)",
882 ubifs_err(
"taken LEB %d on empty list (free %d dirty %d flags %d)",
892 ubifs_err(
"non-freeable LEB %d on freeable list (free %d dirty %d flags %d)",
898 ubifs_err(
"taken LEB %d on freeable list (free %d dirty %d flags %d)",
906 ubifs_err(
"freeable list count %d expected %d", i,
915 ubifs_err(
"idx_gc list count %d expected %d", i,
922 ubifs_err(
"non-freeable LEB %d on frdi_idx list (free %d dirty %d flags %d)",
928 ubifs_err(
"taken LEB %d on frdi_idx list (free %d dirty %d flags %d)",
934 ubifs_err(
"non-index LEB %d on frdi_idx list (free %d dirty %d flags %d)",
944 for (i = 0; i < heap->
cnt; i++) {
945 lprops = heap->
arr[
i];
947 ubifs_err(
"null ptr in LPT heap cat %d", cat);
950 if (lprops->
hpos != i) {
951 ubifs_err(
"bad ptr in LPT heap cat %d", cat);
955 ubifs_err(
"taken LEB in LPT heap cat %d", cat);
967 int i = 0,
j,
err = 0;
969 if (!dbg_is_chk_gen(c) && !dbg_is_chk_lprops(c))
972 for (i = 0; i < heap->
cnt; i++) {
981 if (lprops->
hpos != i) {
991 ubifs_err(
"lprops %zx lp %zx lprops->lnum %d lp->lnum %d",
992 (
size_t)lprops, (
size_t)lp, lprops->
lnum,
997 for (
j = 0;
j <
i;
j++) {
1011 ubifs_err(
"failed cat %d hpos %d err %d", cat, i, err);
1029 static int scan_check_cb(
struct ubifs_info *c,
1042 ubifs_err(
"bad LEB category %d expected %d",
1077 ubifs_err(
"bad LPT list (category %d)", cat);
1087 if ((lp->
hpos != -1 && heap->
arr[lp->
hpos]->lnum != lnum) ||
1089 ubifs_err(
"bad LPT heap (category %d)", cat);
1118 ret = PTR_ERR(sleb);
1128 int found,
level = 0;
1136 ubifs_err(
"indexing node in data LEB %d:%d",
1144 key_read(c, ubifs_idx_key(c, idx), &snod->
key);
1149 snod->
offs, is_idx);
1162 ubifs_err(
"bad calculated accounting for LEB %d: free %d, dirty %d",
1209 ubifs_err(
"indexing node without indexing flag");
1215 ubifs_err(
"data node with indexing flag");
1233 if (spc < c->dead_wm)
1244 ubifs_err(
"bad accounting of LEB %d: free %d, dirty %d flags %#x, should be free %d, dirty %d",
1271 if (!dbg_is_chk_lprops(c))
1279 err = ubifs_wbuf_sync(&c->
jheads[i].wbuf);
1288 if (err && err != -
ENOSPC)
1297 ubifs_err(
"calculated: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld",
1300 ubifs_err(
"read from lprops: empty_lebs %d, idx_lebs %d, total_free %lld, total_dirty %lld, total_used %lld",
1301 c->
lst.empty_lebs, c->
lst.idx_lebs, c->
lst.total_free,
1302 c->
lst.total_dirty, c->
lst.total_used);
1309 ubifs_err(
"bad dead/dark space accounting");
1310 ubifs_err(
"calculated: total_dead %lld, total_dark %lld",
1312 ubifs_err(
"read from lprops: total_dead %lld, total_dark %lld",
1313 c->
lst.total_dead, c->
lst.total_dark);