fs.c 15.6 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
2 3 4 5 6
/*
 * Copyright (c) 2012, NVIDIA CORPORATION.  All rights reserved.
 */

#include <config.h>
7
#include <errno.h>
8
#include <common.h>
9
#include <mapmem.h>
10 11 12 13
#include <part.h>
#include <ext4fs.h>
#include <fat.h>
#include <fs.h>
S
Simon Glass 已提交
14
#include <sandboxfs.h>
H
Hans de Goede 已提交
15
#include <ubifs_uboot.h>
M
Marek Behún 已提交
16
#include <btrfs.h>
S
Simon Glass 已提交
17
#include <asm/io.h>
18 19
#include <div64.h>
#include <linux/math64.h>
20

21 22
DECLARE_GLOBAL_DATA_PTR;

23
static struct blk_desc *fs_dev_desc;
R
Rob Clark 已提交
24
static int fs_dev_part;
25 26 27
static disk_partition_t fs_partition;
static int fs_type = FS_TYPE_ANY;

28
static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
29
				      disk_partition_t *fs_partition)
30 31 32 33 34
{
	printf("** Unrecognized filesystem type **\n");
	return -1;
}

35 36 37 38 39
static inline int fs_ls_unsupported(const char *dirname)
{
	return -1;
}

40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
/* generic implementation of ls in terms of opendir/readdir/closedir */
__maybe_unused
static int fs_ls_generic(const char *dirname)
{
	struct fs_dir_stream *dirs;
	struct fs_dirent *dent;
	int nfiles = 0, ndirs = 0;

	dirs = fs_opendir(dirname);
	if (!dirs)
		return -errno;

	while ((dent = fs_readdir(dirs))) {
		if (dent->type == FS_DT_DIR) {
			printf("            %s/\n", dent->name);
			ndirs++;
		} else {
			printf(" %8lld   %s\n", dent->size, dent->name);
			nfiles++;
		}
	}

	fs_closedir(dirs);

	printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs);

	return 0;
}

69 70 71 72 73
static inline int fs_exists_unsupported(const char *filename)
{
	return 0;
}

74
static inline int fs_size_unsupported(const char *filename, loff_t *size)
75 76 77 78
{
	return -1;
}

S
Simon Glass 已提交
79
static inline int fs_read_unsupported(const char *filename, void *buf,
80 81
				      loff_t offset, loff_t len,
				      loff_t *actread)
82 83 84 85
{
	return -1;
}

86
static inline int fs_write_unsupported(const char *filename, void *buf,
87 88
				      loff_t offset, loff_t len,
				      loff_t *actwrite)
89 90 91 92
{
	return -1;
}

93 94 95 96
static inline void fs_close_unsupported(void)
{
}

97 98 99 100 101
static inline int fs_uuid_unsupported(char *uuid_str)
{
	return -1;
}

R
Rob Clark 已提交
102 103 104 105 106 107
static inline int fs_opendir_unsupported(const char *filename,
					 struct fs_dir_stream **dirs)
{
	return -EACCES;
}

A
AKASHI Takahiro 已提交
108 109 110 111 112
static inline int fs_unlink_unsupported(const char *filename)
{
	return -1;
}

A
AKASHI Takahiro 已提交
113 114 115 116 117
static inline int fs_mkdir_unsupported(const char *dirname)
{
	return -1;
}

