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;
50 static int cur_part = 1;
52 #define DOS_PART_TBL_OFFSET 0x1be
53 #define DOS_PART_MAGIC_OFFSET 0x1fe
54 #define DOS_FS_TYPE_OFFSET 0x36
55 #define DOS_FS32_TYPE_OFFSET 0x52
57 static int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr)
62 startblock += part_offset;
64 if (cur_dev->block_read) {
65 return cur_dev->block_read(cur_dev->dev, startblock, getsize,
66 (unsigned long *) bufptr);
71 int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
73 unsigned char buffer[dev_desc->blksz];
75 if (!dev_desc->block_read)
79 /* check if we have a MBR (on floppies we have only a PBR) */
80 if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)buffer) != 1) {
81 printf("** Can't read from device %d **\n",
85 if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
86 buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) {
87 /* no signature found */
90 #if (defined(CONFIG_CMD_IDE) || \
91 defined(CONFIG_CMD_MG_DISK) || \
92 defined(CONFIG_CMD_SATA) || \
93 defined(CONFIG_CMD_SCSI) || \
94 defined(CONFIG_CMD_USB) || \
95 defined(CONFIG_MMC) || \
96 defined(CONFIG_SYSTEMACE) )
98 disk_partition_t info;
100 /* First we assume there is a MBR */
101 if (!get_partition_info(dev_desc, part_no, &info)) {
102 part_offset = info.start;
104 } else if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET],
106 (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET],
108 /* ok, we assume we are on a PBR only */
112 printf("** Partition %d not valid on device %d **\n",
113 part_no, dev_desc->dev);
118 if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) ||
119 (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET], "FAT32", 5) == 0)) {
120 /* ok, we assume we are on a PBR only */
124 /* FIXME we need to determine the start block of the
125 * partition where the DOS FS resides. This can be done
126 * by using the get_partition_info routine. For this
127 * purpose the libpart must be included.
137 * Get the first occurence of a directory delimiter ('/' or '\') in a string.
138 * Return index into string if found, -1 otherwise.
140 static int dirdelim (char *str)
144 while (*str != '\0') {
145 if (ISDIRDELIM(*str))
153 * Extract zero terminated short name from a directory entry.
155 static void get_name (dir_entry *dirent, char *s_name)
159 memcpy(s_name, dirent->name, 8);
162 while (*ptr && *ptr != ' ')
164 if (dirent->ext[0] && dirent->ext[0] != ' ') {
167 memcpy(ptr, dirent->ext, 3);
169 while (*ptr && *ptr != ' ')
173 if (*s_name == DELETED_FLAG)
175 else if (*s_name == aRING)
176 *s_name = DELETED_FLAG;
181 * Get the entry at index 'entry' in a FAT (12/16/32) table.
182 * On failure 0x00 is returned.
184 static __u32 get_fatent (fsdata *mydata, __u32 entry)
191 switch (mydata->fatsize) {
193 bufnum = entry / FAT32BUFSIZE;
194 offset = entry - bufnum * FAT32BUFSIZE;
197 bufnum = entry / FAT16BUFSIZE;
198 offset = entry - bufnum * FAT16BUFSIZE;
201 bufnum = entry / FAT12BUFSIZE;
202 offset = entry - bufnum * FAT12BUFSIZE;
206 /* Unsupported FAT size */
210 debug("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n",
211 mydata->fatsize, entry, entry, offset, offset);
213 /* Read a new block of FAT entries into the cache. */
214 if (bufnum != mydata->fatbufnum) {
215 __u32 getsize = FATBUFBLOCKS;
216 __u8 *bufptr = mydata->fatbuf;
217 __u32 fatlength = mydata->fatlength;
218 __u32 startblock = bufnum * FATBUFBLOCKS;
220 if (getsize > fatlength)
223 fatlength *= mydata->sect_size; /* We want it in bytes now */
224 startblock += mydata->fat_sect; /* Offset from start of disk */
226 if (disk_read(startblock, getsize, bufptr) < 0) {
227 debug("Error reading FAT blocks\n");
230 mydata->fatbufnum = bufnum;
233 /* Get the actual entry from the table */
234 switch (mydata->fatsize) {
236 ret = FAT2CPU32(((__u32 *) mydata->fatbuf)[offset]);
239 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]);
242 off16 = (offset * 3) / 4;
244 switch (offset & 0x3) {
246 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[off16]);
250 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
252 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
254 ret = (val2 << 4) | (val1 >> 12);
257 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
259 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
261 ret = (val2 << 8) | (val1 >> 8);
264 ret = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
265 ret = (ret & 0xfff0) >> 4;
272 debug("FAT%d: ret: %08x, offset: %04x\n",
273 mydata->fatsize, ret, offset);
279 * Read at most 'size' bytes from the specified cluster into 'buffer'.
280 * Return 0 on success, -1 otherwise.
283 get_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
290 startsect = mydata->data_begin +
291 clustnum * mydata->clust_size;
293 startsect = mydata->rootdir_sect;
296 debug("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
298 if (disk_read(startsect, size / mydata->sect_size, buffer) < 0) {
299 debug("Error reading data\n");
302 if (size % mydata->sect_size) {
303 __u8 tmpbuf[mydata->sect_size];
305 idx = size / mydata->sect_size;
306 if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
307 debug("Error reading data\n");
310 buffer += idx * mydata->sect_size;
312 memcpy(buffer, tmpbuf, size % mydata->sect_size);
320 * Read at most 'maxsize' bytes from the file associated with 'dentptr'
322 * Return the number of bytes read or -1 on fatal errors.
325 get_contents (fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
326 unsigned long maxsize)
328 unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
329 unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
330 __u32 curclust = START(dentptr);
331 __u32 endclust, newclust;
332 unsigned long actsize;
334 debug("Filesize: %ld bytes\n", filesize);
336 if (maxsize > 0 && filesize > maxsize)
339 debug("%ld bytes\n", filesize);
341 actsize = bytesperclust;
345 /* search for consecutive clusters */
346 while (actsize < filesize) {
347 newclust = get_fatent(mydata, endclust);
348 if ((newclust - 1) != endclust)
350 if (CHECK_CLUST(newclust, mydata->fatsize)) {
351 debug("curclust: 0x%x\n", newclust);
352 debug("Invalid FAT entry\n");
356 actsize += bytesperclust;
359 /* actsize >= file size */
360 actsize -= bytesperclust;
362 /* get remaining clusters */
363 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
364 printf("Error reading cluster\n");
368 /* get remaining bytes */
369 gotsize += (int)actsize;
373 if (get_cluster(mydata, endclust, buffer, (int)actsize) != 0) {
374 printf("Error reading cluster\n");
380 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
381 printf("Error reading cluster\n");
384 gotsize += (int)actsize;
388 curclust = get_fatent(mydata, endclust);
389 if (CHECK_CLUST(curclust, mydata->fatsize)) {
390 debug("curclust: 0x%x\n", curclust);
391 printf("Invalid FAT entry\n");
394 actsize = bytesperclust;
399 #ifdef CONFIG_SUPPORT_VFAT
401 * Extract the file name information from 'slotptr' into 'l_name',
402 * starting at l_name[*idx].
403 * Return 1 if terminator (zero byte) is found, 0 otherwise.
405 static int slot2str (dir_slot *slotptr, char *l_name, int *idx)
409 for (j = 0; j <= 8; j += 2) {
410 l_name[*idx] = slotptr->name0_4[j];
411 if (l_name[*idx] == 0x00)
415 for (j = 0; j <= 10; j += 2) {
416 l_name[*idx] = slotptr->name5_10[j];
417 if (l_name[*idx] == 0x00)
421 for (j = 0; j <= 2; j += 2) {
422 l_name[*idx] = slotptr->name11_12[j];
423 if (l_name[*idx] == 0x00)
432 * Extract the full long filename starting at 'retdent' (which is really
433 * a slot) into 'l_name'. If successful also copy the real directory entry
435 * Return 0 on success, -1 otherwise.
437 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
438 __u8 get_vfatname_block[MAX_CLUSTSIZE];
441 get_vfatname (fsdata *mydata, int curclust, __u8 *cluster,
442 dir_entry *retdent, char *l_name)
445 dir_slot *slotptr = (dir_slot *)retdent;
446 __u8 *buflimit = cluster + mydata->sect_size * ((curclust == 0) ?
449 __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
452 if (counter > VFAT_MAXSEQ) {
453 debug("Error: VFAT name is too long\n");
457 while ((__u8 *)slotptr < buflimit) {
460 if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter)
466 if ((__u8 *)slotptr >= buflimit) {
471 curclust = get_fatent(mydata, curclust);
472 if (CHECK_CLUST(curclust, mydata->fatsize)) {
473 debug("curclust: 0x%x\n", curclust);
474 printf("Invalid FAT entry\n");
478 if (get_cluster(mydata, curclust, get_vfatname_block,
479 mydata->clust_size * mydata->sect_size) != 0) {
480 debug("Error: reading directory block\n");
484 slotptr2 = (dir_slot *)get_vfatname_block;
485 while (counter > 0) {
486 if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK)
493 /* Save the real directory entry */
494 realdent = (dir_entry *)slotptr2;
495 while ((__u8 *)slotptr2 > get_vfatname_block) {
497 slot2str(slotptr2, l_name, &idx);
500 /* Save the real directory entry */
501 realdent = (dir_entry *)slotptr;
506 if (slot2str(slotptr, l_name, &idx))
508 } while (!(slotptr->id & LAST_LONG_ENTRY_MASK));
511 if (*l_name == DELETED_FLAG)
513 else if (*l_name == aRING)
514 *l_name = DELETED_FLAG;
517 /* Return the real directory entry */
518 memcpy(retdent, realdent, sizeof(dir_entry));
523 /* Calculate short name checksum */
524 static __u8 mkcksum (const char *str)
530 for (i = 0; i < 11; i++) {
531 ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + str[i];
536 #endif /* CONFIG_SUPPORT_VFAT */
539 * Get the directory entry associated with 'filename' from the directory
540 * starting at 'startsect'
542 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
543 __u8 get_dentfromdir_block[MAX_CLUSTSIZE];
545 static dir_entry *get_dentfromdir (fsdata *mydata, int startsect,
546 char *filename, dir_entry *retdent,
549 __u16 prevcksum = 0xffff;
550 __u32 curclust = START(retdent);
551 int files = 0, dirs = 0;
553 debug("get_dentfromdir: %s\n", filename);
560 if (get_cluster(mydata, curclust, get_dentfromdir_block,
561 mydata->clust_size * mydata->sect_size) != 0) {
562 debug("Error: reading directory block\n");
566 dentptr = (dir_entry *)get_dentfromdir_block;
568 for (i = 0; i < DIRENTSPERCLUST; i++) {
569 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
572 if (dentptr->name[0] == DELETED_FLAG) {
576 if ((dentptr->attr & ATTR_VOLUME)) {
577 #ifdef CONFIG_SUPPORT_VFAT
578 if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
579 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
580 prevcksum = ((dir_slot *)dentptr)->alias_checksum;
581 get_vfatname(mydata, curclust,
582 get_dentfromdir_block,
589 isdir = (dentptr->attr & ATTR_DIR);
597 if (l_name[0] != 0) {
604 printf(" %8ld %s%c\n",
605 (long)FAT2CPU32(dentptr->size),
617 debug("vfatname: |%s|\n", l_name);
621 /* Volume label or VFAT entry */
626 if (dentptr->name[0] == 0) {
628 printf("\n%d file(s), %d dir(s)\n\n",
631 debug("Dentname == NULL - %d\n", i);
634 #ifdef CONFIG_SUPPORT_VFAT
635 if (dols && mkcksum(dentptr->name) == prevcksum) {
640 get_name(dentptr, s_name);
642 int isdir = (dentptr->attr & ATTR_DIR);
652 if (s_name[0] != 0) {
660 printf(" %8ld %s%c\n",
661 (long)FAT2CPU32(dentptr->size),
673 if (strcmp(filename, s_name)
674 && strcmp(filename, l_name)) {
675 debug("Mismatch: |%s|%s|\n", s_name, l_name);
680 memcpy(retdent, dentptr, sizeof(dir_entry));
682 debug("DentName: %s", s_name);
683 debug(", start: 0x%x", START(dentptr));
684 debug(", size: 0x%x %s\n",
685 FAT2CPU32(dentptr->size),
686 (dentptr->attr & ATTR_DIR) ? "(DIR)" : "");
691 curclust = get_fatent(mydata, curclust);
692 if (CHECK_CLUST(curclust, mydata->fatsize)) {
693 debug("curclust: 0x%x\n", curclust);
694 printf("Invalid FAT entry\n");
703 * Read boot sector and volume info from a FAT filesystem
706 read_bootsectandvi (boot_sector *bs, volume_info *volinfo, int *fatsize)
709 volume_info *vistart;
712 if (cur_dev == NULL) {
713 debug("Error: no device selected\n");
717 block = malloc(cur_dev->blksz);
719 debug("Error: allocating block\n");
723 if (disk_read (0, 1, block) < 0) {
724 debug("Error: reading block\n");
728 memcpy(bs, block, sizeof(boot_sector));
729 bs->reserved = FAT2CPU16(bs->reserved);
730 bs->fat_length = FAT2CPU16(bs->fat_length);
731 bs->secs_track = FAT2CPU16(bs->secs_track);
732 bs->heads = FAT2CPU16(bs->heads);
733 bs->total_sect = FAT2CPU32(bs->total_sect);
736 if (bs->fat_length == 0) {
738 bs->fat32_length = FAT2CPU32(bs->fat32_length);
739 bs->flags = FAT2CPU16(bs->flags);
740 bs->root_cluster = FAT2CPU32(bs->root_cluster);
741 bs->info_sector = FAT2CPU16(bs->info_sector);
742 bs->backup_boot = FAT2CPU16(bs->backup_boot);
743 vistart = (volume_info *)(block + sizeof(boot_sector));
746 vistart = (volume_info *)&(bs->fat32_length);
749 memcpy(volinfo, vistart, sizeof(volume_info));
751 if (*fatsize == 32) {
752 if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0)
755 if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
759 if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
765 debug("Error: broken fs_type sign\n");
773 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
774 __u8 do_fat_read_block[MAX_CLUSTSIZE];
777 do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
780 char fnamecopy[2048];
784 fsdata *mydata = &datablock;
786 __u16 prevcksum = 0xffff;
790 int files = 0, dirs = 0;
793 __u32 root_cluster = 0;
794 int rootdir_size = 0;
797 if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
798 debug("Error: reading boot sector\n");
802 if (mydata->fatsize == 32) {
803 root_cluster = bs.root_cluster;
804 mydata->fatlength = bs.fat32_length;
806 mydata->fatlength = bs.fat_length;
809 mydata->fat_sect = bs.reserved;
811 cursect = mydata->rootdir_sect
812 = mydata->fat_sect + mydata->fatlength * bs.fats;
814 mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0];
815 mydata->clust_size = bs.cluster_size;
817 if (mydata->fatsize == 32) {
818 mydata->data_begin = mydata->rootdir_sect -
819 (mydata->clust_size * 2);
821 rootdir_size = ((bs.dir_entries[1] * (int)256 +
825 mydata->data_begin = mydata->rootdir_sect +
827 (mydata->clust_size * 2);
830 mydata->fatbufnum = -1;
831 mydata->fatbuf = malloc(FATBUFSIZE);
832 if (mydata->fatbuf == NULL) {
833 debug("Error: allocating memory\n");
837 #ifdef CONFIG_SUPPORT_VFAT
838 debug("VFAT Support enabled\n");
840 debug("FAT%d, fat_sect: %d, fatlength: %d\n",
841 mydata->fatsize, mydata->fat_sect, mydata->fatlength);
842 debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
843 "Data begins at: %d\n",
845 mydata->rootdir_sect,
846 mydata->rootdir_sect * mydata->sect_size, mydata->data_begin);
847 debug("Sector size: %d, cluster size: %d\n", mydata->sect_size,
850 /* "cwd" is always the root... */
851 while (ISDIRDELIM(*filename))
854 /* Make a copy of the filename and convert it to lowercase */
855 strcpy(fnamecopy, filename);
858 if (*fnamecopy == '\0') {
863 } else if ((idx = dirdelim(fnamecopy)) >= 0) {
865 fnamecopy[idx] = '\0';
866 subname = fnamecopy + idx + 1;
868 /* Handle multiple delimiters */
869 while (ISDIRDELIM(*subname))
879 debug("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%d\n",
880 cursect, mydata->clust_size, DIRENTSPERBLOCK);
882 if (disk_read(cursect,
883 (mydata->fatsize == 32) ?
884 (mydata->clust_size) :
886 do_fat_read_block) < 0) {
887 debug("Error: reading rootdir block\n");
891 dentptr = (dir_entry *) do_fat_read_block;
893 for (i = 0; i < DIRENTSPERBLOCK; i++) {
894 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
897 if (dentptr->name[0] == DELETED_FLAG) {
901 if ((dentptr->attr & ATTR_VOLUME)) {
902 #ifdef CONFIG_SUPPORT_VFAT
903 if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
904 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
906 ((dir_slot *)dentptr)->alias_checksum;
913 if (dols == LS_ROOT) {
917 (dentptr->attr & ATTR_DIR);
925 if (l_name[0] != 0) {
932 printf(" %8ld %s%c\n",
933 (long)FAT2CPU32(dentptr->size),
945 debug("Rootvfatname: |%s|\n",
950 /* Volume label or VFAT entry */
954 } else if (dentptr->name[0] == 0) {
955 debug("RootDentname == NULL - %d\n", i);
956 if (dols == LS_ROOT) {
957 printf("\n%d file(s), %d dir(s)\n\n",
963 #ifdef CONFIG_SUPPORT_VFAT
964 else if (dols == LS_ROOT &&
965 mkcksum(dentptr->name) == prevcksum) {
970 get_name(dentptr, s_name);
972 if (dols == LS_ROOT) {
973 int isdir = (dentptr->attr & ATTR_DIR);
979 if (s_name[0] != 0) {
985 if (s_name[0] != 0) {
992 printf(" %8ld %s%c\n",
993 (long)FAT2CPU32(dentptr->size),
1004 if (strcmp(fnamecopy, s_name)
1005 && strcmp(fnamecopy, l_name)) {
1006 debug("RootMismatch: |%s|%s|\n", s_name,
1012 if (isdir && !(dentptr->attr & ATTR_DIR))
1015 debug("RootName: %s", s_name);
1016 debug(", start: 0x%x", START(dentptr));
1017 debug(", size: 0x%x %s\n",
1018 FAT2CPU32(dentptr->size),
1019 isdir ? "(DIR)" : "");
1021 goto rootdir_done; /* We got a match */
1023 debug("END LOOP: j=%d clust_size=%d\n", j,
1024 mydata->clust_size);
1027 * On FAT32 we must fetch the FAT entries for the next
1028 * root directory clusters when a cluster has been
1029 * completely processed.
1033 if ((mydata->fatsize == 32) && (j == mydata->clust_size)) {
1037 nxt_clust = get_fatent(mydata, root_cluster);
1038 fat32_end = CHECK_CLUST(nxt_clust, 32);
1040 nxtsect = mydata->data_begin +
1041 (nxt_clust * mydata->clust_size);
1043 root_cluster = nxt_clust;
1051 /* If end of rootdir reached */
1052 if ((mydata->fatsize == 32 && fat32_end) ||
1053 (mydata->fatsize != 32 && j == rootdir_size)) {
1054 if (dols == LS_ROOT) {
1055 printf("\n%d file(s), %d dir(s)\n\n",
1067 int startsect = mydata->data_begin
1068 + START(dentptr) * mydata->clust_size;
1070 char *nextname = NULL;
1075 idx = dirdelim(subname);
1078 subname[idx] = '\0';
1079 nextname = subname + idx + 1;
1080 /* Handle multiple delimiters */
1081 while (ISDIRDELIM(*nextname))
1083 if (dols && *nextname == '\0')
1086 if (dols && firsttime) {
1093 if (get_dentfromdir(mydata, startsect, subname, dentptr,
1094 isdir ? 0 : dols) == NULL) {
1101 if (!(dentptr->attr & ATTR_DIR))
1107 ret = get_contents(mydata, dentptr, buffer, maxsize);
1108 debug("Size: %d, got: %ld\n", FAT2CPU32(dentptr->size), ret);
1111 free(mydata->fatbuf);
1115 int file_fat_detectfs (void)
1118 volume_info volinfo;
1122 if (cur_dev == NULL) {
1123 printf("No current device\n");
1127 #if defined(CONFIG_CMD_IDE) || \
1128 defined(CONFIG_CMD_MG_DISK) || \
1129 defined(CONFIG_CMD_SATA) || \
1130 defined(CONFIG_CMD_SCSI) || \
1131 defined(CONFIG_CMD_USB) || \
1133 printf("Interface: ");
1134 switch (cur_dev->if_type) {
1160 printf("\n Device %d: ", cur_dev->dev);
1164 if (read_bootsectandvi(&bs, &volinfo, &fatsize)) {
1165 printf("\nNo valid FAT fs found\n");
1169 memcpy(vol_label, volinfo.volume_label, 11);
1170 vol_label[11] = '\0';
1171 volinfo.fs_type[5] = '\0';
1173 printf("Partition %d: Filesystem: %s \"%s\"\n", cur_part,
1174 volinfo.fs_type, vol_label);
1179 int file_fat_ls (const char *dir)
1181 return do_fat_read(dir, NULL, 0, LS_YES);
1184 long file_fat_read (const char *filename, void *buffer, unsigned long maxsize)
1186 printf("reading %s\n", filename);
1187 return do_fat_read(filename, buffer, maxsize, LS_NO);