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];
74 disk_partition_t info;
76 if (!dev_desc->block_read)
80 /* check if we have a MBR (on floppies we have only a PBR) */
81 if (dev_desc->block_read(dev_desc->dev, 0, 1, (ulong *)buffer) != 1) {
82 printf("** Can't read from device %d **\n",
86 if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
87 buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) {
88 /* no signature found */
91 #if (defined(CONFIG_CMD_IDE) || \
92 defined(CONFIG_CMD_MG_DISK) || \
93 defined(CONFIG_CMD_SATA) || \
94 defined(CONFIG_CMD_SCSI) || \
95 defined(CONFIG_CMD_USB) || \
96 defined(CONFIG_MMC) || \
97 defined(CONFIG_SYSTEMACE) )
98 /* First we assume there is a MBR */
99 if (!get_partition_info(dev_desc, part_no, &info)) {
100 part_offset = info.start;
102 } else if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) ||
103 (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET], "FAT32", 5) == 0)) {
104 /* ok, we assume we are on a PBR only */
108 printf("** Partition %d not valid on device %d **\n",
109 part_no, dev_desc->dev);
114 if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) ||
115 (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET], "FAT32", 5) == 0)) {
116 /* ok, we assume we are on a PBR only */
119 info.start = part_offset;
121 /* FIXME we need to determine the start block of the
122 * partition where the DOS FS resides. This can be done
123 * by using the get_partition_info routine. For this
124 * purpose the libpart must be included.
134 * Get the first occurence of a directory delimiter ('/' or '\') in a string.
135 * Return index into string if found, -1 otherwise.
137 static int dirdelim (char *str)
141 while (*str != '\0') {
142 if (ISDIRDELIM(*str))
150 * Extract zero terminated short name from a directory entry.
152 static void get_name (dir_entry *dirent, char *s_name)
156 memcpy(s_name, dirent->name, 8);
159 while (*ptr && *ptr != ' ')
161 if (dirent->ext[0] && dirent->ext[0] != ' ') {
164 memcpy(ptr, dirent->ext, 3);
166 while (*ptr && *ptr != ' ')
170 if (*s_name == DELETED_FLAG)
172 else if (*s_name == aRING)
173 *s_name = DELETED_FLAG;
178 * Get the entry at index 'entry' in a FAT (12/16/32) table.
179 * On failure 0x00 is returned.
181 static __u32 get_fatent (fsdata *mydata, __u32 entry)
188 switch (mydata->fatsize) {
190 bufnum = entry / FAT32BUFSIZE;
191 offset = entry - bufnum * FAT32BUFSIZE;
194 bufnum = entry / FAT16BUFSIZE;
195 offset = entry - bufnum * FAT16BUFSIZE;
198 bufnum = entry / FAT12BUFSIZE;
199 offset = entry - bufnum * FAT12BUFSIZE;
203 /* Unsupported FAT size */
207 debug("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n",
208 mydata->fatsize, entry, entry, offset, offset);
210 /* Read a new block of FAT entries into the cache. */
211 if (bufnum != mydata->fatbufnum) {
212 __u32 getsize = FATBUFBLOCKS;
213 __u8 *bufptr = mydata->fatbuf;
214 __u32 fatlength = mydata->fatlength;
215 __u32 startblock = bufnum * FATBUFBLOCKS;
217 if (getsize > fatlength)
220 fatlength *= mydata->sect_size; /* We want it in bytes now */
221 startblock += mydata->fat_sect; /* Offset from start of disk */
223 if (disk_read(startblock, getsize, bufptr) < 0) {
224 debug("Error reading FAT blocks\n");
227 mydata->fatbufnum = bufnum;
230 /* Get the actual entry from the table */
231 switch (mydata->fatsize) {
233 ret = FAT2CPU32(((__u32 *) mydata->fatbuf)[offset]);
236 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]);
239 off16 = (offset * 3) / 4;
241 switch (offset & 0x3) {
243 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[off16]);
247 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
249 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
251 ret = (val2 << 4) | (val1 >> 12);
254 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
256 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
258 ret = (val2 << 8) | (val1 >> 8);
261 ret = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
262 ret = (ret & 0xfff0) >> 4;
269 debug("FAT%d: ret: %08x, offset: %04x\n",
270 mydata->fatsize, ret, offset);
276 * Read at most 'size' bytes from the specified cluster into 'buffer'.
277 * Return 0 on success, -1 otherwise.
280 get_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
287 startsect = mydata->data_begin +
288 clustnum * mydata->clust_size;
290 startsect = mydata->rootdir_sect;
293 debug("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
295 if (disk_read(startsect, size / mydata->sect_size, buffer) < 0) {
296 debug("Error reading data\n");
299 if (size % mydata->sect_size) {
300 __u8 tmpbuf[mydata->sect_size];
302 idx = size / mydata->sect_size;
303 if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
304 debug("Error reading data\n");
307 buffer += idx * mydata->sect_size;
309 memcpy(buffer, tmpbuf, size % mydata->sect_size);
317 * Read at most 'maxsize' bytes from the file associated with 'dentptr'
319 * Return the number of bytes read or -1 on fatal errors.
322 get_contents (fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
323 unsigned long maxsize)
325 unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
326 unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
327 __u32 curclust = START(dentptr);
328 __u32 endclust, newclust;
329 unsigned long actsize;
331 debug("Filesize: %ld bytes\n", filesize);
333 if (maxsize > 0 && filesize > maxsize)
336 debug("%ld bytes\n", filesize);
338 actsize = bytesperclust;
342 /* search for consecutive clusters */
343 while (actsize < filesize) {
344 newclust = get_fatent(mydata, endclust);
345 if ((newclust - 1) != endclust)
347 if (CHECK_CLUST(newclust, mydata->fatsize)) {
348 debug("curclust: 0x%x\n", newclust);
349 debug("Invalid FAT entry\n");
353 actsize += bytesperclust;
356 /* actsize >= file size */
357 actsize -= bytesperclust;
359 /* get remaining clusters */
360 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
361 printf("Error reading cluster\n");
365 /* get remaining bytes */
366 gotsize += (int)actsize;
370 if (get_cluster(mydata, endclust, buffer, (int)actsize) != 0) {
371 printf("Error reading cluster\n");
377 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
378 printf("Error reading cluster\n");
381 gotsize += (int)actsize;
385 curclust = get_fatent(mydata, endclust);
386 if (CHECK_CLUST(curclust, mydata->fatsize)) {
387 debug("curclust: 0x%x\n", curclust);
388 printf("Invalid FAT entry\n");
391 actsize = bytesperclust;
396 #ifdef CONFIG_SUPPORT_VFAT
398 * Extract the file name information from 'slotptr' into 'l_name',
399 * starting at l_name[*idx].
400 * Return 1 if terminator (zero byte) is found, 0 otherwise.
402 static int slot2str (dir_slot *slotptr, char *l_name, int *idx)
406 for (j = 0; j <= 8; j += 2) {
407 l_name[*idx] = slotptr->name0_4[j];
408 if (l_name[*idx] == 0x00)
412 for (j = 0; j <= 10; j += 2) {
413 l_name[*idx] = slotptr->name5_10[j];
414 if (l_name[*idx] == 0x00)
418 for (j = 0; j <= 2; j += 2) {
419 l_name[*idx] = slotptr->name11_12[j];
420 if (l_name[*idx] == 0x00)
429 * Extract the full long filename starting at 'retdent' (which is really
430 * a slot) into 'l_name'. If successful also copy the real directory entry
432 * Return 0 on success, -1 otherwise.
434 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
435 __u8 get_vfatname_block[MAX_CLUSTSIZE];
438 get_vfatname (fsdata *mydata, int curclust, __u8 *cluster,
439 dir_entry *retdent, char *l_name)
442 dir_slot *slotptr = (dir_slot *)retdent;
443 __u8 *buflimit = cluster + ((curclust == 0) ?
444 LINEAR_PREFETCH_SIZE :
445 (mydata->clust_size * mydata->sect_size)
447 __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
450 if (counter > VFAT_MAXSEQ) {
451 debug("Error: VFAT name is too long\n");
455 while ((__u8 *)slotptr < buflimit) {
458 if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter)
464 if ((__u8 *)slotptr >= buflimit) {
469 curclust = get_fatent(mydata, curclust);
470 if (CHECK_CLUST(curclust, mydata->fatsize)) {
471 debug("curclust: 0x%x\n", curclust);
472 printf("Invalid FAT entry\n");
476 if (get_cluster(mydata, curclust, get_vfatname_block,
477 mydata->clust_size * mydata->sect_size) != 0) {
478 debug("Error: reading directory block\n");
482 slotptr2 = (dir_slot *)get_vfatname_block;
483 while (counter > 0) {
484 if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK)
491 /* Save the real directory entry */
492 realdent = (dir_entry *)slotptr2;
493 while ((__u8 *)slotptr2 > get_vfatname_block) {
495 slot2str(slotptr2, l_name, &idx);
498 /* Save the real directory entry */
499 realdent = (dir_entry *)slotptr;
504 if (slot2str(slotptr, l_name, &idx))
506 } while (!(slotptr->id & LAST_LONG_ENTRY_MASK));
509 if (*l_name == DELETED_FLAG)
511 else if (*l_name == aRING)
512 *l_name = DELETED_FLAG;
515 /* Return the real directory entry */
516 memcpy(retdent, realdent, sizeof(dir_entry));
521 /* Calculate short name checksum */
522 static __u8 mkcksum (const char *str)
528 for (i = 0; i < 11; i++) {
529 ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + str[i];
534 #endif /* CONFIG_SUPPORT_VFAT */
537 * Get the directory entry associated with 'filename' from the directory
538 * starting at 'startsect'
540 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
541 __u8 get_dentfromdir_block[MAX_CLUSTSIZE];
543 static dir_entry *get_dentfromdir (fsdata *mydata, int startsect,
544 char *filename, dir_entry *retdent,
547 __u16 prevcksum = 0xffff;
548 __u32 curclust = START(retdent);
549 int files = 0, dirs = 0;
551 debug("get_dentfromdir: %s\n", filename);
558 if (get_cluster(mydata, curclust, get_dentfromdir_block,
559 mydata->clust_size * mydata->sect_size) != 0) {
560 debug("Error: reading directory block\n");
564 dentptr = (dir_entry *)get_dentfromdir_block;
566 for (i = 0; i < DIRENTSPERCLUST; i++) {
567 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
570 if (dentptr->name[0] == DELETED_FLAG) {
574 if ((dentptr->attr & ATTR_VOLUME)) {
575 #ifdef CONFIG_SUPPORT_VFAT
576 if ((dentptr->attr & ATTR_VFAT) &&
577 (dentptr-> name[0] & LAST_LONG_ENTRY_MASK)) {
578 prevcksum = ((dir_slot *)dentptr)->alias_checksum;
579 get_vfatname(mydata, curclust,
580 get_dentfromdir_block,
587 isdir = (dentptr->attr & ATTR_DIR);
595 if (l_name[0] != 0) {
602 printf(" %8ld %s%c\n",
603 (long)FAT2CPU32(dentptr->size),
615 debug("vfatname: |%s|\n", l_name);
619 /* Volume label or VFAT entry */
624 if (dentptr->name[0] == 0) {
626 printf("\n%d file(s), %d dir(s)\n\n",
629 debug("Dentname == NULL - %d\n", i);
632 #ifdef CONFIG_SUPPORT_VFAT
633 if (dols && mkcksum(dentptr->name) == prevcksum) {
638 get_name(dentptr, s_name);
640 int isdir = (dentptr->attr & ATTR_DIR);
650 if (s_name[0] != 0) {
658 printf(" %8ld %s%c\n",
659 (long)FAT2CPU32(dentptr->size),
671 if (strcmp(filename, s_name)
672 && strcmp(filename, l_name)) {
673 debug("Mismatch: |%s|%s|\n", s_name, l_name);
678 memcpy(retdent, dentptr, sizeof(dir_entry));
680 debug("DentName: %s", s_name);
681 debug(", start: 0x%x", START(dentptr));
682 debug(", size: 0x%x %s\n",
683 FAT2CPU32(dentptr->size),
684 (dentptr->attr & ATTR_DIR) ? "(DIR)" : "");
689 curclust = get_fatent(mydata, curclust);
690 if (CHECK_CLUST(curclust, mydata->fatsize)) {
691 debug("curclust: 0x%x\n", curclust);
692 printf("Invalid FAT entry\n");
701 * Read boot sector and volume info from a FAT filesystem
704 read_bootsectandvi (boot_sector *bs, volume_info *volinfo, int *fatsize)
707 volume_info *vistart;
710 if (cur_dev == NULL) {
711 debug("Error: no device selected\n");
715 block = malloc(cur_dev->blksz);
717 debug("Error: allocating block\n");
721 if (disk_read (0, 1, block) < 0) {
722 debug("Error: reading block\n");
726 memcpy(bs, block, sizeof(boot_sector));
727 bs->reserved = FAT2CPU16(bs->reserved);
728 bs->fat_length = FAT2CPU16(bs->fat_length);
729 bs->secs_track = FAT2CPU16(bs->secs_track);
730 bs->heads = FAT2CPU16(bs->heads);
731 bs->total_sect = FAT2CPU32(bs->total_sect);
734 if (bs->fat_length == 0) {
736 bs->fat32_length = FAT2CPU32(bs->fat32_length);
737 bs->flags = FAT2CPU16(bs->flags);
738 bs->root_cluster = FAT2CPU32(bs->root_cluster);
739 bs->info_sector = FAT2CPU16(bs->info_sector);
740 bs->backup_boot = FAT2CPU16(bs->backup_boot);
741 vistart = (volume_info *)(block + sizeof(boot_sector));
744 vistart = (volume_info *)&(bs->fat32_length);
747 memcpy(volinfo, vistart, sizeof(volume_info));
749 if (*fatsize == 32) {
750 if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0)
753 if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
757 if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
763 debug("Error: broken fs_type sign\n");
771 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
772 __u8 do_fat_read_block[MAX_CLUSTSIZE];
775 do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
778 char fnamecopy[2048];
782 fsdata *mydata = &datablock;
784 __u16 prevcksum = 0xffff;
788 int files = 0, dirs = 0;
792 int rootdir_size = 0;
795 if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
796 debug("Error: reading boot sector\n");
800 root_cluster = bs.root_cluster;
802 if (mydata->fatsize == 32)
803 mydata->fatlength = bs.fat32_length;
805 mydata->fatlength = bs.fat_length;
807 mydata->fat_sect = bs.reserved;
809 cursect = mydata->rootdir_sect
810 = mydata->fat_sect + mydata->fatlength * bs.fats;
812 mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0];
813 mydata->clust_size = bs.cluster_size;
815 if (mydata->fatsize == 32) {
816 mydata->data_begin = mydata->rootdir_sect -
817 (mydata->clust_size * 2);
819 rootdir_size = ((bs.dir_entries[1] * (int)256 +
823 mydata->data_begin = mydata->rootdir_sect +
825 (mydata->clust_size * 2);
828 mydata->fatbufnum = -1;
829 mydata->fatbuf = malloc(FATBUFSIZE);
830 if (mydata->fatbuf == NULL) {
831 debug("Error: allocating memory\n");
835 #ifdef CONFIG_SUPPORT_VFAT
836 debug("VFAT Support enabled\n");
838 debug("FAT%d, fat_sect: %d, fatlength: %d\n",
839 mydata->fatsize, mydata->fat_sect, mydata->fatlength);
840 debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
841 "Data begins at: %d\n",
843 mydata->rootdir_sect,
844 mydata->rootdir_sect * mydata->sect_size, mydata->data_begin);
845 debug("Sector size: %d, cluster size: %d\n", mydata->sect_size,
848 /* "cwd" is always the root... */
849 while (ISDIRDELIM(*filename))
852 /* Make a copy of the filename and convert it to lowercase */
853 strcpy(fnamecopy, filename);
856 if (*fnamecopy == '\0') {
861 } else if ((idx = dirdelim(fnamecopy)) >= 0) {
863 fnamecopy[idx] = '\0';
864 subname = fnamecopy + idx + 1;
866 /* Handle multiple delimiters */
867 while (ISDIRDELIM(*subname))
877 debug("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%d\n",
878 cursect, mydata->clust_size, DIRENTSPERBLOCK);
880 if (disk_read(cursect,
881 (mydata->fatsize == 32) ?
882 (mydata->clust_size) :
883 LINEAR_PREFETCH_SIZE / mydata->sect_size,
884 do_fat_read_block) < 0) {
885 debug("Error: reading rootdir block\n");
889 dentptr = (dir_entry *) do_fat_read_block;
891 for (i = 0; i < DIRENTSPERBLOCK; i++) {
892 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
895 if (dentptr->name[0] == DELETED_FLAG) {
899 if ((dentptr->attr & ATTR_VOLUME)) {
900 #ifdef CONFIG_SUPPORT_VFAT
901 if ((dentptr->attr & ATTR_VFAT) &&
902 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
904 ((dir_slot *)dentptr)->alias_checksum;
907 (mydata->fatsize == 32) ?
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);