1. get free disk space in win32 -- Solved.
- Posted by ssallen Dec 20, 2009
- 1288 views
Hello again,
Another inane question from yours truly. What is the best way to get the amount of free disk space under win32? I checked the msdn reference and found the following function but have no idea how to wrap it. I tried digging through the internals of win32lib but couldn't find a reference to the PULARGE datatype. Any ideas? How does everyone else do it?
BOOL WINAPI GetDiskFreeSpaceEx( __in_opt LPCTSTR lpDirectoryName, __out_opt PULARGE_INTEGER lpFreeBytesAvailable, __out_opt PULARGE_INTEGER lpTotalNumberOfBytes, __out_opt PULARGE_INTEGER lpTotalNumberOfFreeBytes );
As always, your help is always appreciated!
Thanks in advance!
Steve A.
2. Re: get free disk space in win32
- Posted by LarryMiller Dec 20, 2009
- 1262 views
Hello again,
Another inane question from yours truly. What is the best way to get the amount of free disk space under win32? I checked the msdn reference and found the following function but have no idea how to wrap it. I tried digging through the internals of win32lib but couldn't find a reference to the PULARGE datatype. Any ideas? How does everyone else do it?
BOOL WINAPI GetDiskFreeSpaceEx( __in_opt LPCTSTR lpDirectoryName, __out_opt PULARGE_INTEGER lpFreeBytesAvailable, __out_opt PULARGE_INTEGER lpTotalNumberOfBytes, __out_opt PULARGE_INTEGER lpTotalNumberOfFreeBytes );
As always, your help is always appreciated!
Thanks in advance!
Steve A.
The PULARGE_INTEGER is a structure containing an unsigned 64 bit integer. A 32 bit value could hold only values up to 4GB, much too small for modern drives. You would obtain the value from it like this:
value=peek4u(pAddress) *#100000000 + peek4u(pAddress)
3. Re: get free disk space in win32
- Posted by LarryMiller Dec 20, 2009
- 1217 views
Correction: That should be:
value=peek4u(pAddress) * #100000000 + peek4u(pAddress+4)
4. Re: get free disk space in win32
- Posted by ssallen Dec 20, 2009
- 1233 views
Ok, I am getting the bad routine (-1) error. Anyone see something wrong with this?
constant kernel32 = open_dll( "kernel32.dll" ), xGetFreeSpace = define_c_func(kernel32, "GetDiskFreeSpaceEx", {C_POINTER, C_POINTER, C_POINTER, C_POINTER}, C_INT) global function get_drive_space(sequence mdir) atom strptr, ptr2, ptr3, ptr4 integer retx sequence rets strptr = allocate_string(mdir) ptr2 = allocate(8) ptr3 = allocate(8) ptr4 = allocate(8) retx = c_func(xGetFreeSpace, {strptr, ptr2, ptr3, ptr4}) if retx <= 0 then return {-1, -1} end if rets = {{0, 0}, {0, 0}, {0, 0}} rets[1][1] = peek4u(ptr2) rets[1][2] = peek4u(ptr2+4) rets[2][1] = peek4u(ptr2) rets[2][2] = peek4u(ptr2+4) rets[3][1] = peek4u(ptr2) rets[3][2] = peek4u(ptr2+4) return rets end function
Aside from needing to free the memory for those pointers I mean! :)
Thanks again!
Steve A.
5. Re: get free disk space in win32 ** Figured it out. Code inside for anyone else who wants to use it.
- Posted by ssallen Dec 20, 2009
- 1231 views
Correct Code follows:
New code:
constant kernel32 = open_dll( "kernel32.dll" ), xGetFreeSpace = define_c_func(kernel32, "GetDiskFreeSpaceExA", {C_POINTER, C_POINTER, C_POINTER, C_POINTER}, C_INT) global function get_drive_space(sequence mdir) atom strptr, ptr2, ptr3, ptr4 integer retx sequence rets strptr = allocate_string(mdir) ptr2 = allocate(8) ptr3 = allocate(8) ptr4 = allocate(8) retx = c_func(xGetFreeSpace, {strptr, ptr2, ptr3, ptr4}) if retx <= 0 then free(strptr) free(ptr2) free(ptr3) free(ptr4) return {-1, -1} end if rets = {{0, 0}, {0, 0}, {0, 0}} rets[1][1] = peek4u(ptr2) rets[1][2] = peek4u(ptr2+4) rets[2][1] = peek4u(ptr3) rets[2][2] = peek4u(ptr3+4) rets[3][1] = peek4u(ptr4) rets[3][2] = peek4u(ptr4+4) free(strptr) free(ptr2) free(ptr3) free(ptr4) return rets end function
and then...
sequence vals vals = get_drive_space(data_dir) if length(vals) < 3 then setText(txt2, "BAD DISK SPACE CHECK!") else setText(txt2, sprintf("Disk space is: %d", ((vals[3][2] * #100000000) + vals[3][1]))) end if
((vals[1][2] * #100000000) + vals[1][1])) - total number of free bytes on a disk that are available to the user who is associated with the calling thread. adjusted for per-user quotas
((vals[2][2] * #100000000) + vals[2][1])) - total number of bytes on a disk that are available to the user who is associated with the calling thread. ajusted for per-user quotas
((vals[3][2] * #100000000) + vals[3][1])) - total number of free bytes on a disk. DOES NOT adjust for per-user quotas.
Thanks to Larry! You Rock!
Steve A.
6. Re: get free disk space in win32
- Posted by jimcbrown (admin) Dec 20, 2009
- 1238 views
Hello again,
Another inane question from yours truly. What is the best way to get the amount of free disk space under win32?
Thanks in advance!
Steve A.
The easiest way might be to take the 4.0 library functions disk_size() and disk_metric() and adapt the code for user under 3.1
http://oe.cowgar.com/docs/eu400_0055.html#_991_disk_size http://oe.cowgar.com/docs/eu400_0055.html#_986_disk_metrics
And look at the code in http://rapideuphoria.svn.sourceforge.net/viewvc/rapideuphoria/trunk/include/std/filesys.e?revision=2682
7. Re: get free disk space in win32
- Posted by ssallen Dec 20, 2009
- 1229 views
Thanks Jim!
Looks like we zig-zagged on posts. That might have been the smarter option but I wanted to get in over my head!
Thanks!
Steve A.
8. Re: get free disk space in win32
- Posted by useless Dec 21, 2009
- 1211 views
Hello again,
Another inane question from yours truly. What is the best way to get the amount of free disk space under win32?
Thanks in advance!
Steve A.
The easiest way might be to take the 4.0 library functions disk_size() and disk_metric() and adapt the code for user under 3.1
http://oe.cowgar.com/docs/eu400_0055.html#_991_disk_size http://oe.cowgar.com/docs/eu400_0055.html#_986_disk_metrics
And look at the code in http://rapideuphoria.svn.sourceforge.net/viewvc/rapideuphoria/trunk/include/std/filesys.e?revision=2682
Does this mean Eu v4 is not returning the correct disk sizes over 4gbytes due to a 32bit integer or atom limit?
useless
9. Re: get free disk space in win32
- Posted by jimcbrown (admin) Dec 21, 2009
- 1140 views
Does this mean Eu v4 is not returning the correct disk sizes over 4gbytes due to a 32bit integer or atom limit?
useless
No.
You are confusing the GetFreeDiskSpaceEx() api function (used in the original code in this thread) with the GetFreeDiskSpace() api function (used in std/filesys.e).
10. Re: get free disk space in win32
- Posted by LarryMiller Dec 21, 2009
- 1165 views
Does this mean Eu v4 is not returning the correct disk sizes over 4gbytes due to a 32bit integer or atom limit?
useless
No.
You are confusing the GetFreeDiskSpaceEx() api function (used in the original code in this thread) with the GetFreeDiskSpace() api function (used in std/filesys.e).
The disk_metrics() function in EU4 uses the GetDiskFreeSpaceA() API function and this also returns currect results, at least on the NT platform. You do have to make the calculations yourself based on the values returned. I believe there are some issues when used on Win9x but this a limitation of the API function, not Eeuphoria.
11. Re: get free disk space in win32
- Posted by jimcbrown (admin) Dec 21, 2009
- 1124 views
The disk_metrics() function in EU4 uses the GetDiskFreeSpaceA() API function and this also returns currect results, at least on the NT platform. You do have to make the calculations yourself based on the values returned.
Or call the disk_size() function.