Solved

Space on hard disc drive used by file system

Posted on 1998-05-01
20
403 Views
Last Modified: 2013-12-03
A small amount of space on each hard disc drive is reserved for use by the file system.  The size of this can be shown by running the DOS command CHKDSK.  For FAT drives, CHKDSK shows it as "... bytes in ... directories".  For NTFS drives, CHKDSK shows it as "... kilobytes in ... indexes", "... kilobytes in use by the system." and "... kilobytes occupied by the logfile."  I would like to know which Win32 API function I can use to get the same information.
0
Comment
Question by:SimonORorke
  • 8
  • 7
  • 2
  • +3
20 Comments
 
LVL 11

Expert Comment

by:mikeblas
ID: 1398538
You need to walk the file system yourself if you need this information, as the operating doesn't expose documented APIs that provide it. (It's odd information to need, and in the case of WinNT, it's not very safe to worry about.)

.B ekiM


0
 

Author Comment

by:SimonORorke
ID: 1398539
I have already looked at the Win32 Programmer's reference and did not spot an API function that looked like it could do it.  So, yes, I did suspect that any API function or combination of functions that would do the trick might be undocumented.  But some people seem to know about undocumented API functions...  I agree that it is odd information to need.  But I have a (totally innocent) reason!
0
 
LVL 2

Expert Comment

by:lortega
ID: 1398540
if you are using Delphi you can use DiskFree and if you are using Borland C you can use getdfree, at this time iam not sure if MSCompiler can suport this function...
note: this is not an API but have support to win16 and win32...

#include <dos.h>
void getdfree(unsigned char drive, struct dfree *dtable);

struct dfree {
   unsigned df_avail;     /* available clusters */
   unsigned df_total;     /* total clusters */
   unsigned df_bsec;      /* bytes per sector */
   unsigned df_sclus;     /* sectors per cluster */
};

i hope this will help you,
lortega
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1398541
That information doesn't answer the question, lortega. It doesn't include the amount of space reserved by the operating system, or used by on-disk data structures.

.B ekiM

0
 

Author Comment

by:SimonORorke
ID: 1398542
mikeblas is correct:  GetDiskFreeSpace does not give the information I want.
0
 

Expert Comment

by:jhjeon
ID: 1398543
Use GetDiskFreeSpace API Fuction.

ex)

GetDiskFreeSpace("c:\\",&a,&b,&c,&d);

FreeSpce = a*b*c;
TotalSpace = a*b*d;

ok ?
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1398544
Uh, didn't you read the previous comments, jhjeon?

..B ekiM

0
 
LVL 1

Expert Comment

by:Blondie050798
ID: 1398545
From the experience that I have had with a similar problem, you have to recursively add up the space used....it doesn't actually take too long, but it would be nice if there was a simple one line function call.. :-)
0
 

Author Comment

by:SimonORorke
ID: 1398546
Can you explain how to find the pieces of space to add up?  If I have to scan the whole drive, it may take too long for my purpose.  Biut I would like to find out more.  This is for a new version of Folder Sizer, my freeware disc space analysis program.  The program calculates the physical size of each folder tree.  But it never adds up exactly to the drive size minus the free space.  One reason is the space used by the system.  I was hoping to show this as well, for completeness.  But if I cannot do it, or it takes too long, I shall do without it!
0
 
LVL 1

Expert Comment

by:Blondie050798
ID: 1398547
Surely if you know the amount of space that is used for all the folders, and you know the free space and the total disc size, you can effectively say the remainder is for the system?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 11

Expert Comment

by:mikeblas
ID: 1398548
Part of the remaining space might be bad sectors.

Like I said a couple of weeks ago, you have to crawl the disk structures yourself if you want this info. And, yes: it can take a very long time!

..B ekiM

0
 

Author Comment

