info-mtools
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Info-mtools] Bug: mformat does not format FAT32 correctly


From: Pali Rohár
Subject: Re: [Info-mtools] Bug: mformat does not format FAT32 correctly
Date: Thu, 9 Aug 2018 13:38:46 +0200
User-agent: NeoMutt/20170113 (1.7.2)

Hi! Just a reminding for these 3 problems in mformat...

Correct solution for problem 3) (= calculation of cluster size on FAT32)
will solve also problem 2). And I would suggest to use same calculation
algorithm for FAT32 as for FAT16.

And for problem 1), it would be really nice to choose some sane C/H/S
defaults when creating hard disk image or when formatting non-C/H/S
disk. As it really does not make sense to ask user for supplying C/H/S
geometry when formatting disk.

Even MS format.exe and Windows GUI tools does not ask user for C/H/S
geometry when formatting SSD disk.

On Tuesday 12 December 2017 10:41:26 Pali Rohár wrote:
> On Monday 04 December 2017 19:29:53 Pali Rohár wrote:
> > Hi!
> > 
> > I observed 3 problems when I tried to create FAT32 disk image with
> > mformat tool:
> > 
> > 
> > 1) mformat is not able to format disk images without specifying C/H/S
> > geometry. Nowadays there is no hard disk or SSD disk which use C/H/S
> > geometry and therefore asking user for such thing does not make sense.
> > 
> > So what I used is to specify 64 heads and 32 sectors per track just to
> > easily calculates number of tracks on disk. For disk with logical sector
> > size as 512 bytes (which is probably for all HDD and SSD), number of
> > tracks would be size of disk in megabytes (64*32*512 = 1 megabyte).
> > 
> > So mformat parameters: -h 64 -s 32 -t SIZE_IN_MB
> > Probably it is also needed to specify (for hard disks): -m 0xf8
> > 
> > If you do not enter this C/H/S geometry mformat just show error message:
> > 
> > mformat: Unknown geometry (You must tell the complete geometry of the
> > disk, either in /etc/mtools.conf or on the command line)
> > 
> > I think that except this error message, mformat for hard drives should
> > use above C/H/S auto-calculation.
> > 
> > 
> > 
> > 2) mformat refuse to create FAT32 if disk size is less then 257 MB.
> > 
> > Test to reproduce (-F means to format as FAT32):
> > 
> >   $ truncate -s 100M fat.img
> >   $ mformat -F -h 64 -s 32 -t 100 -m 0xf8 :: -i fat.img
> > 
> > mformay show just error message:
> > 
> > Too few clusters for this fat size. Please choose a 16-bit fat in your
> > /etc/mtools.conf or .mtoolsrc file
> > 
> > Fix is to set size of cluster (in number of sectors) to 1. So mformat
> > parameter: -c 1
> > 
> > It is pity that mformat cannot calculate cluster size for smaller FAT32
> > disks (when size is less then 257 MB). Note that mformat can calculate
> > it correctly for FAT16 (when -F is not used).
> > 
> > 
> > 
> > 3) Cluster size is not calculated correctly according to Microsoft FAT
> > specification. This also answer why there is a bug 2).
> > 
> > Function which calculate cluster size is named calc_cluster_size and can
> > be found in mformat.c source code. Relevant part for FAT32 is:
> > 
> >     switch(abs(fat_bits)) {
> > ...
> >             case 32:
> >                     Fs->cluster_size = 8;
> >                     /* According to
> >                      * 
> > http://support.microsoft.com/support/kb/articles/q154/9/97.asp
> >                      * Micro$oft does not support FAT32 with less than 4K
> >                      */
> >                     return;
> > ...
> > 
> > It means that cluster size is hardcoded to 8 sectors for FAT32. This is
> > also reason for problem 3). For FAT16 there is autodetection code. I do
> > not know what that comment mean or what it try to refer as link is dead.
> > 
> > So I would like to know, why is hardcoded 8 sectors as cluster size for
> > FAT32? I suspect this is a bug which needs fixing. At least to have
> > working mformat in FAT32 mode for small disk (or disk images).
> 
> Also please note that current versions of Windows (probably since 2000)
> allow user to specify cluster size in Format dialog also for FAT32. And
> default value depends on disk size, it is not hardcoded to 8 (=4kB).
> 
> See also:
> https://support.microsoft.com/en-us/help/192322/description-of-default-cluster-sizes-for-fat32-file-system
> https://support.microsoft.com/en-us/help/140365/default-cluster-size-for-ntfs--fat--and-exfat
> 
> So I would really suggest to change above hardcoded value 8 to either
> mapping table or use similar algorithm as is already present for FAT16
> in mformat.c
> 
> > Because, in Microsoft FAT32 specification (fatgen103.doc) on page 20 for
> > FAT32 is written calculation table. For disk size there is cluster size
> > (in number of sectors), see table below:
> > 
> > 32.5 MB - 260 MB   cluster_size =  1
> >  260 MB -   8 GB   cluster_size =  8
> >    8 GB -  16 GB   cluster_size = 16
> >   16 GB -  32 GB   cluster_size = 32
> >   32 GB -   2 TB   cluster_size = 64
> > 
> > Note that in that Microsoft FAT specification is written: "The rest of
> > this section is totally specific to drives that have 512 bytes per
> > sector.". So there is need to recalculate values when (logical) sector
> > size is not 512 bytes.
> > 
> 

-- 
Pali Rohár
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]