wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * fat.c |
| 3 | * |
| 4 | * R/O (V)FAT 12/16/32 filesystem implementation by Marcus Sundberg |
| 5 | * |
| 6 | * 2002-07-28 - rjones@nexus-tech.net - ported to ppcboot v1.1.6 |
| 7 | * 2003-03-10 - kharris@nexus-tech.net - ported to uboot |
| 8 | * |
| 9 | * See file CREDITS for list of people who contributed to this |
| 10 | * project. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License as |
| 14 | * published by the Free Software Foundation; either version 2 of |
| 15 | * the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 25 | * MA 02111-1307 USA |
| 26 | */ |
| 27 | |
| 28 | #include <common.h> |
| 29 | #include <config.h> |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 30 | #include <exports.h> |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 31 | #include <fat.h> |
| 32 | #include <asm/byteorder.h> |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 33 | #include <part.h> |
Eric Nelson | 9a800ac | 2012-04-11 04:08:53 +0000 | [diff] [blame] | 34 | #include <malloc.h> |
| 35 | #include <linux/compiler.h> |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 36 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 37 | /* |
| 38 | * Convert a string to lowercase. |
| 39 | */ |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 40 | static void downcase(char *str) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 41 | { |
| 42 | while (*str != '\0') { |
| 43 | TOLOWER(*str); |
| 44 | str++; |
| 45 | } |
| 46 | } |
| 47 | |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 48 | static block_dev_desc_t *cur_dev; |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 49 | static disk_partition_t cur_part_info; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 50 | |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 51 | #define DOS_BOOT_MAGIC_OFFSET 0x1fe |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 52 | #define DOS_FS_TYPE_OFFSET 0x36 |
Wolfgang Denk | 66c2d73 | 2010-07-19 11:36:57 +0200 | [diff] [blame] | 53 | #define DOS_FS32_TYPE_OFFSET 0x52 |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 54 | |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 55 | static int disk_read(__u32 block, __u32 nr_blocks, void *buf) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 56 | { |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 57 | if (!cur_dev || !cur_dev->block_read) |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 58 | return -1; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 59 | |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 60 | return cur_dev->block_read(cur_dev->dev, |
| 61 | cur_part_info.start + block, nr_blocks, buf); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 64 | int fat_register_device(block_dev_desc_t * dev_desc, int part_no) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 65 | { |
Eric Nelson | 9a800ac | 2012-04-11 04:08:53 +0000 | [diff] [blame] | 66 | ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 67 | |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 68 | /* First close any currently found FAT filesystem */ |
| 69 | cur_dev = NULL; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 70 | |
Jon Loeliger | dd60d12 | 2007-07-09 17:56:50 -0500 | [diff] [blame] | 71 | #if (defined(CONFIG_CMD_IDE) || \ |
Sonic Zhang | 8c5170a | 2008-12-09 23:20:18 -0500 | [diff] [blame] | 72 | defined(CONFIG_CMD_SATA) || \ |
Jon Loeliger | dd60d12 | 2007-07-09 17:56:50 -0500 | [diff] [blame] | 73 | defined(CONFIG_CMD_SCSI) || \ |
| 74 | defined(CONFIG_CMD_USB) || \ |
Andy Fleming | 02df4a2 | 2008-01-09 13:51:32 -0600 | [diff] [blame] | 75 | defined(CONFIG_MMC) || \ |
| 76 | defined(CONFIG_SYSTEMACE) ) |
Andy Fleming | 02df4a2 | 2008-01-09 13:51:32 -0600 | [diff] [blame] | 77 | |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 78 | /* Read the partition table, if present */ |
Stephen Warren | 461f86e | 2012-10-17 06:44:57 +0000 | [diff] [blame] | 79 | if (!get_partition_info(dev_desc, part_no, &cur_part_info)) |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 80 | cur_dev = dev_desc; |
Andy Fleming | 02df4a2 | 2008-01-09 13:51:32 -0600 | [diff] [blame] | 81 | #endif |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 82 | |
| 83 | /* Otherwise it might be a superfloppy (whole-disk FAT filesystem) */ |
| 84 | if (!cur_dev) { |
Stephen Warren | bd1a7e3 | 2012-10-05 13:17:39 +0000 | [diff] [blame] | 85 | if (part_no != 0) { |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 86 | printf("** Partition %d not valid on device %d **\n", |
| 87 | part_no, dev_desc->dev); |
| 88 | return -1; |
| 89 | } |
| 90 | |
| 91 | cur_dev = dev_desc; |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 92 | cur_part_info.start = 0; |
| 93 | cur_part_info.size = dev_desc->lba; |
| 94 | cur_part_info.blksz = dev_desc->blksz; |
Stephen Warren | a1687b8 | 2012-10-17 06:44:58 +0000 | [diff] [blame^] | 95 | cur_part_info.name[0] = 0; |
| 96 | cur_part_info.type[0] = 0; |
| 97 | cur_part_info.bootable = 0; |
| 98 | #ifdef CONFIG_PARTITION_UUIDS |
| 99 | cur_part_info.uuid[0] = 0; |
| 100 | #endif |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* Make sure it has a valid FAT header */ |
| 104 | if (disk_read(0, 1, buffer) != 1) { |
| 105 | cur_dev = NULL; |
| 106 | return -1; |
| 107 | } |
| 108 | |
| 109 | /* Check if it's actually a DOS volume */ |
| 110 | if (memcmp(buffer + DOS_BOOT_MAGIC_OFFSET, "\x55\xAA", 2)) { |
| 111 | cur_dev = NULL; |
| 112 | return -1; |
| 113 | } |
| 114 | |
| 115 | /* Check for FAT12/FAT16/FAT32 filesystem */ |
| 116 | if (!memcmp(buffer + DOS_FS_TYPE_OFFSET, "FAT", 3)) |
| 117 | return 0; |
| 118 | if (!memcmp(buffer + DOS_FS32_TYPE_OFFSET, "FAT32", 5)) |
| 119 | return 0; |
| 120 | |
| 121 | cur_dev = NULL; |
| 122 | return -1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Kyle Moffett | 9813b75 | 2011-12-21 07:08:10 +0000 | [diff] [blame] | 125 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 126 | /* |
| 127 | * Get the first occurence of a directory delimiter ('/' or '\') in a string. |
| 128 | * Return index into string if found, -1 otherwise. |
| 129 | */ |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 130 | static int dirdelim(char *str) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 131 | { |
| 132 | char *start = str; |
| 133 | |
| 134 | while (*str != '\0') { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 135 | if (ISDIRDELIM(*str)) |
| 136 | return str - start; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 137 | str++; |
| 138 | } |
| 139 | return -1; |
| 140 | } |
| 141 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 142 | /* |
| 143 | * Extract zero terminated short name from a directory entry. |
| 144 | */ |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 145 | static void get_name(dir_entry *dirent, char *s_name) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 146 | { |
| 147 | char *ptr; |
| 148 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 149 | memcpy(s_name, dirent->name, 8); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 150 | s_name[8] = '\0'; |
| 151 | ptr = s_name; |
| 152 | while (*ptr && *ptr != ' ') |
| 153 | ptr++; |
| 154 | if (dirent->ext[0] && dirent->ext[0] != ' ') { |
| 155 | *ptr = '.'; |
| 156 | ptr++; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 157 | memcpy(ptr, dirent->ext, 3); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 158 | ptr[3] = '\0'; |
| 159 | while (*ptr && *ptr != ' ') |
| 160 | ptr++; |
| 161 | } |
| 162 | *ptr = '\0'; |
| 163 | if (*s_name == DELETED_FLAG) |
| 164 | *s_name = '\0'; |
| 165 | else if (*s_name == aRING) |
Remy Bohmer | 3c2c2f4 | 2008-11-27 22:30:27 +0100 | [diff] [blame] | 166 | *s_name = DELETED_FLAG; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 167 | downcase(s_name); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Get the entry at index 'entry' in a FAT (12/16/32) table. |
| 172 | * On failure 0x00 is returned. |
| 173 | */ |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 174 | static __u32 get_fatent(fsdata *mydata, __u32 entry) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 175 | { |
| 176 | __u32 bufnum; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 177 | __u32 off16, offset; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 178 | __u32 ret = 0x00; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 179 | __u16 val1, val2; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 180 | |
| 181 | switch (mydata->fatsize) { |
| 182 | case 32: |
| 183 | bufnum = entry / FAT32BUFSIZE; |
| 184 | offset = entry - bufnum * FAT32BUFSIZE; |
| 185 | break; |
| 186 | case 16: |
| 187 | bufnum = entry / FAT16BUFSIZE; |
| 188 | offset = entry - bufnum * FAT16BUFSIZE; |
| 189 | break; |
| 190 | case 12: |
| 191 | bufnum = entry / FAT12BUFSIZE; |
| 192 | offset = entry - bufnum * FAT12BUFSIZE; |
| 193 | break; |
| 194 | |
| 195 | default: |
| 196 | /* Unsupported FAT size */ |
| 197 | return ret; |
| 198 | } |
| 199 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 200 | debug("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n", |
| 201 | mydata->fatsize, entry, entry, offset, offset); |
Wolfgang Denk | 2aa98c6 | 2010-07-19 11:36:58 +0200 | [diff] [blame] | 202 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 203 | /* Read a new block of FAT entries into the cache. */ |
| 204 | if (bufnum != mydata->fatbufnum) { |
Sergei Shtylyov | 60b36f0 | 2011-08-08 09:39:29 +0000 | [diff] [blame] | 205 | __u32 getsize = FATBUFBLOCKS; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 206 | __u8 *bufptr = mydata->fatbuf; |
| 207 | __u32 fatlength = mydata->fatlength; |
| 208 | __u32 startblock = bufnum * FATBUFBLOCKS; |
| 209 | |
Benoît Thébaudeau | 8006dd2 | 2012-07-20 15:19:29 +0200 | [diff] [blame] | 210 | if (startblock + getsize > fatlength) |
| 211 | getsize = fatlength - startblock; |
Sergei Shtylyov | 60b36f0 | 2011-08-08 09:39:29 +0000 | [diff] [blame] | 212 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 213 | startblock += mydata->fat_sect; /* Offset from start of disk */ |
| 214 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 215 | if (disk_read(startblock, getsize, bufptr) < 0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 216 | debug("Error reading FAT blocks\n"); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 217 | return ret; |
| 218 | } |
| 219 | mydata->fatbufnum = bufnum; |
| 220 | } |
| 221 | |
| 222 | /* Get the actual entry from the table */ |
| 223 | switch (mydata->fatsize) { |
| 224 | case 32: |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 225 | ret = FAT2CPU32(((__u32 *) mydata->fatbuf)[offset]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 226 | break; |
| 227 | case 16: |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 228 | ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 229 | break; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 230 | case 12: |
| 231 | off16 = (offset * 3) / 4; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 232 | |
| 233 | switch (offset & 0x3) { |
| 234 | case 0: |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 235 | ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[off16]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 236 | ret &= 0xfff; |
| 237 | break; |
| 238 | case 1: |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 239 | val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 240 | val1 &= 0xf000; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 241 | val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 242 | val2 &= 0x00ff; |
| 243 | ret = (val2 << 4) | (val1 >> 12); |
| 244 | break; |
| 245 | case 2: |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 246 | val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 247 | val1 &= 0xff00; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 248 | val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 249 | val2 &= 0x000f; |
| 250 | ret = (val2 << 8) | (val1 >> 8); |
| 251 | break; |
| 252 | case 3: |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 253 | ret = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 254 | ret = (ret & 0xfff0) >> 4; |
| 255 | break; |
| 256 | default: |
| 257 | break; |
| 258 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 259 | break; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 260 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 261 | debug("FAT%d: ret: %08x, offset: %04x\n", |
| 262 | mydata->fatsize, ret, offset); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 263 | |
| 264 | return ret; |
| 265 | } |
| 266 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 267 | /* |
| 268 | * Read at most 'size' bytes from the specified cluster into 'buffer'. |
| 269 | * Return 0 on success, -1 otherwise. |
| 270 | */ |
| 271 | static int |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 272 | get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 273 | { |
Erik Hansen | 3f270f4 | 2011-03-24 10:15:37 +0100 | [diff] [blame] | 274 | __u32 idx = 0; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 275 | __u32 startsect; |
Kyle Moffett | 46236b1 | 2011-12-20 07:41:13 +0000 | [diff] [blame] | 276 | int ret; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 277 | |
| 278 | if (clustnum > 0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 279 | startsect = mydata->data_begin + |
| 280 | clustnum * mydata->clust_size; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 281 | } else { |
| 282 | startsect = mydata->rootdir_sect; |
| 283 | } |
| 284 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 285 | debug("gc - clustnum: %d, startsect: %d\n", clustnum, startsect); |
| 286 | |
Benoît Thébaudeau | cc63b25 | 2012-07-20 15:21:08 +0200 | [diff] [blame] | 287 | if ((unsigned long)buffer & (ARCH_DMA_MINALIGN - 1)) { |
Eric Nelson | 9a800ac | 2012-04-11 04:08:53 +0000 | [diff] [blame] | 288 | ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 289 | |
Benoît Thébaudeau | cc63b25 | 2012-07-20 15:21:08 +0200 | [diff] [blame] | 290 | printf("FAT: Misaligned buffer address (%p)\n", buffer); |
| 291 | |
| 292 | while (size >= mydata->sect_size) { |
| 293 | ret = disk_read(startsect++, 1, tmpbuf); |
| 294 | if (ret != 1) { |
| 295 | debug("Error reading data (got %d)\n", ret); |
| 296 | return -1; |
| 297 | } |
| 298 | |
| 299 | memcpy(buffer, tmpbuf, mydata->sect_size); |
| 300 | buffer += mydata->sect_size; |
| 301 | size -= mydata->sect_size; |
| 302 | } |
| 303 | } else { |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 304 | idx = size / mydata->sect_size; |
Benoît Thébaudeau | cc63b25 | 2012-07-20 15:21:08 +0200 | [diff] [blame] | 305 | ret = disk_read(startsect, idx, buffer); |
| 306 | if (ret != idx) { |
| 307 | debug("Error reading data (got %d)\n", ret); |
| 308 | return -1; |
| 309 | } |
| 310 | startsect += idx; |
| 311 | idx *= mydata->sect_size; |
| 312 | buffer += idx; |
| 313 | size -= idx; |
| 314 | } |
| 315 | if (size) { |
| 316 | ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size); |
| 317 | |
| 318 | ret = disk_read(startsect, 1, tmpbuf); |
Kyle Moffett | 46236b1 | 2011-12-20 07:41:13 +0000 | [diff] [blame] | 319 | if (ret != 1) { |
| 320 | debug("Error reading data (got %d)\n", ret); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 321 | return -1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 322 | } |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 323 | |
Benoît Thébaudeau | cc63b25 | 2012-07-20 15:21:08 +0200 | [diff] [blame] | 324 | memcpy(buffer, tmpbuf, size); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 330 | /* |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 331 | * Read at most 'maxsize' bytes from 'pos' in the file associated with 'dentptr' |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 332 | * into 'buffer'. |
| 333 | * Return the number of bytes read or -1 on fatal errors. |
| 334 | */ |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 335 | __u8 get_contents_vfatname_block[MAX_CLUSTSIZE] |
| 336 | __aligned(ARCH_DMA_MINALIGN); |
| 337 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 338 | static long |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 339 | get_contents(fsdata *mydata, dir_entry *dentptr, unsigned long pos, |
| 340 | __u8 *buffer, unsigned long maxsize) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 341 | { |
| 342 | unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0; |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 343 | unsigned int bytesperclust = mydata->clust_size * mydata->sect_size; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 344 | __u32 curclust = START(dentptr); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 345 | __u32 endclust, newclust; |
| 346 | unsigned long actsize; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 347 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 348 | debug("Filesize: %ld bytes\n", filesize); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 349 | |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 350 | if (pos >= filesize) { |
| 351 | debug("Read position past EOF: %lu\n", pos); |
| 352 | return gotsize; |
| 353 | } |
| 354 | |
| 355 | if (maxsize > 0 && filesize > pos + maxsize) |
| 356 | filesize = pos + maxsize; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 357 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 358 | debug("%ld bytes\n", filesize); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 359 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 360 | actsize = bytesperclust; |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 361 | |
| 362 | /* go to cluster at pos */ |
| 363 | while (actsize <= pos) { |
| 364 | curclust = get_fatent(mydata, curclust); |
| 365 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
| 366 | debug("curclust: 0x%x\n", curclust); |
| 367 | debug("Invalid FAT entry\n"); |
| 368 | return gotsize; |
| 369 | } |
| 370 | actsize += bytesperclust; |
| 371 | } |
| 372 | |
| 373 | /* actsize > pos */ |
| 374 | actsize -= bytesperclust; |
| 375 | filesize -= actsize; |
| 376 | pos -= actsize; |
| 377 | |
| 378 | /* align to beginning of next cluster if any */ |
| 379 | if (pos) { |
| 380 | actsize = min(filesize, bytesperclust); |
| 381 | if (get_cluster(mydata, curclust, get_contents_vfatname_block, |
| 382 | (int)actsize) != 0) { |
| 383 | printf("Error reading cluster\n"); |
| 384 | return -1; |
| 385 | } |
| 386 | filesize -= actsize; |
| 387 | actsize -= pos; |
| 388 | memcpy(buffer, get_contents_vfatname_block + pos, actsize); |
| 389 | gotsize += actsize; |
| 390 | if (!filesize) |
| 391 | return gotsize; |
| 392 | buffer += actsize; |
| 393 | |
| 394 | curclust = get_fatent(mydata, curclust); |
| 395 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
| 396 | debug("curclust: 0x%x\n", curclust); |
| 397 | debug("Invalid FAT entry\n"); |
| 398 | return gotsize; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | actsize = bytesperclust; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 403 | endclust = curclust; |
| 404 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 405 | do { |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 406 | /* search for consecutive clusters */ |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 407 | while (actsize < filesize) { |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 408 | newclust = get_fatent(mydata, endclust); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 409 | if ((newclust - 1) != endclust) |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 410 | goto getit; |
michael | 8ce4e5c | 2008-03-02 23:33:46 +0100 | [diff] [blame] | 411 | if (CHECK_CLUST(newclust, mydata->fatsize)) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 412 | debug("curclust: 0x%x\n", newclust); |
| 413 | debug("Invalid FAT entry\n"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 414 | return gotsize; |
| 415 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 416 | endclust = newclust; |
| 417 | actsize += bytesperclust; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 418 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 419 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 420 | /* get remaining bytes */ |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 421 | actsize = filesize; |
Benoît Thébaudeau | 0880e5b | 2012-07-20 15:21:37 +0200 | [diff] [blame] | 422 | if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 423 | printf("Error reading cluster\n"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 424 | return -1; |
| 425 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 426 | gotsize += actsize; |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 427 | return gotsize; |
| 428 | getit: |
| 429 | if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 430 | printf("Error reading cluster\n"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 431 | return -1; |
| 432 | } |
| 433 | gotsize += (int)actsize; |
| 434 | filesize -= actsize; |
| 435 | buffer += actsize; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 436 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 437 | curclust = get_fatent(mydata, endclust); |
michael | 8ce4e5c | 2008-03-02 23:33:46 +0100 | [diff] [blame] | 438 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 439 | debug("curclust: 0x%x\n", curclust); |
| 440 | printf("Invalid FAT entry\n"); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 441 | return gotsize; |
| 442 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 443 | actsize = bytesperclust; |
| 444 | endclust = curclust; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 445 | } while (1); |
| 446 | } |
| 447 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 448 | #ifdef CONFIG_SUPPORT_VFAT |
| 449 | /* |
| 450 | * Extract the file name information from 'slotptr' into 'l_name', |
| 451 | * starting at l_name[*idx]. |
| 452 | * Return 1 if terminator (zero byte) is found, 0 otherwise. |
| 453 | */ |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 454 | static int slot2str(dir_slot *slotptr, char *l_name, int *idx) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 455 | { |
| 456 | int j; |
| 457 | |
| 458 | for (j = 0; j <= 8; j += 2) { |
| 459 | l_name[*idx] = slotptr->name0_4[j]; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 460 | if (l_name[*idx] == 0x00) |
| 461 | return 1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 462 | (*idx)++; |
| 463 | } |
| 464 | for (j = 0; j <= 10; j += 2) { |
| 465 | l_name[*idx] = slotptr->name5_10[j]; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 466 | if (l_name[*idx] == 0x00) |
| 467 | return 1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 468 | (*idx)++; |
| 469 | } |
| 470 | for (j = 0; j <= 2; j += 2) { |
| 471 | l_name[*idx] = slotptr->name11_12[j]; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 472 | if (l_name[*idx] == 0x00) |
| 473 | return 1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 474 | (*idx)++; |
| 475 | } |
| 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 480 | /* |
| 481 | * Extract the full long filename starting at 'retdent' (which is really |
| 482 | * a slot) into 'l_name'. If successful also copy the real directory entry |
| 483 | * into 'retdent' |
| 484 | * Return 0 on success, -1 otherwise. |
| 485 | */ |
| 486 | static int |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 487 | get_vfatname(fsdata *mydata, int curclust, __u8 *cluster, |
| 488 | dir_entry *retdent, char *l_name) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 489 | { |
| 490 | dir_entry *realdent; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 491 | dir_slot *slotptr = (dir_slot *)retdent; |
Sergei Shtylyov | 025421e | 2011-08-19 09:37:46 +0000 | [diff] [blame] | 492 | __u8 *buflimit = cluster + mydata->sect_size * ((curclust == 0) ? |
| 493 | PREFETCH_BLOCKS : |
| 494 | mydata->clust_size); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 495 | __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 496 | int idx = 0; |
| 497 | |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 498 | if (counter > VFAT_MAXSEQ) { |
| 499 | debug("Error: VFAT name is too long\n"); |
| 500 | return -1; |
| 501 | } |
| 502 | |
| 503 | while ((__u8 *)slotptr < buflimit) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 504 | if (counter == 0) |
| 505 | break; |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 506 | if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter) |
| 507 | return -1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 508 | slotptr++; |
| 509 | counter--; |
| 510 | } |
| 511 | |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 512 | if ((__u8 *)slotptr >= buflimit) { |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 513 | dir_slot *slotptr2; |
| 514 | |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 515 | if (curclust == 0) |
| 516 | return -1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 517 | curclust = get_fatent(mydata, curclust); |
michael | 8ce4e5c | 2008-03-02 23:33:46 +0100 | [diff] [blame] | 518 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 519 | debug("curclust: 0x%x\n", curclust); |
| 520 | printf("Invalid FAT entry\n"); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 521 | return -1; |
| 522 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 523 | |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 524 | if (get_cluster(mydata, curclust, get_contents_vfatname_block, |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 525 | mydata->clust_size * mydata->sect_size) != 0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 526 | debug("Error: reading directory block\n"); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 527 | return -1; |
| 528 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 529 | |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 530 | slotptr2 = (dir_slot *)get_contents_vfatname_block; |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 531 | while (counter > 0) { |
| 532 | if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK) |
| 533 | & 0xff) != counter) |
| 534 | return -1; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 535 | slotptr2++; |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 536 | counter--; |
| 537 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 538 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 539 | /* Save the real directory entry */ |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 540 | realdent = (dir_entry *)slotptr2; |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 541 | while ((__u8 *)slotptr2 > get_contents_vfatname_block) { |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 542 | slotptr2--; |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 543 | slot2str(slotptr2, l_name, &idx); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 544 | } |
| 545 | } else { |
| 546 | /* Save the real directory entry */ |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 547 | realdent = (dir_entry *)slotptr; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | do { |
| 551 | slotptr--; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 552 | if (slot2str(slotptr, l_name, &idx)) |
| 553 | break; |
wdenk | 2d1a537 | 2004-02-23 19:30:57 +0000 | [diff] [blame] | 554 | } while (!(slotptr->id & LAST_LONG_ENTRY_MASK)); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 555 | |
| 556 | l_name[idx] = '\0'; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 557 | if (*l_name == DELETED_FLAG) |
| 558 | *l_name = '\0'; |
| 559 | else if (*l_name == aRING) |
| 560 | *l_name = DELETED_FLAG; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 561 | downcase(l_name); |
| 562 | |
| 563 | /* Return the real directory entry */ |
| 564 | memcpy(retdent, realdent, sizeof(dir_entry)); |
| 565 | |
| 566 | return 0; |
| 567 | } |
| 568 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 569 | /* Calculate short name checksum */ |
Marek Vasut | ff04f6d | 2012-10-09 07:20:22 +0000 | [diff] [blame] | 570 | static __u8 mkcksum(const char name[8], const char ext[3]) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 571 | { |
| 572 | int i; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 573 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 574 | __u8 ret = 0; |
| 575 | |
Marek Vasut | ff04f6d | 2012-10-09 07:20:22 +0000 | [diff] [blame] | 576 | for (i = 0; i < sizeof(name); i++) |
| 577 | ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + name[i]; |
| 578 | for (i = 0; i < sizeof(ext); i++) |
| 579 | ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + ext[i]; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 580 | |
| 581 | return ret; |
| 582 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 583 | #endif /* CONFIG_SUPPORT_VFAT */ |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 584 | |
| 585 | /* |
| 586 | * Get the directory entry associated with 'filename' from the directory |
| 587 | * starting at 'startsect' |
| 588 | */ |
Eric Nelson | 9a800ac | 2012-04-11 04:08:53 +0000 | [diff] [blame] | 589 | __u8 get_dentfromdir_block[MAX_CLUSTSIZE] |
| 590 | __aligned(ARCH_DMA_MINALIGN); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 591 | |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 592 | static dir_entry *get_dentfromdir(fsdata *mydata, int startsect, |
| 593 | char *filename, dir_entry *retdent, |
| 594 | int dols) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 595 | { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 596 | __u16 prevcksum = 0xffff; |
| 597 | __u32 curclust = START(retdent); |
| 598 | int files = 0, dirs = 0; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 599 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 600 | debug("get_dentfromdir: %s\n", filename); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 601 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 602 | while (1) { |
| 603 | dir_entry *dentptr; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 604 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 605 | int i; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 606 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 607 | if (get_cluster(mydata, curclust, get_dentfromdir_block, |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 608 | mydata->clust_size * mydata->sect_size) != 0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 609 | debug("Error: reading directory block\n"); |
| 610 | return NULL; |
| 611 | } |
| 612 | |
| 613 | dentptr = (dir_entry *)get_dentfromdir_block; |
| 614 | |
| 615 | for (i = 0; i < DIRENTSPERCLUST; i++) { |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 616 | char s_name[14], l_name[VFAT_MAXLEN_BYTES]; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 617 | |
| 618 | l_name[0] = '\0'; |
| 619 | if (dentptr->name[0] == DELETED_FLAG) { |
| 620 | dentptr++; |
| 621 | continue; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 622 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 623 | if ((dentptr->attr & ATTR_VOLUME)) { |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 624 | #ifdef CONFIG_SUPPORT_VFAT |
J. Vijayanand | 206d68f | 2011-10-19 07:43:08 +0000 | [diff] [blame] | 625 | if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT && |
| 626 | (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 627 | prevcksum = ((dir_slot *)dentptr)->alias_checksum; |
| 628 | get_vfatname(mydata, curclust, |
| 629 | get_dentfromdir_block, |
| 630 | dentptr, l_name); |
| 631 | if (dols) { |
| 632 | int isdir; |
| 633 | char dirc; |
| 634 | int doit = 0; |
| 635 | |
| 636 | isdir = (dentptr->attr & ATTR_DIR); |
| 637 | |
| 638 | if (isdir) { |
| 639 | dirs++; |
| 640 | dirc = '/'; |
| 641 | doit = 1; |
| 642 | } else { |
| 643 | dirc = ' '; |
| 644 | if (l_name[0] != 0) { |
| 645 | files++; |
| 646 | doit = 1; |
| 647 | } |
| 648 | } |
| 649 | if (doit) { |
| 650 | if (dirc == ' ') { |
| 651 | printf(" %8ld %s%c\n", |
| 652 | (long)FAT2CPU32(dentptr->size), |
| 653 | l_name, |
| 654 | dirc); |
| 655 | } else { |
| 656 | printf(" %s%c\n", |
| 657 | l_name, |
| 658 | dirc); |
| 659 | } |
| 660 | } |
| 661 | dentptr++; |
| 662 | continue; |
| 663 | } |
| 664 | debug("vfatname: |%s|\n", l_name); |
| 665 | } else |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 666 | #endif |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 667 | { |
| 668 | /* Volume label or VFAT entry */ |
| 669 | dentptr++; |
| 670 | continue; |
| 671 | } |
| 672 | } |
| 673 | if (dentptr->name[0] == 0) { |
| 674 | if (dols) { |
| 675 | printf("\n%d file(s), %d dir(s)\n\n", |
| 676 | files, dirs); |
| 677 | } |
| 678 | debug("Dentname == NULL - %d\n", i); |
| 679 | return NULL; |
| 680 | } |
| 681 | #ifdef CONFIG_SUPPORT_VFAT |
Marek Vasut | ff04f6d | 2012-10-09 07:20:22 +0000 | [diff] [blame] | 682 | __u8 csum = mkcksum(dentptr->name, dentptr->ext); |
| 683 | if (dols && csum == prevcksum) { |
Sergei Shtylyov | bf34e7d | 2012-01-02 06:54:29 +0000 | [diff] [blame] | 684 | prevcksum = 0xffff; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 685 | dentptr++; |
| 686 | continue; |
| 687 | } |
| 688 | #endif |
| 689 | get_name(dentptr, s_name); |
| 690 | if (dols) { |
| 691 | int isdir = (dentptr->attr & ATTR_DIR); |
| 692 | char dirc; |
| 693 | int doit = 0; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 694 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 695 | if (isdir) { |
| 696 | dirs++; |
| 697 | dirc = '/'; |
| 698 | doit = 1; |
| 699 | } else { |
| 700 | dirc = ' '; |
| 701 | if (s_name[0] != 0) { |
| 702 | files++; |
| 703 | doit = 1; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | if (doit) { |
| 708 | if (dirc == ' ') { |
| 709 | printf(" %8ld %s%c\n", |
| 710 | (long)FAT2CPU32(dentptr->size), |
| 711 | s_name, dirc); |
| 712 | } else { |
| 713 | printf(" %s%c\n", |
| 714 | s_name, dirc); |
| 715 | } |
| 716 | } |
| 717 | |
| 718 | dentptr++; |
| 719 | continue; |
| 720 | } |
| 721 | |
| 722 | if (strcmp(filename, s_name) |
| 723 | && strcmp(filename, l_name)) { |
| 724 | debug("Mismatch: |%s|%s|\n", s_name, l_name); |
| 725 | dentptr++; |
| 726 | continue; |
| 727 | } |
| 728 | |
| 729 | memcpy(retdent, dentptr, sizeof(dir_entry)); |
| 730 | |
| 731 | debug("DentName: %s", s_name); |
| 732 | debug(", start: 0x%x", START(dentptr)); |
| 733 | debug(", size: 0x%x %s\n", |
| 734 | FAT2CPU32(dentptr->size), |
| 735 | (dentptr->attr & ATTR_DIR) ? "(DIR)" : ""); |
| 736 | |
| 737 | return retdent; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 738 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 739 | |
| 740 | curclust = get_fatent(mydata, curclust); |
| 741 | if (CHECK_CLUST(curclust, mydata->fatsize)) { |
| 742 | debug("curclust: 0x%x\n", curclust); |
| 743 | printf("Invalid FAT entry\n"); |
| 744 | return NULL; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 745 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 746 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 747 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 748 | return NULL; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 749 | } |
| 750 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 751 | /* |
| 752 | * Read boot sector and volume info from a FAT filesystem |
| 753 | */ |
| 754 | static int |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 755 | read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 756 | { |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 757 | __u8 *block; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 758 | volume_info *vistart; |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 759 | int ret = 0; |
| 760 | |
| 761 | if (cur_dev == NULL) { |
| 762 | debug("Error: no device selected\n"); |
| 763 | return -1; |
| 764 | } |
| 765 | |
Eric Nelson | 9a800ac | 2012-04-11 04:08:53 +0000 | [diff] [blame] | 766 | block = memalign(ARCH_DMA_MINALIGN, cur_dev->blksz); |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 767 | if (block == NULL) { |
| 768 | debug("Error: allocating block\n"); |
| 769 | return -1; |
| 770 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 771 | |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 772 | if (disk_read(0, 1, block) < 0) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 773 | debug("Error: reading block\n"); |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 774 | goto fail; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 775 | } |
| 776 | |
| 777 | memcpy(bs, block, sizeof(boot_sector)); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 778 | bs->reserved = FAT2CPU16(bs->reserved); |
| 779 | bs->fat_length = FAT2CPU16(bs->fat_length); |
| 780 | bs->secs_track = FAT2CPU16(bs->secs_track); |
| 781 | bs->heads = FAT2CPU16(bs->heads); |
| 782 | bs->total_sect = FAT2CPU32(bs->total_sect); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 783 | |
| 784 | /* FAT32 entries */ |
| 785 | if (bs->fat_length == 0) { |
| 786 | /* Assume FAT32 */ |
| 787 | bs->fat32_length = FAT2CPU32(bs->fat32_length); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 788 | bs->flags = FAT2CPU16(bs->flags); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 789 | bs->root_cluster = FAT2CPU32(bs->root_cluster); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 790 | bs->info_sector = FAT2CPU16(bs->info_sector); |
| 791 | bs->backup_boot = FAT2CPU16(bs->backup_boot); |
| 792 | vistart = (volume_info *)(block + sizeof(boot_sector)); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 793 | *fatsize = 32; |
| 794 | } else { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 795 | vistart = (volume_info *)&(bs->fat32_length); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 796 | *fatsize = 0; |
| 797 | } |
| 798 | memcpy(volinfo, vistart, sizeof(volume_info)); |
| 799 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 800 | if (*fatsize == 32) { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 801 | if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0) |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 802 | goto exit; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 803 | } else { |
Tom Rix | 651351f | 2009-05-20 07:55:41 -0500 | [diff] [blame] | 804 | if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) { |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 805 | *fatsize = 12; |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 806 | goto exit; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 807 | } |
Tom Rix | 651351f | 2009-05-20 07:55:41 -0500 | [diff] [blame] | 808 | if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) { |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 809 | *fatsize = 16; |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 810 | goto exit; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 811 | } |
| 812 | } |
| 813 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 814 | debug("Error: broken fs_type sign\n"); |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 815 | fail: |
| 816 | ret = -1; |
| 817 | exit: |
| 818 | free(block); |
| 819 | return ret; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 820 | } |
| 821 | |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 822 | __u8 do_fat_read_at_block[MAX_CLUSTSIZE] |
Eric Nelson | 9a800ac | 2012-04-11 04:08:53 +0000 | [diff] [blame] | 823 | __aligned(ARCH_DMA_MINALIGN); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 824 | |
stroese | 20cc00d | 2004-12-16 17:57:26 +0000 | [diff] [blame] | 825 | long |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 826 | do_fat_read_at(const char *filename, unsigned long pos, void *buffer, |
| 827 | unsigned long maxsize, int dols) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 828 | { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 829 | char fnamecopy[2048]; |
| 830 | boot_sector bs; |
| 831 | volume_info volinfo; |
| 832 | fsdata datablock; |
| 833 | fsdata *mydata = &datablock; |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 834 | dir_entry *dentptr = NULL; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 835 | __u16 prevcksum = 0xffff; |
| 836 | char *subname = ""; |
Erik Hansen | 3f270f4 | 2011-03-24 10:15:37 +0100 | [diff] [blame] | 837 | __u32 cursect; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 838 | int idx, isdir = 0; |
| 839 | int files = 0, dirs = 0; |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 840 | long ret = -1; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 841 | int firsttime; |
Sergei Shtylyov | 40e2191 | 2011-08-19 09:32:34 +0000 | [diff] [blame] | 842 | __u32 root_cluster = 0; |
Erik Hansen | 3f270f4 | 2011-03-24 10:15:37 +0100 | [diff] [blame] | 843 | int rootdir_size = 0; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 844 | int j; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 845 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 846 | if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) { |
| 847 | debug("Error: reading boot sector\n"); |
| 848 | return -1; |
| 849 | } |
| 850 | |
Sergei Shtylyov | 40e2191 | 2011-08-19 09:32:34 +0000 | [diff] [blame] | 851 | if (mydata->fatsize == 32) { |
| 852 | root_cluster = bs.root_cluster; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 853 | mydata->fatlength = bs.fat32_length; |
Sergei Shtylyov | 40e2191 | 2011-08-19 09:32:34 +0000 | [diff] [blame] | 854 | } else { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 855 | mydata->fatlength = bs.fat_length; |
Sergei Shtylyov | 40e2191 | 2011-08-19 09:32:34 +0000 | [diff] [blame] | 856 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 857 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 858 | mydata->fat_sect = bs.reserved; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 859 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 860 | cursect = mydata->rootdir_sect |
| 861 | = mydata->fat_sect + mydata->fatlength * bs.fats; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 862 | |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 863 | mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0]; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 864 | mydata->clust_size = bs.cluster_size; |
Kyle Moffett | 46236b1 | 2011-12-20 07:41:13 +0000 | [diff] [blame] | 865 | if (mydata->sect_size != cur_part_info.blksz) { |
| 866 | printf("Error: FAT sector size mismatch (fs=%hu, dev=%lu)\n", |
| 867 | mydata->sect_size, cur_part_info.blksz); |
| 868 | return -1; |
| 869 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 870 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 871 | if (mydata->fatsize == 32) { |
| 872 | mydata->data_begin = mydata->rootdir_sect - |
| 873 | (mydata->clust_size * 2); |
| 874 | } else { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 875 | rootdir_size = ((bs.dir_entries[1] * (int)256 + |
| 876 | bs.dir_entries[0]) * |
| 877 | sizeof(dir_entry)) / |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 878 | mydata->sect_size; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 879 | mydata->data_begin = mydata->rootdir_sect + |
| 880 | rootdir_size - |
| 881 | (mydata->clust_size * 2); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 882 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 883 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 884 | mydata->fatbufnum = -1; |
Eric Nelson | 9a800ac | 2012-04-11 04:08:53 +0000 | [diff] [blame] | 885 | mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE); |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 886 | if (mydata->fatbuf == NULL) { |
| 887 | debug("Error: allocating memory\n"); |
| 888 | return -1; |
| 889 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 890 | |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 891 | #ifdef CONFIG_SUPPORT_VFAT |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 892 | debug("VFAT Support enabled\n"); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 893 | #endif |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 894 | debug("FAT%d, fat_sect: %d, fatlength: %d\n", |
| 895 | mydata->fatsize, mydata->fat_sect, mydata->fatlength); |
| 896 | debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n" |
| 897 | "Data begins at: %d\n", |
| 898 | root_cluster, |
| 899 | mydata->rootdir_sect, |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 900 | mydata->rootdir_sect * mydata->sect_size, mydata->data_begin); |
| 901 | debug("Sector size: %d, cluster size: %d\n", mydata->sect_size, |
| 902 | mydata->clust_size); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 903 | |
| 904 | /* "cwd" is always the root... */ |
| 905 | while (ISDIRDELIM(*filename)) |
| 906 | filename++; |
| 907 | |
| 908 | /* Make a copy of the filename and convert it to lowercase */ |
| 909 | strcpy(fnamecopy, filename); |
| 910 | downcase(fnamecopy); |
| 911 | |
| 912 | if (*fnamecopy == '\0') { |
| 913 | if (!dols) |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 914 | goto exit; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 915 | |
| 916 | dols = LS_ROOT; |
| 917 | } else if ((idx = dirdelim(fnamecopy)) >= 0) { |
| 918 | isdir = 1; |
| 919 | fnamecopy[idx] = '\0'; |
| 920 | subname = fnamecopy + idx + 1; |
| 921 | |
| 922 | /* Handle multiple delimiters */ |
| 923 | while (ISDIRDELIM(*subname)) |
| 924 | subname++; |
| 925 | } else if (dols) { |
| 926 | isdir = 1; |
| 927 | } |
| 928 | |
| 929 | j = 0; |
| 930 | while (1) { |
| 931 | int i; |
| 932 | |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 933 | if (j == 0) { |
| 934 | debug("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%zd\n", |
| 935 | cursect, mydata->clust_size, DIRENTSPERBLOCK); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 936 | |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 937 | if (disk_read(cursect, |
| 938 | (mydata->fatsize == 32) ? |
| 939 | (mydata->clust_size) : |
| 940 | PREFETCH_BLOCKS, |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 941 | do_fat_read_at_block) < 0) { |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 942 | debug("Error: reading rootdir block\n"); |
| 943 | goto exit; |
| 944 | } |
| 945 | |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 946 | dentptr = (dir_entry *) do_fat_read_at_block; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 947 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 948 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 949 | for (i = 0; i < DIRENTSPERBLOCK; i++) { |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 950 | char s_name[14], l_name[VFAT_MAXLEN_BYTES]; |
Marek Vasut | ff04f6d | 2012-10-09 07:20:22 +0000 | [diff] [blame] | 951 | __u8 csum; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 952 | |
| 953 | l_name[0] = '\0'; |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 954 | if (dentptr->name[0] == DELETED_FLAG) { |
| 955 | dentptr++; |
| 956 | continue; |
| 957 | } |
Marek Vasut | ff04f6d | 2012-10-09 07:20:22 +0000 | [diff] [blame] | 958 | |
| 959 | csum = mkcksum(dentptr->name, dentptr->ext); |
| 960 | if (dentptr->attr & ATTR_VOLUME) { |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 961 | #ifdef CONFIG_SUPPORT_VFAT |
J. Vijayanand | 206d68f | 2011-10-19 07:43:08 +0000 | [diff] [blame] | 962 | if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT && |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 963 | (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) { |
| 964 | prevcksum = |
| 965 | ((dir_slot *)dentptr)->alias_checksum; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 966 | |
Mikhail Zolotaryov | 3831530 | 2010-09-08 17:06:03 +0300 | [diff] [blame] | 967 | get_vfatname(mydata, |
Sergei Shtylyov | 40e2191 | 2011-08-19 09:32:34 +0000 | [diff] [blame] | 968 | root_cluster, |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 969 | do_fat_read_at_block, |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 970 | dentptr, l_name); |
| 971 | |
| 972 | if (dols == LS_ROOT) { |
| 973 | char dirc; |
| 974 | int doit = 0; |
| 975 | int isdir = |
| 976 | (dentptr->attr & ATTR_DIR); |
| 977 | |
| 978 | if (isdir) { |
| 979 | dirs++; |
| 980 | dirc = '/'; |
| 981 | doit = 1; |
| 982 | } else { |
| 983 | dirc = ' '; |
| 984 | if (l_name[0] != 0) { |
| 985 | files++; |
| 986 | doit = 1; |
| 987 | } |
| 988 | } |
| 989 | if (doit) { |
| 990 | if (dirc == ' ') { |
| 991 | printf(" %8ld %s%c\n", |
| 992 | (long)FAT2CPU32(dentptr->size), |
| 993 | l_name, |
| 994 | dirc); |
| 995 | } else { |
| 996 | printf(" %s%c\n", |
| 997 | l_name, |
| 998 | dirc); |
| 999 | } |
| 1000 | } |
| 1001 | dentptr++; |
| 1002 | continue; |
| 1003 | } |
| 1004 | debug("Rootvfatname: |%s|\n", |
| 1005 | l_name); |
| 1006 | } else |
| 1007 | #endif |
| 1008 | { |
| 1009 | /* Volume label or VFAT entry */ |
| 1010 | dentptr++; |
| 1011 | continue; |
| 1012 | } |
| 1013 | } else if (dentptr->name[0] == 0) { |
| 1014 | debug("RootDentname == NULL - %d\n", i); |
| 1015 | if (dols == LS_ROOT) { |
| 1016 | printf("\n%d file(s), %d dir(s)\n\n", |
| 1017 | files, dirs); |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 1018 | ret = 0; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1019 | } |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 1020 | goto exit; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1021 | } |
| 1022 | #ifdef CONFIG_SUPPORT_VFAT |
Marek Vasut | ff04f6d | 2012-10-09 07:20:22 +0000 | [diff] [blame] | 1023 | else if (dols == LS_ROOT && csum == prevcksum) { |
Sergei Shtylyov | bf34e7d | 2012-01-02 06:54:29 +0000 | [diff] [blame] | 1024 | prevcksum = 0xffff; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1025 | dentptr++; |
| 1026 | continue; |
| 1027 | } |
| 1028 | #endif |
| 1029 | get_name(dentptr, s_name); |
| 1030 | |
| 1031 | if (dols == LS_ROOT) { |
| 1032 | int isdir = (dentptr->attr & ATTR_DIR); |
| 1033 | char dirc; |
| 1034 | int doit = 0; |
| 1035 | |
| 1036 | if (isdir) { |
| 1037 | dirc = '/'; |
| 1038 | if (s_name[0] != 0) { |
| 1039 | dirs++; |
| 1040 | doit = 1; |
| 1041 | } |
| 1042 | } else { |
| 1043 | dirc = ' '; |
| 1044 | if (s_name[0] != 0) { |
| 1045 | files++; |
| 1046 | doit = 1; |
| 1047 | } |
| 1048 | } |
| 1049 | if (doit) { |
| 1050 | if (dirc == ' ') { |
| 1051 | printf(" %8ld %s%c\n", |
| 1052 | (long)FAT2CPU32(dentptr->size), |
| 1053 | s_name, dirc); |
| 1054 | } else { |
| 1055 | printf(" %s%c\n", |
| 1056 | s_name, dirc); |
| 1057 | } |
| 1058 | } |
| 1059 | dentptr++; |
| 1060 | continue; |
| 1061 | } |
| 1062 | |
| 1063 | if (strcmp(fnamecopy, s_name) |
| 1064 | && strcmp(fnamecopy, l_name)) { |
| 1065 | debug("RootMismatch: |%s|%s|\n", s_name, |
| 1066 | l_name); |
| 1067 | dentptr++; |
| 1068 | continue; |
| 1069 | } |
| 1070 | |
| 1071 | if (isdir && !(dentptr->attr & ATTR_DIR)) |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 1072 | goto exit; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1073 | |
| 1074 | debug("RootName: %s", s_name); |
| 1075 | debug(", start: 0x%x", START(dentptr)); |
| 1076 | debug(", size: 0x%x %s\n", |
| 1077 | FAT2CPU32(dentptr->size), |
| 1078 | isdir ? "(DIR)" : ""); |
| 1079 | |
| 1080 | goto rootdir_done; /* We got a match */ |
| 1081 | } |
| 1082 | debug("END LOOP: j=%d clust_size=%d\n", j, |
| 1083 | mydata->clust_size); |
| 1084 | |
| 1085 | /* |
| 1086 | * On FAT32 we must fetch the FAT entries for the next |
| 1087 | * root directory clusters when a cluster has been |
| 1088 | * completely processed. |
| 1089 | */ |
Erik Hansen | 3f270f4 | 2011-03-24 10:15:37 +0100 | [diff] [blame] | 1090 | ++j; |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 1091 | int rootdir_end = 0; |
| 1092 | if (mydata->fatsize == 32) { |
| 1093 | if (j == mydata->clust_size) { |
| 1094 | int nxtsect = 0; |
| 1095 | int nxt_clust = 0; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1096 | |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 1097 | nxt_clust = get_fatent(mydata, root_cluster); |
| 1098 | rootdir_end = CHECK_CLUST(nxt_clust, 32); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1099 | |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 1100 | nxtsect = mydata->data_begin + |
| 1101 | (nxt_clust * mydata->clust_size); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1102 | |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 1103 | root_cluster = nxt_clust; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1104 | |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 1105 | cursect = nxtsect; |
| 1106 | j = 0; |
| 1107 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1108 | } else { |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 1109 | if (j == PREFETCH_BLOCKS) |
| 1110 | j = 0; |
| 1111 | |
| 1112 | rootdir_end = (++cursect - mydata->rootdir_sect >= |
| 1113 | rootdir_size); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1114 | } |
Erik Hansen | 3f270f4 | 2011-03-24 10:15:37 +0100 | [diff] [blame] | 1115 | |
| 1116 | /* If end of rootdir reached */ |
Benoît Thébaudeau | cd1b042 | 2012-07-20 15:20:12 +0200 | [diff] [blame] | 1117 | if (rootdir_end) { |
Erik Hansen | 3f270f4 | 2011-03-24 10:15:37 +0100 | [diff] [blame] | 1118 | if (dols == LS_ROOT) { |
| 1119 | printf("\n%d file(s), %d dir(s)\n\n", |
| 1120 | files, dirs); |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 1121 | ret = 0; |
Erik Hansen | 3f270f4 | 2011-03-24 10:15:37 +0100 | [diff] [blame] | 1122 | } |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 1123 | goto exit; |
Erik Hansen | 3f270f4 | 2011-03-24 10:15:37 +0100 | [diff] [blame] | 1124 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1125 | } |
| 1126 | rootdir_done: |
| 1127 | |
| 1128 | firsttime = 1; |
| 1129 | |
| 1130 | while (isdir) { |
| 1131 | int startsect = mydata->data_begin |
| 1132 | + START(dentptr) * mydata->clust_size; |
| 1133 | dir_entry dent; |
| 1134 | char *nextname = NULL; |
| 1135 | |
| 1136 | dent = *dentptr; |
| 1137 | dentptr = &dent; |
| 1138 | |
| 1139 | idx = dirdelim(subname); |
| 1140 | |
| 1141 | if (idx >= 0) { |
| 1142 | subname[idx] = '\0'; |
| 1143 | nextname = subname + idx + 1; |
| 1144 | /* Handle multiple delimiters */ |
| 1145 | while (ISDIRDELIM(*nextname)) |
| 1146 | nextname++; |
| 1147 | if (dols && *nextname == '\0') |
| 1148 | firsttime = 0; |
| 1149 | } else { |
| 1150 | if (dols && firsttime) { |
| 1151 | firsttime = 0; |
| 1152 | } else { |
| 1153 | isdir = 0; |
| 1154 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1155 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1156 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1157 | if (get_dentfromdir(mydata, startsect, subname, dentptr, |
| 1158 | isdir ? 0 : dols) == NULL) { |
| 1159 | if (dols && !isdir) |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 1160 | ret = 0; |
| 1161 | goto exit; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1162 | } |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1163 | |
Benoît Thébaudeau | 7ee46ce | 2012-07-20 03:20:29 +0000 | [diff] [blame] | 1164 | if (isdir && !(dentptr->attr & ATTR_DIR)) |
| 1165 | goto exit; |
| 1166 | |
| 1167 | if (idx >= 0) |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1168 | subname = nextname; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 1171 | ret = get_contents(mydata, dentptr, pos, buffer, maxsize); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1172 | debug("Size: %d, got: %ld\n", FAT2CPU32(dentptr->size), ret); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1173 | |
Sergei Shtylyov | ac49777 | 2011-08-08 09:38:33 +0000 | [diff] [blame] | 1174 | exit: |
| 1175 | free(mydata->fatbuf); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1176 | return ret; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1177 | } |
| 1178 | |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 1179 | long |
| 1180 | do_fat_read(const char *filename, void *buffer, unsigned long maxsize, int dols) |
| 1181 | { |
| 1182 | return do_fat_read_at(filename, 0, buffer, maxsize, dols); |
| 1183 | } |
| 1184 | |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 1185 | int file_fat_detectfs(void) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1186 | { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1187 | boot_sector bs; |
| 1188 | volume_info volinfo; |
| 1189 | int fatsize; |
| 1190 | char vol_label[12]; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1191 | |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1192 | if (cur_dev == NULL) { |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 1193 | printf("No current device\n"); |
| 1194 | return 1; |
| 1195 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1196 | |
Jon Loeliger | dd60d12 | 2007-07-09 17:56:50 -0500 | [diff] [blame] | 1197 | #if defined(CONFIG_CMD_IDE) || \ |
Sonic Zhang | 8c5170a | 2008-12-09 23:20:18 -0500 | [diff] [blame] | 1198 | defined(CONFIG_CMD_SATA) || \ |
Jon Loeliger | dd60d12 | 2007-07-09 17:56:50 -0500 | [diff] [blame] | 1199 | defined(CONFIG_CMD_SCSI) || \ |
| 1200 | defined(CONFIG_CMD_USB) || \ |
Andy Fleming | 21f6f96 | 2008-01-16 13:06:59 -0600 | [diff] [blame] | 1201 | defined(CONFIG_MMC) |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 1202 | printf("Interface: "); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1203 | switch (cur_dev->if_type) { |
| 1204 | case IF_TYPE_IDE: |
| 1205 | printf("IDE"); |
| 1206 | break; |
| 1207 | case IF_TYPE_SATA: |
| 1208 | printf("SATA"); |
| 1209 | break; |
| 1210 | case IF_TYPE_SCSI: |
| 1211 | printf("SCSI"); |
| 1212 | break; |
| 1213 | case IF_TYPE_ATAPI: |
| 1214 | printf("ATAPI"); |
| 1215 | break; |
| 1216 | case IF_TYPE_USB: |
| 1217 | printf("USB"); |
| 1218 | break; |
| 1219 | case IF_TYPE_DOC: |
| 1220 | printf("DOC"); |
| 1221 | break; |
| 1222 | case IF_TYPE_MMC: |
| 1223 | printf("MMC"); |
| 1224 | break; |
| 1225 | default: |
| 1226 | printf("Unknown"); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 1227 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1228 | |
| 1229 | printf("\n Device %d: ", cur_dev->dev); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 1230 | dev_print(cur_dev); |
| 1231 | #endif |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1232 | |
| 1233 | if (read_bootsectandvi(&bs, &volinfo, &fatsize)) { |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 1234 | printf("\nNo valid FAT fs found\n"); |
| 1235 | return 1; |
| 1236 | } |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1237 | |
| 1238 | memcpy(vol_label, volinfo.volume_label, 11); |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 1239 | vol_label[11] = '\0'; |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1240 | volinfo.fs_type[5] = '\0'; |
| 1241 | |
Stephen Warren | 461f86e | 2012-10-17 06:44:57 +0000 | [diff] [blame] | 1242 | printf("Filesystem: %s \"%s\"\n", volinfo.fs_type, vol_label); |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1243 | |
wdenk | 7205e40 | 2003-09-10 22:30:53 +0000 | [diff] [blame] | 1244 | return 0; |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
Benoît Thébaudeau | 9795e07 | 2012-07-20 15:18:44 +0200 | [diff] [blame] | 1247 | int file_fat_ls(const char *dir) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1248 | { |
| 1249 | return do_fat_read(dir, NULL, 0, LS_YES); |
| 1250 | } |
| 1251 | |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 1252 | long file_fat_read_at(const char *filename, unsigned long pos, void *buffer, |
| 1253 | unsigned long maxsize) |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1254 | { |
Wolfgang Denk | 7385c28 | 2010-07-19 11:37:00 +0200 | [diff] [blame] | 1255 | printf("reading %s\n", filename); |
Benoît Thébaudeau | 1170e63 | 2012-09-18 08:14:56 +0000 | [diff] [blame] | 1256 | return do_fat_read_at(filename, pos, buffer, maxsize, LS_NO); |
| 1257 | } |
| 1258 | |
| 1259 | long file_fat_read(const char *filename, void *buffer, unsigned long maxsize) |
| 1260 | { |
| 1261 | return file_fat_read_at(filename, 0, buffer, maxsize); |
wdenk | 71f9511 | 2003-06-15 22:40:42 +0000 | [diff] [blame] | 1262 | } |