On Sun, Jan 25, 2026 at 5:41 PM Michael Brutman via Freedos-devel
<[email protected]> wrote:
>
> In the BIOS Parameter Block 'sectors per cluster' is a single byte. The
> change here allows a '0' value to be interpreted as 256. So in theory, that
> allows for a FAT16 or FAT32 partition to be almost 8G in size. The math is
> 256 sectors per cluster * 512 bytes per sector * 65536 clusters. (Some
> cluster numbers are reserved, so it doesn't quite reach 8T.)
>
> That change is going to break older tools that expect to see a maximum of 64
> or 128 sectors per cluster. Microsoft always recommended 64 as the maximum,
> which is where we get the familiar 2GB limit for FAT16 or 32 partitions. Is
> this change worth the potential breakage?
>
>
> Mike
>
The patch allows the FreeDOS kernel to not itself break should it
encounter such a filesystem (though there may be other places in the
kernel itself that have yet to be updated, didn't check and I don't
recall since this patch went in over 2 years ago). Currently a value
of 0 is simply an impossible file system, i.e. a cluster of 0 sectors
or 0 size, with this change the FreeDOS kernel is more compatible with
file systems created by EDR-DOS with the trade off of a small risk of
allowing a corrupt filesystem (actually invalid BPB with 0 here
meaning 0 or uninitialized) vs being unable to use a valid one.
Someone using older tools on such a filesystem would already have
issues without this patch, so to me the potential breakage it creates
is minimal. The real concern would be if such file systems are
created such as with format without it adequately providing a warning
of incompatibilities and this we may need to address.
The patch in question is:
--- a/kernel/fatfs.c
+++ b/kernel/fatfs.c
@@ -1584,13 +1584,17 @@ VOID bpb_to_dpb(bpb FAR * bpbp, REG struct dpb
FAR * dpbp)
bpb sbpb;
fmemcpy(&sbpb, bpbp, sizeof(sbpb));
- for (shftcnt = 0; (sbpb.bpb_nsector >> shftcnt) > 1; shftcnt++)
- ;
+ if (sbpb.bpb_nsector == 0) {
+ shftcnt = 8;
+ } else {
+ for (shftcnt = 0; (sbpb.bpb_nsector >> shftcnt) > 1; shftcnt++)
+ ;
+ }
dpbp->dpb_shftcnt = shftcnt;
dpbp->dpb_mdb = sbpb.bpb_mdesc;
dpbp->dpb_secsize = sbpb.bpb_nbyte;
- dpbp->dpb_clsmask = sbpb.bpb_nsector - 1;
+ dpbp->dpb_clsmask = (sbpb.bpb_nsector - 1) & 0xFF;
dpbp->dpb_fatstrt = sbpb.bpb_nreserved;
dpbp->dpb_fats = sbpb.bpb_nfat;
dpbp->dpb_dirents = sbpb.bpb_ndirent;
--
Jeremy
_______________________________________________
Freedos-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freedos-devel