1 // SPDX-License-Identifier: GPL-2.0+
4 * Richard Jones, rjones@nexus-tech.net
21 int do_fat_size(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
23 return do_size(cmdtp, flag, argc, argv, FS_TYPE_FAT);
27 fatsize, 4, 0, do_fat_size,
28 "determine a file's size",
29 "<interface> <dev[:part]> <filename>\n"
30 " - Find file 'filename' from 'dev' on 'interface'\n"
31 " and determine its size."
34 int do_fat_fsload(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
36 return do_load(cmdtp, flag, argc, argv, FS_TYPE_FAT);
41 fatload, 7, 0, do_fat_fsload,
42 "load binary file from a dos filesystem",
43 "<interface> [<dev[:part]> [<addr> [<filename> [bytes [pos]]]]]\n"
44 " - Load binary file 'filename' from 'dev' on 'interface'\n"
45 " to address 'addr' from dos filesystem.\n"
46 " 'pos' gives the file position to start loading from.\n"
47 " If 'pos' is omitted, 0 is used. 'pos' requires 'bytes'.\n"
48 " 'bytes' gives the size to load. If 'bytes' is 0 or omitted,\n"
49 " the load stops on end of file.\n"
50 " If either 'pos' or 'bytes' are not aligned to\n"
51 " ARCH_DMA_MINALIGN then a misaligned buffer warning will\n"
52 " be printed and performance will suffer for the load."
55 static int do_fat_ls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
57 return do_ls(cmdtp, flag, argc, argv, FS_TYPE_FAT);
61 fatls, 4, 1, do_fat_ls,
62 "list files in a directory (default /)",
63 "<interface> [<dev[:part]>] [directory]\n"
64 " - list files from 'dev' on 'interface' in a 'directory'"
67 static int do_fat_fsinfo(cmd_tbl_t *cmdtp, int flag, int argc,
71 struct blk_desc *dev_desc;
72 disk_partition_t info;
75 printf("usage: fatinfo <interface> [<dev[:part]>]\n");
79 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
83 dev = dev_desc->devnum;
84 if (fat_set_blk_dev(dev_desc, &info) != 0) {
85 printf("\n** Unable to use %s %d:%d for fatinfo **\n",
89 return file_fat_detectfs();
93 fatinfo, 3, 1, do_fat_fsinfo,
94 "print information about filesystem",
95 "<interface> [<dev[:part]>]\n"
96 " - print information about filesystem from 'dev' on 'interface'"
99 #ifdef CONFIG_FAT_WRITE
100 static int do_fat_fswrite(cmd_tbl_t *cmdtp, int flag,
101 int argc, char * const argv[])
108 struct blk_desc *dev_desc = NULL;
109 disk_partition_t info;
115 return cmd_usage(cmdtp);
117 part = blk_get_device_part_str(argv[1], argv[2], &dev_desc, &info, 1);
121 dev = dev_desc->devnum;
123 if (fat_set_blk_dev(dev_desc, &info) != 0) {
124 printf("\n** Unable to use %s %d:%d for fatwrite **\n",
128 addr = simple_strtoul(argv[3], NULL, 16);
129 count = (argc <= 5) ? 0 : simple_strtoul(argv[5], NULL, 16);
130 /* offset should be a hex, but "-1" is allowed */
131 offset = (argc <= 6) ? 0 : simple_strtol(argv[6], NULL, 16);
133 buf = map_sysmem(addr, count);
134 ret = file_fat_write(argv[4], buf, offset, count, &size);
137 printf("\n** Unable to write \"%s\" from %s %d:%d **\n",
138 argv[4], argv[1], dev, part);
142 printf("%llu bytes written\n", size);
148 fatwrite, 7, 0, do_fat_fswrite,
149 "write file into a dos filesystem",
150 "<interface> <dev[:part]> <addr> <filename> [<bytes> [<offset>]]\n"
151 " - write file 'filename' from the address 'addr' in RAM\n"
152 " to 'dev' on 'interface'"
155 static int do_fat_rm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
157 return do_rm(cmdtp, flag, argc, argv, FS_TYPE_FAT);
161 fatrm, 4, 1, do_fat_rm,
163 "<interface> [<dev[:part]>] <filename>\n"
164 " - delete a file from 'dev' on 'interface'"
167 static int do_fat_mkdir(cmd_tbl_t *cmdtp, int flag, int argc,
170 return do_mkdir(cmdtp, flag, argc, argv, FS_TYPE_FAT);
174 fatmkdir, 4, 1, do_fat_mkdir,
175 "create a directory",
176 "<interface> [<dev[:part]>] <directory>\n"
177 " - create a directory in 'dev' on 'interface'"