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.

172 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. mkdir.c
  5. Abstract:
  6. Shell app "mkdir"
  7. Revision History
  8. --*/
  9. #include "shell.h"
  10. /*
  11. *
  12. */
  13. EFI_STATUS
  14. InitializeLoad (
  15. IN EFI_HANDLE ImageHandle,
  16. IN EFI_SYSTEM_TABLE *SystemTable
  17. );
  18. VOID
  19. LoadDriver (
  20. IN EFI_HANDLE ImageHandle,
  21. IN SHELL_FILE_ARG *Arg
  22. );
  23. /*
  24. *
  25. */
  26. EFI_DRIVER_ENTRY_POINT(InitializeLoad)
  27. EFI_STATUS
  28. InitializeLoad (
  29. IN EFI_HANDLE ImageHandle,
  30. IN EFI_SYSTEM_TABLE *SystemTable
  31. )
  32. {
  33. CHAR16 **Argv;
  34. UINTN Argc;
  35. UINTN Index;
  36. LIST_ENTRY FileList;
  37. LIST_ENTRY *Link;
  38. SHELL_FILE_ARG *Arg;
  39. /*
  40. * Check to see if the app is to install as a "internal command"
  41. * to the shell
  42. */
  43. InstallInternalShellCommand (
  44. ImageHandle, SystemTable, InitializeLoad,
  45. L"load", /* command */
  46. L"load driver_name", /* command syntax */
  47. L"Loads a driver", /* 1 line descriptor */
  48. NULL /* command help page */
  49. );
  50. /*
  51. * We are no being installed as an internal command driver, initialize
  52. * as an nshell app and run
  53. */
  54. InitializeShellApplication (ImageHandle, SystemTable);
  55. Argv = SI->Argv;
  56. Argc = SI->Argc;
  57. /*
  58. * Expand each arg
  59. */
  60. InitializeListHead (&FileList);
  61. for (Index = 1; Index < Argc; Index += 1) {
  62. ShellFileMetaArg (Argv[Index], &FileList);
  63. }
  64. if (IsListEmpty(&FileList)) {
  65. Print (L"load: no file specified\n");
  66. goto Done;
  67. }
  68. /*
  69. * Make each directory
  70. */
  71. for (Link=FileList.Flink; Link!=&FileList; Link=Link->Flink) {
  72. Arg = CR(Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);
  73. LoadDriver (ImageHandle, Arg);
  74. }
  75. Done:
  76. ShellFreeFileList (&FileList);
  77. return EFI_SUCCESS;
  78. }
  79. VOID
  80. LoadDriver (
  81. IN EFI_HANDLE ParentImage,
  82. IN SHELL_FILE_ARG *Arg
  83. )
  84. {
  85. EFI_HANDLE ImageHandle;
  86. EFI_STATUS Status;
  87. EFI_DEVICE_PATH *NodePath, *FilePath;
  88. EFI_LOADED_IMAGE *ImageInfo;
  89. NodePath = FileDevicePath (NULL, Arg->FileName);
  90. FilePath = AppendDevicePath (Arg->ParentDevicePath, NodePath);
  91. FreePool (NodePath);
  92. Status = BS->LoadImage (
  93. FALSE,
  94. ParentImage,
  95. FilePath,
  96. NULL,
  97. 0,
  98. &ImageHandle
  99. );
  100. FreePool (FilePath);
  101. if (EFI_ERROR(Status)) {
  102. Print (L"load: LoadImage error %s - %r\n", Arg->FullName, Status);
  103. goto Done;
  104. }
  105. /*
  106. * Verify the image is a driver ?
  107. */
  108. BS->HandleProtocol (ImageHandle, &LoadedImageProtocol, (VOID*)&ImageInfo);
  109. if (ImageInfo->ImageCodeType != EfiBootServicesCode &&
  110. ImageInfo->ImageCodeType != EfiRuntimeServicesCode) {
  111. Print (L"load: image %s is not a driver\n", Arg->FullName);
  112. BS->Exit (ImageHandle, EFI_SUCCESS, 0, NULL);
  113. goto Done;
  114. }
  115. /*
  116. * Start the image
  117. */
  118. Status = BS->StartImage (ImageHandle, 0, NULL);
  119. if (!EFI_ERROR(Status)) {
  120. Print (L"load: image %s loaded at %x. returned %r\n",
  121. Arg->FullName,
  122. ImageInfo->ImageBase,
  123. Status
  124. );
  125. } else {
  126. Print (L"load: image %s returned %r\n",
  127. Arg->FullName,
  128. Status
  129. );
  130. }
  131. Done:
  132. ;
  133. }