2 * PROJECT: ReactOS Storage Stack
3 * LICENSE: DDK - see license.txt in the root dir
4 * FILE: drivers/storage/disk/disk.c
5 * PURPOSE: Disk class driver
6 * PROGRAMMERS: Based on a source code sample from Microsoft NT4 DDK
15 #include <include/class2.h>
21 #define IO_WRITE_CACHE_ENABLED ((NTSTATUS)0x80040020L)
22 #define IO_WRITE_CACHE_DISABLED ((NTSTATUS)0x80040022L)
28 #define ExAllocatePool(a,b) ExAllocatePoolWithTag(a,b,'DscS')
35 } PARTITION_LIST_STATE
;
41 typedef struct _DISK_DATA
{
47 PDEVICE_EXTENSION NextPartition
;
50 // Disk signature (from MBR)
62 // Number of hidden sectors for BPB.
68 // Partition number of this device object
70 // This field is set during driver initialization or when the partition
71 // is created to identify a parition to the system.
74 ULONG PartitionNumber
;
77 // This field is the ordinal of a partition as it appears on a disk.
80 ULONG PartitionOrdinal
;
83 // Partition type of this device object
85 // This field is set by:
87 // 1) Initially set according to the partition list entry partition
88 // type returned by IoReadPartitionTable.
90 // 2) Subsequently set by the IOCTL_DISK_SET_PARTITION_INFORMATION
91 // I/O control function when IoSetPartitionInformation function
92 // successfully updates the partition type on the disk.
98 // Boot indicator - indicates whether this partition is a bootable (active)
99 // partition for this device
101 // This field is set according to the partition list entry boot indicator
102 // returned by IoReadPartitionTable.
105 BOOLEAN BootIndicator
;
108 // DriveNotReady - inidicates that the this device is currenly not ready
109 // because there is no media in the device.
112 BOOLEAN DriveNotReady
;
115 // State of PartitionList initialization
118 PARTITION_LIST_STATE PartitionListState
;
120 } DISK_DATA
, *PDISK_DATA
;
123 // Define a general structure of identfing disk controllers with bad
127 typedef struct _BAD_CONTROLLER_INFORMATION
{
129 BOOLEAN DisableTaggedQueuing
;
130 BOOLEAN DisableSynchronousTransfers
;
131 BOOLEAN DisableDisconnects
;
132 BOOLEAN DisableWriteCache
;
133 }BAD_CONTROLLER_INFORMATION
, *PBAD_CONTROLLER_INFORMATION
;
135 BAD_CONTROLLER_INFORMATION
const ScsiDiskBadControllers
[] = {
136 { "TOSHIBA MK538FB 60", TRUE
, FALSE
, FALSE
, FALSE
},
137 { "CONNER CP3500", FALSE
, TRUE
, FALSE
, FALSE
},
138 { "OLIVETTICP3500", FALSE
, TRUE
, FALSE
, FALSE
},
139 { "SyQuest SQ5110 CHC", TRUE
, TRUE
, FALSE
, FALSE
},
140 { "SEAGATE ST41601N 0102", FALSE
, TRUE
, FALSE
, FALSE
},
141 { "SEAGATE ST3655N", FALSE
, FALSE
, FALSE
, TRUE
},
142 { "SEAGATE ST3390N", FALSE
, FALSE
, FALSE
, TRUE
},
143 { "SEAGATE ST12550N", FALSE
, FALSE
, FALSE
, TRUE
},
144 { "SEAGATE ST32430N", FALSE
, FALSE
, FALSE
, TRUE
},
145 { "SEAGATE ST31230N", FALSE
, FALSE
, FALSE
, TRUE
},
146 { "SEAGATE ST15230N", FALSE
, FALSE
, FALSE
, TRUE
},
147 { "FUJITSU M2652S-512", TRUE
, FALSE
, FALSE
, FALSE
},
148 { "MAXTOR MXT-540SL I1.2", TRUE
, FALSE
, FALSE
, FALSE
},
149 { "COMPAQ PD-1", FALSE
, TRUE
, FALSE
, FALSE
}
153 #define NUMBER_OF_BAD_CONTROLLERS (sizeof(ScsiDiskBadControllers) / sizeof(BAD_CONTROLLER_INFORMATION))
154 #define DEVICE_EXTENSION_SIZE sizeof(DEVICE_EXTENSION) + sizeof(DISK_DATA)
156 #define MODE_DATA_SIZE 192
157 #define VALUE_BUFFER_SIZE 2048
158 #define SCSI_DISK_TIMEOUT 10
159 #define PARTITION0_LIST_SIZE 4
165 IN PDRIVER_OBJECT DriverObject
,
166 IN PUNICODE_STRING RegistryPath
171 ScsiDiskDeviceVerification(
172 IN PINQUIRYDATA InquiryData
178 IN PDRIVER_OBJECT DriveObject
,
179 IN PUNICODE_STRING RegistryPath
,
180 IN PCLASS_INIT_DATA InitializationData
,
181 IN PDEVICE_OBJECT PortDeviceObject
,
187 ScsiDiskCreateClose (
188 IN PDEVICE_OBJECT DeviceObject
,
194 ScsiDiskReadWriteVerification(
195 IN PDEVICE_OBJECT DeviceObject
,
201 ScsiDiskDeviceControl(
202 IN PDEVICE_OBJECT DeviceObject
,
208 ScsiDiskProcessError(
209 PDEVICE_OBJECT DeviceObject
,
210 PSCSI_REQUEST_BLOCK Srb
,
217 ScsiDiskShutdownFlush(
218 IN PDEVICE_OBJECT DeviceObject
,
225 IN PDEVICE_OBJECT DeviceObject
,
226 IN PSCSI_INQUIRY_DATA LunInfo
232 IN PDEVICE_OBJECT DeviceObject
,
233 IN PCHAR ModeSelectBuffer
,
241 IN PDEVICE_OBJECT DeviceObject
246 CalculateMbrCheckSum(
247 IN PDEVICE_EXTENSION DeviceExtension
,
254 IN PDEVICE_EXTENSION DeviceExtension
,
262 IN PDEVICE_EXTENSION DeviceExtension
267 UpdateRemovableGeometry (
268 IN PDEVICE_OBJECT DeviceObject
,
274 CreateDiskDeviceObject(
275 IN PDRIVER_OBJECT DriverObject
,
276 IN PUNICODE_STRING RegistryPath
,
277 IN PDEVICE_OBJECT PortDeviceObject
,
279 IN PULONG DeviceCount
,
280 IN PIO_SCSI_CAPABILITIES PortCapabilities
,
281 IN PSCSI_INQUIRY_DATA LunInfo
,
282 IN PCLASS_INIT_DATA InitData
287 CreatePartitionDeviceObjects(
288 IN PDEVICE_OBJECT PhysicalDeviceObject
,
289 IN PUNICODE_STRING RegistryPath
295 IN PDEVICE_OBJECT DeviceObject
,
302 PDEVICE_OBJECT DeviceObject
,
303 PSCSI_INQUIRY_DATA LunInfo
,
304 PIO_SCSI_CAPABILITIES PortCapabilities
310 IN PDEVICE_OBJECT DeviceObject
314 #pragma alloc_text(PAGE, DriverEntry)
315 #pragma alloc_text(PAGE, FindScsiDisks)
316 #pragma alloc_text(PAGE, CreateDiskDeviceObject)
317 #pragma alloc_text(PAGE, CalculateMbrCheckSum)
318 #pragma alloc_text(PAGE, EnumerateBusKey)
319 #pragma alloc_text(PAGE, UpdateGeometry)
320 #pragma alloc_text(PAGE, IsFloppyDevice)
321 #pragma alloc_text(PAGE, ScanForSpecial)
322 #pragma alloc_text(PAGE, ScsiDiskDeviceControl)
323 #pragma alloc_text(PAGE, ScsiDiskModeSelect)
330 IN PDRIVER_OBJECT DriverObject
,
331 IN PUNICODE_STRING RegistryPath
338 This routine initializes the SCSI hard disk class driver.
342 DriverObject - Pointer to driver object created by system.
344 RegistryPath - Pointer to the name of the services node for this driver.
348 The function value is the final status from the initialization operation.
353 CLASS_INIT_DATA InitializationData
;
359 RtlZeroMemory (&InitializationData
, sizeof(CLASS_INIT_DATA
));
365 InitializationData
.InitializationDataSize
= sizeof(CLASS_INIT_DATA
);
366 InitializationData
.DeviceExtensionSize
= DEVICE_EXTENSION_SIZE
;
368 InitializationData
.DeviceType
= FILE_DEVICE_DISK
;
369 InitializationData
.DeviceCharacteristics
= 0;
375 InitializationData
.ClassError
= ScsiDiskProcessError
;
376 InitializationData
.ClassReadWriteVerification
= ScsiDiskReadWriteVerification
;
377 InitializationData
.ClassFindDevices
= FindScsiDisks
;
378 InitializationData
.ClassFindDeviceCallBack
= ScsiDiskDeviceVerification
;
379 InitializationData
.ClassDeviceControl
= ScsiDiskDeviceControl
;
380 InitializationData
.ClassShutdownFlush
= ScsiDiskShutdownFlush
;
381 InitializationData
.ClassCreateClose
= NULL
;
384 // Call the class init routine
387 return ScsiClassInitialize( DriverObject
, RegistryPath
, &InitializationData
);
389 } // end DriverEntry()
395 ScsiDiskDeviceVerification(
396 IN PINQUIRYDATA InquiryData
403 This routine checks InquiryData for the correct device type and qualifier.
407 InquiryData - Pointer to the inquiry data for the device in question.
411 True is returned if the correct device type is found.
416 if (((InquiryData
->DeviceType
== DIRECT_ACCESS_DEVICE
) ||
417 (InquiryData
->DeviceType
== OPTICAL_DEVICE
)) &&
418 InquiryData
->DeviceTypeQualifier
== 0) {
431 IN PDRIVER_OBJECT DriverObject
,
432 IN PUNICODE_STRING RegistryPath
,
433 IN PCLASS_INIT_DATA InitializationData
,
434 IN PDEVICE_OBJECT PortDeviceObject
,
442 This routine gets a port drivers capabilities, obtains the
443 inquiry data, searches the SCSI bus for the port driver and creates
444 the device objects for the disks found.
448 DriverObject - Pointer to driver object created by system.
450 PortDeviceObject - Device object use to send requests to port driver.
452 PortNumber - Number for port driver. Used to pass on to
453 CreateDiskDeviceObjects() and create device objects.
457 True is returned if one disk was found and successfully created.
462 PIO_SCSI_CAPABILITIES portCapabilities
;
464 PCONFIGURATION_INFORMATION configurationInformation
;
466 PSCSI_INQUIRY_DATA lunInfo
;
467 PSCSI_ADAPTER_BUS_INFO adapterInfo
;
468 PINQUIRYDATA inquiryData
;
472 BOOLEAN foundOne
= FALSE
;
477 // Call port driver to get adapter capabilities.
480 status
= ScsiClassGetCapabilities(PortDeviceObject
, &portCapabilities
);
482 if (!NT_SUCCESS(status
)) {
483 DebugPrint((1,"FindScsiDevices: ScsiClassGetCapabilities failed\n"));
488 // Call port driver to get inquiry information to find disks.
491 status
= ScsiClassGetInquiryData(PortDeviceObject
, (PSCSI_ADAPTER_BUS_INFO
*) &buffer
);
493 if (!NT_SUCCESS(status
)) {
494 DebugPrint((1,"FindScsiDevices: ScsiClassGetInquiryData failed\n"));
499 // Do a quick scan of the devices on this adapter to determine how many
500 // disks are on this adapter. This is used to determine the number of
501 // SRB zone elements to allocate.
505 adapterInfo
= (PVOID
) buffer
;
507 adapterDisk
= ScsiClassFindUnclaimedDevices(InitializationData
, adapterInfo
);
510 // Allocate a zone of SRB for disks on this adapter.
513 if (adapterDisk
== 0) {
516 // No free disks were found.
523 // Get the number of disks already initialized.
526 configurationInformation
= IoGetConfigurationInformation();
527 diskCount
= &configurationInformation
->DiskCount
;
530 // For each SCSI bus this adapter supports ...
533 for (scsiBus
=0; scsiBus
< (ULONG
)adapterInfo
->NumberOfBuses
; scsiBus
++) {
536 // Get the SCSI bus scan data for this bus.
539 lunInfo
= (PVOID
) (buffer
+ adapterInfo
->BusData
[scsiBus
].InquiryDataOffset
);
542 // Search list for unclaimed disk devices.
545 while (adapterInfo
->BusData
[scsiBus
].InquiryDataOffset
) {
547 inquiryData
= (PVOID
)lunInfo
->InquiryData
;
549 if (((inquiryData
->DeviceType
== DIRECT_ACCESS_DEVICE
) ||
550 (inquiryData
->DeviceType
== OPTICAL_DEVICE
)) &&
551 inquiryData
->DeviceTypeQualifier
== 0 &&
552 (!lunInfo
->DeviceClaimed
)) {
555 "FindScsiDevices: Vendor string is %.24s\n",
556 inquiryData
->VendorId
));
559 // Create device objects for disk
562 status
= CreateDiskDeviceObject(DriverObject
,
571 if (NT_SUCCESS(status
)) {
574 // Increment system disk device count.
587 if (lunInfo
->NextInquiryDataOffset
== 0) {
591 lunInfo
= (PVOID
) (buffer
+ lunInfo
->NextInquiryDataOffset
);
597 // Buffer is allocated by ScsiClassGetInquiryData and must be free returning.
604 } // end FindScsiDisks()
609 CreateDiskDeviceObject(
610 IN PDRIVER_OBJECT DriverObject
,
611 IN PUNICODE_STRING RegistryPath
,
612 IN PDEVICE_OBJECT PortDeviceObject
,
614 IN PULONG DeviceCount
,
615 IN PIO_SCSI_CAPABILITIES PortCapabilities
,
616 IN PSCSI_INQUIRY_DATA LunInfo
,
617 IN PCLASS_INIT_DATA InitData
624 This routine creates an object for the physical device and then searches
625 the device for partitions and creates an object for each partition.
629 DriverObject - Pointer to driver object created by system.
631 PortDeviceObject - Miniport device object.
633 PortNumber - port number. Used in creating disk objects.
635 DeviceCount - Number of previously installed devices.
637 PortCapabilities - Capabilities of this SCSI port.
639 LunInfo - LUN specific information.
647 CCHAR ntNameBuffer
[MAXIMUM_FILENAME_LENGTH
];
649 UNICODE_STRING ntUnicodeString
;
650 OBJECT_ATTRIBUTES objectAttributes
;
653 PDEVICE_OBJECT deviceObject
= NULL
;
654 PDEVICE_OBJECT physicalDevice
;
655 PDISK_GEOMETRY_EX diskGeometry
= NULL
;
656 PDEVICE_EXTENSION deviceExtension
= NULL
;
657 PDEVICE_EXTENSION physicalDeviceExtension
;
658 UCHAR pathId
= LunInfo
->PathId
;
659 UCHAR targetId
= LunInfo
->TargetId
;
660 UCHAR lun
= LunInfo
->Lun
;
662 PVOID senseData
= NULL
;
665 BOOLEAN srbListInitialized
= FALSE
;
671 // Set up an object directory to contain the objects for this
672 // device and all its partitions.
675 sprintf(ntNameBuffer
,
676 "\\Device\\Harddisk%lu",
679 RtlInitString(&ntNameString
,
682 status
= RtlAnsiStringToUnicodeString(&ntUnicodeString
,
686 if (!NT_SUCCESS(status
)) {
690 InitializeObjectAttributes(&objectAttributes
,
692 OBJ_CASE_INSENSITIVE
| OBJ_PERMANENT
,
696 status
= ZwCreateDirectoryObject(&handle
,
697 DIRECTORY_ALL_ACCESS
,
700 RtlFreeUnicodeString(&ntUnicodeString
);
702 if (!NT_SUCCESS(status
)) {
705 "CreateDiskDeviceObjects: Could not create directory %s\n",
715 status
= ScsiClassClaimDevice(PortDeviceObject
,
720 if (!NT_SUCCESS(status
)) {
721 ZwMakeTemporaryObject(handle
);
727 // Create a device object for this device. Each physical disk will
728 // have at least one device object. The required device object
729 // describes the entire device. Its directory path is
730 // \Device\HarddiskN\Partition0, where N = device number.
733 sprintf(ntNameBuffer
,
734 "\\Device\\Harddisk%lu\\Partition0",
738 status
= ScsiClassCreateDeviceObject(DriverObject
,
744 if (!NT_SUCCESS(status
)) {
747 "CreateDiskDeviceObjects: Can not create device object %s\n",
750 goto CreateDiskDeviceObjectsExit
;
754 // Indicate that IRPs should include MDLs for data transfers.
757 deviceObject
->Flags
|= DO_DIRECT_IO
;
760 // Check if this is during initialization. If not indicate that
761 // system initialization already took place and this disk is ready
766 deviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
770 // Check for removable media support.
773 if (((PINQUIRYDATA
)LunInfo
->InquiryData
)->RemovableMedia
) {
774 deviceObject
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
778 // Set up required stack size in device object.
781 deviceObject
->StackSize
= (CCHAR
)PortDeviceObject
->StackSize
+ 1;
783 deviceExtension
= deviceObject
->DeviceExtension
;
786 // Allocate spinlock for split request completion.
789 KeInitializeSpinLock(&deviceExtension
->SplitRequestSpinLock
);
792 // Initialize lock count to zero. The lock count is used to
793 // disable the ejection mechanism on devices that support
794 // removable media. Only the lock count in the physical
795 // device extension is used.
798 deviceExtension
->LockCount
= 0;
801 // Save system disk number.
804 deviceExtension
->DeviceNumber
= *DeviceCount
;
807 // Copy port device object pointer to the device extension.
810 deviceExtension
->PortDeviceObject
= PortDeviceObject
;
813 // Set the alignment requirements for the device based on the
814 // host adapter requirements
817 if (PortDeviceObject
->AlignmentRequirement
> deviceObject
->AlignmentRequirement
) {
818 deviceObject
->AlignmentRequirement
= PortDeviceObject
->AlignmentRequirement
;
822 // This is the physical device object.
825 physicalDevice
= deviceObject
;
826 physicalDeviceExtension
= deviceExtension
;
829 // Save address of port driver capabilities.
832 deviceExtension
->PortCapabilities
= PortCapabilities
;
835 // Build the lookaside list for srb's for the physical disk. Should only
839 ScsiClassInitializeSrbLookasideList(deviceExtension
,
840 PARTITION0_LIST_SIZE
);
842 srbListInitialized
= TRUE
;
845 // Initialize the srb flags.
848 if (((PINQUIRYDATA
)LunInfo
->InquiryData
)->CommandQueue
&&
849 PortCapabilities
->TaggedQueuing
) {
851 deviceExtension
->SrbFlags
= SRB_FLAGS_QUEUE_ACTION_ENABLE
;
855 deviceExtension
->SrbFlags
= 0;
860 // Allow queued requests if this is not removable media.
863 if (!(deviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
)) {
865 deviceExtension
->SrbFlags
|= SRB_FLAGS_NO_QUEUE_FREEZE
;
870 // Look for controller that require special flags.
873 ScanForSpecial(deviceObject
,
877 srbFlags
= deviceExtension
->SrbFlags
;
880 // Allocate buffer for drive geometry.
883 diskGeometry
= ExAllocatePool(NonPagedPool
, sizeof(DISK_GEOMETRY_EX
));
885 if (diskGeometry
== NULL
) {
888 "CreateDiskDeviceObjects: Can not allocate disk geometry buffer\n"));
889 status
= STATUS_INSUFFICIENT_RESOURCES
;
890 goto CreateDiskDeviceObjectsExit
;
893 deviceExtension
->DiskGeometry
= diskGeometry
;
896 // Allocate request sense buffer.
899 senseData
= ExAllocatePool(NonPagedPoolCacheAligned
, SENSE_BUFFER_SIZE
);
901 if (senseData
== NULL
) {
904 // The buffer can not be allocated.
908 "CreateDiskDeviceObjects: Can not allocate request sense buffer\n"));
910 status
= STATUS_INSUFFICIENT_RESOURCES
;
911 goto CreateDiskDeviceObjectsExit
;
915 // Set the sense data pointer in the device extension.
918 deviceExtension
->SenseData
= senseData
;
921 // Physical device object will describe the entire
922 // device, starting at byte offset 0.
925 deviceExtension
->StartingOffset
.QuadPart
= (LONGLONG
)(0);
928 // TargetId/LUN describes a device location on the SCSI bus.
929 // This information comes from the inquiry buffer.
932 deviceExtension
->PortNumber
= (UCHAR
)PortNumber
;
933 deviceExtension
->PathId
= pathId
;
934 deviceExtension
->TargetId
= targetId
;
935 deviceExtension
->Lun
= lun
;
938 // Set timeout value in seconds.
941 timeOut
= ScsiClassQueryTimeOutRegistryValue(RegistryPath
);
943 deviceExtension
->TimeOutValue
= timeOut
;
945 deviceExtension
->TimeOutValue
= SCSI_DISK_TIMEOUT
;
949 // Back pointer to device object.
952 deviceExtension
->DeviceObject
= deviceObject
;
955 // If this is a removable device, then make sure it is not a floppy.
956 // Perform a mode sense command to determine the media type. Note
957 // IsFloppyDevice also checks for write cache enabled.
960 if (IsFloppyDevice(deviceObject
) && deviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
&&
961 (((PINQUIRYDATA
)LunInfo
->InquiryData
)->DeviceType
== DIRECT_ACCESS_DEVICE
)) {
963 status
= STATUS_NO_SUCH_DEVICE
;
964 goto CreateDiskDeviceObjectsExit
;
967 DisableWriteCache(deviceObject
,LunInfo
);
969 writeCache
= deviceExtension
->DeviceFlags
& DEV_WRITE_CACHE
;
972 // NOTE: At this point one device object has been successfully created.
973 // from here on out return success.
977 // Do READ CAPACITY. This SCSI command
978 // returns the number of bytes on a device.
979 // Device extension is updated with device size.
982 status
= ScsiClassReadDriveCapacity(deviceObject
);
985 // If the read capcity failed then just return, unless this is a
986 // removable disk where a device object partition needs to be created.
989 if (!NT_SUCCESS(status
) &&
990 !(deviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
)) {
993 "CreateDiskDeviceObjects: Can't read capacity for device %s\n",
996 return(STATUS_SUCCESS
);
1001 // Make sure the volume verification bit is off so that
1002 // IoReadPartitionTable will work.
1005 deviceObject
->Flags
&= ~DO_VERIFY_VOLUME
;
1008 status
= CreatePartitionDeviceObjects(deviceObject
, RegistryPath
);
1010 if (NT_SUCCESS(status
))
1011 return STATUS_SUCCESS
;
1014 CreateDiskDeviceObjectsExit
:
1017 // Release the device since an error occurred.
1020 ScsiClassClaimDevice(PortDeviceObject
,
1025 if (diskGeometry
!= NULL
) {
1026 ExFreePool(diskGeometry
);
1029 if (senseData
!= NULL
) {
1030 ExFreePool(senseData
);
1033 if (deviceObject
!= NULL
) {
1035 if (srbListInitialized
) {
1036 ExDeleteNPagedLookasideList(&deviceExtension
->SrbLookasideListHead
);
1039 IoDeleteDevice(deviceObject
);
1043 // Delete directory and return.
1046 if (!NT_SUCCESS(status
)) {
1047 ZwMakeTemporaryObject(handle
);
1054 } // end CreateDiskDeviceObjects()
1059 CreatePartitionDeviceObjects(
1060 IN PDEVICE_OBJECT PhysicalDeviceObject
,
1061 IN PUNICODE_STRING RegistryPath
1064 CCHAR ntNameBuffer
[MAXIMUM_FILENAME_LENGTH
];
1065 ULONG partitionNumber
= 0;
1067 PDEVICE_OBJECT deviceObject
= NULL
;
1068 PDISK_GEOMETRY_EX diskGeometry
= NULL
;
1069 PDRIVE_LAYOUT_INFORMATION partitionList
= NULL
;
1070 PDEVICE_EXTENSION deviceExtension
;
1071 PDEVICE_EXTENSION physicalDeviceExtension
;
1072 PCLASS_INIT_DATA initData
= NULL
;
1073 PDISK_DATA diskData
;
1074 PDISK_DATA physicalDiskData
;
1075 ULONG bytesPerSector
;
1078 ULONG dmByteSkew
= 0;
1080 BOOLEAN dmActive
= FALSE
;
1081 ULONG numberListElements
= 0;
1085 // Get physical device geometry information for partition table reads.
1088 physicalDeviceExtension
= PhysicalDeviceObject
->DeviceExtension
;
1089 diskGeometry
= physicalDeviceExtension
->DiskGeometry
;
1090 bytesPerSector
= diskGeometry
->Geometry
.BytesPerSector
;
1093 // Make sure sector size is not zero.
1096 if (bytesPerSector
== 0) {
1099 // Default sector size for disk is 512.
1102 bytesPerSector
= diskGeometry
->Geometry
.BytesPerSector
= 512;
1105 sectorShift
= physicalDeviceExtension
->SectorShift
;
1108 // Set pointer to disk data area that follows device extension.
1111 diskData
= (PDISK_DATA
)(physicalDeviceExtension
+ 1);
1112 diskData
->PartitionListState
= Initializing
;
1115 // Determine is DM Driver is loaded on an IDE drive that is
1116 // under control of Atapi - this could be either a crashdump or
1117 // an Atapi device is sharing the controller with an IDE disk.
1120 HalExamineMBR(PhysicalDeviceObject
,
1121 physicalDeviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
,
1128 // Update the device extension, so that the call to IoReadPartitionTable
1129 // will get the correct information. Any I/O to this disk will have
1130 // to be skewed by *dmSkew sectors aka DMByteSkew.
1133 physicalDeviceExtension
->DMSkew
= *dmSkew
;
1134 physicalDeviceExtension
->DMActive
= TRUE
;
1135 physicalDeviceExtension
->DMByteSkew
= physicalDeviceExtension
->DMSkew
* bytesPerSector
;
1138 // Save away the infomation that we need, since this deviceExtension will soon be
1143 dmByteSkew
= physicalDeviceExtension
->DMByteSkew
;
1148 // Create objects for all the partitions on the device.
1151 status
= IoReadPartitionTable(PhysicalDeviceObject
,
1152 physicalDeviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
,
1154 (PVOID
)&partitionList
);
1157 // If the I/O read partition table failed and this is a removable device,
1158 // then fix up the partition list to make it look like there is one
1159 // zero length partition.
1161 DPRINT("IoReadPartitionTable() status: 0x%08X\n", status
);
1162 if ((!NT_SUCCESS(status
) || partitionList
->PartitionCount
== 0) &&
1163 PhysicalDeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
) {
1165 if (!NT_SUCCESS(status
)) {
1168 // Remember this disk is not ready.
1171 diskData
->DriveNotReady
= TRUE
;
1176 // Free the partition list allocated by IoReadPartitionTable.
1179 ExFreePool(partitionList
);
1183 // Allocate and zero a partition list.
1186 partitionList
= ExAllocatePool(NonPagedPool
, sizeof(*partitionList
));
1189 if (partitionList
!= NULL
) {
1191 RtlZeroMemory( partitionList
, sizeof( *partitionList
));
1194 // Set the partition count to one and the status to success
1195 // so one device object will be created. Set the partition type
1196 // to a bogus value.
1199 partitionList
->PartitionCount
= 1;
1201 status
= STATUS_SUCCESS
;
1205 if (NT_SUCCESS(status
)) {
1208 // Record disk signature.
1211 diskData
->Signature
= partitionList
->Signature
;
1214 // If disk signature is zero, then calculate the MBR checksum.
1217 if (!diskData
->Signature
) {
1219 if (!CalculateMbrCheckSum(physicalDeviceExtension
,
1220 &diskData
->MbrCheckSum
)) {
1223 "SCSIDISK: Can't calculate MBR checksum for disk %x\n",
1224 physicalDeviceExtension
->DeviceNumber
));
1228 "SCSIDISK: MBR checksum for disk %x is %x\n",
1229 physicalDeviceExtension
->DeviceNumber
,
1230 diskData
->MbrCheckSum
));
1235 // Check the registry and determine if the BIOS knew about this drive. If
1236 // it did then update the geometry with the BIOS information.
1239 UpdateGeometry(physicalDeviceExtension
);
1241 srbFlags
= physicalDeviceExtension
->SrbFlags
;
1243 initData
= ExAllocatePool(NonPagedPool
, sizeof(CLASS_INIT_DATA
));
1247 "Disk.CreatePartionDeviceObjects - Allocation of initData failed\n"));
1249 status
= STATUS_INSUFFICIENT_RESOURCES
;
1250 goto CreatePartitionDeviceObjectsExit
;
1253 RtlZeroMemory(initData
, sizeof(CLASS_INIT_DATA
));
1255 initData
->InitializationDataSize
= sizeof(CLASS_INIT_DATA
);
1256 initData
->DeviceExtensionSize
= DEVICE_EXTENSION_SIZE
;
1257 initData
->DeviceType
= FILE_DEVICE_DISK
;
1258 initData
->DeviceCharacteristics
= PhysicalDeviceObject
->Characteristics
;
1259 initData
->ClassError
= physicalDeviceExtension
->ClassError
;
1260 initData
->ClassReadWriteVerification
= physicalDeviceExtension
->ClassReadWriteVerification
;
1261 initData
->ClassFindDevices
= physicalDeviceExtension
->ClassFindDevices
;
1262 initData
->ClassDeviceControl
= physicalDeviceExtension
->ClassDeviceControl
;
1263 initData
->ClassShutdownFlush
= physicalDeviceExtension
->ClassShutdownFlush
;
1264 initData
->ClassCreateClose
= physicalDeviceExtension
->ClassCreateClose
;
1265 initData
->ClassStartIo
= physicalDeviceExtension
->ClassStartIo
;
1268 // Create device objects for the device partitions (if any).
1269 // PartitionCount includes physical device partition 0,
1270 // so only one partition means no objects to create.
1274 "CreateDiskDeviceObjects: Number of partitions is %d\n",
1275 partitionList
->PartitionCount
));
1277 for (partitionNumber
= 0; partitionNumber
<
1278 partitionList
->PartitionCount
; partitionNumber
++) {
1281 // Create partition object and set up partition parameters.
1284 sprintf(ntNameBuffer
,
1285 "\\Device\\Harddisk%lu\\Partition%lu",
1286 physicalDeviceExtension
->DeviceNumber
,
1287 partitionNumber
+ 1);
1290 "CreateDiskDeviceObjects: Create device object %s\n",
1293 status
= ScsiClassCreateDeviceObject(PhysicalDeviceObject
->DriverObject
,
1295 PhysicalDeviceObject
,
1299 if (!NT_SUCCESS(status
)) {
1301 DebugPrint((1, "CreateDiskDeviceObjects: Can't create device object for %s\n", ntNameBuffer
));
1307 // Set up device object fields.
1310 deviceObject
->Flags
|= DO_DIRECT_IO
;
1313 // Check if this is during initialization. If not indicate that
1314 // system initialization already took place and this disk is ready
1318 if (!RegistryPath
) {
1319 deviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
1322 deviceObject
->StackSize
= (CCHAR
)physicalDeviceExtension
->PortDeviceObject
->StackSize
+ 1;
1325 // Set up device extension fields.
1328 deviceExtension
= deviceObject
->DeviceExtension
;
1333 // Restore any saved DM values.
1336 deviceExtension
->DMByteSkew
= dmByteSkew
;
1337 deviceExtension
->DMSkew
= *dmSkew
;
1338 deviceExtension
->DMActive
= TRUE
;
1343 // Link new device extension to previous disk data
1344 // to support dynamic partitioning.
1347 diskData
->NextPartition
= deviceExtension
;
1350 // Get pointer to new disk data.
1353 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
1356 // Set next partition pointer to NULL in case this is the
1360 diskData
->NextPartition
= NULL
;
1363 // Allocate spinlock for zoning for split-request completion.
1366 KeInitializeSpinLock(&deviceExtension
->SplitRequestSpinLock
);
1369 // Copy port device object pointer to device extension.
1372 deviceExtension
->PortDeviceObject
= physicalDeviceExtension
->PortDeviceObject
;
1375 // Set the alignment requirements for the device based on the
1376 // host adapter requirements
1379 if (physicalDeviceExtension
->PortDeviceObject
->AlignmentRequirement
> deviceObject
->AlignmentRequirement
) {
1380 deviceObject
->AlignmentRequirement
= physicalDeviceExtension
->PortDeviceObject
->AlignmentRequirement
;
1384 if (srbFlags
& SRB_FLAGS_QUEUE_ACTION_ENABLE
) {
1385 numberListElements
= 30;
1387 numberListElements
= 8;
1391 // Build the lookaside list for srb's for this partition based on
1392 // whether the adapter and disk can do tagged queueing.
1395 ScsiClassInitializeSrbLookasideList(deviceExtension
,
1396 numberListElements
);
1398 deviceExtension
->SrbFlags
= srbFlags
;
1401 // Set the sense-data pointer in the device extension.
1404 deviceExtension
->SenseData
= physicalDeviceExtension
->SenseData
;
1405 deviceExtension
->PortCapabilities
= physicalDeviceExtension
->PortCapabilities
;
1406 deviceExtension
->DiskGeometry
= diskGeometry
;
1407 diskData
->PartitionOrdinal
= diskData
->PartitionNumber
= partitionNumber
+ 1;
1408 diskData
->PartitionType
= partitionList
->PartitionEntry
[partitionNumber
].PartitionType
;
1409 diskData
->BootIndicator
= partitionList
->PartitionEntry
[partitionNumber
].BootIndicator
;
1411 DebugPrint((2, "CreateDiskDeviceObjects: Partition type is %x\n",
1412 diskData
->PartitionType
));
1414 deviceExtension
->StartingOffset
= partitionList
->PartitionEntry
[partitionNumber
].StartingOffset
;
1415 deviceExtension
->PartitionLength
= partitionList
->PartitionEntry
[partitionNumber
].PartitionLength
;
1416 diskData
->HiddenSectors
= partitionList
->PartitionEntry
[partitionNumber
].HiddenSectors
;
1417 deviceExtension
->PortNumber
= physicalDeviceExtension
->PortNumber
;
1418 deviceExtension
->PathId
= physicalDeviceExtension
->PathId
;
1419 deviceExtension
->TargetId
= physicalDeviceExtension
->TargetId
;
1420 deviceExtension
->Lun
= physicalDeviceExtension
->Lun
;
1423 // Check for removable media support.
1426 if (PhysicalDeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
) {
1427 deviceObject
->Characteristics
|= FILE_REMOVABLE_MEDIA
;
1431 // Set timeout value in seconds.
1434 deviceExtension
->TimeOutValue
= physicalDeviceExtension
->TimeOutValue
;
1435 deviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
= bytesPerSector
;
1436 deviceExtension
->SectorShift
= sectorShift
;
1437 deviceExtension
->DeviceObject
= deviceObject
;
1438 deviceExtension
->DeviceFlags
|= physicalDeviceExtension
->DeviceFlags
;
1440 } // end for (partitionNumber) ...
1443 // Free the buffer allocated by reading the
1447 ExFreePool(partitionList
);
1451 CreatePartitionDeviceObjectsExit
:
1453 if (partitionList
) {
1454 ExFreePool(partitionList
);
1457 ExFreePool(initData
);
1465 physicalDiskData
= (PDISK_DATA
)(physicalDeviceExtension
+ 1);
1466 physicalDiskData
->PartitionListState
= Initialized
;
1468 return(STATUS_SUCCESS
);
1471 } // end CreatePartitionDeviceObjects()
1476 ScsiDiskReadWriteVerification(
1477 IN PDEVICE_OBJECT DeviceObject
,
1483 Routine Description:
1485 I/O System entry for read and write requests to SCSI disks.
1489 DeviceObject - Pointer to driver object created by system.
1499 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
1500 PIO_STACK_LOCATION currentIrpStack
= IoGetCurrentIrpStackLocation(Irp
);
1501 ULONG transferByteCount
= currentIrpStack
->Parameters
.Read
.Length
;
1502 LARGE_INTEGER startingOffset
;
1505 // Verify parameters of this request.
1506 // Check that ending sector is within partition and
1507 // that number of bytes to transfer is a multiple of
1511 startingOffset
.QuadPart
= (currentIrpStack
->Parameters
.Read
.ByteOffset
.QuadPart
+
1514 if ((startingOffset
.QuadPart
> deviceExtension
->PartitionLength
.QuadPart
) ||
1515 (transferByteCount
& (deviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
- 1))) {
1518 // This error maybe caused by the fact that the drive is not ready.
1521 if (((PDISK_DATA
)(deviceExtension
+ 1))->DriveNotReady
) {
1524 // Flag this as a user errror so that a popup is generated.
1527 Irp
->IoStatus
.Status
= STATUS_DEVICE_NOT_READY
;
1528 IoSetHardErrorOrVerifyDevice(Irp
, DeviceObject
);
1533 // Note fastfat depends on this parameter to determine when to
1534 // remount do to a sector size change.
1537 Irp
->IoStatus
.Status
= STATUS_INVALID_PARAMETER
;
1540 return STATUS_INVALID_PARAMETER
;
1543 return STATUS_SUCCESS
;
1545 } // end ScsiDiskReadWrite()
1550 ScsiDiskDeviceControl(
1551 PDEVICE_OBJECT DeviceObject
,
1557 Routine Description:
1559 I/O system entry for device controls to SCSI disks.
1563 DeviceObject - Pointer to driver object created by system.
1573 PIO_STACK_LOCATION irpStack
= IoGetCurrentIrpStackLocation(Irp
);
1574 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
1575 PDISK_DATA diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
1576 PSCSI_REQUEST_BLOCK srb
;
1578 PMODE_PARAMETER_HEADER modeData
;
1583 IO_STATUS_BLOCK ioStatus
;
1587 srb
= ExAllocatePool(NonPagedPool
, SCSI_REQUEST_BLOCK_SIZE
);
1591 Irp
->IoStatus
.Status
= STATUS_INSUFFICIENT_RESOURCES
;
1592 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
1593 return(STATUS_INSUFFICIENT_RESOURCES
);
1597 // Write zeros to Srb.
1600 RtlZeroMemory(srb
, SCSI_REQUEST_BLOCK_SIZE
);
1602 cdb
= (PCDB
)srb
->Cdb
;
1604 switch (irpStack
->Parameters
.DeviceIoControl
.IoControlCode
) {
1606 case SMART_GET_VERSION
: {
1609 PSRB_IO_CONTROL srbControl
;
1610 PGETVERSIONINPARAMS versionParams
;
1612 if (irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
<
1613 sizeof(GETVERSIONINPARAMS
)) {
1614 status
= STATUS_INVALID_PARAMETER
;
1619 // Create notification event object to be used to signal the
1620 // request completion.
1623 KeInitializeEvent(&event
, NotificationEvent
, FALSE
);
1625 srbControl
= ExAllocatePool(NonPagedPool
,
1626 sizeof(SRB_IO_CONTROL
) + sizeof(GETVERSIONINPARAMS
));
1629 status
= STATUS_INSUFFICIENT_RESOURCES
;
1634 // fill in srbControl fields
1637 srbControl
->HeaderLength
= sizeof(SRB_IO_CONTROL
);
1638 RtlMoveMemory (srbControl
->Signature
, "SCSIDISK", 8);
1639 srbControl
->Timeout
= deviceExtension
->TimeOutValue
;
1640 srbControl
->Length
= sizeof(GETVERSIONINPARAMS
);
1641 srbControl
->ControlCode
= IOCTL_SCSI_MINIPORT_SMART_VERSION
;
1644 // Point to the 'buffer' portion of the SRB_CONTROL
1647 buffer
= (ULONG_PTR
)srbControl
+ srbControl
->HeaderLength
;
1650 // Ensure correct target is set in the cmd parameters.
1653 versionParams
= (PGETVERSIONINPARAMS
)buffer
;
1654 versionParams
->bIDEDeviceMap
= deviceExtension
->TargetId
;
1657 // Copy the IOCTL parameters to the srb control buffer area.
1660 RtlMoveMemory((PVOID
)buffer
, Irp
->AssociatedIrp
.SystemBuffer
, sizeof(GETVERSIONINPARAMS
));
1663 irp2
= IoBuildDeviceIoControlRequest(IOCTL_SCSI_MINIPORT
,
1664 deviceExtension
->PortDeviceObject
,
1666 sizeof(SRB_IO_CONTROL
) + sizeof(GETVERSIONINPARAMS
),
1668 sizeof(SRB_IO_CONTROL
) + sizeof(GETVERSIONINPARAMS
),
1674 status
= STATUS_INSUFFICIENT_RESOURCES
;
1679 // Call the port driver with the request and wait for it to complete.
1682 status
= IoCallDriver(deviceExtension
->PortDeviceObject
, irp2
);
1684 if (status
== STATUS_PENDING
) {
1685 KeWaitForSingleObject(&event
, Suspended
, KernelMode
, FALSE
, NULL
);
1686 status
= ioStatus
.Status
;
1690 // If successful, copy the data received into the output buffer.
1691 // This should only fail in the event that the IDE driver is older than this driver.
1694 if (NT_SUCCESS(status
)) {
1696 buffer
= (ULONG_PTR
)srbControl
+ srbControl
->HeaderLength
;
1698 RtlMoveMemory ( Irp
->AssociatedIrp
.SystemBuffer
, (PVOID
)buffer
, sizeof(GETVERSIONINPARAMS
));
1699 Irp
->IoStatus
.Information
= sizeof(GETVERSIONINPARAMS
);
1702 ExFreePool(srbControl
);
1706 case SMART_RCV_DRIVE_DATA
: {
1708 PSENDCMDINPARAMS cmdInParameters
= ((PSENDCMDINPARAMS
)Irp
->AssociatedIrp
.SystemBuffer
);
1709 ULONG controlCode
= 0;
1710 PSRB_IO_CONTROL srbControl
;
1713 if (irpStack
->Parameters
.DeviceIoControl
.InputBufferLength
<
1714 (sizeof(SENDCMDINPARAMS
) - 1)) {
1715 status
= STATUS_INVALID_PARAMETER
;
1718 } else if (irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
<
1719 (sizeof(SENDCMDOUTPARAMS
) + 512 - 1)) {
1720 status
= STATUS_INVALID_PARAMETER
;
1725 // Create notification event object to be used to signal the
1726 // request completion.
1729 KeInitializeEvent(&event
, NotificationEvent
, FALSE
);
1731 if (cmdInParameters
->irDriveRegs
.bCommandReg
== ID_CMD
) {
1733 length
= IDENTIFY_BUFFER_SIZE
+ sizeof(SENDCMDOUTPARAMS
);
1734 controlCode
= IOCTL_SCSI_MINIPORT_IDENTIFY
;
1736 } else if (cmdInParameters
->irDriveRegs
.bCommandReg
== SMART_CMD
) {
1737 switch (cmdInParameters
->irDriveRegs
.bFeaturesReg
) {
1738 case READ_ATTRIBUTES
:
1739 controlCode
= IOCTL_SCSI_MINIPORT_READ_SMART_ATTRIBS
;
1740 length
= READ_ATTRIBUTE_BUFFER_SIZE
+ sizeof(SENDCMDOUTPARAMS
);
1742 case READ_THRESHOLDS
:
1743 controlCode
= IOCTL_SCSI_MINIPORT_READ_SMART_THRESHOLDS
;
1744 length
= READ_THRESHOLD_BUFFER_SIZE
+ sizeof(SENDCMDOUTPARAMS
);
1747 status
= STATUS_INVALID_PARAMETER
;
1752 status
= STATUS_INVALID_PARAMETER
;
1755 if (controlCode
== 0) {
1756 status
= STATUS_INVALID_PARAMETER
;
1760 srbControl
= ExAllocatePool(NonPagedPool
,
1761 sizeof(SRB_IO_CONTROL
) + length
);
1764 status
= STATUS_INSUFFICIENT_RESOURCES
;
1769 // fill in srbControl fields
1772 srbControl
->HeaderLength
= sizeof(SRB_IO_CONTROL
);
1773 RtlMoveMemory (srbControl
->Signature
, "SCSIDISK", 8);
1774 srbControl
->Timeout
= deviceExtension
->TimeOutValue
;
1775 srbControl
->Length
= length
;
1776 srbControl
->ControlCode
= controlCode
;
1779 // Point to the 'buffer' portion of the SRB_CONTROL
1782 buffer
= (ULONG_PTR
)srbControl
+ srbControl
->HeaderLength
;
1785 // Ensure correct target is set in the cmd parameters.
1788 cmdInParameters
->bDriveNumber
= deviceExtension
->TargetId
;
1791 // Copy the IOCTL parameters to the srb control buffer area.
1794 RtlMoveMemory((PVOID
)buffer
, Irp
->AssociatedIrp
.SystemBuffer
, sizeof(SENDCMDINPARAMS
) - 1);
1796 irp2
= IoBuildDeviceIoControlRequest(IOCTL_SCSI_MINIPORT
,
1797 deviceExtension
->PortDeviceObject
,
1799 sizeof(SRB_IO_CONTROL
) + sizeof(SENDCMDINPARAMS
) - 1,
1801 sizeof(SRB_IO_CONTROL
) + length
,
1807 status
= STATUS_INSUFFICIENT_RESOURCES
;
1812 // Call the port driver with the request and wait for it to complete.
1815 status
= IoCallDriver(deviceExtension
->PortDeviceObject
, irp2
);
1817 if (status
== STATUS_PENDING
) {
1818 KeWaitForSingleObject(&event
, Suspended
, KernelMode
, FALSE
, NULL
);
1819 status
= ioStatus
.Status
;
1823 // If successful, copy the data received into the output buffer
1826 buffer
= (ULONG_PTR
)srbControl
+ srbControl
->HeaderLength
;
1828 if (NT_SUCCESS(status
)) {
1830 RtlMoveMemory ( Irp
->AssociatedIrp
.SystemBuffer
, (PVOID
)buffer
, length
- 1);
1831 Irp
->IoStatus
.Information
= length
- 1;
1835 RtlMoveMemory ( Irp
->AssociatedIrp
.SystemBuffer
, (PVOID
)buffer
, (sizeof(SENDCMDOUTPARAMS
) - 1));
1836 Irp
->IoStatus
.Information
= sizeof(SENDCMDOUTPARAMS
) - 1;
1840 ExFreePool(srbControl
);
1845 case SMART_SEND_DRIVE_COMMAND
: {
1847 PSENDCMDINPARAMS cmdInParameters
= ((PSENDCMDINPARAMS
)Irp
->AssociatedIrp
.SystemBuffer
);
1848 PSRB_IO_CONTROL srbControl
;
1849 ULONG controlCode
= 0;
1852 if (irpStack
->Parameters
.DeviceIoControl
.InputBufferLength
<
1853 (sizeof(SENDCMDINPARAMS
) - 1)) {
1854 status
= STATUS_INVALID_PARAMETER
;
1857 } else if (irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
<
1858 (sizeof(SENDCMDOUTPARAMS
) - 1)) {
1859 status
= STATUS_INVALID_PARAMETER
;
1864 // Create notification event object to be used to signal the
1865 // request completion.
1868 KeInitializeEvent(&event
, NotificationEvent
, FALSE
);
1872 if (cmdInParameters
->irDriveRegs
.bCommandReg
== SMART_CMD
) {
1873 switch (cmdInParameters
->irDriveRegs
.bFeaturesReg
) {
1876 controlCode
= IOCTL_SCSI_MINIPORT_ENABLE_SMART
;
1880 controlCode
= IOCTL_SCSI_MINIPORT_DISABLE_SMART
;
1883 case RETURN_SMART_STATUS
:
1886 // Ensure bBuffer is at least 2 bytes (to hold the values of
1887 // cylinderLow and cylinderHigh).
1890 if (irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
<
1891 (sizeof(SENDCMDOUTPARAMS
) - 1 + sizeof(IDEREGS
))) {
1893 status
= STATUS_INVALID_PARAMETER
;
1897 controlCode
= IOCTL_SCSI_MINIPORT_RETURN_STATUS
;
1898 length
= sizeof(IDEREGS
);
1901 case ENABLE_DISABLE_AUTOSAVE
:
1902 controlCode
= IOCTL_SCSI_MINIPORT_ENABLE_DISABLE_AUTOSAVE
;
1905 case SAVE_ATTRIBUTE_VALUES
:
1906 controlCode
= IOCTL_SCSI_MINIPORT_SAVE_ATTRIBUTE_VALUES
;
1909 case EXECUTE_OFFLINE_DIAGS
:
1910 controlCode
= IOCTL_SCSI_MINIPORT_EXECUTE_OFFLINE_DIAGS
;
1913 status
= STATUS_INVALID_PARAMETER
;
1918 status
= STATUS_INVALID_PARAMETER
;
1921 if (controlCode
== 0) {
1922 status
= STATUS_INVALID_PARAMETER
;
1926 length
+= (sizeof(SENDCMDOUTPARAMS
) > sizeof(SENDCMDINPARAMS
)) ? sizeof(SENDCMDOUTPARAMS
) : sizeof(SENDCMDINPARAMS
);
1927 srbControl
= ExAllocatePool(NonPagedPool
,
1928 sizeof(SRB_IO_CONTROL
) + length
);
1931 status
= STATUS_INSUFFICIENT_RESOURCES
;
1936 // fill in srbControl fields
1939 srbControl
->HeaderLength
= sizeof(SRB_IO_CONTROL
);
1940 RtlMoveMemory (srbControl
->Signature
, "SCSIDISK", 8);
1941 srbControl
->Timeout
= deviceExtension
->TimeOutValue
;
1942 srbControl
->Length
= length
;
1945 // Point to the 'buffer' portion of the SRB_CONTROL
1948 buffer
= (ULONG_PTR
)srbControl
+ srbControl
->HeaderLength
;
1951 // Ensure correct target is set in the cmd parameters.
1954 cmdInParameters
->bDriveNumber
= deviceExtension
->TargetId
;
1957 // Copy the IOCTL parameters to the srb control buffer area.
1960 RtlMoveMemory((PVOID
)buffer
, Irp
->AssociatedIrp
.SystemBuffer
, sizeof(SENDCMDINPARAMS
) - 1);
1962 srbControl
->ControlCode
= controlCode
;
1964 irp2
= IoBuildDeviceIoControlRequest(IOCTL_SCSI_MINIPORT
,
1965 deviceExtension
->PortDeviceObject
,
1967 sizeof(SRB_IO_CONTROL
) + sizeof(SENDCMDINPARAMS
) - 1,
1969 sizeof(SRB_IO_CONTROL
) + length
,
1975 status
= STATUS_INSUFFICIENT_RESOURCES
;
1980 // Call the port driver with the request and wait for it to complete.
1983 status
= IoCallDriver(deviceExtension
->PortDeviceObject
, irp2
);
1985 if (status
== STATUS_PENDING
) {
1986 KeWaitForSingleObject(&event
, Suspended
, KernelMode
, FALSE
, NULL
);
1987 status
= ioStatus
.Status
;
1991 // Copy the data received into the output buffer. Since the status buffer
1992 // contains error information also, always perform this copy. IO will will
1993 // either pass this back to the app, or zero it, in case of error.
1996 buffer
= (ULONG_PTR
)srbControl
+ srbControl
->HeaderLength
;
1999 // Update the return buffer size based on the sub-command.
2002 if (cmdInParameters
->irDriveRegs
.bFeaturesReg
== RETURN_SMART_STATUS
) {
2003 length
= sizeof(SENDCMDOUTPARAMS
) - 1 + sizeof(IDEREGS
);
2005 length
= sizeof(SENDCMDOUTPARAMS
) - 1;
2008 RtlMoveMemory ( Irp
->AssociatedIrp
.SystemBuffer
, (PVOID
)buffer
, length
);
2009 Irp
->IoStatus
.Information
= length
;
2011 ExFreePool(srbControl
);
2016 case IOCTL_DISK_GET_DRIVE_GEOMETRY
:
2017 case IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
:
2020 PDEVICE_EXTENSION physicalDeviceExtension
;
2021 PDISK_DATA physicalDiskData
;
2022 BOOLEAN removable
= FALSE
;
2023 BOOLEAN listInitialized
= FALSE
;
2025 if ((irpStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_DISK_GET_DRIVE_GEOMETRY
&&
2026 irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
<
2027 sizeof(DISK_GEOMETRY
)) ||
2028 (irpStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
&&
2029 irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
<
2030 sizeof(DISK_GEOMETRY_EX
))) {
2032 status
= STATUS_INFO_LENGTH_MISMATCH
;
2036 status
= STATUS_SUCCESS
;
2038 physicalDeviceExtension
= deviceExtension
->PhysicalDevice
->DeviceExtension
;
2039 physicalDiskData
= (PDISK_DATA
)(physicalDeviceExtension
+ 1);
2041 removable
= (BOOLEAN
)DeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
;
2042 listInitialized
= (physicalDiskData
->PartitionListState
== Initialized
);
2044 if (removable
|| (!listInitialized
))
2047 // Issue ReadCapacity to update device extension
2048 // with information for current media.
2051 status
= ScsiClassReadDriveCapacity(deviceExtension
->PhysicalDevice
);
2057 if (!NT_SUCCESS(status
)) {
2060 // Note the drive is not ready.
2063 diskData
->DriveNotReady
= TRUE
;
2069 // Note the drive is now ready.
2072 diskData
->DriveNotReady
= FALSE
;
2074 } else if (NT_SUCCESS(status
)) {
2076 // ReadDriveCapacity was allright, create Partition Objects
2078 if (physicalDiskData
->PartitionListState
== NotInitialized
) {
2079 status
= CreatePartitionDeviceObjects(deviceExtension
->PhysicalDevice
, NULL
);
2083 if (NT_SUCCESS(status
)) {
2086 // Copy drive geometry information from device extension.
2089 RtlMoveMemory(Irp
->AssociatedIrp
.SystemBuffer
,
2090 deviceExtension
->DiskGeometry
,
2091 (irpStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_DISK_GET_DRIVE_GEOMETRY
) ?
2092 sizeof(DISK_GEOMETRY
) :
2093 sizeof(DISK_GEOMETRY_EX
));
2095 status
= STATUS_SUCCESS
;
2096 Irp
->IoStatus
.Information
=
2097 (irpStack
->Parameters
.DeviceIoControl
.IoControlCode
== IOCTL_DISK_GET_DRIVE_GEOMETRY
) ?
2098 sizeof(DISK_GEOMETRY
) :
2099 sizeof(DISK_GEOMETRY_EX
);
2106 case IOCTL_DISK_VERIFY
:
2110 PVERIFY_INFORMATION verifyInfo
= Irp
->AssociatedIrp
.SystemBuffer
;
2111 LARGE_INTEGER byteOffset
;
2116 // Validate buffer length.
2119 if (irpStack
->Parameters
.DeviceIoControl
.InputBufferLength
<
2120 sizeof(VERIFY_INFORMATION
)) {
2122 status
= STATUS_INFO_LENGTH_MISMATCH
;
2130 srb
->CdbLength
= 10;
2132 cdb
->CDB10
.OperationCode
= SCSIOP_VERIFY
;
2135 // Add disk offset to starting sector.
2138 byteOffset
.QuadPart
= deviceExtension
->StartingOffset
.QuadPart
+
2139 verifyInfo
->StartingOffset
.QuadPart
;
2142 // Convert byte offset to sector offset.
2145 sectorOffset
= (ULONG
)(byteOffset
.QuadPart
>> deviceExtension
->SectorShift
);
2148 // Convert ULONG byte count to USHORT sector count.
2151 sectorCount
= (USHORT
)(verifyInfo
->Length
>> deviceExtension
->SectorShift
);
2154 // Move little endian values into CDB in big endian format.
2157 cdb
->CDB10
.LogicalBlockByte0
= ((PFOUR_BYTE
)§orOffset
)->Byte3
;
2158 cdb
->CDB10
.LogicalBlockByte1
= ((PFOUR_BYTE
)§orOffset
)->Byte2
;
2159 cdb
->CDB10
.LogicalBlockByte2
= ((PFOUR_BYTE
)§orOffset
)->Byte1
;
2160 cdb
->CDB10
.LogicalBlockByte3
= ((PFOUR_BYTE
)§orOffset
)->Byte0
;
2162 cdb
->CDB10
.TransferBlocksMsb
= ((PFOUR_BYTE
)§orCount
)->Byte1
;
2163 cdb
->CDB10
.TransferBlocksLsb
= ((PFOUR_BYTE
)§orCount
)->Byte0
;
2166 // The verify command is used by the NT FORMAT utility and
2167 // requests are sent down for 5% of the volume size. The
2168 // request timeout value is calculated based on the number of
2169 // sectors verified.
2172 srb
->TimeOutValue
= ((sectorCount
+ 0x7F) >> 7) *
2173 deviceExtension
->TimeOutValue
;
2175 status
= ScsiClassSendSrbAsynchronous(DeviceObject
,
2186 case IOCTL_DISK_GET_PARTITION_INFO
:
2189 // Return the information about the partition specified by the device
2190 // object. Note that no information is ever returned about the size
2191 // or partition type of the physical disk, as this doesn't make any
2195 if (irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
<
2196 sizeof(PARTITION_INFORMATION
)) {
2198 status
= STATUS_INFO_LENGTH_MISMATCH
;
2201 #if 0 // HACK: ReactOS partition numbers must be wrong
2202 else if (diskData
->PartitionNumber
== 0) {
2205 // Paritition zero is not a partition so this is not a
2206 // reasonable request.
2209 status
= STATUS_INVALID_DEVICE_REQUEST
;
2215 PPARTITION_INFORMATION outputBuffer
;
2218 // Update the geometry in case it has changed.
2221 status
= UpdateRemovableGeometry (DeviceObject
, Irp
);
2223 if (!NT_SUCCESS(status
)) {
2226 // Note the drive is not ready.
2229 diskData
->DriveNotReady
= TRUE
;
2234 // Note the drive is now ready.
2237 diskData
->DriveNotReady
= FALSE
;
2238 // HACK: ReactOS partition numbers must be wrong (>0 part)
2239 if (diskData
->PartitionType
== 0 && (diskData
->PartitionNumber
> 0)) {
2241 status
= STATUS_INVALID_DEVICE_REQUEST
;
2246 (PPARTITION_INFORMATION
)Irp
->AssociatedIrp
.SystemBuffer
;
2248 outputBuffer
->PartitionType
= diskData
->PartitionType
;
2249 outputBuffer
->StartingOffset
= deviceExtension
->StartingOffset
;
2250 outputBuffer
->PartitionLength
.QuadPart
= (diskData
->PartitionNumber
) ?
2251 deviceExtension
->PartitionLength
.QuadPart
: 2305843009213693951LL; // HACK
2252 outputBuffer
->HiddenSectors
= diskData
->HiddenSectors
;
2253 outputBuffer
->PartitionNumber
= diskData
->PartitionNumber
;
2254 outputBuffer
->BootIndicator
= diskData
->BootIndicator
;
2255 outputBuffer
->RewritePartition
= FALSE
;
2256 outputBuffer
->RecognizedPartition
=
2257 IsRecognizedPartition(diskData
->PartitionType
);
2259 status
= STATUS_SUCCESS
;
2260 Irp
->IoStatus
.Information
= sizeof(PARTITION_INFORMATION
);
2265 case IOCTL_DISK_SET_PARTITION_INFO
:
2267 if (diskData
->PartitionNumber
== 0) {
2269 status
= STATUS_UNSUCCESSFUL
;
2273 PSET_PARTITION_INFORMATION inputBuffer
=
2274 (PSET_PARTITION_INFORMATION
)Irp
->AssociatedIrp
.SystemBuffer
;
2277 // Validate buffer length.
2280 if (irpStack
->Parameters
.DeviceIoControl
.InputBufferLength
<
2281 sizeof(SET_PARTITION_INFORMATION
)) {
2283 status
= STATUS_INFO_LENGTH_MISMATCH
;
2288 // The HAL routines IoGet- and IoSetPartitionInformation were
2289 // developed before support of dynamic partitioning and therefore
2290 // don't distinguish between partition ordinal (that is the order
2291 // of a partition on a disk) and the partition number. (The
2292 // partition number is assigned to a partition to identify it to
2293 // the system.) Use partition ordinals for these legacy calls.
2296 status
= IoSetPartitionInformation(
2297 deviceExtension
->PhysicalDevice
,
2298 deviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
,
2299 diskData
->PartitionOrdinal
,
2300 inputBuffer
->PartitionType
);
2302 if (NT_SUCCESS(status
)) {
2304 diskData
->PartitionType
= inputBuffer
->PartitionType
;
2310 case IOCTL_DISK_GET_DRIVE_LAYOUT
:
2313 // Return the partition layout for the physical drive. Note that
2314 // the layout is returned for the actual physical drive, regardless
2315 // of which partition was specified for the request.
2318 if (irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
<
2319 sizeof(DRIVE_LAYOUT_INFORMATION
)) {
2320 status
= STATUS_INFO_LENGTH_MISMATCH
;
2324 PDRIVE_LAYOUT_INFORMATION partitionList
;
2325 PDEVICE_EXTENSION physicalExtension
= deviceExtension
;
2326 PPARTITION_INFORMATION partitionEntry
;
2327 PDISK_DATA diskData
;
2332 // Read partition information.
2335 status
= IoReadPartitionTable(deviceExtension
->PhysicalDevice
,
2336 deviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
,
2340 if (!NT_SUCCESS(status
)) {
2345 // The disk layout has been returned in the partitionList
2346 // buffer. Determine its size and, if the data will fit
2347 // into the intermediatery buffer, return it.
2350 tempSize
= FIELD_OFFSET(DRIVE_LAYOUT_INFORMATION
,PartitionEntry
[0]);
2351 tempSize
+= partitionList
->PartitionCount
*
2352 sizeof(PARTITION_INFORMATION
);
2355 irpStack
->Parameters
.DeviceIoControl
.OutputBufferLength
) {
2357 status
= STATUS_BUFFER_TOO_SMALL
;
2358 ExFreePool(partitionList
);
2363 // Walk partition list to associate partition numbers with
2364 // partition entries.
2367 for (i
= 0; i
< partitionList
->PartitionCount
; i
++) {
2370 // Walk partition chain anchored at physical disk extension.
2373 deviceExtension
= physicalExtension
;
2374 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
2378 deviceExtension
= diskData
->NextPartition
;
2381 // Check if this is the last partition in the chain.
2384 if (!deviceExtension
) {
2389 // Get the partition device extension from disk data.
2392 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
2395 // Check if this partition is not currently being used.
2398 if (!deviceExtension
->PartitionLength
.QuadPart
) {
2402 partitionEntry
= &partitionList
->PartitionEntry
[i
];
2405 // Check if empty, or describes extended partiton or hasn't changed.
2408 if (partitionEntry
->PartitionType
== PARTITION_ENTRY_UNUSED
||
2409 IsContainerPartition(partitionEntry
->PartitionType
)) {
2414 // Check if new partition starts where this partition starts.
2417 if (partitionEntry
->StartingOffset
.QuadPart
!=
2418 deviceExtension
->StartingOffset
.QuadPart
) {
2423 // Check if partition length is the same.
2426 if (partitionEntry
->PartitionLength
.QuadPart
==
2427 deviceExtension
->PartitionLength
.QuadPart
) {
2430 // Partitions match. Update partition number.
2433 partitionEntry
->PartitionNumber
=
2434 diskData
->PartitionNumber
;
2442 // Copy partition information to system buffer.
2445 RtlMoveMemory(Irp
->AssociatedIrp
.SystemBuffer
,
2448 status
= STATUS_SUCCESS
;
2449 Irp
->IoStatus
.Information
= tempSize
;
2452 // Finally, free the buffer allocated by reading the
2456 ExFreePool(partitionList
);
2461 case IOCTL_DISK_SET_DRIVE_LAYOUT
:
2466 // Update the disk with new partition information.
2469 PDRIVE_LAYOUT_INFORMATION partitionList
= Irp
->AssociatedIrp
.SystemBuffer
;
2472 // Validate buffer length.
2475 if (irpStack
->Parameters
.DeviceIoControl
.InputBufferLength
<
2476 sizeof(DRIVE_LAYOUT_INFORMATION
)) {
2478 status
= STATUS_INFO_LENGTH_MISMATCH
;
2482 length
= sizeof(DRIVE_LAYOUT_INFORMATION
) +
2483 (partitionList
->PartitionCount
- 1) * sizeof(PARTITION_INFORMATION
);
2486 if (irpStack
->Parameters
.DeviceIoControl
.InputBufferLength
<
2489 status
= STATUS_BUFFER_TOO_SMALL
;
2494 // Verify that device object is for physical disk.
2497 if (deviceExtension
->PhysicalDevice
->DeviceExtension
!= deviceExtension
) {
2498 status
= STATUS_INVALID_PARAMETER
;
2503 // Walk through partition table comparing partitions to
2504 // existing partitions to create, delete and change
2505 // device objects as necessary.
2508 UpdateDeviceObjects(DeviceObject
,
2512 // Write changes to disk.
2515 status
= IoWritePartitionTable(
2516 deviceExtension
->DeviceObject
,
2517 deviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
,
2518 deviceExtension
->DiskGeometry
->Geometry
.SectorsPerTrack
,
2519 deviceExtension
->DiskGeometry
->Geometry
.TracksPerCylinder
,
2524 // Update IRP with bytes returned.
2527 if (NT_SUCCESS(status
)) {
2528 Irp
->IoStatus
.Information
= length
;
2533 case IOCTL_DISK_REASSIGN_BLOCKS
:
2536 // Map defective blocks to new location on disk.
2541 PREASSIGN_BLOCKS badBlocks
= Irp
->AssociatedIrp
.SystemBuffer
;
2547 // Validate buffer length.
2550 if (irpStack
->Parameters
.DeviceIoControl
.InputBufferLength
<
2551 sizeof(REASSIGN_BLOCKS
)) {
2553 status
= STATUS_INFO_LENGTH_MISMATCH
;
2557 bufferSize
= sizeof(REASSIGN_BLOCKS
) +
2558 (badBlocks
->Count
- 1) * sizeof(ULONG
);
2560 if (irpStack
->Parameters
.DeviceIoControl
.InputBufferLength
<
2563 status
= STATUS_INFO_LENGTH_MISMATCH
;
2568 // Build the data buffer to be transferred in the input buffer.
2569 // The format of the data to the device is:
2573 // x * 4 btyes Block Address
2575 // All values are big endian.
2578 badBlocks
->Reserved
= 0;
2579 blockCount
= badBlocks
->Count
;
2582 // Convert # of entries to # of bytes.
2586 badBlocks
->Count
= (USHORT
) ((blockCount
>> 8) & 0XFF);
2587 badBlocks
->Count
|= (USHORT
) ((blockCount
<< 8) & 0XFF00);
2590 // Convert back to number of entries.
2595 for (; blockCount
> 0; blockCount
--) {
2597 blockNumber
= badBlocks
->BlockNumber
[blockCount
-1];
2599 REVERSE_BYTES((PFOUR_BYTE
) &badBlocks
->BlockNumber
[blockCount
-1],
2600 (PFOUR_BYTE
) &blockNumber
);
2605 cdb
->CDB6GENERIC
.OperationCode
= SCSIOP_REASSIGN_BLOCKS
;
2608 // Set timeout value.
2611 srb
->TimeOutValue
= deviceExtension
->TimeOutValue
;
2613 status
= ScsiClassSendSrbSynchronous(DeviceObject
,
2619 Irp
->IoStatus
.Status
= status
;
2620 Irp
->IoStatus
.Information
= 0;
2622 IoCompleteRequest(Irp
, IO_DISK_INCREMENT
);
2627 case IOCTL_DISK_IS_WRITABLE
:
2630 // Determine if the device is writable.
2633 modeData
= ExAllocatePool(NonPagedPoolCacheAligned
, MODE_DATA_SIZE
);
2635 if (modeData
== NULL
) {
2636 status
= STATUS_INSUFFICIENT_RESOURCES
;
2640 RtlZeroMemory(modeData
, MODE_DATA_SIZE
);
2642 length
= ScsiClassModeSense(DeviceObject
,
2645 MODE_SENSE_RETURN_ALL
);
2647 if (length
< sizeof(MODE_PARAMETER_HEADER
)) {
2650 // Retry the request in case of a check condition.
2653 length
= ScsiClassModeSense(DeviceObject
,
2656 MODE_SENSE_RETURN_ALL
);
2658 if (length
< sizeof(MODE_PARAMETER_HEADER
)) {
2659 status
= STATUS_IO_DEVICE_ERROR
;
2660 ExFreePool(modeData
);
2665 if (modeData
->DeviceSpecificParameter
& MODE_DSP_WRITE_PROTECT
) {
2666 status
= STATUS_MEDIA_WRITE_PROTECTED
;
2668 status
= STATUS_SUCCESS
;
2671 ExFreePool(modeData
);
2674 case IOCTL_DISK_INTERNAL_SET_VERIFY
:
2677 // If the caller is kernel mode, set the verify bit.
2680 if (Irp
->RequestorMode
== KernelMode
) {
2681 DeviceObject
->Flags
|= DO_VERIFY_VOLUME
;
2683 status
= STATUS_SUCCESS
;
2686 case IOCTL_DISK_INTERNAL_CLEAR_VERIFY
:
2689 // If the caller is kernel mode, clear the verify bit.
2692 if (Irp
->RequestorMode
== KernelMode
) {
2693 DeviceObject
->Flags
&= ~DO_VERIFY_VOLUME
;
2695 status
= STATUS_SUCCESS
;
2698 case IOCTL_DISK_FIND_NEW_DEVICES
:
2701 // Search for devices that have been powered on since the last
2702 // device search or system initialization.
2705 DebugPrint((3,"CdRomDeviceControl: Find devices\n"));
2706 status
= DriverEntry(DeviceObject
->DriverObject
,
2709 Irp
->IoStatus
.Status
= status
;
2711 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
2714 case IOCTL_DISK_MEDIA_REMOVAL
:
2717 // If the disk is not removable then don't allow this command.
2720 if (!(DeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
)) {
2721 status
= STATUS_INVALID_DEVICE_REQUEST
;
2726 // Fall through and let the class driver process the request.
2732 // Free the Srb, since it is not needed.
2738 // Pass the request to the common device control routine.
2741 return(ScsiClassDeviceControl(DeviceObject
, Irp
));
2745 } // end switch( ...
2747 Irp
->IoStatus
.Status
= status
;
2749 if (!NT_SUCCESS(status
) && IoIsErrorUserInduced(status
)) {
2751 IoSetHardErrorOrVerifyDevice(Irp
, DeviceObject
);
2754 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
2758 } // end ScsiDiskDeviceControl()
2762 ScsiDiskShutdownFlush (
2763 IN PDEVICE_OBJECT DeviceObject
,
2769 Routine Description:
2771 This routine is called for a shutdown and flush IRPs. These are sent by the
2772 system before it actually shuts down or when the file system does a flush.
2773 A synchronize cache command is sent to the device if it is write caching.
2774 If the device is removable an unlock command will be sent. This routine
2775 will sent a shutdown or flush Srb to the port driver.
2779 DriverObject - Pointer to device object to being shutdown by system.
2790 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
2791 PIO_STACK_LOCATION irpStack
;
2792 PSCSI_REQUEST_BLOCK srb
;
2797 // Allocate SCSI request block.
2800 srb
= ExAllocatePool(NonPagedPool
, sizeof(SCSI_REQUEST_BLOCK
));
2805 // Set the status and complete the request.
2808 Irp
->IoStatus
.Status
= STATUS_INSUFFICIENT_RESOURCES
;
2809 IoCompleteRequest(Irp
, IO_NO_INCREMENT
);
2810 return(STATUS_INSUFFICIENT_RESOURCES
);
2813 RtlZeroMemory(srb
, SCSI_REQUEST_BLOCK_SIZE
);
2816 // Write length to SRB.
2819 srb
->Length
= SCSI_REQUEST_BLOCK_SIZE
;
2822 // Set SCSI bus address.
2825 srb
->PathId
= deviceExtension
->PathId
;
2826 srb
->TargetId
= deviceExtension
->TargetId
;
2827 srb
->Lun
= deviceExtension
->Lun
;
2830 // Set timeout value and mark the request as not being a tagged request.
2833 srb
->TimeOutValue
= deviceExtension
->TimeOutValue
* 4;
2834 srb
->QueueTag
= SP_UNTAGGED
;
2835 srb
->QueueAction
= SRB_SIMPLE_TAG_REQUEST
;
2836 srb
->SrbFlags
= deviceExtension
->SrbFlags
;
2839 // If the write cache is enabled then send a synchronize cache request.
2842 if (deviceExtension
->DeviceFlags
& DEV_WRITE_CACHE
) {
2844 srb
->Function
= SRB_FUNCTION_EXECUTE_SCSI
;
2845 srb
->CdbLength
= 10;
2847 srb
->Cdb
[0] = SCSIOP_SYNCHRONIZE_CACHE
;
2849 status
= ScsiClassSendSrbSynchronous(DeviceObject
,
2855 DebugPrint((1, "ScsiDiskShutdownFlush: Synchonize cache sent. Status = %lx\n", status
));
2859 // Unlock the device if it is removable and this is a shutdown.
2862 irpStack
= IoGetCurrentIrpStackLocation(Irp
);
2864 if (DeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
&&
2865 irpStack
->MajorFunction
== IRP_MJ_SHUTDOWN
) {
2868 cdb
= (PVOID
) srb
->Cdb
;
2869 cdb
->MEDIA_REMOVAL
.OperationCode
= SCSIOP_MEDIUM_REMOVAL
;
2870 cdb
->MEDIA_REMOVAL
.Prevent
= FALSE
;
2873 // Set timeout value.
2876 srb
->TimeOutValue
= deviceExtension
->TimeOutValue
;
2877 status
= ScsiClassSendSrbSynchronous(DeviceObject
,
2883 DebugPrint((1, "ScsiDiskShutdownFlush: Unlock device request sent. Status = %lx\n", status
));
2889 // Save a few parameters in the current stack location.
2892 srb
->Function
= irpStack
->MajorFunction
== IRP_MJ_SHUTDOWN
?
2893 SRB_FUNCTION_SHUTDOWN
: SRB_FUNCTION_FLUSH
;
2896 // Set the retry count to zero.
2899 irpStack
->Parameters
.Others
.Argument4
= (PVOID
) 0;
2902 // Set up IoCompletion routine address.
2905 IoSetCompletionRoutine(Irp
, ScsiClassIoComplete
, srb
, TRUE
, TRUE
, TRUE
);
2908 // Get next stack location and
2909 // set major function code.
2912 irpStack
= IoGetNextIrpStackLocation(Irp
);
2914 irpStack
->MajorFunction
= IRP_MJ_SCSI
;
2917 // Set up SRB for execute scsi request.
2918 // Save SRB address in next stack for port driver.
2921 irpStack
->Parameters
.Scsi
.Srb
= srb
;
2924 // Set up Irp Address.
2927 srb
->OriginalRequest
= Irp
;
2930 // Call the port driver to process the request.
2933 return(IoCallDriver(deviceExtension
->PortDeviceObject
, Irp
));
2935 } // end ScsiDiskShutdown()
2941 PDEVICE_OBJECT DeviceObject
2945 Routine Description:
2947 The routine performs the necessary functions to determine if a device is
2948 really a floppy rather than a harddisk. This is done by a mode sense
2949 command. First, a check is made to see if the medimum type is set. Second
2950 a check is made for the flexible parameters mode page. Also a check is
2951 made to see if the write cache is enabled.
2955 DeviceObject - Supplies the device object to be tested.
2959 Return TRUE if the indicated device is a floppy.
2963 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
2970 modeData
= ExAllocatePool(NonPagedPoolCacheAligned
, MODE_DATA_SIZE
);
2972 if (modeData
== NULL
) {
2976 RtlZeroMemory(modeData
, MODE_DATA_SIZE
);
2978 length
= ScsiClassModeSense(DeviceObject
,
2981 MODE_SENSE_RETURN_ALL
);
2983 if (length
< sizeof(MODE_PARAMETER_HEADER
)) {
2986 // Retry the request in case of a check condition.
2989 length
= ScsiClassModeSense(DeviceObject
,
2992 MODE_SENSE_RETURN_ALL
);
2994 if (length
< sizeof(MODE_PARAMETER_HEADER
)) {
2996 ExFreePool(modeData
);
3003 // If the length is greater than length indicated by the mode data reset
3004 // the data to the mode data.
3007 if (length
> (ULONG
) ((PMODE_PARAMETER_HEADER
) modeData
)->ModeDataLength
+ 1) {
3008 length
= ((PMODE_PARAMETER_HEADER
) modeData
)->ModeDataLength
+ 1;
3012 // Look for the flexible disk mode page.
3015 pageData
= ScsiClassFindModePage( modeData
, length
, MODE_PAGE_FLEXIBILE
, TRUE
);
3017 if (pageData
!= NULL
) {
3019 DebugPrint((1, "Scsidisk: Flexible disk page found, This is a floppy.\n"));
3020 ExFreePool(modeData
);
3025 // Check to see if the write cache is enabled.
3028 pageData
= ScsiClassFindModePage( modeData
, length
, MODE_PAGE_CACHING
, TRUE
);
3031 // Assume that write cache is disabled or not supported.
3034 deviceExtension
->DeviceFlags
&= ~DEV_WRITE_CACHE
;
3037 // Check if valid caching page exists.
3040 if (pageData
!= NULL
) {
3043 // Check if write cache is disabled.
3046 if (((PMODE_CACHING_PAGE
)pageData
)->WriteCacheEnable
) {
3049 "SCSIDISK: Disk write cache enabled\n"));
3052 // Check if forced unit access (FUA) is supported.
3055 if (((PMODE_PARAMETER_HEADER
)modeData
)->DeviceSpecificParameter
& MODE_DSP_FUA_SUPPORTED
) {
3057 deviceExtension
->DeviceFlags
|= DEV_WRITE_CACHE
;
3062 "SCSIDISK: Disk does not support FUA or DPO\n"));
3072 ExFreePool(modeData
);
3075 } // end IsFloppyDevice()
3081 IN PDEVICE_OBJECT DeviceObject
,
3082 IN PCHAR ModeSelectBuffer
,
3089 Routine Description:
3091 This routine sends a mode select command.
3095 DeviceObject - Supplies the device object associated with this request.
3097 ModeSelectBuffer - Supplies a buffer containing the page data.
3099 Length - Supplies the length in bytes of the mode select buffer.
3101 SavePage - Indicates that parameters should be written to disk.
3105 Length of the transferred data is returned.
3109 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
3111 SCSI_REQUEST_BLOCK srb
;
3116 PMODE_PARAMETER_BLOCK blockDescriptor
;
3120 length2
= Length
+ sizeof(MODE_PARAMETER_HEADER
) + sizeof(MODE_PARAMETER_BLOCK
);
3123 // Allocate buffer for mode select header, block descriptor, and mode page.
3126 buffer
= (ULONG_PTR
)ExAllocatePool(NonPagedPoolCacheAligned
,length2
);
3128 RtlZeroMemory((PVOID
)buffer
, length2
);
3131 // Set length in header to size of mode page.
3134 ((PMODE_PARAMETER_HEADER
)buffer
)->BlockDescriptorLength
= sizeof(MODE_PARAMETER_BLOCK
);
3136 blockDescriptor
= (PMODE_PARAMETER_BLOCK
)(buffer
+ 1);
3142 blockDescriptor
->BlockLength
[1]=0x02;
3145 // Copy mode page to buffer.
3148 RtlCopyMemory((PVOID
)(buffer
+ 3), ModeSelectBuffer
, Length
);
3154 RtlZeroMemory(&srb
, sizeof(SCSI_REQUEST_BLOCK
));
3157 // Build the MODE SELECT CDB.
3161 cdb
= (PCDB
)srb
.Cdb
;
3164 // Set timeout value from device extension.
3167 srb
.TimeOutValue
= deviceExtension
->TimeOutValue
* 2;
3169 cdb
->MODE_SELECT
.OperationCode
= SCSIOP_MODE_SELECT
;
3170 cdb
->MODE_SELECT
.SPBit
= SavePage
;
3171 cdb
->MODE_SELECT
.PFBit
= 1;
3172 cdb
->MODE_SELECT
.ParameterListLength
= (UCHAR
)(length2
);
3176 status
= ScsiClassSendSrbSynchronous(DeviceObject
,
3183 if (status
== STATUS_VERIFY_REQUIRED
) {
3186 // Routine ScsiClassSendSrbSynchronous does not retry requests returned with
3199 } else if (SRB_STATUS(srb
.SrbStatus
) == SRB_STATUS_DATA_OVERRUN
) {
3200 status
= STATUS_SUCCESS
;
3203 ExFreePool((PVOID
)buffer
);
3205 if (NT_SUCCESS(status
)) {
3211 } // end SciDiskModeSelect()
3217 IN PDEVICE_OBJECT DeviceObject
,
3218 IN PSCSI_INQUIRY_DATA LunInfo
3222 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
3223 PINQUIRYDATA InquiryData
= (PINQUIRYDATA
)LunInfo
->InquiryData
;
3224 BAD_CONTROLLER_INFORMATION
const *controller
;
3229 for (j
= 0; j
< NUMBER_OF_BAD_CONTROLLERS
; j
++) {
3231 controller
= &ScsiDiskBadControllers
[j
];
3233 if (!controller
->DisableWriteCache
|| strncmp(controller
->InquiryString
, (PCCHAR
)InquiryData
->VendorId
, strlen(controller
->InquiryString
))) {
3237 DebugPrint((1, "ScsiDisk.DisableWriteCache, Found bad controller! %s\n", controller
->InquiryString
));
3239 modeData
= ExAllocatePool(NonPagedPoolCacheAligned
, MODE_DATA_SIZE
);
3241 if (modeData
== NULL
) {
3244 "ScsiDisk.DisableWriteCache: Check for write-cache enable failed\n"));
3248 RtlZeroMemory(modeData
, MODE_DATA_SIZE
);
3250 length
= ScsiClassModeSense(DeviceObject
,
3253 MODE_SENSE_RETURN_ALL
);
3255 if (length
< sizeof(MODE_PARAMETER_HEADER
)) {
3258 // Retry the request in case of a check condition.
3261 length
= ScsiClassModeSense(DeviceObject
,
3264 MODE_SENSE_RETURN_ALL
);
3266 if (length
< sizeof(MODE_PARAMETER_HEADER
)) {
3270 "ScsiDisk.DisableWriteCache: Mode Sense failed\n"));
3272 ExFreePool(modeData
);
3279 // If the length is greater than length indicated by the mode data reset
3280 // the data to the mode data.
3283 if (length
> (ULONG
) ((PMODE_PARAMETER_HEADER
) modeData
)->ModeDataLength
+ 1) {
3284 length
= ((PMODE_PARAMETER_HEADER
) modeData
)->ModeDataLength
+ 1;
3288 // Check to see if the write cache is enabled.
3291 pageData
= ScsiClassFindModePage( modeData
, length
, MODE_PAGE_CACHING
, TRUE
);
3294 // Assume that write cache is disabled or not supported.
3297 deviceExtension
->DeviceFlags
&= ~DEV_WRITE_CACHE
;
3300 // Check if valid caching page exists.
3303 if (pageData
!= NULL
) {
3305 BOOLEAN savePage
= FALSE
;
3307 savePage
= (BOOLEAN
)(((PMODE_CACHING_PAGE
)pageData
)->PageSavable
);
3310 // Check if write cache is disabled.
3313 if (((PMODE_CACHING_PAGE
)pageData
)->WriteCacheEnable
) {
3315 PIO_ERROR_LOG_PACKET errorLogEntry
;
3320 // Disable write cache and ensure necessary fields are zeroed.
3323 ((PMODE_CACHING_PAGE
)pageData
)->WriteCacheEnable
= FALSE
;
3324 ((PMODE_CACHING_PAGE
)pageData
)->Reserved
= 0;
3325 ((PMODE_CACHING_PAGE
)pageData
)->PageSavable
= 0;
3326 ((PMODE_CACHING_PAGE
)pageData
)->Reserved2
= 0;
3329 // Extract length from caching page.
3332 length
= ((PMODE_CACHING_PAGE
)pageData
)->PageLength
;
3335 // Compensate for page code and page length.
3341 // Issue mode select to set the parameter.
3344 if (ScsiDiskModeSelect(DeviceObject
,
3350 "SCSIDISK: Disk write cache disabled\n"));
3352 deviceExtension
->DeviceFlags
&= ~DEV_WRITE_CACHE
;
3353 errorCode
= IO_WRITE_CACHE_DISABLED
;
3356 if (ScsiDiskModeSelect(DeviceObject
,
3362 "SCSIDISK: Disk write cache disabled\n"));
3365 deviceExtension
->DeviceFlags
&= ~DEV_WRITE_CACHE
;
3366 errorCode
= IO_WRITE_CACHE_DISABLED
;
3371 "SCSIDISK: Mode select to disable write cache failed\n"));
3373 deviceExtension
->DeviceFlags
|= DEV_WRITE_CACHE
;
3374 errorCode
= IO_WRITE_CACHE_ENABLED
;
3379 // Log the appropriate informational or error entry.
3382 errorLogEntry
= (PIO_ERROR_LOG_PACKET
)IoAllocateErrorLogEntry(
3384 sizeof(IO_ERROR_LOG_PACKET
) + 3
3387 if (errorLogEntry
!= NULL
) {
3389 errorLogEntry
->FinalStatus
= STATUS_SUCCESS
;
3390 errorLogEntry
->ErrorCode
= errorCode
;
3391 errorLogEntry
->SequenceNumber
= 0;
3392 errorLogEntry
->MajorFunctionCode
= IRP_MJ_SCSI
;
3393 errorLogEntry
->IoControlCode
= 0;
3394 errorLogEntry
->RetryCount
= 0;
3395 errorLogEntry
->UniqueErrorValue
= 0x1;
3396 errorLogEntry
->DumpDataSize
= 3 * sizeof(ULONG
);
3397 errorLogEntry
->DumpData
[0] = LunInfo
->PathId
;
3398 errorLogEntry
->DumpData
[1] = LunInfo
->TargetId
;
3399 errorLogEntry
->DumpData
[2] = LunInfo
->Lun
;
3402 // Write the error log packet.
3405 IoWriteErrorLogEntry(errorLogEntry
);
3411 // Found device so exit the loop and return.
3423 CalculateMbrCheckSum(
3424 IN PDEVICE_EXTENSION DeviceExtension
,
3430 Routine Description:
3432 Read MBR and calculate checksum.
3436 DeviceExtension - Supplies a pointer to the device information for disk.
3437 Checksum - Memory location to return MBR checksum.
3441 Returns TRUE if checksum is valid.
3445 LARGE_INTEGER sectorZero
;
3447 IO_STATUS_BLOCK ioStatus
;
3455 sectorZero
.QuadPart
= (LONGLONG
) 0;
3458 // Create notification event object to be used to signal the inquiry
3459 // request completion.
3462 KeInitializeEvent(&event
, NotificationEvent
, FALSE
);
3468 sectorSize
= DeviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
;
3471 // Make sure sector size is at least 512 bytes.
3474 if (sectorSize
< 512) {
3479 // Allocate buffer for sector read.
3482 mbr
= ExAllocatePool(NonPagedPoolCacheAligned
, sectorSize
);
3489 // Build IRP to read MBR.
3492 irp
= IoBuildSynchronousFsdRequest(IRP_MJ_READ
,
3493 DeviceExtension
->DeviceObject
,
3506 // Pass request to port driver and wait for request to complete.
3509 status
= IoCallDriver(DeviceExtension
->DeviceObject
,
3512 if (status
== STATUS_PENDING
) {
3513 KeWaitForSingleObject(&event
,
3518 status
= ioStatus
.Status
;
3521 if (!NT_SUCCESS(status
)) {
3527 // Calculate MBR checksum.
3532 for (i
= 0; i
< 128; i
++) {
3533 *Checksum
+= mbr
[i
];
3536 *Checksum
= ~*Checksum
+ 1;
3546 IN PDEVICE_EXTENSION DeviceExtension
,
3553 Routine Description:
3555 The routine queries the registry to determine if this disk is visible to
3556 the BIOS. If the disk is visable to the BIOS, then the geometry information
3561 DeviceExtension - Supplies a pointer to the device information for disk.
3562 Signature - Unique identifier recorded in MBR.
3563 BusKey - Handle of bus key.
3564 DiskNumber - Returns ordinal of disk as BIOS sees it.
3568 TRUE is disk signature matched.
3572 PDISK_DATA diskData
= (PDISK_DATA
)(DeviceExtension
+ 1);
3573 BOOLEAN diskFound
= FALSE
;
3574 OBJECT_ATTRIBUTES objectAttributes
;
3575 UNICODE_STRING unicodeString
;
3576 UNICODE_STRING identifier
;
3578 ULONG adapterNumber
;
3586 STRING anotherString
;
3589 PKEY_VALUE_FULL_INFORMATION keyData
;
3593 for (busNumber
= 0; ; busNumber
++) {
3596 // Open controller name key.
3599 sprintf((PCHAR
)buffer
,
3603 RtlInitString(&string
,
3606 status
= RtlAnsiStringToUnicodeString(&unicodeString
,
3610 if (!NT_SUCCESS(status
)){
3614 InitializeObjectAttributes(&objectAttributes
,
3616 OBJ_CASE_INSENSITIVE
,
3618 (PSECURITY_DESCRIPTOR
)NULL
);
3620 status
= ZwOpenKey(&spareKey
,
3624 RtlFreeUnicodeString(&unicodeString
);
3626 if (!NT_SUCCESS(status
)) {
3631 // Open up controller ordinal key.
3634 RtlInitUnicodeString(&unicodeString
, L
"DiskController");
3635 InitializeObjectAttributes(&objectAttributes
,
3637 OBJ_CASE_INSENSITIVE
,
3639 (PSECURITY_DESCRIPTOR
)NULL
);
3641 status
= ZwOpenKey(&adapterKey
,
3646 // This could fail even with additional adapters of this type
3650 if (!NT_SUCCESS(status
)) {
3654 for (adapterNumber
= 0; ; adapterNumber
++) {
3660 sprintf((PCHAR
)buffer
,
3661 "%lu\\DiskPeripheral",
3664 RtlInitString(&string
,
3667 status
= RtlAnsiStringToUnicodeString(&unicodeString
,
3671 if (!NT_SUCCESS(status
)){
3675 InitializeObjectAttributes(&objectAttributes
,
3677 OBJ_CASE_INSENSITIVE
,
3679 (PSECURITY_DESCRIPTOR
)NULL
);
3681 status
= ZwOpenKey(&diskKey
,
3685 RtlFreeUnicodeString(&unicodeString
);
3687 if (!NT_SUCCESS(status
)) {
3691 for (diskNumber
= 0; ; diskNumber
++) {
3693 sprintf((PCHAR
)buffer
,
3697 RtlInitString(&string
,
3700 status
= RtlAnsiStringToUnicodeString(&unicodeString
,
3704 if (!NT_SUCCESS(status
)){
3708 InitializeObjectAttributes(&objectAttributes
,
3710 OBJ_CASE_INSENSITIVE
,
3712 (PSECURITY_DESCRIPTOR
)NULL
);
3714 status
= ZwOpenKey(&targetKey
,
3718 RtlFreeUnicodeString(&unicodeString
);
3720 if (!NT_SUCCESS(status
)) {
3725 // Allocate buffer for registry query.
3728 keyData
= ExAllocatePool(PagedPool
, VALUE_BUFFER_SIZE
);
3730 if (keyData
== NULL
) {
3736 // Get disk peripheral identifier.
3739 RtlInitUnicodeString(&unicodeString
, L
"Identifier");
3740 status
= ZwQueryValueKey(targetKey
,
3742 KeyValueFullInformation
,
3749 if (!NT_SUCCESS(status
)) {
3754 // Complete unicode string.
3758 (PWSTR
)((PUCHAR
)keyData
+ keyData
->DataOffset
);
3759 identifier
.Length
= (USHORT
)keyData
->DataLength
;
3760 identifier
.MaximumLength
= (USHORT
)keyData
->DataLength
;
3763 // Convert unicode identifier to ansi string.
3767 RtlUnicodeStringToAnsiString(&anotherString
,
3771 if (!NT_SUCCESS(status
)) {
3776 // If checksum is zero, then the MBR is valid and
3777 // the signature is meaningful.
3780 if (diskData
->MbrCheckSum
) {
3783 // Convert checksum to ansi string.
3786 sprintf((PCHAR
)buffer
, "%08lx", diskData
->MbrCheckSum
);
3791 // Convert signature to ansi string.
3794 sprintf((PCHAR
)buffer
, "%08lx", diskData
->Signature
);
3797 // Make string point at signature. Can't use scan
3798 // functions because they are not exported for driver use.
3801 anotherString
.Buffer
+=9;
3805 // Convert to ansi string.
3808 RtlInitString(&string
,
3813 // Make string lengths equal.
3816 anotherString
.Length
= string
.Length
;
3819 // Check if strings match.
3822 if (RtlCompareString(&string
,
3827 *DiskNumber
= diskNumber
;
3830 ExFreePool(keyData
);
3833 // Readjust indentifier string if necessary.
3836 if (!diskData
->MbrCheckSum
) {
3837 anotherString
.Buffer
-=9;
3840 RtlFreeAnsiString(&anotherString
);
3850 ZwClose(adapterKey
);
3856 } // end EnumerateBusKey()
3862 IN PDEVICE_EXTENSION DeviceExtension
3866 Routine Description:
3868 The routine queries the registry to determine if this disk is visible to
3869 the BIOS. If the disk is visable to the BIOS, then the geometry information
3874 DeviceExtension - Supplies a pointer to the device information for disk.
3883 OBJECT_ATTRIBUTES objectAttributes
;
3884 UNICODE_STRING unicodeString
;
3888 PCM_INT13_DRIVE_PARAMETER driveParameters
;
3889 PCM_FULL_RESOURCE_DESCRIPTOR resourceDescriptor
;
3890 PKEY_VALUE_FULL_INFORMATION keyData
;
3894 ULONG numberOfDrives
;
3897 ULONG sectorsPerTrack
;
3898 ULONG tracksPerCylinder
;
3899 BOOLEAN foundEZHooker
;
3905 // Initialize the object for the key.
3908 InitializeObjectAttributes(&objectAttributes
,
3909 DeviceExtension
->DeviceObject
->DriverObject
->HardwareDatabase
,
3910 OBJ_CASE_INSENSITIVE
,
3912 (PSECURITY_DESCRIPTOR
) NULL
);
3915 // Create the hardware base key.
3918 status
= ZwOpenKey(&hardwareKey
,
3923 if (!NT_SUCCESS(status
)) {
3924 DebugPrint((1, "ScsiDisk UpdateParameters: Cannot open hardware data. Name: %wZ\n", DeviceExtension
->DeviceObject
->DriverObject
->HardwareDatabase
));
3930 // Get disk BIOS geometry information.
3933 RtlInitUnicodeString(&unicodeString
, L
"Configuration Data");
3935 keyData
= ExAllocatePool(PagedPool
, VALUE_BUFFER_SIZE
);
3937 if (keyData
== NULL
) {
3938 ZwClose(hardwareKey
);
3942 status
= ZwQueryValueKey(hardwareKey
,
3944 KeyValueFullInformation
,
3949 if (!NT_SUCCESS(status
)) {
3951 "SCSIDISK: ExtractBiosGeometry: Can't query configuration data (%x)\n",
3953 ExFreePool(keyData
);
3958 // Open EISA bus key.
3961 RtlInitUnicodeString(&unicodeString
, L
"EisaAdapter");
3963 InitializeObjectAttributes(&objectAttributes
,
3965 OBJ_CASE_INSENSITIVE
,
3967 (PSECURITY_DESCRIPTOR
)NULL
);
3969 status
= ZwOpenKey(&busKey
,
3973 if (!NT_SUCCESS(status
)) {
3978 "SCSIDISK: UpdateGeometry: Opened EisaAdapter key\n"));
3979 if (EnumerateBusKey(DeviceExtension
,
3983 ZwClose(hardwareKey
);
3990 // Open Multifunction bus key.
3993 RtlInitUnicodeString(&unicodeString
, L
"MultifunctionAdapter");
3995 InitializeObjectAttributes(&objectAttributes
,
3997 OBJ_CASE_INSENSITIVE
,
3999 (PSECURITY_DESCRIPTOR
)NULL
);
4001 status
= ZwOpenKey(&busKey
,
4005 ZwClose(hardwareKey
);
4006 if (NT_SUCCESS(status
)) {
4008 "SCSIDISK: UpdateGeometry: Opened MultifunctionAdapter key\n"));
4009 if (EnumerateBusKey(DeviceExtension
,
4017 ExFreePool(keyData
);
4022 resourceDescriptor
= (PCM_FULL_RESOURCE_DESCRIPTOR
)((PUCHAR
)keyData
+
4023 keyData
->DataOffset
);
4026 // Check that the data is long enough to hold a full resource descriptor,
4027 // and that the last resouce list is device-specific and long enough.
4030 if (keyData
->DataLength
< sizeof(CM_FULL_RESOURCE_DESCRIPTOR
) ||
4031 resourceDescriptor
->PartialResourceList
.Count
== 0 ||
4032 resourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].Type
!=
4033 CmResourceTypeDeviceSpecific
||
4034 resourceDescriptor
->PartialResourceList
.PartialDescriptors
[0]
4035 .u
.DeviceSpecificData
.DataSize
< sizeof(ULONG
)) {
4037 DebugPrint((1, "SCSIDISK: ExtractBiosGeometry: BIOS header data too small or invalid\n"));
4038 ExFreePool(keyData
);
4043 resourceDescriptor
->PartialResourceList
.PartialDescriptors
[0].u
.DeviceSpecificData
.DataSize
;
4046 // Point to the BIOS data. The BIOS data is located after the first
4047 // partial Resource list which should be device specific data.
4050 buffer
= (PUCHAR
) keyData
+ keyData
->DataOffset
+
4051 sizeof(CM_FULL_RESOURCE_DESCRIPTOR
);
4054 numberOfDrives
= length
/ sizeof(CM_INT13_DRIVE_PARAMETER
);
4057 // Use the defaults if the drive number is greater than the
4058 // number of drives detected by the BIOS.
4061 if (numberOfDrives
<= diskNumber
) {
4062 ExFreePool(keyData
);
4067 // Point to the array of drive parameters.
4070 driveParameters
= (PCM_INT13_DRIVE_PARAMETER
) buffer
+ diskNumber
;
4071 cylinders
= driveParameters
->MaxCylinders
+ 1;
4072 sectorsPerTrack
= driveParameters
->SectorsPerTrack
;
4073 tracksPerCylinder
= driveParameters
->MaxHeads
+1;
4076 // Calculate the actual number of sectors.
4079 sectors
= (ULONG
)(DeviceExtension
->PartitionLength
.QuadPart
>>
4080 DeviceExtension
->SectorShift
);
4083 if (sectors
>= cylinders
* tracksPerCylinder
* sectorsPerTrack
) {
4084 DebugPrint((1, "ScsiDisk: UpdateGeometry: Disk smaller than BIOS indicated\n"
4085 "SCSIDISK: Sectors: %x, Cylinders: %x, Track per Cylinder: %x Sectors per track: %x\n",
4086 sectors
, cylinders
, tracksPerCylinder
, sectorsPerTrack
));
4091 // Since the BIOS may not report the full drive, recalculate the drive
4092 // size based on the volume size and the BIOS values for tracks per
4093 // cylinder and sectors per track..
4096 length
= tracksPerCylinder
* sectorsPerTrack
;
4101 // The BIOS information is bogus.
4104 DebugPrint((1, "ScsiDisk UpdateParameters: sectorPerTrack zero\n"));
4105 ExFreePool(keyData
);
4109 cylinders
= sectors
/ length
;
4112 // Update the actual geometry information.
4115 DeviceExtension
->DiskGeometry
->Geometry
.SectorsPerTrack
= sectorsPerTrack
;
4116 DeviceExtension
->DiskGeometry
->Geometry
.TracksPerCylinder
= tracksPerCylinder
;
4117 DeviceExtension
->DiskGeometry
->Geometry
.Cylinders
.QuadPart
= (LONGLONG
)cylinders
;
4118 DeviceExtension
->DiskGeometry
->DiskSize
.QuadPart
= cylinders
* tracksPerCylinder
* sectorsPerTrack
*
4119 DeviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
;
4122 "SCSIDISK: UpdateGeometry: BIOS spt %x, #heads %x, #cylinders %x\n",
4127 ExFreePool(keyData
);
4129 foundEZHooker
= FALSE
;
4131 if (!DeviceExtension
->DMActive
) {
4133 HalExamineMBR(DeviceExtension
->DeviceObject
,
4134 DeviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
,
4142 foundEZHooker
= TRUE
;
4148 if (DeviceExtension
->DMActive
|| foundEZHooker
) {
4150 while (cylinders
> 1024) {
4152 tracksPerCylinder
= tracksPerCylinder
*2;
4153 cylinders
= cylinders
/2;
4158 // int 13 values are always 1 less.
4161 tracksPerCylinder
-= 1;
4165 // DM reserves the CE cylinder
4170 DeviceExtension
->DiskGeometry
->Geometry
.Cylinders
.QuadPart
= cylinders
+ 1;
4171 DeviceExtension
->DiskGeometry
->Geometry
.TracksPerCylinder
= tracksPerCylinder
+ 1;
4173 DeviceExtension
->PartitionLength
.QuadPart
=
4174 DeviceExtension
->DiskGeometry
->DiskSize
.QuadPart
=
4175 DeviceExtension
->DiskGeometry
->Geometry
.Cylinders
.QuadPart
*
4176 DeviceExtension
->DiskGeometry
->Geometry
.SectorsPerTrack
*
4177 DeviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
*
4178 DeviceExtension
->DiskGeometry
->Geometry
.TracksPerCylinder
;
4180 if (DeviceExtension
->DMActive
) {
4182 DeviceExtension
->DMByteSkew
= DeviceExtension
->DMSkew
* DeviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
;
4188 DeviceExtension
->DMByteSkew
= 0;
4194 } // end UpdateGeometry()
4200 UpdateRemovableGeometry (
4201 IN PDEVICE_OBJECT DeviceObject
,
4207 Routine Description:
4209 This routines updates the size and starting offset of the device. This is
4210 used when the media on the device may have changed thereby changing the
4211 size of the device. If this is the physical device then a
4212 ScsiClassReadDriveCapacity is done; otherewise, a read partition table is done.
4216 DeviceObject - Supplies the device object whos size needs to be updated.
4218 Irp - Supplies a reference where the status can be updated.
4222 Returns the status of the opertion.
4227 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
4228 PDRIVE_LAYOUT_INFORMATION partitionList
;
4230 PDISK_DATA diskData
;
4231 ULONG partitionNumber
;
4234 // Determine if the size of the partition may have changed because
4235 // the media has changed.
4238 if (!(DeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
)) {
4240 return(STATUS_SUCCESS
);
4245 // If this request is for partition zero then do a read drive
4246 // capacity otherwise do a I/O read partition table.
4249 diskData
= (PDISK_DATA
) (deviceExtension
+ 1);
4252 // Read the drive capcity. If that fails, give up.
4255 status
= ScsiClassReadDriveCapacity(deviceExtension
->PhysicalDevice
);
4257 if (!NT_SUCCESS(status
)) {
4262 // Read the partition table agian.
4265 status
= IoReadPartitionTable(deviceExtension
->PhysicalDevice
,
4266 deviceExtension
->DiskGeometry
->Geometry
.BytesPerSector
,
4271 if (!NT_SUCCESS(status
)) {
4274 // Fail the request.
4280 if (diskData
->PartitionNumber
!= 0 &&
4281 diskData
->PartitionNumber
<= partitionList
->PartitionCount
) {
4283 partitionNumber
= diskData
->PartitionNumber
- 1;
4286 // Update the partition information for this parition.
4289 diskData
->PartitionType
=
4290 partitionList
->PartitionEntry
[partitionNumber
].PartitionType
;
4292 diskData
->BootIndicator
=
4293 partitionList
->PartitionEntry
[partitionNumber
].BootIndicator
;
4295 deviceExtension
->StartingOffset
=
4296 partitionList
->PartitionEntry
[partitionNumber
].StartingOffset
;
4298 deviceExtension
->PartitionLength
=
4299 partitionList
->PartitionEntry
[partitionNumber
].PartitionLength
;
4301 diskData
->HiddenSectors
=
4302 partitionList
->PartitionEntry
[partitionNumber
].HiddenSectors
;
4304 deviceExtension
->SectorShift
= ((PDEVICE_EXTENSION
)
4305 deviceExtension
->PhysicalDevice
->DeviceExtension
)->SectorShift
;
4307 } else if (diskData
->PartitionNumber
!= 0) {
4310 // The paritition does not exist. Zero all the data.
4313 diskData
->PartitionType
= 0;
4314 diskData
->BootIndicator
= 0;
4315 diskData
->HiddenSectors
= 0;
4316 deviceExtension
->StartingOffset
.QuadPart
= (LONGLONG
)0;
4317 deviceExtension
->PartitionLength
.QuadPart
= (LONGLONG
)0;
4321 // Free the parition list allocate by I/O read partition table.
4324 ExFreePool(partitionList
);
4327 return(STATUS_SUCCESS
);
4333 ScsiDiskProcessError(
4334 PDEVICE_OBJECT DeviceObject
,
4335 PSCSI_REQUEST_BLOCK Srb
,
4341 Routine Description:
4343 This routine checks the type of error. If the error indicates an underrun
4344 then indicate the request should be retried.
4348 DeviceObject - Supplies a pointer to the device object.
4350 Srb - Supplies a pointer to the failing Srb.
4352 Status - Status with which the IRP will be completed.
4354 Retry - Indication of whether the request will be retried.
4363 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
4365 if (*Status
== STATUS_DATA_OVERRUN
&&
4366 ( Srb
->Cdb
[0] == SCSIOP_WRITE
|| Srb
->Cdb
[0] == SCSIOP_READ
)) {
4371 // Update the error count for the device.
4374 deviceExtension
->ErrorCount
++;
4377 if (SRB_STATUS(Srb
->SrbStatus
) == SRB_STATUS_ERROR
&&
4378 Srb
->ScsiStatus
== SCSISTAT_BUSY
) {
4381 // The disk drive should never be busy this long. Reset the scsi bus
4382 // maybe this will clear the condition.
4385 ResetScsiBus(DeviceObject
);
4388 // Update the error count for the device.
4391 deviceExtension
->ErrorCount
++;
4398 PDEVICE_OBJECT DeviceObject
,
4399 PSCSI_INQUIRY_DATA LunInfo
,
4400 PIO_SCSI_CAPABILITIES PortCapabilities
4405 Routine Description:
4407 This function checks to see if an SCSI logical unit requires speical
4412 DeviceObject - Supplies the device object to be tested.
4414 InquiryData - Supplies the inquiry data returned by the device of interest.
4416 PortCapabilities - Supplies the capabilities of the device object.
4425 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
4426 PINQUIRYDATA InquiryData
= (PINQUIRYDATA
)LunInfo
->InquiryData
;
4427 BAD_CONTROLLER_INFORMATION
const *controller
;
4430 for (j
= 0; j
< NUMBER_OF_BAD_CONTROLLERS
; j
++) {
4432 controller
= &ScsiDiskBadControllers
[j
];
4434 if (strncmp(controller
->InquiryString
, (PCCHAR
)InquiryData
->VendorId
, strlen(controller
->InquiryString
))) {
4438 DebugPrint((1, "ScsiDisk ScanForSpecial, Found bad controller! %s\n", controller
->InquiryString
));
4441 // Found a listed controller. Determine what must be done.
4444 if (controller
->DisableTaggedQueuing
) {
4447 // Disable tagged queuing.
4450 deviceExtension
->SrbFlags
&= ~SRB_FLAGS_QUEUE_ACTION_ENABLE
;
4453 if (controller
->DisableSynchronousTransfers
) {
4456 // Disable synchronous data transfers.
4459 deviceExtension
->SrbFlags
|= SRB_FLAGS_DISABLE_SYNCH_TRANSFER
;
4463 if (controller
->DisableDisconnects
) {
4466 // Disable disconnects.
4469 deviceExtension
->SrbFlags
|= SRB_FLAGS_DISABLE_DISCONNECT
;
4474 // Found device so exit the loop and return.
4481 // Set the StartUnit flag appropriately.
4484 if (DeviceObject
->DeviceType
== FILE_DEVICE_DISK
) {
4485 deviceExtension
->DeviceFlags
|= DEV_SAFE_START_UNIT
;
4487 if (DeviceObject
->Characteristics
& FILE_REMOVABLE_MEDIA
) {
4488 if (_strnicmp((PCCHAR
)InquiryData
->VendorId
, "iomega", strlen("iomega"))) {
4489 deviceExtension
->DeviceFlags
&= ~DEV_SAFE_START_UNIT
;
4500 IN PDEVICE_OBJECT DeviceObject
4505 Routine Description:
4507 This command sends a reset bus command to the SCSI port driver.
4511 DeviceObject - The device object for the logical unit with
4520 PIO_STACK_LOCATION irpStack
;
4522 PDEVICE_EXTENSION deviceExtension
= DeviceObject
->DeviceExtension
;
4523 PSCSI_REQUEST_BLOCK srb
;
4524 PCOMPLETION_CONTEXT context
;
4526 DebugPrint((1, "ScsiDisk ResetScsiBus: Sending reset bus request to port driver.\n"));
4529 // Allocate Srb from nonpaged pool.
4532 context
= ExAllocatePool(NonPagedPoolMustSucceed
,
4533 sizeof(COMPLETION_CONTEXT
));
4536 // Save the device object in the context for use by the completion
4540 context
->DeviceObject
= DeviceObject
;
4541 srb
= &context
->Srb
;
4547 RtlZeroMemory(srb
, SCSI_REQUEST_BLOCK_SIZE
);
4550 // Write length to SRB.
4553 srb
->Length
= SCSI_REQUEST_BLOCK_SIZE
;
4556 // Set up SCSI bus address.
4559 srb
->PathId
= deviceExtension
->PathId
;
4560 srb
->TargetId
= deviceExtension
->TargetId
;
4561 srb
->Lun
= deviceExtension
->Lun
;
4563 srb
->Function
= SRB_FUNCTION_RESET_BUS
;
4566 // Build the asynchronous request to be sent to the port driver.
4567 // Since this routine is called from a DPC the IRP should always be
4571 irp
= IoAllocateIrp(DeviceObject
->StackSize
, FALSE
);
4573 IoSetCompletionRoutine(irp
,
4574 (PIO_COMPLETION_ROUTINE
)ScsiClassAsynchronousCompletion
,
4580 irpStack
= IoGetNextIrpStackLocation(irp
);
4582 irpStack
->MajorFunction
= IRP_MJ_SCSI
;
4584 srb
->OriginalRequest
= irp
;
4587 // Store the SRB address in next stack for port driver.
4590 irpStack
->Parameters
.Scsi
.Srb
= srb
;
4593 // Call the port driver with the IRP.
4596 IoCallDriver(deviceExtension
->PortDeviceObject
, irp
);
4600 } // end ResetScsiBus()
4605 UpdateDeviceObjects(
4606 IN PDEVICE_OBJECT PhysicalDisk
,
4612 Routine Description:
4614 This routine creates, deletes and changes device objects when
4615 the IOCTL_SET_DRIVE_LAYOUT is called. This routine also updates
4616 the drive layout information for the user. It is possible to
4617 call this routine even in the GET_LAYOUT case because RewritePartition
4622 DeviceObject - Device object for physical disk.
4623 Irp - IO Request Packet (IRP).
4631 PDEVICE_EXTENSION physicalExtension
= PhysicalDisk
->DeviceExtension
;
4632 PDRIVE_LAYOUT_INFORMATION partitionList
= Irp
->AssociatedIrp
.SystemBuffer
;
4634 ULONG partitionNumber
;
4635 ULONG partitionCount
;
4636 ULONG lastPartition
;
4637 ULONG partitionOrdinal
;
4638 PPARTITION_INFORMATION partitionEntry
;
4639 CCHAR ntNameBuffer
[MAXIMUM_FILENAME_LENGTH
];
4640 STRING ntNameString
;
4641 UNICODE_STRING ntUnicodeString
;
4642 PDEVICE_OBJECT deviceObject
;
4643 PDEVICE_EXTENSION deviceExtension
;
4644 PDISK_DATA diskData
;
4646 ULONG numberListElements
;
4649 partitionCount
= ((partitionList
->PartitionCount
+ 3) / 4) * 4;
4652 // Zero all of the partition numbers.
4655 for (partition
= 0; partition
< partitionCount
; partition
++) {
4656 partitionEntry
= &partitionList
->PartitionEntry
[partition
];
4657 partitionEntry
->PartitionNumber
= 0;
4661 // Walk through chain of partitions for this disk to determine
4662 // which existing partitions have no match.
4665 deviceExtension
= physicalExtension
;
4666 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
4671 deviceExtension
= diskData
->NextPartition
;
4674 // Check if this is the last partition in the chain.
4677 if (!deviceExtension
) {
4682 // Get the partition device extension from disk data.
4685 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
4688 // Check for highest partition number this far.
4691 if (diskData
->PartitionNumber
> lastPartition
) {
4692 lastPartition
= diskData
->PartitionNumber
;
4696 // Check if this partition is not currently being used.
4699 if (!deviceExtension
->PartitionLength
.QuadPart
) {
4704 // Loop through partition information to look for match.
4708 partitionOrdinal
= 0;
4710 for (partition
= 0; partition
< partitionCount
; partition
++) {
4713 // Get partition descriptor.
4716 partitionEntry
= &partitionList
->PartitionEntry
[partition
];
4719 // Check if empty, or describes extended partiton or hasn't changed.
4722 if (partitionEntry
->PartitionType
== PARTITION_ENTRY_UNUSED
||
4723 IsContainerPartition(partitionEntry
->PartitionType
)) {
4728 // Advance partition ordinal.
4734 // Check if new partition starts where this partition starts.
4737 if (partitionEntry
->StartingOffset
.QuadPart
!=
4738 deviceExtension
->StartingOffset
.QuadPart
) {
4743 // Check if partition length is the same.
4746 if (partitionEntry
->PartitionLength
.QuadPart
==
4747 deviceExtension
->PartitionLength
.QuadPart
) {
4750 "UpdateDeviceObjects: Found match for \\Harddisk%d\\Partition%d\n",
4751 physicalExtension
->DeviceNumber
,
4752 diskData
->PartitionNumber
));
4755 // Indicate match is found and set partition number
4760 partitionEntry
->PartitionNumber
= diskData
->PartitionNumber
;
4768 // A match is found.
4771 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
4774 // If this partition is marked for update then update partition type.
4777 if (partitionEntry
->RewritePartition
) {
4778 diskData
->PartitionType
= partitionEntry
->PartitionType
;
4782 // Update partitional ordinal for calls to HAL routine
4783 // IoSetPartitionInformation.
4786 diskData
->PartitionOrdinal
= partitionOrdinal
;
4789 "UpdateDeviceObjects: Disk %d ordinal %d is partition %d\n",
4790 physicalExtension
->DeviceNumber
,
4791 diskData
->PartitionOrdinal
,
4792 diskData
->PartitionNumber
));
4797 // no match was found, indicate this partition is gone.
4801 "UpdateDeviceObjects: Deleting \\Device\\Harddisk%x\\Partition%x\n",
4802 physicalExtension
->DeviceNumber
,
4803 diskData
->PartitionNumber
));
4805 deviceExtension
->PartitionLength
.QuadPart
= (LONGLONG
) 0;
4811 // Walk through partition loop to find new partitions and set up
4812 // device extensions to describe them. In some cases new device
4813 // objects will be created.
4816 partitionOrdinal
= 0;
4819 partition
< partitionCount
;
4823 // Get partition descriptor.
4826 partitionEntry
= &partitionList
->PartitionEntry
[partition
];
4829 // Check if empty, or describes an extended partiton.
4832 if (partitionEntry
->PartitionType
== PARTITION_ENTRY_UNUSED
||
4833 IsContainerPartition(partitionEntry
->PartitionType
)) {
4838 // Keep track of position on the disk for calls to IoSetPartitionInformation.
4844 // Check if this entry should be rewritten.
4847 if (!partitionEntry
->RewritePartition
) {
4851 if (partitionEntry
->PartitionNumber
) {
4854 // Partition is an exact match with an existing partition, but is
4855 // being written anyway.
4862 // Check first if existing device object is available by
4863 // walking partition extension list.
4866 partitionNumber
= 0;
4867 deviceExtension
= physicalExtension
;
4868 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
4873 // Get next partition device extension from disk data.
4876 deviceExtension
= diskData
->NextPartition
;
4878 if (!deviceExtension
) {
4882 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
4885 // A device object is free if the partition length is set to zero.
4888 if (!deviceExtension
->PartitionLength
.QuadPart
) {
4889 partitionNumber
= diskData
->PartitionNumber
;
4896 // If partition number is still zero then a new device object
4900 if (partitionNumber
== 0) {
4903 partitionNumber
= lastPartition
;
4906 // Get or create partition object and set up partition parameters.
4909 sprintf(ntNameBuffer
,
4910 "\\Device\\Harddisk%lu\\Partition%lu",
4911 physicalExtension
->DeviceNumber
,
4914 RtlInitString(&ntNameString
,
4917 status
= RtlAnsiStringToUnicodeString(&ntUnicodeString
,
4921 if (!NT_SUCCESS(status
)) {
4926 "UpdateDeviceObjects: Create device object %s\n",
4930 // This is a new name. Create the device object to represent it.
4933 status
= IoCreateDevice(PhysicalDisk
->DriverObject
,
4934 DEVICE_EXTENSION_SIZE
,
4941 if (!NT_SUCCESS(status
)) {
4943 "UpdateDeviceObjects: Can't create device %s\n",
4945 RtlFreeUnicodeString(&ntUnicodeString
);
4950 // Set up device object fields.
4953 deviceObject
->Flags
|= DO_DIRECT_IO
;
4954 deviceObject
->StackSize
= PhysicalDisk
->StackSize
;
4957 // Set up device extension fields.
4960 deviceExtension
= deviceObject
->DeviceExtension
;
4963 // Copy physical disk extension to partition extension.
4966 RtlMoveMemory(deviceExtension
,
4968 sizeof(DEVICE_EXTENSION
));
4971 // Initialize the new S-List.
4974 if (deviceExtension
->SrbFlags
& SRB_FLAGS_QUEUE_ACTION_ENABLE
) {
4975 numberListElements
= 30;
4977 numberListElements
= 8;
4981 // Build the lookaside list for srb's for this partition based on
4982 // whether the adapter and disk can do tagged queueing.
4985 ScsiClassInitializeSrbLookasideList(deviceExtension
,
4986 numberListElements
);
4989 // Allocate spinlock for zoning for split-request completion.
4992 KeInitializeSpinLock(&deviceExtension
->SplitRequestSpinLock
);
4995 // Write back partition number used in creating object name.
4998 partitionEntry
->PartitionNumber
= partitionNumber
;
5001 // Clear flags initializing bit.
5004 deviceObject
->Flags
&= ~DO_DEVICE_INITIALIZING
;
5007 // Point back at device object.
5010 deviceExtension
->DeviceObject
= deviceObject
;
5012 RtlFreeUnicodeString(&ntUnicodeString
);
5015 // Link to end of partition chain using previous disk data.
5018 diskData
->NextPartition
= deviceExtension
;
5021 // Get new disk data and zero next partition pointer.
5024 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
5025 diskData
->NextPartition
= NULL
;
5030 // Set pointer to disk data area that follows device extension.
5033 diskData
= (PDISK_DATA
)(deviceExtension
+ 1);
5036 "UpdateDeviceObjects: Used existing device object \\Device\\Harddisk%x\\Partition%x\n",
5037 physicalExtension
->DeviceNumber
,
5042 // Update partition information in partition device extension.
5045 diskData
->PartitionNumber
= partitionNumber
;
5046 diskData
->PartitionType
= partitionEntry
->PartitionType
;
5047 diskData
->BootIndicator
= partitionEntry
->BootIndicator
;
5048 deviceExtension
->StartingOffset
= partitionEntry
->StartingOffset
;
5049 deviceExtension
->PartitionLength
= partitionEntry
->PartitionLength
;
5050 diskData
->HiddenSectors
= partitionEntry
->HiddenSectors
;
5051 diskData
->PartitionOrdinal
= partitionOrdinal
;
5054 "UpdateDeviceObjects: Ordinal %d is partition %d\n",
5055 diskData
->PartitionOrdinal
,
5056 diskData
->PartitionNumber
));
5059 // Update partition number passed in to indicate the
5060 // device name for this partition.
5063 partitionEntry
->PartitionNumber
= partitionNumber
;
5066 } // end UpdateDeviceObjects()