From d4007a884e4a2e086ab914759495753769974aac Mon Sep 17 00:00:00 2001 From: Shashank Kumar <75466339+datacore-skumar@users.noreply.github.com> Date: Thu, 24 Feb 2022 20:04:07 +0530 Subject: [PATCH] Duplicates ZFSin controller in device manager --- cmd/os/windows/zfsinstaller/zfsinstaller.cpp | 28 +++++++++++++------- cmd/os/windows/zfsinstaller/zfsinstaller.h | 2 +- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/cmd/os/windows/zfsinstaller/zfsinstaller.cpp b/cmd/os/windows/zfsinstaller/zfsinstaller.cpp index 149dcf1ef025..56d659aa492e 100644 --- a/cmd/os/windows/zfsinstaller/zfsinstaller.cpp +++ b/cmd/os/windows/zfsinstaller/zfsinstaller.cpp @@ -424,6 +424,7 @@ printUsage() { DWORD zfs_install(char *inf_path) { DWORD error = 0; + bool IsServiceRunning = false; // 128+4 If a reboot of the computer is necessary, // ask the user for permission before rebooting. @@ -445,8 +446,13 @@ DWORD zfs_install(char *inf_path) { fprintf(stderr, "Installation failed, skip " "starting the service\r\n"); - if (!error) - error = installRootDevice(inf_path); + if (error == ERROR_SERVICE_ALREADY_RUNNING) { + IsServiceRunning = true; + error = 0; + } + + if(!error) + error = installRootDevice(inf_path, IsServiceRunning); if (!error) perf_counters_install(inf_path); @@ -580,6 +586,7 @@ startService(char *serviceName) if (!StartServiceA(zfsServHdl, NULL, NULL)) { if (GetLastError() == ERROR_SERVICE_ALREADY_RUNNING) { fprintf(stderr, "Service is already running\n"); + error = GetLastError(); } else { fprintf(stderr, "StartServiceA failed, error %d\n", GetLastError()); @@ -679,7 +686,7 @@ openDeviceInfo(char *inf, GUID *ClassGUID, char *ClassName, int namemax) DWORD -installRootDevice(char *inf) +installRootDevice(char *inf, bool IsServiceRunning) { HDEVINFO DeviceInfoSet = INVALID_HANDLE_VALUE; SP_DEVINFO_DATA DeviceInfoData; @@ -721,12 +728,15 @@ installRootDevice(char *inf) goto final; } - // Transform the registry element into an actual devnode - // in the PnP HW tree. - if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, - DeviceInfoSet, - &DeviceInfoData)) { - goto final; + // If service is running. + if (!IsServiceRunning) { + //Transform the registry element into an actual devnode + //in the PnP HW tree. + if (!SetupDiCallClassInstaller(DIF_REGISTERDEVICE, + DeviceInfoSet, + &DeviceInfoData)) { + goto final; + } } failcode = 0; diff --git a/cmd/os/windows/zfsinstaller/zfsinstaller.h b/cmd/os/windows/zfsinstaller/zfsinstaller.h index a7ed59791d85..32cf930606d1 100644 --- a/cmd/os/windows/zfsinstaller/zfsinstaller.h +++ b/cmd/os/windows/zfsinstaller/zfsinstaller.h @@ -35,5 +35,5 @@ DWORD executeInfSection(const char *, char *); DWORD startService(char *); void printUsage(); DWORD send_zfs_ioc_unregister_fs(); -DWORD installRootDevice(char *inf_path); +DWORD installRootDevice(char *inf_path, bool IsServiceRunning); DWORD uninstallRootDevice(char *inf_path);