Writing to disk without caching
I am attempting to copy file to disk without caching.The code belows details have I am attempting to implement this feature. I am having problems copying files that are much larger than my (typically 256K) buffer. For example if my file size is 1096K. I successfully copy the first 1024K, but the WriteFile operation fails on the last 72K. If my file is 300K the write is successfull. If my file is less that 256K the write is successfull.
[ccode]GetDiskFreeSpace(RootPathName,&dwSectorsPerCluster,&dwBytesPerSector,
&dwNumberOfFreeClusters, &dwTotalNumberOfClusters);
dwBytesToRead = dwBytesPerSector * 200;
pBuffer = VirtualAlloc(NULL,dwBytesToRead , MEM_COMMIT,PAGE_READWRITE | PAGE_NOCACHE);
if(!pBuffer || !CheckFileErrors() )
break;
do
{
bResult = ReadFile(hFromTemp,pBuffer,dwBytesToRead,&dwNumberOfBytesRead,NULL);
if(!bResult || !CheckFileErrors() )
break;
if(!WriteFile(hToTemp,pBuffer,dwNumberOfBytesRead,&dwNumberofBytesWritten,NULL))
{
bResult = FALSE;
CheckFileErrors();
break;
}
m_i64TotalSizeCopied += dwNumberofBytesWritten;
m_lSizeCopied = static_cast<long>(m_i64TotalSizeCopied);
}
while((!bResult && dwNumberOfBytesRead != 0) || (dwBytesToRead = dwNumberofBytesWritten));
[\ccode]
Re: Writing to disk without caching
Can I ask why you want to write a file that is not cached?
There is a CopyFile function which will copy a file for you.
Dave McLelland
D. McLelland (Software) Limited