diff --git a/reactos/ntoskrnl/io/iomgr/deviface.c b/reactos/ntoskrnl/io/iomgr/deviface.c index 912a0ec895b..973053631d9 100644 --- a/reactos/ntoskrnl/io/iomgr/deviface.c +++ b/reactos/ntoskrnl/io/iomgr/deviface.c @@ -887,7 +887,7 @@ IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, ULONG StartIndex; OBJECT_ATTRIBUTES ObjectAttributes; ULONG i; - NTSTATUS Status; + NTSTATUS Status, SymLinkStatus; PEXTENDED_DEVOBJ_EXTENSION DeviceObjectExtension; ASSERT_IRQL_EQUAL(PASSIVE_LEVEL); @@ -1137,6 +1137,28 @@ IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, } RtlAppendUnicodeToString(SymbolicLinkName, L"#"); RtlAppendUnicodeStringToString(SymbolicLinkName, &GuidString); + SymbolicLinkName->Buffer[SymbolicLinkName->Length/sizeof(WCHAR)] = L'\0'; + + /* Create symbolic link */ + DPRINT("IoRegisterDeviceInterface(): creating symbolic link %wZ -> %wZ\n", SymbolicLinkName, &PdoNameInfo->Name); + SymLinkStatus = IoCreateSymbolicLink(SymbolicLinkName, &PdoNameInfo->Name); + + /* If the symbolic link already exists, return an informational success status */ + if (SymLinkStatus == STATUS_OBJECT_NAME_COLLISION) + SymLinkStatus = STATUS_OBJECT_NAME_EXISTS; + + if (!NT_SUCCESS(SymLinkStatus)) + { + DPRINT1("IoCreateSymbolicLink() failed with status 0x%08lx\n", SymLinkStatus); + ZwClose(SubKey); + ZwClose(InterfaceKey); + ZwClose(ClassKey); + ExFreePool(SubKeyName.Buffer); + ExFreePool(InterfaceKeyName.Buffer); + ExFreePool(BaseKeyName.Buffer); + ExFreePool(SymbolicLinkName->Buffer); + return SymLinkStatus; + } if (ReferenceString && ReferenceString->Length) { @@ -1147,44 +1169,23 @@ IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, /* Write symbolic link name in registry */ SymbolicLinkName->Buffer[1] = '\\'; - Status = ZwSetValueKey(SubKey, - &SymbolicLink, - 0, /* TileIndex */ - REG_SZ, - SymbolicLinkName->Buffer, - SymbolicLinkName->Length); + Status = ZwSetValueKey( + SubKey, + &SymbolicLink, + 0, /* TileIndex */ + REG_SZ, + SymbolicLinkName->Buffer, + SymbolicLinkName->Length); if (!NT_SUCCESS(Status)) { DPRINT1("ZwSetValueKey() failed with status 0x%08lx\n", Status); - ZwClose(SubKey); - ZwClose(InterfaceKey); - ZwClose(ClassKey); - ExFreePool(SubKeyName.Buffer); - ExFreePool(InterfaceKeyName.Buffer); - ExFreePool(BaseKeyName.Buffer); ExFreePool(SymbolicLinkName->Buffer); - return Status; } else { SymbolicLinkName->Buffer[1] = '?'; } - /* Create symbolic link */ - DPRINT("IoRegisterDeviceInterface(): creating symbolic link %wZ -> %wZ\n", SymbolicLinkName, &PdoNameInfo->Name); - Status = IoCreateSymbolicLink(SymbolicLinkName, &PdoNameInfo->Name); - - /* If the symbolic link already exists, return an informational success status */ - if (Status == STATUS_OBJECT_NAME_COLLISION) - Status = STATUS_OBJECT_NAME_EXISTS; - - /* Check if it really failed */ - if (!NT_SUCCESS(Status)) - { - DPRINT1("IoCreateSymbolicLink() failed with status 0x%08lx\n", Status); - ExFreePool(SymbolicLinkName->Buffer); - } - ZwClose(SubKey); ZwClose(InterfaceKey); ZwClose(ClassKey); @@ -1192,7 +1193,7 @@ IoRegisterDeviceInterface(IN PDEVICE_OBJECT PhysicalDeviceObject, ExFreePool(InterfaceKeyName.Buffer); ExFreePool(BaseKeyName.Buffer); - return Status; + return NT_SUCCESS(Status) ? SymLinkStatus : Status; } /*++