ReactOS 0.4.16-dev-2633-g8dc9e50
atapi.c File Reference
#include "atapi.h"
Include dependency graph for atapi.c:

Go to the source code of this file.

Functions

PCSTR AtaTypeCodeToName (_In_ PATAPORT_DEVICE_EXTENSION DevExt, _In_ DEVICE_TYPE_NAME Type)
 
NTSTATUS AtaOpenRegistryKey (_Out_ PHANDLE KeyHandle, _In_ HANDLE RootKey, _In_ PUNICODE_STRING KeyName, _In_ BOOLEAN Create)
 
VOID AtaGetRegistryKey (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ UCHAR TargetId, _In_ PCWSTR KeyName, _Out_ PULONG KeyValue, _In_ ULONG DefaultValue)
 
VOID AtaSetRegistryKey (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ UCHAR TargetId, _In_ PCWSTR KeyName, _In_ ULONG KeyValue)
 
VOID AtaSetPortRegistryKey (_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ PCWSTR KeyName, _In_ ULONG KeyValue)
 
NTSTATUS NTAPI AtaDispatchCreateClose (_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
 
VOID NTAPI AtaUnload (_In_ PDRIVER_OBJECT DriverObject)
 
VOID NTAPI AtaStorageNotificationWorker (_In_ PDEVICE_OBJECT DeviceObject, _In_opt_ PVOID Context)
 
VOID NTAPI AtaStorageNotificationlDpc (_In_ PKDPC Dpc, _In_opt_ PVOID DeferredContext, _In_opt_ PVOID SystemArgument1, _In_opt_ PVOID SystemArgument2)
 
NTSTATUS AtaPnpQueryInterface (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ const GUID *Guid, _Out_ PVOID Interface, _In_ ULONG Version, _In_ ULONG Size)
 
NTSTATUS AtaPnpRepeatRequest (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp, _In_opt_ PDEVICE_CAPABILITIES DeviceCapabilities)
 
NTSTATUS AtaPnpQueryDeviceUsageNotification (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp)
 
NTSTATUS AtaPnpQueryPnpDeviceState (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp)
 
VOID AtaPnpInitializeCommonExtension (_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PDEVICE_OBJECT SelfDeviceObject, _In_ ULONG Flags)
 
NTSTATUS NTAPI AtaAddChannel (_In_ PDRIVER_OBJECT DriverObject, _In_ PDEVICE_OBJECT PhysicalDeviceObject)
 
static BOOLEAN AtaInPEMode (VOID)
 
static VOID AtaCreateIdeDirectory (VOID)
 
NTSTATUS NTAPI DriverEntry (_In_ PDRIVER_OBJECT DriverObject, _In_ PUNICODE_STRING RegistryPath)
 

Variables

UNICODE_STRING AtapDriverRegistryPath
 
BOOLEAN AtapInPEMode
 
struct {
   PCSTR   DeviceType
 
   PCSTR   GenericType
 
   PCSTR   PeripheralId
 
AtapGenericDeviceNames []
 

Function Documentation

◆ AtaAddChannel()

NTSTATUS NTAPI AtaAddChannel ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PDEVICE_OBJECT  PhysicalDeviceObject 
)

Definition at line 590 of file atapi.c.

593{
598 WCHAR DeviceNameBuffer[sizeof("\\Device\\Ide\\IdePort99999")];
599 DECLARE_PAGED_WSTRING(FdoFormat, L"\\Device\\Ide\\IdePort%lu");
600 static ULONG AtapFdoNumber = 0;
601
602 PAGED_CODE();
603
604 Status = RtlStringCbPrintfW(DeviceNameBuffer,
605 sizeof(DeviceNameBuffer),
606 FdoFormat,
607 AtapFdoNumber);
609 RtlInitUnicodeString(&DeviceName, DeviceNameBuffer);
610
612
614 sizeof(*ChanExt),
615 &DeviceName,
618 FALSE,
619 &Fdo);
620 if (!NT_SUCCESS(Status))
621 {
622 ERR("Failed to create the FDO with status 0x%lx\n", Status);
623 return Status;
624 }
625
626 ChanExt = Fdo->DeviceExtension;
627
628 RtlZeroMemory(ChanExt, sizeof(*ChanExt));
630
632 if (!ChanExt->Common.LowerDeviceObject)
633 {
634 ERR("Failed to attach the FDO\n");
636 goto Failure;
637 }
638 ChanExt->DeviceObjectNumber = AtapFdoNumber++;
639 ChanExt->Pdo = PhysicalDeviceObject;
640
641 /* DMA buffers alignment */
643 Fdo->AlignmentRequirement = max(Fdo->AlignmentRequirement, ATA_MIN_BUFFER_ALIGNMENT);
644
646
647 Fdo->Flags &= ~DO_DEVICE_INITIALIZING;
648
649 return STATUS_SUCCESS;
650
651Failure:
652 if (ChanExt->Common.LowerDeviceObject)
654
656
657 return Status;
658}
#define PAGED_CODE()
#define ATA_MIN_BUFFER_ALIGNMENT
Definition: ata_shared.h:30
VOID AtaPnpInitializeCommonExtension(_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PDEVICE_OBJECT SelfDeviceObject, _In_ ULONG Flags)
Definition: atapi.c:572
#define DO_IS_FDO
Definition: atapi.h:430
#define DECLARE_PAGED_WSTRING(v, n)
Definition: atapi.h:162
LONG NTSTATUS
Definition: precomp.h:26
#define ERR(fmt,...)
Definition: precomp.h:57
PDEVICE_OBJECT PhysicalDeviceObject
Definition: btrfs_drv.h:1157
#define FILE_DEVICE_SECURE_OPEN
Definition: cdrw_usr.h:46
#define STATUS_DEVICE_REMOVED
Definition: d3dkmdt.h:39
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define L(x)
Definition: resources.c:13
#define __FUNCTION__
Definition: types.h:116
#define INFO
Definition: debug.h:89
#define KeInitializeSpinLock(sl)
Definition: env_spec_w32.h:604
Status
Definition: gdiplustypes.h:25
#define ASSERT(a)
Definition: mode.c:44
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
PDEVICE_OBJECT NTAPI IoAttachDeviceToDeviceStack(IN PDEVICE_OBJECT SourceDevice, IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:967
NTSTATUS NTAPI IoCreateDevice(IN PDRIVER_OBJECT DriverObject, IN ULONG DeviceExtensionSize, IN PUNICODE_STRING DeviceName, IN DEVICE_TYPE DeviceType, IN ULONG DeviceCharacteristics, IN BOOLEAN Exclusive, OUT PDEVICE_OBJECT *DeviceObject)
Definition: device.c:1032
VOID NTAPI IoDetachDevice(IN PDEVICE_OBJECT TargetDevice)
Definition: device.c:1297
VOID NTAPI IoDeleteDevice(IN PDEVICE_OBJECT DeviceObject)
Definition: device.c:1252
NTSTRSAFEVAPI RtlStringCbPrintfW(_Out_writes_bytes_(cbDest) _Always_(_Post_z_) NTSTRSAFE_PWSTR pszDest, _In_ size_t cbDest, _In_ _Printf_format_string_ NTSTRSAFE_PCWSTR pszFormat,...)
Definition: ntstrsafe.h:1173
short WCHAR
Definition: pedump.c:58
#define FILE_DEVICE_CONTROLLER
Definition: winioctl.h:49
#define STATUS_SUCCESS
Definition: shellext.h:65
KSPIN_LOCK PdoListLock
Definition: atapi.h:445
PDEVICE_OBJECT Pdo
Definition: atapi.h:444
ATAPORT_COMMON_EXTENSION Common
Definition: atapi.h:440
PDEVICE_OBJECT LowerDeviceObject
Definition: atapi.h:423
ULONG AlignmentRequirement
Definition: env_spec_w32.h:420
#define max(a, b)
Definition: svc.c:63
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ PWDFDEVICE_INIT _In_opt_ PCUNICODE_STRING DeviceName
Definition: wdfdevice.h:3281
_Must_inspect_result_ _In_ PDRIVER_OBJECT DriverObject
Definition: wdfdriver.h:213
_Must_inspect_result_ _In_ WDFDEVICE Fdo
Definition: wdffdo.h:461

◆ AtaCreateIdeDirectory()

static VOID AtaCreateIdeDirectory ( VOID  )
static

Definition at line 692 of file atapi.c.

693{
697 DECLARE_PAGED_UNICODE_STRING(DirectoryName, L"\\Device\\Ide");
698
699 PAGED_CODE();
700
702 &DirectoryName,
704 NULL,
705 NULL);
706
708 if (NT_SUCCESS(Status))
709 {
710 /* We don't need a handle for a permanent object */
712 }
713 /*
714 * Ignore directory creation failures (don't report them as a driver initialization error)
715 * as the directory may have already been created by another driver.
716 * We will handle fatal errors later via IoCreateDevice() call.
717 */
718}
#define DECLARE_PAGED_UNICODE_STRING(Variable, Str)
Definition: atapi.h:155
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:36
#define NULL
Definition: types.h:112
ULONG Handle
Definition: gdb_input.c:15
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
NTSYSAPI NTSTATUS NTAPI ZwCreateDirectoryObject(_Out_ PHANDLE DirectoryHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
#define DIRECTORY_ALL_ACCESS
Definition: nt_native.h:1262
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define OBJ_PERMANENT
Definition: winternl.h:226

Referenced by DriverEntry().

◆ AtaDispatchCreateClose()

NTSTATUS NTAPI AtaDispatchCreateClose ( _In_ PDEVICE_OBJECT  DeviceObject,
_Inout_ PIRP  Irp 
)

Definition at line 274 of file atapi.c.

277{
278 PAGED_CODE();
279
280 Irp->IoStatus.Status = STATUS_SUCCESS;
282
283 return STATUS_SUCCESS;
284}
_In_ PIRP Irp
Definition: csq.h:116
#define IoCompleteRequest
Definition: irp.c:1240
#define IO_NO_INCREMENT
Definition: iotypes.h:598

Referenced by DriverEntry().

◆ AtaGetRegistryKey()

VOID AtaGetRegistryKey ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ UCHAR  TargetId,
_In_ PCWSTR  KeyName,
_Out_ PULONG  KeyValue,
_In_ ULONG  DefaultValue 
)

