diff --git a/fs/ext2.c b/fs/ext2.c index 184b973..0b96909 100644 --- a/fs/ext2.c +++ b/fs/ext2.c @@ -318,7 +318,7 @@ grub_ext2_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) blknr = -1; } - return grub_fshelp_map_block (data->journal, blknr); + return blknr; } /* Read LEN bytes from the file described by DATA starting with byte @@ -329,7 +329,8 @@ grub_ext2_read_file (grub_fshelp_node_t node, unsigned offset, unsigned length), int pos, grub_size_t len, char *buf) { - return grub_fshelp_read_file (node->data->disk, node, read_hook, + return grub_fshelp_read_jour (node->data->journal, + node->data->disk, node, read_hook, pos, len, buf, grub_ext2_read_block, node->inode.size, LOG2_EXT2_BLOCK_SIZE (node->data)); diff --git a/fs/fshelp.c b/fs/fshelp.c index 2fae065..23a019e 100644 --- a/fs/fshelp.c +++ b/fs/fshelp.c @@ -269,6 +269,21 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node, grub_disk_addr_t block), grub_off_t filesize, int log2blocksize) { + return grub_fshelp_read_jour (0, disk, node, read_hook, pos, len, buf, get_block, + filesize, log2blocksize); +} + +grub_ssize_t +grub_fshelp_read_jour (grub_fshelp_journal_t log, + grub_disk_t disk, grub_fshelp_node_t node, + void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, + unsigned offset, + unsigned length), + grub_off_t pos, grub_size_t len, char *buf, + grub_disk_addr_t (*get_block) (grub_fshelp_node_t node, + grub_disk_addr_t block), + grub_off_t filesize, int log2blocksize) +{ grub_disk_addr_t i, blockcnt; int blocksize = 1 << (log2blocksize + GRUB_DISK_SECTOR_BITS); @@ -314,6 +329,8 @@ grub_fshelp_read_file (grub_disk_t disk, grub_fshelp_node_t node, if (blknr) { disk->read_hook = read_hook; + if (! read_hook) + blknr = grub_fshelp_map_block (log, blknr); grub_disk_read (disk, blknr, skipfirst, blockend, buf); diff --git a/include/grub/fshelp.h b/include/grub/fshelp.h index 847f78e..da70e4e 100644 --- a/include/grub/fshelp.h +++ b/include/grub/fshelp.h @@ -108,6 +108,17 @@ EXPORT_FUNC(grub_fshelp_read_file) (grub_disk_t disk, grub_fshelp_node_t node, grub_disk_addr_t block), grub_off_t filesize, int log2blocksize); +grub_ssize_t +EXPORT_FUNC(grub_fshelp_read_jour) (grub_fshelp_journal_t log, + grub_disk_t disk, grub_fshelp_node_t node, + void NESTED_FUNC_ATTR (*read_hook) (grub_disk_addr_t sector, + unsigned offset, + unsigned length), + grub_off_t pos, grub_size_t len, char *buf, + grub_disk_addr_t (*get_block) (grub_fshelp_node_t node, + grub_disk_addr_t block), + grub_off_t filesize, int log2blocksize); + unsigned int EXPORT_FUNC(grub_fshelp_log2blksize) (unsigned int blksize, unsigned int *pow);