Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 635
  • Last Modified:

dos_getdiskfree and big drives under NT


I have to write a 16-bit program that should run under Win3.x, 95 and NT (MS-VC++ 1.51 or BC++ 3.1) that shows a disk drive size.

Here it is:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
/* DISK.C: This program displays information about the
   default disk drive.  */
#include <stdio.h>
#include <dos.h>

void main( void )
{  struct _diskfree_t drive;
   double TotSpace;

   _dos_getdiskfree( 0, &drive );
   TotSpace = (double) drive.total_clusters *
              (double) drive.sectors_per_cluster *
              (double) drive.bytes_per_sector;
   printf( "tot clusters : %u\n", drive.total_clusters );
   printf( "sect/cluster: %u\n",drive.sectors_per_cluster );
   printf( "bytes/sector: %u\n", drive.bytes_per_sector );
   printf( "total space : %lf\n", TotSpace );
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Under Win3.x and 95 the program works fine as well as under NT for small drives (850 Mb). But for bigger ones (1.2 Gb) under NT, the dos function _dos_getdiskfree() (dos_getdiskfree() under BC++3.1) always
returns a bad number of 31249 clusters (976.5 Mb - wrong).
I find this problem under NT3.51 or NT4.0.
 
I don't think it's a 16 bits limitation (the number of clusters is unsigned so : 65535 max clusters * 512 bytes/sector * 64 sectors/cluster > 2Gb and I should be able to get the drive space correctly).
 
- Is it a NT (un)known bug ? (If the answer is yes,
  does the MS Service Packs correct the problem .)
- Is there a work-around (remember the program MUST run
  under Win3.x, 95 and NT so ONLY 16BIT functions are
  allowed) ?

0
tintin022697
Asked:
tintin022697
1 Solution
 
jrcookCommented:
I compiled your program using BC 5.0.  I tested it undef Win95 and WinNT 3.51.  I verified that it fails to report the correct answer for a large disk on NT.  I tried it on a 3.1GB NTFS drive.

If your problem only occurs on an NTFS drive (not FAT), then the problem might be that NTFS can use more than 64K clusters on a drive.  Thus, returning the number of clusters to a 16-bit unsigned WILL overflow.

FAT drives are limited to 64K clusters, NTFS is not.  If this is your problem, there is no workaround, and 16-bit is not going to give you the correct answer.  Sorry.

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now