Definition at line 113 of file atapi.c.

119{
120 UCHAR Buffer[sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(*KeyValue)];
121 HANDLE HwKeyHandle, TargetKeyHandle;
122 UNICODE_STRING ValueName, TargetKeyName;
124 WCHAR TargetKeyBuffer[sizeof("Target99")];
127
128 PAGED_CODE();
129
130 Status = IoOpenDeviceRegistryKey(ChanExt->Pdo,
133 &HwKeyHandle);
134 if (!NT_SUCCESS(Status))
135 {
136 TRACE("Failed to open device hardware key, status 0x%lx\n", Status);
137 return;
138 }
139
140 /* Open or create the 'TargetX' key */
141 Status = RtlStringCbPrintfW(TargetKeyBuffer,
142 sizeof(TargetKeyBuffer),
143 L"Target%u",
144 TargetId);
146 RtlInitUnicodeString(&TargetKeyName, TargetKeyBuffer);
147 Status = AtaOpenRegistryKey(&TargetKeyHandle, HwKeyHandle, &TargetKeyName, TRUE);
148 if (!NT_SUCCESS(Status))
149 {
150 TRACE("Failed to create '%wZ' key, status 0x%lx\n", &TargetKeyName, Status);
151 goto Cleanup;
152 }
153
155 Status = ZwQueryValueKey(TargetKeyHandle,
156 &ValueName,
158 PartialInfo,
159 sizeof(Buffer),
160 &ResultLength);
161 ZwClose(TargetKeyHandle);
162 if (!NT_SUCCESS(Status) ||
163 (PartialInfo->Type != REG_DWORD) ||
164 (PartialInfo->DataLength != sizeof(*KeyValue)))
165 {
166 TRACE("Failed to read '%wZ' key, status 0x%lx\n", &ValueName, Status);
167
168 *KeyValue = DefaultValue;
169 goto Cleanup;
170 }
171
172 *KeyValue = *(PULONG)&PartialInfo->Data;
173
174Cleanup:
175 ZwClose(HwKeyHandle);
176}
NTSTATUS AtaOpenRegistryKey(_Out_ PHANDLE KeyHandle, _In_ HANDLE RootKey, _In_ PUNICODE_STRING KeyName, _In_ BOOLEAN Create)
Definition: atapi.c:75
Definition: bufpool.h:45
_In_ ULONG _In_ BOOLEAN _In_ ULONG _In_ UCHAR _In_ UCHAR TargetId
Definition: classpnp.h:1314
#define TRUE
Definition: types.h:120
static const WCHAR Cleanup[]
Definition: register.c:80
@ KeyValuePartialInformation
Definition: nt_native.h:1185
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
struct _KEY_VALUE_PARTIAL_INFORMATION KEY_VALUE_PARTIAL_INFORMATION
NTSTATUS NTAPI IoOpenDeviceRegistryKey(IN PDEVICE_OBJECT DeviceObject, IN ULONG DevInstKeyType, IN ACCESS_MASK DesiredAccess, OUT PHANDLE DevInstRegKey)
Definition: pnpmgr.c:1621
#define REG_DWORD
Definition: sdbapi.c:615
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char UCHAR
Definition: typedefs.h:53
void * PVOID
Definition: typedefs.h:50
UCHAR DefaultValue
Definition: via.c:137
_Must_inspect_result_ _In_ WDFDEVICE _In_ DEVICE_REGISTRY_PROPERTY _In_ ULONG _Out_ PULONG ResultLength
Definition: wdfdevice.h:3782
_Must_inspect_result_ _In_ WDFDEVICE _In_ PCUNICODE_STRING KeyName
Definition: wdfdevice.h:2705
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING ValueName
Definition: wdfregistry.h:243
#define PLUGPLAY_REGKEY_DEVICE
Definition: iofuncs.h:2786

