Build a fake partition table for removable media drives.

svn path=/trunk/; revision=2989
This commit is contained in:
Eric Kohl 2002-05-28 09:29:07 +00:00
parent d92e35924c
commit 4cd4c7a855

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: disk.c,v 1.13 2002/05/25 13:30:28 ekohl Exp $ /* $Id: disk.c,v 1.14 2002/05/28 09:29:07 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -534,6 +534,24 @@ DiskClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
DPRINT("SectorSize: %lu\n", DiskDeviceExtension->DiskGeometry->BytesPerSector); DPRINT("SectorSize: %lu\n", DiskDeviceExtension->DiskGeometry->BytesPerSector);
if ((DiskDeviceObject->Characteristics & FILE_REMOVABLE_MEDIA) &&
(DiskDeviceExtension->DiskGeometry->MediaType == RemovableMedia))
{
/* Allocate a partition list for a single entry. */
PartitionList = ExAllocatePool(NonPagedPool,
sizeof(DRIVE_LAYOUT_INFORMATION));
if (PartitionList != NULL)
{
RtlZeroMemory(PartitionList,
sizeof(DRIVE_LAYOUT_INFORMATION));
PartitionList->PartitionCount = 1;
DiskData->DriveNotReady = TRUE;
Status = STATUS_SUCCESS;
}
}
else
{
/* Read partition table */ /* Read partition table */
Status = IoReadPartitionTable(DiskDeviceObject, Status = IoReadPartitionTable(DiskDeviceObject,
DiskDeviceExtension->DiskGeometry->BytesPerSector, DiskDeviceExtension->DiskGeometry->BytesPerSector,
@ -548,7 +566,7 @@ DiskClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* Drive is not ready. */ /* Drive is not ready. */
DPRINT1("Drive not ready\n"); DPRINT("Drive not ready\n");
DiskData->DriveNotReady = TRUE; DiskData->DriveNotReady = TRUE;
} }
else else
@ -568,6 +586,7 @@ DiskClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
} }
} }
}
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
@ -653,23 +672,22 @@ DiskClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
} }
/**********************************************************************
* NAME EXPORTED
* DiskClassDeviceControl
// DiskClassDeviceControl *
// * DESCRIPTION
// DESCRIPTION: * Answer requests for device control calls
// Answer requests for device control calls *
// * RUN LEVEL
// RUN LEVEL: * PASSIVE_LEVEL
// PASSIVE_LEVEL *
// * ARGUMENTS
// ARGUMENTS: * Standard dispatch arguments
// Standard dispatch arguments *
// * RETURNS
// RETURNS: * Status
// NTSTATUS */
//
NTSTATUS STDCALL NTSTATUS STDCALL
DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject, DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
@ -693,7 +711,6 @@ DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension; DeviceExtension = (PDEVICE_EXTENSION)DeviceObject->DeviceExtension;
DiskData = (PDISK_DATA)(DeviceExtension + 1); DiskData = (PDISK_DATA)(DeviceExtension + 1);
/* A huge switch statement in a Windows program?! who would have thought? */
switch (ControlCode) switch (ControlCode)
{ {
case IOCTL_DISK_GET_DRIVE_GEOMETRY: case IOCTL_DISK_GET_DRIVE_GEOMETRY:
@ -702,16 +719,21 @@ DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
{ {
Status = STATUS_INVALID_PARAMETER; Status = STATUS_INVALID_PARAMETER;
} }
else if (DeviceExtension->DiskGeometry == NULL)
{
DPRINT1("No disk geometry available!\n");
Status = STATUS_NO_SUCH_DEVICE;
}
else else
{ {
PDISK_GEOMETRY Geometry; PDISK_GEOMETRY Geometry;
Geometry = (PDISK_GEOMETRY) Irp->AssociatedIrp.SystemBuffer; if (DeviceExtension->DiskGeometry == NULL)
{
DPRINT("No disk geometry available!\n");
DeviceExtension->DiskGeometry = ExAllocatePool(NonPagedPool,
sizeof(DISK_GEOMETRY));
}
Status = ScsiClassReadDriveCapacity(DeviceObject);
DPRINT("ScsiClassReadDriveCapacity() returned (Status %lx)\n", Status);
if (NT_SUCCESS(Status))
{
Geometry = (PDISK_GEOMETRY)Irp->AssociatedIrp.SystemBuffer;
RtlMoveMemory(Geometry, RtlMoveMemory(Geometry,
DeviceExtension->DiskGeometry, DeviceExtension->DiskGeometry,
sizeof(DISK_GEOMETRY)); sizeof(DISK_GEOMETRY));
@ -719,6 +741,7 @@ DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
Information = sizeof(DISK_GEOMETRY); Information = sizeof(DISK_GEOMETRY);
} }
}
break; break;
case IOCTL_DISK_GET_PARTITION_INFO: case IOCTL_DISK_GET_PARTITION_INFO: