aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorSimon Glass2012-12-26 03:53:30 -0600
committerTom Rini2013-03-04 13:19:56 -0600
commitc6f548d232c47a1691124d05c90fe9fb652e6874 (patch)
tree3e84bee29b963c6b158a20d6a7fc438fc079a2ef /fs
parent436e2b731979afc904b2a39f1b2fbb2370f08cb4 (diff)
downloadu-boot-c6f548d232c47a1691124d05c90fe9fb652e6874.tar.gz
u-boot-c6f548d232c47a1691124d05c90fe9fb652e6874.tar.xz
u-boot-c6f548d232c47a1691124d05c90fe9fb652e6874.zip
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>
Diffstat (limited to 'fs')
-rw-r--r--fs/fs.c60
1 files changed, 26 insertions, 34 deletions
diff --git a/fs/fs.c b/fs/fs.c
index 66835e2c74..856d8baf92 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -35,14 +35,12 @@ static inline int fs_probe_unsupported(void)
35 35
36static inline int fs_ls_unsupported(const char *dirname) 36static inline int fs_ls_unsupported(const char *dirname)
37{ 37{
38 printf("** Unrecognized filesystem type **\n");
39 return -1; 38 return -1;
40} 39}
41 40
42static inline int fs_read_unsupported(const char *filename, ulong addr, 41static inline int fs_read_unsupported(const char *filename, ulong addr,
43 int offset, int len) 42 int offset, int len)
44{ 43{
45 printf("** Unrecognized filesystem type **\n");
46 return -1; 44 return -1;
47} 45}
48 46
@@ -189,6 +187,20 @@ static struct fstype_info fstypes[] = {
189 }, 187 },
190}; 188};
191 189
190static struct fstype_info *fs_get_info(int fstype)
191{
192 struct fstype_info *info;
193 int i;
194
195 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
196 if (fstype == info->fstype)
197 return info;
198 }
199
200 /* Return the 'unsupported' sentinel */
201 return info;
202}
203
192int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype) 204int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
193{ 205{
194 struct fstype_info *info; 206 struct fstype_info *info;
@@ -229,17 +241,9 @@ int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
229 241
230static void fs_close(void) 242static void fs_close(void)
231{ 243{
232 switch (fs_type) { 244 struct fstype_info *info = fs_get_info(fs_type);
233 case FS_TYPE_FAT:
234 fs_close_fat();
235 break;
236 case FS_TYPE_EXT:
237 fs_close_ext();
238 break;
239 default:
240 break;
241 }
242 245
246 info->close();
243 fs_type = FS_TYPE_ANY; 247 fs_type = FS_TYPE_ANY;
244} 248}
245 249
@@ -247,17 +251,9 @@ int fs_ls(const char *dirname)
247{ 251{
248 int ret; 252 int ret;
249 253
250 switch (fs_type) { 254 struct fstype_info *info = fs_get_info(fs_type);
251 case FS_TYPE_FAT: 255
252 ret = fs_ls_fat(dirname); 256 ret = info->ls(dirname);
253 break;
254 case FS_TYPE_EXT:
255 ret = fs_ls_ext(dirname);
256 break;
257 default:
258 ret = fs_ls_unsupported(dirname);
259 break;
260 }
261 257
262 fs_close(); 258 fs_close();
263 259
@@ -266,20 +262,16 @@ int fs_ls(const char *dirname)
266 262
267int fs_read(const char *filename, ulong addr, int offset, int len) 263int fs_read(const char *filename, ulong addr, int offset, int len)
268{ 264{
265 struct fstype_info *info = fs_get_info(fs_type);
269 int ret; 266 int ret;
270 267
271 switch (fs_type) { 268 ret = info->read(filename, addr, offset, len);
272 case FS_TYPE_FAT:
273 ret = fs_read_fat(filename, addr, offset, len);
274 break;
275 case FS_TYPE_EXT:
276 ret = fs_read_ext(filename, addr, offset, len);
277 break;
278 default:
279 ret = fs_read_unsupported(filename, addr, offset, len);
280 break;
281 }
282 269
270 /* If we requested a specific number of bytes, check we got it */
271 if (ret >= 0 && len && ret != len) {
272 printf("** Unable to read file %s **\n", filename);
273 ret = -1;
274 }
283 fs_close(); 275 fs_close();
284 276
285 return ret; 277 return ret;