Referenced by AtaFdoEnumeratePort(), AtaFdoQueryBusRelations(), and AtaPdoInit().

◆ AtaInPEMode()

static BOOLEAN AtaInPEMode ( VOID  )
static

Definition at line 663 of file atapi.c.

664{
669 KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\MiniNT");
670
671 PAGED_CODE();
672
674 &KeyName,
676 NULL,
677 NULL);
678
679 Status = ZwOpenKey(&KeyHandle, KEY_READ, &ObjectAttributes);
680 if (NT_SUCCESS(Status))
681 {
683 return TRUE;
684 }
685
686 return FALSE;
687}
_Must_inspect_result_ _Out_ PNDIS_STATUS _In_ NDIS_HANDLE _In_ ULONG _Out_ PNDIS_STRING _Out_ PNDIS_HANDLE KeyHandle
Definition: ndis.h:4715
#define KEY_READ
Definition: nt_native.h:1026

Referenced by DriverEntry().

◆ AtaOpenRegistryKey()

NTSTATUS AtaOpenRegistryKey ( _Out_ PHANDLE  KeyHandle,
_In_ HANDLE  RootKey,
_In_ PUNICODE_STRING  KeyName,
_In_ BOOLEAN  Create 
)

Definition at line 75 of file atapi.c.

80{
84
85 PAGED_CODE();
86
88 KeyName,
90 RootKey,
91 NULL);
92
93 if (Create)
94 {
95 Status = ZwCreateKey(KeyHandle,
98 0,
99 NULL,
101 &Disposition);
102 }
103 else
104 {
106 }
107
108 return Status;
109}
@ Create
Definition: registry.c:563
_In_ ACCESS_MASK _In_ POBJECT_ATTRIBUTES _Reserved_ ULONG _In_opt_ PUNICODE_STRING _In_ ULONG _Out_opt_ PULONG Disposition
Definition: cmfuncs.h:56
#define REG_OPTION_VOLATILE
Definition: nt_native.h:1063
static PMEMKEY RootKey
Definition: registry.c:55

