Lines Matching refs:bb
60 struct backed_block *backed_block_iter_next(struct backed_block *bb)
62 return bb->next;
65 unsigned int backed_block_len(struct backed_block *bb)
67 return bb->len;
70 unsigned int backed_block_block(struct backed_block *bb)
72 return bb->block;
75 void *backed_block_data(struct backed_block *bb)
77 assert(bb->type == BACKED_BLOCK_DATA);
78 return bb->data.data;
81 const char *backed_block_filename(struct backed_block *bb)
83 assert(bb->type == BACKED_BLOCK_FILE);
84 return bb->file.filename;
87 int backed_block_fd(struct backed_block *bb)
89 assert(bb->type == BACKED_BLOCK_FD);
90 return bb->fd.fd;
93 int64_t backed_block_file_offset(struct backed_block *bb)
95 assert(bb->type == BACKED_BLOCK_FILE || bb->type == BACKED_BLOCK_FD);
96 if (bb->type == BACKED_BLOCK_FILE) {
97 return bb->file.offset;
98 } else { /* bb->type == BACKED_BLOCK_FD */
99 return bb->fd.offset;
103 uint32_t backed_block_fill_val(struct backed_block *bb)
105 assert(bb->type == BACKED_BLOCK_FILL);
106 return bb->fill.val;
109 enum backed_block_type backed_block_type(struct backed_block *bb)
111 return bb->type;
114 void backed_block_destroy(struct backed_block *bb)
116 if (bb->type == BACKED_BLOCK_FILE) {
117 free(bb->file.filename);
120 free(bb);
133 struct backed_block *bb = bbl->data_blocks;
134 while (bb) {
135 struct backed_block *next = bb->next;
136 backed_block_destroy(bb);
137 bb = next;
148 struct backed_block *bb;
168 for (bb = from->data_blocks; bb; bb = bb->next) {
169 if (bb->next == start) {
170 bb->next = end->next;
180 for (bb = to->data_blocks; bb; bb = bb->next) {
181 if (!bb->next || bb->next->block > start->block) {
182 end->next = bb->next;
183 bb->next = start;
250 struct backed_block *bb;
264 pointer to the last bb that was added, and start searching from
267 bb = bbl->last_used;
269 bb = bbl->data_blocks;
272 for (; bb->next && bb->next->block < new_bb->block; bb = bb->next)
275 if (bb->next == NULL) {
276 bb->next = new_bb;
278 new_bb->next = bb->next;
279 bb->next = new_bb;
283 if (!merge_bb(bbl, bb, new_bb)) {
285 bbl->last_used = bb;
295 struct backed_block *bb = calloc(1, sizeof(struct backed_block));
296 if (bb == NULL) {
300 bb->block = block;
301 bb->len = len;
302 bb->type = BACKED_BLOCK_FILL;
303 bb->fill.val = fill_val;
304 bb->next = NULL;
306 return queue_bb(bbl, bb);
313 struct backed_block *bb = calloc(1, sizeof(struct backed_block));
314 if (bb == NULL) {
318 bb->block = block;
319 bb->len = len;
320 bb->type = BACKED_BLOCK_DATA;
321 bb->data.data = data;
322 bb->next = NULL;
324 return queue_bb(bbl, bb);
331 struct backed_block *bb = calloc(1, sizeof(struct backed_block));
332 if (bb == NULL) {
336 bb->block = block;
337 bb->len = len;
338 bb->type = BACKED_BLOCK_FILE;
339 bb->file.filename = strdup(filename);
340 bb->file.offset = offset;
341 bb->next = NULL;
343 return queue_bb(bbl, bb);
350 struct backed_block *bb = calloc(1, sizeof(struct backed_block));
351 if (bb == NULL) {
355 bb->block = block;
356 bb->len = len;
357 bb->type = BACKED_BLOCK_FD;
358 bb->fd.fd = fd;
359 bb->fd.offset = offset;
360 bb->next = NULL;
362 return queue_bb(bbl, bb);
365 int backed_block_split(struct backed_block_list *bbl, struct backed_block *bb,
372 if (bb->len <= max_len) {
381 *new_bb = *bb;
383 new_bb->len = bb->len - max_len;
384 new_bb->block = bb->block + max_len / bbl->block_size;
385 new_bb->next = bb->next;
386 bb->next = new_bb;
387 bb->len = max_len;
389 switch (bb->type) {
391 new_bb->data.data = (char *)bb->data.data + max_len;