• Home
  • Raw
  • Download

Lines Matching refs:refcount

38 void ea_refcount_free(ext2_refcount_t refcount)  in ea_refcount_free()  argument
40 if (!refcount) in ea_refcount_free()
43 if (refcount->list) in ea_refcount_free()
44 ext2fs_free_mem(&refcount->list); in ea_refcount_free()
45 ext2fs_free_mem(&refcount); in ea_refcount_free()
50 ext2_refcount_t refcount; in ea_refcount_create() local
54 retval = ext2fs_get_mem(sizeof(struct ea_refcount), &refcount); in ea_refcount_create()
57 memset(refcount, 0, sizeof(struct ea_refcount)); in ea_refcount_create()
61 refcount->size = size; in ea_refcount_create()
65 refcount->size, bytes); in ea_refcount_create()
67 retval = ext2fs_get_mem(bytes, &refcount->list); in ea_refcount_create()
70 memset(refcount->list, 0, bytes); in ea_refcount_create()
72 refcount->count = 0; in ea_refcount_create()
73 refcount->cursor = 0; in ea_refcount_create()
75 *ret = refcount; in ea_refcount_create()
79 ea_refcount_free(refcount); in ea_refcount_create()
87 static void refcount_collapse(ext2_refcount_t refcount) in refcount_collapse() argument
92 list = refcount->list; in refcount_collapse()
93 for (i = 0, j = 0; i < refcount->count; i++) { in refcount_collapse()
102 refcount->count, j); in refcount_collapse()
104 refcount->count = j; in refcount_collapse()
112 static struct ea_refcount_el *insert_refcount_el(ext2_refcount_t refcount, in insert_refcount_el() argument
120 if (refcount->count >= refcount->size) { in insert_refcount_el()
121 new_size = refcount->size + 100; in insert_refcount_el()
125 retval = ext2fs_resize_mem((size_t) refcount->size * in insert_refcount_el()
129 &refcount->list); in insert_refcount_el()
132 refcount->size = new_size; in insert_refcount_el()
134 num = (int) refcount->count - pos; in insert_refcount_el()
138 memmove(&refcount->list[pos+1], &refcount->list[pos], in insert_refcount_el()
141 refcount->count++; in insert_refcount_el()
142 el = &refcount->list[pos]; in insert_refcount_el()
154 static struct ea_refcount_el *get_refcount_el(ext2_refcount_t refcount, in get_refcount_el() argument
161 if (!refcount || !refcount->list) in get_refcount_el()
165 high = (int) refcount->count-1; in get_refcount_el()
166 if (create && ((refcount->count == 0) || in get_refcount_el()
167 (blk > refcount->list[high].ea_blk))) { in get_refcount_el()
168 if (refcount->count >= refcount->size) in get_refcount_el()
169 refcount_collapse(refcount); in get_refcount_el()
171 return insert_refcount_el(refcount, blk, in get_refcount_el()
172 (unsigned) refcount->count); in get_refcount_el()
174 if (refcount->count == 0) in get_refcount_el()
177 if (refcount->cursor >= refcount->count) in get_refcount_el()
178 refcount->cursor = 0; in get_refcount_el()
179 if (blk == refcount->list[refcount->cursor].ea_blk) in get_refcount_el()
180 return &refcount->list[refcount->cursor++]; in get_refcount_el()
192 lowval = refcount->list[low].ea_blk; in get_refcount_el()
193 highval = refcount->list[high].ea_blk; in get_refcount_el()
205 if (blk == refcount->list[mid].ea_blk) { in get_refcount_el()
206 refcount->cursor = mid+1; in get_refcount_el()
207 return &refcount->list[mid]; in get_refcount_el()
209 if (blk < refcount->list[mid].ea_blk) in get_refcount_el()
219 if (refcount->count >= refcount->size) { in get_refcount_el()
220 refcount_collapse(refcount); in get_refcount_el()
221 if (refcount->count < refcount->size) in get_refcount_el()
224 return insert_refcount_el(refcount, blk, low); in get_refcount_el()
229 errcode_t ea_refcount_fetch(ext2_refcount_t refcount, blk_t blk, in ea_refcount_fetch() argument
234 el = get_refcount_el(refcount, blk, 0); in ea_refcount_fetch()
243 errcode_t ea_refcount_increment(ext2_refcount_t refcount, blk_t blk, int *ret) in ea_refcount_increment() argument
247 el = get_refcount_el(refcount, blk, 1); in ea_refcount_increment()
257 errcode_t ea_refcount_decrement(ext2_refcount_t refcount, blk_t blk, int *ret) in ea_refcount_decrement() argument
261 el = get_refcount_el(refcount, blk, 0); in ea_refcount_decrement()
272 errcode_t ea_refcount_store(ext2_refcount_t refcount, blk_t blk, int count) in ea_refcount_store() argument
279 el = get_refcount_el(refcount, blk, count ? 1 : 0); in ea_refcount_store()
286 blk_t ext2fs_get_refcount_size(ext2_refcount_t refcount) in ext2fs_get_refcount_size() argument
288 if (!refcount) in ext2fs_get_refcount_size()
291 return refcount->size; in ext2fs_get_refcount_size()
294 void ea_refcount_intr_begin(ext2_refcount_t refcount) in ea_refcount_intr_begin() argument
296 refcount->cursor = 0; in ea_refcount_intr_begin()
300 blk_t ea_refcount_intr_next(ext2_refcount_t refcount, in ea_refcount_intr_next() argument
306 if (refcount->cursor >= refcount->count) in ea_refcount_intr_next()
308 list = refcount->list; in ea_refcount_intr_next()
309 if (list[refcount->cursor].ea_count) { in ea_refcount_intr_next()
311 *ret = list[refcount->cursor].ea_count; in ea_refcount_intr_next()
312 return list[refcount->cursor++].ea_blk; in ea_refcount_intr_next()
314 refcount->cursor++; in ea_refcount_intr_next()
321 errcode_t ea_refcount_validate(ext2_refcount_t refcount, FILE *out) in ea_refcount_validate() argument
327 if (refcount->count > refcount->size) { in ea_refcount_validate()
331 for (i=1; i < refcount->count; i++) { in ea_refcount_validate()
332 if (refcount->list[i-1].ea_blk >= refcount->list[i].ea_blk) { in ea_refcount_validate()
334 bad, i-1, refcount->list[i-1].ea_blk, in ea_refcount_validate()
335 i, refcount->list[i].ea_blk); in ea_refcount_validate()
391 ext2_refcount_t refcount; in main() local
402 retval = ea_refcount_create(size, &refcount); in main()
412 ea_refcount_free(refcount); in main()
413 refcount = 0; in main()
419 retval = ea_refcount_store(refcount, blk, arg); in main()
426 retval = ea_refcount_fetch(refcount, blk, &arg); in main()
435 retval = ea_refcount_increment(refcount, blk, in main()
446 retval = ea_refcount_decrement(refcount, blk, in main()
456 retval = ea_refcount_validate(refcount, stderr); in main()
464 ea_refcount_intr_begin(refcount); in main()
466 blk = ea_refcount_intr_next(refcount, in main()
475 refcount_collapse(refcount); in main()