Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Vista WriteFile problem

Status
Not open for further replies.

AlbertP321

Programmer
Jan 10, 2007
5
US
Hi,

I'm porting a win32 program from XP to Vista. The program is doing read and write with hard disk and is sector based. In the very beginning the program does,

Read and write to sector 0, then
Write to very end of the hard disk

Steps are very traditional,

CreateFile
SetFilePointer
WriteFile

A problem happened when I do write to very end. CreateFile returns a valid handle. SetFilePointer ok too. However, WriteFile is always failed and last error is ERROR_FILE_NOT_FOUND. This is weird since CreateFile and SetFilePointer worked. Finally I found out it's a disk delay problem. I have to put a while loop to wait till the WriteFile succeeded. I have tried FILE_FLAG_NO_BUFFERING but not any help.

This problem is not happened on XP. Is there anyone knows why on Vista I have to wait till disk is ready for write?

Appreciate for any reply.
AbertP321
 
Can you present all CreateFile arguments? See also special write buffer allocation requirements when an application specifies FILE_FLAG_NO_BUFFERING in CreateFile MSDN description (volume sector size is 512 or 1024 or 2048 etc, or an application wants disk drive access).
 
Thank you for your reply, ArkM.

Here is my CreateFile,

tmpHandle = CreateFile( szDriveName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_SYSTEM,
NULL);

I have tried no-buffering but can't find any difference:
FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_NO_BUFFERING,

All ReadFile and WriteFile in the program are sectors based. All are in the unit of 512 bytes.

Strange thing is this program runs under XP without this disk not ready issue. Perhaps it writes on 1st sector then turn to end of disk and this processing is different between XP and Vista?

Appreciate for further information.

AlbertP321
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top