Re: FAT12 vs FAT16

Richard B. Johnson (root@analogic.com)
Fri, 22 Aug 1997 15:53:45 -0400 (EDT)


On Fri, 22 Aug 1997, Martin Mares wrote:

> Hi,
>
> > > Also, why doesn't the msdos fs simply look for the "FAT12" or "FAT16"
> > > string in the superblock? Seems dangerous to guess based on number
> > > of clusters.
> > >
> >
> > Because in early versions of DOS that string wasn't there. Now if the
> > string *IS* there it should be heeded, though...
>
> There are the following ways to determine FAT type:
>
> (1) "FAT12" or "FAT16" string in the boot block. Not reliable and not supported
> in all DOS versions.
>
> (2) "Sector/cluster count rules" -- described for example in the Tech Help.
> Varies between DOS versions. Even if you know the DOS version, you can still
> be wrong as the disk might have been formatted on a different version.
>
> (3) Partition type. Seems to be totally ignored by DOS and sometimes very
> unreliable as DOS's format command doesn't alter this during reformatting
> (if you create the partition by one DOS version and format it by another one,
> an inconsistency might arise).
>
> (4) Number of sectors per FAT -- this value must be correct as the root
> directory position is calculated from it, but it sometimes allows both
> possibilities (although such cases are very rare).
>
> (5) Number of 0xff's at the start of the FAT. As you can remember, the first
> two cluster numbers are reserved for special purposes and their FAT entries
> are set to 0xff with an exception of the first FAT byte which contains a media
> descriptor. If there are less than 3 0xff's, the FAT must be 12-bit. In other
> case, both types are possible.
>
> Have a nice fortnight
> --
> Martin `MJ' Mares <mj@gts.cz> http://atrey.karlin.mff.cuni.cz/~mj/
> Faculty of Math and Physics, Charles University, Prague, Czech Rep., Earth
> "Error: Compiler unable to abort!"
>

No No No No! Page 3-7 of the MS-DOS Technical information (the real
system integrator's manual) states:

"For disks containing more than 4085 clusters (note that
4085 is the correct number), a 16-bit FAT entry is used."

The number of clusters is calculated from the BPB in the boot record from
the BYTE Custer size and the rest of the information about the size
of the media. The number of sectors entry is the total of the media.
You perform the indicated operations which even provides for the
reserved sectors (like for the boot record), and come up with the
number of clusters.

This will always work. It must work. This is how MS-DOS knows the size
of the media.

typedef struct {
unsigned char[3]; /* 3-byte jump */
char oem_name[8]; /* Name, version */
unsigned short bytes_sector;
unsigned char sect_per_alloc_unit;
unsigned short reserved_sects;
unsigned char num_FATs;
unsigned short root_dir_entries;
unsigned short num_sectors;
unsigned char media;
unsigned short FAT_sectors;
unsigned short sectors_track;
unsigned short num_heads;
unsigned short hidden_sectors;
} BOOT_REC;

I used to get paid for making strange media work on MS-DOS. This will
always work. The media descriptor doesn't mean anything any more nor
does the OEM Name, etc. However the other information is updated in
this table when the disk is formatted. The boot record loading code
with a 360 kb floppy boot-record BPB is used by FORMAT, etc. It is
modified before being written to the physical media. This same boot
record is used for all MS-DOS media and is modified before being written.

You can copy the boot record from a 1.2 mb floppy to a 1.44 mb floppy
and you will find that MS-DOS thinks it is now a 1.2 mb floppy. You
can use format/u to reformat it "as-is", and it is now a 1.2 mb floppy!

Cheers,
DJ
Richard B. Johnson
Analogic Corporation
Penguin : Linux version 2.1.51 on an i586 machine (66.15 BogoMips).
Warning : It's hard to stay on the trailing edge of technology.
Linux : Engineering tool
Windows : Typewriter