efi_device_path_to_text.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * EFI device path interface
  3. *
  4. * Copyright (c) 2017 Heinrich Schuchardt
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <efi_loader.h>
  10. #define MEDIA_DEVICE_PATH 4
  11. #define FILE_PATH_MEDIA_DEVICE_PATH 4
  12. const efi_guid_t efi_guid_device_path_to_text_protocol =
  13. EFI_DEVICE_PATH_TO_TEXT_PROTOCOL_GUID;
  14. uint16_t *efi_convert_device_node_to_text(
  15. struct efi_device_path_protocol *device_node,
  16. bool display_only,
  17. bool allow_shortcuts)
  18. {
  19. EFI_ENTRY("%p, %d, %d", device_node, display_only, allow_shortcuts);
  20. EFI_EXIT(EFI_UNSUPPORTED);
  21. return NULL;
  22. }
  23. uint16_t *efi_convert_device_path_to_text(
  24. struct efi_device_path_protocol *device_path,
  25. bool display_only,
  26. bool allow_shortcuts)
  27. {
  28. EFI_ENTRY("%p, %d, %d", device_path, display_only, allow_shortcuts);
  29. unsigned long buffer_size;
  30. efi_status_t r;
  31. uint16_t *buffer = NULL;
  32. switch (device_path->type) {
  33. case MEDIA_DEVICE_PATH:
  34. switch (device_path->sub_type) {
  35. case FILE_PATH_MEDIA_DEVICE_PATH:
  36. buffer_size = device_path->length - 4;
  37. r = efi_allocate_pool(EFI_ALLOCATE_ANY_PAGES,
  38. buffer_size, (void **) &buffer);
  39. if (r == EFI_SUCCESS)
  40. memcpy(buffer, device_path->data, buffer_size);
  41. break;
  42. }
  43. }
  44. if (buffer) {
  45. EFI_EXIT(EFI_SUCCESS);
  46. } else {
  47. debug("type %d, subtype %d\n",
  48. device_path->type, device_path->sub_type);
  49. EFI_EXIT(EFI_UNSUPPORTED);
  50. }
  51. return buffer;
  52. }
  53. const struct efi_device_path_to_text_protocol efi_device_path_to_text = {
  54. .convert_device_node_to_text = efi_convert_device_node_to_text,
  55. .convert_device_path_to_text = efi_convert_device_path_to_text,
  56. };