[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [win-pv-devel] [PATCH 3/4] Move friendly name setting into driver
XENBUS can set the friendly name directly in the device hardware key at the end of FDO creation. Signed-off-by: Paul Durrant <paul.durrant@xxxxxxxxxx> --- src/coinst/coinst.c | 152 ---------------------------------------------------- src/xenbus/fdo.c | 85 +++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 152 deletions(-) diff --git a/src/coinst/coinst.c b/src/coinst/coinst.c index 5e6f719..755eb06 100644 --- a/src/coinst/coinst.c +++ b/src/coinst/coinst.c @@ -752,76 +752,6 @@ fail1: return FALSE; } -static PTCHAR -GetProperty( - IN HDEVINFO DeviceInfoSet, - IN PSP_DEVINFO_DATA DeviceInfoData, - IN DWORD Index - ) -{ - DWORD Type; - DWORD PropertyLength; - PTCHAR Property; - HRESULT Error; - - if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet, - DeviceInfoData, - Index, - &Type, - NULL, - 0, - &PropertyLength)) { - if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) - goto fail1; - } - - if (Type != REG_SZ) { - SetLastError(ERROR_BAD_FORMAT); - goto fail2; - } - - PropertyLength += sizeof (TCHAR); - - Property = calloc(1, PropertyLength); - if (Property == NULL) - goto fail3; - - if (!SetupDiGetDeviceRegistryProperty(DeviceInfoSet, - DeviceInfoData, - Index, - NULL, - (PBYTE)Property, - PropertyLength, - NULL)) - goto fail4; - - return Property; - -fail4: - Log("fail4"); - - free(Property); - -fail3: - Log("fail3"); - -fail2: - Log("fail2"); - -fail1: - Error = GetLastError(); - - { - PTCHAR Message; - - Message = GetErrorMessage(Error); - Log("fail1 (%s)", Message); - LocalFree(Message); - } - - return NULL; -} - static BOOLEAN MatchExistingDriver( VOID @@ -1441,81 +1371,6 @@ fail1: return FALSE; } -static BOOLEAN -SetFriendlyName( - IN HDEVINFO DeviceInfoSet, - IN PSP_DEVINFO_DATA DeviceInfoData, - IN PTCHAR DeviceID - ) -{ - PTCHAR Description; - unsigned int Value; - TCHAR FriendlyName[MAX_PATH]; - DWORD FriendlyNameLength; - HRESULT Result; - HRESULT Error; - - Description = GetProperty(DeviceInfoSet, - DeviceInfoData, - SPDRP_DEVICEDESC); - if (Description == NULL) - goto fail1; - - if (sscanf_s(DeviceID, - "PCI\\VEN_5853&DEV_%x", - &Value) != 1) { - SetLastError(ERROR_BAD_FORMAT); - goto fail2; - } - - Result = StringCbPrintf(FriendlyName, - MAX_PATH, - "%s (%04X)", - Description, - Value); - if (!SUCCEEDED(Result)) - goto fail3; - - FriendlyNameLength = (DWORD)(strlen(FriendlyName) + sizeof (TCHAR)); - - if (!SetupDiSetDeviceRegistryProperty(DeviceInfoSet, - DeviceInfoData, - SPDRP_FRIENDLYNAME, - (PBYTE)FriendlyName, - FriendlyNameLength)) - goto fail4; - - Log("%s", FriendlyName); - - free(Description); - - return TRUE; - -fail4: - Log("fail4"); - -fail3: - Log("fail3"); - -fail2: - Log("fail2"); - - free(Description); - -fail1: - Error = GetLastError(); - - { - PTCHAR Message; - - Message = GetErrorMessage(Error); - Log("fail1 (%s)", Message); - LocalFree(Message); - } - - return FALSE; -} - static HRESULT DifInstallPreProcess( IN HDEVINFO DeviceInfoSet, @@ -1583,10 +1438,6 @@ DifInstallPostProcess( if (!Success) goto fail1; - Success = SetFriendlyName(DeviceInfoSet, DeviceInfoData, DeviceID); - if (!Success) - goto fail2; - NeedReboot = FALSE; (VOID) CheckStatus("XEN", &NeedReboot); @@ -1603,9 +1454,6 @@ DifInstallPostProcess( return NO_ERROR; -fail2: - Log("fail2"); - fail1: Error = GetLastError(); diff --git a/src/xenbus/fdo.c b/src/xenbus/fdo.c index fdb394d..01ffdc3 100644 --- a/src/xenbus/fdo.c +++ b/src/xenbus/fdo.c @@ -687,6 +687,89 @@ __FdoIsActive( return Fdo->Active; } +static NTSTATUS +FdoSetFriendlyName( + IN PXENBUS_FDO Fdo, + IN USHORT DeviceID + ) +{ + HANDLE SoftwareKey; + HANDLE HardwareKey; + PANSI_STRING DriverDesc; + CHAR Buffer[MAXNAMELEN]; + ANSI_STRING FriendlyName[2]; + NTSTATUS status; + + status = RegistryOpenSoftwareKey(__FdoGetPhysicalDeviceObject(Fdo), + KEY_READ, + &SoftwareKey); + if (!NT_SUCCESS(status)) + goto fail1; + + status = RegistryOpenHardwareKey(__FdoGetPhysicalDeviceObject(Fdo), + KEY_ALL_ACCESS, + &HardwareKey); + if (!NT_SUCCESS(status)) + goto fail2; + + status = RegistryQuerySzValue(SoftwareKey, + "DriverDesc", + &DriverDesc); + if (!NT_SUCCESS(status)) + goto fail3; + + status = RtlStringCbPrintfA(Buffer, + MAXNAMELEN, + "%Z (%04X)", + &DriverDesc[0], + DeviceID + ); + if (!NT_SUCCESS(status)) + goto fail4; + + RtlZeroMemory(FriendlyName, sizeof (ANSI_STRING) * 2); + RtlInitAnsiString(&FriendlyName[0], Buffer); + + status = RegistryUpdateSzValue(HardwareKey, + "FriendlyName", + FriendlyName); + if (!NT_SUCCESS(status)) + goto fail5; + + Info("%Z\n", &FriendlyName[0]); + + RegistryFreeSzValue(DriverDesc); + + RegistryCloseKey(HardwareKey); + + RegistryCloseKey(SoftwareKey); + + return STATUS_SUCCESS; + +fail5: + Error("fail5\n"); + +fail4: + Error("fail4\n"); + + RegistryFreeSzValue(DriverDesc); + +fail3: + Error("fail3\n"); + + RegistryCloseKey(HardwareKey); + +fail2: + Error("fail2\n"); + + RegistryCloseKey(SoftwareKey); + +fail1: + Error("fail1 (%08x)\n", status); + + return status; +} + #define DEFINE_FDO_GET_CONTEXT(_Interface, _Type) \ static FORCEINLINE _Type \ __FdoGet ## _Interface ## Context( \ @@ -4829,6 +4912,8 @@ done: InitializeListHead(&Dx->ListEntry); Fdo->References = 1; + (VOID) FdoSetFriendlyName(Fdo, Header.DeviceID); + Info("%p (%s) %s\n", FunctionDeviceObject, __FdoGetName(Fdo), -- 2.1.1 _______________________________________________ win-pv-devel mailing list win-pv-devel@xxxxxxxxxxxxxxxxxxxx http://lists.xenproject.org/cgi-bin/mailman/listinfo/win-pv-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |