[OpenBIOS] r737 - ofw/fs/fatfs
svn at openbios.org
svn at openbios.org
Tue Nov 20 00:48:42 CET 2007
Author: wmb
Date: 2007-11-20 00:48:42 +0100 (Tue, 20 Nov 2007)
New Revision: 737
Modified:
ofw/fs/fatfs/device.fth
Log:
OLPC trac 5022 - Fixed FAT size determination code in the face of
crazy media type values, using Microsoft's recommended algorithm
for determining whether to use FAT-12, FAT-16, or FAT-32.
Modified: ofw/fs/fatfs/device.fth
===================================================================
--- ofw/fs/fatfs/device.fth 2007-11-18 03:54:48 UTC (rev 736)
+++ ofw/fs/fatfs/device.fth 2007-11-19 23:48:42 UTC (rev 737)
@@ -121,6 +121,9 @@
then
;
+\ This version of read-bpb implements Microsoft's recommended
+\ method for determining whether a filesystem is FAT-16 or FAT-32.
+variable nsects
: ?read-bpb ( -- )
/sector 0= if \ Read bpb if necessary
init-sector-size
@@ -132,25 +135,14 @@
then
bp_bps lew@ bps w!
bp_spc c@ spc c!
- bp_spf lew@ ?dup if
- media c@ h# f8 = if
- dup d# 12 < if fat12 else fat16 then
- else
- fat12
- then 0 0
- 0 fsinfo ! 0 fssector ! false fsinfos-dirty c!
- else
- bp_bspf lel@ fat32
- bp_rdirclus lel@
- bp_fsinfos lew@ dup read-fsinfo
- then
- fsinfos w!
- rdirclus l!
- fat-type c!
- spf l!
+ bp_spf lew@ ?dup 0= if bp_bspf lel@ then spf l!
+ bp_nsects lew@ ?dup 0= if bp_xnsects lel@ then nsects l!
- init-fat-cache
+ bp_ndirs lew@ /dirent * /sector 1- + /sector / #dir-sectors w!
+ \ nsects is TotSec
+ \ #dir-sectors is RootDirSectors
+
\ Sector number where the FAT starts.
\ bp_nhid is the number of sectors before the BPB sector.
\ bp_res is the number of sectors from the BPT sector to the
@@ -158,17 +150,24 @@
\ If the underlying disk driver handles partition offsets,
\ we don't need to handle bp_nhid here.
- bp_res lew@ ( bp_nhid lel@ + ) fat-sector0 w!
+ bp_res lew@ ( bp_nhid lel@ + )
+ dup fat-sector0 w! ( #resv-sectors )
+ spf l@ bp_nfats c@ * + ( #early-sectors )
+ dup dir-sector0 w! ( #early-sectors )
+ #dir-sectors w@ + cl-sector0 l! ( )
- rdirclus @ ?dup if
- dv_cwd-cl l!
+ \ cl-sector0 is FirstDataSector
+
+ nsects l@ #dir-sectors w@ - spc c@ / ( #clusters )
+ dup d# 65525 >= if ( #clusters )
+ drop fat32 fat-type c!
0 dir-sector0 w!
- 0 #dir-sectors w!
- spf l@ bp_nfats c@ * fat-sector0 w@ + cl-sector0 l!
+ bp_rdirclus lel@ rdirclus l!
+ bp_fsinfos lew@ dup read-fsinfo fsinfos w!
else
- spf l@ bp_nfats c@ * fat-sector0 w@ + dir-sector0 w!
- bp_ndirs lew@ /dirent * /sector / #dir-sectors w!
- dir-sector0 w@ #dir-sectors w@ + cl-sector0 l!
+ d# 4085 >= if fat16 else fat12 then fat-type c!
+ 0 fsinfo ! 0 fssector ! false fsinfos-dirty c!
+ 0 fsinfos w! 0 rdirclus l!
then
\ The number of clusters is limited both by space for clusters numbers
@@ -180,16 +179,22 @@
spf l@ /sector * bytes>cl-entries ( #clusters )
\ Compare it with the number of clusters for which there is disk space
- bp_nsects lew@ ?dup 0= if bp_xnsects lel@ then
+ nsects l@
cl-sector0 l@ - spc c@ / 2 + min 1-
max-cl# l!
free-bpb
+
+ \ Start with the root directory as the current working directory
+ rdirclus @ dv_cwd-cl l!
+
+ init-fat-cache
then
;
: set-device ( device# -- ) (set-device) ?read-bpb ;
\ : stand-init ( -- ) stand-init clear-device-records ;
+
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
\
More information about the OpenBIOS
mailing list