Click here to Skip to main content
15,896,393 members

when reading a sparse file, the free space of disk decreases.

Revision 2
Situation :
1,creating a empty Sparse file on the given volume (system xp or server 2003) and specify the 10G size of the file.

2,Like reading a normal file ,codes as follow:
C++
HANDLE hFile = CreateFile(m_strFileName,
		GENERIC_READ,
		FILE_SHARE_READ|FILE_SHARE_WRITE,
		NULL,
		OPEN_EXISTING,
		FILE_ATTRIBUTE_NORMAL,	//FILE_ATTRIBUTE_ARCHIVE FILE_ATTRIBUTE_NORMAL  FILE_FLAG_BACKUP_SEMANTICS
		0);
	if ( INVALID_HANDLE_VALUE  == hFile)
	    return FALSE;
	
	ULARGE_INTEGER uli;
	uli.LowPart = GetFileSize(hFile,&uli.HighPart);
	DWORD dwSize = 1<<15;
	DWORD dwCount = (DWORD)((uli.QuadPart/dwSize)+(uli.QuadPart%dwSize?1:0));
	PBYTE pBuf = new BYTE[dwSize];
	for (DWORD i=0; i<dwcount;>	{
		DWORD dwReal=0;
		BOOL bRead = ReadFile(hFile,pBuf,dwSize,&dwReal,NULL);
		if (!bRead)
		{
			CloseHandle(hFile);
			return FALSE;	
		}
		DWORD dwPos = (i+1)*100/dwCount;
		m_cProgress.SetPos(dwPos);
	}
	
	delete []pBuf;
	CloseHandle(hFile); 


3,Sometimes, i find the free space of my disk decreases 10G,and even the ReadFile Function return error "disk full" ,
4,So far, i didn`t know why, i am glad to hear your tips. Thanks
Posted 11-Sep-12 1:40am by terroblade.
Tags: