Suppose, My D: volume capacity is 100GB.
And I'm using it 80GB now.
The remain is only 20G.
Now, I try to make a sparse file.
DWORD written;
std::wstring s = L"D:\\sparse9.test";
HANDLE h = CreateFileW(s.c_str(),
GENERIC_WRITE,
FILE_SHARE_DELETE,
0,
CREATE_NEW,
0,
0);
if(!DeviceIoControl(
h,
FSCTL_SET_SPARSE, NULL, 0,
NULL, 0, &written,
NULL))
{
DWORD error = GetLastError();
fprintf(stderr, "Error making file sparse (%u)\n", error);
return error;
}
fprintf(stderr, "File sparsed...\n");
WriteFile(h, "aaa", 3, &written, 0);
DWORD d = GetFileAttributes(s.c_str());
LARGE_INTEGER li;
li.QuadPart = 30i64*1024i64*1024i64*1024i64; // trying to expand the file to 30GB.
SetFilePointerEx(h, li, 0, FILE_BEGIN);
SetEndOfFile(h); // It sucesses.
WriteFile(h, "bbb", 3, &written, 0);
30GB file has been created well and that's what I expected.
But according to this document, somethings might be wrong.
A sparse file affects user quotas by the nominal size of the file, not the actual allocated amount of disk space. That is, creating a 50-MB file with all zero bytes consumes 50 MB of that user's quota. This means that as the user writes data to the sparse file, he need not worry about exceeding his hard quota limit, because he has already been charged for the space. System administrators should not count on the size of a sparse file remaining small. Therefore they should not grant their users hard quota limits that exceed the physical space available, despite the use of sparse files.
This sentences seem to be an opposite of my thinking. Isn't it. What is wrong.