INTN EFIAPI ShellAppMain (IN UINTN Argc, IN CHAR16 **Argv) { CHAR8 c; int i; CHAR8 s[2]; CHAR8 *source2 = source; EFI_FILE_HANDLE handle; UINTN size; for (i = 0; i < 4; i++) write_file(filenames[i], files[i]); ShellOpenFileByName(L"Quine.c", (void**)&handle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0); while (c = *source2++, c) { if (36 == c) { print_escape(handle, files[i++-4]); } else if (126 == c) { print_escape(handle, source); } else { s[0] = c; s[1] = 0; size = AsciiStrSize(s) - 1; FileHandleWrite(handle, &size, s); } } FileHandleClose(handle); Print( L" _____ _____ ___ ___ _ \n" L"| ____| ___|_ _| / _ \\ _ _(_)_ __ ___ \n" L"| _| | |_ | | | | | | | | | | '_ \\ / _ \\\n" L"| |___| _| | | | |_| | |_| | | | | | __/\n" L"|_____|_| |___| \\__\\_\\\\__,_|_|_| |_|\\___|\n" ); return 0; }
void write_file(CHAR16 *filename, CHAR8 *source) { EFI_FILE_HANDLE handle; UINTN size = AsciiStrSize(source) - 1; ShellOpenFileByName(filename, (void**)&handle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0); FileHandleWrite(handle, &size, source); FileHandleClose(handle); }
STATIC EFI_STATUS PrepareFirmwareImage ( IN LIST_ENTRY *CheckPackage, IN OUT SHELL_FILE_HANDLE *FileHandle, IN OUT UINTN **FileBuffer, IN OUT UINT64 *FileSize ) { CONST CHAR16 *FileStr; EFI_STATUS Status; UINT64 OpenMode; UINTN *Buffer; // Parse string from commandline FileStr = ShellCommandLineGetRawValue (CheckPackage, 1); if (FileStr == NULL) { Print (L"%s: No image specified\n", CMD_NAME_STRING); return EFI_INVALID_PARAMETER; } else { Status = ShellIsFile (FileStr); if (EFI_ERROR(Status)) { Print (L"%s: File not found\n", CMD_NAME_STRING); return EFI_INVALID_PARAMETER; } } // Obtain file size OpenMode = EFI_FILE_MODE_READ; Status = ShellOpenFileByName (FileStr, FileHandle, OpenMode, 0); if (EFI_ERROR (Status)) { Print (L"%s: Cannot open Image file\n", CMD_NAME_STRING); return EFI_DEVICE_ERROR; } Status = FileHandleGetSize (*FileHandle, FileSize); if (EFI_ERROR (Status)) { Print (L"%s: Cannot get Image file size\n", CMD_NAME_STRING); } // Read Image header into buffer Buffer = AllocateZeroPool (*FileSize); Status = FileHandleRead (*FileHandle, (UINTN *)FileSize, Buffer); if (EFI_ERROR (Status)) { Print (L"%s: Cannot read Image file header\n", CMD_NAME_STRING); ShellCloseFile (FileHandle); FreePool (Buffer); return EFI_DEVICE_ERROR; } *FileBuffer = Buffer; return EFI_SUCCESS; }
/** Function to verify all intermediate directories in the path. @param[in] Path The pointer to the path to fix. @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS EFIAPI VerifyIntermediateDirectories ( IN CONST CHAR16 *Path ) { EFI_STATUS Status; CHAR16 *PathCopy; CHAR16 *TempSpot; SHELL_FILE_HANDLE FileHandle; ASSERT(Path != NULL); Status = EFI_SUCCESS; PathCopy = NULL; PathCopy = StrnCatGrow(&PathCopy, NULL, Path, 0); FileHandle = NULL; if (PathCopy == NULL) { return (EFI_OUT_OF_RESOURCES); } for (TempSpot = &PathCopy[StrLen(PathCopy)-1] ; *TempSpot != CHAR_NULL && *TempSpot != L'\\' ; TempSpot = &PathCopy[StrLen(PathCopy)-1]){ *TempSpot = CHAR_NULL; } if (*TempSpot == L'\\') { *TempSpot = CHAR_NULL; } if (PathCopy != NULL && *PathCopy != CHAR_NULL) { Status = VerifyIntermediateDirectories(PathCopy); if (PathCopy[StrLen(PathCopy)-1] != L':') { if (!EFI_ERROR(Status)) { Status = ShellOpenFileByName(PathCopy, &FileHandle, EFI_FILE_MODE_READ, 0); if (FileHandle != NULL) { ShellCloseFile(&FileHandle); } } } } SHELL_FREE_NON_NULL(PathCopy); return (Status); }
/** Function to Copy one file to another location If the destination exists the user will be prompted and the result put into *resp @param[in] Source pointer to source file name @param[in] Dest pointer to destination file name @param[out] Resp pointer to response from question. Pass back on looped calling @param[in] SilentMode whether to run in quiet mode or not @retval SHELL_SUCCESS The source file was copied to the destination **/ SHELL_STATUS EFIAPI CopySingleFile( IN CONST CHAR16 *Source, IN CONST CHAR16 *Dest, OUT VOID **Resp, IN BOOLEAN SilentMode ) { VOID *Response; UINTN ReadSize; SHELL_FILE_HANDLE SourceHandle; SHELL_FILE_HANDLE DestHandle; EFI_STATUS Status; VOID *Buffer; CHAR16 *TempName; UINTN Size; EFI_SHELL_FILE_INFO *List; SHELL_STATUS ShellStatus; UINT64 SourceFileSize; UINT64 DestFileSize; EFI_FILE_PROTOCOL *DestVolumeFP; EFI_FILE_SYSTEM_INFO *DestVolumeInfo; UINTN DestVolumeInfoSize; ASSERT(Resp != NULL); SourceHandle = NULL; DestHandle = NULL; Response = *Resp; List = NULL; DestVolumeInfo = NULL; ReadSize = PcdGet16(PcdShellFileOperationSize); // Why bother copying a file to itself if (StrCmp(Source, Dest) == 0) { return (SHELL_SUCCESS); } // // Open destination file without create // Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); // // close file // if (DestHandle != NULL) { ShellCloseFile(&DestHandle); DestHandle = NULL; } // // if the destination file existed check response and possibly prompt user // if (!EFI_ERROR(Status)) { if (Response == NULL && !SilentMode) { Status = ShellPromptForResponseHii(ShellPromptResponseTypeYesNoAllCancel, STRING_TOKEN (STR_GEN_DEST_EXIST_OVR), gShellLevel2HiiHandle, &Response); } // // possibly return based on response // if (!SilentMode) { switch (*(SHELL_PROMPT_RESPONSE*)Response) { case ShellPromptResponseNo: // // return success here so we dont stop the process // return (SHELL_SUCCESS); case ShellPromptResponseCancel: *Resp = Response; // // indicate to stop everything // return (SHELL_ABORTED); case ShellPromptResponseAll: *Resp = Response; case ShellPromptResponseYes: break; default: return SHELL_ABORTED; } } } if (ShellIsDirectory(Source) == EFI_SUCCESS) { Status = ShellCreateDirectory(Dest, &DestHandle); if (EFI_ERROR(Status)) { return (SHELL_ACCESS_DENIED); } // // Now copy all the files under the directory... // TempName = NULL; Size = 0; StrnCatGrow(&TempName, &Size, Source, 0); StrnCatGrow(&TempName, &Size, L"\\*", 0); if (TempName != NULL) { ShellOpenFileMetaArg((CHAR16*)TempName, EFI_FILE_MODE_READ, &List); *TempName = CHAR_NULL; StrnCatGrow(&TempName, &Size, Dest, 0); StrnCatGrow(&TempName, &Size, L"\\", 0); ShellStatus = ValidateAndCopyFiles(List, TempName, SilentMode, TRUE, Resp); ShellCloseFileMetaArg(&List); SHELL_FREE_NON_NULL(TempName); Size = 0; } } else { // // open file with create enabled // Status = ShellOpenFileByName(Dest, &DestHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR(Status)) { return (SHELL_ACCESS_DENIED); } // // open source file // Status = ShellOpenFileByName(Source, &SourceHandle, EFI_FILE_MODE_READ, 0); ASSERT_EFI_ERROR(Status); // //get file size of source file and freespace available on destination volume // ShellGetFileSize(SourceHandle, &SourceFileSize); ShellGetFileSize(DestHandle, &DestFileSize); // //if the destination file already exists then it will be replaced, meaning the sourcefile effectively needs less storage space // if(DestFileSize < SourceFileSize){ SourceFileSize -= DestFileSize; } else { SourceFileSize = 0; } // //get the system volume info to check the free space // DestVolumeFP = ConvertShellHandleToEfiFileProtocol(DestHandle); DestVolumeInfo = NULL; DestVolumeInfoSize = 0; Status = DestVolumeFP->GetInfo( DestVolumeFP, &gEfiFileSystemInfoGuid, &DestVolumeInfoSize, DestVolumeInfo ); if (Status == EFI_BUFFER_TOO_SMALL) { DestVolumeInfo = AllocateZeroPool(DestVolumeInfoSize); Status = DestVolumeFP->GetInfo( DestVolumeFP, &gEfiFileSystemInfoGuid, &DestVolumeInfoSize, DestVolumeInfo ); } // //check if enough space available on destination drive to complete copy // if (DestVolumeInfo->FreeSpace < SourceFileSize) { // //not enough space on destination directory to copy file // SHELL_FREE_NON_NULL(DestVolumeInfo); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_CPY_FAIL), gShellLevel2HiiHandle); return(SHELL_VOLUME_FULL); } else { // // copy data between files // Buffer = AllocateZeroPool(ReadSize); ASSERT(Buffer != NULL); while (ReadSize == PcdGet16(PcdShellFileOperationSize) && !EFI_ERROR(Status)) { Status = ShellReadFile(SourceHandle, &ReadSize, Buffer); Status = ShellWriteFile(DestHandle, &ReadSize, Buffer); } } SHELL_FREE_NON_NULL(DestVolumeInfo); } // // close files // if (DestHandle != NULL) { ShellCloseFile(&DestHandle); DestHandle = NULL; } if (SourceHandle != NULL) { ShellCloseFile(&SourceHandle); SourceHandle = NULL; } // // return // return (SHELL_SUCCESS); }
/** Function to read in HII configuration information from a file. @param[in] Handle The handle to get info for. @param[in] FileName The filename to read the info from. **/ SHELL_STATUS EFIAPI ConfigFromFile( IN EFI_HANDLE Handle, IN CONST CHAR16 *FileName ) { EFI_HII_DATABASE_PROTOCOL *HiiDatabase; EFI_STATUS Status; VOID *MainBuffer; UINT64 Temp; UINTN MainBufferSize; EFI_HII_HANDLE HiiHandle; SHELL_FILE_HANDLE FileHandle; CHAR16 *TempDevPathString; EFI_HII_PACKAGE_LIST_HEADER *PackageListHeader; EFI_HII_PACKAGE_HEADER *PackageHeader; EFI_DEVICE_PATH_PROTOCOL *DevPath; UINTN HandleIndex; HiiDatabase = NULL; MainBufferSize = 0; MainBuffer = NULL; FileHandle = NULL; Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_FILE_OPEN), gShellDriver1HiiHandle, FileName, Status); return (SHELL_DEVICE_ERROR); } // // Locate HII Database protocol // Status = gBS->LocateProtocol ( &gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase ); if (EFI_ERROR(Status) || HiiDatabase == NULL) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_PROTOCOL_NF), gShellDriver1HiiHandle, L"EfiHiiDatabaseProtocol", &gEfiHiiDatabaseProtocolGuid); ShellCloseFile(&FileHandle); return (SHELL_NOT_FOUND); } Status = ShellGetFileSize(FileHandle, &Temp); MainBufferSize = (UINTN)Temp; if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_FILE_READ_FAIL), gShellDriver1HiiHandle, FileName, Status); ShellCloseFile(&FileHandle); return (SHELL_DEVICE_ERROR); } MainBuffer = AllocateZeroPool((UINTN)MainBufferSize); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_OUT_MEM), gShellDriver1HiiHandle); ShellCloseFile(&FileHandle); return (SHELL_DEVICE_ERROR); } Status = ShellReadFile(FileHandle, &MainBufferSize, MainBuffer); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_FILE_READ_FAIL), gShellDriver1HiiHandle, FileName, Status); ShellCloseFile(&FileHandle); SHELL_FREE_NON_NULL(MainBuffer); return (SHELL_DEVICE_ERROR); } ShellCloseFile(&FileHandle); if (Handle != NULL) { // // User override in place. Just do it. // HiiHandle = NULL; Status = ConvertHandleToHiiHandle(Handle, &HiiHandle, HiiDatabase); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, ConvertHandleToHandleIndex(Handle), L"Device"); ShellCloseFile(&FileHandle); return (SHELL_DEVICE_ERROR); } Status = HiiDatabase->UpdatePackageList(HiiDatabase, HiiHandle, MainBuffer); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_UEFI_FUNC_ERROR), gShellDriver1HiiHandle, L"HiiDatabase->UpdatePackageList", Status); return (SHELL_DEVICE_ERROR); } } else { // // we need to parse the buffer and try to match the device paths for each item to try to find it's device path. // for (PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)MainBuffer ; PackageListHeader != NULL && ((CHAR8*)PackageListHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) ; PackageListHeader = (EFI_HII_PACKAGE_LIST_HEADER*)(((CHAR8*)(PackageListHeader)) + PackageListHeader->PackageLength )) { for (PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageListHeader))+sizeof(EFI_HII_PACKAGE_LIST_HEADER)) ; PackageHeader != NULL && ((CHAR8*)PackageHeader) < (((CHAR8*)MainBuffer)+MainBufferSize) && PackageHeader->Type != EFI_HII_PACKAGE_END ; PackageHeader = (EFI_HII_PACKAGE_HEADER*)(((CHAR8*)(PackageHeader))+PackageHeader->Length)) { if (PackageHeader->Type == EFI_HII_PACKAGE_DEVICE_PATH) { HiiHandle = NULL; Status = FindHiiHandleViaDevPath((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), &HiiHandle, HiiDatabase); if (EFI_ERROR(Status)) { // // print out an error. // TempDevPathString = ConvertDevicePathToText((EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)), TRUE, TRUE); ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_DRVCFG_IN_FILE_NF), gShellDriver1HiiHandle, TempDevPathString); SHELL_FREE_NON_NULL(TempDevPathString); } else { Status = HiiDatabase->UpdatePackageList(HiiDatabase, HiiHandle, PackageListHeader); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_UEFI_FUNC_ERROR), gShellDriver1HiiHandle, L"HiiDatabase->UpdatePackageList", Status); return (SHELL_DEVICE_ERROR); } else { DevPath = (EFI_DEVICE_PATH_PROTOCOL*)(((CHAR8*)PackageHeader) + sizeof(EFI_HII_PACKAGE_HEADER)); gBS->LocateDevicePath(&gEfiHiiConfigAccessProtocolGuid, &DevPath, &Handle); HandleIndex = ConvertHandleToHandleIndex(Handle); ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_DRVCFG_DONE_HII), gShellDriver1HiiHandle, HandleIndex); } } } } } } SHELL_FREE_NON_NULL(MainBuffer); ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_DRVCFG_COMP), gShellDriver1HiiHandle); return (SHELL_SUCCESS); }
/** Function to print out all HII configuration information to a file. @param[in] Handle The handle to get info on. NULL to do all handles. @param[in] FileName The filename to rwite the info to. **/ SHELL_STATUS EFIAPI ConfigToFile( IN CONST EFI_HANDLE Handle, IN CONST CHAR16 *FileName ) { EFI_HII_DATABASE_PROTOCOL *HiiDatabase; EFI_STATUS Status; VOID *MainBuffer; UINTN MainBufferSize; EFI_HII_HANDLE HiiHandle; SHELL_FILE_HANDLE FileHandle; HiiDatabase = NULL; MainBufferSize = 0; MainBuffer = NULL; FileHandle = NULL; Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_FILE_OPEN), gShellDriver1HiiHandle, FileName, Status); return (SHELL_DEVICE_ERROR); } // // Locate HII Database protocol // Status = gBS->LocateProtocol ( &gEfiHiiDatabaseProtocolGuid, NULL, (VOID **) &HiiDatabase ); if (EFI_ERROR(Status) || HiiDatabase == NULL) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_PROTOCOL_NF), gShellDriver1HiiHandle, L"EfiHiiDatabaseProtocol", &gEfiHiiDatabaseProtocolGuid); ShellCloseFile(&FileHandle); return (SHELL_NOT_FOUND); } Status = ConvertHandleToHiiHandle(Handle, &HiiHandle, HiiDatabase); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_GEN_HANDLE_NOT), gShellDriver1HiiHandle, ConvertHandleToHandleIndex(Handle), L"Device"); ShellCloseFile(&FileHandle); return (SHELL_DEVICE_ERROR); } Status = HiiDatabase->ExportPackageLists(HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer); if (Status == EFI_BUFFER_TOO_SMALL) { MainBuffer = AllocateZeroPool(MainBufferSize); Status = HiiDatabase->ExportPackageLists(HiiDatabase, HiiHandle, &MainBufferSize, MainBuffer); } Status = ShellWriteFile(FileHandle, &MainBufferSize, MainBuffer); ShellCloseFile(&FileHandle); SHELL_FREE_NON_NULL(MainBuffer); if (EFI_ERROR(Status)) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_FILE_WRITE_FAIL), gShellDriver1HiiHandle, FileName, Status); return (SHELL_DEVICE_ERROR); } ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN(STR_DRVCFG_COMP), gShellDriver1HiiHandle); return (SHELL_SUCCESS); }
/** Do the actual parsing of the file. the file should be SFO output from a shell command or a similar format. @param[in] FileName The filename to open. @param[in] TableName The name of the table to find. @param[in] ColumnIndex The column number to get. @param[in] TableNameInstance Which instance of the table to get (row). @param[in] ShellCommandInstance Which instance of the command to get. @retval SHELL_NOT_FOUND The requested instance was not found. @retval SHELL_SUCCESS The operation was successful. **/ SHELL_STATUS EFIAPI PerformParsing( IN CONST CHAR16 *FileName, IN CONST CHAR16 *TableName, IN CONST UINTN ColumnIndex, IN CONST UINTN TableNameInstance, IN CONST UINTN ShellCommandInstance ) { SHELL_FILE_HANDLE FileHandle; EFI_STATUS Status; BOOLEAN Ascii; UINTN LoopVariable; UINTN ColumnLoop; CHAR16 *TempLine; CHAR16 *ColumnPointer; SHELL_STATUS ShellStatus; CHAR16 *TempSpot; ASSERT(FileName != NULL); ASSERT(TableName != NULL); ShellStatus = SHELL_SUCCESS; Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellLevel2HiiHandle, FileName); ShellStatus = SHELL_NOT_FOUND; } else if (!EFI_ERROR (FileHandleIsDirectory (FileHandle))) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NOT_FILE), gShellLevel2HiiHandle, FileName); ShellStatus = SHELL_NOT_FOUND; } else { for (LoopVariable = 0 ; LoopVariable < ShellCommandInstance && !ShellFileHandleEof(FileHandle);) { TempLine = ShellFileHandleReturnLine(FileHandle, &Ascii); if (TempLine == NULL) { break; } // // Search for "ShellCommand," in the file to start the SFO table // for a given ShellCommand. The UEFI Shell spec does not specify // a space after the comma. // if (StrStr (TempLine, L"ShellCommand,") == TempLine) { LoopVariable++; } SHELL_FREE_NON_NULL(TempLine); } if (LoopVariable == ShellCommandInstance) { LoopVariable = 0; while(1) { TempLine = ShellFileHandleReturnLine(FileHandle, &Ascii); if (TempLine == NULL || *TempLine == CHAR_NULL || StrStr (TempLine, L"ShellCommand,") == TempLine) { SHELL_FREE_NON_NULL(TempLine); break; } if (StrStr (TempLine, TableName) == TempLine) { LoopVariable++; if (LoopVariable == TableNameInstance || (TableNameInstance == (UINTN)-1)) { for (ColumnLoop = 1, ColumnPointer = TempLine; ColumnLoop < ColumnIndex && ColumnPointer != NULL && *ColumnPointer != CHAR_NULL; ColumnLoop++) { ColumnPointer = StrStr (ColumnPointer, L",\""); if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL){ ColumnPointer++; } } if (ColumnLoop == ColumnIndex) { if (ColumnPointer == NULL) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellLevel2HiiHandle, L"Column Index"); ShellStatus = SHELL_INVALID_PARAMETER; } else { TempSpot = StrStr (ColumnPointer, L",\""); if (TempSpot != NULL) { *TempSpot = CHAR_NULL; } while (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L' '){ ColumnPointer++; } if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[0] == L'\"'){ ColumnPointer++; } if (ColumnPointer != NULL && *ColumnPointer != CHAR_NULL && ColumnPointer[StrLen (ColumnPointer) - 1] == L'\"'){ ColumnPointer[StrLen (ColumnPointer) - 1] = CHAR_NULL; } ShellPrintEx (-1, -1, L"%s\r\n", ColumnPointer); } } } } SHELL_FREE_NON_NULL(TempLine); } } } return (ShellStatus); }
/** Function for 'comp' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunComp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; CHAR16 *FileName1; CHAR16 *FileName2; CONST CHAR16 *TempParam; SHELL_STATUS ShellStatus; SHELL_FILE_HANDLE FileHandle1; SHELL_FILE_HANDLE FileHandle2; UINT64 Size1; UINT64 Size2; UINT64 DifferentBytes; UINT64 DifferentCount; UINT8 DiffPointNumber; UINT8 OneByteFromFile1; UINT8 OneByteFromFile2; UINT8 *DataFromFile1; UINT8 *DataFromFile2; UINTN InsertPosition1; UINTN InsertPosition2; UINTN DataSizeFromFile1; UINTN DataSizeFromFile2; UINTN TempAddress; UINTN Index; UINTN DiffPointAddress; READ_STATUS ReadStatus; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; FileName1 = NULL; FileName2 = NULL; FileHandle1 = NULL; FileHandle2 = NULL; DataFromFile1 = NULL; DataFromFile2 = NULL; ReadStatus = OutOfDiffPoint; DifferentCount = 10; DifferentBytes = 4; DiffPointNumber = 0; InsertPosition1 = 0; InsertPosition2 = 0; TempAddress = 0; DiffPointAddress = 0; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); // ASSERT_EFI_ERROR(Status); if (EFI_ERROR(Status)) { return SHELL_UNSUPPORTED; } Status = CommandInit(); // ASSERT_EFI_ERROR(Status); if (EFI_ERROR(Status)) { return SHELL_UNSUPPORTED; } // // parse the command line // Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } /* else { ASSERT(FALSE); } */ } else { if (ShellCommandLineGetCount(Package) > 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) < 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp"); ShellStatus = SHELL_INVALID_PARAMETER; } else { TempParam = ShellCommandLineGetRawValue(Package, 1); ASSERT(TempParam != NULL); FileName1 = ShellFindFilePath(TempParam); if (FileName1 == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; } else { Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; } } TempParam = ShellCommandLineGetRawValue(Package, 2); ASSERT(TempParam != NULL); FileName2 = ShellFindFilePath(TempParam); if (FileName2 == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; } else { Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; } } if (ShellStatus == SHELL_SUCCESS) { Status = gEfiShellProtocol->GetFileSize(FileHandle1, &Size1); ASSERT_EFI_ERROR(Status); Status = gEfiShellProtocol->GetFileSize(FileHandle2, &Size2); ASSERT_EFI_ERROR(Status); if (ShellCommandLineGetFlag (Package, L"-n")) { TempParam = ShellCommandLineGetValue (Package, L"-n"); if (TempParam == NULL) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-n"); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (gUnicodeCollation->StriColl (gUnicodeCollation, (CHAR16 *)TempParam, L"all") == 0) { DifferentCount = MAX_UINTN; } else { Status = ShellConvertStringToUint64 (TempParam, &DifferentCount, FALSE, TRUE); if (EFI_ERROR(Status) || DifferentCount == 0) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-n"); ShellStatus = SHELL_INVALID_PARAMETER; } } } } if (ShellCommandLineGetFlag (Package, L"-s")) { TempParam = ShellCommandLineGetValue (Package, L"-s"); if (TempParam == NULL) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDebug1HiiHandle, L"comp", L"-s"); ShellStatus = SHELL_INVALID_PARAMETER; } else { Status = ShellConvertStringToUint64 (TempParam, &DifferentBytes, FALSE, TRUE); if (EFI_ERROR(Status) || DifferentBytes == 0) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM_VAL), gShellDebug1HiiHandle, L"comp", TempParam, L"-s"); ShellStatus = SHELL_INVALID_PARAMETER; } else { if (DifferentBytes > MAX (Size1, Size2)) { DifferentBytes = MAX (Size1, Size2); } } } } } if (ShellStatus == SHELL_SUCCESS) { DataFromFile1 = AllocateZeroPool ((UINTN)DifferentBytes); DataFromFile2 = AllocateZeroPool ((UINTN)DifferentBytes); if (DataFromFile1 == NULL || DataFromFile2 == NULL) { ShellStatus = SHELL_OUT_OF_RESOURCES; SHELL_FREE_NON_NULL (DataFromFile1); SHELL_FREE_NON_NULL (DataFromFile2); } } if (ShellStatus == SHELL_SUCCESS) { while (DiffPointNumber < DifferentCount) { DataSizeFromFile1 = 1; DataSizeFromFile2 = 1; OneByteFromFile1 = 0; OneByteFromFile2 = 0; Status = gEfiShellProtocol->ReadFile (FileHandle1, &DataSizeFromFile1, &OneByteFromFile1); ASSERT_EFI_ERROR (Status); Status = gEfiShellProtocol->ReadFile (FileHandle2, &DataSizeFromFile2, &OneByteFromFile2); ASSERT_EFI_ERROR (Status); TempAddress++; // // 1.When end of file and no chars in DataFromFile buffer, then break while. // 2.If no more char in File1 or File2, The ReadStatus is InPrevDiffPoint forever. // So the previous different point is the last one, then break the while block. // if ( (DataSizeFromFile1 == 0 && InsertPosition1 == 0 && DataSizeFromFile2 == 0 && InsertPosition2 == 0) || (ReadStatus == InPrevDiffPoint && (DataSizeFromFile1 == 0 || DataSizeFromFile2 == 0)) ) { break; } if (ReadStatus == OutOfDiffPoint) { if (OneByteFromFile1 != OneByteFromFile2) { ReadStatus = InDiffPoint; DiffPointAddress = TempAddress; if (DataSizeFromFile1 == 1) { DataFromFile1[InsertPosition1++] = OneByteFromFile1; } if (DataSizeFromFile2 == 1) { DataFromFile2[InsertPosition2++] = OneByteFromFile2; } } } else if (ReadStatus == InDiffPoint) { if (DataSizeFromFile1 == 1) { DataFromFile1[InsertPosition1++] = OneByteFromFile1; } if (DataSizeFromFile2 == 1) { DataFromFile2[InsertPosition2++] = OneByteFromFile2; } } else if (ReadStatus == InPrevDiffPoint) { if (OneByteFromFile1 == OneByteFromFile2) { ReadStatus = OutOfDiffPoint; } } // // ReadStatus should be always equal InDiffPoint. // if ( InsertPosition1 == DifferentBytes || InsertPosition2 == DifferentBytes || (DataSizeFromFile1 == 0 && DataSizeFromFile2 == 0) ) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_COMP_DIFFERENCE_POINT), gShellDebug1HiiHandle, ++DiffPointNumber); PrintDifferentPoint (FileName1, L"File1", DataFromFile1, InsertPosition1, DiffPointAddress, DifferentBytes); PrintDifferentPoint (FileName2, L"File2", DataFromFile2, InsertPosition2, DiffPointAddress, DifferentBytes); // // One of two buffuers is empty, it means this is the last different point. // if (InsertPosition1 == 0 || InsertPosition2 == 0) { break; } for (Index = 1; Index < InsertPosition1 && Index < InsertPosition2; Index++) { if (DataFromFile1[Index] == DataFromFile2[Index]) { ReadStatus = OutOfDiffPoint; break; } } if (ReadStatus == OutOfDiffPoint) { // // Try to find a new different point in the rest of DataFromFile. // for (; Index < MAX (InsertPosition1,InsertPosition2); Index++) { if (DataFromFile1[Index] != DataFromFile2[Index]) { ReadStatus = InDiffPoint; DiffPointAddress += Index; break; } } } else { // // Doesn't find a new different point, still in the same different point. // ReadStatus = InPrevDiffPoint; } CopyMem (DataFromFile1, DataFromFile1 + Index, InsertPosition1 - Index); CopyMem (DataFromFile2, DataFromFile2 + Index, InsertPosition2 - Index); SetMem (DataFromFile1 + InsertPosition1 - Index, (UINTN)DifferentBytes - InsertPosition1 + Index, 0); SetMem (DataFromFile2 + InsertPosition2 - Index, (UINTN)DifferentBytes - InsertPosition2 + Index, 0); InsertPosition1 -= Index; InsertPosition2 -= Index; } } SHELL_FREE_NON_NULL (DataFromFile1); SHELL_FREE_NON_NULL (DataFromFile2); if (DiffPointNumber == 0) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); } } } ShellCommandLineFreeVarList (Package); } SHELL_FREE_NON_NULL(FileName1); SHELL_FREE_NON_NULL(FileName2); if (FileHandle1 != NULL) { gEfiShellProtocol->CloseFile(FileHandle1); } if (FileHandle2 != NULL) { gEfiShellProtocol->CloseFile(FileHandle2); } return (ShellStatus); }
/** Function for 'tftp' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). @return SHELL_SUCCESS The 'tftp' command completed successfully. @return SHELL_ABORTED The Shell Library initialization failed. @return SHELL_INVALID_PARAMETER At least one of the command's arguments is not valid. @return SHELL_OUT_OF_RESOURCES A memory allocation failed. @return SHELL_NOT_FOUND Network Interface Card not found or server error or file error. **/ SHELL_STATUS EFIAPI ShellCommandRunTftp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { SHELL_STATUS ShellStatus; EFI_STATUS Status; LIST_ENTRY *CheckPackage; CHAR16 *ProblemParam; UINTN ParamCount; CONST CHAR16 *UserNicName; BOOLEAN NicFound; CONST CHAR16 *ValueStr; CONST CHAR16 *RemoteFilePath; CHAR8 *AsciiRemoteFilePath; CONST CHAR16 *Walker; CONST CHAR16 *LocalFilePath; EFI_MTFTP4_CONFIG_DATA Mtftp4ConfigData; EFI_HANDLE *Handles; UINTN HandleCount; UINTN NicNumber; CHAR16 NicName[IP4_CONFIG2_INTERFACE_INFO_NAME_LENGTH]; EFI_HANDLE ControllerHandle; EFI_HANDLE Mtftp4ChildHandle; EFI_MTFTP4_PROTOCOL *Mtftp4; UINTN FileSize; VOID *Data; SHELL_FILE_HANDLE FileHandle; ShellStatus = SHELL_INVALID_PARAMETER; ProblemParam = NULL; NicFound = FALSE; AsciiRemoteFilePath = NULL; Handles = NULL; FileSize = 0; // // Initialize the Shell library (we must be in non-auto-init...) // Status = ShellInitialize (); if (EFI_ERROR (Status)) { ASSERT_EFI_ERROR (Status); return SHELL_ABORTED; } // // Parse the command line. // Status = ShellCommandLineParse (ParamList, &CheckPackage, &ProblemParam, TRUE); if (EFI_ERROR (Status)) { if ((Status == EFI_VOLUME_CORRUPTED) && (ProblemParam != NULL) ) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellTftpHiiHandle, L"tftp", ProblemParam ); FreePool (ProblemParam); } else { ASSERT (FALSE); } goto Error; } // // Check the number of parameters // ParamCount = ShellCommandLineGetCount (CheckPackage); if (ParamCount > 4) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellTftpHiiHandle, L"tftp" ); goto Error; } if (ParamCount < 3) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellTftpHiiHandle, L"tftp" ); goto Error; } Mtftp4ConfigData = DefaultMtftp4ConfigData; // // Check the host IPv4 address // ValueStr = ShellCommandLineGetRawValue (CheckPackage, 1); Status = NetLibStrToIp4 (ValueStr, &Mtftp4ConfigData.ServerIp); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellTftpHiiHandle, L"tftp", ValueStr ); goto Error; } RemoteFilePath = ShellCommandLineGetRawValue (CheckPackage, 2); AsciiRemoteFilePath = AllocatePool ( (StrLen (RemoteFilePath) + 1) * sizeof (CHAR8) ); if (AsciiRemoteFilePath == NULL) { ShellStatus = SHELL_OUT_OF_RESOURCES; goto Error; } UnicodeStrToAsciiStr (RemoteFilePath, AsciiRemoteFilePath); if (ParamCount == 4) { LocalFilePath = ShellCommandLineGetRawValue (CheckPackage, 3); } else { Walker = RemoteFilePath + StrLen (RemoteFilePath); while ((--Walker) >= RemoteFilePath) { if ((*Walker == L'\\') || (*Walker == L'/' ) ) { break; } } LocalFilePath = Walker + 1; } // // Get the name of the Network Interface Card to be used if any. // UserNicName = ShellCommandLineGetValue (CheckPackage, L"-i"); ValueStr = ShellCommandLineGetValue (CheckPackage, L"-l"); if (ValueStr != NULL) { if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.LocalPort)) { goto Error; } } ValueStr = ShellCommandLineGetValue (CheckPackage, L"-r"); if (ValueStr != NULL) { if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.InitialServerPort)) { goto Error; } } ValueStr = ShellCommandLineGetValue (CheckPackage, L"-c"); if (ValueStr != NULL) { if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.TryCount)) { goto Error; } } ValueStr = ShellCommandLineGetValue (CheckPackage, L"-t"); if (ValueStr != NULL) { if (!StringToUint16 (ValueStr, &Mtftp4ConfigData.TimeoutValue)) { goto Error; } if (Mtftp4ConfigData.TimeoutValue == 0) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_PARAM_INV), gShellTftpHiiHandle, L"tftp", ValueStr ); goto Error; } } // // Locate all MTFTP4 Service Binding protocols // ShellStatus = SHELL_NOT_FOUND; Status = gBS->LocateHandleBuffer ( ByProtocol, &gEfiManagedNetworkServiceBindingProtocolGuid, NULL, &HandleCount, &Handles ); if (EFI_ERROR (Status) || (HandleCount == 0)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NO_NIC), gShellTftpHiiHandle ); goto Error; } for (NicNumber = 0; (NicNumber < HandleCount) && (ShellStatus != SHELL_SUCCESS); NicNumber++) { ControllerHandle = Handles[NicNumber]; Data = NULL; Status = GetNicName (ControllerHandle, NicNumber, NicName); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NAME), gShellTftpHiiHandle, NicNumber, Status ); continue; } if (UserNicName != NULL) { if (StrCmp (NicName, UserNicName) != 0) { continue; } NicFound = TRUE; } Status = CreateServiceChildAndOpenProtocol ( ControllerHandle, &gEfiMtftp4ServiceBindingProtocolGuid, &gEfiMtftp4ProtocolGuid, &Mtftp4ChildHandle, (VOID**)&Mtftp4 ); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_OPEN_PROTOCOL), gShellTftpHiiHandle, NicName, Status ); continue; } Status = Mtftp4->Configure (Mtftp4, &Mtftp4ConfigData); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_CONFIGURE), gShellTftpHiiHandle, NicName, Status ); goto NextHandle; } Status = GetFileSize (Mtftp4, AsciiRemoteFilePath, &FileSize); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_FILE_SIZE), gShellTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } Status = DownloadFile (Mtftp4, RemoteFilePath, AsciiRemoteFilePath, FileSize, &Data); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_DOWNLOAD), gShellTftpHiiHandle, RemoteFilePath, NicName, Status ); goto NextHandle; } if (!EFI_ERROR (ShellFileExists (LocalFilePath))) { ShellDeleteFileByName (LocalFilePath); } Status = ShellOpenFileByName ( LocalFilePath, &FileHandle, EFI_FILE_MODE_CREATE | EFI_FILE_MODE_WRITE | EFI_FILE_MODE_READ, 0 ); if (EFI_ERROR (Status)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellTftpHiiHandle, L"tftp", LocalFilePath ); goto NextHandle; } Status = ShellWriteFile (FileHandle, &FileSize, Data); if (!EFI_ERROR (Status)) { ShellStatus = SHELL_SUCCESS; } else { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_WRITE), gShellTftpHiiHandle, LocalFilePath, Status ); } ShellCloseFile (&FileHandle); NextHandle: if (Data != NULL) { gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)Data, EFI_SIZE_TO_PAGES (FileSize)); } CloseProtocolAndDestroyServiceChild ( ControllerHandle, &gEfiMtftp4ServiceBindingProtocolGuid, &gEfiMtftp4ProtocolGuid, Mtftp4ChildHandle ); } if ((UserNicName != NULL) && (!NicFound)) { ShellPrintHiiEx ( -1, -1, NULL, STRING_TOKEN (STR_TFTP_ERR_NIC_NOT_FOUND), gShellTftpHiiHandle, UserNicName ); } Error: ShellCommandLineFreeVarList (CheckPackage); if (AsciiRemoteFilePath != NULL) { FreePool (AsciiRemoteFilePath); } if (Handles != NULL) { FreePool (Handles); } return ShellStatus; }
/** Function for 'setsize' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunSetSize ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; CONST CHAR16 *Temp1; UINTN NewSize; UINTN LoopVar; SHELL_FILE_HANDLE FileHandle; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"setsize", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) < 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_INVALID_PARAMETER; NewSize = 0; } else { Temp1 = ShellCommandLineGetRawValue(Package, 1); if (!ShellIsHexOrDecimalNumber(Temp1, FALSE, FALSE)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SIZE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_INVALID_PARAMETER; NewSize = 0; } else { NewSize = ShellStrToUintn(Temp1); } } for (LoopVar = 2 ; LoopVar < ShellCommandLineGetCount(Package) && ShellStatus == SHELL_SUCCESS ; LoopVar++) { Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); if (EFI_ERROR(Status)) { Status = ShellOpenFileByName(ShellCommandLineGetRawValue(Package, LoopVar), &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); } if (EFI_ERROR(Status) && LoopVar == 2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_SPEC), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue(Package, LoopVar)); ShellStatus = SHELL_INVALID_PARAMETER; break; } else { Status = FileHandleSetSize(FileHandle, NewSize); if (Status == EFI_VOLUME_FULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_VOLUME_FULL), gShellDebug1HiiHandle, L"setsize"); ShellStatus = SHELL_VOLUME_FULL; } else if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_FAIL), gShellDebug1HiiHandle, L"setsize", ShellCommandLineGetRawValue(Package, LoopVar)); ShellStatus = SHELL_INVALID_PARAMETER; } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_SET_SIZE_DONE), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, LoopVar)); } ShellCloseFile(&FileHandle); } } ShellCommandLineFreeVarList (Package); } return (ShellStatus); }
/** Function for 'decompress' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunEfiDecompress ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; SHELL_FILE_HANDLE InFileHandle; SHELL_FILE_HANDLE OutFileHandle; UINT32 OutSize; UINTN OutSizeTemp; VOID *OutBuffer; UINTN InSize; VOID *InBuffer; CHAR16 *InFileName; CONST CHAR16 *OutFileName; UINT64 Temp64Bit; UINT32 ScratchSize; VOID *ScratchBuffer; EFI_DECOMPRESS_PROTOCOL *Decompress; CONST CHAR16 *TempParam; InFileName = NULL; OutFileName = NULL; OutSize = 0; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; OutBuffer = NULL; InBuffer = NULL; ScratchBuffer = NULL; InFileHandle = NULL; OutFileHandle = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) > 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) < 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle); ShellStatus = SHELL_INVALID_PARAMETER; } else { TempParam = ShellCommandLineGetRawValue(Package, 1); ASSERT(TempParam != NULL); InFileName = ShellFindFilePath(TempParam); OutFileName = ShellCommandLineGetRawValue(Package, 2); if (InFileName == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, TempParam); ShellStatus = SHELL_NOT_FOUND; } else { if (ShellIsDirectory(InFileName) == EFI_SUCCESS){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, InFileName); ShellStatus = SHELL_INVALID_PARAMETER; } if (ShellIsDirectory(OutFileName) == EFI_SUCCESS){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, OutFileName); ShellStatus = SHELL_INVALID_PARAMETER; } if (ShellStatus == SHELL_SUCCESS) { Status = ShellOpenFileByName(InFileName, &InFileHandle, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 1), Status); ShellStatus = SHELL_NOT_FOUND; } Status = ShellOpenFileByName(OutFileName, &OutFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_OPEN_FAIL), gShellDebug1HiiHandle, ShellCommandLineGetRawValue(Package, 2), Status); ShellStatus = SHELL_NOT_FOUND; } } if (ShellStatus == SHELL_SUCCESS) { Status = FileHandleGetSize(InFileHandle, &Temp64Bit); ASSERT(Temp64Bit <= (UINT32)(-1)); InSize = (UINTN)Temp64Bit; ASSERT_EFI_ERROR(Status); InBuffer = AllocateZeroPool(InSize); ASSERT(InBuffer != NULL); Status = gEfiShellProtocol->ReadFile(InFileHandle, &InSize, InBuffer); ASSERT_EFI_ERROR(Status); Status = gBS->LocateProtocol(&gEfiDecompressProtocolGuid, NULL, (VOID**)&Decompress); ASSERT_EFI_ERROR(Status); Status = Decompress->GetInfo(Decompress, InBuffer, (UINT32)InSize, &OutSize, &ScratchSize); ASSERT_EFI_ERROR(Status); OutBuffer = AllocateZeroPool(OutSize); ScratchBuffer = AllocateZeroPool(ScratchSize); ASSERT(OutBuffer != NULL); ASSERT(ScratchBuffer != NULL); Status = Decompress->Decompress(Decompress, InBuffer, (UINT32)InSize, OutBuffer, OutSize, ScratchBuffer, ScratchSize); ASSERT_EFI_ERROR(Status); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_DECOMPRESS_FAIL), gShellDebug1HiiHandle, Status); ShellStatus = SHELL_DEVICE_ERROR; } else { OutSizeTemp = OutSize; Status = gEfiShellProtocol->WriteFile(OutFileHandle, &OutSizeTemp, OutBuffer); OutSize = (UINT32)OutSizeTemp; if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, OutFileName, Status); ShellStatus = SHELL_DEVICE_ERROR; } } } } } ShellCommandLineFreeVarList (Package); } if (InFileHandle != NULL) { gEfiShellProtocol->CloseFile(InFileHandle); } if (OutFileHandle != NULL) { gEfiShellProtocol->CloseFile(OutFileHandle); } SHELL_FREE_NON_NULL(InFileName); SHELL_FREE_NON_NULL(InBuffer); SHELL_FREE_NON_NULL(OutBuffer); SHELL_FREE_NON_NULL(ScratchBuffer); return (ShellStatus); }
/** Function for 'comp' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunComp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; UINTN LoopVar; SHELL_FILE_HANDLE FileHandle1; SHELL_FILE_HANDLE FileHandle2; UINT8 ErrorCount; UINT64 Size1; UINT64 Size2; UINT8 DataFromFile1; UINT8 DataFromFile2; UINT8 ADF_File11; UINT8 ADF_File12; UINT8 ADF_File13; UINT8 ADF_File21; UINT8 ADF_File22; UINT8 ADF_File23; UINTN DataSizeFromFile1; UINTN DataSizeFromFile2; CHAR16 *FileName1; CHAR16 *FileName2; CONST CHAR16 *TempParam; UINTN ErrorAddress; ErrorCount = 0; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; FileName1 = NULL; FileName2 = NULL; FileHandle1 = NULL; FileHandle2 = NULL; Size1 = 0; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"comp", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) > 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"comp"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) < 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"comp"); ShellStatus = SHELL_INVALID_PARAMETER; } else { TempParam = ShellCommandLineGetRawValue(Package, 1); ASSERT(TempParam != NULL); FileName1 = ShellFindFilePath(TempParam); if (FileName1 == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; } else { Status = ShellOpenFileByName(FileName1, &FileHandle1, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; } } TempParam = ShellCommandLineGetRawValue(Package, 2); ASSERT(TempParam != NULL); FileName2 = ShellFindFilePath(TempParam); if (FileName2 == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; } else { Status = ShellOpenFileByName(FileName2, &FileHandle2, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"comp", TempParam); ShellStatus = SHELL_NOT_FOUND; } } if (ShellStatus == SHELL_SUCCESS) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_HEADER), gShellDebug1HiiHandle, FileName1, FileName2); Status = gEfiShellProtocol->GetFileSize(FileHandle1, &Size1); ASSERT_EFI_ERROR(Status); Status = gEfiShellProtocol->GetFileSize(FileHandle2, &Size2); ASSERT_EFI_ERROR(Status); if (Size1 != Size2) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_SIZE_FAIL), gShellDebug1HiiHandle); ErrorCount++; ShellStatus = SHELL_NOT_EQUAL; } } if (ShellStatus == SHELL_SUCCESS) { for (LoopVar = 0 ; LoopVar < Size1 && ErrorCount <= 10 ; LoopVar++) { DataSizeFromFile1 = 1; DataSizeFromFile2 = 1; Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &DataFromFile1); ASSERT_EFI_ERROR(Status); Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &DataFromFile2); ASSERT_EFI_ERROR(Status); if (DataFromFile1 != DataFromFile2) { ErrorAddress = LoopVar; ADF_File11 = 0; ADF_File12 = 0; ADF_File13 = 0; ADF_File21 = 0; ADF_File22 = 0; ADF_File23 = 0; // // Now check the next 3 bytes if possible. This will make output // cleaner when there are a sequence of differences. // if (LoopVar + 1 < Size1) { LoopVar++; DataSizeFromFile1 = 1; DataSizeFromFile2 = 1; Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File11); ASSERT_EFI_ERROR(Status); Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File21); ASSERT_EFI_ERROR(Status); if (LoopVar + 1 < Size1) { LoopVar++; DataSizeFromFile1 = 1; DataSizeFromFile2 = 1; Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File12); ASSERT_EFI_ERROR(Status); Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File22); ASSERT_EFI_ERROR(Status); if (LoopVar + 1 < Size1) { LoopVar++; DataSizeFromFile1 = 1; DataSizeFromFile2 = 1; Status = gEfiShellProtocol->ReadFile(FileHandle1, &DataSizeFromFile1, &ADF_File13); ASSERT_EFI_ERROR(Status); Status = gEfiShellProtocol->ReadFile(FileHandle2, &DataSizeFromFile2, &ADF_File23); ASSERT_EFI_ERROR(Status); } } } // // Print out based on highest of the 4 bytes that are different. // if (ADF_File13 != ADF_File23) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_COMP_SPOT_FAIL4), gShellDebug1HiiHandle, ++ErrorCount, FileName1, ErrorAddress, DataFromFile1, ADF_File11, ADF_File12, ADF_File13, DataFromFile1, ADF_File11, ADF_File12, ADF_File13, FileName2, ErrorAddress, DataFromFile2, ADF_File21, ADF_File22, ADF_File23, DataFromFile2, ADF_File21, ADF_File22, ADF_File23 ); } else if (ADF_File12 != ADF_File22) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_COMP_SPOT_FAIL3), gShellDebug1HiiHandle, ++ErrorCount, FileName1, ErrorAddress, DataFromFile1, ADF_File11, ADF_File12, DataFromFile1, ADF_File11, ADF_File12, FileName2, ErrorAddress, DataFromFile2, ADF_File21, ADF_File22, DataFromFile2, ADF_File21, ADF_File22 ); } else if (ADF_File11 != ADF_File21) { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_COMP_SPOT_FAIL2), gShellDebug1HiiHandle, ++ErrorCount, FileName1, ErrorAddress, DataFromFile1, ADF_File11, DataFromFile1, ADF_File11, FileName2, ErrorAddress, DataFromFile2, ADF_File21, DataFromFile2, ADF_File21 ); } else { ShellPrintHiiEx( -1, -1, NULL, STRING_TOKEN (STR_COMP_SPOT_FAIL1), gShellDebug1HiiHandle, ++ErrorCount, FileName1, ErrorAddress, DataFromFile1, DataFromFile1, FileName2, ErrorAddress, DataFromFile2, DataFromFile2 ); } ShellStatus = SHELL_NOT_EQUAL; } } if (ErrorCount == 0) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_PASS), gShellDebug1HiiHandle); } else { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_COMP_FOOTER_FAIL), gShellDebug1HiiHandle); } } } ShellCommandLineFreeVarList (Package); } SHELL_FREE_NON_NULL(FileName1); SHELL_FREE_NON_NULL(FileName2); if (FileHandle1 != NULL) { gEfiShellProtocol->CloseFile(FileHandle1); } if (FileHandle2 != NULL) { gEfiShellProtocol->CloseFile(FileHandle2); } return (ShellStatus); }
/** Function for 'mkdir' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunMkDir ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; CONST CHAR16 *NewDirName; UINTN DirCreateCount; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_FILE_HANDLE FileHandle; SHELL_STATUS ShellStatus; ShellStatus = SHELL_SUCCESS; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mkdir", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } // // create a set of directories // if (ShellCommandLineGetRawValue(Package, 1) == NULL) { // // we didnt get a single parameter // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mkdir"); ShellStatus = SHELL_INVALID_PARAMETER; } else { for ( DirCreateCount = 1 ; ; DirCreateCount++ ){ // // loop through each directory specified // NewDirName = ShellCommandLineGetRawValue(Package, DirCreateCount); if (NewDirName == NULL) { break; } // // check if that already exists... if yes fail // FileHandle = NULL; Status = ShellOpenFileByName(NewDirName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, EFI_FILE_DIRECTORY ); if (!EFI_ERROR(Status)) { ShellCloseFile(&FileHandle); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName); ShellStatus = SHELL_INVALID_PARAMETER; break; } else { ASSERT(FileHandle == NULL); // // create the directory named NewDirName // Status = ShellCreateDirectory(NewDirName, &FileHandle); if (FileHandle != NULL) { gEfiShellProtocol->CloseFile(FileHandle); } if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName); ShellStatus = SHELL_ACCESS_DENIED; break; } } } } } // // free the command line package // ShellCommandLineFreeVarList (Package); return (ShellStatus); }
STATIC EFI_STATUS ReadFileData ( IN CHAR16 *FileName, OUT UINT8 **Buffer, OUT UINT32 *BufferSize ) { EFI_STATUS Status; SHELL_FILE_HANDLE FileHandle; UINT64 Size; VOID *NewBuffer; UINTN ReadSize; FileHandle = NULL; NewBuffer = NULL; Size = 0; Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ, 0); if (EFI_ERROR (Status)) { goto Done; } Status = FileHandleIsDirectory (FileHandle); if (!EFI_ERROR (Status)) { Status = EFI_NOT_FOUND; goto Done; } Status = FileHandleGetSize (FileHandle, &Size); if (EFI_ERROR (Status)) { goto Done; } NewBuffer = AllocatePool ((UINTN) Size); ReadSize = (UINTN) Size; Status = FileHandleRead (FileHandle, &ReadSize, NewBuffer); if (EFI_ERROR (Status)) { goto Done; } else if (ReadSize != (UINTN) Size) { Status = EFI_INVALID_PARAMETER; goto Done; } Done: if (FileHandle != NULL) { ShellCloseFile (&FileHandle); } if (EFI_ERROR (Status)) { if (NewBuffer != NULL) { FreePool (NewBuffer); } } else { *Buffer = NewBuffer; *BufferSize = (UINT32) Size; } return Status; }
/** as the real entry point for the application. @param[in] ImageHandle The firmware allocated handle for the EFI image. @param[in] SystemTable A pointer to the EFI System Table. @retval EFI_SUCCESS The entry point is executed successfully. @retval other Some error occurs when executing this entry point. **/ EFI_STATUS EFIAPI UefiMain ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_FILE_HANDLE FileHandle; EFI_STATUS Status; CHAR16 FileName[100]; UINTN BufferSize; UINT64 Position; UINT8 Buffer[200]; EFI_FILE_INFO *pFileInfo; UINT64 Size; BOOLEAN NoFile; EFI_SHELL_FILE_INFO *pShellFileInfo; LIST_ENTRY *List; // CONST CHAR16 *Tester; FileHandle = NULL; StrCpy(FileName, L"testfile.txt"); // Position = 0; pFileInfo = NULL; Size = 0; NoFile = FALSE; pShellFileInfo = NULL; List = NULL; // command line param functions Status = ShellCommandLineParse(ParamList, &List, NULL, FALSE); // if you put an invalid parameter you SHOULD hit this assert. ASSERT_EFI_ERROR(Status); if (List) { ASSERT(ShellCommandLineGetFlag(List, L"/Param5") == FALSE); ASSERT(ShellCommandLineGetFlag(List, L"/Param1") != FALSE); ASSERT(StrCmp(ShellCommandLineGetValue(List, L"/Param2"), L"Val1")==0); ASSERT(StrCmp(ShellCommandLineGetRawValue(List, 0), L"SimpleApplication.efi")==0); // Tester = ShellCommandLineGetValue(List, L"/Param3"); // Tester = ShellCommandLineGetValue(List, L"/Param4"); ShellCommandLineFreeVarList(List); } else { Print(L"param checking skipped.\r\n"); } // return (EFI_SUCCESS); ASSERT(ShellGetExecutionBreakFlag() == FALSE); ASSERT(StrCmp(ShellGetCurrentDir(NULL), L"f10:\\") == 0); Print(L"execution break and get cur dir - pass\r\n"); ShellSetPageBreakMode(TRUE); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); BufferSize = StrSize(FileName); Status = ShellWriteFile(FileHandle, &BufferSize, FileName); ASSERT_EFI_ERROR(Status); Status = ShellGetFilePosition(FileHandle, &Position); ASSERT_EFI_ERROR(Status); ASSERT(Position == 0x1A); Status = ShellSetFilePosition(FileHandle, 0); ASSERT_EFI_ERROR(Status); BufferSize = sizeof(Buffer) * sizeof(Buffer[0]); Status = ShellReadFile(FileHandle, &BufferSize, Buffer); ASSERT_EFI_ERROR(Status); ASSERT(BufferSize == 0x1A); ASSERT(StrCmp((CHAR16*)Buffer, FileName) == 0); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->FileSize == 0x1A); FreePool(pFileInfo); pFileInfo = NULL; Status = ShellCloseFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"read, write, create, getinfo - pass\r\n"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); pFileInfo->FileSize = 0x20; Status = ShellSetFileInfo(FileHandle, pFileInfo); FreePool(pFileInfo); pFileInfo = NULL; ASSERT_EFI_ERROR(Status); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->PhysicalSize == 0x20); ASSERT(pFileInfo->FileSize == 0x20); ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0); FreePool(pFileInfo); Status = ShellGetFileSize(FileHandle, &Size); ASSERT(Size == 0x20); ASSERT_EFI_ERROR(Status); Status = ShellCloseFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"setinfo and change size, getsize - pass\r\n"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->PhysicalSize == 0x20); ASSERT(pFileInfo->FileSize == 0x20); ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0); FreePool(pFileInfo); pFileInfo = NULL; Status = ShellDeleteFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"reopen file - pass\r\n"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->PhysicalSize == 0x0); ASSERT(pFileInfo->FileSize == 0x0); ASSERT((pFileInfo->Attribute&EFI_FILE_DIRECTORY)==0); FreePool(pFileInfo); Status = ShellDeleteFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"size of empty - pass\r\n"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT(Status == EFI_NOT_FOUND); ASSERT(FileHandle == NULL); Status = ShellCreateDirectory(FileName, &FileHandle); ASSERT_EFI_ERROR(Status); ASSERT(FileHandle != NULL); pFileInfo = ShellGetFileInfo(FileHandle); ASSERT(pFileInfo != NULL); ASSERT(StrCmp(pFileInfo->FileName, FileName) == 0); ASSERT(pFileInfo->Attribute&EFI_FILE_DIRECTORY); Status = ShellDeleteFile(&FileHandle); ASSERT_EFI_ERROR(Status); Print(L"Directory create - pass\r\n"); // FindFirst and FindNext StrCpy(FileName, L"testDir"); Status = ShellCreateDirectory(FileName, &FileHandle); Status = ShellCloseFile(&FileHandle); StrCat(FileName, L"\\File.txt"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); Status = ShellCloseFile(&FileHandle); StrCpy(FileName, L"testDir"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); Status = ShellFindFirstFile(FileHandle, &pFileInfo); ASSERT_EFI_ERROR(Status); Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile); ASSERT_EFI_ERROR(Status); ASSERT(NoFile == FALSE); Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile); ASSERT_EFI_ERROR(Status); ASSERT(NoFile == FALSE); Status = ShellFindNextFile(FileHandle, pFileInfo, &NoFile); ASSERT_EFI_ERROR(Status); ///@todo - why is NoFile never set? limitation of NT32 file system? Status = ShellDeleteFile(&FileHandle); ASSERT(Status == RETURN_WARN_DELETE_FAILURE); Print(L"FindFirst - pass\r\n"); Print(L"FindNext - Verify with real EFI system. Cant verify NoFile under NT32\r\n"); // open and close meta arg Status = ShellOpenFileMetaArg(L"testDir\\*.*", EFI_FILE_MODE_READ, &pShellFileInfo); ASSERT_EFI_ERROR(Status); ASSERT(pShellFileInfo->Status == 0); ASSERT(StrCmp(pShellFileInfo->FileName, L"File.txt") == 0); ASSERT(pShellFileInfo->Handle); ASSERT(pShellFileInfo->Info); ASSERT(pShellFileInfo->Info->FileSize == 0); ASSERT(StrCmp(pShellFileInfo->Info->FileName, L"File.txt") == 0); ASSERT(pShellFileInfo->Info->Attribute == 0); Status = ShellCloseFileMetaArg(&pShellFileInfo); ASSERT_EFI_ERROR(Status); Print(L"Open/Close Meta Arg - pass\r\n"); // now delete that file and that directory StrCat(FileName, L"\\File.txt"); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); ASSERT_EFI_ERROR(Status); Status = ShellDeleteFile(&FileHandle); StrCpy(FileName, L"testDir"); ASSERT_EFI_ERROR(Status); Status = ShellOpenFileByName(FileName, &FileHandle, EFI_FILE_MODE_CREATE|EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0 ); Status = ShellDeleteFile(&FileHandle); ASSERT_EFI_ERROR(Status); // get environment variable // made for testing under nt32 ASSERT(StrCmp(ShellGetEnvironmentVariable(L"path"), L".;f10:\\efi\\tools;f10:\\efi\\boot;f10:\\;f9:\\efi\\tools;f9:\\efi\\boot;f9:\\") == 0); Print(L"ShellGetEnvironmentVariable - pass\r\n"); // set environment variable Status = ShellSetEnvironmentVariable(L"", L"", FALSE); ASSERT(Status == EFI_UNSUPPORTED); Print(L"ShellSetEnvironmentVariable - pass\r\n"); // ShellExecute Status = ShellExecute(&ImageHandle, L"EmptyApplication.efi", TRUE, NULL, NULL); ASSERT_EFI_ERROR(Status); // the pass printout for this is performed by EmptyApplication Print(L"\r\n"); // page break mode (done last so we can see the results) // we set this true at the begining of the program // this is enough lines to trigger the page... Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n"); ShellSetPageBreakMode(FALSE); Print(L"1\r\n2\r\n3\r\n4\r\n5\r\n6\r\n7\r\n8\r\n9\r\n10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19\r\n20\r\n21\r\n22\r\n23\r\n24\r\n25\r\n26\r\n27\r\n28\r\n29\r\n30\r\n31\r\n32\r\n33\r\n34\r\n35\r\n36\r\n37\r\n38\r\n39\r\n40\r\n41\r\n42\r\n43\r\n44\r\n45\r\n46\r\n47\r\n48\r\n49\r\n50\r\n51\r\n52\r\n53\r\n54\r\n55\r\n56\r\n57\r\n58\r\n59\r\n60\r\n"); return EFI_SUCCESS; }
/** Save lines in HBufferImage to disk. @param[in] FileName The file name. @retval EFI_SUCCESS The operation was successful. @retval EFI_OUT_OF_RESOURCES A memory allocation failed. @retval EFI_LOAD_ERROR A load error occured. **/ EFI_STATUS HFileImageSave ( IN CHAR16 *FileName ) { LIST_ENTRY *Link; HEFI_EDITOR_LINE *Line; CHAR16 *Str; EFI_STATUS Status; UINTN NumLines; SHELL_FILE_HANDLE FileHandle; UINTN TotalSize; UINT8 *Buffer; UINT8 *Ptr; EDIT_FILE_TYPE BufferTypeBackup; BufferTypeBackup = HBufferImage.BufferType; HBufferImage.BufferType = FileTypeFileBuffer; // // if is the old file // if (HFileImage.FileName != NULL && FileName != NULL && StrCmp (FileName, HFileImage.FileName) == 0) { // // check whether file exists on disk // if (ShellIsFile(FileName) == EFI_SUCCESS) { // // current file exists on disk // so if not modified, then not save // if (HBufferImage.Modified == FALSE) { return EFI_SUCCESS; } // // if file is read-only, set error // if (HFileImage.ReadOnly == TRUE) { StatusBarSetStatusString (L"Read Only File Can Not Be Saved"); return EFI_SUCCESS; } } } if (ShellIsDirectory(FileName) == EFI_SUCCESS) { StatusBarSetStatusString (L"Directory Can Not Be Saved"); return EFI_LOAD_ERROR; } Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE, 0); if (!EFI_ERROR (Status)) { // // the file exits, delete it // Status = ShellDeleteFile (&FileHandle); if (EFI_ERROR (Status) || Status == EFI_WARN_DELETE_FAILURE) { StatusBarSetStatusString (L"Write File Failed"); return EFI_LOAD_ERROR; } } // // write all the lines back to disk // NumLines = 0; TotalSize = 0; for (Link = HBufferImage.ListHead->ForwardLink; Link != HBufferImage.ListHead; Link = Link->ForwardLink) { Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST); if (Line->Size != 0) { TotalSize += Line->Size; } // // end of if Line -> Size != 0 // NumLines++; } // // end of for Link // Buffer = AllocateZeroPool (TotalSize); if (Buffer == NULL) { return EFI_OUT_OF_RESOURCES; } Ptr = Buffer; for (Link = HBufferImage.ListHead->ForwardLink; Link != HBufferImage.ListHead; Link = Link->ForwardLink) { Line = CR (Link, HEFI_EDITOR_LINE, Link, EFI_EDITOR_LINE_LIST); if (Line->Size != 0) { CopyMem (Ptr, Line->Buffer, Line->Size); Ptr += Line->Size; } // // end of if Line -> Size != 0 // } Status = ShellOpenFileByName (FileName, &FileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR (Status)) { StatusBarSetStatusString (L"Create File Failed"); return EFI_LOAD_ERROR; } Status = ShellWriteFile (FileHandle, &TotalSize, Buffer); FreePool (Buffer); if (EFI_ERROR (Status)) { ShellDeleteFile (&FileHandle); return EFI_LOAD_ERROR; } ShellCloseFile(&FileHandle); HBufferImage.Modified = FALSE; // // set status string // Str = CatSPrint(NULL, L"%d Lines Wrote", NumLines); StatusBarSetStatusString (Str); FreePool (Str); // // now everything is ready , you can set the new file name to filebuffer // if ((BufferTypeBackup != FileTypeFileBuffer && FileName != NULL) || (FileName != NULL && HFileImage.FileName != NULL && StringNoCaseCompare (&FileName, &HFileImage.FileName) != 0)){ // // not the same // HFileImageSetFileName (FileName); if (HFileImage.FileName == NULL) { return EFI_OUT_OF_RESOURCES; } } HFileImage.ReadOnly = FALSE; return EFI_SUCCESS; }
/** Function for 'compress' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunEfiCompress ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_STATUS ShellStatus; SHELL_FILE_HANDLE InShellFileHandle; SHELL_FILE_HANDLE OutShellFileHandle; UINT64 OutSize; UINTN OutSize2; VOID *OutBuffer; UINT64 InSize; UINTN InSize2; VOID *InBuffer; CHAR16 *InFileName; CONST CHAR16 *OutFileName; CONST CHAR16 *TempParam; InFileName = NULL; OutFileName = NULL; OutSize = 0; ShellStatus = SHELL_SUCCESS; Status = EFI_SUCCESS; OutBuffer = NULL; InShellFileHandle = NULL; OutShellFileHandle = NULL; InBuffer = NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); Status = CommandInit(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDebug1HiiHandle, L"eficompress", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { if (ShellCommandLineGetCount(Package) > 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDebug1HiiHandle, L"eficompress"); ShellStatus = SHELL_INVALID_PARAMETER; } else if (ShellCommandLineGetCount(Package) < 3) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellDebug1HiiHandle, L"eficompress"); ShellStatus = SHELL_INVALID_PARAMETER; } else { TempParam = ShellCommandLineGetRawValue(Package, 1); ASSERT(TempParam != NULL); InFileName = ShellFindFilePath(TempParam); OutFileName = ShellCommandLineGetRawValue(Package, 2); if (InFileName == NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_FIND_FAIL), gShellDebug1HiiHandle, L"eficompress", TempParam); ShellStatus = SHELL_NOT_FOUND; } else { if (ShellIsDirectory(InFileName) == EFI_SUCCESS){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", InFileName); ShellStatus = SHELL_INVALID_PARAMETER; } if (ShellIsDirectory(OutFileName) == EFI_SUCCESS){ ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_NOT_DIR), gShellDebug1HiiHandle, L"eficompress", OutFileName); ShellStatus = SHELL_INVALID_PARAMETER; } if (ShellStatus == SHELL_SUCCESS) { Status = ShellOpenFileByName(InFileName, &InShellFileHandle, EFI_FILE_MODE_READ, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue(Package, 1)); ShellStatus = SHELL_NOT_FOUND; } Status = ShellOpenFileByName(OutFileName, &OutShellFileHandle, EFI_FILE_MODE_READ|EFI_FILE_MODE_WRITE|EFI_FILE_MODE_CREATE, 0); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_FILE_OPEN_FAIL), gShellDebug1HiiHandle, L"eficompress", ShellCommandLineGetRawValue(Package, 2)); ShellStatus = SHELL_NOT_FOUND; } } if (ShellStatus == SHELL_SUCCESS) { Status = gEfiShellProtocol->GetFileSize(InShellFileHandle, &InSize); ASSERT_EFI_ERROR(Status); InBuffer = AllocateZeroPool((UINTN)InSize); if (InBuffer == NULL) { Status = EFI_OUT_OF_RESOURCES; } else { InSize2 = (UINTN) InSize; Status = gEfiShellProtocol->ReadFile (InShellFileHandle, &InSize2, InBuffer); InSize = InSize2; ASSERT_EFI_ERROR (Status); Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); if (Status == EFI_BUFFER_TOO_SMALL) { OutBuffer = AllocateZeroPool ((UINTN) OutSize); if (OutBuffer == NULL) { Status = EFI_OUT_OF_RESOURCES; } else { Status = Compress (InBuffer, InSize, OutBuffer, &OutSize); } } } if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_EFI_COMPRESS_FAIL), gShellDebug1HiiHandle, Status); ShellStatus = ((Status == EFI_OUT_OF_RESOURCES) ? SHELL_OUT_OF_RESOURCES : SHELL_DEVICE_ERROR); } else { OutSize2 = (UINTN)OutSize; Status = gEfiShellProtocol->WriteFile(OutShellFileHandle, &OutSize2, OutBuffer); if (EFI_ERROR(Status)) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_FILE_WRITE_FAIL), gShellDebug1HiiHandle, L"eficompress", OutFileName); ShellStatus = SHELL_DEVICE_ERROR; } } } } } ShellCommandLineFreeVarList (Package); } if (InShellFileHandle != NULL) { gEfiShellProtocol->CloseFile(InShellFileHandle); } if (OutShellFileHandle != NULL) { gEfiShellProtocol->CloseFile(OutShellFileHandle); } SHELL_FREE_NON_NULL(InFileName); SHELL_FREE_NON_NULL(InBuffer); SHELL_FREE_NON_NULL(OutBuffer); return (ShellStatus); }
/** Function for 'mkdir' command. @param[in] ImageHandle Handle to the Image (NULL if Internal). @param[in] SystemTable Pointer to the System Table (NULL if Internal). **/ SHELL_STATUS EFIAPI ShellCommandRunMkDir ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; CONST CHAR16 *NewDirName; CHAR16 *NewDirNameCopy; CHAR16 *SplitName; CHAR16 SaveSplitChar; UINTN DirCreateCount; LIST_ENTRY *Package; CHAR16 *ProblemParam; SHELL_FILE_HANDLE FileHandle; SHELL_STATUS ShellStatus; ShellStatus = SHELL_SUCCESS; NewDirNameCopy = NULL; SplitName = NULL; SaveSplitChar = CHAR_NULL; // // initialize the shell lib (we must be in non-auto-init...) // Status = ShellInitialize(); ASSERT_EFI_ERROR(Status); // // parse the command line // Status = ShellCommandLineParse (EmptyParamList, &Package, &ProblemParam, TRUE); if (EFI_ERROR(Status)) { if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) { ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellLevel2HiiHandle, L"mkdir", ProblemParam); FreePool(ProblemParam); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FALSE); } } else { // // check for "-?" // if (ShellCommandLineGetFlag(Package, L"-?")) { ASSERT(FALSE); } // // create a set of directories // if (ShellCommandLineGetRawValue(Package, 1) == NULL) { // // we didnt get a single parameter // ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_FEW), gShellLevel2HiiHandle, L"mkdir"); ShellStatus = SHELL_INVALID_PARAMETER; } else { for ( DirCreateCount = 1 ; ; DirCreateCount++ ){ // // loop through each directory specified // NewDirName = ShellCommandLineGetRawValue(Package, DirCreateCount); if (NewDirName == NULL) { break; } // // check if that already exists... if yes fail // FileHandle = NULL; Status = ShellOpenFileByName(NewDirName, &FileHandle, EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, EFI_FILE_DIRECTORY ); if (!EFI_ERROR(Status)) { ShellCloseFile(&FileHandle); ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_MKDIR_ALREADY), gShellLevel2HiiHandle, NewDirName); ShellStatus = SHELL_INVALID_PARAMETER; } else { ASSERT(FileHandle == NULL); // // create the nested directory from parent to child. // if NewDirName = test1\test2\test3, first create "test1\" directory, then "test1\test2\", finally "test1\test2\test3". // NewDirNameCopy = AllocateCopyPool (StrSize(NewDirName), NewDirName); NewDirNameCopy = PathCleanUpDirectories (NewDirNameCopy); if(NewDirNameCopy == NULL) { ShellStatus = SHELL_OUT_OF_RESOURCES; break; } SplitName = NewDirNameCopy; while (SplitName != NULL) { SplitName = StrStr (SplitName + 1, L"\\"); if (SplitName != NULL) { SaveSplitChar = *(SplitName + 1); *(SplitName + 1) = '\0'; } // // check if current nested directory already exists... continue to create the child directory. // Status = ShellOpenFileByName (NewDirNameCopy, &FileHandle, EFI_FILE_MODE_READ, EFI_FILE_DIRECTORY ); if (!EFI_ERROR(Status)) { ShellCloseFile (&FileHandle); } else { Status = ShellCreateDirectory (NewDirNameCopy, &FileHandle); if (EFI_ERROR(Status)) { break; } if (FileHandle != NULL) { gEfiShellProtocol->CloseFile (FileHandle); } } if (SplitName != NULL) { *(SplitName + 1) = SaveSplitChar; } } if (EFI_ERROR(Status)) { ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_MKDIR_CREATEFAIL), gShellLevel2HiiHandle, NewDirName); ShellStatus = SHELL_ACCESS_DENIED; break; } SHELL_FREE_NON_NULL (NewDirNameCopy); } } } } // // free the command line package // ShellCommandLineFreeVarList (Package); return (ShellStatus); }