garybaus
July 19th, 2010, 01:58 PM
I'm trying to get FILE_FLAG_NO_BUFFERING to work on a 32-bit Vista/SP2 host. I always get FILE_HANDLE_ERROR with a GET_LAST_ERROR of 0x57 (87, ERROR_INVALID_PARAMETER).
In the snippet of code below, if the #else branch is enabled, CreateFile works correctly and returns a valid handle. The only difference between the two is FILE_FLAG_NO_BUFFERING. If I or this flag with FILE_FLAG_WRITE_THROUGH in the #else branch, it fails, so it is specifically the BUFFERING flag that causes the problem.
This feels like a Vista/7 security-related issue, but it also fails on XP/SP3. I've tried creating the file in my desktop folder, with the same result, so it's not related to using c:\windows\temp.
#if 0
fh = CreateFileA("C:\\Windows\\Temp\\TTTT",
FILE_GENERIC_READ|FILE_GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_FLAG_WRITE_THROUGH,
NULL);
#else
fh = CreateFileA("C:\\Windows\\Temp\TTTT",
FILE_GENERIC_READ|FILE_GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_FLAG_NO_BUFFERING,
NULL)
In the snippet of code below, if the #else branch is enabled, CreateFile works correctly and returns a valid handle. The only difference between the two is FILE_FLAG_NO_BUFFERING. If I or this flag with FILE_FLAG_WRITE_THROUGH in the #else branch, it fails, so it is specifically the BUFFERING flag that causes the problem.
This feels like a Vista/7 security-related issue, but it also fails on XP/SP3. I've tried creating the file in my desktop folder, with the same result, so it's not related to using c:\windows\temp.
#if 0
fh = CreateFileA("C:\\Windows\\Temp\\TTTT",
FILE_GENERIC_READ|FILE_GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_FLAG_WRITE_THROUGH,
NULL);
#else
fh = CreateFileA("C:\\Windows\\Temp\TTTT",
FILE_GENERIC_READ|FILE_GENERIC_WRITE,
FILE_SHARE_WRITE,
NULL,
CREATE_ALWAYS,
FILE_FLAG_NO_BUFFERING,
NULL)