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.

264 lines
7.9 KiB

  1. #include "mtpt.h"
  2. class CVolume;
  3. class CMtPtLocal : public CMountPoint
  4. {
  5. ///////////////////////////////////////////////////////////////////////////////
  6. // Public methods
  7. ///////////////////////////////////////////////////////////////////////////////
  8. public:
  9. CMtPtLocal();
  10. ~CMtPtLocal();
  11. HRESULT GetMountPointName(LPWSTR pszMountPoint, DWORD cchMountPoint);
  12. HRESULT Eject(HWND hwnd);
  13. BOOL IsEjectable();
  14. BOOL HasMedia();
  15. BOOL IsFormatted();
  16. BOOL IsMounted();
  17. HRESULT GetCDInfo(DWORD* pdwDriveCapabilities, DWORD* pdwMediaCapabilities);
  18. HRESULT GetLabel(LPTSTR pszLabel, DWORD cchLabel);
  19. HRESULT GetLabelNoFancy(LPTSTR pszLabel, DWORD cchLabel);
  20. HRESULT SetLabel(HWND hwnd, LPCTSTR pszLabel);
  21. HRESULT SetDriveLabel(HWND hwnd, LPCTSTR pszLabel);
  22. HRESULT ChangeNotifyRegisterAlias(void)
  23. { /* no-op */ return NOERROR; }
  24. int GetDriveFlags();
  25. HRESULT GetRemotePath(LPWSTR pszPath, DWORD cchPath) { return E_NOTIMPL; }
  26. void GetTypeString(LPTSTR pszType, DWORD cchType);
  27. void StoreIconForUpdateImage(int iImage);
  28. UINT GetIcon(LPTSTR pszModule, DWORD cchModule);
  29. HRESULT GetAssocSystemElement(IAssociationElement **ppae);
  30. DWORD GetShellDescriptionID();
  31. HKEY GetRegKey();
  32. static BOOL IsVolume(LPCWSTR pszDeviceID);
  33. ///////////////////////////////////////////////////////////////////////////////
  34. // Miscellaneous helpers
  35. ///////////////////////////////////////////////////////////////////////////////
  36. public: // should be used in mtptmgmt2.cpp only
  37. BOOL _IsMiniMtPt();
  38. BOOL _NeedToRefresh();
  39. public: // should be used in mtptarun2.cpp only (when used outside of CMtPtLocal)
  40. BOOL _IsMediaPresent();
  41. BOOL _CanUseVolume();
  42. private:
  43. HRESULT _InitWithVolume(LPCWSTR pszMtPt, CVolume* pvol);
  44. HRESULT _Init(LPCWSTR pszMtPt);
  45. LPCTSTR _GetNameForFctCall();
  46. BOOL _IsFloppy();
  47. BOOL _IsFloppy35();
  48. BOOL _IsFloppy525();
  49. BOOL _IsCDROM();
  50. // real removable, excludes floppies
  51. BOOL _IsStrictRemovable();
  52. BOOL _IsFixedDisk();
  53. BOOL _IsFormattable();
  54. BOOL _IsAudioCD();
  55. BOOL _IsAudioCDNoData();
  56. BOOL _IsDVD();
  57. BOOL _IsRemovableDevice();
  58. BOOL _IsAutorun();
  59. BOOL _IsDVDDisc();
  60. BOOL _IsDVDRAMMedia();
  61. BOOL _IsAudioDisc();
  62. BOOL _ForceCheckMediaPresent();
  63. BOOL _IsFormatted();
  64. BOOL _IsReadOnly();
  65. // returns DT_* defined above
  66. DWORD _GetMTPTDriveType();
  67. // returns CT_* defined above
  68. DWORD _GetMTPTContentType();
  69. BOOL _GetFileAttributes(DWORD* pdwAttrib);
  70. BOOL _GetFileSystemName(LPTSTR pszFileSysName, DWORD cchFileSysName);
  71. BOOL _GetGVILabelOrMixedCaseFromReg(LPTSTR pszLabel, DWORD cchLabel);
  72. BOOL _GetGVILabel(LPTSTR pszLabel, DWORD cchLabel);
  73. BOOL _GetSerialNumber(DWORD* pdwSerialNumber);
  74. BOOL _GetFileSystemFlags(DWORD* pdwFlags);
  75. int _GetGVIDriveFlags();
  76. int _GetDriveType();
  77. DWORD _GetAutorunContentType();
  78. HRESULT _Eject(HWND hwnd, LPTSTR pszMountPointNameForError);
  79. BOOL _HasAutorunLabel();
  80. BOOL _HasAutorunIcon();
  81. UINT _GetAutorunIcon(LPTSTR pszModule, DWORD cchModule);
  82. void _GetAutorunLabel(LPWSTR pszLabel, DWORD cchLabel);
  83. void _InitLegacyRegIconAndLabelHelper();
  84. void _InitAutorunInfo();
  85. BOOL _IsMountedOnDriveLetter();
  86. HANDLE _GetHandleWithAccessAndShareMode(DWORD dwDesiredAccess, DWORD dwShareMode);
  87. HANDLE _GetHandleReadRead();
  88. UINT _GetCDROMIcon();
  89. BOOL _GetCDROMName(LPWSTR pszName, DWORD cchName);
  90. DWORD _GetRegVolumeGen();
  91. public:
  92. static BOOL Initialize();
  93. static void FinalCleanUp();
  94. static HRESULT _GetAndRemoveVolumeAndItsMtPts(LPCWSTR pszDeviceIDVolume,
  95. CVolume** ppvol, HDPA hdpaMtPts);
  96. static CVolume* _GetVolumeByID(LPCWSTR pszDeviceIDVolume);
  97. static CVolume* _GetVolumeByMtPt(LPCWSTR pszMountPoint);
  98. static HRESULT _CreateMtPtLocalWithVolume(LPCWSTR pszMountPoint, CVolume* pvol);
  99. static HRESULT _CreateMtPtLocal(LPCWSTR pszMountPoint);
  100. static HRESULT _CreateMtPtLocalFromVolumeGuid(LPCWSTR pszVolumeGuid, CMountPoint ** ppmtpt );
  101. static HRESULT _CreateVolume(VOLUMEINFO* pvolinfo, CVolume** ppvolNew);
  102. static HRESULT _CreateVolumeFromReg(LPCWSTR pszDeviceIDVolume, CVolume** ppvolNew);
  103. static HRESULT _CreateVolumeFromRegHelper(LPCWSTR pszGUID, CVolume** ppvolNew);
  104. static HRESULT _CreateVolumeFromVOLUMEINFO2(VOLUMEINFO2* pvolinfo2, CVolume** ppvolNew);
  105. static CVolume* _GetAndRemoveVolumeByID(LPCWSTR pszDeviceIDVolume);
  106. static HRESULT _UpdateVolumeRegInfo(VOLUMEINFO* pvolinfo);
  107. static HRESULT _UpdateVolumeRegInfo2(VOLUMEINFO2* pvolinfo2);
  108. ///////////////////////////////////////////////////////////////////////////////
  109. // Data
  110. ///////////////////////////////////////////////////////////////////////////////
  111. public: // should be used in mtptarun2.cpp only (when used outside of CMtPtLocal)
  112. CVolume* _pvol;
  113. // should be used in mtptevnt.cpp only (when used outside of CMtPtLocal)
  114. // Watch out! No constructor nor destructor called on the next member
  115. static CRegSupport _rsVolumes;
  116. private:
  117. BOOL _fMountedOnDriveLetter;
  118. BOOL _fVolumePoint;
  119. WCHAR _szNameNoVolume[2];
  120. #ifdef DEBUG
  121. private:
  122. static DWORD _cMtPtLocal;
  123. #endif
  124. };
  125. class CVolume
  126. {
  127. public:
  128. DWORD dwGeneration;
  129. DWORD dwState;
  130. LPWSTR pszDeviceIDVolume; // \\?\STORAGE#Volume#...{...GUID...}
  131. LPWSTR pszVolumeGUID; // \\?\Volume{...GUID...}
  132. DWORD dwVolumeFlags; // see HWDVF_... flags
  133. DWORD dwDriveType; // see HWDT_... flags
  134. DWORD dwDriveCapability; // see HWDDC_... flags
  135. LPWSTR pszLabel; //
  136. LPWSTR pszFileSystem; //
  137. DWORD dwFileSystemFlags; //
  138. DWORD dwMaxFileNameLen; //
  139. DWORD dwRootAttributes; //
  140. DWORD dwSerialNumber; //
  141. DWORD dwDriveState; // see HWDDS_...
  142. DWORD dwMediaState; // see HWDMS_...
  143. DWORD dwMediaCap;
  144. int iShellImageForUpdateImage;
  145. LPWSTR pszAutorunIconLocation;
  146. LPWSTR pszAutorunLabel;
  147. LPWSTR pszKeyName;
  148. LPWSTR pszIconFromService;
  149. LPWSTR pszNoMediaIconFromService;
  150. LPWSTR pszLabelFromService;
  151. public:
  152. ULONG AddRef()
  153. { return InterlockedIncrement(&_cRef); }
  154. ULONG Release()
  155. {
  156. ASSERT( 0 != _cRef );
  157. ULONG cRef = InterlockedDecrement(&_cRef);
  158. if ( 0 == cRef )
  159. {
  160. delete this;
  161. }
  162. return cRef;
  163. }
  164. private:
  165. LONG _cRef;
  166. public:
  167. CVolume() : _cRef(1)
  168. {
  169. #ifdef DEBUG
  170. ++_cVolume;
  171. #endif
  172. }
  173. ~CVolume()
  174. {
  175. if (pszDeviceIDVolume)
  176. {
  177. LocalFree(pszDeviceIDVolume);
  178. }
  179. if (pszVolumeGUID)
  180. {
  181. LocalFree(pszVolumeGUID);
  182. }
  183. if (pszLabel)
  184. {
  185. LocalFree(pszLabel);
  186. }
  187. if (pszFileSystem)
  188. {
  189. LocalFree(pszFileSystem);
  190. }
  191. if (pszAutorunIconLocation)
  192. {
  193. LocalFree(pszAutorunIconLocation);
  194. }
  195. if (pszAutorunLabel)
  196. {
  197. LocalFree(pszAutorunLabel);
  198. }
  199. if (pszIconFromService)
  200. {
  201. LocalFree(pszIconFromService);
  202. }
  203. if (pszNoMediaIconFromService)
  204. {
  205. LocalFree(pszNoMediaIconFromService);
  206. }
  207. if (pszLabelFromService)
  208. {
  209. LocalFree(pszLabelFromService);
  210. }
  211. #ifdef DEBUG
  212. --_cVolume;
  213. #endif
  214. }
  215. #ifdef DEBUG
  216. private:
  217. static DWORD _cVolume;
  218. #endif
  219. };