1. get free disk space in win32 -- Solved.

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.

new topic     » topic index » view message » categorize

2. Re: get free disk space in win32

ssallen said...

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) 
new topic     » goto parent     » topic index » view message » categorize

3. Re: get free disk space in win32

Correction: That should be:

value=peek4u(pAddress) * #100000000 + peek4u(pAddress+4) 
new topic     » goto parent     » topic index » view message » categorize

4. Re: get free disk space in win32

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.

new topic     » goto parent     » topic index » view message » categorize

5. Re: get free disk space in win32 ** Figured it out. Code inside for anyone else who wants to use it.

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.

new topic     » goto parent     » topic index » view message » categorize

6. Re: get free disk space in win32

ssallen said...

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

new topic     » goto parent     » topic index » view message » categorize

7. Re: get free disk space in win32

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.

new topic     » goto parent     » topic index » view message » categorize

8. Re: get free disk space in win32

jimcbrown said...
ssallen said...

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

new topic     » goto parent     » topic index » view message » categorize

9. Re: get free disk space in win32

useless said...

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).

new topic     » goto parent     » topic index » view message » categorize

10. Re: get free disk space in win32

jimcbrown said...
useless said...

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.

new topic     » goto parent     » topic index » view message » categorize

11. Re: get free disk space in win32

LarryMiller said...

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.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu