@@ -59,6 +59,7 @@ const unsigned char OPEN_ZFS_GUID[] = "c20c603c-afd4-467d-bf76-c0a4c10553df";
59
59
const unsigned char LOGGER_SESSION[] = " autosession\\ zfsin_trace" ;
60
60
const std::string ETL_FILE (" \\ ZFSin.etl" );
61
61
const std::string MANIFEST_FILE (" \\ OpenZFS.man" );
62
+ #define DRIVER_SYS_FILE _T (" ZFSin.sys" )
62
63
63
64
enum manifest_install_types
64
65
{
@@ -476,6 +477,8 @@ zfs_uninstall(char *inf_path)
476
477
if (ret == 0 ) {
477
478
ret = uninstallRootDevice (inf_path);
478
479
perf_counters_uninstall (inf_path);
480
+ DeleteOemInf (inf_path);
481
+ DeleteSysFile (DRIVER_SYS_FILE);
479
482
}
480
483
481
484
return (ret);
@@ -895,3 +898,102 @@ uninstallRootDevice(char *inf)
895
898
return (failcode);
896
899
}
897
900
#endif
901
+
902
+ DWORD
903
+ DeleteOemInf (const char * inf_name)
904
+ {
905
+ TCHAR sysDir[MAX_PATH];
906
+ DWORD error = ERROR_SUCCESS;
907
+
908
+ if (!GetSystemDirectory (sysDir, MAX_PATH))
909
+ return GetLastError ();
910
+
911
+ std::wstring infDir = std::wstring (sysDir).substr (0 , (int )(_tcslen (sysDir) - _tcslen (_T (" system32" ))));
912
+ infDir += _T (" inf\\ " );
913
+
914
+ TCHAR inf_nameW[MAX_PATH] = { 0 };
915
+ swprintf_s (inf_nameW, MAX_PATH, _T (" %S" ), inf_name);
916
+
917
+ std::wstring mFullFileName ;
918
+ TCHAR full[MAX_PATH];
919
+ if (_tfullpath (full, inf_nameW, MAX_PATH))
920
+ mFullFileName = full;
921
+ else
922
+ mFullFileName = inf_nameW;
923
+
924
+ // Check for existence.
925
+ if ((_taccess (mFullFileName .c_str (), 0 )) == -1 )
926
+ return (errno);
927
+
928
+ std::wstring oemName = infDir;
929
+ oemName += _T (" oem*" );
930
+ oemName += _T (" .inf" );
931
+
932
+ HANDLE hFile;
933
+ WIN32_FIND_DATA findFileData;
934
+ TCHAR szDriverFileName[MAX_PATH] = DRIVER_SYS_FILE;
935
+
936
+ if (INVALID_HANDLE_VALUE == (hFile = FindFirstFile (oemName.c_str (), &findFileData)))
937
+ return ERROR_SUCCESS;
938
+
939
+ do
940
+ {
941
+ // open each of inf file and search for the .sys file
942
+ // under the section [SourceDisksFiles]
943
+ TCHAR szValue[MAX_PATH];
944
+ std::wstring oemFile;
945
+ oemName = infDir + findFileData.cFileName ;
946
+
947
+ if (0 < GetPrivateProfileString (
948
+ _T (" SourceDisksFiles" ), // section name
949
+ szDriverFileName, // lpKeyName
950
+ NULL ,
951
+ szValue, // lpReturnedString
952
+ MAX_PATH,
953
+ oemName.c_str ())) // lpFileName
954
+ {
955
+ BOOL success = SetupUninstallOEMInf (findFileData.cFileName , SUOI_FORCEDELETE, NULL );
956
+ if (!success)
957
+ {
958
+ error = GetLastError ();
959
+ std::wcout << " \n Failed to delete the driver package from Driver Store.oemfile:" << findFileData.cFileName << " ,error:" << error << std::endl;
960
+ }
961
+ else
962
+ std::wcout << " \n Successfully deleted the driver package from Driver Store.oemfile:" << findFileData.cFileName << std::endl;
963
+ }
964
+ } while (FindNextFile (hFile, &findFileData));
965
+
966
+ FindClose (hFile);
967
+ return (error);
968
+ }
969
+
970
+ DWORD
971
+ DeleteSysFile (const TCHAR* sysFile)
972
+ {
973
+ DWORD error = ERROR_SUCCESS;
974
+ TCHAR sysDir[MAX_PATH];
975
+
976
+ if (!GetSystemDirectory (sysDir, MAX_PATH))
977
+ return GetLastError ();
978
+
979
+ std::wstring fullPathName = sysDir;
980
+ fullPathName += _T (" \\ drivers\\ " );
981
+ fullPathName += sysFile;
982
+
983
+ // Check for existence.
984
+ if ((_taccess (fullPathName.c_str (), 0 )) == -1 )
985
+ return (errno);
986
+
987
+ // The delete may be unsuccessful if
988
+ // 1.File has already been deleted.
989
+ // 2.File has an open handle
990
+ if (!DeleteFile (fullPathName.c_str ()))
991
+ {
992
+ error = GetLastError ();
993
+ std::wcout << " Failed to delete the driver file:" << fullPathName.c_str () << " ,error:" << error << std::endl;
994
+ }
995
+ else
996
+ std::wcout << " Successfully deleted the driver file:" << fullPathName.c_str () << std::endl;
997
+
998
+ return (error);
999
+ }
0 commit comments