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.

206 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. mv.c
  5. Abstract:
  6. Shell app "mv" - moves files on the same volume
  7. Note this app is broke... I only used it to test the rename function
  8. in the SetInfo interface. This app gets confused on simply requests like:
  9. mv \file .
  10. when "." is not the root directory, etc..
  11. Revision History
  12. --*/
  13. #include "shell.h"
  14. /*
  15. *
  16. */
  17. EFI_STATUS
  18. InitializeMv (
  19. IN EFI_HANDLE ImageHandle,
  20. IN EFI_SYSTEM_TABLE *SystemTable
  21. );
  22. VOID
  23. MvFile (
  24. IN SHELL_FILE_ARG *Arg,
  25. IN CHAR16 *NewName
  26. );
  27. /*
  28. *
  29. */
  30. EFI_DRIVER_ENTRY_POINT(InitializeMv)
  31. EFI_STATUS
  32. InitializeMv (
  33. IN EFI_HANDLE ImageHandle,
  34. IN EFI_SYSTEM_TABLE *SystemTable
  35. )
  36. {
  37. CHAR16 **Argv;
  38. UINTN Argc;
  39. UINTN Index;
  40. LIST_ENTRY SrcList;
  41. LIST_ENTRY *Link;
  42. SHELL_FILE_ARG *Arg;
  43. CHAR16 *DestName, *FullDestName;
  44. BOOLEAN DestWild;
  45. CHAR16 *s;
  46. UINTN BufferSize;
  47. /*
  48. * Check to see if the app is to install as a "internal command"
  49. * to the shell
  50. */
  51. InstallInternalShellCommand (
  52. ImageHandle, SystemTable, InitializeMv,
  53. L"mv", /* command */
  54. L"mv sfile dfile", /* command syntax */
  55. L"Moves files", /* 1 line descriptor */
  56. NULL /* command help page */
  57. );
  58. /*
  59. * We are no being installed as an internal command driver, initialize
  60. * as an nshell app and run
  61. */
  62. InitializeShellApplication (ImageHandle, SystemTable);
  63. Argv = SI->Argv;
  64. Argc = SI->Argc;
  65. InitializeListHead (&SrcList);
  66. if (Argc < 3) {
  67. Print (L"mv: sfile dfile\n");
  68. goto Done;
  69. }
  70. /*
  71. * BUGBUG:
  72. * If the last arg has wild cards then perform dos expansion
  73. */
  74. DestWild = FALSE;
  75. DestName = Argv[Argc-1];
  76. for (s = DestName; *s; s += 1) {
  77. if (*s == '*') {
  78. DestWild = TRUE;
  79. }
  80. }
  81. if (DestWild) {
  82. Print (L"mv: bulk rename with '*' not complete\n");
  83. goto Done;
  84. }
  85. /*
  86. * Verify destionation does not include a device mapping
  87. */
  88. for (s = DestName; *s; s += 1) {
  89. if (*s == ':') {
  90. Print (L"mv: dest can not include device mapping\n");
  91. goto Done;
  92. }
  93. if (*s == '\\') {
  94. break;
  95. }
  96. }
  97. /*
  98. * Expand each arg
  99. */
  100. for (Index = 1; Index < Argc-1; Index += 1) {
  101. ShellFileMetaArg (Argv[Index], &SrcList);
  102. }
  103. /*
  104. * If there's only 1 source name, then move it to the dest name
  105. */
  106. Arg = CR(SrcList.Flink, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);
  107. if (Arg->Link.Flink == &SrcList) {
  108. MvFile (Arg, DestName);
  109. } else {
  110. BufferSize = StrSize(DestName) + EFI_FILE_STRING_SIZE;
  111. FullDestName = AllocatePool (BufferSize);
  112. if (!FullDestName) {
  113. Print (L"mv: out of resources\n");
  114. goto Done;
  115. }
  116. for (Link=SrcList.Flink; Link != &SrcList; Link=Link->Flink) {
  117. SPrint (FullDestName, BufferSize, L"%s\\%s", DestName, Arg->FileName);
  118. MvFile (Arg, FullDestName);
  119. }
  120. FreePool (FullDestName);
  121. }
  122. Done:
  123. ShellFreeFileList (&SrcList);
  124. return EFI_SUCCESS;
  125. }
  126. VOID
  127. MvFile (
  128. IN SHELL_FILE_ARG *Arg,
  129. IN CHAR16 *NewName
  130. )
  131. {
  132. EFI_STATUS Status;
  133. EFI_FILE_INFO *Info;
  134. UINTN NameSize;
  135. Status = Arg->Status;
  136. if (!EFI_ERROR(Status)) {
  137. NameSize = StrSize(NewName);
  138. Info = AllocatePool (SIZE_OF_EFI_FILE_INFO + NameSize);
  139. Status = EFI_OUT_OF_RESOURCES;
  140. if (Info) {
  141. CopyMem (Info, Arg->Info, SIZE_OF_EFI_FILE_INFO);
  142. CopyMem (Info->FileName, NewName, NameSize);
  143. Info->Size = SIZE_OF_EFI_FILE_INFO + NameSize;
  144. Status = Arg->Handle->SetInfo(
  145. Arg->Handle,
  146. &GenericFileInfo,
  147. (UINTN) Info->Size,
  148. Info
  149. );
  150. FreePool (Info);
  151. }
  152. }
  153. if (EFI_ERROR(Status)) {
  154. Print (L"mv: %s -> %s : %hr\n", Arg->FullName, NewName, Status);
  155. } else {
  156. Print (L"mv: %s -> %s [ok]\n", Arg->FullName, NewName);
  157. }
  158. }