diff --git a/fs/reiserfs.c b/fs/reiserfs.c index 04d3315..47ba375 100644 --- a/fs/reiserfs.c +++ b/fs/reiserfs.c @@ -25,11 +25,12 @@ */ #if 0 -# define GRUB_REISERFS_DEBUG # define GRUB_REISERFS_JOURNALING # define GRUB_HEXDUMP #endif +#define GRUB_REISERFS_DEBUG 0 + #include #include #include @@ -514,17 +515,23 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data, if (grub_errno) goto fail; current_level = grub_le_to_cpu16 (block_header->level); +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs_tree", " at level %d\n", current_level); +#endif if (current_level >= previous_level) { +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs_tree", "level loop detected, aborting\n"); +#endif grub_error (GRUB_ERR_FILE_READ_ERROR, "level loop"); goto fail; } previous_level = current_level; item_count = grub_le_to_cpu16 (block_header->item_count); +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs_tree", " number of contained items : %d\n", item_count); +#endif if (current_level > 1) { /* Internal node. Navigate to the child that should contain @@ -540,7 +547,7 @@ grub_reiserfs_get_item (struct grub_reiserfs_data *data, && grub_reiserfs_compare_keys (key, &(keys[i])) >= 0; i++) { -#ifdef GRUB_REISERFS_DEBUG +#if GRUB_REISERFS_DEBUG >= 2 grub_printf("i %03d/%03d ", i + 1, item_count + 1); grub_reiserfs_print_key (&(keys[i])); #endif @@ -733,7 +740,9 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, goto fail; block_number = item->block_number; block_position = item->block_position; +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs", "Iterating directory...\n"); +#endif do { struct grub_reiserfs_directory_header *directory_headers; @@ -749,7 +758,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, if (grub_errno) goto fail; -#if 0 +#if GRUB_REISERFS_DEBUG >= 2 if (grub_le_to_cpu16 (block_header->level) != 1) { grub_error (GRUB_ERR_TEST_FAILURE, @@ -825,7 +834,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, entry_version = grub_le_to_cpu16 (entry_item->header.version); entry_block_number = entry_item->block_number; -#if 0 +#if GRUB_REISERFS_DEBUG >= 2 grub_dprintf ("reiserfs", "version %04x block %08x (%08x) position %08x\n", entry_version, entry_block_number, @@ -842,7 +851,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, (char *) &entry_v1_stat); if (grub_errno) goto fail; -#if 0 +#if GRUB_REISERFS_DEBUG >= 2 grub_dprintf ("reiserfs", "%04x %04x %04x %04x %08x %08x | %08x %08x %08x %08x\n", grub_le_to_cpu16 (entry_v1_stat.mode), @@ -884,7 +893,7 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, (char *) &entry_v2_stat); if (grub_errno) goto fail; -#if 0 +#if GRUB_REISERFS_DEBUG >= 2 grub_dprintf ("reiserfs", "%04x %04x %08x %08x%08x | %08x %08x %08x %08x | %08x %08x %08x\n", grub_le_to_cpu16 (entry_v2_stat.mode), @@ -923,19 +932,23 @@ grub_reiserfs_iterate_dir (grub_fshelp_node_t item, } else { +#if GRUB_REISERFS_DEBUG >= 1 /* Pseudo file ".." never has stat block. */ if (grub_strcmp (entry_name, "..")) grub_dprintf ("reiserfs", "Warning : %s has no stat block !\n", entry_name); +#endif grub_free (entry_item); continue; } } if (hook (entry_name, entry_type, entry_item)) { +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs", "Found : %s, type=%d\n", entry_name, entry_type); +#endif ret = 1; goto found; } @@ -1046,9 +1059,11 @@ grub_reiserfs_open (struct grub_file *file, const char *name) goto fail; file->size = (grub_off_t) grub_le_to_cpu64 (entry_v2_stat.size); } +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs", "file size : %d (%08x%08x)\n", (unsigned int) file->size, (unsigned int) (file->size >> 32), (unsigned int) file->size); +#endif file->offset = 0; file->data = found; return GRUB_ERR_NONE; @@ -1087,12 +1102,14 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) initial_position = file->offset; current_position = 0; final_position = MIN (len + initial_position, file->size); +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs", "Reading from %lld to %lld (%lld instead of requested %ld)\n", (unsigned long long) initial_position, (unsigned long long) final_position, (unsigned long long) (final_position - initial_position), (unsigned long) len); +#endif while (current_position < final_position) { grub_reiserfs_set_key_offset (&key, current_key_offset); @@ -1106,16 +1123,20 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) { case GRUB_REISERFS_DIRECT: block = found.block_number * (block_size >> GRUB_DISK_SECTOR_BITS); +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs_blocktype", "D: %u\n", (unsigned) block); +#endif if (initial_position < current_position + item_size) { offset = MAX ((signed) (initial_position - current_position), 0); length = (MIN (item_size, final_position - current_position) - offset); +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs", "Reading direct block %u from %u to %u...\n", (unsigned) block, (unsigned) offset, (unsigned) (offset + length)); +#endif found.data->disk->read_hook = file->read_hook; grub_disk_read (found.data->disk, block, @@ -1150,18 +1171,22 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) { block = grub_le_to_cpu32 (indirect_block_ptr[indirect_block]) * (block_size >> GRUB_DISK_SECTOR_BITS); +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs_blocktype", "I: %u\n", (unsigned) block); +#endif if (current_position + block_size >= initial_position) { offset = MAX ((signed) (initial_position - current_position), 0); length = (MIN (block_size, final_position - current_position) - offset); +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs", "Reading indirect block %u from %u to %u...\n", (unsigned) block, (unsigned) offset, (unsigned) (offset + length)); -#if 0 +#endif +#if GRUB_REISERFS_DEBUG >= 2 grub_dprintf ("reiserfs", "\nib=%04d/%04d, ip=%d, cp=%d, fp=%d, off=%d, l=%d, tl=%d\n", indirect_block + 1, indirect_block_count, @@ -1187,55 +1212,13 @@ grub_reiserfs_read (grub_file_t file, char *buf, grub_size_t len) current_key_offset = current_position + 1; } +#if GRUB_REISERFS_DEBUG >= 1 grub_dprintf ("reiserfs", "Have successfully read %lld bytes (%ld requested)\n", (unsigned long long) (current_position - initial_position), (unsigned long) len); +#endif return current_position - initial_position; -/* - switch (found.type) - { - case GRUB_REISERFS_DIRECT: - read_length = MIN (len, item_size - file->offset); - grub_disk_read (found.data->disk, - (found.block_number * block_size) / GRUB_DISK_SECTOR_SIZE, - grub_le_to_cpu16 (found.header.item_location) + file->offset, - read_length, buf); - if (grub_errno) - goto fail; - break; - case GRUB_REISERFS_INDIRECT: - indirect_block_count = item_size / sizeof (*indirect_block_ptr); - indirect_block_ptr = grub_malloc (item_size); - if (!indirect_block_ptr) - goto fail; - grub_disk_read (found.data->disk, - (found.block_number * block_size) / GRUB_DISK_SECTOR_SIZE, - grub_le_to_cpu16 (found.header.item_location), - item_size, (char *) indirect_block_ptr); - if (grub_errno) - goto fail; - len = MIN (len, file->size - file->offset); - for (indirect_block = file->offset / block_size; - indirect_block < indirect_block_count && read_length < len; - indirect_block++) - { - read = MIN (block_size, len - read_length); - grub_disk_read (found.data->disk, - (grub_le_to_cpu32 (indirect_block_ptr[indirect_block]) * block_size) / GRUB_DISK_SECTOR_SIZE, - file->offset % block_size, read, - ((void *) buf) + read_length); - if (grub_errno) - goto fail; - read_length += read; - } - grub_free (indirect_block_ptr); - break; - default: - goto fail; - } - - return read_length;*/ fail: grub_free (indirect_block_ptr);