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.

227 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. attrib.c
  5. Abstract:
  6. Shell app "attrib"
  7. Revision History
  8. --*/
  9. #include "shell.h"
  10. /*
  11. *
  12. */
  13. EFI_STATUS
  14. InitializeAttrib (
  15. IN EFI_HANDLE ImageHandle,
  16. IN EFI_SYSTEM_TABLE *SystemTable
  17. );
  18. EFI_STATUS
  19. AttribSet (
  20. IN CHAR16 *Str,
  21. IN OUT UINT64 *Attr
  22. );
  23. VOID
  24. AttribFile (
  25. IN SHELL_FILE_ARG *Arg,
  26. IN UINT64 Remove,
  27. IN UINT64 Add
  28. );
  29. BOOLEAN PageBreaks;
  30. UINTN TempColumn;
  31. UINTN ScreenCount;
  32. UINTN ScreenSize;
  33. /*
  34. *
  35. */
  36. EFI_DRIVER_ENTRY_POINT(InitializeAttrib)
  37. EFI_STATUS
  38. InitializeAttrib (
  39. IN EFI_HANDLE ImageHandle,
  40. IN EFI_SYSTEM_TABLE *SystemTable
  41. )
  42. {
  43. CHAR16 **Argv;
  44. UINTN Argc;
  45. UINTN Index;
  46. LIST_ENTRY FileList;
  47. LIST_ENTRY *Link;
  48. SHELL_FILE_ARG *Arg;
  49. UINT64 Remove, Add;
  50. EFI_STATUS Status;
  51. /*
  52. * Check to see if the app is to install as a "internal command"
  53. * to the shell
  54. */
  55. InstallInternalShellCommand (
  56. ImageHandle, SystemTable, InitializeAttrib,
  57. L"attrib", /* command */
  58. L"attrib [-b] [+/- rhs] [file]", /* command syntax */
  59. L"View/sets file attributes", /* 1 line descriptor */
  60. NULL /* command help page */
  61. );
  62. /*
  63. * We are no being installed as an internal command driver, initialize
  64. * as an nshell app and run
  65. */
  66. InitializeShellApplication (ImageHandle, SystemTable);
  67. Argv = SI->Argv;
  68. Argc = SI->Argc;
  69. InitializeListHead (&FileList);
  70. Remove = 0;
  71. Add = 0;
  72. /*
  73. * Expand each arg
  74. */
  75. for (Index = 1; Index < Argc; Index += 1) {
  76. if (Argv[Index][0] == '-') {
  77. /* remove these attributes */
  78. Status = AttribSet (Argv[Index]+1, &Remove);
  79. } else if (Argv[Index][0] == '+') {
  80. /* add these attributes */
  81. Status = AttribSet (Argv[Index]+1, &Add);
  82. } else {
  83. ShellFileMetaArg (Argv[Index], &FileList);
  84. }
  85. if (EFI_ERROR(Status)) {
  86. goto Done;
  87. }
  88. }
  89. /* if no file specified, get the whole directory */
  90. if (IsListEmpty(&FileList)) {
  91. ShellFileMetaArg (L"*", &FileList);
  92. }
  93. /*
  94. * Attrib each file
  95. */
  96. for (Link=FileList.Flink; Link!=&FileList; Link=Link->Flink) {
  97. Arg = CR(Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE);
  98. AttribFile (Arg, Remove, Add);
  99. }
  100. Done:
  101. ShellFreeFileList (&FileList);
  102. return EFI_SUCCESS;
  103. }
  104. EFI_STATUS
  105. AttribSet (
  106. IN CHAR16 *Str,
  107. IN OUT UINT64 *Attr
  108. )
  109. {
  110. while (*Str) {
  111. switch (*Str) {
  112. case 'b' :
  113. case 'B' :
  114. PageBreaks = TRUE;
  115. ST->ConOut->QueryMode (ST->ConOut, ST->ConOut->Mode->Mode, &TempColumn, &ScreenSize);
  116. ScreenCount = 0;
  117. break;
  118. case 'a':
  119. case 'A':
  120. *Attr |= EFI_FILE_ARCHIVE;
  121. break;
  122. case 's':
  123. case 'S':
  124. *Attr |= EFI_FILE_SYSTEM;
  125. break;
  126. case 'h':
  127. case 'H':
  128. *Attr |= EFI_FILE_HIDDEN;
  129. break;
  130. case 'r':
  131. case 'R':
  132. *Attr |= EFI_FILE_READ_ONLY;
  133. break;
  134. default:
  135. Print (L"attr: unknown file attribute %hc\n", *Attr);
  136. return EFI_INVALID_PARAMETER;
  137. }
  138. Str += 1;
  139. }
  140. return EFI_SUCCESS;
  141. }
  142. VOID
  143. AttribFile (
  144. IN SHELL_FILE_ARG *Arg,
  145. IN UINT64 Remove,
  146. IN UINT64 Add
  147. )
  148. {
  149. UINT64 Attr;
  150. EFI_STATUS Status;
  151. EFI_FILE_INFO *Info;
  152. CHAR16 ReturnStr[1];
  153. Status = Arg->Status;
  154. if (EFI_ERROR(Status)) {
  155. goto Done;
  156. }
  157. Info = Arg->Info;
  158. if (Add || Remove) {
  159. Info->Attribute = Info->Attribute & (~Remove) | Add;
  160. Status = Arg->Handle->SetInfo(
  161. Arg->Handle,
  162. &GenericFileInfo,
  163. (UINTN) Info->Size,
  164. Info
  165. );
  166. }
  167. Done:
  168. if (EFI_ERROR(Status)) {
  169. Print (L" %s : %hr\n", Arg->FullName, Status);
  170. } else {
  171. Attr = Info->Attribute;
  172. Print (L"%c%c %c%c%c %s\n",
  173. Attr & EFI_FILE_DIRECTORY ? 'D' : ' ',
  174. Attr & EFI_FILE_ARCHIVE ? 'A' : ' ',
  175. Attr & EFI_FILE_SYSTEM ? 'S' : ' ',
  176. Attr & EFI_FILE_HIDDEN ? 'H' : ' ',
  177. Attr & EFI_FILE_READ_ONLY ? 'R' : ' ',
  178. Arg->FullName
  179. );
  180. }
  181. if (PageBreaks) {
  182. ScreenCount++;
  183. if (ScreenCount > ScreenSize - 4) {
  184. ScreenCount = 0;
  185. Print (L"\nPress Return to contiue :");
  186. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  187. Print (L"\n\n");
  188. }
  189. }
  190. }