Solved

dos_getdiskfree and big drives under NT

Posted on 1997-03-03
1
616 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
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

763 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now