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.

160 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. volumes.cpp
  5. Abstract:
  6. SIS Groveler SIS volume mount classes
  7. Authors:
  8. John Douceur, 1998
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "all.hxx"
  14. Volumes::Volumes()
  15. {
  16. volume_handle = INVALID_HANDLE_VALUE;
  17. }
  18. Volumes::~Volumes()
  19. {
  20. if (volume_handle != INVALID_HANDLE_VALUE)
  21. {
  22. FindVolumeClose(volume_handle);
  23. volume_handle = INVALID_HANDLE_VALUE;
  24. }
  25. }
  26. DWORD
  27. Volumes::find(
  28. _TCHAR *volume_name,
  29. DWORD length)
  30. {
  31. DWORD error_code = NO_ERROR;
  32. if (volume_handle == INVALID_HANDLE_VALUE)
  33. {
  34. volume_handle = FindFirstVolume(volume_name, length);
  35. if (volume_handle == INVALID_HANDLE_VALUE)
  36. {
  37. error_code = GetLastError();
  38. }
  39. }
  40. else
  41. {
  42. BOOL ok = FindNextVolume(volume_handle, volume_name, length);
  43. if (!ok)
  44. {
  45. error_code = GetLastError();
  46. }
  47. }
  48. return error_code;
  49. }
  50. VolumeMountPoints::VolumeMountPoints(
  51. _TCHAR *volume_name)
  52. {
  53. this->volume_name = volume_name;
  54. drive_mask = 0;
  55. drive_letter = 0;
  56. volume_handle = INVALID_HANDLE_VALUE;
  57. if (volume_name == 0)
  58. {
  59. drive_mask = GetLogicalDrives();
  60. _TCHAR drive_name[4];
  61. drive_name[0] = _T('a');
  62. drive_name[1] = _T(':');
  63. drive_name[2] = _T('\\');
  64. drive_name[3] = _T('\0');
  65. DWORD drive_bit = 1;
  66. while (drive_name[0] <= _T('z'))
  67. {
  68. if ((drive_mask & drive_bit) != 0)
  69. {
  70. UINT drive_type = GetDriveType(drive_name);
  71. if (drive_type != DRIVE_FIXED)
  72. {
  73. drive_mask &= ~drive_bit;
  74. }
  75. }
  76. drive_bit <<= 1;
  77. drive_name[0]++;
  78. }
  79. drive_mask <<= 1;
  80. drive_letter = _T('a') - 1;
  81. }
  82. }
  83. VolumeMountPoints::~VolumeMountPoints()
  84. {
  85. if (volume_handle != INVALID_HANDLE_VALUE)
  86. {
  87. FindVolumeMountPointClose(volume_handle);
  88. volume_handle = INVALID_HANDLE_VALUE;
  89. }
  90. }
  91. DWORD
  92. VolumeMountPoints::find(
  93. _TCHAR *volume_mount_point,
  94. DWORD length)
  95. {
  96. if (volume_name == 0)
  97. {
  98. if ((drive_mask & 0xfffffffe) == 0)
  99. {
  100. return ERROR_NO_MORE_FILES;
  101. }
  102. if (length < 4)
  103. {
  104. return ERROR_FILENAME_EXCED_RANGE;
  105. }
  106. do
  107. {
  108. drive_mask >>= 1;
  109. drive_letter++;
  110. } while ((drive_mask & 1) == 0);
  111. volume_mount_point[0] = drive_letter;
  112. volume_mount_point[1] = _T(':');
  113. volume_mount_point[2] = _T('\\');
  114. volume_mount_point[3] = _T('\0');
  115. return NO_ERROR;
  116. }
  117. else
  118. {
  119. if (volume_handle == INVALID_HANDLE_VALUE)
  120. {
  121. volume_handle = FindFirstVolumeMountPoint(
  122. volume_name, volume_mount_point, length);
  123. if (volume_handle == INVALID_HANDLE_VALUE)
  124. {
  125. return GetLastError();
  126. }
  127. }
  128. else
  129. {
  130. BOOL ok = FindNextVolumeMountPoint(
  131. volume_handle, volume_mount_point, length);
  132. if (!ok)
  133. {
  134. return GetLastError();
  135. }
  136. }
  137. return NO_ERROR;
  138. }
  139. }