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.

208 lines
5.5 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1992, Microsoft Corporation
  4. //
  5. // File: lvolinit.c
  6. //
  7. // Contents: Routines to initialize Local volumes
  8. //
  9. // Classes:
  10. //
  11. // Functions:
  12. //
  13. // History: April 27, 1994 Milans Created
  14. //
  15. //-----------------------------------------------------------------------------
  16. #include "dfsprocs.h"
  17. #include "regkeys.h"
  18. #include "registry.h"
  19. #include "lvolinit.h"
  20. #define Dbg DEBUG_TRACE_INIT
  21. NTSTATUS
  22. GetRegVolumes(
  23. OUT PULONG pcLocalVols,
  24. OUT APWSTR *pawstr
  25. );
  26. //+----------------------------------------------------------------------------
  27. //
  28. // Function: DfsInitLocalPartitions
  29. //
  30. // Synopsis: Initializes the local volumes that are shared in the Dfs
  31. // name space by reading the list of shared folders from the
  32. // registry and creating the appropriate Pkt Entries for them.
  33. //
  34. // Arguments: None
  35. //
  36. // Returns: Nothing
  37. //
  38. //-----------------------------------------------------------------------------
  39. VOID
  40. DfsInitLocalPartitions()
  41. {
  42. NTSTATUS status = STATUS_SUCCESS;
  43. ULONG cLocalVols;
  44. APWSTR awstrLocalVols = NULL;
  45. PDFS_PKT pkt;
  46. ULONG i;
  47. BOOLEAN fErrorsFound = FALSE;
  48. DebugTrace(+1, Dbg, "DfsInitLocalPartitions: Entered\n", 0);
  49. //
  50. // Initializing the local volumes might cause some of the underlying
  51. // storage volumes to get mounted. We need to set the LvState to
  52. // prevent a deadlock in DfsReattachToMountedVolume. It is important
  53. // that we set the LvState before we acquire the Pkt and after we
  54. // release it.
  55. //
  56. ExAcquireResourceExclusiveLite( &DfsData.Resource, TRUE );
  57. DfsData.LvState = LV_INITINPROGRESS;
  58. ExReleaseResourceLite( &DfsData.Resource );
  59. pkt = _GetPkt();
  60. status = GetRegVolumes(&cLocalVols, &awstrLocalVols);
  61. if (!NT_SUCCESS(status)) {
  62. DebugTrace(-1, Dbg, "DfsInitLocalPartitions: Unable to get volume list %08lx\n", ULongToPtr( status ));
  63. return;
  64. }
  65. DebugTrace(0, Dbg, "Retrieved %d local volumes\n", ULongToPtr( cLocalVols ));
  66. if (cLocalVols == 0) {
  67. DebugTrace(-1, Dbg, "DfsInitLocalPartitions: No local volumes!\n", 0);
  68. DfsData.LvState = LV_INITIALIZED;
  69. if (awstrLocalVols != NULL) {
  70. KRegFreeArray(cLocalVols, (APBYTE) awstrLocalVols);
  71. }
  72. return;
  73. }
  74. //
  75. // Now we acquire the Pkt and for every volume attempt to initialize
  76. // any partitions we may find.
  77. //
  78. PktAcquireExclusive(pkt, TRUE);
  79. for (i = 0; i < cLocalVols; i++) {
  80. DFS_LOCAL_VOLUME_CONFIG ConfigInfo;
  81. UNICODE_STRING ustrStorageId;
  82. DebugTrace(0, Dbg, "Reading info for [%ws]\n", awstrLocalVols[i]);
  83. RtlZeroMemory(&ConfigInfo, sizeof(DFS_LOCAL_VOLUME_CONFIG));
  84. RtlZeroMemory(&ustrStorageId, sizeof(UNICODE_STRING));
  85. //
  86. // Retrieve the local volume config info from the registry.
  87. //
  88. status = DfsGetLvolInfo(awstrLocalVols[i], &ConfigInfo, &ustrStorageId);
  89. if (!NT_SUCCESS(status)) {
  90. DebugTrace(0, Dbg, "Error %08lx getting info from registry!\n", ULongToPtr( status ));
  91. continue;
  92. }
  93. //
  94. // Ok, we have a valid local volume config structure so we need to go
  95. // and ask the Pkt to initialize the local partition.
  96. //
  97. status = PktInitializeLocalPartition(pkt, &ustrStorageId, &ConfigInfo);
  98. fErrorsFound = (BOOLEAN) (!NT_SUCCESS(status)) || fErrorsFound;
  99. DebugTrace(0, Dbg, "PktInitializeLocalPartition status %08lx\n", ULongToPtr( status ));
  100. //
  101. // Get rid of the memory used by the ConfigInfo structures.
  102. //
  103. if (ustrStorageId.Buffer != NULL)
  104. ExFreePool(ustrStorageId.Buffer);
  105. if (ConfigInfo.StgId.Buffer != NULL)
  106. ExFreePool(ConfigInfo.StgId.Buffer);
  107. if (ConfigInfo.Share.Buffer != NULL)
  108. ExFreePool(ConfigInfo.Share.Buffer);
  109. PktRelationInfoDestroy(&ConfigInfo.RelationInfo, FALSE );
  110. }
  111. //
  112. // Done. Release locks, cleanup, and vamoose.
  113. //
  114. if (awstrLocalVols != NULL) {
  115. KRegFreeArray(cLocalVols, (APBYTE) awstrLocalVols);
  116. }
  117. PktRelease(pkt);
  118. ExAcquireResourceExclusiveLite( &DfsData.Resource, TRUE );
  119. DfsData.LvState = (fErrorsFound ? LV_UNINITIALIZED : LV_INITIALIZED);
  120. ExReleaseResourceLite( &DfsData.Resource );
  121. DebugTrace(-1, Dbg, "DfsInitLocalPartitions: Exited %08lx\n", ULongToPtr( status ));
  122. }
  123. //+----------------------------------------------------------------------------
  124. //
  125. // Function: GetRegVolumes
  126. //
  127. // Synopsis: Read the local volume list from the
  128. // Registry\Machine\System\CurrentControlSet\Dfs\Localvolumes
  129. // section of the registry.
  130. //
  131. // Arguments:
  132. //
  133. // Returns: STATUS_SUCCESS or reason for failure.
  134. //
  135. //-----------------------------------------------------------------------------
  136. NTSTATUS
  137. GetRegVolumes(
  138. OUT PULONG pcLocalVols,
  139. OUT APWSTR *pawstr
  140. )
  141. {
  142. NTSTATUS Status;
  143. PWSTR wszMachineRoot = NULL;
  144. Status = KRegSetRoot( wszLocalVolumesSection );
  145. if (!NT_SUCCESS(Status)) {
  146. DebugTrace(0, Dbg, "GetRegVolumes: Error opening registry %08lx\n", ULongToPtr( Status ));
  147. return(Status);
  148. }
  149. Status = KRegEnumSubKeySet(
  150. L"",
  151. pcLocalVols,
  152. pawstr);
  153. KRegCloseRoot();
  154. DebugTrace(0, Dbg, "GetRegVolumes: Returning %08lx\n", ULongToPtr( Status ));
  155. return(Status);
  156. }