Get Geometry of Virtual Disk Problem

Hello all,

i craeted virtual disk, I want to set a size to it, in IOCTL_DISK_GET_DRIVE_GEOMETRY when iam trying to make BytesPerSector member for DISK_GEOMETRY 0, no problem apperars, but when I set it anoy other value, problems occure.

This is the code Iam used

case IOCTL_DISK_GET_DRIVE_GEOMETRY:
{
PDISK_GEOMETRY disk_geometry;
ULONGLONG length;

DbgPrint(“DeviceIoControl - IOCTL_DISK_GET_DRIVE_GEOMETRY”);

if (irpStack->Parameters.DeviceIoControl.OutputBufferLength {
DbgPrint(“DeviceIoControl - IOCTL_DISK_GET_DRIVE_GEOMETRY - STATUS_BUFFER_TOO_SMALL”);
NtStatus = STATUS_BUFFER_TOO_SMALL;
dwDataWritten = 0;
break;
}

disk_geometry = (PDISK_GEOMETRY) pIrp->AssociatedIrp.SystemBuffer;

length = LEN;

disk_geometry->Cylinders.QuadPart = length / SECTOR_SIZE / 32 / 2;
disk_geometry->MediaType = FixedMedia;
disk_geometry->TracksPerCylinder = 2;
disk_geometry->SectorsPerTrack = 32;
disk_geometry->BytesPerSector = 0;//SECTOR_SIZE;

NtStatus = STATUS_SUCCESS;
dwDataWritten = sizeof(DISK_GEOMETRY);

break;
}

------------------
and finlly I return NtStatus
if I tried to assign disk_geometry->BytesPerSector with any other value, problems occure

Any other value besides 512? I wouldn’t bother with other values.

The drive geometry data is generally ignored except for the bytespersector
value.
On Jan 11, 2008 3:06 PM, wrote:

> Hello all,
>
> i craeted virtual disk, I want to set a size to it, in
> IOCTL_DISK_GET_DRIVE_GEOMETRY when iam trying to make BytesPerSector member
> for DISK_GEOMETRY 0, no problem apperars, but when I set it anoy other
> value, problems occure.
>
> This is the code Iam used
>
> case IOCTL_DISK_GET_DRIVE_GEOMETRY:
> {
> PDISK_GEOMETRY disk_geometry;
> ULONGLONG length;
>
> DbgPrint(“DeviceIoControl -
> IOCTL_DISK_GET_DRIVE_GEOMETRY”);
>
> if (irpStack->
> Parameters.DeviceIoControl.OutputBufferLength > {
> DbgPrint(“DeviceIoControl -
> IOCTL_DISK_GET_DRIVE_GEOMETRY - STATUS_BUFFER_TOO_SMALL”);
> NtStatus = STATUS_BUFFER_TOO_SMALL;
> dwDataWritten = 0;
> break;
> }
>
> disk_geometry = (PDISK_GEOMETRY) pIrp->
> AssociatedIrp.SystemBuffer;
>
> length = LEN;
>
> disk_geometry->Cylinders.QuadPart = length
> / SECTOR_SIZE / 32 / 2;
> disk_geometry->MediaType = FixedMedia;
> disk_geometry->TracksPerCylinder = 2;
> disk_geometry->SectorsPerTrack = 32;
> disk_geometry->BytesPerSector =
> 0;//SECTOR_SIZE;
>
> NtStatus = STATUS_SUCCESS;
> dwDataWritten = sizeof(DISK_GEOMETRY);
>
> break;
> }
>
> ------------------
> and finlly I return NtStatus
> if I tried to assign disk_geometry->BytesPerSector with any other value,
> problems occure
>
> —
> NTDEV is sponsored by OSR
>
> For our schedule of WDF, WDM, debugging and other seminars visit:
> http://www.osr.com/seminars
>
> To unsubscribe, visit the List Server section of OSR Online at
> http://www.osronline.com/page.cfm?name=ListServer
>


Mark Roddy

Hello, Tito -

From my own learning experience in this area, I’ve concluded:

  1. BytesPerSector must be exactly 512
  2. SectorsPerTrack must be a power of 2

Best of luck,
-Steve

P.S. I’m pretty sure you’re heading down the wrong trail on this one. Let others correct me if I’m wrong, but you probably want a storage miniport driver. You can make it work with just a plain disk device but there’s a lot you’ll have to figure out on your own the hard way.

Hello all,
thanks for your suggestions, I treid to BytesPerSector exactly 512 but memory dump apperar.

I think I have to allocate some memory for this drive but I don’t know actually where or how I can do this.

If any body can help me, please do

> The drive geometry data is generally ignored except for the bytespersector value.

Correct - the *actual* disk geometry may be (in fact, almost certainly is going to be) different from the one that IOCTL_DISK_GET_DRIVE_GEOMETRY returns, because what IOCTL_DISK_GET_DRIVE_GEOMETRY returns is logical drive geometry, rather than the physical one. All modern disks use LBA, rather than CHS, addressing. Therefore, the OS does not address the disk location by its logical cylinder/head/sector position - instead, it just treats it as an offset from the beginning of the disk… The only thing it is interested in is sector size, because all reads and writes have to be done only from those locations that are multiples of a sector size…

Anton Bassov

I would use 512 bytes per sector, 64 sectors per track and 256 tracks per
cylinder.

The number of cylinders is your disk size / 8MB

This is what Windows uses for all disks unknown to BIOS (USB flash, USB or
1394 external enclosures, SCSI on a BIOS-less controller and so on) and for all
LBA ATA/SATA disks.


Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

wrote in message news:xxxxx@ntdev…
> Hello all,
>
> i craeted virtual disk, I want to set a size to it, in
IOCTL_DISK_GET_DRIVE_GEOMETRY when iam trying to make BytesPerSector member for
DISK_GEOMETRY 0, no problem apperars, but when I set it anoy other value,
problems occure.
>
> This is the code Iam used
>
> case IOCTL_DISK_GET_DRIVE_GEOMETRY:
> {
> PDISK_GEOMETRY disk_geometry;
> ULONGLONG length;
>
> DbgPrint(“DeviceIoControl - IOCTL_DISK_GET_DRIVE_GEOMETRY”);
>
> if (irpStack->Parameters.DeviceIoControl.OutputBufferLength
> {
> DbgPrint(“DeviceIoControl - IOCTL_DISK_GET_DRIVE_GEOMETRY -
STATUS_BUFFER_TOO_SMALL”);
> NtStatus = STATUS_BUFFER_TOO_SMALL;
> dwDataWritten = 0;
> break;
> }
>
> disk_geometry = (PDISK_GEOMETRY) pIrp->AssociatedIrp.SystemBuffer;
>
> length = LEN;
>
> disk_geometry->Cylinders.QuadPart = length / SECTOR_SIZE / 32 / 2;
> disk_geometry->MediaType = FixedMedia;
> disk_geometry->TracksPerCylinder = 2;
> disk_geometry->SectorsPerTrack = 32;
> disk_geometry->BytesPerSector = 0;//SECTOR_SIZE;
>
> NtStatus = STATUS_SUCCESS;
> dwDataWritten = sizeof(DISK_GEOMETRY);
>
> break;
> }
>
> ------------------
> and finlly I return NtStatus
> if I tried to assign disk_geometry->BytesPerSector with any other value,
problems occure
>