TIP: Click on subject to list as thread! ANSI
echo: 4dos
to: PETER HOLM
from: JONATHAN DE BOYNE POLLARD
date: 1998-04-06 11:00:00
subject: 4DOS, DIR, HPFS and large partitions.

 PH> Now the 4DOS-Dir, without any parameter, in a DOS-box.
 PH>
 PH>  Volume in drive F is unlabeled      Serial number is A77C:E015
 PH>  Directory of  f:\flats\*.*
 PH> [...]
 PH>       882.102 bytes in 5 files and 2 dirs    1.048.576 bytes allocated
 PH> 2.480.930.816 bytes free
 PH> 4DOS-Dir with parameter p, in a DOS-box.
 PH>
 PH>  Volume in drive F is unlabeled      Serial number is A77C:E015
 PH>  Directory of  f:\flats\*.*
 PH> [...]
 PH>       882.102 bytes in 5 files and 2 dirs    1.048.576 bytes allocated
 PH> 2.480.930.816 bytes free
 PH> 4OS2-Dir, no parameter, in an OS2-box.
 PH>
 PH>  Volume in drive F is unlabeled      Serial number is A77C:E015
 PH>  Directory of  F:\flats\*
 PH> [...]
 PH>       882.102 bytes in 5 files and 2 dirs    883.712 bytes allocated 
 PH> 2.480.994.304 bytes free
 PH> So, as you can see, 4OS2 gives correct results, 4DOS doesn't.
That's because, unfortunately, whilst the DOS INT 21h API is capable of 
reporting freespace and size information anywhere up to 2 Terabytes, it works 
in terms of clusters.  A DOS program is handed the "cluster size" and "free 
clusters" for a drive, and is expected to multiply those two values together 
to obtain the free space in bytes.  Because the "free clusters" value is (in 
fact, both values are) a 16-bit unsigned integer, and so cannot be larger 
than 65535, in order to report large free space values on large HPFS 
partitions OS/2's VDM DOS kernel simply increases the cluster size value that 
it will report sufficiently so that the "total clusters" value is below 
65536.  
If you've ever looked at the FAT16 filesystem format, this will be a very 
familiar kludge.  Because FAT16 can hold a maximum of 65533 clusters, 
resulting in a maximum partition size of 32MB when there is 1 sector per 
cluster, in order to accommodate larger partitions the cluster size of FAT16 
is progressively doubled until the number of clusters required is below 
65534, up to a limit of 32KB per cluster (Hence the 2GB partition size limit 
of FAT16.).  There's no real reason why it should stop there, and I suspect 
that the DOS limit of 32KB per cluster imposed upon FAT16 is a consequence of 
the 16-bit nature of DOS and the 64KB limits that this imposes upon its 
internal disk buffering code and data structures.
Unfortunately, because the DOS INT 21h API is restricted to working in terms 
of whole clusters, this means that the free space values calculated by DOS 
programs from the values returned will be rounded to the nearest whole 
cluster.  With FAT volumes on OS/2, FAT will be using the same clustering 
scheme as the DOS INT 21h API is, and so the "real" figures will already be 
rounded to a whole number of clusters.  
HPFS, on the other hand, doesn't use clustering (It allocates space in units 
of 1 sector, whatever the partition size.), and so the rounding of its free 
space values obtained from the OS/2 kernel to nearest "cluster" -- where the 
size of a cluster is calculated by the DOS virtual machine layer such that 
there are always less than 65536 clusters in total -- is noticable, as you 
have found above.
Summary:
This isn't a bug in 4DOS, and it isn't a bug in OS/2 either.  It's something 
that is forced upon one by the original design of the DOS INT21h API when one 
wants to map that API onto filesystems that don't work in the way that FAT 
does.  This is, in fact, a problem of long standing, and one not restricted 
to OS/2 at all.  People running DOS LANs talking to Netware or UNIX NFS file 
servers with large volumes see exactly the same effect as do OS/2 users 
running DOS programs on HPFS in OS/2 VDMs, because neither Netware nor UNIX 
use the same clustering scheme as FAT16 and the DOS INT21h API do, and the 
DOS LAN software thus has to do the same sort of manipulation of the *real* 
free space and size values to achieve "16-bit compatible" ones as does the 
DOS VDM layer in OS/2.
So if you want to measure free space accurately, without the DOS INT 21h API 
forcing the figured to be rounded to the nearest whole "cluster", use a 
native OS/2 program, such as 4OS2 or Take Command for OS/2.
 ¯ JdeBP ®
--- FleetStreet 1.19 NR
---------------
* Origin: JdeBP's point, using Squish (2:440/4.3)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.