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.

120 lines
3.2 KiB

  1. /*
  2. DoPort.c
  3. Contains large routines that are too complicated to "wrap", so
  4. here you have to rewrite the function for whatever the target is.
  5. */
  6. #include "diskpart.h"
  7. EFI_STATUS
  8. FindPartitionableDevices(
  9. EFI_HANDLE **ReturnBuffer,
  10. UINTN *Count
  11. )
  12. /*
  13. FindPartitionableDevices gets the list of handles that support
  14. the block I/O protocol. It then traverses these handles, and
  15. filters out any that don't appear to be fixed mount, present, read/write,
  16. disks.
  17. ReturnBuffer - will be set to point to a buffer with a an array of
  18. handles to partitionable disks. NULL if failure or
  19. no such disks found. Caller may free from pool
  20. an
  21. Count - number of entries in ReturnBuffer, 0 if none.
  22. Return is a status.an
  23. */
  24. {
  25. EFI_HANDLE *HandlePointer;
  26. UINTN HandleCount;
  27. EFI_BLOCK_IO *BlkIo;
  28. EFI_DEVICE_PATH *DevicePath;
  29. UINTN PathSize;
  30. BOOLEAN Partitionable;
  31. EFI_DEVICE_PATH *PathInstance;
  32. UINTN SpindleCount;
  33. UINTN i;
  34. *ReturnBuffer = NULL;
  35. *Count = 0;
  36. //
  37. // Try to find all of the hard disks by finding all
  38. // handles that support BlockIo protocol
  39. //
  40. status = LibLocateHandle(
  41. ByProtocol,
  42. &BlockIoProtocol,
  43. NULL,
  44. &HandleCount,
  45. &HandlePointer
  46. );
  47. if (EFI_ERROR(status)) {
  48. return status;
  49. }
  50. *ReturnBuffer = DoAllocate(sizeof(EFI_HANDLE)*HandleCount);
  51. if (*ReturnBuffer == NULL) {
  52. *Count = 0;
  53. return EFI_OUT_OF_RESOURCES;
  54. }
  55. SpindleCount = 0;
  56. for (i = 0; i < HandleCount; i++) {
  57. Partitionable = TRUE;
  58. status = BS->HandleProtocol(HandlePointer[i], &BlockIoProtocol, &BlkIo);
  59. if (BlkIo->Media->RemovableMedia) {
  60. //
  61. // It's removable, it's not for us
  62. //
  63. Partitionable = FALSE;
  64. }
  65. if ( ! BlkIo->Media->MediaPresent) {
  66. //
  67. // It's still not for us
  68. //
  69. Partitionable = FALSE;
  70. }
  71. if (BlkIo->Media->ReadOnly) {
  72. //
  73. // Cannot partition a read-only device!
  74. //
  75. Partitionable = FALSE;
  76. }
  77. //
  78. // OK, it seems to be a present, fixed, read/write, block device.
  79. // Now, make sure it's really the raw device by inspecting the
  80. // device path.
  81. //
  82. DevicePath = DevicePathFromHandle(HandlePointer[i]);
  83. while (DevicePath != NULL) {
  84. PathInstance = DevicePathInstance(&DevicePath, &PathSize);
  85. while (!IsDevicePathEnd(PathInstance)) {
  86. if ((DevicePathType(PathInstance) == MEDIA_DEVICE_PATH)) {
  87. Partitionable = FALSE;
  88. }
  89. PathInstance = NextDevicePathNode(PathInstance);
  90. }
  91. }
  92. if (Partitionable) {
  93. //
  94. // Return this handle
  95. //
  96. (*ReturnBuffer)[*Count] = HandlePointer[i];
  97. (*Count)++;
  98. }
  99. }
  100. return EFI_SUCCESS;
  101. }