]> xenbits.xensource.com Git - pvdrivers/win/xenbus.git/commitdiff
Move friendly name setting into driver
authorPaul Durrant <paul.durrant@citrix.com>
Wed, 22 Jul 2015 14:21:54 +0000 (15:21 +0100)
committerPaul Durrant <paul.durrant@citrix.com>
Wed, 22 Jul 2015 14:23:14 +0000 (15:23 +0100)
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@citrix.com>
src/coinst/coinst.c
src/xenbus/fdo.c

index 5e6f719d9bbec38f4fa85add09279ebafa0bd83a..755eb063e75e53c2cd51b8100ffe4fab22cce701 100644 (file)
@@ -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();
 
index fdb394d829e5fe11a319f5ef8f445e29609ab353..01ffdc3617cb02c80e36351ef1238ad5ec4d5a21 100644 (file)
@@ -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),