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.

170 lines
4.5 KiB

  1. /*
  2. * MEDIAPRT.C
  3. *
  4. * RSM Service : Media Partitions (i.e. "sides")
  5. *
  6. * Author: ErvinP
  7. *
  8. * (c) 2001 Microsoft Corporation
  9. *
  10. */
  11. #include <windows.h>
  12. #include <stdlib.h>
  13. #include <wtypes.h>
  14. #include <ntmsapi.h>
  15. #include "internal.h"
  16. #include "resource.h"
  17. #include "debug.h"
  18. MEDIA_PARTITION *FindMediaPartition(LPNTMS_GUID lpLogicalMediaId)
  19. {
  20. MEDIA_PARTITION *foundMediaPartition = NULL;
  21. if (lpLogicalMediaId){
  22. OBJECT_HEADER *objHdr;
  23. objHdr = FindObjectInGuidHash(lpLogicalMediaId);
  24. if (objHdr){
  25. if (objHdr->objType == OBJECTTYPE_MEDIAPARTITION){
  26. foundMediaPartition = (MEDIA_PARTITION *)objHdr;
  27. }
  28. else {
  29. DerefObject(objHdr);
  30. }
  31. }
  32. }
  33. return foundMediaPartition;
  34. }
  35. HRESULT ReleaseMediaPartition(SESSION *thisSession, MEDIA_PARTITION *thisMediaPartition)
  36. {
  37. PHYSICAL_MEDIA *physMedia = thisMediaPartition->owningPhysicalMedia;
  38. HRESULT result;
  39. EnterCriticalSection(&physMedia->lock);
  40. if (thisMediaPartition->owningSession == thisSession){
  41. thisMediaPartition->owningSession = NULL;
  42. if (physMedia->owningSession == thisSession){
  43. ASSERT(physMedia->numPartitionsOwnedBySession > 0);
  44. physMedia->numPartitionsOwnedBySession--;
  45. if (physMedia->numPartitionsOwnedBySession == 0){
  46. physMedia->owningSession = NULL;
  47. // BUGBUG FINISH - move to scratch pool ?
  48. }
  49. }
  50. else {
  51. ASSERT(!physMedia->owningSession);
  52. }
  53. result = ERROR_SUCCESS;
  54. }
  55. else {
  56. ASSERT(thisMediaPartition->owningSession == thisSession);
  57. result = ERROR_INVALID_MEDIA;
  58. }
  59. LeaveCriticalSection(&physMedia->lock);
  60. return result;
  61. }
  62. HRESULT SetMediaPartitionState( MEDIA_PARTITION *mediaPart,
  63. enum mediaPartitionStates newState)
  64. {
  65. PHYSICAL_MEDIA *physMedia = mediaPart->owningPhysicalMedia;
  66. HRESULT result;
  67. EnterCriticalSection(&physMedia->lock);
  68. switch (newState){
  69. case MEDIAPARTITIONSTATE_AVAILABLE:
  70. // BUGBUG FINISH
  71. result = ERROR_CALL_NOT_IMPLEMENTED;
  72. break;
  73. case MEDIAPARTITIONSTATE_ALLOCATED:
  74. // BUGBUG FINISH
  75. result = ERROR_CALL_NOT_IMPLEMENTED;
  76. break;
  77. case MEDIAPARTITIONSTATE_MOUNTED:
  78. // BUGBUG FINISH
  79. result = ERROR_CALL_NOT_IMPLEMENTED;
  80. break;
  81. case MEDIAPARTITIONSTATE_INUSE:
  82. // BUGBUG FINISH
  83. result = ERROR_CALL_NOT_IMPLEMENTED;
  84. break;
  85. case MEDIAPARTITIONSTATE_DECOMMISSIONED:
  86. if (mediaPart->state == MEDIAPARTITIONSTATE_AVAILABLE){
  87. mediaPart->state = MEDIAPARTITIONSTATE_DECOMMISSIONED;
  88. result = ERROR_SUCCESS;
  89. }
  90. else {
  91. result = ERROR_INVALID_STATE;
  92. }
  93. break;
  94. default:
  95. DBGERR(("illegal state (%xh) in SetMediaPartitionState", newState));
  96. result = ERROR_INVALID_STATE;
  97. break;
  98. }
  99. LeaveCriticalSection(&physMedia->lock);
  100. return result;
  101. }
  102. HRESULT SetMediaPartitionComplete(MEDIA_PARTITION *mediaPart)
  103. {
  104. PHYSICAL_MEDIA *physMedia = mediaPart->owningPhysicalMedia;
  105. HRESULT result;
  106. EnterCriticalSection(&physMedia->lock);
  107. switch (mediaPart->state){
  108. case MEDIAPARTITIONSTATE_ALLOCATED:
  109. if (mediaPart->isComplete){
  110. DBGWARN(("SetMediaPartitionComplete: media partition is already complete."));
  111. }
  112. else {
  113. mediaPart->isComplete = TRUE;
  114. }
  115. result = ERROR_SUCCESS;
  116. break;
  117. case MEDIAPARTITIONSTATE_AVAILABLE:
  118. case MEDIAPARTITIONSTATE_MOUNTED:
  119. case MEDIAPARTITIONSTATE_INUSE:
  120. case MEDIAPARTITIONSTATE_DECOMMISSIONED:
  121. result = ERROR_INVALID_STATE;
  122. break;
  123. default:
  124. DBGERR(("illegal state (%xh) in SetMediaPartitionComplete", mediaPart->state));
  125. result = ERROR_INVALID_STATE;
  126. break;
  127. }
  128. LeaveCriticalSection(&physMedia->lock);
  129. return result;
  130. }