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.

131 lines
3.7 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998-1999.
  5. //
  6. // File: DrvNotif.hxx
  7. //
  8. // Contents: This file contains a class that keeps the information of a
  9. // volume which is registered for device notification.
  10. //
  11. // History: 23-Jun-98 KitmanH Created
  12. //
  13. //--------------------------------------------------------------------------
  14. #pragma once
  15. enum eCiSvcVolState
  16. {
  17. eVolReady,
  18. eVolLocked
  19. };
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Function: IsRemovableDrive
  23. //
  24. // Synopsis: Checks if a drive is removable or cd-rom/dvd
  25. //
  26. // Arguments: [wc] - Dirve letter
  27. //
  28. // Returns: TRUE if removable, FALSE otherwise
  29. //
  30. // History: 1-Apr-99 dlee Created
  31. //
  32. //--------------------------------------------------------------------------
  33. inline BOOL IsRemovableDrive( WCHAR wc )
  34. {
  35. WCHAR awc[4];
  36. wcscpy( awc, L"C:\\" );
  37. awc[0] = wc;
  38. UINT uiRC = GetDriveType( awc );
  39. return ( DRIVE_REMOVABLE == uiRC || DRIVE_CDROM == uiRC );
  40. } //IsRemovableDrive
  41. //+---------------------------------------------------------------------------
  42. //
  43. // Class: CDrvNotificationInfo
  44. //
  45. // Purpose: Maintains the info for a volume regarding receiving
  46. // notificaitons
  47. //
  48. // History: 06/23/98 KitmanH created
  49. //
  50. //----------------------------------------------------------------------------
  51. class CDrvNotificationInfo
  52. {
  53. public:
  54. CDrvNotificationInfo( WCHAR wcDriveLetter, BOOL fAutoMountMode = FALSE );
  55. ~CDrvNotificationInfo();
  56. BOOL RegisterNotification();
  57. void UnregisterNotification();
  58. BOOL Touch();
  59. WCHAR GetDrvLetter() const { return (WCHAR) toupper( _wcDriveLetter ); }
  60. HDEVNOTIFY const GethNotify() { return _hNotify; }
  61. void AddOldState( DWORD dwOldState, WCHAR * wcsCatName );
  62. DWORD * GetOldState( WCHAR * wcsCatName ) const;
  63. DWORD GetVolState() const { return _dwVolState; }
  64. void SetVolState( DWORD dwVolState )
  65. {
  66. // no lock needed, since it's only called in service control
  67. // which can has no contender
  68. _dwVolState = dwVolState;
  69. }
  70. void ClearOldStateArray();
  71. void CloseVolumeHandle()
  72. {
  73. if ( INVALID_HANDLE_VALUE != _hVol )
  74. {
  75. CloseHandle( _hVol );
  76. _hVol = INVALID_HANDLE_VALUE;
  77. }
  78. }
  79. DWORD GetLockAttempts() const { return _cLockAttempts; }
  80. void IncLockAttempts() { _cLockAttempts++; }
  81. void DecLockAttempts() { _cLockAttempts--; }
  82. void ResetLockAttempts() { _cLockAttempts = 0; }
  83. BOOL IsAutoMount() const { return _fAutoMountMode; }
  84. BOOL IsRemovable() const { return DRIVE_REMOVABLE == _uiDriveType ||
  85. DRIVE_CDROM == _uiDriveType; }
  86. BOOL IsCDROM() const { return DRIVE_CDROM == _uiDriveType; }
  87. BOOL IsRegistered() const { return INVALID_HANDLE_VALUE != _hNotify; }
  88. private:
  89. BOOL ReallyTouch();
  90. BOOL GetVolumeHandle();
  91. HANDLE _hVol;
  92. HDEVNOTIFY _hNotify;
  93. WCHAR _wcDriveLetter;
  94. DWORD _dwVolState; // is the drive dismounted or locked
  95. DWORD _cLockAttempts; // how many times a volume lock is attempted
  96. BOOL _fAutoMountMode;
  97. UINT _uiDriveType;
  98. };