Referenced by AtaGetRegistryKey(), and AtaSetRegistryKey().

◆ AtaPnpInitializeCommonExtension()

VOID AtaPnpInitializeCommonExtension ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ PDEVICE_OBJECT  SelfDeviceObject,
_In_ ULONG  Flags 
)

Definition at line 572 of file atapi.c.

576{
577 PAGED_CODE();
578
579 CommonExt->Flags = Flags;
580 CommonExt->Self = SelfDeviceObject;
581 CommonExt->DevicePowerState = PowerDeviceD0;
582 CommonExt->SystemPowerState = PowerSystemWorking;
583
584 IoInitializeRemoveLock(&CommonExt->RemoveLock, ATAPORT_TAG, 0, 0);
585}
#define ATAPORT_TAG
Definition: atapi.h:171
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerDeviceD0
Definition: ntpoapi.h:49
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define IoInitializeRemoveLock(Lock, AllocateTag, MaxLockedMinutes, HighWatermark)
Definition: iofuncs.h:2833

Referenced by AtaAddChannel(), and AtaPdoCreateDevice().

◆ AtaPnpQueryDeviceUsageNotification()

NTSTATUS AtaPnpQueryDeviceUsageNotification ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ PIRP  Irp 
)

Definition at line 503 of file atapi.c.

506{
507 PIO_STACK_LOCATION IoStack;
509 volatile LONG* Counter;
510
511 PAGED_CODE();
512
513 if (!IS_FDO(CommonExt))
514 {
515 Status = AtaPnpRepeatRequest(CommonExt, Irp, NULL);
516 }
517 else
518 {
519 if (!NT_VERIFY(IoForwardIrpSynchronously(CommonExt->LowerDeviceObject, Irp)))
520 return STATUS_UNSUCCESSFUL;
521 Status = Irp->IoStatus.Status;
522 }
523 if (!NT_SUCCESS(Status))
524 return Status;
525
527 switch (IoStack->Parameters.UsageNotification.Type)
528 {
530 Counter = &CommonExt->PageFiles;
531 break;
532
534 Counter = &CommonExt->HibernateFiles;
535 break;
536
538 Counter = &CommonExt->DumpFiles;
539 break;
540
541 default:
542 return Status;
543 }
544
546
547 if (!IS_FDO(CommonExt))
548 IoInvalidateDeviceState(CommonExt->Self);
549
550 return STATUS_SUCCESS;
551}
static PIO_STACK_LOCATION IoGetCurrentIrpStackLocation(PIRP Irp)
NTSTATUS AtaPnpRepeatRequest(_In_ PATAPORT_COMMON_EXTENSION CommonExt, _In_ PIRP Irp, _In_opt_ PDEVICE_CAPABILITIES DeviceCapabilities)
Definition: atapi.c:445
#define IS_FDO(p)
Definition: atapi.h:173
BOOLEAN NTAPI IoForwardIrpSynchronously(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp)
Definition: irp.c:1625
long LONG
Definition: pedump.c:60
VOID NTAPI IoInvalidateDeviceState(IN PDEVICE_OBJECT DeviceObject)
Definition: pnpmgr.c:1848
union _IO_STACK_LOCATION::@1696 Parameters
struct _IO_STACK_LOCATION::@4366::@4399 UsageNotification
static LARGE_INTEGER Counter
Definition: clock.c:43
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define IoAdjustPagingPathCount(_Count, _Increment)
@ DeviceUsageTypeHibernation
Definition: iotypes.h:1171
@ DeviceUsageTypeDumpFile
Definition: iotypes.h:1172
@ DeviceUsageTypePaging
Definition: iotypes.h:1170
#define NT_VERIFY(exp)
Definition: rtlfuncs.h:3304

Referenced by AtaFdoPnp(), and AtaPdoPnp().

◆ AtaPnpQueryInterface()

NTSTATUS AtaPnpQueryInterface ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ const GUID Guid,
_Out_ PVOID  Interface,
_In_ ULONG  Version,
_In_ ULONG  Size 
)

Definition at line 396 of file atapi.c.