by:SimonORorke
ID: 1398549
As mikeblas says, part of the remaining space might be bad sectors.  Other possible parts I have thought of are: (1) lost clusters, which, as opposed to bad ones, can be recovered for use, for example by SCANDISK;  (2) unavoidable inaccuracies in the way I calculate physical file sizes (the inaccuracy, if any, would always be in the direction of underestimation).  This will all be extensively explained in the help file of Folder Sizer 2.0.

Now I would like to explore mikeblas's comment that "you have to crawl the disk structures yourself if you want this info".  Well, in a way, my program already does.  I have to navigate to the end of every branch of the tree of folders in order to include the size of each file in the appropriate tree sizes and folder sizes.  Now, if there was something extra I could do while navigating the folder tree to also pick up the system space (and possibly even the bad and lost clusters), it might not add much to the overall time taken.  However, I suspect that what mikeblas terms "crawling the disc structures" is a completely different procedure compared to what I am already doing.  Is that correct?

If so, it would presumably at least double the time taken. CHKDSK is the quickest way I know to discover the amount of system space.  If a comparison with that is anything to go by, the time taken would much more than double.  Unless I can pick up the system space using the navigation I am already doing, it will not be worth attemting.  

If you can clarify this, mikeblas, please pose your comment as an answer.  I would consider my question answered as far as I need it.  I would probably rate you're your answer "satisfactory".  This feels like a strange thing to have to decide:  I reckon I should only give a rating of "excellent" for an actual way to get the system space size;  but maybe that is unfair if I have concluded that it is not feasible in the context of what I am doing.  I dunno!
0
 
LVL 1

Expert Comment

by:lekshmikr
ID: 1398550
The GetDiskFreeSpaceEx function could give u  info about the amount of space available on a disk volume: the total amount of space, the total amount of free space

0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1398551
Didn't you read any of the previous responses, lekshmikr?  GetDiskFreeSpaceEx() won't provide the information SimonORorke is asking for.

..B ekiM
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1398552
By "crawling the disk structures", I mean that you'll need to do the low-level analysis yourself. That is, you'll have to read the FAT and directory structures and add things up yourself.  Or, you'll need to get Helen Custer's NTFS book and do the same thing for the NTFS structures.

Adding up directory totals will make it hard to get the right answer; there's rounding, hidden space, reserved space, the NTFS index pages, and all sorts of stuff.

Maybe your best alternative, if you really must do this, is to run spawn CHKDSK and capture it's output. Of course, that leaves you in the lurch if CHKDSK finds any errors.

..B ekiM

0
 

Author Comment

by:SimonORorke
ID: 1398553
As already explained in previous comments, GetDiskFreeSpace does not provide the infomation I need.
0
 

Author Comment

by:SimonORorke
ID: 1398554
I think I have heard enough now.  Thanks for the explanations mikeblas.  I had considered spawning CHKDSK and trapping its result.  But it sounds too risky and would be too slow anyway.  And it is clear that any other method would make my program run for much too slowly for what it is worth to me.  Unless anyone else has any brilliant suggestions (i.e. not GetDiskFreeSpace!), I shall withdraw the question in a couple of days.
0
 
LVL 11

Expert Comment

by:mikeblas
ID: 1398555
I didn't intend to offer my answers, insight, and advice for free.

..B ekiM

0
 

Author Comment

by:SimonORorke
ID: 1398556
I am puzzled by mikeblas's latest comment.  As I said in a previous comment, I am quite willing to give you points, mikeblas.  But, as I said, you will have to pose your comments as an answer so that I can give you the points.  On the other hand, I have not used Experts Exchange much:  so may be there is a trick to it that I have not understood.  If so, please let me know what i need to do.  Otherwise, send an answe,r as I suggested.
0
 
LVL 11

Accepted Solution

by:
mikeblas earned 200 total points
ID: 1398557
I made that comment because you said you would "withdraw the question in a couple of days".  If you withdraw the question, nobody gets points.

..B ekiM
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

12 Experts available now in Live!

Get 1:1 Help Now