blob: 99dac0fd79fe8b4e54a97136c5871ad906ea2b7a [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 Glass3ba929a2020-10-30 21:38:53 -060023#include <asm/global_data.h>
Simon Glasscbe5d5d2012-12-26 09:53:32 +000024#include <asm/io.h>
Tom Rinia17b7bc2014-11-24 11:50:46 -050025#include <div64.h>
26#include <linux/math64.h>
Mian Yousaf Kaukab961ebe82019-06-18 15:03:44 +020027#include <efi_loader.h>
Joao Marcos Costa29da3742020-07-30 15:33:47 +020028#include <squashfs.h>
Huang Jianan024fb2f2022-02-26 15:05:47 +080029#include <erofs.h>
Stephen Warreneefbc3f2012-10-22 06:43:51 +000030
Stephen Warren44161af2012-10-30 07:50:47 +000031DECLARE_GLOBAL_DATA_PTR;
32
Simon Glasse3394752016-02-29 15:25:34 -070033static struct blk_desc *fs_dev_desc;
Rob Clark2b7bfd92017-09-09 13:15:55 -040034static int fs_dev_part;
Simon Glassc1c4a8f2020-05-10 11:39:57 -060035static struct disk_partition fs_partition;
Stephen Warreneefbc3f2012-10-22 06:43:51 +000036static int fs_type = FS_TYPE_ANY;
37
Simon Glasse3394752016-02-29 15:25:34 -070038static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
Simon Glassc1c4a8f2020-05-10 11:39:57 -060039 struct disk_partition *fs_partition)
Simon Glass1aede482012-12-26 09:53:29 +000040{
Heinrich Schuchardt3f006d52021-09-20 14:15:03 +020041 log_debug("Unrecognized filesystem type\n");
Simon Glass1aede482012-12-26 09:53:29 +000042 return -1;
43}
44
Stephen Warreneefbc3f2012-10-22 06:43:51 +000045static inline int fs_ls_unsupported(const char *dirname)
46{
Stephen Warreneefbc3f2012-10-22 06:43:51 +000047 return -1;
48}
49
Rob Clark60d74a92017-09-09 13:15:58 -040050/* generic implementation of ls in terms of opendir/readdir/closedir */
51__maybe_unused
52static int fs_ls_generic(const char *dirname)
53{
54 struct fs_dir_stream *dirs;
55 struct fs_dirent *dent;
56 int nfiles = 0, ndirs = 0;
57
58 dirs = fs_opendir(dirname);
59 if (!dirs)
60 return -errno;
61
62 while ((dent = fs_readdir(dirs))) {
63 if (dent->type == FS_DT_DIR) {
64 printf(" %s/\n", dent->name);
65 ndirs++;
Joao Marcos Costa2a7fb152020-07-30 15:33:51 +020066 } else if (dent->type == FS_DT_LNK) {
67 printf(" <SYM> %s\n", dent->name);
68 nfiles++;
Rob Clark60d74a92017-09-09 13:15:58 -040069 } else {
70 printf(" %8lld %s\n", dent->size, dent->name);
71 nfiles++;
72 }
73 }
74
75 fs_closedir(dirs);
76
77 printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs);
78
79 return 0;
80}
81
Stephen Warrend008fbb2014-02-03 13:21:00 -070082static inline int fs_exists_unsupported(const char *filename)
83{
84 return 0;
85}
86
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080087static inline int fs_size_unsupported(const char *filename, loff_t *size)
Stephen Warren3eb58f52014-06-11 12:47:26 -060088{
89 return -1;
90}
91
Simon Glasscbe5d5d2012-12-26 09:53:32 +000092static inline int fs_read_unsupported(const char *filename, void *buf,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -080093 loff_t offset, loff_t len,
94 loff_t *actread)
Stephen Warreneefbc3f2012-10-22 06:43:51 +000095{
Stephen Warreneefbc3f2012-10-22 06:43:51 +000096 return -1;
97}
98
Simon Glasseda14ea2013-04-20 08:42:50 +000099static inline int fs_write_unsupported(const char *filename, void *buf,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800100 loff_t offset, loff_t len,
101 loff_t *actwrite)
Simon Glasseda14ea2013-04-20 08:42:50 +0000102{
103 return -1;
104}
105
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100106static inline int fs_ln_unsupported(const char *filename, const char *target)
107{
108 return -1;
109}
110
Simon Glass1aede482012-12-26 09:53:29 +0000111static inline void fs_close_unsupported(void)
112{
113}
114
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100115static inline int fs_uuid_unsupported(char *uuid_str)
116{
117 return -1;
118}
119
Rob Clark2b7bfd92017-09-09 13:15:55 -0400120static inline int fs_opendir_unsupported(const char *filename,
121 struct fs_dir_stream **dirs)
122{
123 return -EACCES;
124}
125
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900126static inline int fs_unlink_unsupported(const char *filename)
127{
128 return -1;
129}
130
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900131static inline int fs_mkdir_unsupported(const char *dirname)
132{
133 return -1;
134}
135
Simon Glass1aede482012-12-26 09:53:29 +0000136struct fstype_info {
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000137 int fstype;
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100138 char *name;
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700139 /*
140 * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This
141 * should be false in most cases. For "virtual" filesystems which
142 * aren't based on a U-Boot block device (e.g. sandbox), this can be
Heinrich Schuchardt99dc17d2018-08-11 15:52:14 +0200143 * set to true. This should also be true for the dummy entry at the end
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700144 * of fstypes[], since that is essentially a "virtual" (non-existent)
145 * filesystem.
146 */
147 bool null_dev_desc_ok;
Simon Glasse3394752016-02-29 15:25:34 -0700148 int (*probe)(struct blk_desc *fs_dev_desc,
Simon Glassc1c4a8f2020-05-10 11:39:57 -0600149 struct disk_partition *fs_partition);
Simon Glass1aede482012-12-26 09:53:29 +0000150 int (*ls)(const char *dirname);
Stephen Warrend008fbb2014-02-03 13:21:00 -0700151 int (*exists)(const char *filename);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800152 int (*size)(const char *filename, loff_t *size);
153 int (*read)(const char *filename, void *buf, loff_t offset,
154 loff_t len, loff_t *actread);
155 int (*write)(const char *filename, void *buf, loff_t offset,
156 loff_t len, loff_t *actwrite);
Simon Glass1aede482012-12-26 09:53:29 +0000157 void (*close)(void);
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100158 int (*uuid)(char *uuid_str);
Rob Clark2b7bfd92017-09-09 13:15:55 -0400159 /*
160 * Open a directory stream. On success return 0 and directory
161 * stream pointer via 'dirsp'. On error, return -errno. See
162 * fs_opendir().
163 */
164 int (*opendir)(const char *filename, struct fs_dir_stream **dirsp);
165 /*
166 * Read next entry from directory stream. On success return 0
167 * and directory entry pointer via 'dentp'. On error return
168 * -errno. See fs_readdir().
169 */
170 int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp);
171 /* see fs_closedir() */
172 void (*closedir)(struct fs_dir_stream *dirs);
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900173 int (*unlink)(const char *filename);
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900174 int (*mkdir)(const char *dirname);
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100175 int (*ln)(const char *filename, const char *target);
Simon Glass1aede482012-12-26 09:53:29 +0000176};
177
178static struct fstype_info fstypes[] = {
179#ifdef CONFIG_FS_FAT
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000180 {
181 .fstype = FS_TYPE_FAT,
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100182 .name = "fat",
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700183 .null_dev_desc_ok = false,
Simon Glass19e38582012-12-26 09:53:33 +0000184 .probe = fat_set_blk_dev,
185 .close = fat_close,
Rob Clark60d74a92017-09-09 13:15:58 -0400186 .ls = fs_ls_generic,
Stephen Warren1d2f9a02014-02-03 13:21:10 -0700187 .exists = fat_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600188 .size = fat_size,
Simon Glass19e38582012-12-26 09:53:33 +0000189 .read = fat_read_file,
Tien Fong Chee87fda0c2019-01-23 14:20:04 +0800190#if CONFIG_IS_ENABLED(FAT_WRITE)
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800191 .write = file_fat_write,
AKASHI Takahiro73b34972018-09-11 15:59:14 +0900192 .unlink = fat_unlink,
AKASHI Takahiro1c24b7b2018-09-11 15:59:10 +0900193 .mkdir = fat_mkdir,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800194#else
Stephen Warren9df25802014-02-03 13:20:59 -0700195 .write = fs_write_unsupported,
AKASHI Takahiro73b34972018-09-11 15:59:14 +0900196 .unlink = fs_unlink_unsupported,
AKASHI Takahiro1c24b7b2018-09-11 15:59:10 +0900197 .mkdir = fs_mkdir_unsupported,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800198#endif
Heinrich Schuchardtfac91832020-12-31 00:38:13 +0100199 .uuid = fat_uuid,
Rob Clark60d74a92017-09-09 13:15:58 -0400200 .opendir = fat_opendir,
201 .readdir = fat_readdir,
202 .closedir = fat_closedir,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100203 .ln = fs_ln_unsupported,
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000204 },
Simon Glass1aede482012-12-26 09:53:29 +0000205#endif
Tien Fong Chee64eab042019-01-23 14:20:06 +0800206
207#if CONFIG_IS_ENABLED(FS_EXT4)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000208 {
209 .fstype = FS_TYPE_EXT,
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100210 .name = "ext4",
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700211 .null_dev_desc_ok = false,
Simon Glass19e38582012-12-26 09:53:33 +0000212 .probe = ext4fs_probe,
213 .close = ext4fs_close,
Simon Glass1aede482012-12-26 09:53:29 +0000214 .ls = ext4fs_ls,
Stephen Warren12d6d0c2014-02-03 13:21:09 -0700215 .exists = ext4fs_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600216 .size = ext4fs_size,
Simon Glass19e38582012-12-26 09:53:33 +0000217 .read = ext4_read_file,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800218#ifdef CONFIG_CMD_EXT4_WRITE
219 .write = ext4_write_file,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100220 .ln = ext4fs_create_link,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800221#else
Stephen Warren9df25802014-02-03 13:20:59 -0700222 .write = fs_write_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100223 .ln = fs_ln_unsupported,
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800224#endif
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100225 .uuid = ext4fs_uuid,
Rob Clark2b7bfd92017-09-09 13:15:55 -0400226 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900227 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900228 .mkdir = fs_mkdir_unsupported,
Simon Glass1aede482012-12-26 09:53:29 +0000229 },
230#endif
Simon Glass11842872012-12-26 09:53:35 +0000231#ifdef CONFIG_SANDBOX
232 {
233 .fstype = FS_TYPE_SANDBOX,
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100234 .name = "sandbox",
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700235 .null_dev_desc_ok = true,
Simon Glass11842872012-12-26 09:53:35 +0000236 .probe = sandbox_fs_set_blk_dev,
237 .close = sandbox_fs_close,
238 .ls = sandbox_fs_ls,
Stephen Warren97d66f22014-02-03 13:21:07 -0700239 .exists = sandbox_fs_exists,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600240 .size = sandbox_fs_size,
Simon Glass11842872012-12-26 09:53:35 +0000241 .read = fs_read_sandbox,
Simon Glassea307e82013-04-20 08:42:51 +0000242 .write = fs_write_sandbox,
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100243 .uuid = fs_uuid_unsupported,
Rob Clark2b7bfd92017-09-09 13:15:55 -0400244 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900245 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900246 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100247 .ln = fs_ln_unsupported,
Simon Glass11842872012-12-26 09:53:35 +0000248 },
249#endif
Hans de Goede690c7962015-09-17 18:46:58 -0400250#ifdef CONFIG_CMD_UBIFS
251 {
252 .fstype = FS_TYPE_UBIFS,
253 .name = "ubifs",
254 .null_dev_desc_ok = true,
255 .probe = ubifs_set_blk_dev,
256 .close = ubifs_close,
257 .ls = ubifs_ls,
258 .exists = ubifs_exists,
259 .size = ubifs_size,
260 .read = ubifs_read,
261 .write = fs_write_unsupported,
262 .uuid = fs_uuid_unsupported,
Rob Clark2b7bfd92017-09-09 13:15:55 -0400263 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900264 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900265 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100266 .ln = fs_ln_unsupported,
Hans de Goede690c7962015-09-17 18:46:58 -0400267 },
268#endif
Marek BehĂșn98ec1d12017-09-03 17:00:29 +0200269#ifdef CONFIG_FS_BTRFS
270 {
271 .fstype = FS_TYPE_BTRFS,
272 .name = "btrfs",
273 .null_dev_desc_ok = false,
274 .probe = btrfs_probe,
275 .close = btrfs_close,
276 .ls = btrfs_ls,
277 .exists = btrfs_exists,
278 .size = btrfs_size,
279 .read = btrfs_read,
280 .write = fs_write_unsupported,
281 .uuid = btrfs_uuid,
Marek BehĂșn90762d92017-10-06 16:56:07 +0200282 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900283 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900284 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100285 .ln = fs_ln_unsupported,
Marek BehĂșn98ec1d12017-09-03 17:00:29 +0200286 },
287#endif
Joao Marcos Costa29da3742020-07-30 15:33:47 +0200288#if IS_ENABLED(CONFIG_FS_SQUASHFS)
289 {
290 .fstype = FS_TYPE_SQUASHFS,
291 .name = "squashfs",
Richard Genoud654b2482020-11-03 12:10:59 +0100292 .null_dev_desc_ok = false,
Joao Marcos Costa29da3742020-07-30 15:33:47 +0200293 .probe = sqfs_probe,
294 .opendir = sqfs_opendir,
295 .readdir = sqfs_readdir,
296 .ls = fs_ls_generic,
297 .read = sqfs_read,
298 .size = sqfs_size,
299 .close = sqfs_close,
300 .closedir = sqfs_closedir,
Richard Genoudcfca20c2020-11-03 12:11:26 +0100301 .exists = sqfs_exists,
Richard Genoud654b2482020-11-03 12:10:59 +0100302 .uuid = fs_uuid_unsupported,
303 .write = fs_write_unsupported,
304 .ln = fs_ln_unsupported,
305 .unlink = fs_unlink_unsupported,
306 .mkdir = fs_mkdir_unsupported,
Joao Marcos Costa29da3742020-07-30 15:33:47 +0200307 },
308#endif
Huang Jianan024fb2f2022-02-26 15:05:47 +0800309#if IS_ENABLED(CONFIG_FS_EROFS)
310 {
311 .fstype = FS_TYPE_EROFS,
312 .name = "erofs",
313 .null_dev_desc_ok = false,
314 .probe = erofs_probe,
315 .opendir = erofs_opendir,
316 .readdir = erofs_readdir,
317 .ls = fs_ls_generic,
318 .read = erofs_read,
319 .size = erofs_size,
320 .close = erofs_close,
321 .closedir = erofs_closedir,
322 .exists = erofs_exists,
323 .uuid = fs_uuid_unsupported,
324 .write = fs_write_unsupported,
325 .ln = fs_ln_unsupported,
326 .unlink = fs_unlink_unsupported,
327 .mkdir = fs_mkdir_unsupported,
328 },
329#endif
Simon Glass1aede482012-12-26 09:53:29 +0000330 {
331 .fstype = FS_TYPE_ANY,
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100332 .name = "unsupported",
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700333 .null_dev_desc_ok = true,
Simon Glass1aede482012-12-26 09:53:29 +0000334 .probe = fs_probe_unsupported,
335 .close = fs_close_unsupported,
336 .ls = fs_ls_unsupported,
Stephen Warrend008fbb2014-02-03 13:21:00 -0700337 .exists = fs_exists_unsupported,
Stephen Warren3eb58f52014-06-11 12:47:26 -0600338 .size = fs_size_unsupported,
Simon Glass1aede482012-12-26 09:53:29 +0000339 .read = fs_read_unsupported,
Simon Glasseda14ea2013-04-20 08:42:50 +0000340 .write = fs_write_unsupported,
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100341 .uuid = fs_uuid_unsupported,
Rob Clark2b7bfd92017-09-09 13:15:55 -0400342 .opendir = fs_opendir_unsupported,
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900343 .unlink = fs_unlink_unsupported,
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900344 .mkdir = fs_mkdir_unsupported,
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100345 .ln = fs_ln_unsupported,
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000346 },
347};
348
Simon Glasse6aad852012-12-26 09:53:30 +0000349static struct fstype_info *fs_get_info(int fstype)
350{
351 struct fstype_info *info;
352 int i;
353
354 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
355 if (fstype == info->fstype)
356 return info;
357 }
358
359 /* Return the 'unsupported' sentinel */
360 return info;
361}
362
Alex Kiernan3a6163a2018-05-29 15:30:50 +0000363/**
AKASHI Takahiro80ac7342019-10-07 14:59:37 +0900364 * fs_get_type() - Get type of current filesystem
365 *
366 * Return: filesystem type
367 *
368 * Returns filesystem type representing the current filesystem, or
369 * FS_TYPE_ANY for any unrecognised filesystem.
370 */
371int fs_get_type(void)
372{
373 return fs_type;
374}
375
376/**
Alex Kiernan3a6163a2018-05-29 15:30:50 +0000377 * fs_get_type_name() - Get type of current filesystem
378 *
379 * Return: Pointer to filesystem name
380 *
381 * Returns a string describing the current filesystem, or the sentinel
382 * "unsupported" for any unrecognised filesystem.
383 */
384const char *fs_get_type_name(void)
385{
386 return fs_get_info(fs_type)->name;
387}
388
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000389int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
390{
Simon Glass1aede482012-12-26 09:53:29 +0000391 struct fstype_info *info;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000392 int part, i;
Stephen Warren44161af2012-10-30 07:50:47 +0000393#ifdef CONFIG_NEEDS_MANUAL_RELOC
394 static int relocated;
395
396 if (!relocated) {
Simon Glass1aede482012-12-26 09:53:29 +0000397 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
398 i++, info++) {
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100399 info->name += gd->reloc_off;
Simon Glass1aede482012-12-26 09:53:29 +0000400 info->probe += gd->reloc_off;
401 info->close += gd->reloc_off;
402 info->ls += gd->reloc_off;
403 info->read += gd->reloc_off;
Simon Glasseda14ea2013-04-20 08:42:50 +0000404 info->write += gd->reloc_off;
Simon Glass1aede482012-12-26 09:53:29 +0000405 }
Stephen Warren44161af2012-10-30 07:50:47 +0000406 relocated = 1;
407 }
408#endif
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000409
Sean Andersonf476b4a2021-04-12 18:53:05 -0400410 part = part_get_info_by_dev_and_name_or_num(ifname, dev_part_str, &fs_dev_desc,
411 &fs_partition, 1);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000412 if (part < 0)
413 return -1;
414
Simon Glass1aede482012-12-26 09:53:29 +0000415 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
416 if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY &&
417 fstype != info->fstype)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000418 continue;
419
Stephen Warrenec63d4a2014-02-03 13:21:01 -0700420 if (!fs_dev_desc && !info->null_dev_desc_ok)
421 continue;
422
Simon Glass6a46e2f2012-12-26 09:53:31 +0000423 if (!info->probe(fs_dev_desc, &fs_partition)) {
Simon Glass1aede482012-12-26 09:53:29 +0000424 fs_type = info->fstype;
Rob Clark2b7bfd92017-09-09 13:15:55 -0400425 fs_dev_part = part;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000426 return 0;
427 }
428 }
429
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000430 return -1;
431}
432
Rob Clark2b7bfd92017-09-09 13:15:55 -0400433/* set current blk device w/ blk_desc + partition # */
434int fs_set_blk_dev_with_part(struct blk_desc *desc, int part)
435{
436 struct fstype_info *info;
437 int ret, i;
438
439 if (part >= 1)
440 ret = part_get_info(desc, part, &fs_partition);
441 else
442 ret = part_get_info_whole_disk(desc, &fs_partition);
443 if (ret)
444 return ret;
445 fs_dev_desc = desc;
446
447 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
448 if (!info->probe(fs_dev_desc, &fs_partition)) {
449 fs_type = info->fstype;
AKASHI Takahiro43efaa02018-10-17 16:32:02 +0900450 fs_dev_part = part;
Rob Clark2b7bfd92017-09-09 13:15:55 -0400451 return 0;
452 }
453 }
454
455 return -1;
456}
457
AKASHI Takahiroca8e3772019-10-07 14:59:35 +0900458void fs_close(void)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000459{
Simon Glasse6aad852012-12-26 09:53:30 +0000460 struct fstype_info *info = fs_get_info(fs_type);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000461
Simon Glasse6aad852012-12-26 09:53:30 +0000462 info->close();
Simon Glass19e38582012-12-26 09:53:33 +0000463
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000464 fs_type = FS_TYPE_ANY;
465}
466
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100467int fs_uuid(char *uuid_str)
468{
469 struct fstype_info *info = fs_get_info(fs_type);
470
471 return info->uuid(uuid_str);
472}
473
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000474int fs_ls(const char *dirname)
475{
476 int ret;
477
Simon Glasse6aad852012-12-26 09:53:30 +0000478 struct fstype_info *info = fs_get_info(fs_type);
479
480 ret = info->ls(dirname);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000481
482 fs_close();
483
484 return ret;
485}
486
Stephen Warrend008fbb2014-02-03 13:21:00 -0700487int fs_exists(const char *filename)
488{
489 int ret;
490
491 struct fstype_info *info = fs_get_info(fs_type);
492
493 ret = info->exists(filename);
494
495 fs_close();
496
497 return ret;
498}
499
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800500int fs_size(const char *filename, loff_t *size)
Stephen Warren3eb58f52014-06-11 12:47:26 -0600501{
502 int ret;
503
504 struct fstype_info *info = fs_get_info(fs_type);
505
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800506 ret = info->size(filename, size);
Stephen Warren3eb58f52014-06-11 12:47:26 -0600507
508 fs_close();
509
510 return ret;
511}
512
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100513#ifdef CONFIG_LMB
514/* Check if a file may be read to the given address */
515static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
516 loff_t len, struct fstype_info *info)
517{
518 struct lmb lmb;
519 int ret;
520 loff_t size;
521 loff_t read_len;
522
523 /* get the actual size of the file */
524 ret = info->size(filename, &size);
525 if (ret)
526 return ret;
527 if (offset >= size) {
528 /* offset >= EOF, no bytes will be written */
529 return 0;
530 }
531 read_len = size - offset;
532
533 /* limit to 'len' if it is smaller */
534 if (len && len < read_len)
535 read_len = len;
536
Simon Goldschmidt8890e7d2019-01-26 22:13:04 +0100537 lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100538 lmb_dump_all(&lmb);
539
540 if (lmb_alloc_addr(&lmb, addr, read_len) == addr)
541 return 0;
542
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000543 log_err("** Reading file would overwrite reserved memory **\n");
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100544 return -ENOSPC;
545}
546#endif
547
548static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
549 int do_lmb_check, loff_t *actread)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000550{
Simon Glasse6aad852012-12-26 09:53:30 +0000551 struct fstype_info *info = fs_get_info(fs_type);
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000552 void *buf;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000553 int ret;
554
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100555#ifdef CONFIG_LMB
556 if (do_lmb_check) {
557 ret = fs_read_lmb_check(filename, addr, offset, len, info);
558 if (ret)
559 return ret;
560 }
561#endif
562
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000563 /*
564 * We don't actually know how many bytes are being read, since len==0
565 * means read the whole file.
566 */
567 buf = map_sysmem(addr, len);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800568 ret = info->read(filename, buf, offset, len, actread);
Simon Glasscbe5d5d2012-12-26 09:53:32 +0000569 unmap_sysmem(buf);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000570
Simon Glasse6aad852012-12-26 09:53:30 +0000571 /* If we requested a specific number of bytes, check we got it */
Max Krummenacher56d9cdf2015-08-05 17:16:58 +0200572 if (ret == 0 && len && *actread != len)
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000573 log_debug("** %s shorter than offset + len **\n", filename);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000574 fs_close();
575
576 return ret;
577}
578
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100579int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
580 loff_t *actread)
581{
582 return _fs_read(filename, addr, offset, len, 0, actread);
583}
584
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800585int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
586 loff_t *actwrite)
Simon Glasseda14ea2013-04-20 08:42:50 +0000587{
588 struct fstype_info *info = fs_get_info(fs_type);
589 void *buf;
590 int ret;
591
Simon Glasseda14ea2013-04-20 08:42:50 +0000592 buf = map_sysmem(addr, len);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800593 ret = info->write(filename, buf, offset, len, actwrite);
Simon Glasseda14ea2013-04-20 08:42:50 +0000594 unmap_sysmem(buf);
595
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800596 if (ret < 0 && len != *actwrite) {
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000597 log_err("** Unable to write file %s **\n", filename);
Simon Glasseda14ea2013-04-20 08:42:50 +0000598 ret = -1;
599 }
600 fs_close();
601
602 return ret;
603}
604
Rob Clark2b7bfd92017-09-09 13:15:55 -0400605struct fs_dir_stream *fs_opendir(const char *filename)
606{
607 struct fstype_info *info = fs_get_info(fs_type);
608 struct fs_dir_stream *dirs = NULL;
609 int ret;
610
611 ret = info->opendir(filename, &dirs);
612 fs_close();
613 if (ret) {
614 errno = -ret;
615 return NULL;
616 }
617
618 dirs->desc = fs_dev_desc;
619 dirs->part = fs_dev_part;
620
621 return dirs;
622}
623
624struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs)
625{
626 struct fstype_info *info;
627 struct fs_dirent *dirent;
628 int ret;
629
630 fs_set_blk_dev_with_part(dirs->desc, dirs->part);
631 info = fs_get_info(fs_type);
632
633 ret = info->readdir(dirs, &dirent);
634 fs_close();
635 if (ret) {
636 errno = -ret;
637 return NULL;
638 }
639
640 return dirent;
641}
642
643void fs_closedir(struct fs_dir_stream *dirs)
644{
645 struct fstype_info *info;
646
647 if (!dirs)
648 return;
649
650 fs_set_blk_dev_with_part(dirs->desc, dirs->part);
651 info = fs_get_info(fs_type);
652
653 info->closedir(dirs);
654 fs_close();
655}
656
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900657int fs_unlink(const char *filename)
658{
659 int ret;
660
661 struct fstype_info *info = fs_get_info(fs_type);
662
663 ret = info->unlink(filename);
664
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900665 fs_close();
666
667 return ret;
668}
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900669
670int fs_mkdir(const char *dirname)
671{
672 int ret;
673
674 struct fstype_info *info = fs_get_info(fs_type);
675
676 ret = info->mkdir(dirname);
677
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900678 fs_close();
679
680 return ret;
681}
Rob Clark2b7bfd92017-09-09 13:15:55 -0400682
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100683int fs_ln(const char *fname, const char *target)
684{
685 struct fstype_info *info = fs_get_info(fs_type);
686 int ret;
687
688 ret = info->ln(fname, target);
689
690 if (ret < 0) {
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000691 log_err("** Unable to create link %s -> %s **\n", fname, target);
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100692 ret = -1;
693 }
694 fs_close();
695
696 return ret;
697}
698
Simon Glassed38aef2020-05-10 11:40:03 -0600699int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
700 int fstype)
Stephen Warren3eb58f52014-06-11 12:47:26 -0600701{
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800702 loff_t size;
Stephen Warren3eb58f52014-06-11 12:47:26 -0600703
704 if (argc != 4)
705 return CMD_RET_USAGE;
706
707 if (fs_set_blk_dev(argv[1], argv[2], fstype))
708 return 1;
709
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800710 if (fs_size(argv[3], &size) < 0)
Stephen Warren3eb58f52014-06-11 12:47:26 -0600711 return CMD_RET_FAILURE;
712
Simon Glass4d949a22017-08-03 12:22:10 -0600713 env_set_hex("filesize", size);
Stephen Warren3eb58f52014-06-11 12:47:26 -0600714
715 return 0;
716}
717
Simon Glassed38aef2020-05-10 11:40:03 -0600718int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
719 int fstype)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000720{
721 unsigned long addr;
722 const char *addr_str;
723 const char *filename;
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800724 loff_t bytes;
725 loff_t pos;
726 loff_t len_read;
727 int ret;
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100728 unsigned long time;
Pavel Machek4c1a9c52014-07-09 22:42:57 +0200729 char *ep;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000730
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000731 if (argc < 2)
732 return CMD_RET_USAGE;
733 if (argc > 7)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000734 return CMD_RET_USAGE;
735
Heinrich Schuchardtc556a452021-01-27 21:26:43 +0100736 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype)) {
737 log_err("Can't set block device\n");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000738 return 1;
Heinrich Schuchardtc556a452021-01-27 21:26:43 +0100739 }
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000740
741 if (argc >= 4) {
Simon Glass3ff49ec2021-07-24 09:03:29 -0600742 addr = hextoul(argv[3], &ep);
Pavel Machek4c1a9c52014-07-09 22:42:57 +0200743 if (ep == argv[3] || *ep != '\0')
744 return CMD_RET_USAGE;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000745 } else {
Simon Glass64b723f2017-08-03 12:22:12 -0600746 addr_str = env_get("loadaddr");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000747 if (addr_str != NULL)
Simon Glass3ff49ec2021-07-24 09:03:29 -0600748 addr = hextoul(addr_str, NULL);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000749 else
750 addr = CONFIG_SYS_LOAD_ADDR;
751 }
752 if (argc >= 5) {
753 filename = argv[4];
754 } else {
Simon Glass64b723f2017-08-03 12:22:12 -0600755 filename = env_get("bootfile");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000756 if (!filename) {
757 puts("** No boot file defined **\n");
758 return 1;
759 }
760 }
761 if (argc >= 6)
Simon Glass3ff49ec2021-07-24 09:03:29 -0600762 bytes = hextoul(argv[5], NULL);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000763 else
764 bytes = 0;
765 if (argc >= 7)
Simon Glass3ff49ec2021-07-24 09:03:29 -0600766 pos = hextoul(argv[6], NULL);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000767 else
768 pos = 0;
769
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100770 time = get_timer(0);
Simon Goldschmidt5b2c6872019-01-14 22:38:19 +0100771 ret = _fs_read(filename, addr, pos, bytes, 1, &len_read);
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100772 time = get_timer(time);
Heinrich Schuchardtca816ce2020-06-29 20:08:49 +0200773 if (ret < 0) {
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000774 log_err("Failed to load '%s'\n", filename);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000775 return 1;
Heinrich Schuchardtca816ce2020-06-29 20:08:49 +0200776 }
777
778 if (IS_ENABLED(CONFIG_CMD_BOOTEFI))
779 efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "",
Heinrich Schuchardt6b821592021-01-12 12:46:24 +0100780 (argc > 4) ? argv[4] : "", map_sysmem(addr, 0),
781 len_read);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000782
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800783 printf("%llu bytes read in %lu ms", len_read, time);
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100784 if (time > 0) {
785 puts(" (");
Tom Rinia17b7bc2014-11-24 11:50:46 -0500786 print_size(div_u64(len_read, time) * 1000, "/s");
Andreas Bießmann1fd2d8a2012-11-14 13:32:37 +0100787 puts(")");
788 }
789 puts("\n");
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000790
Simon Glass4d949a22017-08-03 12:22:10 -0600791 env_set_hex("fileaddr", addr);
792 env_set_hex("filesize", len_read);
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000793
794 return 0;
795}
796
Simon Glassed38aef2020-05-10 11:40:03 -0600797int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
798 int fstype)
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000799{
800 if (argc < 2)
801 return CMD_RET_USAGE;
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000802 if (argc > 4)
803 return CMD_RET_USAGE;
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000804
805 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
806 return 1;
807
Stephen Warrenb2d5cd62012-10-30 12:04:17 +0000808 if (fs_ls(argc >= 4 ? argv[3] : "/"))
Stephen Warreneefbc3f2012-10-22 06:43:51 +0000809 return 1;
810
811 return 0;
812}
Simon Glasseda14ea2013-04-20 08:42:50 +0000813
Stephen Warrend008fbb2014-02-03 13:21:00 -0700814int file_exists(const char *dev_type, const char *dev_part, const char *file,
815 int fstype)
816{
817 if (fs_set_blk_dev(dev_type, dev_part, fstype))
818 return 0;
819
820 return fs_exists(file);
821}
822
Simon Glassed38aef2020-05-10 11:40:03 -0600823int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
824 int fstype)
Simon Glasseda14ea2013-04-20 08:42:50 +0000825{
826 unsigned long addr;
827 const char *filename;
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800828 loff_t bytes;
829 loff_t pos;
830 loff_t len;
831 int ret;
Simon Glasseda14ea2013-04-20 08:42:50 +0000832 unsigned long time;
833
834 if (argc < 6 || argc > 7)
835 return CMD_RET_USAGE;
836
837 if (fs_set_blk_dev(argv[1], argv[2], fstype))
838 return 1;
839
Simon Glass3ff49ec2021-07-24 09:03:29 -0600840 addr = hextoul(argv[3], NULL);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800841 filename = argv[4];
Simon Glass3ff49ec2021-07-24 09:03:29 -0600842 bytes = hextoul(argv[5], NULL);
Simon Glasseda14ea2013-04-20 08:42:50 +0000843 if (argc >= 7)
Simon Glass3ff49ec2021-07-24 09:03:29 -0600844 pos = hextoul(argv[6], NULL);
Simon Glasseda14ea2013-04-20 08:42:50 +0000845 else
846 pos = 0;
847
848 time = get_timer(0);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800849 ret = fs_write(filename, addr, pos, bytes, &len);
Simon Glasseda14ea2013-04-20 08:42:50 +0000850 time = get_timer(time);
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800851 if (ret < 0)
Simon Glasseda14ea2013-04-20 08:42:50 +0000852 return 1;
853
Suriyan Ramasami96171fb2014-11-17 14:39:38 -0800854 printf("%llu bytes written in %lu ms", len, time);
Simon Glasseda14ea2013-04-20 08:42:50 +0000855 if (time > 0) {
856 puts(" (");
Tom Rinia17b7bc2014-11-24 11:50:46 -0500857 print_size(div_u64(len, time) * 1000, "/s");
Simon Glasseda14ea2013-04-20 08:42:50 +0000858 puts(")");
859 }
860 puts("\n");
861
862 return 0;
863}
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100864
Simon Glassed38aef2020-05-10 11:40:03 -0600865int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
866 int fstype)
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100867{
868 int ret;
869 char uuid[37];
870 memset(uuid, 0, sizeof(uuid));
871
872 if (argc < 3 || argc > 4)
873 return CMD_RET_USAGE;
874
875 if (fs_set_blk_dev(argv[1], argv[2], fstype))
876 return 1;
877
878 ret = fs_uuid(uuid);
879 if (ret)
880 return CMD_RET_FAILURE;
881
882 if (argc == 4)
Simon Glass6a38e412017-08-03 12:22:09 -0600883 env_set(argv[3], uuid);
Christian Gmeiner9f9eec32014-11-12 14:35:04 +0100884 else
885 printf("%s\n", uuid);
886
887 return CMD_RET_SUCCESS;
888}
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100889
Simon Glassed38aef2020-05-10 11:40:03 -0600890int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100891{
892 struct fstype_info *info;
893
894 if (argc < 3 || argc > 4)
895 return CMD_RET_USAGE;
896
897 if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY))
898 return 1;
899
900 info = fs_get_info(fs_type);
901
902 if (argc == 4)
Simon Glass6a38e412017-08-03 12:22:09 -0600903 env_set(argv[3], info->name);
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100904 else
905 printf("%s\n", info->name);
906
Marek Vasut08d1c422019-02-06 13:19:29 +0100907 fs_close();
908
Sjoerd Simons7d9faf62015-01-05 18:13:36 +0100909 return CMD_RET_SUCCESS;
910}
911
Simon Glassed38aef2020-05-10 11:40:03 -0600912int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
AKASHI Takahiro1ba42532018-09-11 15:59:13 +0900913 int fstype)
914{
915 if (argc != 4)
916 return CMD_RET_USAGE;
917
918 if (fs_set_blk_dev(argv[1], argv[2], fstype))
919 return 1;
920
921 if (fs_unlink(argv[3]))
922 return 1;
923
924 return 0;
925}
926
Simon Glassed38aef2020-05-10 11:40:03 -0600927int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900928 int fstype)
929{
930 int ret;
931
932 if (argc != 4)
933 return CMD_RET_USAGE;
934
935 if (fs_set_blk_dev(argv[1], argv[2], fstype))
936 return 1;
937
938 ret = fs_mkdir(argv[3]);
939 if (ret) {
Heinrich Schuchardtb4559782020-08-25 17:49:16 +0000940 log_err("** Unable to create a directory \"%s\" **\n", argv[3]);
AKASHI Takahiroadc8c9f2018-09-11 15:59:08 +0900941 return 1;
942 }
943
944 return 0;
945}
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100946
Simon Glassed38aef2020-05-10 11:40:03 -0600947int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
Jean-Jacques Hiblotbc237482019-02-13 12:15:26 +0100948 int fstype)
949{
950 if (argc != 5)
951 return CMD_RET_USAGE;
952
953 if (fs_set_blk_dev(argv[1], argv[2], fstype))
954 return 1;
955
956 if (fs_ln(argv[3], argv[4]))
957 return 1;
958
959 return 0;
960}
Niel Fourie9252d702020-03-24 16:17:04 +0100961
962int do_fs_types(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[])
963{
964 struct fstype_info *drv = fstypes;
965 const int n_ents = ARRAY_SIZE(fstypes);
966 struct fstype_info *entry;
967 int i = 0;
968
969 puts("Supported filesystems");
970 for (entry = drv; entry != drv + n_ents; entry++) {
971 if (entry->fstype != FS_TYPE_ANY) {
972 printf("%c %s", i ? ',' : ':', entry->name);
973 i++;
974 }
975 }
976 if (!i)
977 puts(": <none>");
978 puts("\n");
979 return CMD_RET_SUCCESS;
980}