402{
404 PIRP Irp;
406 PIO_STACK_LOCATION IoStack;
408
409 PAGED_CODE();
410
412
414 CommonExt->LowerDeviceObject,
415 NULL,
416 0,
417 NULL,
418 &Event,
420 if (!Irp)
422
423 Irp->IoStatus.Status = STATUS_NOT_SUPPORTED;
424
427 IoStack->Parameters.QueryInterface.InterfaceType = Guid;
428 IoStack->Parameters.QueryInterface.Size = Size;
429 IoStack->Parameters.QueryInterface.Version = Version;
430 IoStack->Parameters.QueryInterface.Interface = Interface;
431 IoStack->Parameters.QueryInterface.InterfaceSpecificData = NULL;
432
433 Status = IoCallDriver(CommonExt->LowerDeviceObject, Irp);
434 if (Status == STATUS_PENDING)
435 {
438 }
439
440 return Status;
441}
#define IRP_MJ_PNP
Definition: cdrw_usr.h:52
#define STATUS_NOT_SUPPORTED
Definition: d3dkmdt.h:48
#define KeWaitForSingleObject(pEvt, foo, a, b, c)
Definition: env_spec_w32.h:478
#define KeInitializeEvent(pEvt, foo, foo2)
Definition: env_spec_w32.h:477
#define KernelMode
Definition: asm.h:38
@ NotificationEvent
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
PIRP NTAPI IoBuildSynchronousFsdRequest(IN ULONG MajorFunction, IN PDEVICE_OBJECT DeviceObject, IN PVOID Buffer, IN ULONG Length, IN PLARGE_INTEGER StartingOffset, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:1069
#define IoCallDriver
Definition: irp.c:1225
struct _IO_STACK_LOCATION::@4366::@4392 QueryInterface
#define STATUS_PENDING
Definition: telnetd.h:14
#define STATUS_INSUFFICIENT_RESOURCES
Definition: udferr_usr.h:158
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4539
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE Interface
Definition: wdffdo.h:465
_Must_inspect_result_ _In_ WDFDEVICE _In_ LPCGUID _Out_ PINTERFACE _In_ USHORT _In_ USHORT Version
Definition: wdffdo.h:469
_Must_inspect_result_ _In_ WDFOBJECT _In_ CONST GUID * Guid
Definition: wdfobject.h:762
__drv_aliasesMem FORCEINLINE PIO_STACK_LOCATION IoGetNextIrpStackLocation(_In_ PIRP Irp)
Definition: iofuncs.h:2695
#define IRP_MN_QUERY_INTERFACE
@ Executive
Definition: ketypes.h:467

Referenced by AtaFdoStartDevice().

◆ AtaPnpQueryPnpDeviceState()

NTSTATUS AtaPnpQueryPnpDeviceState ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ PIRP  Irp 
)

Definition at line 555 of file atapi.c.

558{
559 PAGED_CODE();
560
561 if (CommonExt->PageFiles || CommonExt->HibernateFiles || CommonExt->DumpFiles)
562 Irp->IoStatus.Information |= PNP_DEVICE_NOT_DISABLEABLE;
563
564 if (IS_FDO(CommonExt))
565 Irp->IoStatus.Status = STATUS_SUCCESS;
566
567 return STATUS_SUCCESS;
568}
#define PNP_DEVICE_NOT_DISABLEABLE
Definition: iotypes.h:1006

Referenced by AtaFdoPnp(), and AtaPdoPnp().

◆ AtaPnpRepeatRequest()

NTSTATUS AtaPnpRepeatRequest ( _In_ PATAPORT_COMMON_EXTENSION  CommonExt,
_In_ PIRP  Irp,
_In_opt_ PDEVICE_CAPABILITIES  DeviceCapabilities 
)

Definition at line 445 of file atapi.c.

449{
450 PATAPORT_COMMON_EXTENSION FdoExt = CommonExt->FdoExt;
451 PDEVICE_OBJECT TopDeviceObject;
452 PIO_STACK_LOCATION IoStack, SubStack;
453 PIRP SubIrp;
456
457 PAGED_CODE();
458 ASSERT(!IS_FDO(CommonExt));
459
460 TopDeviceObject = IoGetAttachedDeviceReference(FdoExt->Self);
461
462 SubIrp = IoAllocateIrp(TopDeviceObject->StackSize, FALSE);
463 if (!SubIrp)
464 {
465 ObDereferenceObject(TopDeviceObject);
467 }
468
470
472 SubStack = IoGetNextIrpStackLocation(SubIrp);
473 RtlCopyMemory(SubStack, IoStack, sizeof(*SubStack));
474
476 SubStack->Parameters.DeviceCapabilities.Capabilities = DeviceCapabilities;
477
480 &Event,
481 TRUE,
482 TRUE,
483 TRUE);
484
486
487 Status = IoCallDriver(TopDeviceObject, SubIrp);
488 if (Status == STATUS_PENDING)
489 {
491 }
492
493 ObDereferenceObject(TopDeviceObject);
494
495 Status = SubIrp->IoStatus.Status;
496 IoFreeIrp(SubIrp);
497
498 return Status;
499}
IO_COMPLETION_ROUTINE AtaPdoCompletionRoutine
Definition: atapi.h:859
#define IoSetCompletionRoutine(_Irp, _CompletionRoutine, _Context, _InvokeOnSuccess, _InvokeOnError, _InvokeOnCancel)
Definition: irp.cpp:490
_In_ PIOMMU_DEVICE_PATH _In_ PIOMMU_SVM_CAPABILITIES DeviceCapabilities
Definition: haltypes.h:1824
PDEVICE_OBJECT NTAPI IoGetAttachedDeviceReference(PDEVICE_OBJECT DeviceObject)
Definition: device.c:1407
PIRP NTAPI IoAllocateIrp(IN CCHAR StackSize, IN BOOLEAN ChargeQuota)
Definition: irp.c:615
VOID NTAPI IoFreeIrp(IN PIRP Irp)
Definition: irp.c:1666
PDEVICE_OBJECT Self
Definition: atapi.h:432
struct _IO_STACK_LOCATION::@4366::@4393 DeviceCapabilities
IO_STATUS_BLOCK IoStatus
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
#define DeviceCapabilities
Definition: wingdi.h:4895
#define ObDereferenceObject
Definition: obfuncs.h:203

Referenced by AtaPdoQueryCapabilities(), and AtaPnpQueryDeviceUsageNotification().

◆ AtaSetPortRegistryKey()

VOID AtaSetPortRegistryKey ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ PCWSTR  KeyName,
_In_ ULONG  KeyValue 
)

