Solved

dos_getdiskfree and big drives under NT

Posted on 1997-03-03
1
621 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

738 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