Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Sat, 08 Sep 2007 01:41:35 -0400
You can't. For all practical purposes, the *concept* does not even exist. Since it makes
no sense to allow this (you don't even know what the last sector is, and given dynamic
remapping, RAID drives, virtual drives, etc.) there is no way to even *identify* what the
last sector is! You can only do this if you have privileged access to the physical drive,
and you don't have that.
I have no idea why this could possibly make sense, even if it were possible, but no sane
operating system would ever permit this sort of thing to be done. It would be a truly
massive security hole. So it isn't going to happen.
joe
On Fri, 07 Sep 2007 21:27:28 -0700, xmllmx <xmllmx@xxxxxxxxx> wrote:
Thank you, Joseph.Joseph M. Newcomer [MVP]
My purpose is simple: I want to read the last sector of the drive.
All of the first three posts are mine. Maybe you just saw my first
post.
My second post:
==================
"Even if I change the value -512 to 0, the call to SetFilePointerEx
still fails.
How weird it is!"
==================
My third post:
==============
"PS.
The error code returned by SetFilePointerEx is 0x87
(ERROR_INVALID_PARAMETER)."
==================
CreateFile is successful. And I can sucessfully call SetFilePointerEx
with positive value such as 512, 1024, etc. As long as the offset is
positive and sector-aligned, the call will always succeed!
For example, the following code is OK.
========== Code =============
HANDLE hDrive = CreateFile(L"\\\\.\\C:", GENERIC_READ,
FILE_SHARE_READ|FILE_SHARE_WRITE, 0, OPEN_EXISTING,
NULL, NULL);
LARGE_INTEGER i64;
i64.QuadPart = 512; // must be a whole number multiple of the volume's
sector size
SetFilePointerEx(hDrive, i64, 0, FILE_BEGIN); // OK!
CloseHandle(hDrive);
========== Code =============
Moreover, in some case, I can use a negative value successfully. See
below:
i64.QuadPart = 512; // must be a whole number multiple of the volume's
sector size
SetFilePointerEx(hDrive, i64, 0, FILE_BEGIN); // OK!
/*
Now the current file pointer points to 512, so I can move the file
pointer backward.
*/
i64.QuadPart = -512;
SetFilePointerEx(hDrive, i64, 0, FILE_CURRENT); // OK!
meaning. I think a drive can be treated as an ordinary file.From the experiments above, we can see that SetFilePointerEx() has its
GetFileType() will return FILE_TYPE_DISK, which means the drive is
seeking device rather than nonseeking device, so we can call
SetFilePointerEx on the drive.
After I rephrase my problem, my original problem is still unsolved:
i64.QuadPart = -512;
SetFilePointerEx(hDrive, i64, 0, FILE_END); // This time the call will
still return 0x87
I'm still awaiting help for this. Thanks.
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- Follow-Ups:
- Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: Norman Diamond
- Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- References:
- Prev by Date: Re: Code Page problem in SetWindowText
- Next by Date: Re: Write to an Edit Control with the << operator
- Previous by thread: Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- Next by thread: Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- Index(es):
Relevant Pages
|