1 // SPDX-License-Identifier: GPL-2.0+
4 * Richard Jones, rjones@nexus-tech.net
15 int do_fat_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
17 return do_size(cmdtp, flag, argc, argv, FS_TYPE_FAT);
21 fatsize, 4, 0, do_fat_size,
22 "determine a file's size",
23 "<interface> <dev[:part]> <filename>\n"
24 " - Find file 'filename' from 'dev' on 'interface'\n"
25 " and determine its size."
28 int do_fat_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
30 return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT);
35 fatload, 7, 0, do_fat_fsload,
36 "load binary file from a dos filesystem",
37 "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
38 " - Load binary file 'filename' from 'dev' on 'interface'\n"
39 " to address 'addr' from dos filesystem.\n"
40 " 'pos' gives the file position to start loading from.\n"
41 " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
42 " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
43 " the load stops on end of file.\n"
44 " If either 'pos' or 'bytes' are not aligned to\n"
45 " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
46 " be printed and performance will suffer for the load."
49 static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
51 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
55 fatls, 4, 1, do_fat_ls,
56 "list files in a directory (default /)",
57 "<interface> [<dev[:part]>] [directory]\n"
58 " - list files from 'dev' on 'interface' in a 'directory'"
61 static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
65 struct blk_desc *dev_desc;
66 disk_partition_t info;
69 printf("usage: fatinfo <interface> [<dev[:part]>]\n");
73 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
77 dev = dev_desc->devnum;
78 if (fat_set_blk_dev(dev_desc, &info) != 0) {
79 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
83 return file_fat_detectfs();
87 fatinfo, 3, 1, do_fat_fsinfo,
88 "print information about filesystem",
89 "<interface> [<dev[:part]>]\n"
90 " - print information about filesystem from 'dev' on 'interface'"
93 #ifdef CONFIG_FAT_WRITE
94 static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
95 int argc, char * const argv[])
102 struct blk_desc *dev_desc = NULL;
103 disk_partition_t info;
109 return cmd_usage(cmdtp);
111 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
115 dev = dev_desc->devnum;
117 if (fat_set_blk_dev(dev_desc, &info) != 0) {
118 printf("\n** Unable to use %s %d:%d for fatwrite **\n",
122 addr = simple_strtoul(argv[3], NULL, 16);
123 count = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16);
124 /* offset should be a hex, but "-1" is allowed */
125 offset = (argc <= 6) ? 0 : simple_strtol(argv[6], NULL, 16);
127 buf = map_sysmem(addr, count);
128 ret = file_fat_write(argv[4], buf, offset, count, &size);
131 printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
132 argv[4], argv[1], dev, part);
136 printf("%llu bytes written\n", size);
142 fatwrite, 7, 0, do_fat_fswrite,
143 "write file into a dos filesystem",
144 "<interface> <dev[:part]> <addr> <filename> [<bytes> [<offset>]]\n"
145 " - write file 'filename' from the address 'addr' in RAM\n"
146 " to 'dev' on 'interface'"
149 static int do_fat_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
151 return do_rm(cmdtp, flag, argc, argv, FS_TYPE_FAT);
155 fatrm, 4, 1, do_fat_rm,
157 "<interface> [<dev[:part]>] <filename>\n"
158 " - delete a file from 'dev' on 'interface'"
161 static int do_fat_mkdir(cmd_tbl_t *cmdtp, int flag, int argc,
164 return do_mkdir(cmdtp, flag, argc, argv, FS_TYPE_FAT);
168 fatmkdir, 4, 1, do_fat_mkdir,
169 "create a directory",
170 "<interface> [<dev[:part]>] <directory>\n"
171 " - create a directory in 'dev' on 'interface'"