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>
34 #if (CONFIG_COMMANDS & CFG_CMD_FAT)
37 * Convert a string to lowercase.
42 while (*str
!= '\0') {
48 static block_dev_desc_t
*cur_dev
= NULL
;
49 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
56 int disk_read (__u32 startblock
, __u32 getsize
, __u8
* bufptr
)
58 startblock
+= part_offset
;
61 if (cur_dev
->block_read
) {
62 return cur_dev
->block_read (cur_dev
->dev
, startblock
, getsize
, (unsigned long *)bufptr
);
69 fat_register_device(block_dev_desc_t
*dev_desc
, int part_no
)
71 unsigned char buffer
[SECTOR_SIZE
];
73 if (!dev_desc
->block_read
)
76 /* check if we have a MBR (on floppies we have only a PBR) */
77 if (dev_desc
->block_read (dev_desc
->dev
, 0, 1, (ulong
*) buffer
) != 1) {
78 printf ("** Can't read from device %d **\n", dev_desc
->dev
);
81 if (buffer
[DOS_PART_MAGIC_OFFSET
] != 0x55 ||
82 buffer
[DOS_PART_MAGIC_OFFSET
+ 1] != 0xaa) {
83 /* no signature found */
86 if(!strncmp(&buffer
[DOS_FS_TYPE_OFFSET
],"FAT",3)) {
87 /* ok, we assume we are on a PBR only */
92 #if (CONFIG_COMMANDS & CFG_CMD_IDE) || (CONFIG_COMMANDS & CFG_CMD_SCSI)
93 disk_partition_t info
;
94 if(!get_partition_info(dev_desc
, part_no
, &info
)) {
95 part_offset
= info
.start
;
99 printf ("** Partition %d not valid on device %d **\n",part_no
,dev_desc
->dev
);
103 /* FIXME we need to determine the start block of the
104 * partition where the DOS FS resides. This can be done
105 * by using the get_partition_info routine. For this
106 * purpose the libpart must be included.
117 * Get the first occurence of a directory delimiter ('/' or '\') in a string.
118 * Return index into string if found, -1 otherwise.
125 while (*str
!= '\0') {
126 if (ISDIRDELIM(*str
)) return str
- start
;
134 * Match volume_info fs_type strings.
135 * Return 0 on match, -1 otherwise.
138 compare_sign(char *str1
, char *str2
)
140 char *end
= str1
+SIGNLEN
;
142 while (str1
!= end
) {
143 if (*str1
!= *str2
) {
155 * Extract zero terminated short name from a directory entry.
157 static void get_name (dir_entry
*dirent
, char *s_name
)
161 memcpy (s_name
, dirent
->name
, 8);
164 while (*ptr
&& *ptr
!= ' ')
166 if (dirent
->ext
[0] && dirent
->ext
[0] != ' ') {
169 memcpy (ptr
, dirent
->ext
, 3);
171 while (*ptr
&& *ptr
!= ' ')
175 if (*s_name
== DELETED_FLAG
)
177 else if (*s_name
== aRING
)
183 * Get the entry at index 'entry' in a FAT (12/16/32) table.
184 * On failure 0x00 is returned.
187 get_fatent(fsdata
*mydata
, __u32 entry
)
193 switch (mydata
->fatsize
) {
195 bufnum
= entry
/ FAT32BUFSIZE
;
196 offset
= entry
- bufnum
* FAT32BUFSIZE
;
199 bufnum
= entry
/ FAT16BUFSIZE
;
200 offset
= entry
- bufnum
* FAT16BUFSIZE
;
203 bufnum
= entry
/ FAT12BUFSIZE
;
204 offset
= entry
- bufnum
* FAT12BUFSIZE
;
208 /* Unsupported FAT size */
212 /* Read a new block of FAT entries into the cache. */
213 if (bufnum
!= mydata
->fatbufnum
) {
214 int getsize
= FATBUFSIZE
/FS_BLOCK_SIZE
;
215 __u8
*bufptr
= mydata
->fatbuf
;
216 __u32 fatlength
= mydata
->fatlength
;
217 __u32 startblock
= bufnum
* FATBUFBLOCKS
;
219 fatlength
*= SECTOR_SIZE
; /* We want it in bytes now */
220 startblock
+= mydata
->fat_sect
; /* Offset from start of disk */
222 if (getsize
> fatlength
) getsize
= fatlength
;
223 if (disk_read(startblock
, getsize
, bufptr
) < 0) {
224 FAT_DPRINT("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 __u32 off16
= (offset
*3)/4;
242 switch (offset
& 0x3) {
244 ret
= FAT2CPU16(((__u16
*)mydata
->fatbuf
)[off16
]);
248 val1
= FAT2CPU16(((__u16
*)mydata
->fatbuf
)[off16
]);
250 val2
= FAT2CPU16(((__u16
*)mydata
->fatbuf
)[off16
+1]);
252 ret
= (val2
<< 4) | (val1
>> 12);
255 val1
= FAT2CPU16(((__u16
*)mydata
->fatbuf
)[off16
]);
257 val2
= FAT2CPU16(((__u16
*)mydata
->fatbuf
)[off16
+1]);
259 ret
= (val2
<< 8) | (val1
>> 8);
262 ret
= FAT2CPU16(((__u16
*)mydata
->fatbuf
)[off16
]);;
263 ret
= (ret
& 0xfff0) >> 4;
271 FAT_DPRINT("ret: %d, offset: %d\n", ret
, offset
);
278 * Read at most 'size' bytes from the specified cluster into 'buffer'.
279 * Return 0 on success, -1 otherwise.
282 get_cluster(fsdata
*mydata
, __u32 clustnum
, __u8
*buffer
, unsigned long size
)
288 startsect
= mydata
->data_begin
+ clustnum
*mydata
->clust_size
;
290 startsect
= mydata
->rootdir_sect
;
293 FAT_DPRINT("gc - clustnum: %d, startsect: %d\n", clustnum
, startsect
);
294 if (disk_read(startsect
, size
/FS_BLOCK_SIZE
, buffer
) < 0) {
295 FAT_DPRINT("Error reading data\n");
298 if(size
% FS_BLOCK_SIZE
) {
299 __u8 tmpbuf
[FS_BLOCK_SIZE
];
300 idx
= size
/FS_BLOCK_SIZE
;
301 if (disk_read(startsect
+ idx
, 1, tmpbuf
) < 0) {
302 FAT_DPRINT("Error reading data\n");
305 buffer
+= idx
*FS_BLOCK_SIZE
;
307 memcpy(buffer
, tmpbuf
, size
% FS_BLOCK_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
* SECTOR_SIZE
;
326 __u32 curclust
= START(dentptr
);
327 __u32 endclust
, newclust
;
328 unsigned long actsize
;
330 FAT_DPRINT("Filesize: %ld bytes\n", filesize
);
332 if (maxsize
> 0 && filesize
> maxsize
) filesize
= maxsize
;
334 FAT_DPRINT("Reading: %ld bytes\n", filesize
);
336 actsize
=bytesperclust
;
339 /* search for consecutive clusters */
340 while(actsize
< filesize
) {
341 newclust
= get_fatent(mydata
, endclust
);
342 if((newclust
-1)!=endclust
)
344 if (newclust
<= 0x0001 || newclust
>= 0xfff0) {
345 FAT_DPRINT("curclust: 0x%x\n", newclust
);
346 FAT_DPRINT("Invalid FAT entry\n");
350 actsize
+= bytesperclust
;
352 /* actsize >= file size */
353 actsize
-= bytesperclust
;
354 /* get remaining clusters */
355 if (get_cluster(mydata
, curclust
, buffer
, (int)actsize
) != 0) {
356 FAT_ERROR("Error reading cluster\n");
359 /* get remaining bytes */
360 gotsize
+= (int)actsize
;
364 if (get_cluster(mydata
, endclust
, buffer
, (int)actsize
) != 0) {
365 FAT_ERROR("Error reading cluster\n");
371 if (get_cluster(mydata
, curclust
, buffer
, (int)actsize
) != 0) {
372 FAT_ERROR("Error reading cluster\n");
375 gotsize
+= (int)actsize
;
378 curclust
= get_fatent(mydata
, endclust
);
379 if (curclust
<= 0x0001 || curclust
>= 0xfff0) {
380 FAT_DPRINT("curclust: 0x%x\n", curclust
);
381 FAT_ERROR("Invalid FAT entry\n");
384 actsize
=bytesperclust
;
390 #ifdef CONFIG_SUPPORT_VFAT
392 * Extract the file name information from 'slotptr' into 'l_name',
393 * starting at l_name[*idx].
394 * Return 1 if terminator (zero byte) is found, 0 otherwise.
397 slot2str(dir_slot
*slotptr
, char *l_name
, int *idx
)
401 for (j
= 0; j
<= 8; j
+= 2) {
402 l_name
[*idx
] = slotptr
->name0_4
[j
];
403 if (l_name
[*idx
] == 0x00) return 1;
406 for (j
= 0; j
<= 10; j
+= 2) {
407 l_name
[*idx
] = slotptr
->name5_10
[j
];
408 if (l_name
[*idx
] == 0x00) return 1;
411 for (j
= 0; j
<= 2; j
+= 2) {
412 l_name
[*idx
] = slotptr
->name11_12
[j
];
413 if (l_name
[*idx
] == 0x00) return 1;
422 * Extract the full long filename starting at 'retdent' (which is really
423 * a slot) into 'l_name'. If successful also copy the real directory entry
425 * Return 0 on success, -1 otherwise.
427 __u8 get_vfatname_block
[MAX_CLUSTSIZE
];
429 get_vfatname(fsdata
*mydata
, int curclust
, __u8
*cluster
,
430 dir_entry
*retdent
, char *l_name
)
433 dir_slot
*slotptr
= (dir_slot
*) retdent
;
434 __u8
*nextclust
= cluster
+ mydata
->clust_size
* SECTOR_SIZE
;
435 __u8 counter
= (slotptr
->id
& ~LAST_LONG_ENTRY_MASK
) & 0xff;
438 while ((__u8
*)slotptr
< nextclust
) {
439 if (counter
== 0) break;
440 if (((slotptr
->id
& ~LAST_LONG_ENTRY_MASK
) & 0xff) != counter
)
446 if ((__u8
*)slotptr
>= nextclust
) {
450 curclust
= get_fatent(mydata
, curclust
);
451 if (curclust
<= 0x0001 || curclust
>= 0xfff0) {
452 FAT_DPRINT("curclust: 0x%x\n", curclust
);
453 FAT_ERROR("Invalid FAT entry\n");
456 if (get_cluster(mydata
, curclust
, get_vfatname_block
,
457 mydata
->clust_size
* SECTOR_SIZE
) != 0) {
458 FAT_DPRINT("Error: reading directory block\n");
461 slotptr2
= (dir_slot
*) get_vfatname_block
;
462 while (slotptr2
->id
> 0x01) {
465 /* Save the real directory entry */
466 realdent
= (dir_entry
*)slotptr2
+ 1;
467 while ((__u8
*)slotptr2
>= get_vfatname_block
) {
468 slot2str(slotptr2
, l_name
, &idx
);
472 /* Save the real directory entry */
473 realdent
= (dir_entry
*)slotptr
;
478 if (slot2str(slotptr
, l_name
, &idx
)) break;
479 } while (!(slotptr
->id
& LAST_LONG_ENTRY_MASK
));
482 if (*l_name
== DELETED_FLAG
) *l_name
= '\0';
483 else if (*l_name
== aRING
) *l_name
= 'å';
486 /* Return the real directory entry */
487 memcpy(retdent
, realdent
, sizeof(dir_entry
));
493 /* Calculate short name checksum */
495 mkcksum(const char *str
)
500 for (i
= 0; i
< 11; i
++) {
501 ret
= (((ret
&1)<<7)|((ret
&0xfe)>>1)) + str
[i
];
510 * Get the directory entry associated with 'filename' from the directory
511 * starting at 'startsect'
513 __u8 get_dentfromdir_block
[MAX_CLUSTSIZE
];
514 static dir_entry
*get_dentfromdir (fsdata
* mydata
, int startsect
,
515 char *filename
, dir_entry
* retdent
,
518 __u16 prevcksum
= 0xffff;
519 __u32 curclust
= START (retdent
);
520 int files
= 0, dirs
= 0;
522 FAT_DPRINT ("get_dentfromdir: %s\n", filename
);
527 if (get_cluster (mydata
, curclust
, get_dentfromdir_block
,
528 mydata
->clust_size
* SECTOR_SIZE
) != 0) {
529 FAT_DPRINT ("Error: reading directory block\n");
532 dentptr
= (dir_entry
*) get_dentfromdir_block
;
533 for (i
= 0; i
< DIRENTSPERCLUST
; i
++) {
534 char s_name
[14], l_name
[256];
537 if ((dentptr
->attr
& ATTR_VOLUME
)) {
538 #ifdef CONFIG_SUPPORT_VFAT
539 if ((dentptr
->attr
& ATTR_VFAT
) &&
540 (dentptr
->name
[0] & LAST_LONG_ENTRY_MASK
)) {
541 prevcksum
= ((dir_slot
*) dentptr
)
543 get_vfatname (mydata
, curclust
, get_dentfromdir_block
,
546 int isdir
= (dentptr
->attr
& ATTR_DIR
);
556 if (l_name
[0] != 0) {
563 printf (" %8ld %s%c\n",
564 (long) FAT2CPU32 (dentptr
->size
),
567 printf (" %s%c\n", l_name
, dirc
);
573 FAT_DPRINT ("vfatname: |%s|\n", l_name
);
577 /* Volume label or VFAT entry */
582 if (dentptr
->name
[0] == 0) {
584 printf ("\n%d file(s), %d dir(s)\n\n", files
, dirs
);
586 FAT_DPRINT ("Dentname == NULL - %d\n", i
);
589 #ifdef CONFIG_SUPPORT_VFAT
590 if (dols
&& mkcksum (dentptr
->name
) == prevcksum
) {
595 get_name (dentptr
, s_name
);
597 int isdir
= (dentptr
->attr
& ATTR_DIR
);
607 if (s_name
[0] != 0) {
614 printf (" %8ld %s%c\n",
615 (long) FAT2CPU32 (dentptr
->size
), s_name
,
618 printf (" %s%c\n", s_name
, dirc
);
624 if (strcmp (filename
, s_name
) && strcmp (filename
, l_name
)) {
625 FAT_DPRINT ("Mismatch: |%s|%s|\n", s_name
, l_name
);
629 memcpy (retdent
, dentptr
, sizeof (dir_entry
));
631 FAT_DPRINT ("DentName: %s", s_name
);
632 FAT_DPRINT (", start: 0x%x", START (dentptr
));
633 FAT_DPRINT (", size: 0x%x %s\n",
634 FAT2CPU32 (dentptr
->size
),
635 (dentptr
->attr
& ATTR_DIR
) ? "(DIR)" : "");
639 curclust
= get_fatent (mydata
, curclust
);
640 if (curclust
<= 0x0001 || curclust
>= 0xfff0) {
641 FAT_DPRINT ("curclust: 0x%x\n", curclust
);
642 FAT_ERROR ("Invalid FAT entry\n");
652 * Read boot sector and volume info from a FAT filesystem
655 read_bootsectandvi(boot_sector
*bs
, volume_info
*volinfo
, int *fatsize
)
657 __u8 block
[FS_BLOCK_SIZE
];
658 volume_info
*vistart
;
660 if (disk_read(0, 1, block
) < 0) {
661 FAT_DPRINT("Error: reading block\n");
665 memcpy(bs
, block
, sizeof(boot_sector
));
666 bs
->reserved
= FAT2CPU16(bs
->reserved
);
667 bs
->fat_length
= FAT2CPU16(bs
->fat_length
);
668 bs
->secs_track
= FAT2CPU16(bs
->secs_track
);
669 bs
->heads
= FAT2CPU16(bs
->heads
);
671 bs
->hidden
= FAT2CPU32(bs
->hidden
);
673 bs
->total_sect
= FAT2CPU32(bs
->total_sect
);
676 if (bs
->fat_length
== 0) {
678 bs
->fat32_length
= FAT2CPU32(bs
->fat32_length
);
679 bs
->flags
= FAT2CPU16(bs
->flags
);
680 bs
->root_cluster
= FAT2CPU32(bs
->root_cluster
);
681 bs
->info_sector
= FAT2CPU16(bs
->info_sector
);
682 bs
->backup_boot
= FAT2CPU16(bs
->backup_boot
);
683 vistart
= (volume_info
*) (block
+ sizeof(boot_sector
));
686 vistart
= (volume_info
*) &(bs
->fat32_length
);
689 memcpy(volinfo
, vistart
, sizeof(volume_info
));
691 /* Terminate fs_type string. Writing past the end of vistart
692 is ok - it's just the buffer. */
693 vistart
->fs_type
[8] = '\0';
695 if (*fatsize
== 32) {
696 if (compare_sign(FAT32_SIGN
, vistart
->fs_type
) == 0) {
700 if (compare_sign(FAT12_SIGN
, vistart
->fs_type
) == 0) {
704 if (compare_sign(FAT16_SIGN
, vistart
->fs_type
) == 0) {
710 FAT_DPRINT("Error: broken fs_type sign\n");
715 __u8 do_fat_read_block
[MAX_CLUSTSIZE
]; /* Block buffer */
717 do_fat_read (const char *filename
, void *buffer
, unsigned long maxsize
,
720 char fnamecopy
[2048];
724 fsdata
*mydata
= &datablock
;
726 __u16 prevcksum
= 0xffff;
728 int rootdir_size
, cursect
;
730 int files
= 0, dirs
= 0;
734 if (read_bootsectandvi (&bs
, &volinfo
, &mydata
->fatsize
)) {
735 FAT_DPRINT ("Error: reading boot sector\n");
738 if (mydata
->fatsize
== 32) {
739 mydata
->fatlength
= bs
.fat32_length
;
741 mydata
->fatlength
= bs
.fat_length
;
743 mydata
->fat_sect
= bs
.reserved
;
744 cursect
= mydata
->rootdir_sect
745 = mydata
->fat_sect
+ mydata
->fatlength
* bs
.fats
;
746 mydata
->clust_size
= bs
.cluster_size
;
747 if (mydata
->fatsize
== 32) {
748 rootdir_size
= mydata
->clust_size
;
749 mydata
->data_begin
= mydata
->rootdir_sect
/* + rootdir_size */
750 - (mydata
->clust_size
* 2);
752 rootdir_size
= ((bs
.dir_entries
[1] * (int) 256 + bs
.dir_entries
[0])
753 * sizeof (dir_entry
)) / SECTOR_SIZE
;
754 mydata
->data_begin
= mydata
->rootdir_sect
+ rootdir_size
755 - (mydata
->clust_size
* 2);
757 mydata
->fatbufnum
= -1;
759 FAT_DPRINT ("FAT%d, fatlength: %d\n", mydata
->fatsize
,
761 FAT_DPRINT ("Rootdir begins at sector: %d, offset: %x, size: %d\n"
762 "Data begins at: %d\n",
763 mydata
->rootdir_sect
, mydata
->rootdir_sect
* SECTOR_SIZE
,
764 rootdir_size
, mydata
->data_begin
);
765 FAT_DPRINT ("Cluster size: %d\n", mydata
->clust_size
);
767 /* "cwd" is always the root... */
768 while (ISDIRDELIM (*filename
))
770 /* Make a copy of the filename and convert it to lowercase */
771 strcpy (fnamecopy
, filename
);
772 downcase (fnamecopy
);
773 if (*fnamecopy
== '\0') {
777 } else if ((idx
= dirdelim (fnamecopy
)) >= 0) {
779 fnamecopy
[idx
] = '\0';
780 subname
= fnamecopy
+ idx
+ 1;
781 /* Handle multiple delimiters */
782 while (ISDIRDELIM (*subname
))
791 if (disk_read (cursect
, mydata
->clust_size
, do_fat_read_block
) < 0) {
792 FAT_DPRINT ("Error: reading rootdir block\n");
795 dentptr
= (dir_entry
*) do_fat_read_block
;
796 for (i
= 0; i
< DIRENTSPERBLOCK
; i
++) {
797 char s_name
[14], l_name
[256];
800 if ((dentptr
->attr
& ATTR_VOLUME
)) {
801 #ifdef CONFIG_SUPPORT_VFAT
802 if ((dentptr
->attr
& ATTR_VFAT
) &&
803 (dentptr
->name
[0] & LAST_LONG_ENTRY_MASK
)) {
804 prevcksum
= ((dir_slot
*) dentptr
)->alias_checksum
;
805 get_vfatname (mydata
, 0, do_fat_read_block
, dentptr
, l_name
);
806 if (dols
== LS_ROOT
) {
807 int isdir
= (dentptr
->attr
& ATTR_DIR
);
817 if (l_name
[0] != 0) {
824 printf (" %8ld %s%c\n",
825 (long) FAT2CPU32 (dentptr
->size
),
828 printf (" %s%c\n", l_name
, dirc
);
834 FAT_DPRINT ("Rootvfatname: |%s|\n", l_name
);
838 /* Volume label or VFAT entry */
842 } else if (dentptr
->name
[0] == 0) {
843 FAT_DPRINT ("RootDentname == NULL - %d\n", i
);
844 if (dols
== LS_ROOT
) {
845 printf ("\n%d file(s), %d dir(s)\n\n", files
, dirs
);
850 #ifdef CONFIG_SUPPORT_VFAT
851 else if (dols
== LS_ROOT
852 && mkcksum (dentptr
->name
) == prevcksum
) {
857 get_name (dentptr
, s_name
);
858 if (dols
== LS_ROOT
) {
859 int isdir
= (dentptr
->attr
& ATTR_DIR
);
865 if (s_name
[0] != 0) {
871 if (s_name
[0] != 0) {
878 printf (" %8ld %s%c\n",
879 (long) FAT2CPU32 (dentptr
->size
), s_name
,
882 printf (" %s%c\n", s_name
, dirc
);
888 if (strcmp (fnamecopy
, s_name
) && strcmp (fnamecopy
, l_name
)) {
889 FAT_DPRINT ("RootMismatch: |%s|%s|\n", s_name
, l_name
);
893 if (isdir
&& !(dentptr
->attr
& ATTR_DIR
))
896 FAT_DPRINT ("RootName: %s", s_name
);
897 FAT_DPRINT (", start: 0x%x", START (dentptr
));
898 FAT_DPRINT (", size: 0x%x %s\n",
899 FAT2CPU32 (dentptr
->size
), isdir
? "(DIR)" : "");
901 goto rootdir_done
; /* We got a match */
909 int startsect
= mydata
->data_begin
910 + START (dentptr
) * mydata
->clust_size
;
912 char *nextname
= NULL
;
917 idx
= dirdelim (subname
);
920 nextname
= subname
+ idx
+ 1;
921 /* Handle multiple delimiters */
922 while (ISDIRDELIM (*nextname
))
924 if (dols
&& *nextname
== '\0')
927 if (dols
&& firsttime
) {
934 if (get_dentfromdir (mydata
, startsect
, subname
, dentptr
,
935 isdir
? 0 : dols
) == NULL
) {
942 if (!(dentptr
->attr
& ATTR_DIR
))
947 ret
= get_contents (mydata
, dentptr
, buffer
, maxsize
);
948 FAT_DPRINT ("Size: %d, got: %ld\n", FAT2CPU32 (dentptr
->size
), ret
);
955 file_fat_detectfs(void)
963 printf("No current device\n");
966 #if (CONFIG_COMMANDS & CFG_CMD_IDE) || (CONFIG_COMMANDS & CFG_CMD_SCSI) || \
967 (CONFIG_COMMANDS & CFG_CMD_USB) || (CONFIG_MMC)
968 printf("Interface: ");
969 switch(cur_dev
->if_type
) {
970 case IF_TYPE_IDE
: printf("IDE"); break;
971 case IF_TYPE_SCSI
: printf("SCSI"); break;
972 case IF_TYPE_ATAPI
: printf("ATAPI"); break;
973 case IF_TYPE_USB
: printf("USB"); break;
974 case IF_TYPE_DOC
: printf("DOC"); break;
975 case IF_TYPE_MMC
: printf("MMC"); break;
976 default : printf("Unknown");
978 printf("\n Device %d: ",cur_dev
->dev
);
981 if(read_bootsectandvi(&bs
, &volinfo
, &fatsize
)) {
982 printf("\nNo valid FAT fs found\n");
985 memcpy (vol_label
, volinfo
.volume_label
, 11);
986 vol_label
[11] = '\0';
987 volinfo
.fs_type
[5]='\0';
988 printf("Partition %d: Filesystem: %s \"%s\"\n",cur_part
,volinfo
.fs_type
,vol_label
);
994 file_fat_ls(const char *dir
)
996 return do_fat_read(dir
, NULL
, 0, LS_YES
);
1001 file_fat_read(const char *filename
, void *buffer
, unsigned long maxsize
)
1003 printf("reading %s\n",filename
);
1004 return do_fat_read(filename
, buffer
, maxsize
, LS_NO
);
1007 #endif /* #if (CONFIG_COMMANDS & CFG_CMD_FAT) */