118
struct fstype_info {
119
	int fstype;
120
	char *name;
121 122 123 124
	/*
	 * Is it legal to pass NULL as .probe()'s  fs_dev_desc parameter? This
	 * should be false in most cases. For "virtual" filesystems which
	 * aren't based on a U-Boot block device (e.g. sandbox), this can be
H
Heinrich Schuchardt 已提交
125
	 * set to true. This should also be true for the dummy entry at the end
126 127 128 129
	 * of fstypes[], since that is essentially a "virtual" (non-existent)
	 * filesystem.
	 */
	bool null_dev_desc_ok;
130
	int (*probe)(struct blk_desc *fs_dev_desc,
131
		     disk_partition_t *fs_partition);
132
	int (*ls)(const char *dirname);
133
	int (*exists)(const char *filename);
134 135 136 137 138
	int (*size)(const char *filename, loff_t *size);
	int (*read)(const char *filename, void *buf, loff_t offset,
		    loff_t len, loff_t *actread);
	int (*write)(const char *filename, void *buf, loff_t offset,
		     loff_t len, loff_t *actwrite);
139
	void (*close)(void);
140
	int (*uuid)(char *uuid_str);
R
Rob Clark 已提交
141 142 143 144 145 146 147 148 149 150 151 152 153 154
	/*
	 * Open a directory stream.  On success return 0 and directory
	 * stream pointer via 'dirsp'.  On error, return -errno.  See
	 * fs_opendir().
	 */
	int (*opendir)(const char *filename, struct fs_dir_stream **dirsp);
	/*
	 * Read next entry from directory stream.  On success return 0
	 * and directory entry pointer via 'dentp'.  On error return
	 * -errno.  See fs_readdir().
	 */
	int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp);
	/* see fs_closedir() */
	void (*closedir)(struct fs_dir_stream *dirs);
A
AKASHI Takahiro 已提交
155
	int (*unlink)(const char *filename);
A
AKASHI Takahiro 已提交
156
	int (*mkdir)(const char *dirname);
157 158 159 160
};

