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.

172 lines
4.3 KiB

  1. /*
  2. * POOL.C
  3. *
  4. * RSM Service : Media Pools
  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_POOL *NewMediaPool(LPCWSTR name, LPNTMS_GUID mediaType, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
  19. {
  20. MEDIA_POOL *newMediaPool;
  21. newMediaPool = GlobalAlloc(GMEM_FIXED|GMEM_ZEROINIT, sizeof(MEDIA_POOL));
  22. if (newMediaPool){
  23. newMediaPool->newMediaEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  24. if (newMediaPool->newMediaEvent){
  25. WStrNCpy(newMediaPool->name, name, NTMS_OBJECTNAME_LENGTH);
  26. InitializeCriticalSection(&newMediaPool->lock);
  27. newMediaPool->objHeader.objType = OBJECTTYPE_MEDIAPOOL;
  28. newMediaPool->objHeader.refCount = 1;
  29. // BUGBUG FINISH
  30. }
  31. else {
  32. GlobalFree(newMediaPool);
  33. newMediaPool = NULL;
  34. }
  35. }
  36. ASSERT(newMediaPool);
  37. return newMediaPool;
  38. }
  39. /*
  40. * DestroyMediaPool
  41. *
  42. * Actually delete a media pool.
  43. * Assumes that there are no remaining references on the pool, etc.
  44. */
  45. VOID DestroyMediaPool(MEDIA_POOL *mediaPool)
  46. {
  47. // BUGBUG FINISH
  48. DeleteCriticalSection(&mediaPool->lock);
  49. GlobalFree(mediaPool);
  50. }
  51. MEDIA_POOL *FindMediaPool(LPNTMS_GUID mediaPoolId)
  52. {
  53. MEDIA_POOL *foundMediaPool = NULL;
  54. if (mediaPoolId){
  55. OBJECT_HEADER *objHdr;
  56. objHdr = FindObjectInGuidHash(mediaPoolId);
  57. if (objHdr){
  58. if (objHdr->objType == OBJECTTYPE_MEDIAPOOL){
  59. foundMediaPool = (MEDIA_POOL *)objHdr;
  60. }
  61. else {
  62. DerefObject(objHdr);
  63. }
  64. }
  65. }
  66. return foundMediaPool;
  67. }
  68. MEDIA_POOL *FindMediaPoolByName(PWSTR poolName)
  69. {
  70. MEDIA_POOL *mediaPool = NULL;
  71. LIST_ENTRY *listEntry;
  72. EnterCriticalSection(&g_globalServiceLock);
  73. listEntry = &g_allLibrariesList;
  74. while ((listEntry = listEntry->Flink) != &g_allLibrariesList){
  75. LIBRARY *lib = CONTAINING_RECORD(listEntry, LIBRARY, allLibrariesListEntry);
  76. mediaPool = FindMediaPoolByNameInLibrary(lib, poolName);
  77. if (mediaPool){
  78. break;
  79. }
  80. }
  81. LeaveCriticalSection(&g_globalServiceLock);
  82. return mediaPool;
  83. }
  84. MEDIA_POOL *FindMediaPoolByNameInLibrary(LIBRARY *lib, PWSTR poolName)
  85. {
  86. MEDIA_POOL *mediaPool = NULL;
  87. LIST_ENTRY *listEntry;
  88. EnterCriticalSection(&lib->lock);
  89. listEntry = &lib->mediaPoolsList;
  90. while ((listEntry = listEntry->Flink) != &lib->mediaPoolsList){
  91. MEDIA_POOL *thisMediaPool = CONTAINING_RECORD(listEntry, MEDIA_POOL, mediaPoolsListEntry);
  92. if (WStringsEqualN(thisMediaPool->name, poolName, FALSE, NTMS_OBJECTNAME_LENGTH)){
  93. mediaPool = thisMediaPool;
  94. RefObject(mediaPool);
  95. break;
  96. }
  97. }
  98. LeaveCriticalSection(&lib->lock);
  99. return mediaPool;
  100. }
  101. HRESULT DeleteMediaPool(MEDIA_POOL *mediaPool)
  102. {
  103. HRESULT result;
  104. EnterCriticalSection(&mediaPool->lock);
  105. /*
  106. * The pool can only be deleted if it is empty and has no
  107. * child pools.
  108. */
  109. if (mediaPool->numPhysMedia || mediaPool->numChildPools){
  110. result = ERROR_NOT_EMPTY;
  111. }
  112. else if (mediaPool->objHeader.isDeleted){
  113. /*
  114. * Already deleted. Do nothing.
  115. */
  116. result = ERROR_SUCCESS;
  117. }
  118. else {
  119. /*
  120. * If the mediaPool can be deleted, mark it as deleted and
  121. * dereference it.
  122. * This will cause no new references to be opened on it
  123. * and will cause it to actually get deleted once all existing
  124. * references go away.
  125. * We can still use our mediaPool pointer because the caller
  126. * has a reference on it (by virtue of having a pointer).
  127. */
  128. mediaPool->objHeader.isDeleted = TRUE;
  129. DerefObject(mediaPool);
  130. result = ERROR_SUCCESS;
  131. }
  132. LeaveCriticalSection(&mediaPool->lock);
  133. return result;
  134. }