@@ -69,6 +69,8 @@ int ext4fs_read_file(struct ext2fs_node *node, loff_t pos,
short status;
struct ext_block_cache cache;
+ assert(IS_ALIGNED(pos, blocksize));
+
ext_cache_init(&cache);
/* Adjust len so it we can't read past the end of the file. */
@@ -259,6 +261,26 @@ int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
return ext4fs_read(buf, offset, len, len_read);
}
+int ext4_get_blocksize(const char *filename)
+{
+ struct ext_filesystem *fs;
+ int log2blksz;
+ int log2_fs_blocksize;
+ loff_t file_len;
+ int ret;
+
+ ret = ext4fs_open(filename, &file_len);
+ if (ret < 0) {
+ printf("** File not found %s **\n", filename);
+ return -1;
+ }
+ fs = get_fs();
+ log2blksz = fs->dev_desc->log2blksz;
+ log2_fs_blocksize = LOG2_BLOCK_SIZE(ext4fs_file->data) - log2blksz;
+
+ return (1 << (log2_fs_blocksize + log2blksz));
+}
+
int ext4fs_uuid(char *uuid_str)
{
if (ext4fs_root == NULL)
@@ -236,7 +236,7 @@ static struct fstype_info fstypes[] = {
.exists = ext4fs_exists,
.size = ext4fs_size,
.read = ext4_read_file,
- .get_blocksize = fs_get_blocksize_unsupported,
+ .get_blocksize = ext4_get_blocksize,
#ifdef CONFIG_CMD_EXT4_WRITE
.write = ext4_write_file,
.ln = ext4fs_create_link,
@@ -161,6 +161,7 @@ int ext4fs_probe(struct blk_desc *fs_dev_desc,
struct disk_partition *fs_partition);
int ext4_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
loff_t *actread);
+int ext4_get_blocksize(const char *filename);
int ext4_read_superblock(char *buffer);
int ext4fs_uuid(char *uuid_str);
void ext_cache_init(struct ext_block_cache *cache);
Just add ext4_get_blocksize() and a new assert() in ext4fs_read_file(). Signed-off-by: Qu Wenruo <wqu@suse.com> --- Several cleanup candicate: 1. ext_fs->blksz is never populated, thus it's always 0 We can not easily grab blocksize just like btrfs in this case. Thus we have to go the same calculation in ext4fs_read_file(). 2. can not easily cleanup @skipfirst in ext4fs_read_file() It seems to screw up with soft link read. --- fs/ext4/ext4fs.c | 22 ++++++++++++++++++++++ fs/fs.c | 2 +- include/ext4fs.h | 1 + 3 files changed, 24 insertions(+), 1 deletion(-)