]> git.ipfire.org Git - thirdparty/u-boot.git/blob - fs/fs.c
spl: add fixed memory node in target fdt also when loading ATF
[thirdparty/u-boot.git] / fs / fs.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
4 */
5
6 #include <command.h>
7 #include <config.h>
8 #include <errno.h>
9 #include <common.h>
10 #include <env.h>
11 #include <lmb.h>
12 #include <log.h>
13 #include <mapmem.h>
14 #include <part.h>
15 #include <ext4fs.h>
16 #include <fat.h>
17 #include <fs.h>
18 #include <sandboxfs.h>
19 #include <ubifs_uboot.h>
20 #include <btrfs.h>
21 #include <asm/io.h>
22 #include <div64.h>
23 #include <linux/math64.h>
24 #include <efi_loader.h>
25
26 DECLARE_GLOBAL_DATA_PTR;
27
28 static struct blk_desc *fs_dev_desc;
29 static int fs_dev_part;
30 static struct disk_partition fs_partition;
31 static int fs_type = FS_TYPE_ANY;
32
33 static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
34 struct disk_partition *fs_partition)
35 {
36 printf("** Unrecognized filesystem type **\n");
37 return -1;
38 }
39
40 static inline int fs_ls_unsupported(const char *dirname)
41 {
42 return -1;
43 }
44
45 /* generic implementation of ls in terms of opendir/readdir/closedir */
46 __maybe_unused
47 static int fs_ls_generic(const char *dirname)
48 {
49 struct fs_dir_stream *dirs;
50 struct fs_dirent *dent;
51 int nfiles = 0, ndirs = 0;
52
53 dirs = fs_opendir(dirname);
54 if (!dirs)
55 return -errno;
56
57 while ((dent = fs_readdir(dirs))) {
58 if (dent->type == FS_DT_DIR) {
59 printf(" %s/\n", dent->name);
60 ndirs++;
61 } else {
62 printf(" %8lld %s\n", dent->size, dent->name);
63 nfiles++;
64 }
65 }
66
67 fs_closedir(dirs);
68
69 printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs);
70
71 return 0;
72 }
73
74 static inline int fs_exists_unsupported(const char *filename)
75 {
76 return 0;
77 }
78
79 static inline int fs_size_unsupported(const char *filename, loff_t *size)
80 {
81 return -1;
82 }
83
84 static inline int fs_read_unsupported(const char *filename, void *buf,
85 loff_t offset, loff_t len,
86 loff_t *actread)
87 {
88 return -1;
89 }
90
91 static inline int fs_write_unsupported(const char *filename, void *buf,
92 loff_t offset, loff_t len,
93 loff_t *actwrite)
94 {
95 return -1;
96 }
97
98 static inline int fs_ln_unsupported(const char *filename, const char *target)
99 {
100 return -1;
101 }
102
103 static inline void fs_close_unsupported(void)
104 {
105 }
106
107 static inline int fs_uuid_unsupported(char *uuid_str)
108 {
109 return -1;
110 }
111
112 static inline int fs_opendir_unsupported(const char *filename,
113 struct fs_dir_stream **dirs)
114 {
115 return -EACCES;
116 }
117
118 static inline int fs_unlink_unsupported(const char *filename)
119 {
120 return -1;
121 }
122
123 static inline int fs_mkdir_unsupported(const char *dirname)
124 {
125 return -1;
126 }
127
128 struct fstype_info {
129 int fstype;
130 char *name;
131 /*
132 * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This
133 * should be false in most cases. For "virtual" filesystems which
134 * aren't based on a U-Boot block device (e.g. sandbox), this can be
135 * set to true. This should also be true for the dummy entry at the end
136 * of fstypes[], since that is essentially a "virtual" (non-existent)
137 * filesystem.
138 */
139 bool null_dev_desc_ok;
140 int (*probe)(struct blk_desc *fs_dev_desc,
141 struct disk_partition *fs_partition);
142 int (*ls)(const char *dirname);
143 int (*exists)(const char *filename);
144 int (*size)(const char *filename, loff_t *size);
145 int (*read)(const char *filename, void *buf, loff_t offset,
146 loff_t len, loff_t *actread);
147 int (*write)(const char *filename, void *buf, loff_t offset,
148 loff_t len, loff_t *actwrite);
149 void (*close)(void);
150 int (*uuid)(char *uuid_str);
151 /*
152 * Open a directory stream. On success return 0 and directory
153 * stream pointer via 'dirsp'. On error, return -errno. See
154 * fs_opendir().
155 */
156 int (*opendir)(const char *filename, struct fs_dir_stream **dirsp);
157 /*
158 * Read next entry from directory stream. On success return 0
159 * and directory entry pointer via 'dentp'. On error return
160 * -errno. See fs_readdir().
161 */
162 int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp);
163 /* see fs_closedir() */
164 void (*closedir)(struct fs_dir_stream *dirs);
165 int (*unlink)(const char *filename);
166 int (*mkdir)(const char *dirname);
167 int (*ln)(const char *filename, const char *target);
168 };
169
170 static struct fstype_info fstypes[] = {
171 #ifdef CONFIG_FS_FAT
172 {
173 .fstype = FS_TYPE_FAT,
174 .name = "fat",
175 .null_dev_desc_ok = false,
176 .probe = fat_set_blk_dev,
177 .close = fat_close,
178 .ls = fs_ls_generic,
179 .exists = fat_exists,
180 .size = fat_size,
181 .read = fat_read_file,
182 #if CONFIG_IS_ENABLED(FAT_WRITE)
183 .write = file_fat_write,
184 .unlink = fat_unlink,
185 .mkdir = fat_mkdir,
186 #else
187 .write = fs_write_unsupported,
188 .unlink = fs_unlink_unsupported,
189 .mkdir = fs_mkdir_unsupported,
190 #endif
191 .uuid = fs_uuid_unsupported,
192 .opendir = fat_opendir,
193 .readdir = fat_readdir,
194 .closedir = fat_closedir,
195 .ln = fs_ln_unsupported,
196 },
197 #endif
198
199 #if CONFIG_IS_ENABLED(FS_EXT4)
200 {
201 .fstype = FS_TYPE_EXT,
202 .name = "ext4",
203 .null_dev_desc_ok = false,
204 .probe = ext4fs_probe,
205 .close = ext4fs_close,
206 .ls = ext4fs_ls,
207 .exists = ext4fs_exists,
208 .size = ext4fs_size,
209 .read = ext4_read_file,
210 #ifdef CONFIG_CMD_EXT4_WRITE
211 .write = ext4_write_file,
212 .ln = ext4fs_create_link,
213 #else
214 .write = fs_write_unsupported,
215 .ln = fs_ln_unsupported,
216 #endif
217 .uuid = ext4fs_uuid,
218 .opendir = fs_opendir_unsupported,
219 .unlink = fs_unlink_unsupported,
220 .mkdir = fs_mkdir_unsupported,
221 },
222 #endif
223 #ifdef CONFIG_SANDBOX
224 {
225 .fstype = FS_TYPE_SANDBOX,
226 .name = "sandbox",
227 .null_dev_desc_ok = true,
228 .probe = sandbox_fs_set_blk_dev,
229 .close = sandbox_fs_close,
230 .ls = sandbox_fs_ls,
231 .exists = sandbox_fs_exists,
232 .size = sandbox_fs_size,
233 .read = fs_read_sandbox,
234 .write = fs_write_sandbox,
235 .uuid = fs_uuid_unsupported,
236 .opendir = fs_opendir_unsupported,
237 .unlink = fs_unlink_unsupported,
238 .mkdir = fs_mkdir_unsupported,
239 .ln = fs_ln_unsupported,
240 },
241 #endif
242 #ifdef CONFIG_CMD_UBIFS
243 {
244 .fstype = FS_TYPE_UBIFS,
245 .name = "ubifs",
246 .null_dev_desc_ok = true,
247 .probe = ubifs_set_blk_dev,
248 .close = ubifs_close,
249 .ls = ubifs_ls,
250 .exists = ubifs_exists,
251 .size = ubifs_size,
252 .read = ubifs_read,
253 .write = fs_write_unsupported,
254 .uuid = fs_uuid_unsupported,
255 .opendir = fs_opendir_unsupported,
256 .unlink = fs_unlink_unsupported,
257 .mkdir = fs_mkdir_unsupported,
258 .ln = fs_ln_unsupported,
259 },
260 #endif
261 #ifdef CONFIG_FS_BTRFS
262 {
263 .fstype = FS_TYPE_BTRFS,
264 .name = "btrfs",
265 .null_dev_desc_ok = false,
266 .probe = btrfs_probe,
267 .close = btrfs_close,
268 .ls = btrfs_ls,
269 .exists = btrfs_exists,
270 .size = btrfs_size,
271 .read = btrfs_read,
272 .write = fs_write_unsupported,
273 .uuid = btrfs_uuid,
274 .opendir = fs_opendir_unsupported,
275 .unlink = fs_unlink_unsupported,
276 .mkdir = fs_mkdir_unsupported,
277 .ln = fs_ln_unsupported,
278 },
279 #endif
280 {
281 .fstype = FS_TYPE_ANY,
282 .name = "unsupported",
283 .null_dev_desc_ok = true,
284 .probe = fs_probe_unsupported,
285 .close = fs_close_unsupported,
286 .ls = fs_ls_unsupported,
287 .exists = fs_exists_unsupported,
288 .size = fs_size_unsupported,
289 .read = fs_read_unsupported,
290 .write = fs_write_unsupported,
291 .uuid = fs_uuid_unsupported,
292 .opendir = fs_opendir_unsupported,
293 .unlink = fs_unlink_unsupported,
294 .mkdir = fs_mkdir_unsupported,
295 .ln = fs_ln_unsupported,
296 },
297 };
298
299 static struct fstype_info *fs_get_info(int fstype)
300 {
301 struct fstype_info *info;
302 int i;
303
304 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
305 if (fstype == info->fstype)
306 return info;
307 }
308
309 /* Return the 'unsupported' sentinel */
310 return info;
311 }
312
313 /**
314 * fs_get_type() - Get type of current filesystem
315 *
316 * Return: filesystem type
317 *
318 * Returns filesystem type representing the current filesystem, or
319 * FS_TYPE_ANY for any unrecognised filesystem.
320 */
321 int fs_get_type(void)
322 {
323 return fs_type;
324 }
325
326 /**
327 * fs_get_type_name() - Get type of current filesystem
328 *
329 * Return: Pointer to filesystem name
330 *
331 * Returns a string describing the current filesystem, or the sentinel
332 * "unsupported" for any unrecognised filesystem.
333 */
334 const char *fs_get_type_name(void)
335 {
336 return fs_get_info(fs_type)->name;
337 }
338
339 int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
340 {
341 struct fstype_info *info;
342 int part, i;
343 #ifdef CONFIG_NEEDS_MANUAL_RELOC
344 static int relocated;
345
346 if (!relocated) {
347 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
348 i++, info++) {
349 info->name += gd->reloc_off;
350 info->probe += gd->reloc_off;
351 info->close += gd->reloc_off;
352 info->ls += gd->reloc_off;
353 info->read += gd->reloc_off;
354 info->write += gd->reloc_off;
355 }
356 relocated = 1;
357 }
358 #endif
359
360 part = blk_get_device_part_str(ifname, dev_part_str, &fs_dev_desc,
361 &fs_partition, 1);
362 if (part < 0)
363 return -1;
364
365 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
366 if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY &&
367 fstype != info->fstype)
368 continue;
369
370 if (!fs_dev_desc && !info->null_dev_desc_ok)
371 continue;
372
373 if (!info->probe(fs_dev_desc, &fs_partition)) {
374 fs_type = info->fstype;
375 fs_dev_part = part;
376 return 0;
377 }
378 }
379
380 return -1;
381 }
382
383 /* set current blk device w/ blk_desc + partition # */
384 int fs_set_blk_dev_with_part(struct blk_desc *desc, int part)
385 {
386 struct fstype_info *info;
387 int ret, i;
388
389 if (part >= 1)
390 ret = part_get_info(desc, part, &fs_partition);
391 else
392 ret = part_get_info_whole_disk(desc, &fs_partition);
393 if (ret)
394 return ret;
395 fs_dev_desc = desc;
396
397 for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
398 if (!info->probe(fs_dev_desc, &fs_partition)) {
399 fs_type = info->fstype;
400 fs_dev_part = part;
401 return 0;
402 }
403 }
404
405 return -1;
406 }
407
408 void fs_close(void)
409 {
410 struct fstype_info *info = fs_get_info(fs_type);
411
412 info->close();
413
414 fs_type = FS_TYPE_ANY;
415 }
416
417 int fs_uuid(char *uuid_str)
418 {
419 struct fstype_info *info = fs_get_info(fs_type);
420
421 return info->uuid(uuid_str);
422 }
423
424 int fs_ls(const char *dirname)
425 {
426 int ret;
427
428 struct fstype_info *info = fs_get_info(fs_type);
429
430 ret = info->ls(dirname);
431
432 fs_close();
433
434 return ret;
435 }
436
437 int fs_exists(const char *filename)
438 {
439 int ret;
440
441 struct fstype_info *info = fs_get_info(fs_type);
442
443 ret = info->exists(filename);
444
445 fs_close();
446
447 return ret;
448 }
449
450 int fs_size(const char *filename, loff_t *size)
451 {
452 int ret;
453
454 struct fstype_info *info = fs_get_info(fs_type);
455
456 ret = info->size(filename, size);
457
458 fs_close();
459
460 return ret;
461 }
462
463 #ifdef CONFIG_LMB
464 /* Check if a file may be read to the given address */
465 static int fs_read_lmb_check(const char *filename, ulong addr, loff_t offset,
466 loff_t len, struct fstype_info *info)
467 {
468 struct lmb lmb;
469 int ret;
470 loff_t size;
471 loff_t read_len;
472
473 /* get the actual size of the file */
474 ret = info->size(filename, &size);
475 if (ret)
476 return ret;
477 if (offset >= size) {
478 /* offset >= EOF, no bytes will be written */
479 return 0;
480 }
481 read_len = size - offset;
482
483 /* limit to 'len' if it is smaller */
484 if (len && len < read_len)
485 read_len = len;
486
487 lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob);
488 lmb_dump_all(&lmb);
489
490 if (lmb_alloc_addr(&lmb, addr, read_len) == addr)
491 return 0;
492
493 printf("** Reading file would overwrite reserved memory **\n");
494 return -ENOSPC;
495 }
496 #endif
497
498 static int _fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
499 int do_lmb_check, loff_t *actread)
500 {
501 struct fstype_info *info = fs_get_info(fs_type);
502 void *buf;
503 int ret;
504
505 #ifdef CONFIG_LMB
506 if (do_lmb_check) {
507 ret = fs_read_lmb_check(filename, addr, offset, len, info);
508 if (ret)
509 return ret;
510 }
511 #endif
512
513 /*
514 * We don't actually know how many bytes are being read, since len==0
515 * means read the whole file.
516 */
517 buf = map_sysmem(addr, len);
518 ret = info->read(filename, buf, offset, len, actread);
519 unmap_sysmem(buf);
520
521 /* If we requested a specific number of bytes, check we got it */
522 if (ret == 0 && len && *actread != len)
523 debug("** %s shorter than offset + len **\n", filename);
524 fs_close();
525
526 return ret;
527 }
528
529 int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
530 loff_t *actread)
531 {
532 return _fs_read(filename, addr, offset, len, 0, actread);
533 }
534
535 int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
536 loff_t *actwrite)
537 {
538 struct fstype_info *info = fs_get_info(fs_type);
539 void *buf;
540 int ret;
541
542 buf = map_sysmem(addr, len);
543 ret = info->write(filename, buf, offset, len, actwrite);
544 unmap_sysmem(buf);
545
546 if (ret < 0 && len != *actwrite) {
547 printf("** Unable to write file %s **\n", filename);
548 ret = -1;
549 }
550 fs_close();
551
552 return ret;
553 }
554
555 struct fs_dir_stream *fs_opendir(const char *filename)
556 {
557 struct fstype_info *info = fs_get_info(fs_type);
558 struct fs_dir_stream *dirs = NULL;
559 int ret;
560
561 ret = info->opendir(filename, &dirs);
562 fs_close();
563 if (ret) {
564 errno = -ret;
565 return NULL;
566 }
567
568 dirs->desc = fs_dev_desc;
569 dirs->part = fs_dev_part;
570
571 return dirs;
572 }
573
574 struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs)
575 {
576 struct fstype_info *info;
577 struct fs_dirent *dirent;
578 int ret;
579
580 fs_set_blk_dev_with_part(dirs->desc, dirs->part);
581 info = fs_get_info(fs_type);
582
583 ret = info->readdir(dirs, &dirent);
584 fs_close();
585 if (ret) {
586 errno = -ret;
587 return NULL;
588 }
589
590 return dirent;
591 }
592
593 void fs_closedir(struct fs_dir_stream *dirs)
594 {
595 struct fstype_info *info;
596
597 if (!dirs)
598 return;
599
600 fs_set_blk_dev_with_part(dirs->desc, dirs->part);
601 info = fs_get_info(fs_type);
602
603 info->closedir(dirs);
604 fs_close();
605 }
606
607 int fs_unlink(const char *filename)
608 {
609 int ret;
610
611 struct fstype_info *info = fs_get_info(fs_type);
612
613 ret = info->unlink(filename);
614
615 fs_close();
616
617 return ret;
618 }
619
620 int fs_mkdir(const char *dirname)
621 {
622 int ret;
623
624 struct fstype_info *info = fs_get_info(fs_type);
625
626 ret = info->mkdir(dirname);
627
628 fs_close();
629
630 return ret;
631 }
632
633 int fs_ln(const char *fname, const char *target)
634 {
635 struct fstype_info *info = fs_get_info(fs_type);
636 int ret;
637
638 ret = info->ln(fname, target);
639
640 if (ret < 0) {
641 printf("** Unable to create link %s -> %s **\n", fname, target);
642 ret = -1;
643 }
644 fs_close();
645
646 return ret;
647 }
648
649 int do_size(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
650 int fstype)
651 {
652 loff_t size;
653
654 if (argc != 4)
655 return CMD_RET_USAGE;
656
657 if (fs_set_blk_dev(argv[1], argv[2], fstype))
658 return 1;
659
660 if (fs_size(argv[3], &size) < 0)
661 return CMD_RET_FAILURE;
662
663 env_set_hex("filesize", size);
664
665 return 0;
666 }
667
668 int do_load(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
669 int fstype)
670 {
671 unsigned long addr;
672 const char *addr_str;
673 const char *filename;
674 loff_t bytes;
675 loff_t pos;
676 loff_t len_read;
677 int ret;
678 unsigned long time;
679 char *ep;
680
681 if (argc < 2)
682 return CMD_RET_USAGE;
683 if (argc > 7)
684 return CMD_RET_USAGE;
685
686 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
687 return 1;
688
689 if (argc >= 4) {
690 addr = simple_strtoul(argv[3], &ep, 16);
691 if (ep == argv[3] || *ep != '\0')
692 return CMD_RET_USAGE;
693 } else {
694 addr_str = env_get("loadaddr");
695 if (addr_str != NULL)
696 addr = simple_strtoul(addr_str, NULL, 16);
697 else
698 addr = CONFIG_SYS_LOAD_ADDR;
699 }
700 if (argc >= 5) {
701 filename = argv[4];
702 } else {
703 filename = env_get("bootfile");
704 if (!filename) {
705 puts("** No boot file defined **\n");
706 return 1;
707 }
708 }
709 if (argc >= 6)
710 bytes = simple_strtoul(argv[5], NULL, 16);
711 else
712 bytes = 0;
713 if (argc >= 7)
714 pos = simple_strtoul(argv[6], NULL, 16);
715 else
716 pos = 0;
717
718 #ifdef CONFIG_CMD_BOOTEFI
719 efi_set_bootdev(argv[1], (argc > 2) ? argv[2] : "",
720 (argc > 4) ? argv[4] : "");
721 #endif
722 time = get_timer(0);
723 ret = _fs_read(filename, addr, pos, bytes, 1, &len_read);
724 time = get_timer(time);
725 if (ret < 0)
726 return 1;
727
728 printf("%llu bytes read in %lu ms", len_read, time);
729 if (time > 0) {
730 puts(" (");
731 print_size(div_u64(len_read, time) * 1000, "/s");
732 puts(")");
733 }
734 puts("\n");
735
736 env_set_hex("fileaddr", addr);
737 env_set_hex("filesize", len_read);
738
739 return 0;
740 }
741
742 int do_ls(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
743 int fstype)
744 {
745 if (argc < 2)
746 return CMD_RET_USAGE;
747 if (argc > 4)
748 return CMD_RET_USAGE;
749
750 if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
751 return 1;
752
753 if (fs_ls(argc >= 4 ? argv[3] : "/"))
754 return 1;
755
756 return 0;
757 }
758
759 int file_exists(const char *dev_type, const char *dev_part, const char *file,
760 int fstype)
761 {
762 if (fs_set_blk_dev(dev_type, dev_part, fstype))
763 return 0;
764
765 return fs_exists(file);
766 }
767
768 int do_save(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
769 int fstype)
770 {
771 unsigned long addr;
772 const char *filename;
773 loff_t bytes;
774 loff_t pos;
775 loff_t len;
776 int ret;
777 unsigned long time;
778
779 if (argc < 6 || argc > 7)
780 return CMD_RET_USAGE;
781
782 if (fs_set_blk_dev(argv[1], argv[2], fstype))
783 return 1;
784
785 addr = simple_strtoul(argv[3], NULL, 16);
786 filename = argv[4];
787 bytes = simple_strtoul(argv[5], NULL, 16);
788 if (argc >= 7)
789 pos = simple_strtoul(argv[6], NULL, 16);
790 else
791 pos = 0;
792
793 time = get_timer(0);
794 ret = fs_write(filename, addr, pos, bytes, &len);
795 time = get_timer(time);
796 if (ret < 0)
797 return 1;
798
799 printf("%llu bytes written in %lu ms", len, time);
800 if (time > 0) {
801 puts(" (");
802 print_size(div_u64(len, time) * 1000, "/s");
803 puts(")");
804 }
805 puts("\n");
806
807 return 0;
808 }
809
810 int do_fs_uuid(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
811 int fstype)
812 {
813 int ret;
814 char uuid[37];
815 memset(uuid, 0, sizeof(uuid));
816
817 if (argc < 3 || argc > 4)
818 return CMD_RET_USAGE;
819
820 if (fs_set_blk_dev(argv[1], argv[2], fstype))
821 return 1;
822
823 ret = fs_uuid(uuid);
824 if (ret)
825 return CMD_RET_FAILURE;
826
827 if (argc == 4)
828 env_set(argv[3], uuid);
829 else
830 printf("%s\n", uuid);
831
832 return CMD_RET_SUCCESS;
833 }
834
835 int do_fs_type(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
836 {
837 struct fstype_info *info;
838
839 if (argc < 3 || argc > 4)
840 return CMD_RET_USAGE;
841
842 if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY))
843 return 1;
844
845 info = fs_get_info(fs_type);
846
847 if (argc == 4)
848 env_set(argv[3], info->name);
849 else
850 printf("%s\n", info->name);
851
852 fs_close();
853
854 return CMD_RET_SUCCESS;
855 }
856
857 int do_rm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
858 int fstype)
859 {
860 if (argc != 4)
861 return CMD_RET_USAGE;
862
863 if (fs_set_blk_dev(argv[1], argv[2], fstype))
864 return 1;
865
866 if (fs_unlink(argv[3]))
867 return 1;
868
869 return 0;
870 }
871
872 int do_mkdir(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
873 int fstype)
874 {
875 int ret;
876
877 if (argc != 4)
878 return CMD_RET_USAGE;
879
880 if (fs_set_blk_dev(argv[1], argv[2], fstype))
881 return 1;
882
883 ret = fs_mkdir(argv[3]);
884 if (ret) {
885 printf("** Unable to create a directory \"%s\" **\n", argv[3]);
886 return 1;
887 }
888
889 return 0;
890 }
891
892 int do_ln(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[],
893 int fstype)
894 {
895 if (argc != 5)
896 return CMD_RET_USAGE;
897
898 if (fs_set_blk_dev(argv[1], argv[2], fstype))
899 return 1;
900
901 if (fs_ln(argv[3], argv[4]))
902 return 1;
903
904 return 0;
905 }