Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on GetDiskFreeSpaceEx

Status
Not open for further replies.

Zyrenthian

Programmer
Mar 30, 2001
1,440
US
Hi all,
I am currently working on writing DVD's. The DVD's write fine but now the user gets an option to compress the data before storing it on the DVD. My validation option which did a bit for bit comparison no longer is valid. My fix for this was to create a temporary directory to store compressed images and when the situation waranted it, compare the data on the DVD with that temporary one.

Originally, I was re-doing the compression and comparing but by doing that, I am not only verifying the write to the DVD but my compression algorithm as well. Too much overhead! So working on the assumption that the compression algorithm is correct I now just call CopyFile(...) when a compression was performed.

My problem comes when the user specifies the temporary drive. Through the use of API calls I have found the local hard drives but I need to check if they have enough storage space incase EVERYTHING (worst case) is compressed. That means 4.7 gigs!

Through the use of GetDiskFreeSpaceEx I thought I could do this but I think the number is TOO large. I am testing GetDiskFreeSpaceEx against my G drive with these properties:

Used Space: 3,978,084,352 bytes 3.70 GB
Free Space: 26,751,528,960 bytes 24.9GB
Capacity: 30,729,613,312 bytes 28.6GB

I am using ULARGE_INTEGER and __i64toa but I dont seem to be getting the appropriate numbers. Can anyone give some suggestions???

Matt
 
Well... it was a stupid human error. It seems I mis_typed 1024 so my calculations were off. DOH! Everything is fully operational once again.

Matt
 
For those who search on this API call here is what I did:

const signed __int64 KB = 1024;
const signed __int64 MB = KB*KB;
const signed __int64 GB = KB*KB*KB;

...

ULARGE_INTEGER ulFreeBytesAvailableToCaller,
ulTotalNumberOfBytes,
ulTotalNumberOfFreeBytes;

GetDiskFreeSpaceEx((LPCTSTR)driveLetter /* format "C:\" */
&ulFreeBytesAvailableToCaller,
&ulTotalNumberOfBytes,
&ulTotalNumberOfFreeBytes);

if(ulFreeBytesAvailableToCaller.HighPart & 1<<31)
{
// we are maxed out but we have a heck of alot of room
return 4.7; // min value I need... value not displayed
}

signed __int64 totalGigs = ulFreeBytesAvailableToCaller.QuadPart;

return ((double)totalGigs/ (double)GB);


// this is not an exact copy of the code as my code was
//doing some other extraneous things. This is just the
// basic idea. If you have questions zyrenthian@home.com

Matt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top