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,
31 #include <asm/byteorder.h>
35 * Convert a string to lowercase.
40 while (*str != '\0') {
46 static block_dev_desc_t *cur_dev = NULL;
47 static unsigned long part_offset = 0;
48 static int cur_part = 1;
50 #define DOS_PART_TBL_OFFSET 0x1be
51 #define DOS_PART_MAGIC_OFFSET 0x1fe
52 #define DOS_FS_TYPE_OFFSET 0x36
53 #define DOS_FS32_TYPE_OFFSET 0x52
55 int disk_read (__u32 startblock, __u32 getsize, __u8 * bufptr)
57 startblock += part_offset;
60 if (cur_dev->block_read) {
61 return cur_dev->block_read (cur_dev->dev
62 , startblock, getsize, (unsigned long *)bufptr);
69 fat_register_device(block_dev_desc_t *dev_desc, int part_no)
71 unsigned char buffer[SECTOR_SIZE];
72 disk_partition_t info;
74 if (!dev_desc->block_read)
77 /* check if we have a MBR (on floppies we have only a PBR) */
78 if (dev_desc->block_read (dev_desc->dev, 0, 1, (ulong *) buffer) != 1) {
79 printf ("** Can't read from device %d **\n", dev_desc->dev);
82 if (buffer[DOS_PART_MAGIC_OFFSET] != 0x55 ||
83 buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) {
84 /* no signature found */
87 #if (defined(CONFIG_CMD_IDE) || \
88 defined(CONFIG_CMD_MG_DISK) || \
89 defined(CONFIG_CMD_SATA) || \
90 defined(CONFIG_CMD_SCSI) || \
91 defined(CONFIG_CMD_USB) || \
92 defined(CONFIG_MMC) || \
93 defined(CONFIG_SYSTEMACE) )
94 /* First we assume, there is a MBR */
95 if (!get_partition_info (dev_desc, part_no, &info)) {
96 part_offset = info.start;
98 } else if (strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3)==0 ||
99 strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET],"FAT32",5)==0) {
100 /* ok, we assume we are on a PBR only */
104 printf ("** Partition %d not valid on device %d **\n",
105 part_no, dev_desc->dev);
110 if ((strncmp((char *)&buffer[DOS_FS_TYPE_OFFSET], "FAT", 3) == 0) ||
111 (strncmp((char *)&buffer[DOS_FS32_TYPE_OFFSET], "FAT32", 5) == 0)) {
112 /* ok, we assume we are on a PBR only */
115 info.start = part_offset;
117 /* FIXME we need to determine the start block of the
118 * partition where the DOS FS resides. This can be done
119 * by using the get_partition_info routine. For this
120 * purpose the libpart must be included.
131 * Get the first occurence of a directory delimiter ('/' or '\') in a string.
132 * Return index into string if found, -1 otherwise.
139 while (*str != '\0') {
140 if (ISDIRDELIM(*str)) return str - start;
147 * Extract zero terminated short name from a directory entry.
149 static void get_name (dir_entry *dirent, char *s_name)
153 memcpy (s_name, dirent->name, 8);
156 while (*ptr && *ptr != ' ')
158 if (dirent->ext[0] && dirent->ext[0] != ' ') {
161 memcpy (ptr, dirent->ext, 3);
163 while (*ptr && *ptr != ' ')
167 if (*s_name == DELETED_FLAG)
169 else if (*s_name == aRING)
170 *s_name = DELETED_FLAG;
175 * Get the entry at index 'entry' in a FAT (12/16/32) table.
176 * On failure 0x00 is returned.
179 get_fatent(fsdata *mydata, __u32 entry)
185 switch (mydata->fatsize) {
187 bufnum = entry / FAT32BUFSIZE;
188 offset = entry - bufnum * FAT32BUFSIZE;
191 bufnum = entry / FAT16BUFSIZE;
192 offset = entry - bufnum * FAT16BUFSIZE;
195 bufnum = entry / FAT12BUFSIZE;
196 offset = entry - bufnum * FAT12BUFSIZE;
200 /* Unsupported FAT size */
204 FAT_DPRINT("FAT%d: entry: 0x%04x = %d, offset: 0x%04x = %d\n",
205 mydata->fatsize, entry, entry, offset, offset);
207 /* Read a new block of FAT entries into the cache. */
208 if (bufnum != mydata->fatbufnum) {
209 int getsize = FATBUFSIZE/FS_BLOCK_SIZE;
210 __u8 *bufptr = mydata->fatbuf;
211 __u32 fatlength = mydata->fatlength;
212 __u32 startblock = bufnum * FATBUFBLOCKS;
214 fatlength *= SECTOR_SIZE; /* We want it in bytes now */
215 startblock += mydata->fat_sect; /* Offset from start of disk */
217 if (getsize > fatlength) getsize = fatlength;
218 if (disk_read(startblock, getsize, bufptr) < 0) {
219 FAT_DPRINT("Error reading FAT blocks\n");
222 mydata->fatbufnum = bufnum;
225 /* Get the actual entry from the table */
226 switch (mydata->fatsize) {
228 ret = FAT2CPU32(((__u32*)mydata->fatbuf)[offset]);
231 ret = FAT2CPU16(((__u16*)mydata->fatbuf)[offset]);
234 __u32 off16 = (offset*3)/4;
237 switch (offset & 0x3) {
239 ret = FAT2CPU16(((__u16*)mydata->fatbuf)[off16]);
243 val1 = FAT2CPU16(((__u16*)mydata->fatbuf)[off16]);
245 val2 = FAT2CPU16(((__u16*)mydata->fatbuf)[off16+1]);
247 ret = (val2 << 4) | (val1 >> 12);
250 val1 = FAT2CPU16(((__u16*)mydata->fatbuf)[off16]);
252 val2 = FAT2CPU16(((__u16*)mydata->fatbuf)[off16+1]);
254 ret = (val2 << 8) | (val1 >> 8);
257 ret = FAT2CPU16(((__u16*)mydata->fatbuf)[off16]);;
258 ret = (ret & 0xfff0) >> 4;
266 FAT_DPRINT("FAT%d: ret: %08x, offset: %04x\n",
267 mydata->fatsize, ret, offset);
274 * Read at most 'size' bytes from the specified cluster into 'buffer'.
275 * Return 0 on success, -1 otherwise.
278 get_cluster(fsdata *mydata, __u32 clustnum, __u8 *buffer, unsigned long size)
284 startsect = mydata->data_begin + clustnum*mydata->clust_size;
286 startsect = mydata->rootdir_sect;
289 FAT_DPRINT("gc - clustnum: %d, startsect: %d\n", clustnum, startsect);
290 if (disk_read(startsect, size/FS_BLOCK_SIZE , buffer) < 0) {
291 FAT_DPRINT("Error reading data\n");
294 if(size % FS_BLOCK_SIZE) {
295 __u8 tmpbuf[FS_BLOCK_SIZE];
296 idx= size/FS_BLOCK_SIZE;
297 if (disk_read(startsect + idx, 1, tmpbuf) < 0) {
298 FAT_DPRINT("Error reading data\n");
301 buffer += idx*FS_BLOCK_SIZE;
303 memcpy(buffer, tmpbuf, size % FS_BLOCK_SIZE);
312 * Read at most 'maxsize' bytes from the file associated with 'dentptr'
314 * Return the number of bytes read or -1 on fatal errors.
317 get_contents(fsdata *mydata, dir_entry *dentptr, __u8 *buffer,
318 unsigned long maxsize)
320 unsigned long filesize = FAT2CPU32(dentptr->size), gotsize = 0;
321 unsigned int bytesperclust = mydata->clust_size * SECTOR_SIZE;
322 __u32 curclust = START(dentptr);
323 __u32 endclust, newclust;
324 unsigned long actsize;
326 FAT_DPRINT("Filesize: %ld bytes\n", filesize);
328 if (maxsize > 0 && filesize > maxsize) filesize = maxsize;
330 FAT_DPRINT("%ld bytes\n", filesize);
332 actsize=bytesperclust;
335 /* search for consecutive clusters */
336 while(actsize < filesize) {
337 newclust = get_fatent(mydata, endclust);
338 if((newclust -1)!=endclust)
340 if (CHECK_CLUST(newclust, mydata->fatsize)) {
341 FAT_DPRINT("curclust: 0x%x\n", newclust);
342 FAT_DPRINT("Invalid FAT entry\n");
346 actsize+= bytesperclust;
348 /* actsize >= file size */
349 actsize -= bytesperclust;
350 /* get remaining clusters */
351 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
352 FAT_ERROR("Error reading cluster\n");
355 /* get remaining bytes */
356 gotsize += (int)actsize;
360 if (get_cluster(mydata, endclust, buffer, (int)actsize) != 0) {
361 FAT_ERROR("Error reading cluster\n");
367 if (get_cluster(mydata, curclust, buffer, (int)actsize) != 0) {
368 FAT_ERROR("Error reading cluster\n");
371 gotsize += (int)actsize;
374 curclust = get_fatent(mydata, endclust);
375 if (CHECK_CLUST(curclust, mydata->fatsize)) {
376 FAT_DPRINT("curclust: 0x%x\n", curclust);
377 FAT_ERROR("Invalid FAT entry\n");
380 actsize=bytesperclust;
386 #ifdef CONFIG_SUPPORT_VFAT
388 * Extract the file name information from 'slotptr' into 'l_name',
389 * starting at l_name[*idx].
390 * Return 1 if terminator (zero byte) is found, 0 otherwise.
393 slot2str(dir_slot *slotptr, char *l_name, int *idx)
397 for (j = 0; j <= 8; j += 2) {
398 l_name[*idx] = slotptr->name0_4[j];
399 if (l_name[*idx] == 0x00) return 1;
402 for (j = 0; j <= 10; j += 2) {
403 l_name[*idx] = slotptr->name5_10[j];
404 if (l_name[*idx] == 0x00) return 1;
407 for (j = 0; j <= 2; j += 2) {
408 l_name[*idx] = slotptr->name11_12[j];
409 if (l_name[*idx] == 0x00) return 1;
418 * Extract the full long filename starting at 'retdent' (which is really
419 * a slot) into 'l_name'. If successful also copy the real directory entry
421 * Return 0 on success, -1 otherwise.
423 __attribute__ ((__aligned__(__alignof__(dir_entry))))
424 __u8 get_vfatname_block[MAX_CLUSTSIZE];
426 get_vfatname(fsdata *mydata, int curclust, __u8 *cluster,
427 dir_entry *retdent, char *l_name)
430 dir_slot *slotptr = (dir_slot*) retdent;
431 __u8 *nextclust = cluster + mydata->clust_size * SECTOR_SIZE;
432 __u8 counter = (slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff;
435 while ((__u8*)slotptr < nextclust) {
436 if (counter == 0) break;
437 if (((slotptr->id & ~LAST_LONG_ENTRY_MASK) & 0xff) != counter)
443 if ((__u8*)slotptr >= nextclust) {
447 curclust = get_fatent(mydata, curclust);
448 if (CHECK_CLUST(curclust, mydata->fatsize)) {
449 FAT_DPRINT("curclust: 0x%x\n", curclust);
450 FAT_ERROR("Invalid FAT entry\n");
453 if (get_cluster(mydata, curclust, get_vfatname_block,
454 mydata->clust_size * SECTOR_SIZE) != 0) {
455 FAT_DPRINT("Error: reading directory block\n");
458 slotptr2 = (dir_slot*) get_vfatname_block;
459 while (slotptr2->id > 0x01) {
462 /* Save the real directory entry */
463 realdent = (dir_entry*)slotptr2 + 1;
464 while ((__u8*)slotptr2 >= get_vfatname_block) {
465 slot2str(slotptr2, l_name, &idx);
469 /* Save the real directory entry */
470 realdent = (dir_entry*)slotptr;
475 if (slot2str(slotptr, l_name, &idx)) break;
476 } while (!(slotptr->id & LAST_LONG_ENTRY_MASK));
479 if (*l_name == DELETED_FLAG) *l_name = '\0';
480 else if (*l_name == aRING) *l_name = DELETED_FLAG;
483 /* Return the real directory entry */
484 memcpy(retdent, realdent, sizeof(dir_entry));
490 /* Calculate short name checksum */
492 mkcksum(const char *str)
497 for (i = 0; i < 11; i++) {
498 ret = (((ret&1)<<7)|((ret&0xfe)>>1)) + str[i];
507 * Get the directory entry associated with 'filename' from the directory
508 * starting at 'startsect'
510 __attribute__ ((__aligned__(__alignof__(dir_entry))))
511 __u8 get_dentfromdir_block[MAX_CLUSTSIZE];
512 static dir_entry *get_dentfromdir (fsdata * mydata, int startsect,
513 char *filename, dir_entry * retdent,
516 __u16 prevcksum = 0xffff;
517 __u32 curclust = START (retdent);
518 int files = 0, dirs = 0;
520 FAT_DPRINT ("get_dentfromdir: %s\n", filename);
525 if (get_cluster (mydata, curclust, get_dentfromdir_block,
526 mydata->clust_size * SECTOR_SIZE) != 0) {
527 FAT_DPRINT ("Error: reading directory block\n");
530 dentptr = (dir_entry *) get_dentfromdir_block;
531 for (i = 0; i < DIRENTSPERCLUST; i++) {
532 char s_name[14], l_name[256];
535 if (dentptr->name[0] == DELETED_FLAG) {
539 if ((dentptr->attr & ATTR_VOLUME)) {
540 #ifdef CONFIG_SUPPORT_VFAT
541 if ((dentptr->attr & ATTR_VFAT) &&
542 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
543 prevcksum = ((dir_slot *) dentptr)
545 get_vfatname (mydata, curclust, get_dentfromdir_block,
548 int isdir = (dentptr->attr & ATTR_DIR);
558 if (l_name[0] != 0) {
565 printf (" %8ld %s%c\n",
566 (long) FAT2CPU32 (dentptr->size),
569 printf (" %s%c\n", l_name, dirc);
575 FAT_DPRINT ("vfatname: |%s|\n", l_name);
579 /* Volume label or VFAT entry */
584 if (dentptr->name[0] == 0) {
586 printf ("\n%d file(s), %d dir(s)\n\n", files, dirs);
588 FAT_DPRINT ("Dentname == NULL - %d\n", i);
591 #ifdef CONFIG_SUPPORT_VFAT
592 if (dols && mkcksum (dentptr->name) == prevcksum) {
597 get_name (dentptr, s_name);
599 int isdir = (dentptr->attr & ATTR_DIR);
609 if (s_name[0] != 0) {
616 printf (" %8ld %s%c\n",
617 (long) FAT2CPU32 (dentptr->size), s_name,
620 printf (" %s%c\n", s_name, dirc);
626 if (strcmp (filename, s_name) && strcmp (filename, l_name)) {
627 FAT_DPRINT ("Mismatch: |%s|%s|\n", s_name, l_name);
631 memcpy (retdent, dentptr, sizeof (dir_entry));
633 FAT_DPRINT ("DentName: %s", s_name);
634 FAT_DPRINT (", start: 0x%x", START (dentptr));
635 FAT_DPRINT (", size: 0x%x %s\n",
636 FAT2CPU32 (dentptr->size),
637 (dentptr->attr & ATTR_DIR) ? "(DIR)" : "");
641 curclust = get_fatent (mydata, curclust);
642 if (CHECK_CLUST(curclust, mydata->fatsize)) {
643 FAT_DPRINT ("curclust: 0x%x\n", curclust);
644 FAT_ERROR ("Invalid FAT entry\n");
654 * Read boot sector and volume info from a FAT filesystem
657 read_bootsectandvi(boot_sector *bs, volume_info *volinfo, int *fatsize)
659 __u8 block[FS_BLOCK_SIZE];
660 volume_info *vistart;
662 if (disk_read(0, 1, block) < 0) {
663 FAT_DPRINT("Error: reading block\n");
667 memcpy(bs, block, sizeof(boot_sector));
668 bs->reserved = FAT2CPU16(bs->reserved);
669 bs->fat_length = FAT2CPU16(bs->fat_length);
670 bs->secs_track = FAT2CPU16(bs->secs_track);
671 bs->heads = FAT2CPU16(bs->heads);
673 bs->hidden = FAT2CPU32(bs->hidden);
675 bs->total_sect = FAT2CPU32(bs->total_sect);
678 if (bs->fat_length == 0) {
680 bs->fat32_length = FAT2CPU32(bs->fat32_length);
681 bs->flags = FAT2CPU16(bs->flags);
682 bs->root_cluster = FAT2CPU32(bs->root_cluster);
683 bs->info_sector = FAT2CPU16(bs->info_sector);
684 bs->backup_boot = FAT2CPU16(bs->backup_boot);
685 vistart = (volume_info*) (block + sizeof(boot_sector));
688 vistart = (volume_info*) &(bs->fat32_length);
691 memcpy(volinfo, vistart, sizeof(volume_info));
693 if (*fatsize == 32) {
694 if (strncmp(FAT32_SIGN, vistart->fs_type, SIGNLEN) == 0) {
698 if (strncmp(FAT12_SIGN, vistart->fs_type, SIGNLEN) == 0) {
702 if (strncmp(FAT16_SIGN, vistart->fs_type, SIGNLEN) == 0) {
708 FAT_DPRINT("Error: broken fs_type sign\n");
712 __attribute__ ((__aligned__(__alignof__(dir_entry))))
713 __u8 do_fat_read_block[MAX_CLUSTSIZE];
715 do_fat_read (const char *filename, void *buffer, unsigned long maxsize,
718 char fnamecopy[2048];
722 fsdata *mydata = &datablock;
724 __u16 prevcksum = 0xffff;
728 int files = 0, dirs = 0;
734 if (read_bootsectandvi (&bs, &volinfo, &mydata->fatsize)) {
735 FAT_DPRINT ("Error: reading boot sector\n");
738 root_cluster = bs.root_cluster;
739 if (mydata->fatsize == 32) {
740 mydata->fatlength = bs.fat32_length;
742 mydata->fatlength = bs.fat_length;
744 mydata->fat_sect = bs.reserved;
745 cursect = mydata->rootdir_sect
746 = mydata->fat_sect + mydata->fatlength * bs.fats;
747 mydata->clust_size = bs.cluster_size;
748 if (mydata->fatsize == 32) {
749 mydata->data_begin = mydata->rootdir_sect
750 - (mydata->clust_size * 2);
754 rootdir_size = ((bs.dir_entries[1] * (int) 256 + bs.dir_entries[0])
755 * sizeof (dir_entry)) / SECTOR_SIZE;
756 mydata->data_begin = mydata->rootdir_sect + rootdir_size
757 - (mydata->clust_size * 2);
759 mydata->fatbufnum = -1;
761 #ifdef CONFIG_SUPPORT_VFAT
762 FAT_DPRINT ("VFAT Support enabled\n");
764 FAT_DPRINT ("FAT%d, fat_sect: %d, fatlength: %d\n",
768 FAT_DPRINT ("Rootdir begins at cluster: %d, sector: %d, offset: %x\n"
769 "Data begins at: %d\n",
771 mydata->rootdir_sect,
772 mydata->rootdir_sect * SECTOR_SIZE,
774 FAT_DPRINT ("Cluster size: %d\n", mydata->clust_size);
776 /* "cwd" is always the root... */
777 while (ISDIRDELIM (*filename))
779 /* Make a copy of the filename and convert it to lowercase */
780 strcpy (fnamecopy, filename);
781 downcase (fnamecopy);
782 if (*fnamecopy == '\0') {
786 } else if ((idx = dirdelim (fnamecopy)) >= 0) {
788 fnamecopy[idx] = '\0';
789 subname = fnamecopy + idx + 1;
790 /* Handle multiple delimiters */
791 while (ISDIRDELIM (*subname))
801 FAT_DPRINT ("FAT read sect=%d, clust_size=%d, DIRENTSPERBLOCK=%d\n",
802 cursect, mydata->clust_size, DIRENTSPERBLOCK);
803 if (disk_read (cursect, mydata->clust_size, do_fat_read_block) < 0) {
804 FAT_DPRINT ("Error: reading rootdir block\n");
807 dentptr = (dir_entry *) do_fat_read_block;
808 for (i = 0; i < DIRENTSPERBLOCK; i++) {
809 char s_name[14], l_name[256];
812 if ((dentptr->attr & ATTR_VOLUME)) {
813 #ifdef CONFIG_SUPPORT_VFAT
814 if ((dentptr->attr & ATTR_VFAT) &&
815 (dentptr->name[0] & LAST_LONG_ENTRY_MASK)) {
816 prevcksum = ((dir_slot *) dentptr)->alias_checksum;
817 get_vfatname (mydata, 0, do_fat_read_block, dentptr, l_name);
818 if (dols == LS_ROOT) {
819 int isdir = (dentptr->attr & ATTR_DIR);
829 if (l_name[0] != 0) {
836 printf (" %8ld %s%c\n",
837 (long) FAT2CPU32 (dentptr->size),
840 printf (" %s%c\n", l_name, dirc);
846 FAT_DPRINT ("Rootvfatname: |%s|\n", l_name);
850 /* Volume label or VFAT entry */
854 } else if (dentptr->name[0] == 0) {
855 FAT_DPRINT ("RootDentname == NULL - %d\n", i);
856 if (dols == LS_ROOT) {
857 printf ("\n%d file(s), %d dir(s)\n\n", files, dirs);
862 #ifdef CONFIG_SUPPORT_VFAT
863 else if (dols == LS_ROOT
864 && mkcksum (dentptr->name) == prevcksum) {
869 get_name (dentptr, s_name);
870 if (dols == LS_ROOT) {
871 int isdir = (dentptr->attr & ATTR_DIR);
877 if (s_name[0] != 0) {
883 if (s_name[0] != 0) {
890 printf (" %8ld %s%c\n",
891 (long) FAT2CPU32 (dentptr->size), s_name,
894 printf (" %s%c\n", s_name, dirc);
900 if (strcmp (fnamecopy, s_name) && strcmp (fnamecopy, l_name)) {
901 FAT_DPRINT ("RootMismatch: |%s|%s|\n", s_name, l_name);
905 if (isdir && !(dentptr->attr & ATTR_DIR))
908 FAT_DPRINT ("RootName: %s", s_name);
909 FAT_DPRINT (", start: 0x%x", START (dentptr));
910 FAT_DPRINT (", size: 0x%x %s\n",
911 FAT2CPU32 (dentptr->size), isdir ? "(DIR)" : "");
913 goto rootdir_done; /* We got a match */
915 FAT_DPRINT ("END LOOP: j=%d clust_size=%d\n", j, mydata->clust_size);
918 * On FAT32 we must fetch the FAT entries for the next
919 * root directory clusters when a cluster has been
920 * completely processed.
922 if ((mydata->fatsize == 32) && (++j == mydata->clust_size)) {
924 int cur_clust, nxt_clust;
926 cur_clust = (cursect - mydata->data_begin) / mydata->clust_size;
927 nxt_clust = get_fatent(mydata, root_cluster);
928 nxtsect = mydata->data_begin + (nxt_clust * mydata->clust_size);
929 FAT_DPRINT ("END LOOP: sect=%d, clust=%d, root_clust=%d, n_sect=%d, n_clust=%d\n",
930 cursect, cur_clust, root_cluster, nxtsect, nxt_clust);
931 root_cluster = nxt_clust;
943 int startsect = mydata->data_begin
944 + START (dentptr) * mydata->clust_size;
946 char *nextname = NULL;
951 idx = dirdelim (subname);
954 nextname = subname + idx + 1;
955 /* Handle multiple delimiters */
956 while (ISDIRDELIM (*nextname))
958 if (dols && *nextname == '\0')
961 if (dols && firsttime) {
968 if (get_dentfromdir (mydata, startsect, subname, dentptr,
969 isdir ? 0 : dols) == NULL) {
976 if (!(dentptr->attr & ATTR_DIR))
981 ret = get_contents (mydata, dentptr, buffer, maxsize);
982 FAT_DPRINT ("Size: %d, got: %ld\n", FAT2CPU32 (dentptr->size), ret);
989 file_fat_detectfs(void)
997 printf("No current device\n");
1000 #if defined(CONFIG_CMD_IDE) || \
1001 defined(CONFIG_CMD_MG_DISK) || \
1002 defined(CONFIG_CMD_SATA) || \
1003 defined(CONFIG_CMD_SCSI) || \
1004 defined(CONFIG_CMD_USB) || \
1006 printf("Interface: ");
1007 switch(cur_dev->if_type) {
1008 case IF_TYPE_IDE : printf("IDE"); break;
1009 case IF_TYPE_SATA : printf("SATA"); break;
1010 case IF_TYPE_SCSI : printf("SCSI"); break;
1011 case IF_TYPE_ATAPI : printf("ATAPI"); break;
1012 case IF_TYPE_USB : printf("USB"); break;
1013 case IF_TYPE_DOC : printf("DOC"); break;
1014 case IF_TYPE_MMC : printf("MMC"); break;
1015 default : printf("Unknown");
1017 printf("\n Device %d: ",cur_dev->dev);
1020 if(read_bootsectandvi(&bs, &volinfo, &fatsize)) {
1021 printf("\nNo valid FAT fs found\n");
1024 memcpy (vol_label, volinfo.volume_label, 11);
1025 vol_label[11] = '\0';
1026 volinfo.fs_type[5]='\0';
1027 printf("Partition %d: Filesystem: %s \"%s\"\n"
1028 ,cur_part,volinfo.fs_type,vol_label);
1034 file_fat_ls(const char *dir)
1036 return do_fat_read(dir, NULL, 0, LS_YES);
1041 file_fat_read(const char *filename, void *buffer, unsigned long maxsize)
1043 printf("reading %s\n",filename);
1044 return do_fat_read(filename, buffer, maxsize, LS_NO);