Source code of Windows XP (NT5)
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.

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