static struct fstype_info fstypes[] = {
#ifdef CONFIG_FS_FAT
161 162
	{
		.fstype = FS_TYPE_FAT,
163
		.name = "fat",
164
		.null_dev_desc_ok = false,
165 166
		.probe = fat_set_blk_dev,
		.close = fat_close,
167
		.ls = fs_ls_generic,
168
		.exists = fat_exists,
169
		.size = fat_size,
170
		.read = fat_read_file,
171 172
#ifdef CONFIG_FAT_WRITE
		.write = file_fat_write,
A
AKASHI Takahiro 已提交
173
		.mkdir = fat_mkdir,
174
#else
175
		.write = fs_write_unsupported,
A
AKASHI Takahiro 已提交
176
		.mkdir = fs_mkdir_unsupported,
177
#endif
178
		.uuid = fs_uuid_unsupported,
179 180 181
		.opendir = fat_opendir,
		.readdir = fat_readdir,
		.closedir = fat_closedir,
A
AKASHI Takahiro 已提交
182
		.unlink = fs_unlink_unsupported,
183
	},
184 185
#endif
#ifdef CONFIG_FS_EXT4
186 187
	{
		.fstype = FS_TYPE_EXT,
188
		.name = "ext4",
189
		.null_dev_desc_ok = false,
190 191
		.probe = ext4fs_probe,
		.close = ext4fs_close,
192
		.ls = ext4fs_ls,
193
		.exists = ext4fs_exists,
194
		.size = ext4fs_size,
195
		.read = ext4_read_file,
196 197 198
#ifdef CONFIG_CMD_EXT4_WRITE
		.write = ext4_write_file,
#else
199
		.write = fs_write_unsupported,
200
#endif
201
		.uuid = ext4fs_uuid,
R
Rob Clark 已提交
202
		.opendir = fs_opendir_unsupported,
A
AKASHI Takahiro 已提交
203
		.unlink = fs_unlink_unsupported,
A
AKASHI Takahiro 已提交
204
		.mkdir = fs_mkdir_unsupported,
205
	},
S
Simon Glass 已提交
206 207 208 209
#endif
#ifdef CONFIG_SANDBOX
	{
		.fstype = FS_TYPE_SANDBOX,
210
		.name = "sandbox",
211
		.null_dev_desc_ok = true,
S
Simon Glass 已提交
212 213 214
		.probe = sandbox_fs_set_blk_dev,
		.close = sandbox_fs_close,
		.ls = sandbox_fs_ls,
215
		.exists = sandbox_fs_exists,
216
		.size = sandbox_fs_size,
S
Simon Glass 已提交
217
		.read = fs_read_sandbox,
218
		.write = fs_write_sandbox,
219
		.uuid = fs_uuid_unsupported,
R
Rob Clark 已提交
220
		.opendir = fs_opendir_unsupported,
A
AKASHI Takahiro 已提交
221
		.unlink = fs_unlink_unsupported,
A
AKASHI Takahiro 已提交
222
		.mkdir = fs_mkdir_unsupported,
S
Simon Glass 已提交
223
	},
H
Hans de Goede 已提交
224 225 226 227 228 229 230 231 232 233 234 235 236 237
#endif
#ifdef CONFIG_CMD_UBIFS
	{
		.fstype = FS_TYPE_UBIFS,
		.name = "ubifs",
		.null_dev_desc_ok = true,
		.probe = ubifs_set_blk_dev,
		.close = ubifs_close,
		.ls = ubifs_ls,
		.exists = ubifs_exists,
		.size = ubifs_size,
		.read = ubifs_read,
		.write = fs_write_unsupported,
		.uuid = fs_uuid_unsupported,
R
Rob Clark 已提交
238
		.opendir = fs_opendir_unsupported,
A
AKASHI Takahiro 已提交
239
		.unlink = fs_unlink_unsupported,
A
AKASHI Takahiro 已提交
240
		.mkdir = fs_mkdir_unsupported,
H
Hans de Goede 已提交
241
	},
M
Marek Behún 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255
#endif
#ifdef CONFIG_FS_BTRFS
	{
		.fstype = FS_TYPE_BTRFS,
		.name = "btrfs",
		.null_dev_desc_ok = false,
		.probe = btrfs_probe,
		.close = btrfs_close,
		.ls = btrfs_ls,
		.exists = btrfs_exists,
		.size = btrfs_size,
		.read = btrfs_read,
		.write = fs_write_unsupported,
		.uuid = btrfs_uuid,
256
		.opendir = fs_opendir_unsupported,
A
AKASHI Takahiro 已提交
257
		.unlink = fs_unlink_unsupported,
A
AKASHI Takahiro 已提交
258
		.mkdir = fs_mkdir_unsupported,
M
Marek Behún 已提交
259
	},
260 261 262
#endif
	{
		.fstype = FS_TYPE_ANY,
263
		.name = "unsupported",
264
		.null_dev_desc_ok = true,
265 266 267
		.probe = fs_probe_unsupported,
		.close = fs_close_unsupported,
		.ls = fs_ls_unsupported,
268
		.exists = fs_exists_unsupported,
269
		.size = fs_size_unsupported,
270
		.read = fs_read_unsupported,
271
		.write = fs_write_unsupported,
272
		.uuid = fs_uuid_unsupported,
R
Rob Clark 已提交
273
		.opendir = fs_opendir_unsupported,
A
AKASHI Takahiro 已提交
274
		.unlink = fs_unlink_unsupported,
A
AKASHI Takahiro 已提交
275
		.mkdir = fs_mkdir_unsupported,
276 277 278
	},
};

279 280 281 282 283 284 285 286 287 288 289 290 291 292
static struct fstype_info *fs_get_info(int fstype)
{
	struct fstype_info *info;
	int i;

	for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
		if (fstype == info->fstype)
			return info;
	}

	/* Return the 'unsupported' sentinel */
	return info;
}

293 294 295 296 297 298 299 300 301 302 303 304 305
/**
 * fs_get_type_name() - Get type of current filesystem
 *
 * Return: Pointer to filesystem name
 *
 * Returns a string describing the current filesystem, or the sentinel
 * "unsupported" for any unrecognised filesystem.
 */
const char *fs_get_type_name(void)
{
	return fs_get_info(fs_type)->name;
}

306 307
int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
{
308
	struct fstype_info *info;
309
	int part, i;
310 311 312 313
#ifdef CONFIG_NEEDS_MANUAL_RELOC
	static int relocated;

	if (!relocated) {
314 315
		for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
				i++, info++) {
316
			info->name += gd->reloc_off;
317 318 319 320
			info->probe += gd->reloc_off;
			info->close += gd->reloc_off;
			info->ls += gd->reloc_off;
			info->read += gd->reloc_off;
321
			info->write += gd->reloc_off;
322
		}
323 324 325
		relocated = 1;
	}
