Skip to content

Commit a9b97ae

Browse files
committed
[USBSTOR] General refactoring.
Remove unused structures and unused fields in device extensions. Replaced magic numbers with constants
1 parent cb2515d commit a9b97ae

File tree

6 files changed

+93
-320
lines changed

6 files changed

+93
-320
lines changed

drivers/usb/usbstor/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11

2-
add_definitions(-DDEBUG_MODE)
3-
include_directories(${REACTOS_SOURCE_DIR}/ntoskrnl/include)
4-
52
list(APPEND SOURCE
63
descriptor.c
74
disk.c

drivers/usb/usbstor/fdo.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ USBSTOR_FdoHandleDeviceRelations(
4242
IN PFDO_DEVICE_EXTENSION DeviceExtension,
4343
IN OUT PIRP Irp)
4444
{
45-
ULONG DeviceCount = 0;
45+
INT32 DeviceCount = 0;
4646
LONG Index;
4747
PDEVICE_RELATIONS DeviceRelations;
4848
PIO_STACK_LOCATION IoStack;
@@ -61,7 +61,7 @@ USBSTOR_FdoHandleDeviceRelations(
6161
}
6262
}
6363

64-
DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount > 1 ? (DeviceCount-1) * sizeof(PDEVICE_OBJECT) : 0));
64+
DeviceRelations = ExFreePoolWithTag(PagedPool, sizeof(DEVICE_RELATIONS) + (DeviceCount-1) * sizeof(PDEVICE_OBJECT), USB_STOR_TAG);
6565
if (!DeviceRelations)
6666
{
6767
Irp->IoStatus.Information = 0;
@@ -106,7 +106,7 @@ USBSTOR_FdoHandleRemoveDevice(
106106
DPRINT("Handling FDO removal %p\n", DeviceObject);
107107

108108
// FIXME: wait for devices finished processing
109-
for (Index = 0; Index < 16; Index++)
109+
for (Index = 0; Index < USB_MAXCHILDREN; Index++)
110110
{
111111
if (DeviceExtension->ChildPDO[Index] != NULL)
112112
{
@@ -198,17 +198,15 @@ USBSTOR_FdoHandleStartDevice(
198198
ASSERT(InterfaceDesc->bLength == sizeof(USB_INTERFACE_DESCRIPTOR));
199199

200200
DPRINT("bInterfaceSubClass %x\n", InterfaceDesc->bInterfaceSubClass);
201-
if (InterfaceDesc->bInterfaceProtocol != 0x50)
201+
if (InterfaceDesc->bInterfaceProtocol != USB_PROTOCOL_BULK)
202202
{
203203
DPRINT1("USB Device is not a bulk only device and is not currently supported\n");
204204
return STATUS_NOT_SUPPORTED;
205205
}
206206

207-
if (InterfaceDesc->bInterfaceSubClass == 0x04) // UFI subclass
207+
if (InterfaceDesc->bInterfaceSubClass == USB_SUBCLASS_UFI)
208208
{
209-
// FIXME: need to pad CDBs to 12 byte
210-
// mode select commands must be translated from 1AH / 15h to 5AH / 55h
211-
DPRINT1("[USBSTOR] Error: need to pad CDBs\n");
209+
DPRINT1("USB Floppy devices are not supported\n");
212210
return STATUS_NOT_SUPPORTED;
213211
}
214212

drivers/usb/usbstor/misc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,9 @@ USBSTOR_GetMaxLUN(
208208
PUCHAR Buffer;
209209
NTSTATUS Status;
210210

211-
Buffer = (PUCHAR)AllocateItem(NonPagedPool, sizeof(UCHAR));
211+
Buffer = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, sizeof(UCHAR), USB_STOR_TAG);
212212
if (!Buffer)
213213
{
214-
FreeItem(Buffer);
215214
return STATUS_INSUFFICIENT_RESOURCES;
216215
}
217216

@@ -221,7 +220,7 @@ USBSTOR_GetMaxLUN(
221220

222221
if (NT_SUCCESS(Status))
223222
{
224-
if (*Buffer > 0xF)
223+
if (*Buffer > MAX_LUN)
225224
{
226225
// invalid response documented in usb mass storage specification
227226
Status = STATUS_DEVICE_DATA_ERROR;
@@ -243,7 +242,7 @@ USBSTOR_GetMaxLUN(
243242
Status = STATUS_SUCCESS;
244243
}
245244

246-
FreeItem(Buffer);
245+
ExFreePoolWithTag(Buffer, USB_STOR_TAG);
247246
return Status;
248247
}
249248

@@ -258,6 +257,7 @@ USBSTOR_ResetDevice(
258257
return Status;
259258
}
260259

260+
// if somebody wants to add UFI support, here is a useful function
261261
#if 0
262262
BOOLEAN
263263
USBSTOR_IsFloppy(

drivers/usb/usbstor/pdo.c

Lines changed: 30 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -15,107 +15,53 @@
1515
#include <debug.h>
1616

1717

18+
static
1819
LPCSTR
1920
USBSTOR_GetDeviceType(
20-
IN PINQUIRYDATA InquiryData,
21-
IN UCHAR IsFloppy)
21+
IN PINQUIRYDATA InquiryData)
2222
{
23-
if (InquiryData->DeviceType == 0)
24-
{
25-
if (IsFloppy)
26-
{
27-
// floppy device
28-
return "SFloppy";
29-
}
30-
31-
// direct access device
32-
return "Disk";
33-
}
34-
3523
switch (InquiryData->DeviceType)
3624
{
37-
case 1:
38-
{
25+
case DIRECT_ACCESS_DEVICE:
26+
return "Disk";
27+
case SEQUENTIAL_ACCESS_DEVICE:
3928
// sequential device, i.e magnetic tape
4029
return "Sequential";
41-
}
42-
case 4:
43-
{
44-
// write once device
30+
case WRITE_ONCE_READ_MULTIPLE_DEVICE:
4531
return "Worm";
46-
}
47-
case 5:
48-
{
49-
// CDROM device
32+
case READ_ONLY_DIRECT_ACCESS_DEVICE:
5033
return "CdRom";
51-
}
52-
case 7:
53-
{
54-
// optical memory device
34+
case OPTICAL_DEVICE:
5535
return "Optical";
56-
}
57-
case 8:
58-
{
59-
// medium change device
36+
case MEDIUM_CHANGER:
6037
return "Changer";
61-
}
6238
default:
63-
{
64-
// other device
6539
return "Other";
66-
}
6740
}
6841
}
6942

43+
static
7044
LPCSTR
7145
USBSTOR_GetGenericType(
72-
IN PINQUIRYDATA InquiryData,
73-
IN UCHAR IsFloppy)
46+
IN PINQUIRYDATA InquiryData)
7447
{
75-
if (InquiryData->DeviceType == 0)
76-
{
77-
if (IsFloppy)
78-
{
79-
// floppy device
80-
return "GenSFloppy";
81-
}
82-
83-
// direct access device
84-
return "GenDisk";
85-
}
86-
8748
switch (InquiryData->DeviceType)
8849
{
89-
case 1:
90-
{
50+
case DIRECT_ACCESS_DEVICE:
51+
return "GenDisk";
52+
case SEQUENTIAL_ACCESS_DEVICE:
9153
// sequential device, i.e magnetic tape
9254
return "GenSequential";
93-
}
94-
case 4:
95-
{
96-
// write once device
55+
case WRITE_ONCE_READ_MULTIPLE_DEVICE:
9756
return "GenWorm";
98-
}
99-
case 5:
100-
{
101-
// CDROM device
57+
case READ_ONLY_DIRECT_ACCESS_DEVICE:
10258
return "GenCdRom";
103-
}
104-
case 7:
105-
{
106-
// optical memory device
59+
case OPTICAL_DEVICE:
10760
return "GenOptical";
108-
}
109-
case 8:
110-
{
111-
// medium change device
61+
case MEDIUM_CHANGER:
11262
return "GenChanger";
113-
}
11463
default:
115-
{
116-
// other device
11764
return "UsbstorOther";
118-
}
11965
}
12066
}
12167

@@ -210,7 +156,7 @@ USBSTOR_PdoHandleQueryDeviceText(
210156

211157
DeviceDescription.Length = 0;
212158
DeviceDescription.MaximumLength = (USHORT)(Offset * sizeof(WCHAR));
213-
DeviceDescription.Buffer = (LPWSTR)AllocateItem(PagedPool, DeviceDescription.MaximumLength);
159+
DeviceDescription.Buffer = ExAllocatePoolWithTag(PagedPool, DeviceDescription.MaximumLength, USB_STOR_TAG);
214160
if (!DeviceDescription.Buffer)
215161
{
216162
Irp->IoStatus.Information = 0;
@@ -248,7 +194,7 @@ USBSTOR_PdoHandleQueryDeviceId(
248194
ASSERT(DeviceExtension->InquiryData);
249195
InquiryData = DeviceExtension->InquiryData;
250196

251-
DeviceType = USBSTOR_GetDeviceType(InquiryData, DeviceExtension->IsFloppy);
197+
DeviceType = USBSTOR_GetDeviceType(InquiryData);
252198

253199
// lets create device string
254200
Offset = sprintf(&Buffer[Offset], "USBSTOR\\");
@@ -265,7 +211,7 @@ USBSTOR_PdoHandleQueryDeviceId(
265211
// allocate DeviceId string
266212
DeviceId.Length = 0;
267213
DeviceId.MaximumLength = (USHORT)((strlen((PCHAR)Buffer) + 1) * sizeof(WCHAR));
268-
DeviceId.Buffer = (LPWSTR)AllocateItem(PagedPool, DeviceId.MaximumLength);
214+
DeviceId.Buffer = ExAllocatePoolWithTag(PagedPool, DeviceId.MaximumLength, USB_STOR_TAG);
269215
if (!DeviceId.Buffer)
270216
{
271217
Irp->IoStatus.Information = 0;
@@ -338,8 +284,8 @@ USBSTOR_PdoHandleQueryHardwareId(
338284
ASSERT(FDODeviceExtension->DeviceDescriptor);
339285
InquiryData = PDODeviceExtension->InquiryData;
340286

341-
DeviceType = USBSTOR_GetDeviceType(InquiryData, PDODeviceExtension->IsFloppy);
342-
GenericType = USBSTOR_GetGenericType(InquiryData, PDODeviceExtension->IsFloppy);
287+
DeviceType = USBSTOR_GetDeviceType(InquiryData);
288+
GenericType = USBSTOR_GetGenericType(InquiryData);
343289

344290
ASSERT(GenericType);
345291

@@ -418,7 +364,7 @@ USBSTOR_PdoHandleQueryHardwareId(
418364

419365
TotalLength = Id1Length + Id2Length + Id3Length + Id4Length + Id5Length + Id6Length + Id7Length + 1;
420366

421-
Buffer = (LPWSTR)AllocateItem(PagedPool, TotalLength * sizeof(WCHAR));
367+
Buffer = ExAllocatePoolWithTag(PagedPool, TotalLength * sizeof(WCHAR), USB_STOR_TAG);
422368
if (!Buffer)
423369
{
424370
Irp->IoStatus.Information = 0;
@@ -458,13 +404,13 @@ USBSTOR_PdoHandleQueryCompatibleId(
458404
PDODeviceExtension = (PPDO_DEVICE_EXTENSION)DeviceObject->DeviceExtension;
459405
FDODeviceExtension = (PFDO_DEVICE_EXTENSION)PDODeviceExtension->LowerDeviceObject->DeviceExtension;
460406
ASSERT(FDODeviceExtension->DeviceDescriptor);
461-
DeviceType = USBSTOR_GetDeviceType(PDODeviceExtension->InquiryData, PDODeviceExtension->IsFloppy);
407+
DeviceType = USBSTOR_GetDeviceType(PDODeviceExtension->InquiryData);
462408

463409
// format instance id
464410
Length = sprintf(Buffer, "USBSTOR\\%s", DeviceType) + 1;
465411
Length += sprintf(&Buffer[Length], "USBSTOR\\%s", "RAW") + 2;
466412

467-
InstanceId = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR));
413+
InstanceId = ExAllocatePoolWithTag(PagedPool, Length * sizeof(WCHAR), USB_STOR_TAG);
468414
if (!InstanceId)
469415
{
470416
Irp->IoStatus.Information = 0;
@@ -508,7 +454,7 @@ USBSTOR_PdoHandleQueryInstanceId(
508454

509455
Length = wcslen(Buffer) + 1;
510456

511-
InstanceId = (LPWSTR)AllocateItem(PagedPool, Length * sizeof(WCHAR));
457+
InstanceId = ExAllocatePoolWithTag(PagedPool, Length * sizeof(WCHAR), USB_STOR_TAG);
512458
if (!InstanceId)
513459
{
514460
Irp->IoStatus.Information = 0;
@@ -542,7 +488,7 @@ USBSTOR_PdoHandleDeviceRelations(
542488
return Irp->IoStatus.Status;
543489
}
544490

545-
DeviceRelations = (PDEVICE_RELATIONS)AllocateItem(PagedPool, sizeof(DEVICE_RELATIONS));
491+
DeviceRelations = ExAllocatePoolWithTag(PagedPool, sizeof(DEVICE_RELATIONS), USB_STOR_TAG);
546492
if (!DeviceRelations)
547493
{
548494
return STATUS_INSUFFICIENT_RESOURCES;
@@ -953,13 +899,9 @@ USBSTOR_CreatePDO(
953899
return Status;
954900
}
955901

956-
if (PDODeviceExtension->InquiryData->DeviceType == DIRECT_ACCESS_DEVICE || PDODeviceExtension->InquiryData->DeviceType == READ_ONLY_DIRECT_ACCESS_DEVICE)
957-
{
958-
PDODeviceExtension->IsFloppy = FALSE; // TODO: implement the actual check
959-
}
960-
else
902+
if (PDODeviceExtension->InquiryData->DeviceType != DIRECT_ACCESS_DEVICE &&
903+
PDODeviceExtension->InquiryData->DeviceType != READ_ONLY_DIRECT_ACCESS_DEVICE)
961904
{
962-
// we work only with DIRECT_ACCESS_DEVICE for now
963905
return STATUS_NOT_SUPPORTED;
964906
}
965907

drivers/usb/usbstor/scsi.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ USBSTOR_CSWCompletionRoutine(
137137
PPDO_DEVICE_EXTENSION PDODeviceExtension;
138138
PFDO_DEVICE_EXTENSION FDODeviceExtension;
139139
PSCSI_REQUEST_BLOCK Request;
140-
PUFI_CAPACITY_RESPONSE Response;
141140

142141
Context = (PIRP_CONTEXT)Ctx;
143142

@@ -191,17 +190,6 @@ USBSTOR_CSWCompletionRoutine(
191190
Request->SrbStatus |= SRB_STATUS_AUTOSENSE_VALID;
192191
}
193192

194-
// read capacity needs special work
195-
if (Request->Cdb[0] == SCSIOP_READ_CAPACITY)
196-
{
197-
// get output buffer
198-
Response = (PUFI_CAPACITY_RESPONSE)Request->DataBuffer;
199-
200-
// store in pdo
201-
PDODeviceExtension->BlockLength = NTOHL(Response->BlockLength);
202-
PDODeviceExtension->LastLogicBlockAddress = NTOHL(Response->LastLogicalBlockAddress);
203-
}
204-
205193
Irp->IoStatus.Status = USBSTOR_SrbStatusToNtStatus(Request);
206194
}
207195
else if (Context->csw.Status == CSW_STATUS_COMMAND_FAILED)

0 commit comments

Comments
 (0)