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.

145 lines
2.9 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. InitializeMkDir (
  15. IN EFI_HANDLE ImageHandle,
  16. IN EFI_SYSTEM_TABLE *SystemTable
  17. );
  18. VOID
  19. MkDir (
  20. IN SHELL_FILE_ARG *Arg
  21. );
  22. /*
  23. *
  24. */
  25. EFI_DRIVER_ENTRY_POINT(InitializeMkDir)
  26. EFI_STATUS
  27. InitializeMkDir (
  28. IN EFI_HANDLE ImageHandle,
  29. IN EFI_SYSTEM_TABLE *SystemTable
  30. )
  31. {
  32. CHAR16 **Argv;
  33. UINTN Argc;
  34. UINTN Index;
  35. LIST_ENTRY FileList;
  36. LIST_ENTRY *Link;
  37. SHELL_FILE_ARG *Arg;
  38. /*
  39. * Check to see if the app is to install as a "internal command"
  40. * to the shell
  41. */
  42. InstallInternalShellCommand (
  43. ImageHandle, SystemTable, InitializeMkDir,
  44. L"mkdir", /* command */
  45. L"mkdir dir [dir] ...", /* command syntax */
  46. L"Make directory", /* 1 line descriptor */
  47. NULL /* command help page */
  48. );
  49. /*
  50. * We are no being installed as an internal command driver, initialize
  51. * as an nshell app and run
  52. */
  53. InitializeShellApplication (ImageHandle, SystemTable);
  54. Argv = SI->Argv;
  55. Argc = SI->Argc;
  56. /*
  57. * Expand each arg
  58. */
  59. InitializeListHead (&FileList);
  60. for (Index = 1; Index < Argc; Index += 1) {
  61. ShellFileMetaArg (Argv[Index], &FileList);
  62. }
  63. if (IsListEmpty(&FileList)) {
  64. Print (L"mkdir: no directory specified\n");
  65. goto Done;
  66. }
  67. /*
  68. * Make each directory
  69. */
  70. for (Link=FileList.Flink; Link!=&FileList; Link=Link->Flink) {
  71. Arg = CR(Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);
  72. MkDir (Arg);
  73. }
  74. Done:
  75. ShellFreeFileList (&FileList);
  76. return EFI_SUCCESS;
  77. }
  78. VOID
  79. MkDir (
  80. IN SHELL_FILE_ARG *Arg
  81. )
  82. {
  83. EFI_FILE_HANDLE NewDir;
  84. EFI_STATUS Status;
  85. NewDir = NULL;
  86. Status = Arg->Status;
  87. if (!EFI_ERROR(Status)) {
  88. Print (L"mkdir: file %hs already exists\n", Arg->FullName);
  89. return ;
  90. }
  91. if (Status == EFI_NOT_FOUND) {
  92. Status = Arg->Parent->Open (
  93. Arg->Parent,
  94. &NewDir,
  95. Arg->FileName,
  96. EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_CREATE,
  97. EFI_FILE_DIRECTORY
  98. );
  99. }
  100. if (EFI_ERROR(Status)) {
  101. Print (L"mkdir: failed to create %s - %r\n", Arg->FullName, Status);
  102. }
  103. if (NewDir) {
  104. NewDir->Close(NewDir);
  105. }
  106. }