Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

347 lines
7.9 KiB

  1. //
  2. // Microsoft Windows Media Technologies
  3. // � 1999 Microsoft Corporation. All rights reserved.
  4. //
  5. // Refer to your End User License Agreement for details on your rights/restrictions to use these sample files.
  6. //
  7. // MSHDSP.DLL is a sample WMDM Service Provider(SP) that enumerates fixed drives.
  8. // This sample shows you how to implement an SP according to the WMDM documentation.
  9. // This sample uses fixed drives on your PC to emulate portable media, and
  10. // shows the relationship between different interfaces and objects. Each hard disk
  11. // volume is enumerated as a device and directories and files are enumerated as
  12. // Storage objects under respective devices. You can copy non-SDMI compliant content
  13. // to any device that this SP enumerates. To copy an SDMI compliant content to a
  14. // device, the device must be able to report a hardware embedded serial number.
  15. // Hard disks do not have such serial numbers.
  16. //
  17. // To build this SP, you are recommended to use the MSHDSP.DSP file under Microsoft
  18. // Visual C++ 6.0 and run REGSVR32.EXE to register the resulting MSHDSP.DLL. You can
  19. // then build the sample application from the WMDMAPP directory to see how it gets
  20. // loaded by the application. However, you need to obtain a certificate from
  21. // Microsoft to actually run this SP. This certificate would be in the KEY.C file
  22. // under the INCLUDE directory for one level up.
  23. // MDSPStorageGlobals.cpp : Implementation of CMDSPStorageGlobals
  24. #include "hdspPCH.h"
  25. #include <SerialNumber.h>
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CMDSPStorageGlobals
  28. CMDSPStorageGlobals::~CMDSPStorageGlobals()
  29. {
  30. if( m_pMDSPDevice != NULL )
  31. {
  32. m_pMDSPDevice->Release();
  33. }
  34. for(int i=0; i<MDSP_MAX_DEVICE_OBJ;i++)
  35. {
  36. if( !wcscmp(g_GlobalDeviceInfo[i].wcsDevName, m_wcsName) )
  37. {
  38. g_GlobalDeviceInfo[i].pIMDSPStorageGlobals = NULL;
  39. }
  40. }
  41. }
  42. STDMETHODIMP CMDSPStorageGlobals::GetCapabilities(DWORD * pdwCapabilities)
  43. {
  44. HRESULT hr = S_OK;
  45. CFRg(g_pAppSCServer);
  46. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  47. {
  48. CORg(WMDM_E_NOTCERTIFIED);
  49. }
  50. CARg(pdwCapabilities);
  51. *pdwCapabilities = 0;
  52. *pdwCapabilities = WMDM_STORAGECAP_FOLDERSINROOT |
  53. WMDM_STORAGECAP_FILESINROOT |
  54. WMDM_STORAGECAP_FOLDERSINFOLDERS |
  55. WMDM_STORAGECAP_FILESINFOLDERS ;
  56. Error:
  57. hrLogDWORD("IMDSPStorageGlobals::GetCapabilities returned 0x%08lx", hr, hr);
  58. return hr;
  59. }
  60. STDMETHODIMP CMDSPStorageGlobals::GetSerialNumber(
  61. PWMDMID pSerialNum,
  62. BYTE abMac[WMDM_MAC_LENGTH])
  63. {
  64. HRESULT hr;
  65. CFRg(g_pAppSCServer);
  66. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  67. {
  68. CORg(WMDM_E_NOTCERTIFIED);
  69. }
  70. CARg(pSerialNum);
  71. IMDSPDevice *pDev; // For PM SP, device is the same as StorageGlobals
  72. CHRg(GetDevice(&pDev));
  73. hr = UtilGetSerialNumber(m_wcsName, pSerialNum, FALSE);
  74. pDev->Release();
  75. if( hr == HRESULT_FROM_WIN32(ERROR_NOT_SUPPORTED) )
  76. {
  77. hr = WMDM_E_NOTSUPPORTED;
  78. }
  79. if( hr == S_OK )
  80. {
  81. // MAC the parameters
  82. HMAC hMAC;
  83. CORg(g_pAppSCServer->MACInit(&hMAC));
  84. CORg(g_pAppSCServer->MACUpdate(hMAC, (BYTE*)(pSerialNum), sizeof(WMDMID)));
  85. CORg(g_pAppSCServer->MACFinal(hMAC, abMac));
  86. }
  87. Error:
  88. hrLogDWORD("IMDSPStorageGlobals::GetSerialNumber returned 0x%08lx", hr, hr);
  89. return hr;
  90. }
  91. STDMETHODIMP CMDSPStorageGlobals::GetTotalSize(DWORD * pdwTotalSizeLow, DWORD * pdwTotalSizeHigh)
  92. {
  93. HRESULT hr = S_OK;
  94. char pszDrive[32];
  95. DWORD dwSectPerClust;
  96. DWORD dwBytesPerSect;
  97. DWORD dwFreeClusters;
  98. DWORD dwTotalClusters;
  99. ULARGE_INTEGER i64TotalBytes;
  100. CFRg(g_pAppSCServer);
  101. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  102. {
  103. CORg(WMDM_E_NOTCERTIFIED);
  104. }
  105. CARg(pdwTotalSizeLow);
  106. CARg(pdwTotalSizeHigh);
  107. WideCharToMultiByte(CP_ACP, NULL, m_wcsName, -1, pszDrive, 32, NULL, NULL);
  108. CFRg(GetDiskFreeSpace(
  109. pszDrive,
  110. &dwSectPerClust, &dwBytesPerSect,
  111. &dwFreeClusters, &dwTotalClusters)
  112. );
  113. i64TotalBytes.QuadPart = UInt32x32To64(dwBytesPerSect, dwSectPerClust*dwTotalClusters);
  114. *pdwTotalSizeLow = i64TotalBytes.LowPart;
  115. *pdwTotalSizeHigh = i64TotalBytes.HighPart;
  116. Error:
  117. hrLogDWORD("IMDSPStorageGlobals::GetTotalFree returned 0x%08lx", hr, hr);
  118. return hr;
  119. }
  120. STDMETHODIMP CMDSPStorageGlobals::GetTotalFree(DWORD * pdwFreeLow, DWORD * pdwFreeHigh)
  121. {
  122. HRESULT hr = S_OK;
  123. char pszDrive[32];
  124. DWORD dwSectPerClust;
  125. DWORD dwBytesPerSect;
  126. DWORD dwFreeClusters;
  127. DWORD dwTotalClusters;
  128. ULARGE_INTEGER i64FreeBytesToCaller;
  129. CFRg(g_pAppSCServer);
  130. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  131. {
  132. CORg(WMDM_E_NOTCERTIFIED);
  133. }
  134. CARg(pdwFreeLow);
  135. CARg(pdwFreeHigh);
  136. WideCharToMultiByte(CP_ACP, NULL, m_wcsName, -1, pszDrive, 32, NULL, NULL);
  137. CFRg(GetDiskFreeSpace(
  138. pszDrive,
  139. &dwSectPerClust, &dwBytesPerSect,
  140. &dwFreeClusters, &dwTotalClusters)
  141. );
  142. i64FreeBytesToCaller.QuadPart = UInt32x32To64(dwBytesPerSect, dwSectPerClust*dwFreeClusters);
  143. *pdwFreeLow = i64FreeBytesToCaller.LowPart;
  144. *pdwFreeHigh = i64FreeBytesToCaller.HighPart;
  145. Error:
  146. hrLogDWORD("IMDSPStorageGlobals::GetTotalFree returned 0x%08lx", hr, hr);
  147. return hr;
  148. }
  149. STDMETHODIMP CMDSPStorageGlobals::GetTotalBad(DWORD * pdwBadLow, DWORD * pdwBadHigh)
  150. {
  151. HRESULT hr;
  152. CFRg(g_pAppSCServer);
  153. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  154. {
  155. CORg(WMDM_E_NOTCERTIFIED);
  156. }
  157. CORg(WMDM_E_NOTSUPPORTED);
  158. Error:
  159. hrLogDWORD("IMDSPStorageGlobals::GetTotalBad returned 0x%08lx", hr, hr);
  160. return hr;
  161. }
  162. STDMETHODIMP CMDSPStorageGlobals::GetStatus(DWORD * pdwStatus)
  163. {
  164. HRESULT hr;
  165. IMDSPDevice *pDev;
  166. CFRg(g_pAppSCServer);
  167. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  168. {
  169. CORg(WMDM_E_NOTCERTIFIED);
  170. }
  171. CHRg(GetDevice(&pDev));
  172. hr = pDev->GetStatus(pdwStatus);
  173. pDev->Release();
  174. Error:
  175. hrLogDWORD("IMDSPStorageGlobals::GetStatus returned 0x%08lx", hr, hr);
  176. return hr;
  177. }
  178. STDMETHODIMP CMDSPStorageGlobals::Initialize(UINT fuMode, IWMDMProgress * pProgress)
  179. {
  180. HRESULT hr=S_OK;
  181. CFRg(g_pAppSCServer);
  182. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  183. {
  184. CORg(WMDM_E_NOTCERTIFIED);
  185. }
  186. CORg(WMDM_E_NOTSUPPORTED);
  187. Error:
  188. hrLogDWORD("IMDSPStorageGlobals::Initialize returned 0x%08lx", hr, hr);
  189. return hr;
  190. }
  191. STDMETHODIMP CMDSPStorageGlobals::GetDevice(IMDSPDevice * * ppDevice)
  192. {
  193. HRESULT hr;
  194. CComObject<CMDSPDevice> *pObj;
  195. CFRg(g_pAppSCServer);
  196. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  197. {
  198. CORg(WMDM_E_NOTCERTIFIED);
  199. }
  200. CARg(ppDevice);
  201. if( m_pMDSPDevice )
  202. {
  203. *ppDevice = m_pMDSPDevice;
  204. (*ppDevice)->AddRef();
  205. return S_OK;
  206. }
  207. CORg(CComObject<CMDSPDevice>::CreateInstance(&pObj));
  208. hr = pObj->QueryInterface(
  209. IID_IMDSPDevice,
  210. reinterpret_cast<void**>(ppDevice)
  211. );
  212. if( FAILED(hr) )
  213. {
  214. delete pObj;
  215. goto Error;
  216. }
  217. else
  218. {
  219. wcscpy(pObj->m_wcsName, m_wcsName);
  220. pObj->InitGlobalDeviceInfo();
  221. m_pMDSPDevice = *ppDevice;
  222. m_pMDSPDevice->AddRef();
  223. }
  224. hr = S_OK;
  225. Error:
  226. hrLogDWORD("IMDSPStorageGlobals::GetDevice returned 0x%08lx", hr, hr);
  227. return hr;
  228. }
  229. STDMETHODIMP CMDSPStorageGlobals::GetRootStorage(IMDSPStorage * * ppRoot)
  230. {
  231. HRESULT hr;
  232. CComObject<CMDSPStorage> *pObj;
  233. CFRg(g_pAppSCServer);
  234. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  235. {
  236. CORg(WMDM_E_NOTCERTIFIED);
  237. }
  238. CARg(ppRoot);
  239. CORg(CComObject<CMDSPStorage>::CreateInstance(&pObj));
  240. hr = pObj->QueryInterface(
  241. IID_IMDSPStorage,
  242. reinterpret_cast<void**>(ppRoot)
  243. );
  244. if( FAILED(hr) )
  245. {
  246. delete pObj;
  247. goto Error;
  248. }
  249. else
  250. {
  251. wcscpy(pObj->m_wcsName, m_wcsName);
  252. if( m_wcsName[wcslen(m_wcsName)-1] != 0x5c )
  253. {
  254. wcscat(pObj->m_wcsName, g_wcsBackslash);
  255. }
  256. }
  257. hr = S_OK;
  258. Error:
  259. hrLogDWORD("IMDSPStorageGlobals::GetRootStorage returned 0x%08lx", hr, hr);
  260. return hr;
  261. }