Always update disk geometry.

svn path=/trunk/; revision=2983
This commit is contained in:
Eric Kohl 2002-05-26 20:23:22 +00:00
parent 5aad28cf99
commit af5a948adf

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: cdrom.c,v 1.9 2002/05/25 13:29:58 ekohl Exp $ /* $Id: cdrom.c,v 1.10 2002/05/26 20:23:22 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -25,6 +25,12 @@
* PROGRAMMER: Eric Kohl (ekohl@rz-online.de) * PROGRAMMER: Eric Kohl (ekohl@rz-online.de)
*/ */
/*
* TODO:
* - Add io timer routine for autorun support.
* - Add cdaudio support (cd player).
*/
/* INCLUDES *****************************************************************/ /* INCLUDES *****************************************************************/
#include <ddk/ntddk.h> #include <ddk/ntddk.h>
@ -62,7 +68,7 @@ CdromClassCheckReadWrite(IN PDEVICE_OBJECT DeviceObject,
static NTSTATUS static NTSTATUS
CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject, CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath, /* what's this used for? */ IN PUNICODE_STRING RegistryPath,
IN PDEVICE_OBJECT PortDeviceObject, IN PDEVICE_OBJECT PortDeviceObject,
IN ULONG PortNumber, IN ULONG PortNumber,
IN ULONG DeviceNumber, IN ULONG DeviceNumber,
@ -79,27 +85,34 @@ NTSTATUS STDCALL
CdromClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject, CdromClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp); IN PIRP Irp);
VOID STDCALL
CdromTimerRoutine(IN PDEVICE_OBJECT DeviceObject,
IN PVOID Context);
/* FUNCTIONS ****************************************************************/ /* FUNCTIONS ****************************************************************/
// DriverEntry /**********************************************************************
// * NAME EXPORTED
// DESCRIPTION: * DriverEntry
// This function initializes the driver, locates and claims *
// hardware resources, and creates various NT objects needed * DESCRIPTION:
// to process I/O requests. * This function initializes the driver, locates and claims
// * hardware resources, and creates various NT objects needed
// RUN LEVEL: * to process I/O requests.
// PASSIVE_LEVEL *
// * RUN LEVEL:
// ARGUMENTS: * PASSIVE_LEVEL
// IN PDRIVER_OBJECT DriverObject System allocated Driver Object *
// for this driver * ARGUMENTS:
// IN PUNICODE_STRING RegistryPath Name of registry driver service * DriverObject
// key * System allocated Driver Object for this driver
// * RegistryPath
// RETURNS: * Name of registry driver service key
// NTSTATUS *
* RETURNS:
* Status.
*/
NTSTATUS STDCALL NTSTATUS STDCALL
DriverEntry(IN PDRIVER_OBJECT DriverObject, DriverEntry(IN PDRIVER_OBJECT DriverObject,
@ -107,8 +120,8 @@ DriverEntry(IN PDRIVER_OBJECT DriverObject,
{ {
CLASS_INIT_DATA InitData; CLASS_INIT_DATA InitData;
DbgPrint("CD-ROM Class Driver %s\n", DPRINT("CD-ROM Class Driver %s\n",
VERSION); VERSION);
DPRINT("RegistryPath '%wZ'\n", DPRINT("RegistryPath '%wZ'\n",
RegistryPath); RegistryPath);
@ -117,7 +130,7 @@ DriverEntry(IN PDRIVER_OBJECT DriverObject,
InitData.DeviceType = FILE_DEVICE_CD_ROM; InitData.DeviceType = FILE_DEVICE_CD_ROM;
InitData.DeviceCharacteristics = FILE_REMOVABLE_MEDIA | FILE_READ_ONLY_DEVICE; InitData.DeviceCharacteristics = FILE_REMOVABLE_MEDIA | FILE_READ_ONLY_DEVICE;
InitData.ClassError = NULL; // CdromClassProcessError; InitData.ClassError = NULL; // CdromClassProcessError;
InitData.ClassReadWriteVerification = CdromClassCheckReadWrite; InitData.ClassReadWriteVerification = CdromClassCheckReadWrite;
InitData.ClassFindDeviceCallBack = CdromClassCheckDevice; InitData.ClassFindDeviceCallBack = CdromClassCheckDevice;
InitData.ClassFindDevices = CdromClassFindDevices; InitData.ClassFindDevices = CdromClassFindDevices;
@ -132,25 +145,33 @@ DriverEntry(IN PDRIVER_OBJECT DriverObject,
} }
// CdromClassFindDevices /**********************************************************************
// * NAME EXPORTED
// DESCRIPTION: * CdromClassFindDevices
// This function searches for device that are attached to the given scsi port. *
// * DESCRIPTION:
// RUN LEVEL: * This function searches for device that are attached to the
// PASSIVE_LEVEL * given scsi port.
// *
// ARGUMENTS: * RUN LEVEL:
// IN PDRIVER_OBJECT DriverObject System allocated Driver Object for this driver * PASSIVE_LEVEL
// IN PUNICODE_STRING RegistryPath Name of registry driver service key *
// IN PCLASS_INIT_DATA InitializationData Pointer to the main initialization data * ARGUMENTS:
// IN PDEVICE_OBJECT PortDeviceObject Scsi port device object * DriverObject
// IN ULONG PortNumber Port number * System allocated Driver Object for this driver
// * RegistryPath
// RETURNS: * Name of registry driver service key.
// TRUE: At least one disk drive was found * InitializationData
// FALSE: No disk drive found * Pointer to the main initialization data
// * PortDeviceObject
* Scsi port device object
* PortNumber
* Port number
*
* RETURNS:
* TRUE: At least one disk drive was found
* FALSE: No disk drive found
*/
BOOLEAN STDCALL BOOLEAN STDCALL
CdromClassFindDevices(IN PDRIVER_OBJECT DriverObject, CdromClassFindDevices(IN PDRIVER_OBJECT DriverObject,
@ -198,7 +219,7 @@ CdromClassFindDevices(IN PDRIVER_OBJECT DriverObject,
AdapterBusInfo); AdapterBusInfo);
if (DeviceCount == 0) if (DeviceCount == 0)
{ {
DPRINT1("No unclaimed devices!\n"); DPRINT("No unclaimed devices!\n");
return(FALSE); return(FALSE);
} }
@ -253,7 +274,8 @@ CdromClassFindDevices(IN PDRIVER_OBJECT DriverObject,
DPRINT("CdromClassFindDevices() done\n"); DPRINT("CdromClassFindDevices() done\n");
return(TRUE); return(FoundDevice);
// return(TRUE);
} }
@ -298,7 +320,6 @@ CdromClassCheckDevice(IN PINQUIRYDATA InquiryData)
* ARGUMENTS * ARGUMENTS
* DeviceObject * DeviceObject
* Pointer to the device. * Pointer to the device.
*
* Irp * Irp
* Irp to check. * Irp to check.
* *
@ -317,33 +338,35 @@ CdromClassCheckReadWrite(IN PDEVICE_OBJECT DeviceObject,
} }
// CdromClassCreateDeviceObject /**********************************************************************
// * NAME EXPORTED
// DESCRIPTION: * CdromClassCreateDeviceObject
// Create the raw device and any partition devices on this drive *
// * DESCRIPTION:
// RUN LEVEL: * Create the raw device and any partition devices on this drive
// PASSIVE_LEVEL *
// * RUN LEVEL:
// ARGUMENTS: * PASSIVE_LEVEL
// IN PDRIVER_OBJECT DriverObject The system created driver object *
// IN PCONTROLLER_OBJECT ControllerObject * ARGUMENTS:
// IN PIDE_CONTROLLER_EXTENSION ControllerExtension * DriverObject
// The IDE controller extension for * System allocated Driver Object for this driver.
// this device * RegistryPath
// IN int DriveIdx The index of the drive on this * Name of registry driver service key.
// controller * PortDeviceObject
// IN int HarddiskIdx The NT device number for this * PortNumber
// drive * DeviceNumber
// * Capabilities
// RETURNS: * InquiryData
// TRUE Drive exists and devices were created * InitializationData
// FALSE no devices were created for this device *
// * RETURNS:
* Status.
*/
static NTSTATUS static NTSTATUS
CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject, CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath, /* what's this used for? */ IN PUNICODE_STRING RegistryPath,
IN PDEVICE_OBJECT PortDeviceObject, IN PDEVICE_OBJECT PortDeviceObject,
IN ULONG PortNumber, IN ULONG PortNumber,
IN ULONG DeviceNumber, IN ULONG DeviceNumber,
@ -481,6 +504,11 @@ CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
/* FIXME: initialize media change support */ /* FIXME: initialize media change support */
IoInitializeTimer(DiskDeviceObject,
CdromTimerRoutine,
NULL);
IoStartTimer(DiskDeviceObject);
DPRINT("CdromClassCreateDeviceObjects() done\n"); DPRINT("CdromClassCreateDeviceObjects() done\n");
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
@ -488,20 +516,24 @@ CdromClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
// CdromClassDeviceControl /**********************************************************************
// * NAME EXPORTED
// DESCRIPTION: * CdromClassDeviceControl
// Answer requests for device control calls *
// * DESCRIPTION:
// RUN LEVEL: * Answer requests for device control calls
// PASSIVE_LEVEL *
// * RUN LEVEL:
// ARGUMENTS: * PASSIVE_LEVEL
// Standard dispatch arguments *
// * ARGUMENTS:
// RETURNS: * DeviceObject
// NTSTATUS * Irp
// * Standard dispatch arguments
*
* RETURNS:
* Status.
*/
NTSTATUS STDCALL NTSTATUS STDCALL
CdromClassDeviceControl(IN PDEVICE_OBJECT DeviceObject, CdromClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
@ -528,27 +560,32 @@ CdromClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
switch (ControlCode) switch (ControlCode)
{ {
case IOCTL_CDROM_GET_DRIVE_GEOMETRY: case IOCTL_CDROM_GET_DRIVE_GEOMETRY:
DPRINT1("IOCTL_CDROM_GET_DRIVE_GEOMETRY\n"); DPRINT("IOCTL_CDROM_GET_DRIVE_GEOMETRY\n");
if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(DISK_GEOMETRY)) if (IrpStack->Parameters.DeviceIoControl.OutputBufferLength < sizeof(DISK_GEOMETRY))
{ {
Status = STATUS_INVALID_PARAMETER; Status = STATUS_INVALID_PARAMETER;
} }
else if (DeviceExtension->DiskGeometry == NULL)
{
DPRINT1("No cdrom 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)
RtlMoveMemory(Geometry, {
DeviceExtension->DiskGeometry, DPRINT("No cdrom geometry available!\n");
sizeof(DISK_GEOMETRY)); DeviceExtension->DiskGeometry = ExAllocatePool(NonPagedPool,
sizeof(DISK_GEOMETRY));
}
Status = ScsiClassReadDriveCapacity(DeviceObject);
if (NT_SUCCESS(Status))
{
Geometry = (PDISK_GEOMETRY) Irp->AssociatedIrp.SystemBuffer;
RtlMoveMemory(Geometry,
DeviceExtension->DiskGeometry,
sizeof(DISK_GEOMETRY));
Status = STATUS_SUCCESS; Status = STATUS_SUCCESS;
Information = sizeof(DISK_GEOMETRY); Information = sizeof(DISK_GEOMETRY);
}
} }
break; break;
@ -567,20 +604,24 @@ CdromClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
} }
// CdromClassShutdownFlush /**********************************************************************
// * NAME EXPORTED
// DESCRIPTION: * CdromClassShutdownFlush
// Answer requests for shutdown and flush calls *
// * DESCRIPTION:
// RUN LEVEL: * Answer requests for shutdown and flush calls
// PASSIVE_LEVEL *
// * RUN LEVEL:
// ARGUMENTS: * PASSIVE_LEVEL
// Standard dispatch arguments *
// * ARGUMENTS:
// RETURNS: * DeviceObject
// NTSTATUS * Irp
// * Standard dispatch arguments
*
* RETURNS:
* Status.
*/
NTSTATUS STDCALL NTSTATUS STDCALL
CdromClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject, CdromClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
@ -596,4 +637,12 @@ CdromClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
} }
VOID STDCALL
CdromTimerRoutine(PDEVICE_OBJECT DeviceObject,
PVOID Context)
{
DPRINT("CdromTimerRoutine() called\n");
}
/* EOF */ /* EOF */