part.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*++
  2. Copyright (c) 2014 Minoca Corp.
  3. This file is licensed under the terms of the GNU General Public License
  4. version 3. Alternative licensing terms are available. Contact
  5. info@minocacorp.com for details. See the LICENSE file at the root of this
  6. project for complete licensing information.
  7. Module Name:
  8. part.c
  9. Abstract:
  10. This module implements partition support for the setup app on Minoca OS.
  11. Author:
  12. Evan Green 10-Apr-2014
  13. Environment:
  14. User
  15. --*/
  16. //
  17. // ------------------------------------------------------------------- Includes
  18. //
  19. #include <assert.h>
  20. #include <errno.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include "../setup.h"
  25. #include "win32sup.h"
  26. //
  27. // ---------------------------------------------------------------- Definitions
  28. //
  29. //
  30. // ------------------------------------------------------ Data Type Definitions
  31. //
  32. //
  33. // ----------------------------------------------- Internal Function Prototypes
  34. //
  35. //
  36. // -------------------------------------------------------------------- Globals
  37. //
  38. //
  39. // ------------------------------------------------------------------ Functions
  40. //
  41. INT
  42. SetupOsEnumerateDevices (
  43. PSETUP_PARTITION_DESCRIPTION *DeviceArray,
  44. PULONG DeviceCount
  45. )
  46. /*++
  47. Routine Description:
  48. This routine enumerates all the disks and partitions on the system.
  49. Arguments:
  50. DeviceArray - Supplies a pointer where an array of partition structures
  51. will be returned on success.
  52. DeviceCount - Supplies a pointer where the number of elements in the
  53. partition array will be returned on success.
  54. Return Value:
  55. 0 on success.
  56. Returns an error code on failure.
  57. --*/
  58. {
  59. SETUP_DESTINATION_TYPE DestinationType;
  60. PSETUP_PARTITION_DESCRIPTION Device;
  61. DEVICE_ID DeviceId;
  62. PSETUP_PARTITION_DESCRIPTION Devices;
  63. ULONG Index;
  64. INT Result;
  65. ULONG WinDeviceCount;
  66. PSETUP_WIN32_PARTITION_DESCRIPTION WinDevices;
  67. *DeviceArray = NULL;
  68. *DeviceCount = 0;
  69. Devices = NULL;
  70. WinDevices = NULL;
  71. WinDeviceCount = 0;
  72. Result = SetupWin32EnumerateDevices(&WinDevices, &WinDeviceCount);
  73. if (Result != 0) {
  74. goto OsEnumerateDevicesEnd;
  75. }
  76. Devices = malloc(WinDeviceCount * sizeof(SETUP_PARTITION_DESCRIPTION));
  77. if (Devices == NULL) {
  78. Result = ENOMEM;
  79. goto OsEnumerateDevicesEnd;
  80. }
  81. memset(Devices, 0, WinDeviceCount * sizeof(SETUP_PARTITION_DESCRIPTION));
  82. Device = Devices;
  83. for (Index = 0; Index < WinDeviceCount; Index += 1) {
  84. memcpy(&(Device->Partition),
  85. &(WinDevices[Index].Partition),
  86. sizeof(PARTITION_DEVICE_INFORMATION));
  87. if ((WinDevices[Index].Partition.Flags &
  88. PARTITION_FLAG_RAW_DISK) != 0) {
  89. DestinationType = SetupDestinationDisk;
  90. Device->Partition.PartitionType = PartitionTypeNone;
  91. } else {
  92. DestinationType = SetupDestinationPartition;
  93. Device->Partition.PartitionType = PartConvertToPartitionType(
  94. Device->Partition.PartitionFormat,
  95. Device->Partition.PartitionTypeId);
  96. }
  97. assert((WinDevices[Index].DiskNumber < 0x10000) &&
  98. (WinDevices[Index].PartitionNumber < 0x10000));
  99. DeviceId = (WinDevices[Index].DiskNumber << 16) |
  100. WinDevices[Index].PartitionNumber;
  101. Device->Destination = SetupCreateDestination(
  102. DestinationType,
  103. NULL,
  104. DeviceId);
  105. if (Device->Destination == NULL) {
  106. Result = ENOMEM;
  107. goto OsEnumerateDevicesEnd;
  108. }
  109. Device += 1;
  110. }
  111. OsEnumerateDevicesEnd:
  112. if (WinDevices != NULL) {
  113. for (Index = 0; Index < WinDeviceCount; Index += 1) {
  114. if (WinDevices[Index].DevicePath != NULL) {
  115. free(WinDevices[Index].DevicePath);
  116. }
  117. }
  118. free(WinDevices);
  119. }
  120. if (Result != 0) {
  121. if (Devices != NULL) {
  122. for (Index = 0; Index < WinDeviceCount; Index += 1) {
  123. if (Devices[Index].Destination != NULL) {
  124. SetupDestroyDestination(Devices[Index].Destination);
  125. }
  126. }
  127. free(Devices);
  128. Device = NULL;
  129. }
  130. WinDeviceCount = 0;
  131. }
  132. *DeviceArray = Devices;
  133. *DeviceCount = WinDeviceCount;
  134. return Result;
  135. }
  136. INT
  137. SetupOsGetPartitionInformation (
  138. PSETUP_DESTINATION Destination,
  139. PPARTITION_DEVICE_INFORMATION Information
  140. )
  141. /*++
  142. Routine Description:
  143. This routine returns the partition information for the given destination.
  144. Arguments:
  145. Destination - Supplies a pointer to the partition to query.
  146. Information - Supplies a pointer where the information will be returned
  147. on success.
  148. Return Value:
  149. 0 on success.
  150. Returns an error code on failure.
  151. --*/
  152. {
  153. return ENOSYS;
  154. }
  155. PVOID
  156. SetupOsOpenBootVolume (
  157. PSETUP_CONTEXT Context
  158. )
  159. /*++
  160. Routine Description:
  161. This routine opens the boot volume on the current machine.
  162. Arguments:
  163. Context - Supplies a pointer to the application context.
  164. Return Value:
  165. Returns the open handle to the boot volume on success.
  166. NULL on failure.
  167. --*/
  168. {
  169. return NULL;
  170. }
  171. //
  172. // --------------------------------------------------------- Internal Functions
  173. //