]> git.sur5r.net Git - u-boot/commitdiff
fs: Fully populate the filesystem method struct
authorSimon Glass <sjg@chromium.org>
Wed, 26 Dec 2012 09:53:29 +0000 (09:53 +0000)
committerTom Rini <trini@ti.com>
Mon, 4 Mar 2013 19:19:56 +0000 (14:19 -0500)
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>
fs/fs.c

diff --git a/fs/fs.c b/fs/fs.c
index 2c9f2c5ac1b01ec882547c5995e034206c9a2729..66835e2c747bd9455324147036d098ee27fb5384 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -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;
 }