[PATCH 6/8] fs: fat: rely on higher layer to get block aligned read range
Qu Wenruo
wqu at suse.com
Wed Jun 29 13:38:27 CEST 2022
Just implement fat_get_blocksize() for fat, so that fat_read_file()
always get a block aligned read range.
Unfortunately I'm not experienced enough to cleanup the fat code, thus
further cleanup is appreciated.
Cc: Tom Rini <trini at konsulko.com>
Signed-off-by: Qu Wenruo <wqu at suse.com>
---
fs/fat/fat.c | 13 +++++++++++++
fs/fs.c | 2 +-
include/fat.h | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/fs/fat/fat.c b/fs/fat/fat.c
index dcceccbcee0a..e13035e8e6d1 100644
--- a/fs/fat/fat.c
+++ b/fs/fat/fat.c
@@ -1299,6 +1299,19 @@ int fat_read_file(const char *filename, void *buf, loff_t offset, loff_t len,
return ret;
}
+int fat_get_blocksize(const char *filename)
+{
+ fsdata fsdata = {0};
+ int ret;
+
+ ret = get_fs_info(&fsdata);
+ if (ret)
+ return ret;
+
+ free(fsdata.fatbuf);
+ return fsdata.sect_size;
+}
+
typedef struct {
struct fs_dir_stream parent;
struct fs_dirent dirent;
diff --git a/fs/fs.c b/fs/fs.c
index 3cd2c88a4895..09625f52e913 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -207,7 +207,7 @@ static struct fstype_info fstypes[] = {
.exists = fat_exists,
.size = fat_size,
.read = fat_read_file,
- .get_blocksize = fs_get_blocksize_unsupported,
+ .get_blocksize = fat_get_blocksize,
#if CONFIG_IS_ENABLED(FAT_WRITE)
.write = file_fat_write,
.unlink = fat_unlink,
diff --git a/include/fat.h b/include/fat.h
index a9756fb4cd1b..c03a2bebecef 100644
--- a/include/fat.h
+++ b/include/fat.h
@@ -201,6 +201,7 @@ int file_fat_detectfs(void);
int fat_exists(const char *filename);
int fat_size(const char *filename, loff_t *size);
int file_fat_read(const char *filename, void *buffer, int maxsize);
+int fat_get_blocksize(const char *filename);
int fat_set_blk_dev(struct blk_desc *rbdd, struct disk_partition *info);
int fat_register_device(struct blk_desc *dev_desc, int part_no);
--
2.36.1
More information about the U-Boot
mailing list