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.

161 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. vol.c
  5. Abstract:
  6. Shell app "vol"
  7. Revision History
  8. --*/
  9. #include "shell.h"
  10. EFI_STATUS
  11. InitializeVol (
  12. IN EFI_HANDLE ImageHandle,
  13. IN EFI_SYSTEM_TABLE *SystemTable
  14. );
  15. EFI_DRIVER_ENTRY_POINT(InitializeVol)
  16. EFI_STATUS
  17. InitializeVol (
  18. IN EFI_HANDLE ImageHandle,
  19. IN EFI_SYSTEM_TABLE *SystemTable
  20. )
  21. {
  22. CHAR16 *VolumeLabel = NULL;
  23. EFI_STATUS Status;
  24. EFI_DEVICE_PATH *DevicePath;
  25. EFI_FILE_IO_INTERFACE *Vol;
  26. EFI_FILE_HANDLE RootFs;
  27. EFI_FILE_SYSTEM_INFO *VolumeInfo;
  28. UINTN Size;
  29. CHAR16 *CurDir;
  30. UINTN i;
  31. /*
  32. * Check to see if the app is to install as a "internal command"
  33. * to the shell
  34. */
  35. InstallInternalShellCommand (
  36. ImageHandle, SystemTable, InitializeVol,
  37. L"vol", /* command */
  38. L"vol fs [Volume Label]", /* command syntax */
  39. L"Set or display volume label", /* 1 line descriptor */
  40. NULL /* command help page */
  41. );
  42. /*
  43. * We are no being installed as an internal command driver, initialize
  44. * as an nshell app and run
  45. */
  46. InitializeShellApplication (ImageHandle, SystemTable);
  47. /*
  48. *
  49. */
  50. if ( SI->Argc < 1 || SI->Argc > 3 ) {
  51. Print(L"vol [fs] [volume label]\n");
  52. BS->Exit(ImageHandle,EFI_SUCCESS,0,NULL);
  53. }
  54. DevicePath = NULL;
  55. if (SI->Argc == 1) {
  56. CurDir = ShellCurDir(NULL);
  57. if (CurDir) {
  58. for (i=0; i < StrLen(CurDir) && CurDir[i] != ':'; i++);
  59. CurDir[i] = 0;
  60. DevicePath = (EFI_DEVICE_PATH *)ShellGetMap (CurDir);
  61. }
  62. } else {
  63. DevicePath = (EFI_DEVICE_PATH *)ShellGetMap (SI->Argv[1]);
  64. }
  65. if (DevicePath == NULL) {
  66. Print (L"%s is not a mapped short name\n", SI->Argv[1]);
  67. return EFI_INVALID_PARAMETER;
  68. }
  69. Status = LibDevicePathToInterface (&FileSystemProtocol, DevicePath, (VOID **)&Vol);
  70. if (EFI_ERROR(Status)) {
  71. Print (L"%s is not a file system\n",SI->Argv[1]);
  72. return Status;
  73. }
  74. if ( SI->Argc == 3 ) {
  75. VolumeLabel = SI->Argv[2];
  76. if (StrLen(VolumeLabel) > 11) {
  77. Print(L"Volume label %s is longer than 11 characters\n",VolumeLabel);
  78. return EFI_INVALID_PARAMETER;
  79. }
  80. }
  81. Status = Vol->OpenVolume (Vol, &RootFs);
  82. if (EFI_ERROR(Status)) {
  83. Print(L"Can not open the volume %s\n",SI->Argv[1]);
  84. return Status;
  85. }
  86. /*
  87. *
  88. */
  89. Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + 100;
  90. VolumeInfo = (EFI_FILE_SYSTEM_INFO *)AllocatePool(Size);
  91. Status = RootFs->GetInfo(RootFs,&FileSystemInfo,&Size,VolumeInfo);
  92. if (EFI_ERROR(Status)) {
  93. Print(L"Can not get a volume information for %s\n",SI->Argv[1]);
  94. return Status;
  95. }
  96. if (VolumeLabel) {
  97. StrCpy (VolumeInfo->VolumeLabel, VolumeLabel);
  98. Size = SIZE_OF_EFI_FILE_SYSTEM_INFO + StrSize(VolumeLabel);
  99. Status = RootFs->SetInfo(RootFs,&FileSystemInfo,Size,VolumeInfo);
  100. if (EFI_ERROR(Status)) {
  101. Print(L"Can not set volume information for %s\n",SI->Argv[1]);
  102. return Status;
  103. }
  104. Status = RootFs->GetInfo(RootFs,&FileSystemInfo,&Size,VolumeInfo);
  105. if (EFI_ERROR(Status)) {
  106. Print(L"Can not verify a volume information for %s\n",SI->Argv[1]);
  107. return Status;
  108. }
  109. }
  110. if (StrLen(VolumeInfo->VolumeLabel) == 0) {
  111. Print(L"Volume has no label",VolumeInfo->VolumeLabel);
  112. } else {
  113. Print(L"Volume %s",VolumeInfo->VolumeLabel);
  114. }
  115. if (VolumeInfo->ReadOnly) {
  116. Print(L" (ro)\n");
  117. } else {
  118. Print(L" (rw)\n");
  119. }
  120. Print(L" %13,d bytes total disk space\n",VolumeInfo->VolumeSize);
  121. Print(L" %13,d bytes available on disk\n",VolumeInfo->FreeSpace);
  122. Print(L" %13,d bytes in each allocation unit\n",VolumeInfo->BlockSize);
  123. RootFs->Close(RootFs);
  124. return EFI_SUCCESS;
  125. }