views:

241

answers:

2

I want to get the free space on a compressed disk to show it to a end user. I'm using C++, MFC on Windows 2000 and later. The Windows API offers the GetDiskFreeSpaceEx() function.

However, this function seems to return the "uncompressed" sized of the data. This cause me some problem.

For example : - Disk size is 100 GB - Data size is 90 GB - Compressed data size is 80 GB

The user will see that the disk is 90% full, but in reality, it is only 80% full.


EDIT

As Gleb pointed out, the function is returning the good information.

So here is the new question : is there a way to get both the compressed size and the uncompressed one?

+1  A: 

The function returns the amount of free space correctly. It can be demonstrated by using this simple program.

#include <stdio.h>
#include <windows.h>

void main() {
    ULARGE_INTEGER p1, p2, p3;
    GetDiskFreeSpaceEx(".", &p1, &p2, &p3);
    printf("%llu %llu %llu\n", p1, p2, p3);
}

After compressing a previously uncompressed directory the free space grows.

So what are you talking about?

Gleb
+1  A: 

I think you would have to map over all files, query with GetFileSize() and GetCompressedFileSize() and sum them up. Use GetFileAttributes() to know if a file is compressed or not, in case only parts of the whole volume is compressed, which might certainly be the case.

Hum, so that's not a trivial operation. I suppose I must implement some mechanism to avoid querying all files size all the time. I mean ... if I have a 800GB hard drive, it could take some very long time to get all file size.

True.

Perhaps start off by a full scan (application startup) and populate your custom data structure, e.g. a hash/map from file name to file data struct/class, then poll the drive with FindFirstChangeNotification() and update your internal structure accordingly.

You might also want to read about "Change Journals". I have never used them myself so don't know how they work, but might be worth checking out.

Magnus Skog
Hum, so that's not a trivial operation. I suppose I must implement some mechanism to avoid querying all files size all the time.I mean ... if I have a 800GB hard drive, it could take some very long time to get all file size.
Nicolas
Added a comment to your note. See my post.
Magnus Skog