PhysicalDrive size detection?

Hi All. I’m using IOCTL_DISK_GET_DRIVE_GEOMETRY to get size of the
“\.\PhysicalDriveX” but it returns wrong size because of CHS translation:
Under W2K i’ve got : CHS=(788,255,63)-> amount of sectors = 12659220;
But under 9x from BIOS: CHS=(13410,15,63) and amount of sectors =
12672450;
Under W2k i can read from the last sectors but how to get exact number of
sectors? I need to locate LDM database when the beginning of the disk is
corrupted but for this i need to locate the end of disk first :frowning:

Vladimir.

See Microsoft article Q153973, Q121517, and Q245725 for information on how
to recover this information.

-----Original Message-----
From: Vlad [mailto:xxxxx@newmail.ru]
Sent: Monday, June 10, 2002 5:57 AM
To: File Systems Developers
Subject: [ntfsd] PhysicalDrive size detection?

Hi All. I’m using IOCTL_DISK_GET_DRIVE_GEOMETRY to get size of the
“\.\PhysicalDriveX” but it returns wrong size because of CHS translation:
Under W2K i’ve got : CHS=(788,255,63)-> amount of sectors = 12659220;
But under 9x from BIOS: CHS=(13410,15,63) and amount of sectors =
12672450;
Under W2k i can read from the last sectors but how to get exact number of
sectors? I need to locate LDM database when the beginning of the disk is
corrupted but for this i need to locate the end of disk first :frowning:

Vladimir.


You are currently subscribed to ntfsd as: xxxxx@1vision.com
To unsubscribe send a blank email to %%email.unsub%%

> Hi All. I’m using IOCTL_DISK_GET_DRIVE_GEOMETRY to get size of the

“\.\PhysicalDriveX” but it returns wrong size because of CHS
translation:
Under W2K i’ve got : CHS=(788,255,63)-> amount of sectors =
12659220;

First, forget about CHS values on NT at all. They are emulated by ATA
stack. Only their product is valid.
Second, NT’s ATA stack is known to interpret IDENTIFY data in
different way then Win9x sometimes. In this cases, it just sees not
the whole disk.

Max

I don’t need CHS values, I need size ( in byte or in sectors) of the
“\.\PhysicalDriveN” but IOCTL_DISK_GET_DRIVE_GEOMETRY returns only CHS
configuration and i’ve got size computed from this values. From other side i
can read sectors beyond this size till the real end of the disk, so it’s
interesting - is there any other way to get real disk size? In the WinXP
there are new IOCTLs but what to do under 2k and NT4.0?

----- Original Message -----
From: Maxim S. Shatskih
To: File Systems Developers
Sent: Monday, June 10, 2002 11:48 PM
Subject: [ntfsd] Re: PhysicalDrive size detection?

> > Hi All. I’m using IOCTL_DISK_GET_DRIVE_GEOMETRY to get size of the
> > “\.\PhysicalDriveX” but it returns wrong size because of CHS
> translation:
> > Under W2K i’ve got : CHS=(788,255,63)-> amount of sectors =
> 12659220;
>
> First, forget about CHS values on NT at all. They are emulated by ATA
> stack. Only their product is valid.
> Second, NT’s ATA stack is known to interpret IDENTIFY data in
> different way then Win9x sometimes. In this cases, it just sees not
> the whole disk.
>
> Max
>
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@newmail.ru
> To unsubscribe send a blank email to %%email.unsub%%
> __________
> http://www.newhost.ru - ÓÁÊÔÙ ÷ÁÛÉ, ÐÒÏÂÌÅÍÙ îÁÛÉ
>

> can read sectors beyond this size till the real end of the disk, so
it’s

interesting - is there any other way to get real disk size? In the
WinXP
there are new IOCTLs but what to do under 2k and NT4.0?

This seems to be a problem of w2k’s ATA stack - it is known to report
the disks as smaller then they are really, even smaller then in NT4.

Max

----- Original Message -----
From: Maxim S. Shatskih
> To: File Systems Developers
> Sent: Monday, June 10, 2002 11:48 PM
> Subject: [ntfsd] Re: PhysicalDrive size detection?
>
>
> > > Hi All. I’m using IOCTL_DISK_GET_DRIVE_GEOMETRY to get size of
the
> > > “\.\PhysicalDriveX” but it returns wrong size because of CHS
> > translation:
> > > Under W2K i’ve got : CHS=(788,255,63)-> amount of sectors =
> > 12659220;
> >
> > First, forget about CHS values on NT at all. They are emulated by
ATA
> > stack. Only their product is valid.
> > Second, NT’s ATA stack is known to interpret IDENTIFY data in
> > different way then Win9x sometimes. In this cases, it just sees
not
> > the whole disk.
> >
> > Max
> >
> >
> >
> > —
> > You are currently subscribed to ntfsd as: xxxxx@newmail.ru
> > To unsubscribe send a blank email to %%email.unsub%%
> > __________
> > http://www.newhost.ru - ÓÁÊÔÙ ÷ÁÛÉ, ÐÒÏÂÌÅÍÙ îÁÛÉ
> >
>
>
> —
> You are currently subscribed to ntfsd as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to %%email.unsub%%
>

I do this by calling “SCSIOP_READ_CAPACITY” command via
IOCTL_SCSI_PASS_THROUGH.
You can try it from UserMode using DDK sample “SPTI”.

After successful call you will obtain READ_CAPACITY_DATA stuct

typedef struct _READ_CAPACITY_DATA {
ULONG LogicalBlockAddress;
ULONG BytesPerBlock;
} READ_CAPACITY_DATA, *PREAD_CAPACITY_DATA;

// Calculate the offset of LDM( in bytes )
LdmStartOffset = (LONGLONG)(LogicalBlockAddress + 1) *
(LONGLONG)BytesPerBlock - (LONGLONG)LDM_SIZE;

Kristian