#endif
326

327
	part = blk_get_device_part_str(ifname, dev_part_str, &fs_dev_desc,
328 329 330 331
					&fs_partition, 1);
	if (part < 0)
		return -1;

332 333 334
	for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
		if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY &&
				fstype != info->fstype)
335 336
			continue;

337 338 339
		if (!fs_dev_desc && !info->null_dev_desc_ok)
			continue;

R
Rob Clark 已提交
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364
		if (!info->probe(fs_dev_desc, &fs_partition)) {
			fs_type = info->fstype;
			fs_dev_part = part;
			return 0;
		}
	}

	return -1;
}

/* set current blk device w/ blk_desc + partition # */
int fs_set_blk_dev_with_part(struct blk_desc *desc, int part)
{
	struct fstype_info *info;
	int ret, i;

	if (part >= 1)
		ret = part_get_info(desc, part, &fs_partition);
	else
		ret = part_get_info_whole_disk(desc, &fs_partition);
	if (ret)
		return ret;
	fs_dev_desc = desc;

	for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
365
		if (!info->probe(fs_dev_desc, &fs_partition)) {
366
			fs_type = info->fstype;
367 368 369 370 371 372 373 374 375
			return 0;
		}
	}

	return -1;
}

static void fs_close(void)
{
376
	struct fstype_info *info = fs_get_info(fs_type);
377

378
	info->close();
379

380 381 382
	fs_type = FS_TYPE_ANY;
}

383 384 385 386 387 388 389
int fs_uuid(char *uuid_str)
{
	struct fstype_info *info = fs_get_info(fs_type);

	return info->uuid(uuid_str);
}

390 391 392 393
int fs_ls(const char *dirname)
{
	int ret;

394 395 396
	struct fstype_info *info = fs_get_info(fs_type);

	ret = info->ls(dirname);
397

398
	fs_type = FS_TYPE_ANY;
399 400 401 402 403
	fs_close();

	return ret;
}

404 405 406 407 408 409 410 411 412 413 414 415 416
int fs_exists(const char *filename)
{
	int ret;

	struct fstype_info *info = fs_get_info(fs_type);

	ret = info->exists(filename);

	fs_close();

	return ret;
}

417
int fs_size(const char *filename, loff_t *size)
418 419 420 421 422
{
	int ret;

	struct fstype_info *info = fs_get_info(fs_type);

423
	ret = info->size(filename, size);
424 425 426 427 428 429

	fs_close();

	return ret;
}

430 431
int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
	    loff_t *actread)
432
{
433
	struct fstype_info *info = fs_get_info(fs_type);
S
Simon Glass 已提交
434
	void *buf;
435 436
	int ret;

S
Simon Glass 已提交
437 438 439 440 441
	/*
	 * We don't actually know how many bytes are being read, since len==0
	 * means read the whole file.
	 */
	buf = map_sysmem(addr, len);
442
	ret = info->read(filename, buf, offset, len, actread);
S
Simon Glass 已提交
443
	unmap_sysmem(buf);
444

445
	/* If we requested a specific number of bytes, check we got it */
446
	if (ret == 0 && len && *actread != len)
447
		debug("** %s shorter than offset + len **\n", filename);
448 449 450 451 452
	fs_close();

	return ret;
}

453 454
int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
	     loff_t *actwrite)
455 456 457 458 459 460
{
	struct fstype_info *info = fs_get_info(fs_type);
	void *buf;
	int ret;

	buf = map_sysmem(addr, len);
461
	ret = info->write(filename, buf, offset, len, actwrite);
462 463
	unmap_sysmem(buf);

464
	if (ret < 0 && len != *actwrite) {
465 466 467 468 469 470 471 472
		printf("** Unable to write file %s **\n", filename);
		ret = -1;
	}
	fs_close();

	return ret;
}

R
Rob Clark 已提交
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524
struct fs_dir_stream *fs_opendir(const char *filename)
{
	struct fstype_info *info = fs_get_info(fs_type);
	struct fs_dir_stream *dirs = NULL;
	int ret;

	ret = info->opendir(filename, &dirs);
	fs_close();
	if (ret) {
		errno = -ret;
		return NULL;
	}

	dirs->desc = fs_dev_desc;
	dirs->part = fs_dev_part;

	return dirs;
}

struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs)
{
	struct fstype_info *info;
	struct fs_dirent *dirent;
	int ret;

	fs_set_blk_dev_with_part(dirs->desc, dirs->part);
	info = fs_get_info(fs_type);

	ret = info->readdir(dirs, &dirent);
	fs_close();
	if (ret) {
		errno = -ret;
		return NULL;
	}

	return dirent;
}

void fs_closedir(struct fs_dir_stream *dirs)
{
	struct fstype_info *info;

	if (!dirs)
		return;

	fs_set_blk_dev_with_part(dirs->desc, dirs->part);
	info = fs_get_info(fs_type);

	info->closedir(dirs);
	fs_close();
}

A
AKASHI Takahiro 已提交
525 526 527 528 529 530 531 532 533 534 535 536 537
int fs_unlink(const char *filename)
{
	int ret;

	struct fstype_info *info = fs_get_info(fs_type);

	ret = info->unlink(filename);

	fs_type = FS_TYPE_ANY;
	fs_close();

	return ret;
}
R
Rob Clark 已提交
538

A
AKASHI Takahiro 已提交
539 540 541 542 543 544 545 546 547 548 549 550 551 552
int fs_mkdir(const char *dirname)
{
	int ret;

	struct fstype_info *info = fs_get_info(fs_type);

	ret = info->mkdir(dirname);

	fs_type = FS_TYPE_ANY;
	fs_close();

	return ret;
}

553 554 555
int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
		int fstype)
{
556
	loff_t size;
557 558 559 560 561 562 563

	if (argc != 4)
		return CMD_RET_USAGE;

	if (fs_set_blk_dev(argv[1], argv[2], fstype))
		return 1;

564
	if (fs_size(argv[3], &size) < 0)
565 566
		return CMD_RET_FAILURE;

567
	env_set_hex("filesize", size);
568 569 570 571

	return 0;
}

S
Stephen Warren 已提交
572
int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
573
		int fstype)
574 575 576 577
{
	unsigned long addr;
	const char *addr_str;
	const char *filename;
578 579 580 581
	loff_t bytes;
	loff_t pos;
	loff_t len_read;
	int ret;
582
	unsigned long time;
583
	char *ep;
584

585 586 587
	if (argc < 2)
		return CMD_RET_USAGE;
	if (argc > 7)
588 589
		return CMD_RET_USAGE;

590
	if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
591 592 593
		return 1;

	if (argc >= 4) {
594 595 596
		addr = simple_strtoul(argv[3], &ep, 16);
		if (ep == argv[3] || *ep != '\0')
			return CMD_RET_USAGE;
597
	} else {
598
		addr_str = env_get("loadaddr");
599 600 601 602 603 604 605 606
		if (addr_str != NULL)
			addr = simple_strtoul(addr_str, NULL, 16);
		else
			addr = CONFIG_SYS_LOAD_ADDR;
	}
	if (argc >= 5) {
		filename = argv[4];
	} else {
607
		filename = env_get("bootfile");
608 609 610 611 612 613
		if (!filename) {
			puts("** No boot file defined **\n");
			return 1;
		}
	}
	if (argc >= 6)
614
		bytes = simple_strtoul(argv[5], NULL, 16);
615 616 617
	else
		bytes = 0;
	if (argc >= 7)
618
		pos = simple_strtoul(argv[6], NULL, 16);
619 620 621
	else
		pos = 0;

622
	time = get_timer(0);
623
	ret = fs_read(filename, addr, pos, bytes, &len_read);
624
	time = get_timer(time);
625
	if (ret < 0)
626 627
		return 1;

628
	printf("%llu bytes read in %lu ms", len_read, time);
629 630
	if (time > 0) {
		puts(" (");
631
		print_size(div_u64(len_read, time) * 1000, "/s");
632 633 634
		puts(")");
	}
	puts("\n");
635

636 637
	env_set_hex("fileaddr", addr);
	env_set_hex("filesize", len_read);
638 639 640 641 642 643 644 645 646

	return 0;
}

