Tech Support > Microsoft Windows > Development Resources > GetDiskFreeSpaceEx returns disk free space without consideringuser-quota
GetDiskFreeSpaceEx returns disk free space without consideringuser-quota
Posted by somi on May 9th, 2008


Hi

I am finding problem with what GetDiskFreeSpaceEx returns.
GetDiskFreeSpaceEx returns below three parameters:
lpFreeBytesAvailable: the total number of free bytes on a disk that
are available to the
user who is associated with the calling thread. If per-user quotas are
being used, this
value may be less than the total number of free bytes on a disk.
lpTotalNumberOfBytes: the total number of bytes on a disk that are
available to the user who
is associated with the calling thread. If per-user quotas are being
used, this value may be
less than the total number of bytes on a disk.
lpTotalNumberOfFreeBytes: the total number of free bytes on a disk.

In our application the parameters lpFreeBytesAvailable and
lpTotalNumberOfBytes are not
returning the values considering the user-quota that is defined on the
volume.

1) Drive D has 25 Gb total space and 19 GB free space.
2) Enabled quota in the D:\ Drive Properties/Quota tab and checked
"Deny disk space to user
exceeding quota limit" checkbox. Verified that the disk quota system
is active.
3) Set quota limit for a user (domain user) as 2 GB through "Quota
entries".
4) Ran the application in the context that user. The
parameters(lpFreeBytesAvailable = 19 GB
and lpTotalNumberOfBytes = 25 GB) returns sizes without considering
user quota.

But they do consider the hard quota set through FSRM (File Server
Resource Manager) on
Windows 2003 server R2 and Windows 2008 server OS, but does not
consider the quota set per-user.

So the statement “total number of free bytes on a disk that are
available to the user who is
associated with the calling thread” seems inacccurate. May be I am not
understanding
it correctly. Please comment on this.

~Somesh

Posted by Sebastian G. on May 10th, 2008


somi wrote:



Did you verify the quota and their effectiveness again after this stpe?


Might be a caching issue or an issue with not receiving change notifications.

Posted by Christian ASTOR on May 10th, 2008


somi wrote:

BTW, I can't reproduce your problem : it works for me on XP SP2...
(e.g., for a quota limit of 350 GB, the QuadPart of lpTotalNumberOfBytes
is 375809638400 bytes)

Posted by somi on May 12th, 2008


On May 10, 8:06 am, Christian ASTOR <casto...@club-internet.fr> wrote:
-------------------
Hey,
I verified again that the quota is not considered during disk space
calculation.
I wrote a simple POC to verify this:
int main()
{
wprintf(L"Calculating Disk Space");

BOOL fResult;
ULARGE_INTEGER i64FreeBytesToCaller, i64TotalBytes, i64FreeBytes;

fResult =::GetDiskFreeSpaceEx("\\\\12.168.8.6\\D$",
&i64FreeBytesToCaller,
&i64TotalBytes,
&i64FreeBytes);

if(fResult)
{
wprintf(L"Total free bytes = %I64d\n",
i64FreeBytesToCaller.QuadPart /1073741824 );
wprintf(L"Total free bytes = %I64d\n", i64TotalBytes.QuadPart /
1073741824 );
wprintf(L"Total free bytes = %I64d\n", i64FreeBytes.QuadPart /
1073741824 );
}
wprintf(L"Error: %d", ::GetLastError());
getch();
}

My observation is: For disk quota set to 2 GB for a user and 1.86 GB
used by that user, API returns me 19 GB as free space and 25 Gb as
total space when above POC run in the context of that user.
Actually I should get 1.86 Gb and 2 GB resp! 25 GB is the total volume
space and 19 GB is the total volume free space.
Christian, can you please verify this on your system and let me know
where I am going wrong? I am setting quota from the drive properties/
Quota/Quota Entries.
Thanks in advance.
~Somesh

Posted by Sebastian G. on May 12th, 2008


somi wrote:



Quoting <http://msdn.microsoft.com/en-us/library/aa364937(VS.85).aspx>:

| If this parameter is a UNC name, it must include a trailing backslash,
| for example, "\\MyServer\MyShare\".

(I will also ignore the type above, your surely mean 192.* and not 12.*)

Posted by somi on May 12th, 2008


On May 12, 3:17 pm, "Sebastian G." <se...@seppig.de> wrote:
----------------
That's OK. I had tried it with "D:\\" as well.
I don't see that being issue for not reporting correct values. I
restarted the machine as well to eliminate caching issue.
Please reply.

Thanks
~Somesh

Posted by Sebastian G. on May 12th, 2008


somi wrote:


OK, then some further guesses:

lpDirectoryName should be an LPCTSTR, but you're providing an LPCSTR and
because of our usage of wprintf() I presume you have defined _UNICODE, so
LPCTSTR is LPCWSTR and you got a very clear ANI/UNICODE mismatch.

Did you try what is displayed by a well-known correct implementation, f.e.
Windows Explorer's status bar showing the available space?

Maybe you want to run strace?

Posted by somi on May 13th, 2008


On May 12, 3:50 pm, "Sebastian G." <se...@seppig.de> wrote:
-----------
Hey, I found where the issue was. It is reporting correctly now. It
was not reporting because the user was member of Domain Admin group.
But it does report correct values on Win2k8 even if the user is member
of admin group.
Anyways, Thanks a lot. Researching more on this, found some other
related issues, shall write them after I confirm them.
~somesh