blob: 023f89cafec22eb11b7da11442e25e6f4711fac7 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Stephen Warren045fa1e2012-10-22 06:43:51 +00002/*
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
Stephen Warren045fa1e2012-10-22 06:43:51 +00004 */
5
Heinrich Schuchardt0d32d8c2020-08-25 17:49:16 +00006#define LOG_CATEGORY LOGC_CORE
7
Simon Glass09140112020-05-10 11:40:03 -06008#include <command.h>
Stephen Warren045fa1e2012-10-22 06:43:51 +00009#include <config.h>
Christian Gmeiner59e890e2014-11-12 14:35:04 +010010#include <errno.h>
Stephen Warren045fa1e2012-10-22 06:43:51 +000011#include <common.h>
Simon Glassc7694dd2019-08-01 09:46:46 -060012#include <env.h>
Simon Glasse6f6f9e2020-05-10 11:39:58 -060013#include <lmb.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060014#include <log.h>
Joe Hershberger0eb25b62015-03-22 17:08:59 -050015#include <mapmem.h>
Stephen Warren045fa1e2012-10-22 06:43:51 +000016#include <part.h>
17#include <ext4fs.h>
18#include <fat.h>
19#include <fs.h>
Simon Glass92ccc962012-12-26 09:53:35 +000020#include <sandboxfs.h>
Hans de Goede251cee02015-09-17 18:46:58 -040021#include <ubifs_uboot.h>
Marek BehĂșn0c936ee2017-09-03 17:00:29 +020022#include <btrfs.h>
Simon Glass401d1c42020-10-30 21:38:53 -060023#include <asm/global_data.h>
Simon Glass117e0502012-12-26 09:53:32 +000024#include <asm/io.h>
Tom Rini9e374e72014-11-24 11:50:46 -050025#include <div64.h>
26#include <linux/math64.h>
Mian Yousaf Kaukabee88eac2019-06-18 15:03:44 +020027#include <efi_loader.h>
Joao Marcos Costac5100612020-07-30 15:33:47 +020028#include <squashfs.h>
Stephen Warren045fa1e2012-10-22 06:43:51 +000029
Stephen Warrena1b231c2012-10-30 07:50:47 +000030DECLARE_GLOBAL_DATA_PTR;
31
Simon Glass4101f682016-02-29 15:25:34 -070032static struct blk_desc *fs_dev_desc;
Rob Clark4bbcc962017-09-09 13:15:55 -040033static int fs_dev_part;
Simon Glass05289792020-05-10 11:39:57 -060034static struct disk_partition fs_partition;
Stephen Warren045fa1e2012-10-22 06:43:51 +000035static int fs_type = FS_TYPE_ANY;
36
Simon Glass4101f682016-02-29 15:25:34 -070037static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
Simon Glass05289792020-05-10 11:39:57 -060038 struct disk_partition *fs_partition)
Simon Glass436e2b72012-12-26 09:53:29 +000039{
Heinrich Schuchardt3bd0e2c2021-09-20 14:15:03 +020040 log_debug("Unrecognized filesystem type\n");
Simon Glass436e2b72012-12-26 09:53:29 +000041 return -1;
42}
43
Stephen Warren045fa1e2012-10-22 06:43:51 +000044static inline int fs_ls_unsupported(const char *dirname)
45{
Stephen Warren045fa1e2012-10-22 06:43:51 +000046 return -1;
47}
48
Rob Clark89191d62017-09-09 13:15:58 -040049/* generic implementation of ls in terms of opendir/readdir/closedir */
50__maybe_unused
51static int fs_ls_generic(const char *dirname)
52{
53 struct fs_dir_stream *dirs;
54 struct fs_dirent *dent;
55 int nfiles = 0, ndirs = 0;
56
57 dirs = fs_opendir(dirname);
58 if (!dirs)
59 return -errno;
60
61 while ((dent = fs_readdir(dirs))) {
62 if (dent->type == FS_DT_DIR) {
63 printf(" %s/\n", dent->name);
64 ndirs++;
Joao Marcos Costa02c366b2020-07-30 15:33:51 +020065 } else if (dent->type == FS_DT_LNK) {
66 printf(" <SYM> %s\n", dent->name);
67 nfiles++;
Rob Clark89191d62017-09-09 13:15:58 -040068 } else {
69 printf(" %8lld %s\n", dent->size, dent->name);
70 nfiles++;
71 }
72 }
73
74 fs_closedir(dirs);
75
76 printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs);
77
78 return 0;
79}
80
Stephen Warren61529162014-02-03 13:21:00 -070081static inline int fs_exists_unsupported(const char *filename)
82{
83 return 0;
84}
85
Suriyan Ramasamid455d872014-11-17 14:39:38 -080086static inline int fs_size_unsupported(const char *filename, loff_t *size)
Stephen Warrencf659812014-06-11 12:47:26 -060087{
88 return -1;
89}
90
Simon Glass117e0502012-12-26 09:53:32 +000091static inline int fs_read_unsupported(const char *filename, void *buf,
Suriyan Ramasamid455d872014-11-17 14:39:38 -080092 loff_t offset, loff_t len,
93 loff_t *actread)
Stephen Warren045fa1e2012-10-22 06:43:51 +000094{
Stephen Warren045fa1e2012-10-22 06:43:51 +000095 return -1;
96}
97
Simon Glassa8f6ab52013-04-20 08:42:50 +000098static inline int fs_write_unsupported(const char *filename, void *buf,
Suriyan Ramasamid455d872014-11-17 14:39:38 -080099 loff_t offset, loff_t len,
100 loff_t *actwrite)
Simon Glassa8f6ab52013-04-20 08:42:50 +0000101{
102 return -1;
103}
104
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100105static inline int fs_ln_unsupported(const char *filename, const char *target)
106{
107 return -1;
108}
109
Simon Glass436e2b72012-12-26 09:53:29 +0000110static inline void fs_close_unsupported(void)
111{
112}
113
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100114static inline int fs_uuid_unsupported(char *uuid_str)
115{
116 return -1;
117}
118
Rob Clark4bbcc962017-09-09 13:15:55 -0400119static inline int fs_opendir_unsupported(const char *filename,
120 struct fs_dir_stream **dirs)
121{
122 return -EACCES;
123}
124
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900125static inline int fs_unlink_unsupported(const char *filename)
126{
127 return -1;
128}
129
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900130static inline int fs_mkdir_unsupported(const char *dirname)
131{
132 return -1;
133}
134
Simon Glass436e2b72012-12-26 09:53:29 +0000135struct fstype_info {
Stephen Warren045fa1e2012-10-22 06:43:51 +0000136 int fstype;
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100137 char *name;
Stephen Warren377202b2014-02-03 13:21:01 -0700138 /*
139 * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This
140 * should be false in most cases. For "virtual" filesystems which
141 * aren't based on a U-Boot block device (e.g. sandbox), this can be
Heinrich Schuchardtca230b02018-08-11 15:52:14 +0200142 * set to true. This should also be true for the dummy entry at the end
Stephen Warren377202b2014-02-03 13:21:01 -0700143 * of fstypes[], since that is essentially a "virtual" (non-existent)
144 * filesystem.
145 */
146 bool null_dev_desc_ok;
Simon Glass4101f682016-02-29 15:25:34 -0700147 int (*probe)(struct blk_desc *fs_dev_desc,
Simon Glass05289792020-05-10 11:39:57 -0600148 struct disk_partition *fs_partition);
Simon Glass436e2b72012-12-26 09:53:29 +0000149 int (*ls)(const char *dirname);
Stephen Warren61529162014-02-03 13:21:00 -0700150 int (*exists)(const char *filename);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800151 int (*size)(const char *filename, loff_t *size);
152 int (*read)(const char *filename, void *buf, loff_t offset,
153 loff_t len, loff_t *actread);
154 int (*write)(const char *filename, void *buf, loff_t offset,
155 loff_t len, loff_t *actwrite);
Simon Glass436e2b72012-12-26 09:53:29 +0000156 void (*close)(void);
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100157 int (*uuid)(char *uuid_str);
Rob Clark4bbcc962017-09-09 13:15:55 -0400158 /*
159 * Open a directory stream. On success return 0 and directory
160 * stream pointer via 'dirsp'. On error, return -errno. See
161 * fs_opendir().
162 */
163 int (*opendir)(const char *filename, struct fs_dir_stream **dirsp);
164 /*
165 * Read next entry from directory stream. On success return 0
166 * and directory entry pointer via 'dentp'. On error return
167 * -errno. See fs_readdir().
168 */
169 int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp);
170 /* see fs_closedir() */
171 void (*closedir)(struct fs_dir_stream *dirs);
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900172 int (*unlink)(const char *filename);
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900173 int (*mkdir)(const char *dirname);
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100174 int (*ln)(const char *filename, const char *target);
Simon Glass436e2b72012-12-26 09:53:29 +0000175};
176
177static struct fstype_info fstypes[] = {
178#ifdef CONFIG_FS_FAT
Stephen Warren045fa1e2012-10-22 06:43:51 +0000179 {
180 .fstype = FS_TYPE_FAT,
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100181 .name = "fat",
Stephen Warren377202b2014-02-03 13:21:01 -0700182 .null_dev_desc_ok = false,
Simon Glasse6d52412012-12-26 09:53:33 +0000183 .probe = fat_set_blk_dev,
184 .close = fat_close,
Rob Clark89191d62017-09-09 13:15:58 -0400185 .ls = fs_ls_generic,
Stephen Warrenb7b5f312014-02-03 13:21:10 -0700186 .exists = fat_exists,
Stephen Warrencf659812014-06-11 12:47:26 -0600187 .size = fat_size,
Simon Glasse6d52412012-12-26 09:53:33 +0000188 .read = fat_read_file,
Tien Fong Cheed8c3ea92019-01-23 14:20:04 +0800189#if CONFIG_IS_ENABLED(FAT_WRITE)
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800190 .write = file_fat_write,
AKASHI Takahirof8240ce2018-09-11 15:59:14 +0900191 .unlink = fat_unlink,
AKASHI Takahiro31a18d52018-09-11 15:59:10 +0900192 .mkdir = fat_mkdir,
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800193#else
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700194 .write = fs_write_unsupported,
AKASHI Takahirof8240ce2018-09-11 15:59:14 +0900195 .unlink = fs_unlink_unsupported,
AKASHI Takahiro31a18d52018-09-11 15:59:10 +0900196 .mkdir = fs_mkdir_unsupported,
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800197#endif
Heinrich Schuchardtc0029e42020-12-31 00:38:13 +0100198 .uuid = fat_uuid,
Rob Clark89191d62017-09-09 13:15:58 -0400199 .opendir = fat_opendir,
200 .readdir = fat_readdir,
201 .closedir = fat_closedir,
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100202 .ln = fs_ln_unsupported,
Stephen Warren045fa1e2012-10-22 06:43:51 +0000203 },
Simon Glass436e2b72012-12-26 09:53:29 +0000204#endif
Tien Fong Cheecafc4292019-01-23 14:20:06 +0800205
206#if CONFIG_IS_ENABLED(FS_EXT4)
Stephen Warren045fa1e2012-10-22 06:43:51 +0000207 {
208 .fstype = FS_TYPE_EXT,
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100209 .name = "ext4",
Stephen Warren377202b2014-02-03 13:21:01 -0700210 .null_dev_desc_ok = false,
Simon Glasse6d52412012-12-26 09:53:33 +0000211 .probe = ext4fs_probe,
212 .close = ext4fs_close,
Simon Glass436e2b72012-12-26 09:53:29 +0000213 .ls = ext4fs_ls,
Stephen Warren55af5c92014-02-03 13:21:09 -0700214 .exists = ext4fs_exists,
Stephen Warrencf659812014-06-11 12:47:26 -0600215 .size = ext4fs_size,
Simon Glasse6d52412012-12-26 09:53:33 +0000216 .read = ext4_read_file,
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800217#ifdef CONFIG_CMD_EXT4_WRITE
218 .write = ext4_write_file,
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100219 .ln = ext4fs_create_link,
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800220#else
Stephen Warrenbd6fb312014-02-03 13:20:59 -0700221 .write = fs_write_unsupported,
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100222 .ln = fs_ln_unsupported,
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800223#endif
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100224 .uuid = ext4fs_uuid,
Rob Clark4bbcc962017-09-09 13:15:55 -0400225 .opendir = fs_opendir_unsupported,
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900226 .unlink = fs_unlink_unsupported,
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900227 .mkdir = fs_mkdir_unsupported,
Simon Glass436e2b72012-12-26 09:53:29 +0000228 },
229#endif
Simon Glass92ccc962012-12-26 09:53:35 +0000230#ifdef CONFIG_SANDBOX
231 {
232 .fstype = FS_TYPE_SANDBOX,
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100233 .name = "sandbox",
Stephen Warren377202b2014-02-03 13:21:01 -0700234 .null_dev_desc_ok = true,
Simon Glass92ccc962012-12-26 09:53:35 +0000235 .probe = sandbox_fs_set_blk_dev,
236 .close = sandbox_fs_close,
237 .ls = sandbox_fs_ls,
Stephen Warren0a30aa12014-02-03 13:21:07 -0700238 .exists = sandbox_fs_exists,
Stephen Warrencf659812014-06-11 12:47:26 -0600239 .size = sandbox_fs_size,
Simon Glass92ccc962012-12-26 09:53:35 +0000240 .read = fs_read_sandbox,
Simon Glass7eb2c8d2013-04-20 08:42:51 +0000241 .write = fs_write_sandbox,
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100242 .uuid = fs_uuid_unsupported,
Rob Clark4bbcc962017-09-09 13:15:55 -0400243 .opendir = fs_opendir_unsupported,
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900244 .unlink = fs_unlink_unsupported,
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900245 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100246 .ln = fs_ln_unsupported,
Simon Glass92ccc962012-12-26 09:53:35 +0000247 },
248#endif
Hans de Goede251cee02015-09-17 18:46:58 -0400249#ifdef CONFIG_CMD_UBIFS
250 {
251 .fstype = FS_TYPE_UBIFS,
252 .name = "ubifs",
253 .null_dev_desc_ok = true,
254 .probe = ubifs_set_blk_dev,
255 .close = ubifs_close,
256 .ls = ubifs_ls,
257 .exists = ubifs_exists,
258 .size = ubifs_size,
259 .read = ubifs_read,
260 .write = fs_write_unsupported,
261 .uuid = fs_uuid_unsupported,
Rob Clark4bbcc962017-09-09 13:15:55 -0400262 .opendir = fs_opendir_unsupported,
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900263 .unlink = fs_unlink_unsupported,
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900264 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100265 .ln = fs_ln_unsupported,
Hans de Goede251cee02015-09-17 18:46:58 -0400266 },
267#endif
Marek BehĂșn0c936ee2017-09-03 17:00:29 +0200268#ifdef CONFIG_FS_BTRFS
269 {
270 .fstype = FS_TYPE_BTRFS,
271 .name = "btrfs",
272 .null_dev_desc_ok = false,
273 .probe = btrfs_probe,
274 .close = btrfs_close,
275 .ls = btrfs_ls,
276 .exists = btrfs_exists,
277 .size = btrfs_size,
278 .read = btrfs_read,
279 .write = fs_write_unsupported,
280 .uuid = btrfs_uuid,
Marek BehĂșn38fc6832017-10-06 16:56:07 +0200281 .opendir = fs_opendir_unsupported,
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900282 .unlink = fs_unlink_unsupported,
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900283 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100284 .ln = fs_ln_unsupported,
Marek BehĂșn0c936ee2017-09-03 17:00:29 +0200285 },
286#endif
Joao Marcos Costac5100612020-07-30 15:33:47 +0200287#if IS_ENABLED(CONFIG_FS_SQUASHFS)
288 {
289 .fstype = FS_TYPE_SQUASHFS,
290 .name = "squashfs",
Richard Genoud1b1e0c02020-11-03 12:10:59 +0100291 .null_dev_desc_ok = false,
Joao Marcos Costac5100612020-07-30 15:33:47 +0200292 .probe = sqfs_probe,
293 .opendir = sqfs_opendir,
294 .readdir = sqfs_readdir,
295 .ls = fs_ls_generic,
296 .read = sqfs_read,
297 .size = sqfs_size,
298 .close = sqfs_close,
299 .closedir = sqfs_closedir,
Richard Genouddd4866b2020-11-03 12:11:26 +0100300 .exists = sqfs_exists,
Richard Genoud1b1e0c02020-11-03 12:10:59 +0100301 .uuid = fs_uuid_unsupported,
302 .write = fs_write_unsupported,
303 .ln = fs_ln_unsupported,
304 .unlink = fs_unlink_unsupported,
305 .mkdir = fs_mkdir_unsupported,
Joao Marcos Costac5100612020-07-30 15:33:47 +0200306 },
307#endif
Simon Glass436e2b72012-12-26 09:53:29 +0000308 {
309 .fstype = FS_TYPE_ANY,
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100310 .name = "unsupported",
Stephen Warren377202b2014-02-03 13:21:01 -0700311 .null_dev_desc_ok = true,
Simon Glass436e2b72012-12-26 09:53:29 +0000312 .probe = fs_probe_unsupported,
313 .close = fs_close_unsupported,
314 .ls = fs_ls_unsupported,
Stephen Warren61529162014-02-03 13:21:00 -0700315 .exists = fs_exists_unsupported,
Stephen Warrencf659812014-06-11 12:47:26 -0600316 .size = fs_size_unsupported,
Simon Glass436e2b72012-12-26 09:53:29 +0000317 .read = fs_read_unsupported,
Simon Glassa8f6ab52013-04-20 08:42:50 +0000318 .write = fs_write_unsupported,
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100319 .uuid = fs_uuid_unsupported,
Rob Clark4bbcc962017-09-09 13:15:55 -0400320 .opendir = fs_opendir_unsupported,
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900321 .unlink = fs_unlink_unsupported,
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900322 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100323 .ln = fs_ln_unsupported,
Stephen Warren045fa1e2012-10-22 06:43:51 +0000324 },
325};
326
Simon Glassc6f548d2012-12-26 09:53:30 +0000327static struct fstype_info *fs_get_info(int fstype)
328{
329 struct fstype_info *info;
330 int i;
331
332 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
333 if (fstype == info->fstype)
334 return info;
335 }
336
337 /* Return the 'unsupported' sentinel */
338 return info;
339}
340
Alex Kiernan0d488e82018-05-29 15:30:50 +0000341/**
AKASHI Takahirob7cd9562019-10-07 14:59:37 +0900342 * fs_get_type() - Get type of current filesystem
343 *
344 * Return: filesystem type
345 *
346 * Returns filesystem type representing the current filesystem, or
347 * FS_TYPE_ANY for any unrecognised filesystem.
348 */
349int fs_get_type(void)
350{
351 return fs_type;
352}
353
354/**
Alex Kiernan0d488e82018-05-29 15:30:50 +0000355 * fs_get_type_name() - Get type of current filesystem
356 *
357 * Return: Pointer to filesystem name
358 *
359 * Returns a string describing the current filesystem, or the sentinel
360 * "unsupported" for any unrecognised filesystem.
361 */
362const char *fs_get_type_name(void)
363{
364 return fs_get_info(fs_type)->name;
365}
366
Stephen Warren045fa1e2012-10-22 06:43:51 +0000367int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
368{
Simon Glass436e2b72012-12-26 09:53:29 +0000369 struct fstype_info *info;
Stephen Warren045fa1e2012-10-22 06:43:51 +0000370 int part, i;
Stephen Warrena1b231c2012-10-30 07:50:47 +0000371#ifdef CONFIG_NEEDS_MANUAL_RELOC
372 static int relocated;
373
374 if (!relocated) {
Simon Glass436e2b72012-12-26 09:53:29 +0000375 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
376 i++, info++) {
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100377 info->name += gd->reloc_off;
Simon Glass436e2b72012-12-26 09:53:29 +0000378 info->probe += gd->reloc_off;
379 info->close += gd->reloc_off;
380 info->ls += gd->reloc_off;
381 info->read += gd->reloc_off;
Simon Glassa8f6ab52013-04-20 08:42:50 +0000382 info->write += gd->reloc_off;
Simon Glass436e2b72012-12-26 09:53:29 +0000383 }
Stephen Warrena1b231c2012-10-30 07:50:47 +0000384 relocated = 1;
385 }
386#endif
Stephen Warren045fa1e2012-10-22 06:43:51 +0000387
Sean Anderson71945272021-04-12 18:53:05 -0400388 part = part_get_info_by_dev_and_name_or_num(ifname, dev_part_str, &fs_dev_desc,
389 &fs_partition, 1);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000390 if (part < 0)
391 return -1;
392
Simon Glass436e2b72012-12-26 09:53:29 +0000393 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
394 if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY &&
395 fstype != info->fstype)
Stephen Warren045fa1e2012-10-22 06:43:51 +0000396 continue;
397
Stephen Warren377202b2014-02-03 13:21:01 -0700398 if (!fs_dev_desc && !info->null_dev_desc_ok)
399 continue;
400
Simon Glass2ded0d42012-12-26 09:53:31 +0000401 if (!info->probe(fs_dev_desc, &fs_partition)) {
Simon Glass436e2b72012-12-26 09:53:29 +0000402 fs_type = info->fstype;
Rob Clark4bbcc962017-09-09 13:15:55 -0400403 fs_dev_part = part;
404 return 0;
405 }
406 }
407
408 return -1;
409}
410
411/* set current blk device w/ blk_desc + partition # */
412int fs_set_blk_dev_with_part(struct blk_desc *desc, int part)
413{
414 struct fstype_info *info;
415 int ret, i;
416
417 if (part >= 1)
418 ret = part_get_info(desc, part, &fs_partition);
419 else
420 ret = part_get_info_whole_disk(desc, &fs_partition);
421 if (ret)
422 return ret;
423 fs_dev_desc = desc;
424
425 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
426 if (!info->probe(fs_dev_desc, &fs_partition)) {
427 fs_type = info->fstype;
AKASHI Takahirob0c78d82018-10-17 16:32:02 +0900428 fs_dev_part = part;
Stephen Warren045fa1e2012-10-22 06:43:51 +0000429 return 0;
430 }
431 }
432
Stephen Warren045fa1e2012-10-22 06:43:51 +0000433 return -1;
434}
435
AKASHI Takahiro64f49eb2019-10-07 14:59:35 +0900436void fs_close(void)
Stephen Warren045fa1e2012-10-22 06:43:51 +0000437{
Simon Glassc6f548d2012-12-26 09:53:30 +0000438 struct fstype_info *info = fs_get_info(fs_type);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000439
Simon Glassc6f548d2012-12-26 09:53:30 +0000440 info->close();
Simon Glasse6d52412012-12-26 09:53:33 +0000441
Stephen Warren045fa1e2012-10-22 06:43:51 +0000442 fs_type = FS_TYPE_ANY;
443}
444
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100445int fs_uuid(char *uuid_str)
446{
447 struct fstype_info *info = fs_get_info(fs_type);
448
449 return info->uuid(uuid_str);
450}
451
Stephen Warren045fa1e2012-10-22 06:43:51 +0000452int fs_ls(const char *dirname)
453{
454 int ret;
455
Simon Glassc6f548d2012-12-26 09:53:30 +0000456 struct fstype_info *info = fs_get_info(fs_type);
457
458 ret = info->ls(dirname);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000459
460 fs_close();
461
462 return ret;
463}
464
Stephen Warren61529162014-02-03 13:21:00 -0700465int fs_exists(const char *filename)
466{
467 int ret;
468
469 struct fstype_info *info = fs_get_info(fs_type);
470
471 ret = info->exists(filename);
472
473 fs_close();
474
475 return ret;
476}
477
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800478int fs_size(const char *filename, loff_t *size)
Stephen Warrencf659812014-06-11 12:47:26 -0600479{
480 int ret;
481
482 struct fstype_info *info = fs_get_info(fs_type);
483
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800484 ret = info->size(filename, size);
Stephen Warrencf659812014-06-11 12:47:26 -0600485
486 fs_close();
487
488 return ret;
489}
490
Simon Goldschmidtaa3c6092019-01-14 22:38:19 +0100491#ifdef CONFIG_LMB
492/* Check if a file may be read to the given address */
493static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
494 loff_t len, struct fstype_info *info)
495{
496 struct lmb lmb;
497 int ret;
498 loff_t size;
499 loff_t read_len;
500
501 /* get the actual size of the file */
502 ret = info->size(filename, &size);
503 if (ret)
504 return ret;
505 if (offset >= size) {
506 /* offset >= EOF, no bytes will be written */
507 return 0;
508 }
509 read_len = size - offset;
510
511 /* limit to 'len' if it is smaller */
512 if (len && len < read_len)
513 read_len = len;
514
Simon Goldschmidt9cc23232019-01-26 22:13:04 +0100515 lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
Simon Goldschmidtaa3c6092019-01-14 22:38:19 +0100516 lmb_dump_all(&lmb);
517
518 if (lmb_alloc_addr(&lmb, addr, read_len) == addr)
519 return 0;
520
Heinrich Schuchardt0d32d8c2020-08-25 17:49:16 +0000521 log_err("** Reading file would overwrite reserved memory **\n");
Simon Goldschmidtaa3c6092019-01-14 22:38:19 +0100522 return -ENOSPC;
523}
524#endif
525
526static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
527 int do_lmb_check, loff_t *actread)
Stephen Warren045fa1e2012-10-22 06:43:51 +0000528{
Simon Glassc6f548d2012-12-26 09:53:30 +0000529 struct fstype_info *info = fs_get_info(fs_type);
Simon Glass117e0502012-12-26 09:53:32 +0000530 void *buf;
Stephen Warren045fa1e2012-10-22 06:43:51 +0000531 int ret;
532
Simon Goldschmidtaa3c6092019-01-14 22:38:19 +0100533#ifdef CONFIG_LMB
534 if (do_lmb_check) {
535 ret = fs_read_lmb_check(filename, addr, offset, len, info);
536 if (ret)
537 return ret;
538 }
539#endif
540
Simon Glass117e0502012-12-26 09:53:32 +0000541 /*
542 * We don't actually know how many bytes are being read, since len==0
543 * means read the whole file.
544 */
545 buf = map_sysmem(addr, len);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800546 ret = info->read(filename, buf, offset, len, actread);
Simon Glass117e0502012-12-26 09:53:32 +0000547 unmap_sysmem(buf);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000548
Simon Glassc6f548d2012-12-26 09:53:30 +0000549 /* If we requested a specific number of bytes, check we got it */
Max Krummenacher7a3e70c2015-08-05 17:16:58 +0200550 if (ret == 0 && len && *actread != len)
Heinrich Schuchardt0d32d8c2020-08-25 17:49:16 +0000551 log_debug("** %s shorter than offset + len **\n", filename);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000552 fs_close();
553
554 return ret;
555}
556
Simon Goldschmidtaa3c6092019-01-14 22:38:19 +0100557int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
558 loff_t *actread)
559{
560 return _fs_read(filename, addr, offset, len, 0, actread);
561}
562
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800563int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
564 loff_t *actwrite)
Simon Glassa8f6ab52013-04-20 08:42:50 +0000565{
566 struct fstype_info *info = fs_get_info(fs_type);
567 void *buf;
568 int ret;
569
Simon Glassa8f6ab52013-04-20 08:42:50 +0000570 buf = map_sysmem(addr, len);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800571 ret = info->write(filename, buf, offset, len, actwrite);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000572 unmap_sysmem(buf);
573
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800574 if (ret < 0 && len != *actwrite) {
Heinrich Schuchardt0d32d8c2020-08-25 17:49:16 +0000575 log_err("** Unable to write file %s **\n", filename);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000576 ret = -1;
577 }
578 fs_close();
579
580 return ret;
581}
582
Rob Clark4bbcc962017-09-09 13:15:55 -0400583struct fs_dir_stream *fs_opendir(const char *filename)
584{
585 struct fstype_info *info = fs_get_info(fs_type);
586 struct fs_dir_stream *dirs = NULL;
587 int ret;
588
589 ret = info->opendir(filename, &dirs);
590 fs_close();
591 if (ret) {
592 errno = -ret;
593 return NULL;
594 }
595
596 dirs->desc = fs_dev_desc;
597 dirs->part = fs_dev_part;
598
599 return dirs;
600}
601
602struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs)
603{
604 struct fstype_info *info;
605 struct fs_dirent *dirent;
606 int ret;
607
608 fs_set_blk_dev_with_part(dirs->desc, dirs->part);
609 info = fs_get_info(fs_type);
610
611 ret = info->readdir(dirs, &dirent);
612 fs_close();
613 if (ret) {
614 errno = -ret;
615 return NULL;
616 }
617
618 return dirent;
619}
620
621void fs_closedir(struct fs_dir_stream *dirs)
622{
623 struct fstype_info *info;
624
625 if (!dirs)
626 return;
627
628 fs_set_blk_dev_with_part(dirs->desc, dirs->part);
629 info = fs_get_info(fs_type);
630
631 info->closedir(dirs);
632 fs_close();
633}
634
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900635int fs_unlink(const char *filename)
636{
637 int ret;
638
639 struct fstype_info *info = fs_get_info(fs_type);
640
641 ret = info->unlink(filename);
642
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900643 fs_close();
644
645 return ret;
646}
Rob Clark4bbcc962017-09-09 13:15:55 -0400647
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900648int fs_mkdir(const char *dirname)
649{
650 int ret;
651
652 struct fstype_info *info = fs_get_info(fs_type);
653
654 ret = info->mkdir(dirname);
655
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900656 fs_close();
657
658 return ret;
659}
660
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100661int fs_ln(const char *fname, const char *target)
662{
663 struct fstype_info *info = fs_get_info(fs_type);
664 int ret;
665
666 ret = info->ln(fname, target);
667
668 if (ret < 0) {
Heinrich Schuchardt0d32d8c2020-08-25 17:49:16 +0000669 log_err("** Unable to create link %s -> %s **\n", fname, target);
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100670 ret = -1;
671 }
672 fs_close();
673
674 return ret;
675}
676
Simon Glass09140112020-05-10 11:40:03 -0600677int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
678 int fstype)
Stephen Warrencf659812014-06-11 12:47:26 -0600679{
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800680 loff_t size;
Stephen Warrencf659812014-06-11 12:47:26 -0600681
682 if (argc != 4)
683 return CMD_RET_USAGE;
684
685 if (fs_set_blk_dev(argv[1], argv[2], fstype))
686 return 1;
687
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800688 if (fs_size(argv[3], &size) < 0)
Stephen Warrencf659812014-06-11 12:47:26 -0600689 return CMD_RET_FAILURE;
690
Simon Glass018f5302017-08-03 12:22:10 -0600691 env_set_hex("filesize", size);
Stephen Warrencf659812014-06-11 12:47:26 -0600692
693 return 0;
694}
695
Simon Glass09140112020-05-10 11:40:03 -0600696int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
697 int fstype)
Stephen Warren045fa1e2012-10-22 06:43:51 +0000698{
699 unsigned long addr;
700 const char *addr_str;
701 const char *filename;
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800702 loff_t bytes;
703 loff_t pos;
704 loff_t len_read;
705 int ret;
Andreas Bießmannda1fd962012-11-14 13:32:37 +0100706 unsigned long time;
Pavel Machek949bbd72014-07-09 22:42:57 +0200707 char *ep;
Stephen Warren045fa1e2012-10-22 06:43:51 +0000708
Stephen Warrene9b0f992012-10-30 12:04:17 +0000709 if (argc < 2)
710 return CMD_RET_USAGE;
711 if (argc > 7)
Stephen Warren045fa1e2012-10-22 06:43:51 +0000712 return CMD_RET_USAGE;
713
Heinrich Schuchardtec9d19b2021-01-27 21:26:43 +0100714 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype)) {
715 log_err("Can't set block device\n");
Stephen Warren045fa1e2012-10-22 06:43:51 +0000716 return 1;
Heinrich Schuchardtec9d19b2021-01-27 21:26:43 +0100717 }
Stephen Warren045fa1e2012-10-22 06:43:51 +0000718
719 if (argc >= 4) {
Simon Glass7e5f4602021-07-24 09:03:29 -0600720 addr = hextoul(argv[3], &ep);
Pavel Machek949bbd72014-07-09 22:42:57 +0200721 if (ep == argv[3] || *ep != '\0')
722 return CMD_RET_USAGE;
Stephen Warren045fa1e2012-10-22 06:43:51 +0000723 } else {
Simon Glass00caae62017-08-03 12:22:12 -0600724 addr_str = env_get("loadaddr");
Stephen Warren045fa1e2012-10-22 06:43:51 +0000725 if (addr_str != NULL)
Simon Glass7e5f4602021-07-24 09:03:29 -0600726 addr = hextoul(addr_str, NULL);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000727 else
728 addr = CONFIG_SYS_LOAD_ADDR;
729 }
730 if (argc >= 5) {
731 filename = argv[4];
732 } else {
Simon Glass00caae62017-08-03 12:22:12 -0600733 filename = env_get("bootfile");
Stephen Warren045fa1e2012-10-22 06:43:51 +0000734 if (!filename) {
735 puts("** No boot file defined **\n");
736 return 1;
737 }
738 }
739 if (argc >= 6)
Simon Glass7e5f4602021-07-24 09:03:29 -0600740 bytes = hextoul(argv[5], NULL);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000741 else
742 bytes = 0;
743 if (argc >= 7)
Simon Glass7e5f4602021-07-24 09:03:29 -0600744 pos = hextoul(argv[6], NULL);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000745 else
746 pos = 0;
747
Andreas Bießmannda1fd962012-11-14 13:32:37 +0100748 time = get_timer(0);
Simon Goldschmidtaa3c6092019-01-14 22:38:19 +0100749 ret = _fs_read(filename, addr, pos, bytes, 1, &len_read);
Andreas Bießmannda1fd962012-11-14 13:32:37 +0100750 time = get_timer(time);
Heinrich Schuchardt1244f362020-06-29 20:08:49 +0200751 if (ret < 0) {
Heinrich Schuchardt0d32d8c2020-08-25 17:49:16 +0000752 log_err("Failed to load '%s'\n", filename);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000753 return 1;
Heinrich Schuchardt1244f362020-06-29 20:08:49 +0200754 }
755
756 if (IS_ENABLED(CONFIG_CMD_BOOTEFI))
757 efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "",
Heinrich Schuchardt5f595182021-01-12 12:46:24 +0100758 (argc > 4) ? argv[4] : "", map_sysmem(addr, 0),
759 len_read);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000760
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800761 printf("%llu bytes read in %lu ms", len_read, time);
Andreas Bießmannda1fd962012-11-14 13:32:37 +0100762 if (time > 0) {
763 puts(" (");
Tom Rini9e374e72014-11-24 11:50:46 -0500764 print_size(div_u64(len_read, time) * 1000, "/s");
Andreas Bießmannda1fd962012-11-14 13:32:37 +0100765 puts(")");
766 }
767 puts("\n");
Stephen Warren045fa1e2012-10-22 06:43:51 +0000768
Simon Glass018f5302017-08-03 12:22:10 -0600769 env_set_hex("fileaddr", addr);
770 env_set_hex("filesize", len_read);
Stephen Warren045fa1e2012-10-22 06:43:51 +0000771
772 return 0;
773}
774
Simon Glass09140112020-05-10 11:40:03 -0600775int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
776 int fstype)
Stephen Warren045fa1e2012-10-22 06:43:51 +0000777{
778 if (argc < 2)
779 return CMD_RET_USAGE;
Stephen Warrene9b0f992012-10-30 12:04:17 +0000780 if (argc > 4)
781 return CMD_RET_USAGE;
Stephen Warren045fa1e2012-10-22 06:43:51 +0000782
783 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
784 return 1;
785
Stephen Warrene9b0f992012-10-30 12:04:17 +0000786 if (fs_ls(argc >= 4 ? argv[3] : "/"))
Stephen Warren045fa1e2012-10-22 06:43:51 +0000787 return 1;
788
789 return 0;
790}
Simon Glassa8f6ab52013-04-20 08:42:50 +0000791
Stephen Warren61529162014-02-03 13:21:00 -0700792int file_exists(const char *dev_type, const char *dev_part, const char *file,
793 int fstype)
794{
795 if (fs_set_blk_dev(dev_type, dev_part, fstype))
796 return 0;
797
798 return fs_exists(file);
799}
800
Simon Glass09140112020-05-10 11:40:03 -0600801int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
802 int fstype)
Simon Glassa8f6ab52013-04-20 08:42:50 +0000803{
804 unsigned long addr;
805 const char *filename;
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800806 loff_t bytes;
807 loff_t pos;
808 loff_t len;
809 int ret;
Simon Glassa8f6ab52013-04-20 08:42:50 +0000810 unsigned long time;
811
812 if (argc < 6 || argc > 7)
813 return CMD_RET_USAGE;
814
815 if (fs_set_blk_dev(argv[1], argv[2], fstype))
816 return 1;
817
Simon Glass7e5f4602021-07-24 09:03:29 -0600818 addr = hextoul(argv[3], NULL);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800819 filename = argv[4];
Simon Glass7e5f4602021-07-24 09:03:29 -0600820 bytes = hextoul(argv[5], NULL);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000821 if (argc >= 7)
Simon Glass7e5f4602021-07-24 09:03:29 -0600822 pos = hextoul(argv[6], NULL);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000823 else
824 pos = 0;
825
826 time = get_timer(0);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800827 ret = fs_write(filename, addr, pos, bytes, &len);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000828 time = get_timer(time);
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800829 if (ret < 0)
Simon Glassa8f6ab52013-04-20 08:42:50 +0000830 return 1;
831
Suriyan Ramasamid455d872014-11-17 14:39:38 -0800832 printf("%llu bytes written in %lu ms", len, time);
Simon Glassa8f6ab52013-04-20 08:42:50 +0000833 if (time > 0) {
834 puts(" (");
Tom Rini9e374e72014-11-24 11:50:46 -0500835 print_size(div_u64(len, time) * 1000, "/s");
Simon Glassa8f6ab52013-04-20 08:42:50 +0000836 puts(")");
837 }
838 puts("\n");
839
840 return 0;
841}
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100842
Simon Glass09140112020-05-10 11:40:03 -0600843int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
844 int fstype)
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100845{
846 int ret;
847 char uuid[37];
848 memset(uuid, 0, sizeof(uuid));
849
850 if (argc < 3 || argc > 4)
851 return CMD_RET_USAGE;
852
853 if (fs_set_blk_dev(argv[1], argv[2], fstype))
854 return 1;
855
856 ret = fs_uuid(uuid);
857 if (ret)
858 return CMD_RET_FAILURE;
859
860 if (argc == 4)
Simon Glass382bee52017-08-03 12:22:09 -0600861 env_set(argv[3], uuid);
Christian Gmeiner59e890e2014-11-12 14:35:04 +0100862 else
863 printf("%s\n", uuid);
864
865 return CMD_RET_SUCCESS;
866}
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100867
Simon Glass09140112020-05-10 11:40:03 -0600868int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100869{
870 struct fstype_info *info;
871
872 if (argc < 3 || argc > 4)
873 return CMD_RET_USAGE;
874
875 if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY))
876 return 1;
877
878 info = fs_get_info(fs_type);
879
880 if (argc == 4)
Simon Glass382bee52017-08-03 12:22:09 -0600881 env_set(argv[3], info->name);
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100882 else
883 printf("%s\n", info->name);
884
Marek Vasute531c672019-02-06 13:19:29 +0100885 fs_close();
886
Sjoerd Simons1a1ad8e2015-01-05 18:13:36 +0100887 return CMD_RET_SUCCESS;
888}
889
Simon Glass09140112020-05-10 11:40:03 -0600890int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
AKASHI Takahiroe2519da2018-09-11 15:59:13 +0900891 int fstype)
892{
893 if (argc != 4)
894 return CMD_RET_USAGE;
895
896 if (fs_set_blk_dev(argv[1], argv[2], fstype))
897 return 1;
898
899 if (fs_unlink(argv[3]))
900 return 1;
901
902 return 0;
903}
904
Simon Glass09140112020-05-10 11:40:03 -0600905int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900906 int fstype)
907{
908 int ret;
909
910 if (argc != 4)
911 return CMD_RET_USAGE;
912
913 if (fs_set_blk_dev(argv[1], argv[2], fstype))
914 return 1;
915
916 ret = fs_mkdir(argv[3]);
917 if (ret) {
Heinrich Schuchardt0d32d8c2020-08-25 17:49:16 +0000918 log_err("** Unable to create a directory \"%s\" **\n", argv[3]);
AKASHI Takahiroe7074cf2018-09-11 15:59:08 +0900919 return 1;
920 }
921
922 return 0;
923}
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100924
Simon Glass09140112020-05-10 11:40:03 -0600925int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
Jean-Jacques Hiblotaaa12152019-02-13 12:15:26 +0100926 int fstype)
927{
928 if (argc != 5)
929 return CMD_RET_USAGE;
930
931 if (fs_set_blk_dev(argv[1], argv[2], fstype))
932 return 1;
933
934 if (fs_ln(argv[3], argv[4]))
935 return 1;
936
937 return 0;
938}
Niel Fourie2280fa52020-03-24 16:17:04 +0100939
940int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
941{
942 struct fstype_info *drv = fstypes;
943 const int n_ents = ARRAY_SIZE(fstypes);
944 struct fstype_info *entry;
945 int i = 0;
946
947 puts("Supported filesystems");
948 for (entry = drv; entry != drv + n_ents; entry++) {
949 if (entry->fstype != FS_TYPE_ANY) {
950 printf("%c %s", i ? ',' : ':', entry->name);
951 i++;
952 }
953 }
954 if (!i)
955 puts(": <none>");
956 puts("\n");
957 return CMD_RET_SUCCESS;
958}