Definition at line 236 of file atapi.c.

240{
241 HANDLE HwKeyHandle;
244
245 PAGED_CODE();
246
247 Status = IoOpenDeviceRegistryKey(ChanExt->Pdo,
250 &HwKeyHandle);
251 if (!NT_SUCCESS(Status))
252 {
253 TRACE("Failed to open device hardware key, status 0x%lx\n", Status);
254 return;
255 }
256
258 Status = ZwSetValueKey(HwKeyHandle,
259 &ValueName,
260 0,
261 REG_DWORD,
262 &KeyValue,
263 sizeof(KeyValue));
264 ZwClose(HwKeyHandle);
265 if (!NT_SUCCESS(Status))
266 {
267 TRACE("Failed to set '%wZ' key, status 0x%lx\n", &ValueName, Status);
268 }
269}

Referenced by AtaFdoStartDevice().

◆ AtaSetRegistryKey()

VOID AtaSetRegistryKey ( _In_ PATAPORT_CHANNEL_EXTENSION  ChanExt,
_In_ UCHAR  TargetId,
_In_ PCWSTR  KeyName,
_In_ ULONG  KeyValue 
)

Definition at line 180 of file atapi.c.

185{
186 HANDLE HwKeyHandle, TargetKeyHandle;
187 UNICODE_STRING ValueName, TargetKeyName;
189 WCHAR TargetKeyBuffer[sizeof("Target99")];
190
191 PAGED_CODE();
192
193 Status = IoOpenDeviceRegistryKey(ChanExt->Pdo,
196 &HwKeyHandle);
197 if (!NT_SUCCESS(Status))
198 {
199 TRACE("Failed to open device hardware key, status 0x%lx\n", Status);
200 return;
201 }
202
203 /* Open or create the 'TargetX' key */
204 Status = RtlStringCbPrintfW(TargetKeyBuffer,
205 sizeof(TargetKeyBuffer),
206 L"Target%u",
207 TargetId);
209 RtlInitUnicodeString(&TargetKeyName, TargetKeyBuffer);
210 Status = AtaOpenRegistryKey(&TargetKeyHandle, HwKeyHandle, &TargetKeyName, TRUE);
211 if (!NT_SUCCESS(Status))
212 {
213 TRACE("Failed to create '%wZ' key, status 0x%lx\n", &TargetKeyName, Status);
214 goto Cleanup;
215 }
216
218 Status = ZwSetValueKey(TargetKeyHandle,
219 &ValueName,
220 0,
221 REG_DWORD,
222 &KeyValue,
223 sizeof(KeyValue));
224 ZwClose(TargetKeyHandle);
225 if (!NT_SUCCESS(Status))
226 {
227 TRACE("Failed to set '%wZ' key, status 0x%lx\n", &ValueName, Status);
228 }
229
230Cleanup:
231 ZwClose(HwKeyHandle);
232}

Referenced by AtaFdoInitializeDeviceRelations(), and AtaPdoInit().

◆ AtaStorageNotificationlDpc()

VOID NTAPI AtaStorageNotificationlDpc ( _In_ PKDPC  Dpc,
_In_opt_ PVOID  DeferredContext,
_In_opt_ PVOID  SystemArgument1,
_In_opt_ PVOID  SystemArgument2 
)

Definition at line 350 of file atapi.c.

