We can number all devices on a bus, rather than just disks.
disk__type_ptr disk = disk__get_ptr(dev_walker);
struct aoe__disk_type_ * aoe_disk = aoe__get_(dev_walker);
- disks->Disk[count].Disk = disk->DiskNumber;
+ disks->Disk[count].Disk = dev_walker->dev_num;
RtlCopyMemory(
&disks->Disk[count].ClientMac,
&aoe_disk->ClientMac,
PDEVICE_OBJECT Self;
/* Points to the parent bus' DEVICE_OBJECT */
PDEVICE_OBJECT Parent;
+ /* The device's child ID relative to the parent bus. */
+ winvblock__uint32 dev_num;
/* Points to the driver. */
PDRIVER_OBJECT DriverObject;
/* Current state of the device. */
KSPIN_LOCK SpinLock;
winvblock__bool BootDrive;
winvblock__bool Unmount;
- winvblock__uint32 DiskNumber;
disk__media media;
disk__ops disk_ops;
ULONGLONG LBADiskSize;
PDEVICE_OBJECT dev_obj_ptr;
/* Walks the child nodes. */
struct device__type * walker;
+ winvblock__uint32 dev_num;
DBG("Entry\n");
if ((bus_ptr == NULL) || (dev_ptr == NULL)) {
dev_ptr->ops.init(dev_ptr);
dev_obj_ptr->Flags &= ~DO_DEVICE_INITIALIZING;
/* Add the new device's extension to the bus' list of children. */
+ dev_num = 0;
if (bus_ptr->first_child == NULL) {
bus_ptr->first_child = dev_ptr;
} else {
walker = bus_ptr->first_child;
- while (walker->next_sibling_ptr != NULL)
- walker = walker->next_sibling_ptr;
- walker->next_sibling_ptr = dev_ptr;
+ /* If the first child device number isn't 0... */
+ if (walker->dev_num) {
+ /* We insert before. */
+ dev_ptr->next_sibling_ptr = walker;
+ bus_ptr->first_child = dev_ptr;
+ } else {
+ while (walker->next_sibling_ptr != NULL) {
+ /* If there's a gap in the device numbers for the bus... */
+ if (walker->dev_num < walker->next_sibling_ptr->dev_num - 1) {
+ /* Insert here, instead of at the end. */
+ dev_num = walker->dev_num + 1;
+ dev_ptr->next_sibling_ptr = walker->next_sibling_ptr;
+ walker->next_sibling_ptr = dev_ptr;
+ break;
+ }
+ walker = walker->next_sibling_ptr;
+ dev_num = walker->dev_num + 1;
+ }
+ /* If we haven't already inserted the device... */
+ if (!dev_ptr->next_sibling_ptr) {
+ walker->next_sibling_ptr = dev_ptr;
+ dev_num = walker->dev_num + 1;
+ }
+ }
}
+ dev_ptr->dev_num = dev_num;
bus_ptr->Children++;
if (bus_ptr->PhysicalDeviceObject != NULL) {
IoInvalidateDeviceRelations(
if (dev_walker != NULL)
disk_walker = disk__get_ptr(dev_walker);
prev_disk_walker = disk_walker;
- while ((disk_walker != NULL) && (disk_walker->DiskNumber != disk_num)) {
+ while ((disk_walker != NULL) && (dev_walker->dev_num != disk_num)) {
prev_disk_walker = disk_walker;
dev_walker = dev_walker->next_sibling_ptr;
if (dev_walker != NULL)
*completion = TRUE;
return STATUS_INVALID_DEVICE_REQUEST;
}
- DBG("Deleting disk %d\n", disk_walker->DiskNumber);
+ DBG("Deleting disk %d\n", dev_walker->dev_num);
if (disk_walker == disk__get_ptr(bus->first_child))
bus->first_child = dev_walker->next_sibling_ptr;
else {
{
winvblock__uint32 copy_size;
SCSI_ADDRESS scsi_address;
- disk__type_ptr disk_ptr;
copy_size =
( Stack->Parameters.DeviceIoControl.OutputBufferLength <
scsi_address.Length = sizeof ( SCSI_ADDRESS );
scsi_address.PortNumber = 0;
scsi_address.PathId = 0;
- disk_ptr = disk__get_ptr ( dev_ptr );
- scsi_address.TargetId = ( winvblock__uint8 ) disk_ptr->DiskNumber;
+ scsi_address.TargetId = (winvblock__uint8) dev_ptr->dev_num;
scsi_address.Lun = 0;
RtlCopyMemory ( Irp->AssociatedIrp.SystemBuffer, &scsi_address, copy_size );
Irp->IoStatus.Information = ( ULONG_PTR ) copy_size;
#endif
/* Globals. */
-static winvblock__uint32 next_disk = 0;
static LIST_ENTRY disk_list;
static KSPIN_LOCK disk_list_lock;
winvblock__bool disk__removable[disk__media_count] = { TRUE, FALSE, TRUE };
dev_ptr->Self = dev_obj_ptr;
KeInitializeEvent ( &disk_ptr->SearchEvent, SynchronizationEvent, FALSE );
KeInitializeSpinLock ( &disk_ptr->SpinLock );
- disk_ptr->DiskNumber = InterlockedIncrement ( &next_disk ) - 1;
/*
* Some device parameters
*/