From 3d7d36cf914b1861a9af50c450a3edf4bb408ea8 Mon Sep 17 00:00:00 2001 From: Bart Oldeman Date: Mon, 26 Jan 2004 02:01:34 +0000 Subject: [PATCH] Using a FAT32 table so that FATs won't be too big for drives <= 64 GB git-svn-id: https://svn.code.sf.net/p/freedos/svn/kernel/trunk@754 6ac86273-5f31-0410-b378-82cca8765d1b --- kernel/initdisk.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/kernel/initdisk.c b/kernel/initdisk.c index bc9fdeb..e9986dc 100644 --- a/kernel/initdisk.c +++ b/kernel/initdisk.c @@ -501,10 +501,20 @@ VOID CalculateFATData(ddt FAR * pddt, ULONG NumSectors, UBYTE FileSystem) { unsigned long fatlength, clust, maxclust; - /* For FAT32, use 4k clusters on sufficiently large file systems, - * otherwise 1 sector per cluster. This is also what M$'s format - * command does for FAT32. */ - defbpb->bpb_nsector = (NumSectors >= 512 * 1024ul ? 8 : 1); + /* For FAT32, use the cluster size table described in the FAT spec: + * http://www.microsoft.com/hwdev/download/hardware/fatgen103.pdf + */ + unsigned sz_gb = (unsigned)(NumSectors / 2097152UL); + unsigned char nsector = 64; /* disks greater than 32 GB, 32K cluster */ + if (sz_gb <= 32) /* disks up to 32 GB, 16K cluster */ + nsector = 32; + if (sz_gb <= 16) /* disks up to 16 GB, 8K cluster */ + nsector = 16; + if (sz_gb <= 8) /* disks up to 8 GB, 4K cluster */ + nsector = 8; + if (NumSectors <= 532480) /* disks up to 260 MB, 0.5K cluster */ + nsector = 1; + defbpb->bpb_nsector = nsector; do { fatlength = cdiv(fatdata + 2 * defbpb->bpb_nsector,