📄 node40_repair.c
字号:
}errno_t node40_check_struct(reiser4_node_t *node, uint8_t mode) { errno_t res; aal_assert("vpf-194", node != NULL); /* Check the content of the node40 header. */ if ((res = node40_count_check(node, mode))) return res; if (nh_get_num_items(node) == 0) { uint32_t offset = sizeof(node40_header_t); return node40_space_check(node, offset, mode); } /* Count looks ok. Recover the item array. */ res = node40_ih_array_check(node, mode); if (repair_error_fatal(res)) return res; res |= node40_iplug_check(node, mode); return res;}errno_t node40_corrupt(reiser4_node_t *entity, uint16_t options) { int i; for(i = 0; i < nh_get_num_items(entity) + 1; i++) { if (aal_test_bit(&options, i)) { node40_set_offset_at(entity, i, 0xafff); } } return 0;}int64_t node40_insert_raw(reiser4_node_t *entity, pos_t *pos, trans_hint_t *hint) { aal_assert("vpf-965", entity != NULL); aal_assert("vpf-966", pos != NULL); aal_assert("vpf-1368", hint != NULL); return node40_modify(entity, pos, hint, hint->plug->repair->insert_raw);}errno_t node40_pack(reiser4_node_t *entity, aal_stream_t *stream) { node40_header_t *head; reiser4_place_t place; uint16_t num; pos_t *pos; rid_t pid; aal_assert("umka-2596", entity != NULL); aal_assert("umka-2598", stream != NULL); pid = entity->plug->p.id.id; aal_stream_write(stream, &pid, sizeof(pid)); /* Write node block number. */ aal_stream_write(stream, &entity->block->nr, sizeof(entity->block->nr)); /* Pack the node content. */ /* Node header w/out magic and padding. */ head = nh(entity->block); aal_stream_write(stream, &head->num_items, sizeof(head->num_items)); aal_stream_write(stream, &head->free_space, sizeof(head->free_space)); aal_stream_write(stream, &head->free_space_start, sizeof(head->free_space_start)); aal_stream_write(stream, &head->mkfs_id, sizeof(head->mkfs_id)); aal_stream_write(stream, &head->flush_id, sizeof(head->flush_id)); aal_stream_write(stream, &head->flags, sizeof(head->flags)); aal_stream_write(stream, &head->level, sizeof(head->level)); /* All items. */ num = nh_get_num_items(entity); pos = &place.pos; pos->unit = MAX_UINT32; /* Pack all item headers. */ for (pos->item = 0; pos->item < num; pos->item++) { void *ih = node40_ih_at(entity, pos->item); aal_stream_write(stream, ih, ih_size(entity->keypol)); } /* Pack all item bodies. */ for (pos->item = 0; pos->item < num; pos->item++) { if (node40_fetch(entity, pos, &place)) return -EINVAL; if (place.plug->repair->pack) { /* Pack body. */ if (objcall(&place, repair->pack, stream)) return -EINVAL; } else { /* Do not pack body. */ aal_stream_write(stream, node40_ib_at(entity, pos->item), node40_len(entity, &place.pos)); } } return 0;}reiser4_node_t *node40_unpack(aal_block_t *block, reiser4_key_plug_t *kplug, aal_stream_t *stream){ node40_header_t *head; reiser4_node_t *entity; reiser4_place_t place; uint32_t read; uint16_t num; pos_t *pos; aal_assert("umka-2597", block != NULL); aal_assert("umka-2632", kplug != NULL); aal_assert("umka-2599", stream != NULL); if (!(entity = aal_calloc(sizeof(*entity), 0))) return NULL; if (!(entity = node40_prepare(block, kplug))) return NULL; node40_mkdirty(entity); /* Unpack the node content. */ /* Node header w/out magic and padding. */ head = nh(entity->block); read = aal_stream_read(stream, &head->num_items, sizeof(head->num_items)); if (read != sizeof(head->num_items)) goto error_free_entity; read = aal_stream_read(stream, &head->free_space, sizeof(head->free_space)); if (read != sizeof(head->free_space)) goto error_free_entity; read = aal_stream_read(stream, &head->free_space_start, sizeof(head->free_space_start)); if (read != sizeof(head->free_space_start)) goto error_free_entity; read = aal_stream_read(stream, &head->mkfs_id, sizeof(head->mkfs_id)); if (read != sizeof(head->mkfs_id)) goto error_free_entity; read = aal_stream_read(stream, &head->flush_id, sizeof(head->flush_id)); if (read != sizeof(head->flush_id)) goto error_free_entity; read = aal_stream_read(stream, &head->flags, sizeof(head->flags)); if (read != sizeof(head->flags)) goto error_free_entity; read = aal_stream_read(stream, &head->level, sizeof(head->level)); if (read != sizeof(head->level)) goto error_free_entity; /* Set the magic and the pid. */ nh_set_magic(entity, NODE40_MAGIC); nh_set_pid(entity, node40_plug.p.id.id); /* All items. */ num = nh_get_num_items(entity); pos = &place.pos; pos->unit = MAX_UINT32; /* Unpack all item headers. */ for (pos->item = 0; pos->item < num; pos->item++) { void *ih = node40_ih_at(entity, pos->item); read = aal_stream_read(stream, ih, ih_size(entity->keypol)); if (read != ih_size(entity->keypol)) goto error_free_entity; } /* Unpack all item bodies. */ for (pos->item = 0; pos->item < num; pos->item++) { if (node40_fetch(entity, pos, &place)) goto error_free; if (place.plug->repair->unpack) { /* Unpack body. */ if (objcall(&place, repair->unpack, stream)) goto error_free_entity; } else { void *ib = node40_ib_at(entity, pos->item); uint32_t len = node40_len(entity, &place.pos); /* Do not unpack body. */ if (aal_stream_read(stream, ib, len) != (int32_t)len) goto error_free_entity; } } return entity; error_free_entity: aal_error("Can't unpack the node (%llu). " "Stream is over?", block->nr); error_free: aal_free(entity); return NULL;}/* Prepare text node description and push it into specified @stream. */void node40_print(reiser4_node_t *entity, aal_stream_t *stream, uint32_t start, uint32_t count, uint16_t options) { void *ih; char *key; pos_t pos; uint8_t pol; uint8_t level; uint32_t last, num; reiser4_place_t place; aal_assert("vpf-023", entity != NULL); aal_assert("umka-457", stream != NULL); level = node40_get_level(entity); /* Print node header. */ aal_stream_format(stream, "NODE (%llu) LEVEL=%u ITEMS=%u " "SPACE=%u MKFS ID=0x%x FLUSH=0x%llx\n", entity->block->nr, level, node40_items(entity), node40_space(entity), nh_get_mkfs_id(entity), nh_get_flush_id(entity)); pos.unit = MAX_UINT32; if (start == MAX_UINT32) start = 0; num = node40_items(entity); if (node40_count_valid(entity)) { last = num; } else { last = node40_estimate_count(entity); if (last > nh_get_num_items(entity)) last = nh_get_num_items(entity); } if (count != MAX_UINT32 && last > start + count) last = start + count; pol = entity->keypol; /* Loop through the all items */ for (pos.item = start; pos.item < last; pos.item++) { if (pos.item) { aal_stream_format(stream, "----------------------------" "------------------------------------" "--------------\n"); } place.plug = NULL; node40_fetch(entity, &pos, &place); ih = node40_ih_at(entity, pos.item); key = print_key(node40_core, &place.key); aal_stream_format(stream, "#%u%s %s (%s): [%s] OFF=%u, " "LEN=%u, flags=0x%x", pos.item, pos.item >= num ? "D" : " ", place.plug ? reiser4_igname[place.plug->p.id.group] : "UNKN", place.plug ? place.plug->p.label : "UNKN", key, ih_get_offset(ih, pol), place.len, ih_get_flags(ih, pol)); /* Printing item by means of calling item print method if it is implemented. If it is not, then print common item information like key, len, etc. */ if (place.plug && place.plug->debug->print && place.body - entity->block->data + place.len < entity->block->size) { objcall(&place, debug->print, stream, options); } else { aal_stream_format(stream, "\n"); } } aal_stream_format(stream, "============================" "====================================" "==============\n");}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -