fs.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved.
  4. */
  5. #include <config.h>
  6. #include <errno.h>
  7. #include <common.h>
  8. #include <mapmem.h>
  9. #include <part.h>
  10. #include <ext4fs.h>
  11. #include <fat.h>
  12. #include <fs.h>
  13. #include <sandboxfs.h>
  14. #include <ubifs_uboot.h>
  15. #include <btrfs.h>
  16. #include <asm/io.h>
  17. #include <div64.h>
  18. #include <linux/math64.h>
  19. DECLARE_GLOBAL_DATA_PTR;
  20. static struct blk_desc *fs_dev_desc;
  21. static int fs_dev_part;
  22. static disk_partition_t fs_partition;
  23. static int fs_type = FS_TYPE_ANY;
  24. static inline int fs_probe_unsupported(struct blk_desc *fs_dev_desc,
  25. disk_partition_t *fs_partition)
  26. {
  27. printf("** Unrecognized filesystem type **\n");
  28. return -1;
  29. }
  30. static inline int fs_ls_unsupported(const char *dirname)
  31. {
  32. return -1;
  33. }
  34. /* generic implementation of ls in terms of opendir/readdir/closedir */
  35. __maybe_unused
  36. static int fs_ls_generic(const char *dirname)
  37. {
  38. struct fs_dir_stream *dirs;
  39. struct fs_dirent *dent;
  40. int nfiles = 0, ndirs = 0;
  41. dirs = fs_opendir(dirname);
  42. if (!dirs)
  43. return -errno;
  44. while ((dent = fs_readdir(dirs))) {
  45. if (dent->type == FS_DT_DIR) {
  46. printf(" %s/\n", dent->name);
  47. ndirs++;
  48. } else {
  49. printf(" %8lld %s\n", dent->size, dent->name);
  50. nfiles++;
  51. }
  52. }
  53. fs_closedir(dirs);
  54. printf("\n%d file(s), %d dir(s)\n\n", nfiles, ndirs);
  55. return 0;
  56. }
  57. static inline int fs_exists_unsupported(const char *filename)
  58. {
  59. return 0;
  60. }
  61. static inline int fs_size_unsupported(const char *filename, loff_t *size)
  62. {
  63. return -1;
  64. }
  65. static inline int fs_read_unsupported(const char *filename, void *buf,
  66. loff_t offset, loff_t len,
  67. loff_t *actread)
  68. {
  69. return -1;
  70. }
  71. static inline int fs_write_unsupported(const char *filename, void *buf,
  72. loff_t offset, loff_t len,
  73. loff_t *actwrite)
  74. {
  75. return -1;
  76. }
  77. static inline void fs_close_unsupported(void)
  78. {
  79. }
  80. static inline int fs_uuid_unsupported(char *uuid_str)
  81. {
  82. return -1;
  83. }
  84. static inline int fs_opendir_unsupported(const char *filename,
  85. struct fs_dir_stream **dirs)
  86. {
  87. return -EACCES;
  88. }
  89. static inline int fs_unlink_unsupported(const char *filename)
  90. {
  91. return -1;
  92. }
  93. static inline int fs_mkdir_unsupported(const char *dirname)
  94. {
  95. return -1;
  96. }
  97. struct fstype_info {
  98. int fstype;
  99. char *name;
  100. /*
  101. * Is it legal to pass NULL as .probe()'s fs_dev_desc parameter? This
  102. * should be false in most cases. For "virtual" filesystems which
  103. * aren't based on a U-Boot block device (e.g. sandbox), this can be
  104. * set to true. This should also be true for the dummy entry at the end
  105. * of fstypes[], since that is essentially a "virtual" (non-existent)
  106. * filesystem.
  107. */
  108. bool null_dev_desc_ok;
  109. int (*probe)(struct blk_desc *fs_dev_desc,
  110. disk_partition_t *fs_partition);
  111. int (*ls)(const char *dirname);
  112. int (*exists)(const char *filename);
  113. int (*size)(const char *filename, loff_t *size);
  114. int (*read)(const char *filename, void *buf, loff_t offset,
  115. loff_t len, loff_t *actread);
  116. int (*write)(const char *filename, void *buf, loff_t offset,
  117. loff_t len, loff_t *actwrite);
  118. void (*close)(void);
  119. int (*uuid)(char *uuid_str);
  120. /*
  121. * Open a directory stream. On success return 0 and directory
  122. * stream pointer via 'dirsp'. On error, return -errno. See
  123. * fs_opendir().
  124. */
  125. int (*opendir)(const char *filename, struct fs_dir_stream **dirsp);
  126. /*
  127. * Read next entry from directory stream. On success return 0
  128. * and directory entry pointer via 'dentp'. On error return
  129. * -errno. See fs_readdir().
  130. */
  131. int (*readdir)(struct fs_dir_stream *dirs, struct fs_dirent **dentp);
  132. /* see fs_closedir() */
  133. void (*closedir)(struct fs_dir_stream *dirs);
  134. int (*unlink)(const char *filename);
  135. int (*mkdir)(const char *dirname);
  136. };
  137. static struct fstype_info fstypes[] = {
  138. #ifdef CONFIG_FS_FAT
  139. {
  140. .fstype = FS_TYPE_FAT,
  141. .name = "fat",
  142. .null_dev_desc_ok = false,
  143. .probe = fat_set_blk_dev,
  144. .close = fat_close,
  145. .ls = fs_ls_generic,
  146. .exists = fat_exists,
  147. .size = fat_size,
  148. .read = fat_read_file,
  149. #ifdef CONFIG_FAT_WRITE
  150. .write = file_fat_write,
  151. .unlink = fat_unlink,
  152. .mkdir = fat_mkdir,
  153. #else
  154. .write = fs_write_unsupported,
  155. .unlink = fs_unlink_unsupported,
  156. .mkdir = fs_mkdir_unsupported,
  157. #endif
  158. .uuid = fs_uuid_unsupported,
  159. .opendir = fat_opendir,
  160. .readdir = fat_readdir,
  161. .closedir = fat_closedir,
  162. },
  163. #endif
  164. #ifdef CONFIG_FS_EXT4
  165. {
  166. .fstype = FS_TYPE_EXT,
  167. .name = "ext4",
  168. .null_dev_desc_ok = false,
  169. .probe = ext4fs_probe,
  170. .close = ext4fs_close,
  171. .ls = ext4fs_ls,
  172. .exists = ext4fs_exists,
  173. .size = ext4fs_size,
  174. .read = ext4_read_file,
  175. #ifdef CONFIG_CMD_EXT4_WRITE
  176. .write = ext4_write_file,
  177. #else
  178. .write = fs_write_unsupported,
  179. #endif
  180. .uuid = ext4fs_uuid,
  181. .opendir = fs_opendir_unsupported,
  182. .unlink = fs_unlink_unsupported,
  183. .mkdir = fs_mkdir_unsupported,
  184. },
  185. #endif
  186. #ifdef CONFIG_SANDBOX
  187. {
  188. .fstype = FS_TYPE_SANDBOX,
  189. .name = "sandbox",
  190. .null_dev_desc_ok = true,
  191. .probe = sandbox_fs_set_blk_dev,
  192. .close = sandbox_fs_close,
  193. .ls = sandbox_fs_ls,
  194. .exists = sandbox_fs_exists,
  195. .size = sandbox_fs_size,
  196. .read = fs_read_sandbox,
  197. .write = fs_write_sandbox,
  198. .uuid = fs_uuid_unsupported,
  199. .opendir = fs_opendir_unsupported,
  200. .unlink = fs_unlink_unsupported,
  201. .mkdir = fs_mkdir_unsupported,
  202. },
  203. #endif
  204. #ifdef CONFIG_CMD_UBIFS
  205. {
  206. .fstype = FS_TYPE_UBIFS,
  207. .name = "ubifs",
  208. .null_dev_desc_ok = true,
  209. .probe = ubifs_set_blk_dev,
  210. .close = ubifs_close,
  211. .ls = ubifs_ls,
  212. .exists = ubifs_exists,
  213. .size = ubifs_size,
  214. .read = ubifs_read,
  215. .write = fs_write_unsupported,
  216. .uuid = fs_uuid_unsupported,
  217. .opendir = fs_opendir_unsupported,
  218. .unlink = fs_unlink_unsupported,
  219. .mkdir = fs_mkdir_unsupported,
  220. },
  221. #endif
  222. #ifdef CONFIG_FS_BTRFS
  223. {
  224. .fstype = FS_TYPE_BTRFS,
  225. .name = "btrfs",
  226. .null_dev_desc_ok = false,
  227. .probe = btrfs_probe,
  228. .close = btrfs_close,
  229. .ls = btrfs_ls,
  230. .exists = btrfs_exists,
  231. .size = btrfs_size,
  232. .read = btrfs_read,
  233. .write = fs_write_unsupported,
  234. .uuid = btrfs_uuid,
  235. .opendir = fs_opendir_unsupported,
  236. .unlink = fs_unlink_unsupported,
  237. .mkdir = fs_mkdir_unsupported,
  238. },
  239. #endif
  240. {
  241. .fstype = FS_TYPE_ANY,
  242. .name = "unsupported",
  243. .null_dev_desc_ok = true,
  244. .probe = fs_probe_unsupported,
  245. .close = fs_close_unsupported,
  246. .ls = fs_ls_unsupported,
  247. .exists = fs_exists_unsupported,
  248. .size = fs_size_unsupported,
  249. .read = fs_read_unsupported,
  250. .write = fs_write_unsupported,
  251. .uuid = fs_uuid_unsupported,
  252. .opendir = fs_opendir_unsupported,
  253. .unlink = fs_unlink_unsupported,
  254. .mkdir = fs_mkdir_unsupported,
  255. },
  256. };
  257. static struct fstype_info *fs_get_info(int fstype)
  258. {
  259. struct fstype_info *info;
  260. int i;
  261. for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes) - 1; i++, info++) {
  262. if (fstype == info->fstype)
  263. return info;
  264. }
  265. /* Return the 'unsupported' sentinel */
  266. return info;
  267. }
  268. /**
  269. * fs_get_type_name() - Get type of current filesystem
  270. *
  271. * Return: Pointer to filesystem name
  272. *
  273. * Returns a string describing the current filesystem, or the sentinel
  274. * "unsupported" for any unrecognised filesystem.
  275. */
  276. const char *fs_get_type_name(void)
  277. {
  278. return fs_get_info(fs_type)->name;
  279. }
  280. int fs_set_blk_dev(const char *ifname, const char *dev_part_str, int fstype)
  281. {
  282. struct fstype_info *info;
  283. int part, i;
  284. #ifdef CONFIG_NEEDS_MANUAL_RELOC
  285. static int relocated;
  286. if (!relocated) {
  287. for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes);
  288. i++, info++) {
  289. info->name += gd->reloc_off;
  290. info->probe += gd->reloc_off;
  291. info->close += gd->reloc_off;
  292. info->ls += gd->reloc_off;
  293. info->read += gd->reloc_off;
  294. info->write += gd->reloc_off;
  295. }
  296. relocated = 1;
  297. }
  298. #endif
  299. part = blk_get_device_part_str(ifname, dev_part_str, &fs_dev_desc,
  300. &fs_partition, 1);
  301. if (part < 0)
  302. return -1;
  303. for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
  304. if (fstype != FS_TYPE_ANY && info->fstype != FS_TYPE_ANY &&
  305. fstype != info->fstype)
  306. continue;
  307. if (!fs_dev_desc && !info->null_dev_desc_ok)
  308. continue;
  309. if (!info->probe(fs_dev_desc, &fs_partition)) {
  310. fs_type = info->fstype;
  311. fs_dev_part = part;
  312. return 0;
  313. }
  314. }
  315. return -1;
  316. }
  317. /* set current blk device w/ blk_desc + partition # */
  318. int fs_set_blk_dev_with_part(struct blk_desc *desc, int part)
  319. {
  320. struct fstype_info *info;
  321. int ret, i;
  322. if (part >= 1)
  323. ret = part_get_info(desc, part, &fs_partition);
  324. else
  325. ret = part_get_info_whole_disk(desc, &fs_partition);
  326. if (ret)
  327. return ret;
  328. fs_dev_desc = desc;
  329. for (i = 0, info = fstypes; i < ARRAY_SIZE(fstypes); i++, info++) {
  330. if (!info->probe(fs_dev_desc, &fs_partition)) {
  331. fs_type = info->fstype;
  332. return 0;
  333. }
  334. }
  335. return -1;
  336. }
  337. static void fs_close(void)
  338. {
  339. struct fstype_info *info = fs_get_info(fs_type);
  340. info->close();
  341. fs_type = FS_TYPE_ANY;
  342. }
  343. int fs_uuid(char *uuid_str)
  344. {
  345. struct fstype_info *info = fs_get_info(fs_type);
  346. return info->uuid(uuid_str);
  347. }
  348. int fs_ls(const char *dirname)
  349. {
  350. int ret;
  351. struct fstype_info *info = fs_get_info(fs_type);
  352. ret = info->ls(dirname);
  353. fs_type = FS_TYPE_ANY;
  354. fs_close();
  355. return ret;
  356. }
  357. int fs_exists(const char *filename)
  358. {
  359. int ret;
  360. struct fstype_info *info = fs_get_info(fs_type);
  361. ret = info->exists(filename);
  362. fs_close();
  363. return ret;
  364. }
  365. int fs_size(const char *filename, loff_t *size)
  366. {
  367. int ret;
  368. struct fstype_info *info = fs_get_info(fs_type);
  369. ret = info->size(filename, size);
  370. fs_close();
  371. return ret;
  372. }
  373. int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
  374. loff_t *actread)
  375. {
  376. struct fstype_info *info = fs_get_info(fs_type);
  377. void *buf;
  378. int ret;
  379. /*
  380. * We don't actually know how many bytes are being read, since len==0
  381. * means read the whole file.
  382. */
  383. buf = map_sysmem(addr, len);
  384. ret = info->read(filename, buf, offset, len, actread);
  385. unmap_sysmem(buf);
  386. /* If we requested a specific number of bytes, check we got it */
  387. if (ret == 0 && len && *actread != len)
  388. debug("** %s shorter than offset + len **\n", filename);
  389. fs_close();
  390. return ret;
  391. }
  392. int fs_write(const char *filename, ulong addr, loff_t offset, loff_t len,
  393. loff_t *actwrite)
  394. {
  395. struct fstype_info *info = fs_get_info(fs_type);
  396. void *buf;
  397. int ret;
  398. buf = map_sysmem(addr, len);
  399. ret = info->write(filename, buf, offset, len, actwrite);
  400. unmap_sysmem(buf);
  401. if (ret < 0 && len != *actwrite) {
  402. printf("** Unable to write file %s **\n", filename);
  403. ret = -1;
  404. }
  405. fs_close();
  406. return ret;
  407. }
  408. struct fs_dir_stream *fs_opendir(const char *filename)
  409. {
  410. struct fstype_info *info = fs_get_info(fs_type);
  411. struct fs_dir_stream *dirs = NULL;
  412. int ret;
  413. ret = info->opendir(filename, &dirs);
  414. fs_close();
  415. if (ret) {
  416. errno = -ret;
  417. return NULL;
  418. }
  419. dirs->desc = fs_dev_desc;
  420. dirs->part = fs_dev_part;
  421. return dirs;
  422. }
  423. struct fs_dirent *fs_readdir(struct fs_dir_stream *dirs)
  424. {
  425. struct fstype_info *info;
  426. struct fs_dirent *dirent;
  427. int ret;
  428. fs_set_blk_dev_with_part(dirs->desc, dirs->part);
  429. info = fs_get_info(fs_type);
  430. ret = info->readdir(dirs, &dirent);
  431. fs_close();
  432. if (ret) {
  433. errno = -ret;
  434. return NULL;
  435. }
  436. return dirent;
  437. }
  438. void fs_closedir(struct fs_dir_stream *dirs)
  439. {
  440. struct fstype_info *info;
  441. if (!dirs)
  442. return;
  443. fs_set_blk_dev_with_part(dirs->desc, dirs->part);
  444. info = fs_get_info(fs_type);
  445. info->closedir(dirs);
  446. fs_close();
  447. }
  448. int fs_unlink(const char *filename)
  449. {
  450. int ret;
  451. struct fstype_info *info = fs_get_info(fs_type);
  452. ret = info->unlink(filename);
  453. fs_type = FS_TYPE_ANY;
  454. fs_close();
  455. return ret;
  456. }
  457. int fs_mkdir(const char *dirname)
  458. {
  459. int ret;
  460. struct fstype_info *info = fs_get_info(fs_type);
  461. ret = info->mkdir(dirname);
  462. fs_type = FS_TYPE_ANY;
  463. fs_close();
  464. return ret;
  465. }
  466. int do_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
  467. int fstype)
  468. {
  469. loff_t size;
  470. if (argc != 4)
  471. return CMD_RET_USAGE;
  472. if (fs_set_blk_dev(argv[1], argv[2], fstype))
  473. return 1;
  474. if (fs_size(argv[3], &size) < 0)
  475. return CMD_RET_FAILURE;
  476. env_set_hex("filesize", size);
  477. return 0;
  478. }
  479. int do_load(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
  480. int fstype)
  481. {
  482. unsigned long addr;
  483. const char *addr_str;
  484. const char *filename;
  485. loff_t bytes;
  486. loff_t pos;
  487. loff_t len_read;
  488. int ret;
  489. unsigned long time;
  490. char *ep;
  491. if (argc < 2)
  492. return CMD_RET_USAGE;
  493. if (argc > 7)
  494. return CMD_RET_USAGE;
  495. if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
  496. return 1;
  497. if (argc >= 4) {
  498. addr = simple_strtoul(argv[3], &ep, 16);
  499. if (ep == argv[3] || *ep != '\0')
  500. return CMD_RET_USAGE;
  501. } else {
  502. addr_str = env_get("loadaddr");
  503. if (addr_str != NULL)
  504. addr = simple_strtoul(addr_str, NULL, 16);
  505. else
  506. addr = CONFIG_SYS_LOAD_ADDR;
  507. }
  508. if (argc >= 5) {
  509. filename = argv[4];
  510. } else {
  511. filename = env_get("bootfile");
  512. if (!filename) {
  513. puts("** No boot file defined **\n");
  514. return 1;
  515. }
  516. }
  517. if (argc >= 6)
  518. bytes = simple_strtoul(argv[5], NULL, 16);
  519. else
  520. bytes = 0;
  521. if (argc >= 7)
  522. pos = simple_strtoul(argv[6], NULL, 16);
  523. else
  524. pos = 0;
  525. time = get_timer(0);
  526. ret = fs_read(filename, addr, pos, bytes, &len_read);
  527. time = get_timer(time);
  528. if (ret < 0)
  529. return 1;
  530. printf("%llu bytes read in %lu ms", len_read, time);
  531. if (time > 0) {
  532. puts(" (");
  533. print_size(div_u64(len_read, time) * 1000, "/s");
  534. puts(")");
  535. }
  536. puts("\n");
  537. env_set_hex("fileaddr", addr);
  538. env_set_hex("filesize", len_read);
  539. return 0;
  540. }
  541. int do_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
  542. int fstype)
  543. {
  544. if (argc < 2)
  545. return CMD_RET_USAGE;
  546. if (argc > 4)
  547. return CMD_RET_USAGE;
  548. if (fs_set_blk_dev(argv[1], (argc >= 3) ? argv[2] : NULL, fstype))
  549. return 1;
  550. if (fs_ls(argc >= 4 ? argv[3] : "/"))
  551. return 1;
  552. return 0;
  553. }
  554. int file_exists(const char *dev_type, const char *dev_part, const char *file,
  555. int fstype)
  556. {
  557. if (fs_set_blk_dev(dev_type, dev_part, fstype))
  558. return 0;
  559. return fs_exists(file);
  560. }
  561. int do_save(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
  562. int fstype)
  563. {
  564. unsigned long addr;
  565. const char *filename;
  566. loff_t bytes;
  567. loff_t pos;
  568. loff_t len;
  569. int ret;
  570. unsigned long time;
  571. if (argc < 6 || argc > 7)
  572. return CMD_RET_USAGE;
  573. if (fs_set_blk_dev(argv[1], argv[2], fstype))
  574. return 1;
  575. addr = simple_strtoul(argv[3], NULL, 16);
  576. filename = argv[4];
  577. bytes = simple_strtoul(argv[5], NULL, 16);
  578. if (argc >= 7)
  579. pos = simple_strtoul(argv[6], NULL, 16);
  580. else
  581. pos = 0;
  582. time = get_timer(0);
  583. ret = fs_write(filename, addr, pos, bytes, &len);
  584. time = get_timer(time);
  585. if (ret < 0)
  586. return 1;
  587. printf("%llu bytes written in %lu ms", len, time);
  588. if (time > 0) {
  589. puts(" (");
  590. print_size(div_u64(len, time) * 1000, "/s");
  591. puts(")");
  592. }
  593. puts("\n");
  594. return 0;
  595. }
  596. int do_fs_uuid(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
  597. int fstype)
  598. {
  599. int ret;
  600. char uuid[37];
  601. memset(uuid, 0, sizeof(uuid));
  602. if (argc < 3 || argc > 4)
  603. return CMD_RET_USAGE;
  604. if (fs_set_blk_dev(argv[1], argv[2], fstype))
  605. return 1;
  606. ret = fs_uuid(uuid);
  607. if (ret)
  608. return CMD_RET_FAILURE;
  609. if (argc == 4)
  610. env_set(argv[3], uuid);
  611. else
  612. printf("%s\n", uuid);
  613. return CMD_RET_SUCCESS;
  614. }
  615. int do_fs_type(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  616. {
  617. struct fstype_info *info;
  618. if (argc < 3 || argc > 4)
  619. return CMD_RET_USAGE;
  620. if (fs_set_blk_dev(argv[1], argv[2], FS_TYPE_ANY))
  621. return 1;
  622. info = fs_get_info(fs_type);
  623. if (argc == 4)
  624. env_set(argv[3], info->name);
  625. else
  626. printf("%s\n", info->name);
  627. return CMD_RET_SUCCESS;
  628. }
  629. int do_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
  630. int fstype)
  631. {
  632. if (argc != 4)
  633. return CMD_RET_USAGE;
  634. if (fs_set_blk_dev(argv[1], argv[2], fstype))
  635. return 1;
  636. if (fs_unlink(argv[3]))
  637. return 1;
  638. return 0;
  639. }
  640. int do_mkdir(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[],
  641. int fstype)
  642. {
  643. int ret;
  644. if (argc != 4)
  645. return CMD_RET_USAGE;
  646. if (fs_set_blk_dev(argv[1], argv[2], fstype))
  647. return 1;
  648. ret = fs_mkdir(argv[3]);
  649. if (ret) {
  650. printf("** Unable to create a directory \"%s\" **\n", argv[3]);
  651. return 1;
  652. }
  653. return 0;
  654. }