Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: "Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx>
- Date: Mon, 10 Sep 2007 09:37:27 +0900
The original poster has permission to open the entire partition and read/write the entire partition, so an attempt to read the last sector of the partition is not a security hole.
Even though we don't know in the physical hardware which sector is "last" in some sense in the physical drive (or in which physical drive in RAID as you point out) there is some sector that has the highest block number, starting from 0 for the first block in the partition.
I don't know why Windows doesn't deliver, but the original poster's wishes look sensible to me.
"Joseph M. Newcomer" <newcomer@xxxxxxxxxxxx> wrote in message news:tad4e35ub4jp9foqgcirq2t290buqdmv1b@xxxxxxxxxx
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: Alexander Grigoriev
- Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- References:
- Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: xmllmx
- Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: Joseph M . Newcomer
- Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: xmllmx
- Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: Joseph M . Newcomer
- Why SetFilePointerEx can't accept a negative number as the distance offset?
- Prev by Date: Re: Script to convert "" to _T("")
- Next by Date: Re: Code Page problem in SetWindowText
- 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
|