blob: 7a4020607a3950e76ca46f53dbc4aa6296f2b55d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warreneefbc3f2012-10-22 06:43:51 +00002/*
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
Stephen Warreneefbc3f2012-10-22 06:43:51 +00004 */
5
Heinrich Schuchardtb4559782020-08-25 17:49:16 +00006#define LOG_CATEGORY LOGC_CORE
7
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Stephen Warreneefbc3f2012-10-22 06:43:51 +00009#include <config.h>
Christian Gmeiner9f9eec32014-11-12 14:35:04 +010010#include <errno.h>
Stephen Warreneefbc3f2012-10-22 06:43:51 +000011#include <common.h>
Simon Glass313112a2019-08-01 09:46:46 -060012#include <env.h>
Simon Glass655306c2020-05-10 11:39:58 -060013#include <lmb.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Joe Hershberger65b905b2015-03-22 17:08:59 -050015#include <mapmem.h>
Stephen Warreneefbc3f2012-10-22 06:43:51 +000016#include <part.h>
17#include <ext4fs.h>
18#include <fat.h>
19#include <fs.h>
Simon Glass11842872012-12-26 09:53:35 +000020#include <sandboxfs.h>
Hans de Goede690c7962015-09-17 18:46:58 -040021#include <ubifs_uboot.h>
Marek BehĂșn98ec1d12017-09-03 17:00:29 +020022#include <btrfs.h>
Simon Glasscbe5d5d2012-12-26 09:53:32 +000023#include <asm/io.h>
Tom Rinia17b7bc2014-11-24 11:50:46 -050024#include <div64.h>
25#include <linux/math64.h>
Mian Yousaf Kaukab961ebe82019-06-18 15:03:44 +020026#include <efi_loader.h>
Joao Marcos Costa29da3742020-07-30 15:33:47 +020027#include <squashfs.h>
Stephen Warreneefbc3f2012-10-22 06:43:51 +000028
Stephen Warren44161af2012-10-30 07:50:47 +000029DECLARE_GLOBAL_DATA_PTR;
30
Simon Glasse3394752016-02-29 15:25:34 -070031static struct blk_desc *fs_dev_desc;
Rob Clark2b7bfd92017-09-09 13:15:55 -040032static int fs_dev_part;
Simon Glassc1c4a8f2020-05-10 11:39:57 -060033static struct disk_partition fs_partition;
Stephen Warreneefbc3f2012-10-22 06:43:51 +000034static int fs_type = FS_TYPE_ANY;
35
Simon Glasse3394752016-02-29 15:25:34 -070036static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
Simon Glassc1c4a8f2020-05-10 11:39:57 -060037 struct disk_partition *fs_partition)
Simon Glass1aede482012-12-26 09:53:29 +000038{
Heinrich Schuchardtb4559782020-08-25 17:49:16 +000039 log_err("** Unrecognized filesystem type **\n");
Simon Glass1aede482012-12-26 09:53:29 +000040 return -1;
41}
42
Stephen Warreneefbc3f2012-10-22 06:43:51 +000043static inline int fs_ls_unsupported(const char *dirname)
44{
Stephen Warreneefbc3f2012-10-22 06:43:51 +000045 return -1;
46}
47
Rob Clark60d74a92017-09-09 13:15:58 -040048/* generic implementation of ls in terms of opendir/readdir/closedir */
49__maybe_unused
50static int fs_ls_generic(const char *dirname)
51{
52 struct fs_dir_stream *dirs;
53 struct fs_dirent *dent;
54 int nfiles = 0, ndirs = 0;
55
56 dirs = fs_opendir(dirname);
57 if (!dirs)
58 return -errno;
59
60 while ((dent = fs_readdir(dirs))) {
61 if (dent->type == FS_DT_DIR) {
62 printf(" %s/\n", dent->name);
63 ndirs++;
Joao Marcos Costa2a7fb152020-07-30 15:33:51 +020064 } else if (dent->type == FS_DT_LNK) {
65 printf(" <SYM> %s\n", dent->name);
66 nfiles++;
Rob Clark60d74a92017-09-09 13:15:58 -040067 } else {
68 printf(" %8lld %s\n", dent->size, dent->name);
69 nfiles++;
70 }
71 }
72
73 fs_closedir(dirs);
74
75 printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs);
76
77 return 0;
78}
79
Stephen Warrend008fbb2014-02-03 13:21:00 -070080static inline int fs_exists_unsupported(const char *filename)
81{
82 return 0;
83}
84
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080085static inline int fs_size_unsupported(const char *filename, loff_t *size)
Stephen Warren3eb58f52014-06-11 12:47:26 -060086{
87 return -1;
88}
89
Simon Glasscbe5d5d2012-12-26 09:53:32 +000090static inline int fs_read_unsupported(const char *filename, void *buf,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080091 loff_t offset, loff_t len,
92 loff_t *actread)
Stephen Warreneefbc3f2012-10-22 06:43:51 +000093{
Stephen Warreneefbc3f2012-10-22 06:43:51 +000094 return -1;
95}
96
Simon Glasseda14ea2013-04-20 08:42:50 +000097static inline int fs_write_unsupported(const char *filename, void *buf,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080098 loff_t offset, loff_t len,
99 loff_t *actwrite)
Simon Glasseda14ea2013-04-20 08:42:50 +0000100{
101 return -1;
102}
103
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100104static inline int fs_ln_unsupported(const char *filename, const char *target)
105{
106 return -1;
107}
108
Simon Glass1aede482012-12-26 09:53:29 +0000109static inline void fs_close_unsupported(void)
110{
111}
112
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100113static inline int fs_uuid_unsupported(char *uuid_str)
114{
115 return -1;
116}
117
Rob Clark2b7bfd92017-09-09 13:15:55 -0400118static inline int fs_opendir_unsupported(const char *filename,
119 struct fs_dir_stream **dirs)
120{
121 return -EACCES;
122}
123
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900124static inline int fs_unlink_unsupported(const char *filename)
125{
126 return -1;
127}
128
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900129static inline int fs_mkdir_unsupported(const char *dirname)
130{
131 return -1;
132}
133
Simon Glass1aede482012-12-26 09:53:29 +0000134struct fstype_info {
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000135 int fstype;
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100136 char *name;
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700137 /*
138 * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This
139 * should be false in most cases. For "virtual" filesystems which
140 * aren't based on a U-Boot block device (e.g. sandbox), this can be
Heinrich Schuchardt99dc17d2018-08-11 15:52:14 +0200141 * set to true. This should also be true for the dummy entry at the end
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700142 * of fstypes[], since that is essentially a "virtual" (non-existent)
143 * filesystem.
144 */
145 bool null_dev_desc_ok;
Simon Glasse3394752016-02-29 15:25:34 -0700146 int (*probe)(struct blk_desc *fs_dev_desc,
Simon Glassc1c4a8f2020-05-10 11:39:57 -0600147 struct disk_partition *fs_partition);
Simon Glass1aede482012-12-26 09:53:29 +0000148 int (*ls)(const char *dirname);
Stephen Warrend008fbb2014-02-03 13:21:00 -0700149 int (*exists)(const char *filename);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800150 int (*size)(const char *filename, loff_t *size);
151 int (*read)(const char *filename, void *buf, loff_t offset,
152 loff_t len, loff_t *actread);
153 int (*write)(const char *filename, void *buf, loff_t offset,
154 loff_t len, loff_t *actwrite);
Simon Glass1aede482012-12-26 09:53:29 +0000155 void (*close)(void);
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100156 int (*uuid)(char *uuid_str);
Rob Clark2b7bfd92017-09-09 13:15:55 -0400157 /*
158 * Open a directory stream. On success return 0 and directory
159 * stream pointer via 'dirsp'. On error, return -errno. See
160 * fs_opendir().
161 */
162 int (*opendir)(const char *filename, struct fs_dir_stream **dirsp);
163 /*
164 * Read next entry from directory stream. On success return 0
165 * and directory entry pointer via 'dentp'. On error return
166 * -errno. See fs_readdir().
167 */
168 int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp);
169 /* see fs_closedir() */
170 void (*closedir)(struct fs_dir_stream *dirs);
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900171 int (*unlink)(const char *filename);
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900172 int (*mkdir)(const char *dirname);
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100173 int (*ln)(const char *filename, const char *target);
Simon Glass1aede482012-12-26 09:53:29 +0000174};
175
176static struct fstype_info fstypes[] = {
177#ifdef CONFIG_FS_FAT
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000178 {
179 .fstype = FS_TYPE_FAT,
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100180 .name = "fat",
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700181 .null_dev_desc_ok = false,
Simon Glass19e38582012-12-26 09:53:33 +0000182 .probe = fat_set_blk_dev,
183 .close = fat_close,
Rob Clark60d74a92017-09-09 13:15:58 -0400184 .ls = fs_ls_generic,
Stephen Warren1d2f9a02014-02-03 13:21:10 -0700185 .exists = fat_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600186 .size = fat_size,
Simon Glass19e38582012-12-26 09:53:33 +0000187 .read = fat_read_file,
Tien Fong Chee87fda0c2019-01-23 14:20:04 +0800188#if CONFIG_IS_ENABLED(FAT_WRITE)
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800189 .write = file_fat_write,
AKASHI Takahiro73b34972018-09-11 15:59:14 +0900190 .unlink = fat_unlink,
AKASHI Takahiro1c24b7b2018-09-11 15:59:10 +0900191 .mkdir = fat_mkdir,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800192#else
Stephen Warren9df25802014-02-03 13:20:59 -0700193 .write = fs_write_unsupported,
AKASHI Takahiro73b34972018-09-11 15:59:14 +0900194 .unlink = fs_unlink_unsupported,
AKASHI Takahiro1c24b7b2018-09-11 15:59:10 +0900195 .mkdir = fs_mkdir_unsupported,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800196#endif
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100197 .uuid = fs_uuid_unsupported,
Rob Clark60d74a92017-09-09 13:15:58 -0400198 .opendir = fat_opendir,
199 .readdir = fat_readdir,
200 .closedir = fat_closedir,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100201 .ln = fs_ln_unsupported,
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000202 },
Simon Glass1aede482012-12-26 09:53:29 +0000203#endif
Tien Fong Chee64eab042019-01-23 14:20:06 +0800204
205#if CONFIG_IS_ENABLED(FS_EXT4)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000206 {
207 .fstype = FS_TYPE_EXT,
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100208 .name = "ext4",
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700209 .null_dev_desc_ok = false,
Simon Glass19e38582012-12-26 09:53:33 +0000210 .probe = ext4fs_probe,
211 .close = ext4fs_close,
Simon Glass1aede482012-12-26 09:53:29 +0000212 .ls = ext4fs_ls,
Stephen Warren12d6d0c2014-02-03 13:21:09 -0700213 .exists = ext4fs_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600214 .size = ext4fs_size,
Simon Glass19e38582012-12-26 09:53:33 +0000215 .read = ext4_read_file,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800216#ifdef CONFIG_CMD_EXT4_WRITE
217 .write = ext4_write_file,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100218 .ln = ext4fs_create_link,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800219#else
Stephen Warren9df25802014-02-03 13:20:59 -0700220 .write = fs_write_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100221 .ln = fs_ln_unsupported,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800222#endif
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100223 .uuid = ext4fs_uuid,
Rob Clark2b7bfd92017-09-09 13:15:55 -0400224 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900225 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900226 .mkdir = fs_mkdir_unsupported,
Simon Glass1aede482012-12-26 09:53:29 +0000227 },
228#endif
Simon Glass11842872012-12-26 09:53:35 +0000229#ifdef CONFIG_SANDBOX
230 {
231 .fstype = FS_TYPE_SANDBOX,
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100232 .name = "sandbox",
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700233 .null_dev_desc_ok = true,
Simon Glass11842872012-12-26 09:53:35 +0000234 .probe = sandbox_fs_set_blk_dev,
235 .close = sandbox_fs_close,
236 .ls = sandbox_fs_ls,
Stephen Warren97d66f22014-02-03 13:21:07 -0700237 .exists = sandbox_fs_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600238 .size = sandbox_fs_size,
Simon Glass11842872012-12-26 09:53:35 +0000239 .read = fs_read_sandbox,
Simon Glassea307e82013-04-20 08:42:51 +0000240 .write = fs_write_sandbox,
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100241 .uuid = fs_uuid_unsupported,
Rob Clark2b7bfd92017-09-09 13:15:55 -0400242 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900243 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900244 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100245 .ln = fs_ln_unsupported,
Simon Glass11842872012-12-26 09:53:35 +0000246 },
247#endif
Hans de Goede690c7962015-09-17 18:46:58 -0400248#ifdef CONFIG_CMD_UBIFS
249 {
250 .fstype = FS_TYPE_UBIFS,
251 .name = "ubifs",
252 .null_dev_desc_ok = true,
253 .probe = ubifs_set_blk_dev,
254 .close = ubifs_close,
255 .ls = ubifs_ls,
256 .exists = ubifs_exists,
257 .size = ubifs_size,
258 .read = ubifs_read,
259 .write = fs_write_unsupported,
260 .uuid = fs_uuid_unsupported,
Rob Clark2b7bfd92017-09-09 13:15:55 -0400261 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900262 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900263 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100264 .ln = fs_ln_unsupported,
Hans de Goede690c7962015-09-17 18:46:58 -0400265 },
266#endif
Marek BehĂșn98ec1d12017-09-03 17:00:29 +0200267#ifdef CONFIG_FS_BTRFS
268 {
269 .fstype = FS_TYPE_BTRFS,
270 .name = "btrfs",
271 .null_dev_desc_ok = false,
272 .probe = btrfs_probe,
273 .close = btrfs_close,
274 .ls = btrfs_ls,
275 .exists = btrfs_exists,
276 .size = btrfs_size,
277 .read = btrfs_read,
278 .write = fs_write_unsupported,
279 .uuid = btrfs_uuid,
Marek BehĂșn90762d92017-10-06 16:56:07 +0200280 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900281 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900282 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100283 .ln = fs_ln_unsupported,
Marek BehĂșn98ec1d12017-09-03 17:00:29 +0200284 },
285#endif
Joao Marcos Costa29da3742020-07-30 15:33:47 +0200286#if IS_ENABLED(CONFIG_FS_SQUASHFS)
287 {
288 .fstype = FS_TYPE_SQUASHFS,
289 .name = "squashfs",
Richard Genoud654b2482020-11-03 12:10:59 +0100290 .null_dev_desc_ok = false,
Joao Marcos Costa29da3742020-07-30 15:33:47 +0200291 .probe = sqfs_probe,
292 .opendir = sqfs_opendir,
293 .readdir = sqfs_readdir,
294 .ls = fs_ls_generic,
295 .read = sqfs_read,
296 .size = sqfs_size,
297 .close = sqfs_close,
298 .closedir = sqfs_closedir,
Richard Genoudcfca20c2020-11-03 12:11:26 +0100299 .exists = sqfs_exists,
Richard Genoud654b2482020-11-03 12:10:59 +0100300 .uuid = fs_uuid_unsupported,
301 .write = fs_write_unsupported,
302 .ln = fs_ln_unsupported,
303 .unlink = fs_unlink_unsupported,
304 .mkdir = fs_mkdir_unsupported,
Joao Marcos Costa29da3742020-07-30 15:33:47 +0200305 },
306#endif
Simon Glass1aede482012-12-26 09:53:29 +0000307 {
308 .fstype = FS_TYPE_ANY,
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100309 .name = "unsupported",
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700310 .null_dev_desc_ok = true,
Simon Glass1aede482012-12-26 09:53:29 +0000311 .probe = fs_probe_unsupported,
312 .close = fs_close_unsupported,
313 .ls = fs_ls_unsupported,
Stephen Warrend008fbb2014-02-03 13:21:00 -0700314 .exists = fs_exists_unsupported,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600315 .size = fs_size_unsupported,
Simon Glass1aede482012-12-26 09:53:29 +0000316 .read = fs_read_unsupported,
Simon Glasseda14ea2013-04-20 08:42:50 +0000317 .write = fs_write_unsupported,
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100318 .uuid = fs_uuid_unsupported,
Rob Clark2b7bfd92017-09-09 13:15:55 -0400319 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900320 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900321 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100322 .ln = fs_ln_unsupported,
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000323 },
324};
325
Simon Glasse6aad852012-12-26 09:53:30 +0000326static struct fstype_info *fs_get_info(int fstype)
327{
328 struct fstype_info *info;
329 int i;
330
331 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
332 if (fstype == info->fstype)
333 return info;
334 }
335
336 /* Return the 'unsupported' sentinel */
337 return info;
338}
339
Alex Kiernan3a6163a2018-05-29 15:30:50 +0000340/**
AKASHI Takahiro80ac7342019-10-07 14:59:37 +0900341 * fs_get_type() - Get type of current filesystem
342 *
343 * Return: filesystem type
344 *
345 * Returns filesystem type representing the current filesystem, or
346 * FS_TYPE_ANY for any unrecognised filesystem.
347 */
348int fs_get_type(void)
349{
350 return fs_type;
351}
352
353/**
Alex Kiernan3a6163a2018-05-29 15:30:50 +0000354 * fs_get_type_name() - Get type of current filesystem
355 *
356 * Return: Pointer to filesystem name
357 *
358 * Returns a string describing the current filesystem, or the sentinel
359 * "unsupported" for any unrecognised filesystem.
360 */
361const char *fs_get_type_name(void)
362{
363 return fs_get_info(fs_type)->name;
364}
365
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000366int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
367{
Simon Glass1aede482012-12-26 09:53:29 +0000368 struct fstype_info *info;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000369 int part, i;
Stephen Warren44161af2012-10-30 07:50:47 +0000370#ifdef CONFIG_NEEDS_MANUAL_RELOC
371 static int relocated;
372
373 if (!relocated) {
Simon Glass1aede482012-12-26 09:53:29 +0000374 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
375 i++, info++) {
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100376 info->name += gd->reloc_off;
Simon Glass1aede482012-12-26 09:53:29 +0000377 info->probe += gd->reloc_off;
378 info->close += gd->reloc_off;
379 info->ls += gd->reloc_off;
380 info->read += gd->reloc_off;
Simon Glasseda14ea2013-04-20 08:42:50 +0000381 info->write += gd->reloc_off;
Simon Glass1aede482012-12-26 09:53:29 +0000382 }
Stephen Warren44161af2012-10-30 07:50:47 +0000383 relocated = 1;
384 }
385#endif
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000386
Simon Glasse76ee972016-02-29 15:25:44 -0700387 part = blk_get_device_part_str(ifname, dev_part_str, &fs_dev_desc,
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000388 &fs_partition, 1);
389 if (part < 0)
390 return -1;
391
Simon Glass1aede482012-12-26 09:53:29 +0000392 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
393 if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY &&
394 fstype != info->fstype)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000395 continue;
396
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700397 if (!fs_dev_desc && !info->null_dev_desc_ok)
398 continue;
399
Simon Glass6a46e2f2012-12-26 09:53:31 +0000400 if (!info->probe(fs_dev_desc, &fs_partition)) {
Simon Glass1aede482012-12-26 09:53:29 +0000401 fs_type = info->fstype;
Rob Clark2b7bfd92017-09-09 13:15:55 -0400402 fs_dev_part = part;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000403 return 0;
404 }
405 }
406
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000407 return -1;
408}
409
Rob Clark2b7bfd92017-09-09 13:15:55 -0400410/* set current blk device w/ blk_desc + partition # */
411int fs_set_blk_dev_with_part(struct blk_desc *desc, int part)
412{
413 struct fstype_info *info;
414 int ret, i;
415
416 if (part >= 1)
417 ret = part_get_info(desc, part, &fs_partition);
418 else
419 ret = part_get_info_whole_disk(desc, &fs_partition);
420 if (ret)
421 return ret;
422 fs_dev_desc = desc;
423
424 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
425 if (!info->probe(fs_dev_desc, &fs_partition)) {
426 fs_type = info->fstype;
AKASHI Takahiro43efaa02018-10-17 16:32:02 +0900427 fs_dev_part = part;
Rob Clark2b7bfd92017-09-09 13:15:55 -0400428 return 0;
429 }
430 }
431
432 return -1;
433}
434
AKASHI Takahiroca8e3772019-10-07 14:59:35 +0900435void fs_close(void)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000436{
Simon Glasse6aad852012-12-26 09:53:30 +0000437 struct fstype_info *info = fs_get_info(fs_type);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000438
Simon Glasse6aad852012-12-26 09:53:30 +0000439 info->close();
Simon Glass19e38582012-12-26 09:53:33 +0000440
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000441 fs_type = FS_TYPE_ANY;
442}
443
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100444int fs_uuid(char *uuid_str)
445{
446 struct fstype_info *info = fs_get_info(fs_type);
447
448 return info->uuid(uuid_str);
449}
450
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000451int fs_ls(const char *dirname)
452{
453 int ret;
454
Simon Glasse6aad852012-12-26 09:53:30 +0000455 struct fstype_info *info = fs_get_info(fs_type);
456
457 ret = info->ls(dirname);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000458
459 fs_close();
460
461 return ret;
462}
463
Stephen Warrend008fbb2014-02-03 13:21:00 -0700464int fs_exists(const char *filename)
465{
466 int ret;
467
468 struct fstype_info *info = fs_get_info(fs_type);
469
470 ret = info->exists(filename);
471
472 fs_close();
473
474 return ret;
475}
476
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800477int fs_size(const char *filename, loff_t *size)
Stephen Warren3eb58f52014-06-11 12:47:26 -0600478{
479 int ret;
480
481 struct fstype_info *info = fs_get_info(fs_type);
482
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800483 ret = info->size(filename, size);
Stephen Warren3eb58f52014-06-11 12:47:26 -0600484
485 fs_close();
486
487 return ret;
488}
489
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100490#ifdef CONFIG_LMB
491/* Check if a file may be read to the given address */
492static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
493 loff_t len, struct fstype_info *info)
494{
495 struct lmb lmb;
496 int ret;
497 loff_t size;
498 loff_t read_len;
499
500 /* get the actual size of the file */
501 ret = info->size(filename, &size);
502 if (ret)
503 return ret;
504 if (offset >= size) {
505 /* offset >= EOF, no bytes will be written */
506 return 0;
507 }
508 read_len = size - offset;
509
510 /* limit to 'len' if it is smaller */
511 if (len && len < read_len)
512 read_len = len;
513
Simon Goldschmidt8890e7d2019-01-26 22:13:04 +0100514 lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100515 lmb_dump_all(&lmb);
516
517 if (lmb_alloc_addr(&lmb, addr, read_len) == addr)
518 return 0;
519
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000520 log_err("** Reading file would overwrite reserved memory **\n");
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100521 return -ENOSPC;
522}
523#endif
524
525static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
526 int do_lmb_check, loff_t *actread)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000527{
Simon Glasse6aad852012-12-26 09:53:30 +0000528 struct fstype_info *info = fs_get_info(fs_type);
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000529 void *buf;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000530 int ret;
531
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100532#ifdef CONFIG_LMB
533 if (do_lmb_check) {
534 ret = fs_read_lmb_check(filename, addr, offset, len, info);
535 if (ret)
536 return ret;
537 }
538#endif
539
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000540 /*
541 * We don't actually know how many bytes are being read, since len==0
542 * means read the whole file.
543 */
544 buf = map_sysmem(addr, len);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800545 ret = info->read(filename, buf, offset, len, actread);
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000546 unmap_sysmem(buf);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000547
Simon Glasse6aad852012-12-26 09:53:30 +0000548 /* If we requested a specific number of bytes, check we got it */
Max Krummenacher56d9cdf2015-08-05 17:16:58 +0200549 if (ret == 0 && len && *actread != len)
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000550 log_debug("** %s shorter than offset + len **\n", filename);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000551 fs_close();
552
553 return ret;
554}
555
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100556int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
557 loff_t *actread)
558{
559 return _fs_read(filename, addr, offset, len, 0, actread);
560}
561
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800562int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
563 loff_t *actwrite)
Simon Glasseda14ea2013-04-20 08:42:50 +0000564{
565 struct fstype_info *info = fs_get_info(fs_type);
566 void *buf;
567 int ret;
568
Simon Glasseda14ea2013-04-20 08:42:50 +0000569 buf = map_sysmem(addr, len);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800570 ret = info->write(filename, buf, offset, len, actwrite);
Simon Glasseda14ea2013-04-20 08:42:50 +0000571 unmap_sysmem(buf);
572
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800573 if (ret < 0 && len != *actwrite) {
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000574 log_err("** Unable to write file %s **\n", filename);
Simon Glasseda14ea2013-04-20 08:42:50 +0000575 ret = -1;
576 }
577 fs_close();
578
579 return ret;
580}
581
Rob Clark2b7bfd92017-09-09 13:15:55 -0400582struct fs_dir_stream *fs_opendir(const char *filename)
583{
584 struct fstype_info *info = fs_get_info(fs_type);
585 struct fs_dir_stream *dirs = NULL;
586 int ret;
587
588 ret = info->opendir(filename, &dirs);
589 fs_close();
590 if (ret) {
591 errno = -ret;
592 return NULL;
593 }
594
595 dirs->desc = fs_dev_desc;
596 dirs->part = fs_dev_part;
597
598 return dirs;
599}
600
601struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs)
602{
603 struct fstype_info *info;
604 struct fs_dirent *dirent;
605 int ret;
606
607 fs_set_blk_dev_with_part(dirs->desc, dirs->part);
608 info = fs_get_info(fs_type);
609
610 ret = info->readdir(dirs, &dirent);
611 fs_close();
612 if (ret) {
613 errno = -ret;
614 return NULL;
615 }
616
617 return dirent;
618}
619
620void fs_closedir(struct fs_dir_stream *dirs)
621{
622 struct fstype_info *info;
623
624 if (!dirs)
625 return;
626
627 fs_set_blk_dev_with_part(dirs->desc, dirs->part);
628 info = fs_get_info(fs_type);
629
630 info->closedir(dirs);
631 fs_close();
632}
633
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900634int fs_unlink(const char *filename)
635{
636 int ret;
637
638 struct fstype_info *info = fs_get_info(fs_type);
639
640 ret = info->unlink(filename);
641
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900642 fs_close();
643
644 return ret;
645}
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900646
647int fs_mkdir(const char *dirname)
648{
649 int ret;
650
651 struct fstype_info *info = fs_get_info(fs_type);
652
653 ret = info->mkdir(dirname);
654
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900655 fs_close();
656
657 return ret;
658}
Rob Clark2b7bfd92017-09-09 13:15:55 -0400659
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100660int fs_ln(const char *fname, const char *target)
661{
662 struct fstype_info *info = fs_get_info(fs_type);
663 int ret;
664
665 ret = info->ln(fname, target);
666
667 if (ret < 0) {
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000668 log_err("** Unable to create link %s -> %s **\n", fname, target);
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100669 ret = -1;
670 }
671 fs_close();
672
673 return ret;
674}
675
Simon Glassed38aef2020-05-10 11:40:03 -0600676int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
677 int fstype)
Stephen Warren3eb58f52014-06-11 12:47:26 -0600678{
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800679 loff_t size;
Stephen Warren3eb58f52014-06-11 12:47:26 -0600680
681 if (argc != 4)
682 return CMD_RET_USAGE;
683
684 if (fs_set_blk_dev(argv[1], argv[2], fstype))
685 return 1;
686
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800687 if (fs_size(argv[3], &size) < 0)
Stephen Warren3eb58f52014-06-11 12:47:26 -0600688 return CMD_RET_FAILURE;
689
Simon Glass4d949a22017-08-03 12:22:10 -0600690 env_set_hex("filesize", size);
Stephen Warren3eb58f52014-06-11 12:47:26 -0600691
692 return 0;
693}
694
Simon Glassed38aef2020-05-10 11:40:03 -0600695int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
696 int fstype)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000697{
698 unsigned long addr;
699 const char *addr_str;
700 const char *filename;
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800701 loff_t bytes;
702 loff_t pos;
703 loff_t len_read;
704 int ret;
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100705 unsigned long time;
Pavel Machek4c1a9c52014-07-09 22:42:57 +0200706 char *ep;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000707
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000708 if (argc < 2)
709 return CMD_RET_USAGE;
710 if (argc > 7)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000711 return CMD_RET_USAGE;
712
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000713 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000714 return 1;
715
716 if (argc >= 4) {
Pavel Machek4c1a9c52014-07-09 22:42:57 +0200717 addr = simple_strtoul(argv[3], &ep, 16);
718 if (ep == argv[3] || *ep != '\0')
719 return CMD_RET_USAGE;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000720 } else {
Simon Glass64b723f2017-08-03 12:22:12 -0600721 addr_str = env_get("loadaddr");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000722 if (addr_str != NULL)
723 addr = simple_strtoul(addr_str, NULL, 16);
724 else
725 addr = CONFIG_SYS_LOAD_ADDR;
726 }
727 if (argc >= 5) {
728 filename = argv[4];
729 } else {
Simon Glass64b723f2017-08-03 12:22:12 -0600730 filename = env_get("bootfile");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000731 if (!filename) {
732 puts("** No boot file defined **\n");
733 return 1;
734 }
735 }
736 if (argc >= 6)
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200737 bytes = simple_strtoul(argv[5], NULL, 16);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000738 else
739 bytes = 0;
740 if (argc >= 7)
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200741 pos = simple_strtoul(argv[6], NULL, 16);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000742 else
743 pos = 0;
744
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100745 time = get_timer(0);
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100746 ret = _fs_read(filename, addr, pos, bytes, 1, &len_read);
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100747 time = get_timer(time);
Heinrich Schuchardtca816ce2020-06-29 20:08:49 +0200748 if (ret < 0) {
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000749 log_err("Failed to load '%s'\n", filename);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000750 return 1;
Heinrich Schuchardtca816ce2020-06-29 20:08:49 +0200751 }
752
753 if (IS_ENABLED(CONFIG_CMD_BOOTEFI))
754 efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "",
755 (argc > 4) ? argv[4] : "");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000756
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800757 printf("%llu bytes read in %lu ms", len_read, time);
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100758 if (time > 0) {
759 puts(" (");
Tom Rinia17b7bc2014-11-24 11:50:46 -0500760 print_size(div_u64(len_read, time) * 1000, "/s");
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100761 puts(")");
762 }
763 puts("\n");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000764
Simon Glass4d949a22017-08-03 12:22:10 -0600765 env_set_hex("fileaddr", addr);
766 env_set_hex("filesize", len_read);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000767
768 return 0;
769}
770
Simon Glassed38aef2020-05-10 11:40:03 -0600771int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
772 int fstype)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000773{
774 if (argc < 2)
775 return CMD_RET_USAGE;
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000776 if (argc > 4)
777 return CMD_RET_USAGE;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000778
779 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
780 return 1;
781
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000782 if (fs_ls(argc >= 4 ? argv[3] : "/"))
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000783 return 1;
784
785 return 0;
786}
Simon Glasseda14ea2013-04-20 08:42:50 +0000787
Stephen Warrend008fbb2014-02-03 13:21:00 -0700788int file_exists(const char *dev_type, const char *dev_part, const char *file,
789 int fstype)
790{
791 if (fs_set_blk_dev(dev_type, dev_part, fstype))
792 return 0;
793
794 return fs_exists(file);
795}
796
Simon Glassed38aef2020-05-10 11:40:03 -0600797int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
798 int fstype)
Simon Glasseda14ea2013-04-20 08:42:50 +0000799{
800 unsigned long addr;
801 const char *filename;
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800802 loff_t bytes;
803 loff_t pos;
804 loff_t len;
805 int ret;
Simon Glasseda14ea2013-04-20 08:42:50 +0000806 unsigned long time;
807
808 if (argc < 6 || argc > 7)
809 return CMD_RET_USAGE;
810
811 if (fs_set_blk_dev(argv[1], argv[2], fstype))
812 return 1;
813
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800814 addr = simple_strtoul(argv[3], NULL, 16);
815 filename = argv[4];
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200816 bytes = simple_strtoul(argv[5], NULL, 16);
Simon Glasseda14ea2013-04-20 08:42:50 +0000817 if (argc >= 7)
Wolfgang Denka10c7a52013-10-05 21:07:25 +0200818 pos = simple_strtoul(argv[6], NULL, 16);
Simon Glasseda14ea2013-04-20 08:42:50 +0000819 else
820 pos = 0;
821
822 time = get_timer(0);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800823 ret = fs_write(filename, addr, pos, bytes, &len);
Simon Glasseda14ea2013-04-20 08:42:50 +0000824 time = get_timer(time);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800825 if (ret < 0)
Simon Glasseda14ea2013-04-20 08:42:50 +0000826 return 1;
827
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800828 printf("%llu bytes written in %lu ms", len, time);
Simon Glasseda14ea2013-04-20 08:42:50 +0000829 if (time > 0) {
830 puts(" (");
Tom Rinia17b7bc2014-11-24 11:50:46 -0500831 print_size(div_u64(len, time) * 1000, "/s");
Simon Glasseda14ea2013-04-20 08:42:50 +0000832 puts(")");
833 }
834 puts("\n");
835
836 return 0;
837}
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100838
Simon Glassed38aef2020-05-10 11:40:03 -0600839int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
840 int fstype)
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100841{
842 int ret;
843 char uuid[37];
844 memset(uuid, 0, sizeof(uuid));
845
846 if (argc < 3 || argc > 4)
847 return CMD_RET_USAGE;
848
849 if (fs_set_blk_dev(argv[1], argv[2], fstype))
850 return 1;
851
852 ret = fs_uuid(uuid);
853 if (ret)
854 return CMD_RET_FAILURE;
855
856 if (argc == 4)
Simon Glass6a38e412017-08-03 12:22:09 -0600857 env_set(argv[3], uuid);
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100858 else
859 printf("%s\n", uuid);
860
861 return CMD_RET_SUCCESS;
862}
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100863
Simon Glassed38aef2020-05-10 11:40:03 -0600864int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100865{
866 struct fstype_info *info;
867
868 if (argc < 3 || argc > 4)
869 return CMD_RET_USAGE;
870
871 if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY))
872 return 1;
873
874 info = fs_get_info(fs_type);
875
876 if (argc == 4)
Simon Glass6a38e412017-08-03 12:22:09 -0600877 env_set(argv[3], info->name);
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100878 else
879 printf("%s\n", info->name);
880
Marek Vasut08d1c422019-02-06 13:19:29 +0100881 fs_close();
882
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100883 return CMD_RET_SUCCESS;
884}
885
Simon Glassed38aef2020-05-10 11:40:03 -0600886int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900887 int fstype)
888{
889 if (argc != 4)
890 return CMD_RET_USAGE;
891
892 if (fs_set_blk_dev(argv[1], argv[2], fstype))
893 return 1;
894
895 if (fs_unlink(argv[3]))
896 return 1;
897
898 return 0;
899}
900
Simon Glassed38aef2020-05-10 11:40:03 -0600901int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900902 int fstype)
903{
904 int ret;
905
906 if (argc != 4)
907 return CMD_RET_USAGE;
908
909 if (fs_set_blk_dev(argv[1], argv[2], fstype))
910 return 1;
911
912 ret = fs_mkdir(argv[3]);
913 if (ret) {
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000914 log_err("** Unable to create a directory \"%s\" **\n", argv[3]);
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900915 return 1;
916 }
917
918 return 0;
919}
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100920
Simon Glassed38aef2020-05-10 11:40:03 -0600921int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100922 int fstype)
923{
924 if (argc != 5)
925 return CMD_RET_USAGE;
926
927 if (fs_set_blk_dev(argv[1], argv[2], fstype))
928 return 1;
929
930 if (fs_ln(argv[3], argv[4]))
931 return 1;
932
933 return 0;
934}
Niel Fourie9252d702020-03-24 16:17:04 +0100935
936int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
937{
938 struct fstype_info *drv = fstypes;
939 const int n_ents = ARRAY_SIZE(fstypes);
940 struct fstype_info *entry;
941 int i = 0;
942
943 puts("Supported filesystems");
944 for (entry = drv; entry != drv + n_ents; entry++) {
945 if (entry->fstype != FS_TYPE_ANY) {
946 printf("%c %s", i ? ',' : ':', entry->name);
947 i++;
948 }
949 }
950 if (!i)
951 puts(": <none>");
952 puts("\n");
953 return CMD_RET_SUCCESS;
954}