2 * PROJECT: ReactOS Storage Stack / SCSIPORT storage port library
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Logical Unit (PDO) functions
5 * COPYRIGHT: Eric Kohl (eric.kohl@reactos.org)
6 * Aleksey Bragin (aleksey@reactos.org)
15 PSCSI_PORT_LUN_EXTENSION
16 SpiAllocateLunExtension(
17 _In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
)
19 PSCSI_PORT_LUN_EXTENSION LunExtension
;
20 ULONG LunExtensionSize
;
22 DPRINT("SpiAllocateLunExtension(%p)\n", DeviceExtension
);
24 /* Round LunExtensionSize first to the sizeof LONGLONG */
25 LunExtensionSize
= (DeviceExtension
->LunExtensionSize
+
26 sizeof(LONGLONG
) - 1) & ~(sizeof(LONGLONG
) - 1);
28 LunExtensionSize
+= sizeof(SCSI_PORT_LUN_EXTENSION
);
29 DPRINT("LunExtensionSize %lu\n", LunExtensionSize
);
31 LunExtension
= ExAllocatePoolWithTag(NonPagedPool
, LunExtensionSize
, TAG_SCSIPORT
);
32 if (LunExtension
== NULL
)
34 DPRINT1("Out of resources!\n");
39 RtlZeroMemory(LunExtension
, LunExtensionSize
);
41 /* Initialize a list of requests */
42 InitializeListHead(&LunExtension
->SrbInfo
.Requests
);
44 /* Initialize timeout counter */
45 LunExtension
->RequestTimeout
= -1;
47 /* Set maximum queue size */
48 LunExtension
->MaxQueueCount
= 256;
50 /* Initialize request queue */
51 KeInitializeDeviceQueue(&LunExtension
->DeviceQueue
);
56 PSCSI_PORT_LUN_EXTENSION
58 _In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
63 PSCSI_PORT_LUN_EXTENSION LunExtension
;
65 DPRINT("SpiGetLunExtension(%p %u %u %u) called\n",
66 DeviceExtension
, PathId
, TargetId
, Lun
);
68 /* Get appropriate list */
69 LunExtension
= DeviceExtension
->LunExtensionList
[(TargetId
+ Lun
) % LUS_NUMBER
];
71 /* Iterate it until we find what we need */
74 if (LunExtension
->TargetId
== TargetId
&&
75 LunExtension
->Lun
== Lun
&&
76 LunExtension
->PathId
== PathId
)
78 /* All matches, return */
82 /* Advance to the next item */
83 LunExtension
= LunExtension
->Next
;
86 /* We did not find anything */
87 DPRINT("Nothing found\n");
91 PSCSI_REQUEST_BLOCK_INFO
93 _In_ PSCSI_PORT_DEVICE_EXTENSION DeviceExtension
,
99 PSCSI_PORT_LUN_EXTENSION LunExtension
;
101 if (QueueTag
== SP_UNTAGGED
)
103 /* Untagged request, get LU and return pointer to SrbInfo */
104 LunExtension
= SpiGetLunExtension(DeviceExtension
,
109 /* Return NULL in case of error */
113 /* Return the pointer to SrbInfo */
114 return &LunExtension
->SrbInfo
;
118 /* Make sure the tag is valid, if it is - return the data */
119 if (QueueTag
> DeviceExtension
->SrbDataCount
|| QueueTag
< 1)
122 return &DeviceExtension
->SrbInfo
[QueueTag
-1];