Re: Why SetFilePointerEx can't accept a negative number as the distance offset?



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.

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!

From the experiments above, we can see that SetFilePointerEx() has its
meaning. I think a drive can be treated as an ordinary file.
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.
Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm



.



Relevant Pages

  • vinum limits disk size to 255MB
    ... I'm trying to set up vinum on a freshly installed FreeBSD 5.3-BETA7 ... drives to create a vinum volume. ... BIOS sector numbering starts with sector 1 ... The data for partition 1 is: ...
    (freebsd-questions)
  • Re: Resizing FAT partitions
    ... The software is used to copy from a source USB drive to many drives ... requested are to allow "short imaging" of a disk by skipping unused portions ... and resize the partition. ... sector. ...
    (microsoft.public.win32.programmer.kernel)
  • disklabel and fdisk cant write to disk. Interactive versions?
    ... When I run fdisk and dislabel from /stand/sysinstall, ... This happens on all four scsi drives on this system, ... BIOS sector numbering starts with sector 1 ... The data for partition 1 is: ...
    (comp.unix.bsd.freebsd.misc)
  • Re: Why SetFilePointerEx cant accept a negative number as the distance offset?
    ... For all practical purposes, the *concept* does not even exist. ... no sense to allow this (you don't even know what the last sector is, ... remapping, RAID drives, virtual drives, etc.) there is no way to even *identify* what the ... "Even if I change the value -512 to 0, the call to SetFilePointerEx ...
    (microsoft.public.vc.mfc)
  • Re: Anyone used paragon drive backup 5.5 with SCO partitions?
    ... > any type of partition because it can do a sector to sector copy. ... has the same geometry as the old ... transport partition data between IDE and SCSI drives. ...
    (comp.unix.sco.misc)