mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-07-06 06:21:51 +00:00
fs: Use filesystem methods instead of switch()
We can use the available methods and avoid using switch(). When the filesystem is not supported, we fall through to the 'unsupported' methods: fs_probe_unsupported() prints an error, so the others do not need to. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Tom Rini <trini@ti.com>
This commit is contained in:
parent
436e2b7319
commit
c6f548d232
1 changed files with 26 additions and 34 deletions
60
fs/fs.c
60
fs/fs.c
|
@ -35,14 +35,12 @@ static inline int fs_probe_unsupported(void)
|
||||||
|
|
||||||
static inline int fs_ls_unsupported(const char *dirname)
|
static inline int fs_ls_unsupported(const char *dirname)
|
||||||
{
|
{
|
||||||
printf("** Unrecognized filesystem type **\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int fs_read_unsupported(const char *filename, ulong addr,
|
static inline int fs_read_unsupported(const char *filename, ulong addr,
|
||||||
int offset, int len)
|
int offset, int len)
|
||||||
{
|
{
|
||||||
printf("** Unrecognized filesystem type **\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,6 +187,20 @@ static struct fstype_info fstypes[] = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static struct fstype_info *fs_get_info(int fstype)
|
||||||
|
{
|
||||||
|
struct fstype_info *info;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
|
||||||
|
if (fstype == info->fstype)
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return the 'unsupported' sentinel */
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
|
int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
|
||||||
{
|
{
|
||||||
struct fstype_info *info;
|
struct fstype_info *info;
|
||||||
|
@ -229,17 +241,9 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
|
||||||
|
|
||||||
static void fs_close(void)
|
static void fs_close(void)
|
||||||
{
|
{
|
||||||
switch (fs_type) {
|
struct fstype_info *info = fs_get_info(fs_type);
|
||||||
case FS_TYPE_FAT:
|
|
||||||
fs_close_fat();
|
|
||||||
break;
|
|
||||||
case FS_TYPE_EXT:
|
|
||||||
fs_close_ext();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
info->close();
|
||||||
fs_type = FS_TYPE_ANY;
|
fs_type = FS_TYPE_ANY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,17 +251,9 @@ int fs_ls(const char *dirname)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (fs_type) {
|
struct fstype_info *info = fs_get_info(fs_type);
|
||||||
case FS_TYPE_FAT:
|
|
||||||
ret = fs_ls_fat(dirname);
|
ret = info->ls(dirname);
|
||||||
break;
|
|
||||||
case FS_TYPE_EXT:
|
|
||||||
ret = fs_ls_ext(dirname);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ret = fs_ls_unsupported(dirname);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fs_close();
|
fs_close();
|
||||||
|
|
||||||
|
@ -266,20 +262,16 @@ int fs_ls(const char *dirname)
|
||||||
|
|
||||||
int fs_read(const char *filename, ulong addr, int offset, int len)
|
int fs_read(const char *filename, ulong addr, int offset, int len)
|
||||||
{
|
{
|
||||||
|
struct fstype_info *info = fs_get_info(fs_type);
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
switch (fs_type) {
|
ret = info->read(filename, addr, offset, len);
|
||||||
case FS_TYPE_FAT:
|
|
||||||
ret = fs_read_fat(filename, addr, offset, len);
|
|
||||||
break;
|
|
||||||
case FS_TYPE_EXT:
|
|
||||||
ret = fs_read_ext(filename, addr, offset, len);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ret = fs_read_unsupported(filename, addr, offset, len);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* If we requested a specific number of bytes, check we got it */
|
||||||
|
if (ret >= 0 && len && ret != len) {
|
||||||
|
printf("** Unable to read file %s **\n", filename);
|
||||||
|
ret = -1;
|
||||||
|
}
|
||||||
fs_close();
|
fs_close();
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue