I want to read the boot sector of my pen drive with Fat32 file system
on it. I use win32 API CreateFile() to open the drive, Set file pointer
to begin of drive and call ReadFile() to read 512 bytes.
ReadFile() fails with error code 87. (The parameter is incorrect)
Code:
--------------------
PBYTE byFatBootBlock[512];
hDrive = CreateFile(
_T("\\\\.\\H:"),
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
0,
OPEN_EXISTING,
0,
0
);
if (INVALID_HANDLE_VALUE == hDrive)
{
_tprintf(_T("CreateFile() failed.\n"));
return FALSE;
}
dwLowPtr = SetFilePointer(
hDrive,
0,
0,
FILE_BEGIN
);
if (INVALID_SET_FILE_POINTER == dwLowPtr)
{
_tprintf(_T("SetFilePointer() failed.\n"));
CloseHandle(hDrive);
return FALSE;
}
bRet = ReadFile(
hDrive,
byFatBootBlock,
512,
&dwBytesRead,
NULL
);
if (FALSE == bRet || 512 != dwBytesRead)
{
_tprintf(_T("ReadFile() failed.\n"));
CloseHandle(hDrive);
return FALSE;
}
--------------------
What is wrong in the parameters??
I am reading bytes in multiple of sector size, also the buffer is
aligned to 8 byte boundary.
Thanks.
--
amr123
Posted via http://ms-os.com Forum to Usenet gateway
"amr123" <amr123...@news.home.local> schrieb im Newsbeitrag
news:amr123...@news.home.local...
--
Peter
Please Reply to Newsgroup for the benefit of others
Requests for assistance by email can not and will not be acknowledged.
"amr123" <amr123...@news.home.local> wrote in message
news:amr123...@news.home.local...
--
SPAMCOP User
"Peter Foldes" <ok...@hotmail.com> wrote in message
news:umNb%230PSK...@TK2MSFTNGP02.phx.gbl...
--
Peter
Please Reply to Newsgroup for the benefit of others
Requests for assistance by email can not and will not be acknowledged.
"SPAMCOP User" <spamcop_user@no_mail.haha> wrote in message
news:%23naZjuQ...@TK2MSFTNGP02.phx.gbl...
Thanks for reply.
I got the solution. The problem was my pen drive had 2048 bytes per
sector and so ReadFile() failed as number of bytes to read was not
sector aligned.
I used DeviceIoControl() with IOCTL_DISK_GET_DRIVE_GEOMETRY flag to get
the value of bytes per sector and then called ReadFile() with this
value.
I hope this will be helpful to someone.