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;
47 static unsigned int cur_part_nr;
48 static disk_partition_t cur_part_info;
50 #define DOS_BOOT_MAGIC_OFFSET 0x1fe
51 #define DOS_FS_TYPE_OFFSET 0x36
52 #define DOS_FS32_TYPE_OFFSET 0x52
54 static int disk_read(__u32 block, __u32 nr_blocks, void *buf)
56 if (!cur_dev || !cur_dev->block_read)
59 return cur_dev->block_read(cur_dev->dev,
60 cur_part_info.start + block, nr_blocks, buf);
63 int fat_register_device (block_dev_desc_t * dev_desc, int part_no)
65 unsigned char buffer[dev_desc->blksz];
67 /* First close any currently found FAT filesystem */
70 #if (defined(CONFIG_CMD_IDE) || \
71 defined(CONFIG_CMD_MG_DISK) || \
72 defined(CONFIG_CMD_SATA) || \
73 defined(CONFIG_CMD_SCSI) || \
74 defined(CONFIG_CMD_USB) || \
75 defined(CONFIG_MMC) || \
76 defined(CONFIG_SYSTEMACE) )
78 /* Read the partition table, if present */
79 if (!get_partition_info(dev_desc, part_no, &cur_part_info)) {
81 cur_part_nr = part_no;
85 /* Otherwise it might be a superfloppy (whole-disk FAT filesystem) */
88 printf("** Partition %d not valid on device %d **\n",
89 part_no, dev_desc->dev);
95 cur_part_info.start = 0;
96 cur_part_info.size = dev_desc->lba;
97 cur_part_info.blksz = dev_desc->blksz;
98 memset(cur_part_info.name, 0, sizeof(cur_part_info.name));
99 memset(cur_part_info.type, 0, sizeof(cur_part_info.type));
102 /* Make sure it has a valid FAT header */
103 if (disk_read(0, 1, buffer) != 1) {
108 /* Check if it's actually a DOS volume */
109 if (memcmp(buffer + DOS_BOOT_MAGIC_OFFSET, "\x55\xAA", 2)) {
114 /* Check for FAT12/FAT16/FAT32 filesystem */
115 if (!memcmp(buffer + DOS_FS_TYPE_OFFSET, "FAT", 3))
117 if (!memcmp(buffer + DOS_FS32_TYPE_OFFSET, "FAT32", 5))
126 * Get the first occurence of a directory delimiter ('/' or '\') in a string.
127 * Return index into string if found, -1 otherwise.
129 static int dirdelim (char *str)
133 while (*str != '\0') {
134 if (ISDIRDELIM(*str))
142 * Extract zero terminated short name from a directory entry.
144 static void get_name (dir_entry *dirent, char *s_name)
148 memcpy(s_name, dirent->name, 8);
151 while (*ptr && *ptr != ' ')
153 if (dirent->ext[0] && dirent->ext[0] != ' ') {
156 memcpy(ptr, dirent->ext, 3);
158 while (*ptr && *ptr != ' ')
162 if (*s_name == DELETED_FLAG)
164 else if (*s_name == aRING)
165 *s_name = DELETED_FLAG;
170 * Get the entry at index 'entry' in a FAT (12/16/32) table.
171 * On failure 0x00 is returned.
173 static __u32 get_fatent (fsdata *mydata, __u32 entry)
180 switch (mydata->fatsize) {
182 bufnum = entry / FAT32BUFSIZE;
183 offset = entry - bufnum * FAT32BUFSIZE;
186 bufnum = entry / FAT16BUFSIZE;
187 offset = entry - bufnum * FAT16BUFSIZE;
190 bufnum = entry / FAT12BUFSIZE;
191 offset = entry - bufnum * FAT12BUFSIZE;
195 /* Unsupported FAT size */
199 debug("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n",
200 mydata->fatsize, entry, entry, offset, offset);
202 /* Read a new block of FAT entries into the cache. */
203 if (bufnum != mydata->fatbufnum) {
204 __u32 getsize = FATBUFBLOCKS;
205 __u8 *bufptr = mydata->fatbuf;
206 __u32 fatlength = mydata->fatlength;
207 __u32 startblock = bufnum * FATBUFBLOCKS;
209 if (getsize > fatlength)
212 fatlength *= mydata->sect_size; /* We want it in bytes now */
213 startblock += mydata->fat_sect; /* Offset from start of disk */
215 if (disk_read(startblock, getsize, bufptr) < 0) {
216 debug("Error reading FAT blocks\n");
219 mydata->fatbufnum = bufnum;
222 /* Get the actual entry from the table */
223 switch (mydata->fatsize) {
225 ret = FAT2CPU32(((__u32 *) mydata->fatbuf)[offset]);
228 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[offset]);
231 off16 = (offset * 3) / 4;
233 switch (offset & 0x3) {
235 ret = FAT2CPU16(((__u16 *) mydata->fatbuf)[off16]);
239 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
241 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
243 ret = (val2 << 4) | (val1 >> 12);
246 val1 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
248 val2 = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16 + 1]);
250 ret = (val2 << 8) | (val1 >> 8);
253 ret = FAT2CPU16(((__u16 *)mydata->fatbuf)[off16]);
254 ret = (ret & 0xfff0) >> 4;
261 debug("FAT%d: ret: %08x, offset: %04x\n",
262 mydata->fatsize, ret, offset);
268 * Read at most 'size' bytes from the specified cluster into 'buffer'.
269 * Return 0 on success, -1 otherwise.
272 get_cluster (fsdata *mydata, __u32 clustnum, __u8 *buffer,
281 startsect = mydata->data_begin +
282 clustnum * mydata->clust_size;
284 startsect = mydata->rootdir_sect;
287 debug("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
289 nr_sect = size / mydata->sect_size;
290 ret = disk_read(startsect, nr_sect, buffer);
291 if (ret != nr_sect) {
292 debug("Error reading data (got %d)\n", ret);
295 if (size % mydata->sect_size) {
296 __u8 tmpbuf[mydata->sect_size];
298 idx = size / mydata->sect_size;
299 ret = disk_read(startsect + idx, 1, tmpbuf);
301 debug("Error reading data (got %d)\n", ret);
304 buffer += idx * mydata->sect_size;
306 memcpy(buffer, tmpbuf, size % mydata->sect_size);
314 * Read at most 'maxsize' bytes from the file associated with 'dentptr'
316 * Return the number of bytes read or -1 on fatal errors.
319 get_contents (fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
320 unsigned long maxsize)
322 unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
323 unsigned int bytesperclust = mydata->clust_size * mydata->sect_size;
324 __u32 curclust = START(dentptr);
325 __u32 endclust, newclust;
326 unsigned long actsize;
328 debug("Filesize: %ld bytes\n", filesize);
330 if (maxsize > 0 && filesize > maxsize)
333 debug("%ld bytes\n", filesize);
335 actsize = bytesperclust;
339 /* search for consecutive clusters */
340 while (actsize < filesize) {
341 newclust = get_fatent(mydata, endclust);
342 if ((newclust - 1) != endclust)
344 if (CHECK_CLUST(newclust, mydata->fatsize)) {
345 debug("curclust: 0x%x\n", newclust);
346 debug("Invalid FAT entry\n");
350 actsize += bytesperclust;
353 /* actsize >= file size */
354 actsize -= bytesperclust;
356 /* get remaining clusters */
357 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
358 printf("Error reading cluster\n");
362 /* get remaining bytes */
363 gotsize += (int)actsize;
367 if (get_cluster(mydata, endclust, buffer, (int)actsize) != 0) {
368 printf("Error reading cluster\n");
374 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
375 printf("Error reading cluster\n");
378 gotsize += (int)actsize;
382 curclust = get_fatent(mydata, endclust);
383 if (CHECK_CLUST(curclust, mydata->fatsize)) {
384 debug("curclust: 0x%x\n", curclust);
385 printf("Invalid FAT entry\n");
388 actsize = bytesperclust;
393 #ifdef CONFIG_SUPPORT_VFAT
395 * Extract the file name information from 'slotptr' into 'l_name',
396 * starting at l_name[*idx].
397 * Return 1 if terminator (zero byte) is found, 0 otherwise.
399 static int slot2str (dir_slot *slotptr, char *l_name, int *idx)
403 for (j = 0; j <= 8; j += 2) {
404 l_name[*idx] = slotptr->name0_4[j];
405 if (l_name[*idx] == 0x00)
409 for (j = 0; j <= 10; j += 2) {
410 l_name[*idx] = slotptr->name5_10[j];
411 if (l_name[*idx] == 0x00)
415 for (j = 0; j <= 2; j += 2) {
416 l_name[*idx] = slotptr->name11_12[j];
417 if (l_name[*idx] == 0x00)
426 * Extract the full long filename starting at 'retdent' (which is really
427 * a slot) into 'l_name'. If successful also copy the real directory entry
429 * Return 0 on success, -1 otherwise.
431 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
432 __u8 get_vfatname_block[MAX_CLUSTSIZE];
435 get_vfatname (fsdata *mydata, int curclust, __u8 *cluster,
436 dir_entry *retdent, char *l_name)
439 dir_slot *slotptr = (dir_slot *)retdent;
440 __u8 *buflimit = cluster + mydata->sect_size * ((curclust == 0) ?
443 __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
446 if (counter > VFAT_MAXSEQ) {
447 debug("Error: VFAT name is too long\n");
451 while ((__u8 *)slotptr < buflimit) {
454 if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter)
460 if ((__u8 *)slotptr >= buflimit) {
465 curclust = get_fatent(mydata, curclust);
466 if (CHECK_CLUST(curclust, mydata->fatsize)) {
467 debug("curclust: 0x%x\n", curclust);
468 printf("Invalid FAT entry\n");
472 if (get_cluster(mydata, curclust, get_vfatname_block,
473 mydata->clust_size * mydata->sect_size) != 0) {
474 debug("Error: reading directory block\n");
478 slotptr2 = (dir_slot *)get_vfatname_block;
479 while (counter > 0) {
480 if (((slotptr2->id & ~LAST_LONG_ENTRY_MASK)
487 /* Save the real directory entry */
488 realdent = (dir_entry *)slotptr2;
489 while ((__u8 *)slotptr2 > get_vfatname_block) {
491 slot2str(slotptr2, l_name, &idx);
494 /* Save the real directory entry */
495 realdent = (dir_entry *)slotptr;
500 if (slot2str(slotptr, l_name, &idx))
502 } while (!(slotptr->id & LAST_LONG_ENTRY_MASK));
505 if (*l_name == DELETED_FLAG)
507 else if (*l_name == aRING)
508 *l_name = DELETED_FLAG;
511 /* Return the real directory entry */
512 memcpy(retdent, realdent, sizeof(dir_entry));
517 /* Calculate short name checksum */
518 static __u8 mkcksum (const char *str)
524 for (i = 0; i < 11; i++) {
525 ret = (((ret & 1) << 7) | ((ret & 0xfe) >> 1)) + str[i];
530 #endif /* CONFIG_SUPPORT_VFAT */
533 * Get the directory entry associated with 'filename' from the directory
534 * starting at 'startsect'
536 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
537 __u8 get_dentfromdir_block[MAX_CLUSTSIZE];
539 static dir_entry *get_dentfromdir (fsdata *mydata, int startsect,
540 char *filename, dir_entry *retdent,
543 __u16 prevcksum = 0xffff;
544 __u32 curclust = START(retdent);
545 int files = 0, dirs = 0;
547 debug("get_dentfromdir: %s\n", filename);
554 if (get_cluster(mydata, curclust, get_dentfromdir_block,
555 mydata->clust_size * mydata->sect_size) != 0) {
556 debug("Error: reading directory block\n");
560 dentptr = (dir_entry *)get_dentfromdir_block;
562 for (i = 0; i < DIRENTSPERCLUST; i++) {
563 char s_name[14], l_name[VFAT_MAXLEN_BYTES];
566 if (dentptr->name[0] == DELETED_FLAG) {
570 if ((dentptr->attr & ATTR_VOLUME)) {
571 #ifdef CONFIG_SUPPORT_VFAT
572 if ((dentptr->attr & ATTR_VFAT) == ATTR_VFAT &&
573 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
574 prevcksum = ((dir_slot *)dentptr)->alias_checksum;
575 get_vfatname(mydata, curclust,
576 get_dentfromdir_block,
583 isdir = (dentptr->attr & ATTR_DIR);
591 if (l_name[0] != 0) {
598 printf(" %8ld %s%c\n",
599 (long)FAT2CPU32(dentptr->size),
611 debug("vfatname: |%s|\n", l_name);
615 /* Volume label or VFAT entry */
620 if (dentptr->name[0] == 0) {
622 printf("\n%d file(s), %d dir(s)\n\n",
625 debug("Dentname == NULL - %d\n", i);
628 #ifdef CONFIG_SUPPORT_VFAT
629 if (dols && mkcksum(dentptr->name) == prevcksum) {
635 get_name(dentptr, s_name);
637 int isdir = (dentptr->attr & ATTR_DIR);
647 if (s_name[0] != 0) {
655 printf(" %8ld %s%c\n",
656 (long)FAT2CPU32(dentptr->size),
668 if (strcmp(filename, s_name)
669 && strcmp(filename, l_name)) {
670 debug("Mismatch: |%s|%s|\n", s_name, l_name);
675 memcpy(retdent, dentptr, sizeof(dir_entry));
677 debug("DentName: %s", s_name);
678 debug(", start: 0x%x", START(dentptr));
679 debug(", size: 0x%x %s\n",
680 FAT2CPU32(dentptr->size),
681 (dentptr->attr & ATTR_DIR) ? "(DIR)" : "");
686 curclust = get_fatent(mydata, curclust);
687 if (CHECK_CLUST(curclust, mydata->fatsize)) {
688 debug("curclust: 0x%x\n", curclust);
689 printf("Invalid FAT entry\n");
698 * Read boot sector and volume info from a FAT filesystem
701 read_bootsectandvi (boot_sector *bs, volume_info *volinfo, int *fatsize)
704 volume_info *vistart;
707 if (cur_dev == NULL) {
708 debug("Error: no device selected\n");
712 block = malloc(cur_dev->blksz);
714 debug("Error: allocating block\n");
718 if (disk_read (0, 1, block) < 0) {
719 debug("Error: reading block\n");
723 memcpy(bs, block, sizeof(boot_sector));
724 bs->reserved = FAT2CPU16(bs->reserved);
725 bs->fat_length = FAT2CPU16(bs->fat_length);
726 bs->secs_track = FAT2CPU16(bs->secs_track);
727 bs->heads = FAT2CPU16(bs->heads);
728 bs->total_sect = FAT2CPU32(bs->total_sect);
731 if (bs->fat_length == 0) {
733 bs->fat32_length = FAT2CPU32(bs->fat32_length);
734 bs->flags = FAT2CPU16(bs->flags);
735 bs->root_cluster = FAT2CPU32(bs->root_cluster);
736 bs->info_sector = FAT2CPU16(bs->info_sector);
737 bs->backup_boot = FAT2CPU16(bs->backup_boot);
738 vistart = (volume_info *)(block + sizeof(boot_sector));
741 vistart = (volume_info *)&(bs->fat32_length);
744 memcpy(volinfo, vistart, sizeof(volume_info));
746 if (*fatsize == 32) {
747 if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0)
750 if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
754 if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
760 debug("Error: broken fs_type sign\n");
768 __attribute__ ((__aligned__ (__alignof__ (dir_entry))))
769 __u8 do_fat_read_block[MAX_CLUSTSIZE];
772 do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
775 char fnamecopy[2048];
779 fsdata *mydata = &datablock;
781 __u16 prevcksum = 0xffff;
785 int files = 0, dirs = 0;
788 __u32 root_cluster = 0;
789 int rootdir_size = 0;
792 if (read_bootsectandvi(&bs, &volinfo, &mydata->fatsize)) {
793 debug("Error: reading boot sector\n");
797 if (mydata->fatsize == 32) {
798 root_cluster = bs.root_cluster;
799 mydata->fatlength = bs.fat32_length;
801 mydata->fatlength = bs.fat_length;
804 mydata->fat_sect = bs.reserved;
806 cursect = mydata->rootdir_sect
807 = mydata->fat_sect + mydata->fatlength * bs.fats;
809 mydata->sect_size = (bs.sector_size[1] << 8) + bs.sector_size[0];
810 mydata->clust_size = bs.cluster_size;
811 if (mydata->sect_size != cur_part_info.blksz) {
812 printf("Error: FAT sector size mismatch (fs=%hu, dev=%lu)\n",
813 mydata->sect_size, cur_part_info.blksz);
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=%zd\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) {
971 get_name(dentptr, s_name);
973 if (dols == LS_ROOT) {
974 int isdir = (dentptr->attr & ATTR_DIR);
980 if (s_name[0] != 0) {
986 if (s_name[0] != 0) {
993 printf(" %8ld %s%c\n",
994 (long)FAT2CPU32(dentptr->size),
1005 if (strcmp(fnamecopy, s_name)
1006 && strcmp(fnamecopy, l_name)) {
1007 debug("RootMismatch: |%s|%s|\n", s_name,
1013 if (isdir && !(dentptr->attr & ATTR_DIR))
1016 debug("RootName: %s", s_name);
1017 debug(", start: 0x%x", START(dentptr));
1018 debug(", size: 0x%x %s\n",
1019 FAT2CPU32(dentptr->size),
1020 isdir ? "(DIR)" : "");
1022 goto rootdir_done; /* We got a match */
1024 debug("END LOOP: j=%d clust_size=%d\n", j,
1025 mydata->clust_size);
1028 * On FAT32 we must fetch the FAT entries for the next
1029 * root directory clusters when a cluster has been
1030 * completely processed.
1034 if ((mydata->fatsize == 32) && (j == mydata->clust_size)) {
1038 nxt_clust = get_fatent(mydata, root_cluster);
1039 fat32_end = CHECK_CLUST(nxt_clust, 32);
1041 nxtsect = mydata->data_begin +
1042 (nxt_clust * mydata->clust_size);
1044 root_cluster = nxt_clust;
1052 /* If end of rootdir reached */
1053 if ((mydata->fatsize == 32 && fat32_end) ||
1054 (mydata->fatsize != 32 && j == rootdir_size)) {
1055 if (dols == LS_ROOT) {
1056 printf("\n%d file(s), %d dir(s)\n\n",
1068 int startsect = mydata->data_begin
1069 + START(dentptr) * mydata->clust_size;
1071 char *nextname = NULL;
1076 idx = dirdelim(subname);
1079 subname[idx] = '\0';
1080 nextname = subname + idx + 1;
1081 /* Handle multiple delimiters */
1082 while (ISDIRDELIM(*nextname))
1084 if (dols && *nextname == '\0')
1087 if (dols && firsttime) {
1094 if (get_dentfromdir(mydata, startsect, subname, dentptr,
1095 isdir ? 0 : dols) == NULL) {
1102 if (!(dentptr->attr & ATTR_DIR))
1108 ret = get_contents(mydata, dentptr, buffer, maxsize);
1109 debug("Size: %d, got: %ld\n", FAT2CPU32(dentptr->size), ret);
1112 free(mydata->fatbuf);
1116 int file_fat_detectfs (void)
1119 volume_info volinfo;
1123 if (cur_dev == NULL) {
1124 printf("No current device\n");
1128 #if defined(CONFIG_CMD_IDE) || \
1129 defined(CONFIG_CMD_MG_DISK) || \
1130 defined(CONFIG_CMD_SATA) || \
1131 defined(CONFIG_CMD_SCSI) || \
1132 defined(CONFIG_CMD_USB) || \
1134 printf("Interface: ");
1135 switch (cur_dev->if_type) {
1161 printf("\n Device %d: ", cur_dev->dev);
1165 if (read_bootsectandvi(&bs, &volinfo, &fatsize)) {
1166 printf("\nNo valid FAT fs found\n");
1170 memcpy(vol_label, volinfo.volume_label, 11);
1171 vol_label[11] = '\0';
1172 volinfo.fs_type[5] = '\0';
1174 printf("Partition %d: Filesystem: %s \"%s\"\n", cur_part_nr,
1175 volinfo.fs_type, vol_label);
1180 int file_fat_ls (const char *dir)
1182 return do_fat_read(dir, NULL, 0, LS_YES);
1185 long file_fat_read (const char *filename, void *buffer, unsigned long maxsize)
1187 printf("reading %s\n", filename);
1188 return do_fat_read(filename, buffer, maxsize, LS_NO);