4 * R/O (V)FAT 12/16/32 filesystem implementation by Marcus Sundberg
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
9 * See file CREDITS for list of people who contributed to this
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.
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.
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,
32 #include <asm/byteorder.h>
36 * Convert a string to lowercase.
38 static void downcase (char *str)
40 while (*str != '\0') {
46 static block_dev_desc_t *cur_dev = NULL;
48 static unsigned long part_offset = 0;
49 static unsigned long part_size;
51 static int cur_part = 1;
53 #define DOS_PART_TBL_OFFSET 0x1be
54 #define DOS_PART_MAGIC_OFFSET 0x1fe
55 #define DOS_FS_TYPE_OFFSET 0x36
56 #define DOS_FS32_TYPE_OFFSET 0x52
58 static int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr)
63 startblock += part_offset;
65 if (cur_dev->block_read) {
66 return cur_dev->block_read(cur_dev->dev, startblock, getsize,
67 (unsigned long *) bufptr);
72 int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
74 unsigned char buffer[dev_desc->blksz];
75 disk_partition_t info;
77 if (!dev_desc->block_read)
81 /* check if we have a MBR (on floppies we have only a PBR) */
82 if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)buffer) != 1) {
83 printf("** Can't read from device %d **\n",
87 if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
88 buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) {
89 /* no signature found */
92 #if (defined(CONFIG_CMD_IDE) || \
93 defined(CONFIG_CMD_MG_DISK) || \
94 defined(CONFIG_CMD_SATA) || \
95 defined(CONFIG_CMD_SCSI) || \
96 defined(CONFIG_CMD_USB) || \
97 defined(CONFIG_MMC) || \
98 defined(CONFIG_SYSTEMACE) )
99 /* First we assume there is a MBR */
100 if (!get_partition_info(dev_desc, part_no, &info)) {
101 part_offset = info.start;
103 part_size = info.size;
104 } else if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) ||
105 (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET], "FAT32", 5) == 0)) {
106 /* ok, we assume we are on a PBR only */
110 printf("** Partition %d not valid on device %d **\n",
111 part_no, dev_desc->dev);
116 if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) ||
117 (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET], "FAT32", 5) == 0)) {
118 /* ok, we assume we are on a PBR only */
121 info.start = part_offset;
123 /* FIXME we need to determine the start block of the
124 * partition where the DOS FS resides. This can be done
125 * by using the get_partition_info routine. For this
126 * purpose the libpart must be included.
136 * Get the first occurence of a directory delimiter ('/' or '\') in a string.
137 * Return index into string if found, -1 otherwise.
139 static int dirdelim (char *str)
143 while (*str != '\0') {
144 if (ISDIRDELIM(*str))
152 * Extract zero terminated short name from a directory entry.
154 static void get_name (dir_entry *dirent, char *s_name)
158 memcpy(s_name, dirent->name, 8);
161 while (*ptr && *ptr != ' ')
163 if (dirent->ext[0] && dirent->ext[0] != ' ') {
166 memcpy(ptr, dirent->ext, 3);
168 while (*ptr && *ptr != ' ')
172 if (*s_name == DELETED_FLAG)
174 else if (*s_name == aRING)
175 *s_name = DELETED_FLAG;
180 * Get the entry at index 'entry' in a FAT (12/16/32) table.
181 * On failure 0x00 is returned.
183 static __u32 get_fatent (fsdata *mydata, __u32 entry)
190 switch (mydata->fatsize) {
192 bufnum = entry / FAT32BUFSIZE;
193 offset = entry - bufnum * FAT32BUFSIZE;
196 bufnum = entry / FAT16BUFSIZE;
197 offset = entry - bufnum * FAT16BUFSIZE;
200 bufnum = entry / FAT12BUFSIZE;
201 offset = entry - bufnum * FAT12BUFSIZE;
205 /* Unsupported FAT size */
209 debug("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n",
210 mydata->fatsize, entry, entry, offset, offset);
212 /* Read a new block of FAT entries into the cache. */
213 if (bufnum != mydata->fatbufnum) {
214 __u32 getsize = FATBUFBLOCKS;
215 __u8 *bufptr = mydata->fatbuf;
216 __u32 fatlength = mydata->fatlength;
217 __u32 startblock = bufnum * FATBUFBLOCKS;
219 if (getsize > fatlength)
222 fatlength *= mydata->sect_size; /* We want it in bytes now */
223 startblock += mydata->fat_sect; /* Offset from start of disk */
225 if (disk_read(startblock, getsize, bufptr) < 0) {
226 debug("Error reading FAT blocks\n");
229 mydata->fatbufnum = bufnum;
232 /* Get the actual entry from the table */
233 switch (mydata->fatsize) {
235 ret = FAT2CPU32(((__u32 *) mydata->fatbuf)[offset]);
238 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]);
241 off16 = (offset * 3) / 4;
243 switch (offset & 0x3) {
245 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[off16]);
249 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
251 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
253 ret = (val2 << 4) | (val1 >> 12);
256 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
258 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
260 ret = (val2 << 8) | (val1 >> 8);
263 ret = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
264 ret = (ret & 0xfff0) >> 4;
271 debug("FAT%d: ret: %08x, offset: %04x\n",
272 mydata->fatsize, ret, offset);
278 * Read at most 'size' bytes from the specified cluster into 'buffer'.
279 * Return 0 on success, -1 otherwise.
282 get_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
289 startsect = mydata->data_begin +
290 clustnum * mydata->clust_size;
292 startsect = mydata->rootdir_sect;
295 debug("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
297 if (disk_read(startsect, size / mydata->sect_size, buffer) < 0) {
298 debug("Error reading data\n");
301 if (size % mydata->sect_size) {
302 __u8 tmpbuf[mydata->sect_size];
304 idx = size / mydata->sect_size;
305 if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
306 debug("Error reading data\n");
309 buffer += idx * mydata->sect_size;
311 memcpy(buffer, tmpbuf, size % mydata->sect_size);
319 * Read at most 'maxsize' bytes from the file associated with 'dentptr'
321 * Return the number of bytes read or -1 on fatal errors.
324 get_contents (fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
325 unsigned long maxsize)
327 unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
328 unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
329 __u32 curclust = START(dentptr);
330 __u32 endclust, newclust;
331 unsigned long actsize;
333 debug("Filesize: %ld bytes\n", filesize);
335 if (maxsize > 0 && filesize > maxsize)
338 debug("%ld bytes\n", filesize);
340 actsize = bytesperclust;
344 /* search for consecutive clusters */
345 while (actsize < filesize) {
346 newclust = get_fatent(mydata, endclust);
347 if ((newclust - 1) != endclust)
349 if (CHECK_CLUST(newclust, mydata->fatsize)) {
350 debug("curclust: 0x%x\n", newclust);
351 debug("Invalid FAT entry\n");
355 actsize += bytesperclust;
358 /* actsize >= file size */
359 actsize -= bytesperclust;
361 /* get remaining clusters */
362 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
363 printf("Error reading cluster\n");
367 /* get remaining bytes */
368 gotsize += (int)actsize;
372 if (get_cluster(mydata, endclust, buffer, (int)actsize) != 0) {
373 printf("Error reading cluster\n");
379 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
380 printf("Error reading cluster\n");
383 gotsize += (int)actsize;
387 curclust = get_fatent(mydata, endclust);
388 if (CHECK_CLUST(curclust, mydata->fatsize)) {
389 debug("curclust: 0x%x\n", curclust);
390 printf("Invalid FAT entry\n");
393 actsize = bytesperclust;
398 #ifdef CONFIG_SUPPORT_VFAT
400 * Extract the file name information from 'slotptr' into 'l_name',
401 * starting at l_name[*idx].
402 * Return 1 if terminator (zero byte) is found, 0 otherwise.
404 static int slot2str (dir_slot *slotptr, char *l_name, int *idx)
408 for (j = 0; j <= 8; j += 2) {
409 l_name[*idx] = slotptr->name0_4[j];
410 if (l_name[*idx] == 0x00)
414 for (j = 0; j <= 10; j += 2) {
415 l_name[*idx] = slotptr->name5_10[j];
416 if (l_name[*idx] == 0x00)
420 for (j = 0; j <= 2; j += 2) {
421 l_name[*idx] = slotptr->name11_12[j];
422 if (l_name[*idx] == 0x00)
431 * Extract the full long filename starting at 'retdent' (which is really
432 * a slot) into 'l_name'. If successful also copy the real directory entry
434 * Return 0 on success, -1 otherwise.
436 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
437 __u8 get_vfatname_block[MAX_CLUSTSIZE];
440 get_vfatname (fsdata *mydata, int curclust, __u8 *cluster,
441 dir_entry *retdent, char *l_name)
444 dir_slot *slotptr = (dir_slot *)retdent;
445 __u8 *buflimit = cluster + mydata->sect_size * ((curclust == 0) ?
448 __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
451 if (counter > VFAT_MAXSEQ) {
452 debug("Error: VFAT name is too long\n");
456 while ((__u8 *)slotptr < buflimit) {
459 if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter)
465 if ((__u8 *)slotptr >= buflimit) {
470 curclust = get_fatent(mydata, curclust);
471 if (CHECK_CLUST(curclust, mydata->fatsize)) {
472 debug("curclust: 0x%x\n", curclust);
473 printf("Invalid FAT entry\n");
477 if (get_cluster(mydata, curclust, get_vfatname_block,
478 mydata->clust_size * mydata->sect_size) != 0) {
479 debug("Error: reading directory block\n");
483 slotptr2 = (dir_slot *)get_vfatname_block;
484 while (counter > 0) {
485 if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK)
492 /* Save the real directory entry */
493 realdent = (dir_entry *)slotptr2;
494 while ((__u8 *)slotptr2 > get_vfatname_block) {
496 slot2str(slotptr2, l_name, &idx);
499 /* Save the real directory entry */
500 realdent = (dir_entry *)slotptr;
505 if (slot2str(slotptr, l_name, &idx))
507 } while (!(slotptr->id & LAST_LONG_ENTRY_MASK));
510 if (*l_name == DELETED_FLAG)
512 else if (*l_name == aRING)
513 *l_name = DELETED_FLAG;
516 /* Return the real directory entry */
517 memcpy(retdent, realdent, sizeof(dir_entry));
522 /* Calculate short name checksum */
523 static __u8 mkcksum (const char *str)
529 for (i = 0; i < 11; i++) {
530 ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + str[i];
535 #endif /* CONFIG_SUPPORT_VFAT */
538 * Get the directory entry associated with 'filename' from the directory
539 * starting at 'startsect'
541 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
542 __u8 get_dentfromdir_block[MAX_CLUSTSIZE];
544 static dir_entry *get_dentfromdir (fsdata *mydata, int startsect,
545 char *filename, dir_entry *retdent,
548 __u16 prevcksum = 0xffff;
549 __u32 curclust = START(retdent);
550 int files = 0, dirs = 0;
552 debug("get_dentfromdir: %s\n", filename);
559 if (get_cluster(mydata, curclust, get_dentfromdir_block,
560 mydata->clust_size * mydata->sect_size) != 0) {
561 debug("Error: reading directory block\n");
565 dentptr = (dir_entry *)get_dentfromdir_block;
567 for (i = 0; i < DIRENTSPERCLUST; i++) {
568 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
571 if (dentptr->name[0] == DELETED_FLAG) {
575 if ((dentptr->attr & ATTR_VOLUME)) {
576 #ifdef CONFIG_SUPPORT_VFAT
577 if ((dentptr->attr & ATTR_VFAT) &&
578 (dentptr-> name[0] & LAST_LONG_ENTRY_MASK)) {
579 prevcksum = ((dir_slot *)dentptr)->alias_checksum;
580 get_vfatname(mydata, curclust,
581 get_dentfromdir_block,
588 isdir = (dentptr->attr & ATTR_DIR);
596 if (l_name[0] != 0) {
603 printf(" %8ld %s%c\n",
604 (long)FAT2CPU32(dentptr->size),
616 debug("vfatname: |%s|\n", l_name);
620 /* Volume label or VFAT entry */
625 if (dentptr->name[0] == 0) {
627 printf("\n%d file(s), %d dir(s)\n\n",
630 debug("Dentname == NULL - %d\n", i);
633 #ifdef CONFIG_SUPPORT_VFAT
634 if (dols && mkcksum(dentptr->name) == prevcksum) {
639 get_name(dentptr, s_name);
641 int isdir = (dentptr->attr & ATTR_DIR);
651 if (s_name[0] != 0) {
659 printf(" %8ld %s%c\n",
660 (long)FAT2CPU32(dentptr->size),
672 if (strcmp(filename, s_name)
673 && strcmp(filename, l_name)) {
674 debug("Mismatch: |%s|%s|\n", s_name, l_name);
679 memcpy(retdent, dentptr, sizeof(dir_entry));
681 debug("DentName: %s", s_name);
682 debug(", start: 0x%x", START(dentptr));
683 debug(", size: 0x%x %s\n",
684 FAT2CPU32(dentptr->size),
685 (dentptr->attr & ATTR_DIR) ? "(DIR)" : "");
690 curclust = get_fatent(mydata, curclust);
691 if (CHECK_CLUST(curclust, mydata->fatsize)) {
692 debug("curclust: 0x%x\n", curclust);
693 printf("Invalid FAT entry\n");
702 * Read boot sector and volume info from a FAT filesystem
705 read_bootsectandvi (boot_sector *bs, volume_info *volinfo, int *fatsize)
708 volume_info *vistart;
711 if (cur_dev == NULL) {
712 debug("Error: no device selected\n");
716 block = malloc(cur_dev->blksz);
718 debug("Error: allocating block\n");
722 if (disk_read (0, 1, block) < 0) {
723 debug("Error: reading block\n");
727 memcpy(bs, block, sizeof(boot_sector));
728 bs->reserved = FAT2CPU16(bs->reserved);
729 bs->fat_length = FAT2CPU16(bs->fat_length);
730 bs->secs_track = FAT2CPU16(bs->secs_track);
731 bs->heads = FAT2CPU16(bs->heads);
732 bs->total_sect = FAT2CPU32(bs->total_sect);
735 if (bs->fat_length == 0) {
737 bs->fat32_length = FAT2CPU32(bs->fat32_length);
738 bs->flags = FAT2CPU16(bs->flags);
739 bs->root_cluster = FAT2CPU32(bs->root_cluster);
740 bs->info_sector = FAT2CPU16(bs->info_sector);
741 bs->backup_boot = FAT2CPU16(bs->backup_boot);
742 vistart = (volume_info *)(block + sizeof(boot_sector));
745 vistart = (volume_info *)&(bs->fat32_length);
748 memcpy(volinfo, vistart, sizeof(volume_info));
750 if (*fatsize == 32) {
751 if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0)
754 if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
758 if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
764 debug("Error: broken fs_type sign\n");
772 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
773 __u8 do_fat_read_block[MAX_CLUSTSIZE];
776 do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
779 char fnamecopy[2048];
783 fsdata *mydata = &datablock;
785 __u16 prevcksum = 0xffff;
789 int files = 0, dirs = 0;
792 __u32 root_cluster = 0;
793 int rootdir_size = 0;
796 if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
797 debug("Error: reading boot sector\n");
801 if (mydata->fatsize == 32) {
802 root_cluster = bs.root_cluster;
803 mydata->fatlength = bs.fat32_length;
805 mydata->fatlength = bs.fat_length;
808 mydata->fat_sect = bs.reserved;
810 cursect = mydata->rootdir_sect
811 = mydata->fat_sect + mydata->fatlength * bs.fats;
813 mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0];
814 mydata->clust_size = bs.cluster_size;
816 if (mydata->fatsize == 32) {
817 mydata->data_begin = mydata->rootdir_sect -
818 (mydata->clust_size * 2);
820 rootdir_size = ((bs.dir_entries[1] * (int)256 +
824 mydata->data_begin = mydata->rootdir_sect +
826 (mydata->clust_size * 2);
829 mydata->fatbufnum = -1;
830 mydata->fatbuf = malloc(FATBUFSIZE);
831 if (mydata->fatbuf == NULL) {
832 debug("Error: allocating memory\n");
836 #ifdef CONFIG_SUPPORT_VFAT
837 debug("VFAT Support enabled\n");
839 debug("FAT%d, fat_sect: %d, fatlength: %d\n",
840 mydata->fatsize, mydata->fat_sect, mydata->fatlength);
841 debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
842 "Data begins at: %d\n",
844 mydata->rootdir_sect,
845 mydata->rootdir_sect * mydata->sect_size, mydata->data_begin);
846 debug("Sector size: %d, cluster size: %d\n", mydata->sect_size,
849 /* "cwd" is always the root... */
850 while (ISDIRDELIM(*filename))
853 /* Make a copy of the filename and convert it to lowercase */
854 strcpy(fnamecopy, filename);
857 if (*fnamecopy == '\0') {
862 } else if ((idx = dirdelim(fnamecopy)) >= 0) {
864 fnamecopy[idx] = '\0';
865 subname = fnamecopy + idx + 1;
867 /* Handle multiple delimiters */
868 while (ISDIRDELIM(*subname))
878 debug("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%d\n",
879 cursect, mydata->clust_size, DIRENTSPERBLOCK);
881 if (disk_read(cursect,
882 (mydata->fatsize == 32) ?
883 (mydata->clust_size) :
885 do_fat_read_block) < 0) {
886 debug("Error: reading rootdir block\n");
890 dentptr = (dir_entry *) do_fat_read_block;
892 for (i = 0; i < DIRENTSPERBLOCK; i++) {
893 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
896 if (dentptr->name[0] == DELETED_FLAG) {
900 if ((dentptr->attr & ATTR_VOLUME)) {
901 #ifdef CONFIG_SUPPORT_VFAT
902 if ((dentptr->attr & ATTR_VFAT) &&
903 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
905 ((dir_slot *)dentptr)->alias_checksum;
912 if (dols == LS_ROOT) {
916 (dentptr->attr & ATTR_DIR);
924 if (l_name[0] != 0) {
931 printf(" %8ld %s%c\n",
932 (long)FAT2CPU32(dentptr->size),
944 debug("Rootvfatname: |%s|\n",
949 /* Volume label or VFAT entry */
953 } else if (dentptr->name[0] == 0) {
954 debug("RootDentname == NULL - %d\n", i);
955 if (dols == LS_ROOT) {
956 printf("\n%d file(s), %d dir(s)\n\n",
962 #ifdef CONFIG_SUPPORT_VFAT
963 else if (dols == LS_ROOT &&
964 mkcksum(dentptr->name) == prevcksum) {
969 get_name(dentptr, s_name);
971 if (dols == LS_ROOT) {
972 int isdir = (dentptr->attr & ATTR_DIR);
978 if (s_name[0] != 0) {
984 if (s_name[0] != 0) {
991 printf(" %8ld %s%c\n",
992 (long)FAT2CPU32(dentptr->size),
1003 if (strcmp(fnamecopy, s_name)
1004 && strcmp(fnamecopy, l_name)) {
1005 debug("RootMismatch: |%s|%s|\n", s_name,
1011 if (isdir && !(dentptr->attr & ATTR_DIR))
1014 debug("RootName: %s", s_name);
1015 debug(", start: 0x%x", START(dentptr));
1016 debug(", size: 0x%x %s\n",
1017 FAT2CPU32(dentptr->size),
1018 isdir ? "(DIR)" : "");
1020 goto rootdir_done; /* We got a match */
1022 debug("END LOOP: j=%d clust_size=%d\n", j,
1023 mydata->clust_size);
1026 * On FAT32 we must fetch the FAT entries for the next
1027 * root directory clusters when a cluster has been
1028 * completely processed.
1032 if ((mydata->fatsize == 32) && (j == mydata->clust_size)) {
1036 nxt_clust = get_fatent(mydata, root_cluster);
1037 fat32_end = CHECK_CLUST(nxt_clust, 32);
1039 nxtsect = mydata->data_begin +
1040 (nxt_clust * mydata->clust_size);
1042 root_cluster = nxt_clust;
1050 /* If end of rootdir reached */
1051 if ((mydata->fatsize == 32 && fat32_end) ||
1052 (mydata->fatsize != 32 && j == rootdir_size)) {
1053 if (dols == LS_ROOT) {
1054 printf("\n%d file(s), %d dir(s)\n\n",
1066 int startsect = mydata->data_begin
1067 + START(dentptr) * mydata->clust_size;
1069 char *nextname = NULL;
1074 idx = dirdelim(subname);
1077 subname[idx] = '\0';
1078 nextname = subname + idx + 1;
1079 /* Handle multiple delimiters */
1080 while (ISDIRDELIM(*nextname))
1082 if (dols && *nextname == '\0')
1085 if (dols && firsttime) {
1092 if (get_dentfromdir(mydata, startsect, subname, dentptr,
1093 isdir ? 0 : dols) == NULL) {
1100 if (!(dentptr->attr & ATTR_DIR))
1106 ret = get_contents(mydata, dentptr, buffer, maxsize);
1107 debug("Size: %d, got: %ld\n", FAT2CPU32(dentptr->size), ret);
1110 free(mydata->fatbuf);
1114 int file_fat_detectfs (void)
1117 volume_info volinfo;
1121 if (cur_dev == NULL) {
1122 printf("No current device\n");
1126 #if defined(CONFIG_CMD_IDE) || \
1127 defined(CONFIG_CMD_MG_DISK) || \
1128 defined(CONFIG_CMD_SATA) || \
1129 defined(CONFIG_CMD_SCSI) || \
1130 defined(CONFIG_CMD_USB) || \
1132 printf("Interface: ");
1133 switch (cur_dev->if_type) {
1159 printf("\n Device %d: ", cur_dev->dev);
1163 if (read_bootsectandvi(&bs, &volinfo, &fatsize)) {
1164 printf("\nNo valid FAT fs found\n");
1168 memcpy(vol_label, volinfo.volume_label, 11);
1169 vol_label[11] = '\0';
1170 volinfo.fs_type[5] = '\0';
1172 printf("Partition %d: Filesystem: %s \"%s\"\n", cur_part,
1173 volinfo.fs_type, vol_label);
1178 int file_fat_ls (const char *dir)
1180 return do_fat_read(dir, NULL, 0, LS_YES);
1183 long file_fat_read (const char *filename, void *buffer, unsigned long maxsize)
1185 printf("reading %s\n", filename);
1186 return do_fat_read(filename, buffer, maxsize, LS_NO);