Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dos_getdiskfree and big drives under NT

Posted on 1997-03-03
1
Medium Priority
?
628 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

604 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