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.

153 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. io.c
  5. Abstract:
  6. Intialize the shell library
  7. Revision History
  8. --*/
  9. #include "shelllib.h"
  10. CHAR16 *
  11. ShellGetEnv (
  12. IN CHAR16 *Name
  13. )
  14. {
  15. return SE->GetEnv (Name);
  16. }
  17. CHAR16 *
  18. ShellGetMap (
  19. IN CHAR16 *Name
  20. )
  21. {
  22. return SE->GetMap (Name);
  23. }
  24. CHAR16 *
  25. ShellCurDir (
  26. IN CHAR16 *DeviceName OPTIONAL
  27. )
  28. /* N.B. Results are allocated from pool. The caller must free the pool */
  29. {
  30. return SE->CurDir (DeviceName);
  31. }
  32. EFI_STATUS
  33. ShellFileMetaArg (
  34. IN CHAR16 *Arg,
  35. IN OUT LIST_ENTRY *ListHead
  36. )
  37. {
  38. return SE->FileMetaArg(Arg, ListHead);
  39. }
  40. EFI_STATUS
  41. ShellFreeFileList (
  42. IN OUT LIST_ENTRY *ListHead
  43. )
  44. {
  45. return SE->FreeFileList(ListHead);
  46. }
  47. EFI_FILE_HANDLE
  48. ShellOpenFilePath (
  49. IN EFI_DEVICE_PATH *FilePath,
  50. IN UINT64 FileMode
  51. )
  52. {
  53. EFI_HANDLE DeviceHandle;
  54. EFI_STATUS Status;
  55. EFI_FILE_HANDLE FileHandle, LastHandle;
  56. FILEPATH_DEVICE_PATH *FilePathNode;
  57. /*
  58. * File the file system for this file path
  59. */
  60. Status = BS->LocateDevicePath (&FileSystemProtocol, &FilePath, &DeviceHandle);
  61. if (EFI_ERROR(Status)) {
  62. return NULL;
  63. }
  64. /*
  65. * Attempt to access the file via a file system interface
  66. */
  67. FileHandle = LibOpenRoot (DeviceHandle);
  68. Status = FileHandle ? EFI_SUCCESS : EFI_UNSUPPORTED;
  69. /*
  70. * To access as a filesystem, the filepath should only
  71. * contain filepath components. Follow the filepath nodes
  72. * and find the target file
  73. */
  74. FilePathNode = (FILEPATH_DEVICE_PATH *) FilePath;
  75. while (!IsDevicePathEnd(&FilePathNode->Header)) {
  76. /*
  77. * For filesystem access each node should be a filepath component
  78. */
  79. if (DevicePathType(&FilePathNode->Header) != MEDIA_DEVICE_PATH ||
  80. DevicePathSubType(&FilePathNode->Header) != MEDIA_FILEPATH_DP) {
  81. Status = EFI_UNSUPPORTED;
  82. }
  83. /*
  84. * If there's been an error, stop
  85. */
  86. if (EFI_ERROR(Status)) {
  87. break;
  88. }
  89. /*
  90. * Open this file path node
  91. */
  92. LastHandle = FileHandle;
  93. FileHandle = NULL;
  94. Status = LastHandle->Open (
  95. LastHandle,
  96. &FileHandle,
  97. FilePathNode->PathName,
  98. FileMode,
  99. 0
  100. );
  101. /*
  102. * Close the last node
  103. */
  104. LastHandle->Close (LastHandle);
  105. /*
  106. * Get the next node
  107. */
  108. FilePathNode = (FILEPATH_DEVICE_PATH *) NextDevicePathNode(&FilePathNode->Header);
  109. }
  110. if (EFI_ERROR(Status)) {
  111. FileHandle = NULL;
  112. }
  113. return FileHandle;
  114. }