Solved

dos_getdiskfree and big drives under NT

Posted on 1997-03-03
1
618 Views
Last Modified: 2011-10-03

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
Comment
Question by:tintin022697
1 Comment
 

Accepted Solution

by:
jrcook earned 200 total points
ID: 1249523
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question