int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
	int fstype)
{
	if (argc < 2)
		return CMD_RET_USAGE;
647 648
	if (argc > 4)
		return CMD_RET_USAGE;
649 650 651 652

	if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
		return 1;

653
	if (fs_ls(argc >= 4 ? argv[3] : "/"))
654 655 656 657
		return 1;

	return 0;
}
658

659 660 661 662 663 664 665 666 667
int file_exists(const char *dev_type, const char *dev_part, const char *file,
		int fstype)
{
	if (fs_set_blk_dev(dev_type, dev_part, fstype))
		return 0;

	return fs_exists(file);
}

668
int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
669
		int fstype)
670 671 672
{
	unsigned long addr;
	const char *filename;
673 674 675 676
	loff_t bytes;
	loff_t pos;
	loff_t len;
	int ret;
677 678 679 680 681 682 683 684
	unsigned long time;

	if (argc < 6 || argc > 7)
		return CMD_RET_USAGE;

	if (fs_set_blk_dev(argv[1], argv[2], fstype))
		return 1;

685 686
	addr = simple_strtoul(argv[3], NULL, 16);
	filename = argv[4];
687
	bytes = simple_strtoul(argv[5], NULL, 16);
688
	if (argc >= 7)
689
		pos = simple_strtoul(argv[6], NULL, 16);
690 691 692 693
	else
		pos = 0;

	time = get_timer(0);
694
	ret = fs_write(filename, addr, pos, bytes, &len);
695
	time = get_timer(time);
696
	if (ret < 0)
697 698
		return 1;

699
	printf("%llu bytes written in %lu ms", len, time);
700 701
	if (time > 0) {
		puts(" (");
702
		print_size(div_u64(len, time) * 1000, "/s");
703 704 705 706 707 708
		puts(")");
	}
	puts("\n");

	return 0;
}
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727

int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
		int fstype)
{
	int ret;
	char uuid[37];
	memset(uuid, 0, sizeof(uuid));

	if (argc < 3 || argc > 4)
		return CMD_RET_USAGE;

	if (fs_set_blk_dev(argv[1], argv[2], fstype))
		return 1;

	ret = fs_uuid(uuid);
	if (ret)
		return CMD_RET_FAILURE;

	if (argc == 4)
S
Simon Glass 已提交
728
		env_set(argv[3], uuid);
729 730 731 732 733
	else
		printf("%s\n", uuid);

	return CMD_RET_SUCCESS;
}
734 735 736 737 738 739 740 741 742 743 744 745 746 747

int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{
	struct fstype_info *info;

	if (argc < 3 || argc > 4)
		return CMD_RET_USAGE;

	if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY))
		return 1;

	info = fs_get_info(fs_type);

	if (argc == 4)
S
Simon Glass 已提交
748
		env_set(argv[3], info->name);
749 750 751 752 753 754
	else
		printf("%s\n", info->name);

	return CMD_RET_SUCCESS;
}

A
AKASHI Takahiro 已提交
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769
int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
	  int fstype)
{
	if (argc != 4)
		return CMD_RET_USAGE;

	if (fs_set_blk_dev(argv[1], argv[2], fstype))
		return 1;

	if (fs_unlink(argv[3]))
		return 1;

	return 0;
}

A
AKASHI Takahiro 已提交
770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788
int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
	     int fstype)
{
	int ret;

	if (argc != 4)
		return CMD_RET_USAGE;

	if (fs_set_blk_dev(argv[1], argv[2], fstype))
		return 1;

	ret = fs_mkdir(argv[3]);
	if (ret) {
		printf("** Unable to create a directory \"%s\" **\n", argv[3]);
		return 1;
	}

	return 0;
}