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>
35 #include <linux/compiler.h>
38 * Convert a string to lowercase.
40 static void downcase (char *str)
42 while (*str != '\0') {
48 static block_dev_desc_t *cur_dev;
49 static unsigned int cur_part_nr;
50 static disk_partition_t cur_part_info;
52 #define DOS_BOOT_MAGIC_OFFSET 0x1fe
53 #define DOS_FS_TYPE_OFFSET 0x36
54 #define DOS_FS32_TYPE_OFFSET 0x52
56 static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
58 if (!cur_dev || !cur_dev->block_read)
61 return cur_dev->block_read(cur_dev->dev,
62 cur_part_info.start + block, nr_blocks, buf);
65 int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
67 ALLOC_CACHE_ALIGN_BUFFER(unsigned char, buffer, dev_desc->blksz);
69 /* First close any currently found FAT filesystem */
72 #if (defined(CONFIG_CMD_IDE) || \
73 defined(CONFIG_CMD_MG_DISK) || \
74 defined(CONFIG_CMD_SATA) || \
75 defined(CONFIG_CMD_SCSI) || \
76 defined(CONFIG_CMD_USB) || \
77 defined(CONFIG_MMC) || \
78 defined(CONFIG_SYSTEMACE) )
80 /* Read the partition table, if present */
81 if (!get_partition_info(dev_desc, part_no, &cur_part_info)) {
83 cur_part_nr = part_no;
87 /* Otherwise it might be a superfloppy (whole-disk FAT filesystem) */
90 printf("** Partition %d not valid on device %d **\n",
91 part_no, dev_desc->dev);
97 cur_part_info.start = 0;
98 cur_part_info.size = dev_desc->lba;
99 cur_part_info.blksz = dev_desc->blksz;
100 memset(cur_part_info.name, 0, sizeof(cur_part_info.name));
101 memset(cur_part_info.type, 0, sizeof(cur_part_info.type));
104 /* Make sure it has a valid FAT header */
105 if (disk_read(0, 1, buffer) != 1) {
110 /* Check if it's actually a DOS volume */
111 if (memcmp(buffer + DOS_BOOT_MAGIC_OFFSET, "\x55\xAA", 2)) {
116 /* Check for FAT12/FAT16/FAT32 filesystem */
117 if (!memcmp(buffer + DOS_FS_TYPE_OFFSET, "FAT", 3))
119 if (!memcmp(buffer + DOS_FS32_TYPE_OFFSET, "FAT32", 5))
128 * Get the first occurence of a directory delimiter ('/' or '\') in a string.
129 * Return index into string if found, -1 otherwise.
131 static int dirdelim (char *str)
135 while (*str != '\0') {
136 if (ISDIRDELIM(*str))
144 * Extract zero terminated short name from a directory entry.
146 static void get_name (dir_entry *dirent, char *s_name)
150 memcpy(s_name, dirent->name, 8);
153 while (*ptr && *ptr != ' ')
155 if (dirent->ext[0] && dirent->ext[0] != ' ') {
158 memcpy(ptr, dirent->ext, 3);
160 while (*ptr && *ptr != ' ')
164 if (*s_name == DELETED_FLAG)
166 else if (*s_name == aRING)
167 *s_name = DELETED_FLAG;
172 * Get the entry at index 'entry' in a FAT (12/16/32) table.
173 * On failure 0x00 is returned.
175 static __u32 get_fatent (fsdata *mydata, __u32 entry)
182 switch (mydata->fatsize) {
184 bufnum = entry / FAT32BUFSIZE;
185 offset = entry - bufnum * FAT32BUFSIZE;
188 bufnum = entry / FAT16BUFSIZE;
189 offset = entry - bufnum * FAT16BUFSIZE;
192 bufnum = entry / FAT12BUFSIZE;
193 offset = entry - bufnum * FAT12BUFSIZE;
197 /* Unsupported FAT size */
201 debug("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n",
202 mydata->fatsize, entry, entry, offset, offset);
204 /* Read a new block of FAT entries into the cache. */
205 if (bufnum != mydata->fatbufnum) {
206 __u32 getsize = FATBUFBLOCKS;
207 __u8 *bufptr = mydata->fatbuf;
208 __u32 fatlength = mydata->fatlength;
209 __u32 startblock = bufnum * FATBUFBLOCKS;
211 if (getsize > fatlength)
214 fatlength *= mydata->sect_size; /* We want it in bytes now */
215 startblock += mydata->fat_sect; /* Offset from start of disk */
217 if (disk_read(startblock, getsize, bufptr) < 0) {
218 debug("Error reading FAT blocks\n");
221 mydata->fatbufnum = bufnum;
224 /* Get the actual entry from the table */
225 switch (mydata->fatsize) {
227 ret = FAT2CPU32(((__u32 *) mydata->fatbuf)[offset]);
230 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]);
233 off16 = (offset * 3) / 4;
235 switch (offset & 0x3) {
237 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[off16]);
241 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
243 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
245 ret = (val2 << 4) | (val1 >> 12);
248 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
250 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
252 ret = (val2 << 8) | (val1 >> 8);
255 ret = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
256 ret = (ret & 0xfff0) >> 4;
263 debug("FAT%d: ret: %08x, offset: %04x\n",
264 mydata->fatsize, ret, offset);
270 * Read at most 'size' bytes from the specified cluster into 'buffer'.
271 * Return 0 on success, -1 otherwise.
274 get_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
283 startsect = mydata->data_begin +
284 clustnum * mydata->clust_size;
286 startsect = mydata->rootdir_sect;
289 debug("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
291 nr_sect = size / mydata->sect_size;
292 ret = disk_read(startsect, nr_sect, buffer);
293 if (ret != nr_sect) {
294 debug("Error reading data (got %d)\n", ret);
297 if (size % mydata->sect_size) {
298 ALLOC_CACHE_ALIGN_BUFFER(__u8, tmpbuf, mydata->sect_size);
300 idx = size / mydata->sect_size;
301 ret = disk_read(startsect + idx, 1, tmpbuf);
303 debug("Error reading data (got %d)\n", ret);
306 buffer += idx * mydata->sect_size;
308 memcpy(buffer, tmpbuf, size % mydata->sect_size);
316 * Read at most 'maxsize' bytes from the file associated with 'dentptr'
318 * Return the number of bytes read or -1 on fatal errors.
321 get_contents (fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
322 unsigned long maxsize)
324 unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
325 unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
326 __u32 curclust = START(dentptr);
327 __u32 endclust, newclust;
328 unsigned long actsize;
330 debug("Filesize: %ld bytes\n", filesize);
332 if (maxsize > 0 && filesize > maxsize)
335 debug("%ld bytes\n", filesize);
337 actsize = bytesperclust;
341 /* search for consecutive clusters */
342 while (actsize < filesize) {
343 newclust = get_fatent(mydata, endclust);
344 if ((newclust - 1) != endclust)
346 if (CHECK_CLUST(newclust, mydata->fatsize)) {
347 debug("curclust: 0x%x\n", newclust);
348 debug("Invalid FAT entry\n");
352 actsize += bytesperclust;
355 /* actsize >= file size */
356 actsize -= bytesperclust;
358 /* get remaining clusters */
359 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
360 printf("Error reading cluster\n");
364 /* get remaining bytes */
365 gotsize += (int)actsize;
369 if (get_cluster(mydata, endclust, buffer, (int)actsize) != 0) {
370 printf("Error reading cluster\n");
376 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
377 printf("Error reading cluster\n");
380 gotsize += (int)actsize;
384 curclust = get_fatent(mydata, endclust);
385 if (CHECK_CLUST(curclust, mydata->fatsize)) {
386 debug("curclust: 0x%x\n", curclust);
387 printf("Invalid FAT entry\n");
390 actsize = bytesperclust;
395 #ifdef CONFIG_SUPPORT_VFAT
397 * Extract the file name information from 'slotptr' into 'l_name',
398 * starting at l_name[*idx].
399 * Return 1 if terminator (zero byte) is found, 0 otherwise.
401 static int slot2str (dir_slot *slotptr, char *l_name, int *idx)
405 for (j = 0; j <= 8; j += 2) {
406 l_name[*idx] = slotptr->name0_4[j];
407 if (l_name[*idx] == 0x00)
411 for (j = 0; j <= 10; j += 2) {
412 l_name[*idx] = slotptr->name5_10[j];
413 if (l_name[*idx] == 0x00)
417 for (j = 0; j <= 2; j += 2) {
418 l_name[*idx] = slotptr->name11_12[j];
419 if (l_name[*idx] == 0x00)
428 * Extract the full long filename starting at 'retdent' (which is really
429 * a slot) into 'l_name'. If successful also copy the real directory entry
431 * Return 0 on success, -1 otherwise.
433 __u8 get_vfatname_block[MAX_CLUSTSIZE]
434 __aligned(ARCH_DMA_MINALIGN);
437 get_vfatname (fsdata *mydata, int curclust, __u8 *cluster,
438 dir_entry *retdent, char *l_name)
441 dir_slot *slotptr = (dir_slot *)retdent;
442 __u8 *buflimit = cluster + mydata->sect_size * ((curclust == 0) ?
445 __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
448 if (counter > VFAT_MAXSEQ) {
449 debug("Error: VFAT name is too long\n");
453 while ((__u8 *)slotptr < buflimit) {
456 if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter)
462 if ((__u8 *)slotptr >= buflimit) {
467 curclust = get_fatent(mydata, curclust);
468 if (CHECK_CLUST(curclust, mydata->fatsize)) {
469 debug("curclust: 0x%x\n", curclust);
470 printf("Invalid FAT entry\n");
474 if (get_cluster(mydata, curclust, get_vfatname_block,
475 mydata->clust_size * mydata->sect_size) != 0) {
476 debug("Error: reading directory block\n");
480 slotptr2 = (dir_slot *)get_vfatname_block;
481 while (counter > 0) {
482 if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK)
489 /* Save the real directory entry */
490 realdent = (dir_entry *)slotptr2;
491 while ((__u8 *)slotptr2 > get_vfatname_block) {
493 slot2str(slotptr2, l_name, &idx);
496 /* Save the real directory entry */
497 realdent = (dir_entry *)slotptr;
502 if (slot2str(slotptr, l_name, &idx))
504 } while (!(slotptr->id & LAST_LONG_ENTRY_MASK));
507 if (*l_name == DELETED_FLAG)
509 else if (*l_name == aRING)
510 *l_name = DELETED_FLAG;
513 /* Return the real directory entry */
514 memcpy(retdent, realdent, sizeof(dir_entry));
519 /* Calculate short name checksum */
520 static __u8 mkcksum (const char *str)
526 for (i = 0; i < 11; i++) {
527 ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + str[i];
532 #endif /* CONFIG_SUPPORT_VFAT */
535 * Get the directory entry associated with 'filename' from the directory
536 * starting at 'startsect'
538 __u8 get_dentfromdir_block[MAX_CLUSTSIZE]
539 __aligned(ARCH_DMA_MINALIGN);
541 static dir_entry *get_dentfromdir (fsdata *mydata, int startsect,
542 char *filename, dir_entry *retdent,
545 __u16 prevcksum = 0xffff;
546 __u32 curclust = START(retdent);
547 int files = 0, dirs = 0;
549 debug("get_dentfromdir: %s\n", filename);
556 if (get_cluster(mydata, curclust, get_dentfromdir_block,
557 mydata->clust_size * mydata->sect_size) != 0) {
558 debug("Error: reading directory block\n");
562 dentptr = (dir_entry *)get_dentfromdir_block;
564 for (i = 0; i < DIRENTSPERCLUST; i++) {
565 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
568 if (dentptr->name[0] == DELETED_FLAG) {
572 if ((dentptr->attr & ATTR_VOLUME)) {
573 #ifdef CONFIG_SUPPORT_VFAT
574 if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
575 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
576 prevcksum = ((dir_slot *)dentptr)->alias_checksum;
577 get_vfatname(mydata, curclust,
578 get_dentfromdir_block,
585 isdir = (dentptr->attr & ATTR_DIR);
593 if (l_name[0] != 0) {
600 printf(" %8ld %s%c\n",
601 (long)FAT2CPU32(dentptr->size),
613 debug("vfatname: |%s|\n", l_name);
617 /* Volume label or VFAT entry */
622 if (dentptr->name[0] == 0) {
624 printf("\n%d file(s), %d dir(s)\n\n",
627 debug("Dentname == NULL - %d\n", i);
630 #ifdef CONFIG_SUPPORT_VFAT
631 if (dols && mkcksum(dentptr->name) == prevcksum) {
637 get_name(dentptr, s_name);
639 int isdir = (dentptr->attr & ATTR_DIR);
649 if (s_name[0] != 0) {
657 printf(" %8ld %s%c\n",
658 (long)FAT2CPU32(dentptr->size),
670 if (strcmp(filename, s_name)
671 && strcmp(filename, l_name)) {
672 debug("Mismatch: |%s|%s|\n", s_name, l_name);
677 memcpy(retdent, dentptr, sizeof(dir_entry));
679 debug("DentName: %s", s_name);
680 debug(", start: 0x%x", START(dentptr));
681 debug(", size: 0x%x %s\n",
682 FAT2CPU32(dentptr->size),
683 (dentptr->attr & ATTR_DIR) ? "(DIR)" : "");
688 curclust = get_fatent(mydata, curclust);
689 if (CHECK_CLUST(curclust, mydata->fatsize)) {
690 debug("curclust: 0x%x\n", curclust);
691 printf("Invalid FAT entry\n");
700 * Read boot sector and volume info from a FAT filesystem
703 read_bootsectandvi (boot_sector *bs, volume_info *volinfo, int *fatsize)
706 volume_info *vistart;
709 if (cur_dev == NULL) {
710 debug("Error: no device selected\n");
714 block = memalign(ARCH_DMA_MINALIGN, cur_dev->blksz);
716 debug("Error: allocating block\n");
720 if (disk_read (0, 1, block) < 0) {
721 debug("Error: reading block\n");
725 memcpy(bs, block, sizeof(boot_sector));
726 bs->reserved = FAT2CPU16(bs->reserved);
727 bs->fat_length = FAT2CPU16(bs->fat_length);
728 bs->secs_track = FAT2CPU16(bs->secs_track);
729 bs->heads = FAT2CPU16(bs->heads);
730 bs->total_sect = FAT2CPU32(bs->total_sect);
733 if (bs->fat_length == 0) {
735 bs->fat32_length = FAT2CPU32(bs->fat32_length);
736 bs->flags = FAT2CPU16(bs->flags);
737 bs->root_cluster = FAT2CPU32(bs->root_cluster);
738 bs->info_sector = FAT2CPU16(bs->info_sector);
739 bs->backup_boot = FAT2CPU16(bs->backup_boot);
740 vistart = (volume_info *)(block + sizeof(boot_sector));
743 vistart = (volume_info *)&(bs->fat32_length);
746 memcpy(volinfo, vistart, sizeof(volume_info));
748 if (*fatsize == 32) {
749 if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0)
752 if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
756 if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
762 debug("Error: broken fs_type sign\n");
770 __u8 do_fat_read_block[MAX_CLUSTSIZE]
771 __aligned(ARCH_DMA_MINALIGN);
774 do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
777 char fnamecopy[2048];
781 fsdata *mydata = &datablock;
783 __u16 prevcksum = 0xffff;
787 int files = 0, dirs = 0;
790 __u32 root_cluster = 0;
791 int rootdir_size = 0;
794 if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
795 debug("Error: reading boot sector\n");
799 if (mydata->fatsize == 32) {
800 root_cluster = bs.root_cluster;
801 mydata->fatlength = bs.fat32_length;
803 mydata->fatlength = bs.fat_length;
806 mydata->fat_sect = bs.reserved;
808 cursect = mydata->rootdir_sect
809 = mydata->fat_sect + mydata->fatlength * bs.fats;
811 mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0];
812 mydata->clust_size = bs.cluster_size;
813 if (mydata->sect_size != cur_part_info.blksz) {
814 printf("Error: FAT sector size mismatch (fs=%hu, dev=%lu)\n",
815 mydata->sect_size, cur_part_info.blksz);
819 if (mydata->fatsize == 32) {
820 mydata->data_begin = mydata->rootdir_sect -
821 (mydata->clust_size * 2);
823 rootdir_size = ((bs.dir_entries[1] * (int)256 +
827 mydata->data_begin = mydata->rootdir_sect +
829 (mydata->clust_size * 2);
832 mydata->fatbufnum = -1;
833 mydata->fatbuf = memalign(ARCH_DMA_MINALIGN, FATBUFSIZE);
834 if (mydata->fatbuf == NULL) {
835 debug("Error: allocating memory\n");
839 #ifdef CONFIG_SUPPORT_VFAT
840 debug("VFAT Support enabled\n");
842 debug("FAT%d, fat_sect: %d, fatlength: %d\n",
843 mydata->fatsize, mydata->fat_sect, mydata->fatlength);
844 debug("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
845 "Data begins at: %d\n",
847 mydata->rootdir_sect,
848 mydata->rootdir_sect * mydata->sect_size, mydata->data_begin);
849 debug("Sector size: %d, cluster size: %d\n", mydata->sect_size,
852 /* "cwd" is always the root... */
853 while (ISDIRDELIM(*filename))
856 /* Make a copy of the filename and convert it to lowercase */
857 strcpy(fnamecopy, filename);
860 if (*fnamecopy == '\0') {
865 } else if ((idx = dirdelim(fnamecopy)) >= 0) {
867 fnamecopy[idx] = '\0';
868 subname = fnamecopy + idx + 1;
870 /* Handle multiple delimiters */
871 while (ISDIRDELIM(*subname))
881 debug("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%zd\n",
882 cursect, mydata->clust_size, DIRENTSPERBLOCK);
884 if (disk_read(cursect,
885 (mydata->fatsize == 32) ?
886 (mydata->clust_size) :
888 do_fat_read_block) < 0) {
889 debug("Error: reading rootdir block\n");
893 dentptr = (dir_entry *) do_fat_read_block;
895 for (i = 0; i < DIRENTSPERBLOCK; i++) {
896 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
899 if (dentptr->name[0] == DELETED_FLAG) {
903 if ((dentptr->attr & ATTR_VOLUME)) {
904 #ifdef CONFIG_SUPPORT_VFAT
905 if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
906 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
908 ((dir_slot *)dentptr)->alias_checksum;
915 if (dols == LS_ROOT) {
919 (dentptr->attr & ATTR_DIR);
927 if (l_name[0] != 0) {
934 printf(" %8ld %s%c\n",
935 (long)FAT2CPU32(dentptr->size),
947 debug("Rootvfatname: |%s|\n",
952 /* Volume label or VFAT entry */
956 } else if (dentptr->name[0] == 0) {
957 debug("RootDentname == NULL - %d\n", i);
958 if (dols == LS_ROOT) {
959 printf("\n%d file(s), %d dir(s)\n\n",
965 #ifdef CONFIG_SUPPORT_VFAT
966 else if (dols == LS_ROOT &&
967 mkcksum(dentptr->name) == prevcksum) {
973 get_name(dentptr, s_name);
975 if (dols == LS_ROOT) {
976 int isdir = (dentptr->attr & ATTR_DIR);
982 if (s_name[0] != 0) {
988 if (s_name[0] != 0) {
995 printf(" %8ld %s%c\n",
996 (long)FAT2CPU32(dentptr->size),
1007 if (strcmp(fnamecopy, s_name)
1008 && strcmp(fnamecopy, l_name)) {
1009 debug("RootMismatch: |%s|%s|\n", s_name,
1015 if (isdir && !(dentptr->attr & ATTR_DIR))
1018 debug("RootName: %s", s_name);
1019 debug(", start: 0x%x", START(dentptr));
1020 debug(", size: 0x%x %s\n",
1021 FAT2CPU32(dentptr->size),
1022 isdir ? "(DIR)" : "");
1024 goto rootdir_done; /* We got a match */
1026 debug("END LOOP: j=%d clust_size=%d\n", j,
1027 mydata->clust_size);
1030 * On FAT32 we must fetch the FAT entries for the next
1031 * root directory clusters when a cluster has been
1032 * completely processed.
1036 if ((mydata->fatsize == 32) && (j == mydata->clust_size)) {
1040 nxt_clust = get_fatent(mydata, root_cluster);
1041 fat32_end = CHECK_CLUST(nxt_clust, 32);
1043 nxtsect = mydata->data_begin +
1044 (nxt_clust * mydata->clust_size);
1046 root_cluster = nxt_clust;
1054 /* If end of rootdir reached */
1055 if ((mydata->fatsize == 32 && fat32_end) ||
1056 (mydata->fatsize != 32 && j == rootdir_size)) {
1057 if (dols == LS_ROOT) {
1058 printf("\n%d file(s), %d dir(s)\n\n",
1070 int startsect = mydata->data_begin
1071 + START(dentptr) * mydata->clust_size;
1073 char *nextname = NULL;
1078 idx = dirdelim(subname);
1081 subname[idx] = '\0';
1082 nextname = subname + idx + 1;
1083 /* Handle multiple delimiters */
1084 while (ISDIRDELIM(*nextname))
1086 if (dols && *nextname == '\0')
1089 if (dols && firsttime) {
1096 if (get_dentfromdir(mydata, startsect, subname, dentptr,
1097 isdir ? 0 : dols) == NULL) {
1104 if (!(dentptr->attr & ATTR_DIR))
1110 ret = get_contents(mydata, dentptr, buffer, maxsize);
1111 debug("Size: %d, got: %ld\n", FAT2CPU32(dentptr->size), ret);
1114 free(mydata->fatbuf);
1118 int file_fat_detectfs (void)
1121 volume_info volinfo;
1125 if (cur_dev == NULL) {
1126 printf("No current device\n");
1130 #if defined(CONFIG_CMD_IDE) || \
1131 defined(CONFIG_CMD_MG_DISK) || \
1132 defined(CONFIG_CMD_SATA) || \
1133 defined(CONFIG_CMD_SCSI) || \
1134 defined(CONFIG_CMD_USB) || \
1136 printf("Interface: ");
1137 switch (cur_dev->if_type) {
1163 printf("\n Device %d: ", cur_dev->dev);
1167 if (read_bootsectandvi(&bs, &volinfo, &fatsize)) {
1168 printf("\nNo valid FAT fs found\n");
1172 memcpy(vol_label, volinfo.volume_label, 11);
1173 vol_label[11] = '\0';
1174 volinfo.fs_type[5] = '\0';
1176 printf("Partition %d: Filesystem: %s \"%s\"\n", cur_part_nr,
1177 volinfo.fs_type, vol_label);
1182 int file_fat_ls (const char *dir)
1184 return do_fat_read(dir, NULL, 0, LS_YES);
1187 long file_fat_read (const char *filename, void *buffer, unsigned long maxsize)
1189 printf("reading %s\n", filename);
1190 return do_fat_read(filename, buffer, maxsize, LS_NO);