Added IOCTL_DISK_SET_PARTITION_INFO.

Added checks for user induced errors.
Added basic shutdown/flush support.

svn path=/trunk/; revision=3253
This commit is contained in:
Eric Kohl 2002-07-18 18:09:59 +00:00
parent 3b8674494e
commit b0c64e3f9f
4 changed files with 166 additions and 79 deletions

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.11 2002/06/06 23:19:19 ekohl Exp $ /* $Id: cdrom.c,v 1.12 2002/07/18 18:08:59 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -592,6 +592,11 @@ CdromClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
return(ScsiClassDeviceControl(DeviceObject, Irp)); return(ScsiClassDeviceControl(DeviceObject, Irp));
} }
/* Verify the device if the user caused the error */
if (!NT_SUCCESS(Status) && IoIsErrorUserInduced(Status))
{
IoSetHardErrorOrVerifyDevice(Irp, DeviceObject);
}
Irp->IoStatus.Status = Status; Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = Information; Irp->IoStatus.Information = Information;

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.15 2002/06/06 23:19:53 ekohl Exp $ /* $Id: disk.c,v 1.16 2002/07/18 18:09:29 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -43,6 +43,7 @@ typedef struct _DISK_DATA
{ {
ULONG HiddenSectors; ULONG HiddenSectors;
ULONG PartitionNumber; ULONG PartitionNumber;
ULONG PartitionOrdinal;
UCHAR PartitionType; UCHAR PartitionType;
BOOLEAN BootIndicator; BOOLEAN BootIndicator;
BOOLEAN DriveNotReady; BOOLEAN DriveNotReady;
@ -352,29 +353,31 @@ DiskClassCheckReadWrite(IN PDEVICE_OBJECT DeviceObject,
} }
// DiskClassCreateDeviceObject /**********************************************************************
// * NAME EXPORTED
// DESCRIPTION: * DiskClassCreateDeviceObject
// 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 * The system created driver object
// this device * RegistryPath
// IN int DriveIdx The index of the drive on this * PortDeviceObject
// controller * PortNumber
// IN int HarddiskIdx The NT device number for this * DiskNumber
// drive * Capabilities
// * InquiryData
// RETURNS: * InitialzationData
// TRUE Drive exists and devices were created *
// FALSE no devices were created for this device * RETURN VALUE
// * STATUS_SUCCESS: Device objects for disk and partitions were created.
* Others: Failure.
*/
static NTSTATUS static NTSTATUS
DiskClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject, DiskClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
@ -643,6 +646,7 @@ DiskClassCreateDeviceObject(IN PDRIVER_OBJECT DriverObject,
DiskData = (PDISK_DATA)(PartitionDeviceExtension + 1); DiskData = (PDISK_DATA)(PartitionDeviceExtension + 1);
DiskData->PartitionType = PartitionEntry->PartitionType; DiskData->PartitionType = PartitionEntry->PartitionType;
DiskData->PartitionNumber = PartitionNumber + 1; DiskData->PartitionNumber = PartitionNumber + 1;
DiskData->PartitionOrdinal = PartitionNumber + 1;
DiskData->HiddenSectors = PartitionEntry->HiddenSectors; DiskData->HiddenSectors = PartitionEntry->HiddenSectors;
DiskData->BootIndicator = PartitionEntry->BootIndicator; DiskData->BootIndicator = PartitionEntry->BootIndicator;
DiskData->DriveNotReady = FALSE; DiskData->DriveNotReady = FALSE;
@ -770,9 +774,30 @@ DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
break; break;
case IOCTL_DISK_SET_PARTITION_INFO: case IOCTL_DISK_SET_PARTITION_INFO:
DPRINT1("Unhandled IOCTL_DISK_SET_PARTITION_INFO\n"); if (IrpStack->Parameters.DeviceIoControl.InputBufferLength <
Status = STATUS_INVALID_DEVICE_REQUEST; sizeof(SET_PARTITION_INFORMATION))
Information = 0; {
Status = STATUS_INFO_LENGTH_MISMATCH;
}
else if (DiskData->PartitionNumber == 0)
{
Status = STATUS_INVALID_DEVICE_REQUEST;
}
else
{
PSET_PARTITION_INFORMATION PartitionInfo;
PartitionInfo = (PSET_PARTITION_INFORMATION)Irp->AssociatedIrp.SystemBuffer;
Status = IoSetPartitionInformation(DeviceExtension->PhysicalDevice,
DeviceExtension->DiskGeometry->BytesPerSector,
DiskData->PartitionOrdinal,
PartitionInfo->PartitionType);
if (NT_SUCCESS(Status))
{
DiskData->PartitionType = PartitionInfo->PartitionType;
}
}
break; break;
case IOCTL_DISK_GET_DRIVE_LAYOUT: case IOCTL_DISK_GET_DRIVE_LAYOUT:
@ -837,6 +862,12 @@ DiskClassDeviceControl(IN PDEVICE_OBJECT DeviceObject,
return(ScsiClassDeviceControl(DeviceObject, Irp)); return(ScsiClassDeviceControl(DeviceObject, Irp));
} }
/* Verify the device if the user caused the error */
if (!NT_SUCCESS(Status) && IoIsErrorUserInduced(Status))
{
IoSetHardErrorOrVerifyDevice(Irp, DeviceObject);
}
Irp->IoStatus.Status = Status; Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = Information; Irp->IoStatus.Information = Information;
IoCompleteRequest(Irp, IoCompleteRequest(Irp,
@ -871,14 +902,72 @@ NTSTATUS STDCALL
DiskClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject, DiskClassShutdownFlush(IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp) IN PIRP Irp)
{ {
PDEVICE_EXTENSION DeviceExtension;
PIO_STACK_LOCATION IrpStack;
PSCSI_REQUEST_BLOCK Srb;
DPRINT("DiskClassShutdownFlush() called!\n"); DPRINT("DiskClassShutdownFlush() called!\n");
Irp->IoStatus.Status = STATUS_SUCCESS; DeviceExtension = DeviceObject->DeviceExtension;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(STATUS_SUCCESS); /* Allocate SRB */
Srb = ExAllocatePool(NonPagedPool,
sizeof(SCSI_REQUEST_BLOCK));
if (Srb == NULL)
{
Irp->IoStatus.Status = STATUS_INSUFFICIENT_RESOURCES;
Irp->IoStatus.Information = 0;
IoCompleteRequest(Irp, IO_NO_INCREMENT);
return(STATUS_INSUFFICIENT_RESOURCES);
}
/* Initialize SRB */
RtlZeroMemory(Srb, sizeof(SCSI_REQUEST_BLOCK));
Srb->Length = sizeof(SCSI_REQUEST_BLOCK);
/* Set device IDs */
Srb->PathId = DeviceExtension->PathId;
Srb->TargetId = DeviceExtension->TargetId;
Srb->Lun = DeviceExtension->Lun;
/* FIXME: Flush write cache */
/* Get current stack location */
IrpStack = IoGetCurrentIrpStackLocation(Irp);
/* FIXME: Unlock removable media upon shutdown */
/* No retry */
IrpStack->Parameters.Others.Argument4 = (PVOID)0;
/* Send shutdown or flush request to the port driver */
Srb->CdbLength = 0;
if (IrpStack->MajorFunction == IRP_MJ_SHUTDOWN)
Srb->Function = SRB_FUNCTION_SHUTDOWN;
else
Srb->Function = SRB_FUNCTION_FLUSH;
/* Init completion routine */
IoSetCompletionRoutine(Irp,
ScsiClassIoComplete,
Srb,
TRUE,
TRUE,
TRUE);
/* Prepare next stack location for a call to the port driver */
IrpStack = IoGetNextIrpStackLocation(Irp);
IrpStack->MajorFunction = IRP_MJ_SCSI;
IrpStack->Parameters.Scsi.Srb = Srb;
Srb->OriginalRequest = Irp;
/* Call port driver */
return(IoCallDriver(DeviceExtension->PortDeviceObject, Irp));
} }
/* EOF */ /* EOF */

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: scsiport.c,v 1.17 2002/07/15 18:25:17 hbirr Exp $ /* $Id: scsiport.c,v 1.18 2002/07/18 18:09:59 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -706,42 +706,17 @@ ScsiPortDispatchScsi(IN PDEVICE_OBJECT DeviceObject,
NTSTATUS Status = STATUS_SUCCESS; NTSTATUS Status = STATUS_SUCCESS;
ULONG DataSize = 0; ULONG DataSize = 0;
DPRINT("ScsiPortDispatchScsi(DeviceObject %p Irp %p)\n", DPRINT("ScsiPortDispatchScsi(DeviceObject %p Irp %p)\n",
DeviceObject, Irp); DeviceObject, Irp);
DeviceExtension = DeviceObject->DeviceExtension; DeviceExtension = DeviceObject->DeviceExtension;
Stack = IoGetCurrentIrpStackLocation(Irp); Stack = IoGetCurrentIrpStackLocation(Irp);
switch(Stack->Parameters.DeviceIoControl.IoControlCode)
{
case IOCTL_SCSI_EXECUTE_IN:
{
DPRINT(" IOCTL_SCSI_EXECUTE_IN\n");
}
break;
case IOCTL_SCSI_EXECUTE_OUT:
{
DPRINT(" IOCTL_SCSI_EXECUTE_OUT\n");
}
break;
case IOCTL_SCSI_EXECUTE_NONE:
{
DPRINT(" IOCTL_SCSI_EXECUTE_NONE\n");
}
break;
}
Srb = Stack->Parameters.Scsi.Srb; Srb = Stack->Parameters.Scsi.Srb;
if (Srb == NULL) if (Srb == NULL)
{ {
Status = STATUS_UNSUCCESSFUL; Status = STATUS_UNSUCCESSFUL;
Irp->IoStatus.Status = Status; Irp->IoStatus.Status = Status;
Irp->IoStatus.Information = 0; Irp->IoStatus.Information = 0;
@ -757,11 +732,18 @@ ScsiPortDispatchScsi(IN PDEVICE_OBJECT DeviceObject,
switch (Srb->Function) switch (Srb->Function)
{ {
case SRB_FUNCTION_EXECUTE_SCSI: case SRB_FUNCTION_EXECUTE_SCSI:
DPRINT(" SRB_FUNCTION_EXECUTE_SCSI\n");
IoStartPacket(DeviceObject, Irp, NULL, NULL); IoStartPacket(DeviceObject, Irp, NULL, NULL);
DPRINT("Returning STATUS_PENDING\n");
return(STATUS_PENDING); return(STATUS_PENDING);
case SRB_FUNCTION_SHUTDOWN:
case SRB_FUNCTION_FLUSH:
if (DeviceExtension->PortConfig.CachesData == TRUE)
{
IoStartPacket(DeviceObject, Irp, NULL, NULL);
return(STATUS_PENDING);
}
break;
case SRB_FUNCTION_CLAIM_DEVICE: case SRB_FUNCTION_CLAIM_DEVICE:
{ {
PSCSI_ADAPTER_BUS_INFO AdapterInfo; PSCSI_ADAPTER_BUS_INFO AdapterInfo;
@ -849,6 +831,11 @@ ScsiPortDispatchScsi(IN PDEVICE_OBJECT DeviceObject,
} }
} }
break; break;
default:
DPRINT1("SRB function not implemented (Function %lu)\n", Srb->Function);
Status = STATUS_NOT_IMPLEMENTED;
break;
} }
Irp->IoStatus.Status = Status; Irp->IoStatus.Status = Status;

View file

@ -1,4 +1,4 @@
/* $Id: disk.h,v 1.8 2002/05/29 21:39:06 ekohl Exp $ /* $Id: disk.h,v 1.9 2002/07/18 18:08:27 ekohl Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -105,7 +105,8 @@
(P) == PARTITION_XINT13_EXTENDED) (P) == PARTITION_XINT13_EXTENDED)
typedef enum _MEDIA_TYPE { typedef enum _MEDIA_TYPE
{
Unknown, Unknown,
F5_1Pt2_512, F5_1Pt2_512,
F3_1Pt44_512, F3_1Pt44_512,
@ -123,30 +124,35 @@ typedef enum _MEDIA_TYPE {
typedef struct _PARTITION_INFORMATION typedef struct _PARTITION_INFORMATION
{ {
LARGE_INTEGER StartingOffset; LARGE_INTEGER StartingOffset;
LARGE_INTEGER PartitionLength; LARGE_INTEGER PartitionLength;
DWORD HiddenSectors; DWORD HiddenSectors;
DWORD PartitionNumber; DWORD PartitionNumber;
BYTE PartitionType; BYTE PartitionType;
BOOLEAN BootIndicator; BOOLEAN BootIndicator;
BOOLEAN RecognizedPartition; BOOLEAN RecognizedPartition;
BOOLEAN RewritePartition; BOOLEAN RewritePartition;
} PARTITION_INFORMATION, *PPARTITION_INFORMATION; } PARTITION_INFORMATION, *PPARTITION_INFORMATION;
typedef struct _DRIVE_LAYOUT_INFORMATION typedef struct _DRIVE_LAYOUT_INFORMATION
{ {
DWORD PartitionCount; DWORD PartitionCount;
DWORD Signature; DWORD Signature;
PARTITION_INFORMATION PartitionEntry[1]; PARTITION_INFORMATION PartitionEntry[1];
} DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION; } DRIVE_LAYOUT_INFORMATION, *PDRIVE_LAYOUT_INFORMATION;
typedef struct _SET_PARTITION_INFORMATION
{
ULONG PartitionType;
} SET_PARTITION_INFORMATION, *PSET_PARTITION_INFORMATION;
typedef struct _DISK_GEOMETRY typedef struct _DISK_GEOMETRY
{ {
LARGE_INTEGER Cylinders; LARGE_INTEGER Cylinders;
MEDIA_TYPE MediaType; MEDIA_TYPE MediaType;
DWORD TracksPerCylinder; DWORD TracksPerCylinder;
DWORD SectorsPerTrack; DWORD SectorsPerTrack;
DWORD BytesPerSector; DWORD BytesPerSector;
} DISK_GEOMETRY, *PDISK_GEOMETRY; } DISK_GEOMETRY, *PDISK_GEOMETRY;
#endif /* __INCLUDE_DISK_H */ #endif /* __INCLUDE_DISK_H */