355{
357 ULONG DeviceBitmap = PtrToUlong(SystemArgument1);
359 ULONG i;
360
363
364 ChanExt = CONTAINING_RECORD(PortData, ATAPORT_CHANNEL_EXTENSION, PortData);
365
366 for (i = 0; i < ATA_MAX_DEVICE; ++i)
367 {
370
371 if (!(DeviceBitmap & (1 << i)))
372 continue;
373
374 DevExt = AtaFdoFindDeviceByPath(ChanExt,
375 AtaMarshallScsiAddress(PortData->PortNumber, i, 0),
377 if (!DevExt)
378 continue;
379
381 if (!WorkItem)
382 {
383 ERR("Failed to allocate workitem");
384 }
385 else
386 {
388 }
389
391 }
392}
#define ATA_MAX_DEVICE
Definition: ata_shared.h:15
KDEFERRED_ROUTINE AtaStorageNotificationlDpc
Definition: atapi.h:655
FORCEINLINE ATA_SCSI_ADDRESS AtaMarshallScsiAddress(_In_ ULONG PathId, _In_ ULONG TargetId, _In_ ULONG Lun)
Definition: atapi.h:585
DECLSPEC_NOINLINE_FROM_PAGED PATAPORT_DEVICE_EXTENSION AtaFdoFindDeviceByPath(_In_ PATAPORT_CHANNEL_EXTENSION ChanExt, _In_ ATA_SCSI_ADDRESS AtaScsiAddress, _In_ PVOID ReferenceTag)
Definition: fdo.c:614
IO_WORKITEM_ROUTINE AtaStorageNotificationWorker
Definition: atapi.h:654
#define PtrToUlong(u)
Definition: config.h:107
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
VOID NTAPI IoQueueWorkItem(IN PIO_WORKITEM IoWorkItem, IN PIO_WORKITEM_ROUTINE WorkerRoutine, IN WORK_QUEUE_TYPE QueueType, IN PVOID Context)
Definition: iowork.c:40
PIO_WORKITEM NTAPI IoAllocateWorkItem(IN PDEVICE_OBJECT DeviceObject)
Definition: iowork.c:75
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:329
IO_REMOVE_LOCK RemoveLock
Definition: atapi.h:434
ATAPORT_COMMON_EXTENSION Common
Definition: atapi.h:455
ULONG PortNumber
Definition: atapi.h:396
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260
_Must_inspect_result_ _In_ PWDF_DPC_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFDPC * Dpc
Definition: wdfdpc.h:112
_Must_inspect_result_ _In_ PWDF_WORKITEM_CONFIG _In_ PWDF_OBJECT_ATTRIBUTES _Out_ WDFWORKITEM * WorkItem
Definition: wdfworkitem.h:115
@ CriticalWorkQueue
Definition: extypes.h:189
#define IoReleaseRemoveLock(_RemoveLock, _Tag)
Definition: iofuncs.h:2764
_In_opt_ PVOID _In_opt_ PVOID SystemArgument1
Definition: ketypes.h:740
_In_opt_ PVOID DeferredContext
Definition: ketypes.h:739
_In_opt_ PVOID _In_opt_ PVOID _In_opt_ PVOID SystemArgument2
Definition: ketypes.h:741

◆ AtaStorageNotificationWorker()

VOID NTAPI AtaStorageNotificationWorker ( _In_ PDEVICE_OBJECT  DeviceObject,
_In_opt_ PVOID  Context 
)

Definition at line 299 of file atapi.c.

302{
304 PDEVICE_OBJECT TopDeviceObject;
305 PIRP Irp;
308 STORAGE_EVENT_NOTIFICATION EventObject;
310
312
314
316 EventObject.Size = sizeof(EventObject);
317 EventObject.Events = STORAGE_EVENT_ALL;
318
320 TopDeviceObject,
321 &EventObject,
322 sizeof(EventObject),
323 NULL,
324 0,
325 FALSE,
326 &Event,
327 &IoStatus);
328 if (!Irp)
329 {
330 ERR("IoBuildDeviceIoControlRequest() failed\n");
331 goto Exit;
332 }
333
335 if (Status == STATUS_PENDING)
336 {
338 Status = IoStatus.Status;
339 }
340
341 TRACE("Notification result %08lx\n", Status);
342
343Exit:
344 ObDereferenceObject(TopDeviceObject);
346}
VOID NTAPI IoFreeWorkItem(IN PIO_WORKITEM IoWorkItem)
Definition: iowork.c:64
__in UCHAR __in POWER_STATE __in_opt PVOID __in PIO_STATUS_BLOCK IoStatus
Definition: mxum.h:159
PIRP NTAPI IoBuildDeviceIoControlRequest(IN ULONG IoControlCode, IN PDEVICE_OBJECT DeviceObject, IN PVOID InputBuffer, IN ULONG InputBufferLength, IN PVOID OutputBuffer, IN ULONG OutputBufferLength, IN BOOLEAN InternalDeviceIoControl, IN PKEVENT Event, IN PIO_STATUS_BLOCK IoStatusBlock)
Definition: irp.c:881
#define STORAGE_EVENT_NOTIFICATION_VERSION_V1
Definition: ntddstor.h:979
#define IOCTL_STORAGE_EVENT_NOTIFICATION
Definition: ntddstor.h:226
#define STORAGE_EVENT_ALL
Definition: ntddstor.h:984
static void Exit(void)
Definition: sock.c:1330
_In_ PVOID Context
Definition: storport.h:2269
_In_ PDEVICE_OBJECT DeviceObject
Definition: wdfdevice.h:2061
@ Suspended
Definition: ketypes.h:472

◆ AtaTypeCodeToName()

PCSTR AtaTypeCodeToName ( _In_ PATAPORT_DEVICE_EXTENSION  DevExt,
_In_ DEVICE_TYPE_NAME  Type 
)

Definition at line 42 of file atapi.c.

45{
47
48 PAGED_CODE();
49
50 DeviceType = DevExt->InquiryData.DeviceType;
52
53 switch (Type)
54 {
55 case GetDeviceType:
56 return AtapGenericDeviceNames[DeviceType].DeviceType;
57
58 case GetPeripheralId:
59 return AtapGenericDeviceNames[DeviceType].PeripheralId;
60
61 case GetGenericType:
62 if (DevExt->Device.DeviceFlags & DEVICE_IS_SUPER_FLOPPY)
63 return "GenSFloppy"; // Install the Super Floppy storage class driver
64 else
65 return AtapGenericDeviceNames[DeviceType].GenericType;
66
67 default:
70 }
71}
#define RTL_NUMBER_OF(x)
Definition: RtlRegistry.c:12
Type
Definition: Type.h:7
PCSTR DeviceType
Definition: atapi.c:20
static ATAPORT_PAGED_DATA const struct @1160 AtapGenericDeviceNames[]
#define DEVICE_IS_SUPER_FLOPPY
Definition: atapi.h:89
@ GetGenericType
Definition: atapi.h:567
@ GetPeripheralId
Definition: atapi.h:568
@ GetDeviceType
Definition: atapi.h:566
DeviceType
Definition: mmdrv.h:42
#define min(a, b)
Definition: monoChain.cc:55
#define UNREACHABLE

Referenced by AtaPdoQueryId().

◆ AtaUnload()

VOID NTAPI AtaUnload ( _In_ PDRIVER_OBJECT  DriverObject)

Definition at line 289 of file atapi.c.

