diff options
author | Simon Glass <sjg@chromium.org> | 2012-12-26 09:53:29 +0000 |
---|---|---|
committer | Tom Rini <trini@ti.com> | 2013-03-04 14:19:56 -0500 |
commit | 436e2b731979afc904b2a39f1b2fbb2370f08cb4 (patch) | |
tree | 23676e587914d61df1e9757cec378846af592672 /fs/fs.c | |
parent | 293d7fbd47f473d8a6b01a5f80d7faa5cd6b67b3 (diff) | |
download | u-boot-436e2b731979afc904b2a39f1b2fbb2370f08cb4.tar.gz |
fs: Fully populate the filesystem method struct
There is a structure in fs.c with just a probe method. By adding methods
for other operations, we can avoid lots of #ifdefs and switch()s. As a
first step, create the structure ready for use.
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@ti.com>
Diffstat (limited to 'fs/fs.c')
-rw-r--r-- | fs/fs.c | 56 |
1 files changed, 47 insertions, 9 deletions
@@ -27,6 +27,12 @@ static block_dev_desc_t *fs_dev_desc; static disk_partition_t fs_partition; static int fs_type = FS_TYPE_ANY; +static inline int fs_probe_unsupported(void) +{ + printf("** Unrecognized filesystem type **\n"); + return -1; +} + static inline int fs_ls_unsupported(const char *dirname) { printf("** Unrecognized filesystem type **\n"); @@ -40,6 +46,10 @@ static inline int fs_read_unsupported(const char *filename, ulong addr, return -1; } +static inline void fs_close_unsupported(void) +{ +} + #ifdef CONFIG_FS_FAT static int fs_probe_fat(void) { @@ -143,29 +153,57 @@ static inline void fs_close_ext(void) #define fs_read_ext fs_read_unsupported #endif -static struct { +struct fstype_info { int fstype; int (*probe)(void); -} fstypes[] = { + int (*ls)(const char *dirname); + int (*read)(const char *filename, ulong addr, int offset, int len); + void (*close)(void); +}; + +static struct fstype_info fstypes[] = { +#ifdef CONFIG_FS_FAT { .fstype = FS_TYPE_FAT, .probe = fs_probe_fat, + .close = fs_close_fat, + .ls = file_fat_ls, + .read = fs_read_fat, }, +#endif +#ifdef CONFIG_FS_EXT4 { .fstype = FS_TYPE_EXT, .probe = fs_probe_ext, + .close = fs_close_ext, + .ls = ext4fs_ls, + .read = fs_read_ext, + }, +#endif + { + .fstype = FS_TYPE_ANY, + .probe = fs_probe_unsupported, + .close = fs_close_unsupported, + .ls = fs_ls_unsupported, + .read = fs_read_unsupported, }, }; int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) { + struct fstype_info *info; int part, i; #ifdef CONFIG_NEEDS_MANUAL_RELOC static int relocated; if (!relocated) { - for (i = 0; i < ARRAY_SIZE(fstypes); i++) - fstypes[i].probe += gd->reloc_off; + for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); + i++, info++) { + info->probe += gd->reloc_off; + info->close += gd->reloc_off; + info->ls += gd->reloc_off; + info->read += gd->reloc_off; + } relocated = 1; } #endif @@ -175,17 +213,17 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) if (part < 0) return -1; - for (i = 0; i < ARRAY_SIZE(fstypes); i++) { - if ((fstype != FS_TYPE_ANY) && (fstype != fstypes[i].fstype)) + for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) { + if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY && + fstype != info->fstype) continue; - if (!fstypes[i].probe()) { - fs_type = fstypes[i].fstype; + if (!info->probe()) { + fs_type = info->fstype; return 0; } } - printf("** Unrecognized filesystem type **\n"); return -1; } |