Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: "Alexander Grigoriev" <alegr@xxxxxxxxxxxxx>
- Date: Sun, 9 Sep 2007 18:56:18 -0700
It could be that files opened to the whole partition don't have "size"
concept. Thus, end of file is not known for them.
I wonder whether GetFileSize(Ex) will succeed for such a handle and return
non-zero result.
"Norman Diamond" <ndiamond@xxxxxxxxxxxxxxxx> wrote in message
news:OvgmML08HHA.1188@xxxxxxxxxxxxxxxxxxxxxxx
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
.
- 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
- Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- From: Norman Diamond
- Why SetFilePointerEx can't accept a negative number as the distance offset?
- Prev by Date: Re: return int value to OS in MFC App
- Next by Date: Re: Script to convert "" to _T("")
- Previous by thread: Re: Why SetFilePointerEx can't accept a negative number as the distance offset?
- Next by thread: SetWindowRgn - Used to create a rounded window
- Index(es):
Relevant Pages
|