291{
292 PAGED_CODE();
293
295}
UNICODE_STRING AtapDriverRegistryPath
Definition: atapi.c:14
NTSYSAPI VOID NTAPI RtlFreeUnicodeString(PUNICODE_STRING UnicodeString)

◆ DriverEntry()

NTSTATUS NTAPI DriverEntry ( _In_ PDRIVER_OBJECT  DriverObject,
_In_ PUNICODE_STRING  RegistryPath 
)

Definition at line 723 of file atapi.c.

726{
727 INFO("ATAPI driver entry\n");
728
729 // FIXME: No crashdump/hibernation support
730 if (!DriverObject)
732
733 /* Make a copy of the registry path */
740 {
742 }
745
749 DriverObject->MajorFunction[IRP_MJ_SCSI] = AtaDispatchScsi;
752 DriverObject->MajorFunction[IRP_MJ_PNP] = AtaDispatchPnp;
753 DriverObject->DriverExtension->AddDevice = AtaAddChannel;
754 DriverObject->DriverUnload = AtaUnload;
755
758
759 /* Create a directory to hold the driver's device objects */
761
763
764 return STATUS_SUCCESS;
765}
#define ExAllocatePoolUninitialized
BOOLEAN AtapInPEMode
Definition: atapi.c:15
NTSTATUS NTAPI AtaDispatchCreateClose(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: atapi.c:274
static BOOLEAN AtaInPEMode(VOID)
Definition: atapi.c:663
static VOID AtaCreateIdeDirectory(VOID)
Definition: atapi.c:692
SLIST_HEADER AtapCompletionQueueList
Definition: scsi.c:14
KDEFERRED_ROUTINE AtaReqCompletionDpc
Definition: atapi.h:939
DRIVER_UNLOAD AtaUnload
Definition: atapi.h:649
DRIVER_ADD_DEVICE AtaAddChannel
Definition: atapi.h:646
KDPC AtapCompletionDpc
Definition: scsi.c:15
#define STATUS_NOT_IMPLEMENTED
Definition: d3dkmdt.h:42
NTSTATUS NTAPI AtaDispatchPower(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: dev_power.c:523
VOID NTAPI KeInitializeDpc(IN PKDPC Dpc, IN PKDEFERRED_ROUTINE DeferredRoutine, IN PVOID DeferredContext)
Definition: dpc.c:712
NTSTATUS NTAPI AtaDispatchDeviceControl(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: ioctl.c:932
NTSTATUS NTAPI AtaDispatchWmi(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: wmi.c:175
#define NonPagedPool
Definition: env_spec_w32.h:307
NTSYSAPI VOID NTAPI RtlCopyUnicodeString(PUNICODE_STRING DestinationString, PUNICODE_STRING SourceString)
#define UNICODE_NULL
#define IRP_MJ_CLOSE
Definition: rdpdr.c:45
#define IRP_MJ_DEVICE_CONTROL
Definition: rdpdr.c:52
#define IRP_MJ_CREATE
Definition: rdpdr.c:44
NTSTATUS NTAPI AtaDispatchPnp(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: pdo.c:644
NTSTATUS NTAPI AtaDispatchScsi(_In_ PDEVICE_OBJECT DeviceObject, _Inout_ PIRP Irp)
Definition: scsi.c:1771
USHORT MaximumLength
Definition: env_spec_w32.h:370
_Must_inspect_result_ _In_ PDRIVER_OBJECT _In_ PCUNICODE_STRING RegistryPath
Definition: wdfdriver.h:215
#define IRP_MJ_SCSI
#define IRP_MJ_SYSTEM_CONTROL
#define IRP_MJ_POWER
FORCEINLINE VOID InitializeSListHead(_Out_ PSLIST_HEADER SListHead)
Definition: rtlfuncs.h:3368

Variable Documentation

◆ AtapDriverRegistryPath

UNICODE_STRING AtapDriverRegistryPath

Definition at line 14 of file atapi.c.

Referenced by AtaQueryWmiRegInfo(), AtaUnload(), and DriverEntry().

◆ 

ATAPORT_PAGED_DATA const struct { ... } AtapGenericDeviceNames[]
Initial value:
=
{
{"Disk", "GenDisk", "DiskPeripheral" },
{"Sequential", "GenSequential", "TapePeripheral" },
{"Printer", "GenPrinter", "PrinterPeripheral" },
{"Processor", "GenProcessor", "ProcessorPeripheral" },
{"Worm", "GenWorm", "WormPeripheral" },
{"CdRom", "GenCdRom", "CdRomPeripheral" },
{"Scanner", "GenScanner", "ScannerPeripheral" },
{"Optical", "GenOptical", "OpticalDiskPeripheral" },
{"Changer", "GenChanger", "MediumChangerPeripheral" },
{"Net", "GenNet", "CommunicationsPeripheral"},
{"Other", "IdeOther", "OtherPeripheral" },
}

Referenced by AtaTypeCodeToName().

◆ AtapInPEMode

BOOLEAN AtapInPEMode

Definition at line 15 of file atapi.c.

Referenced by AtaDeviceLockSecurityModeFeatureCommands(), and DriverEntry().

◆ DeviceType

Definition at line 20 of file atapi.c.

Referenced by AtaTypeCodeToName().

◆ GenericType

PCSTR GenericType

◆ PeripheralId

PCSTR PeripheralId

Definition at line 22 of file atapi.c.