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.

118 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. dblk.c
  5. Abstract:
  6. Dump Data from block IO devices
  7. Revision History
  8. --*/
  9. #include "shelle.h"
  10. EFI_STATUS
  11. DumpBlockDev (
  12. IN EFI_HANDLE ImageHandle,
  13. IN EFI_SYSTEM_TABLE *SystemTable
  14. );
  15. EFI_DRIVER_ENTRY_POINT(DumpBlockDev)
  16. EFI_STATUS
  17. DumpBlockDev (
  18. IN EFI_HANDLE ImageHandle,
  19. IN EFI_SYSTEM_TABLE *SystemTable
  20. )
  21. /*
  22. dblk BlockDeviceName [LBA] [# Blocks]
  23. if no Address default address is LBA 0
  24. if no # Blocks then # Blocks is 1
  25. */
  26. {
  27. UINT64 BlockAddress;
  28. UINT32 NumBlocks;
  29. UINTN ByteSize;
  30. EFI_DEVICE_PATH *DevicePath;
  31. EFI_STATUS Status;
  32. EFI_BLOCK_IO *BlkIo;
  33. VOID *Buffer;
  34. /*
  35. * Check to see if the app is to install as a "internal command"
  36. * to the shell
  37. */
  38. InstallInternalShellCommand (
  39. ImageHandle, SystemTable, DumpBlockDev,
  40. L"dblk", /* command */
  41. L"dblk device [Lba] [Blocks]", /* command syntax */
  42. L"Hex dump of BlkIo Devices", /* 1 line descriptor */
  43. NULL /* command help page */
  44. );
  45. InitializeShellApplication (ImageHandle, SystemTable);
  46. if ( SI->Argc < 2 ) {
  47. Print (L"Usage - %Hdblk%N BlockDeviceName [LBA] [# Blocks]\n");
  48. return EFI_SUCCESS;
  49. }
  50. if (SI->Argc >= 3) {
  51. BlockAddress = xtoi(SI->Argv[2]);
  52. } else {
  53. BlockAddress = 0;
  54. }
  55. if (SI->Argc >= 4) {
  56. NumBlocks = (UINT32) xtoi(SI->Argv[3]);
  57. } else {
  58. NumBlocks = 1;
  59. }
  60. /*
  61. * Check for the device mapping
  62. */
  63. DevicePath = (EFI_DEVICE_PATH *)ShellGetMap (SI->Argv[1]);
  64. if (DevicePath == NULL) {
  65. return EFI_INVALID_PARAMETER;
  66. }
  67. Status = LibDevicePathToInterface (&BlockIoProtocol, DevicePath, (VOID **)&BlkIo);
  68. if (EFI_ERROR(Status)) {
  69. Print (L"%E - Device Not a BlockIo Device %r%N", Status);
  70. return Status;
  71. }
  72. if (NumBlocks > 0x10) {
  73. NumBlocks = 0x10;
  74. }
  75. if (BlockAddress > BlkIo->Media->LastBlock) {
  76. BlockAddress = 0;
  77. }
  78. ByteSize = BlkIo->Media->BlockSize*NumBlocks;
  79. Buffer = AllocatePool (ByteSize);
  80. if (Buffer) {
  81. Print (L"\n LBA 0x%016lx Size 0x%08x bytes BlkIo 0x%08x\n", BlockAddress, ByteSize, BlkIo);
  82. Status = BlkIo->ReadBlocks(BlkIo, BlkIo->Media->MediaId, BlockAddress, ByteSize, Buffer);
  83. if (Status == EFI_SUCCESS) {
  84. DumpHex (2, 0, ByteSize, Buffer);
  85. EFIStructsPrint (Buffer, BlkIo->Media->BlockSize, BlockAddress, BlkIo);
  86. } else {
  87. Print (L" ERROR in Read %er\n", Status);
  88. }
  89. FreePool (Buffer);
  90. }
  91. return EFI_SUCCESS;
  92. }