EFI_STATUS EFIAPI InitializeDate ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Display or set date Arguments: ImageHandle The image handle. SystemTable The system table. Returns: EFI_SUCCESS - Command completed successfully EFI_INVALID_PARAMETER - Command usage error Other value - Unknown error Notes: date [mm/dd/yyyy] --*/ { EFI_STATUS Status; EFI_TIME Time; UINTN Offset; UINTN Data; EFI_HII_HANDLE HiiHandle; SHELL_VAR_CHECK_PACKAGE ChkPck; CHAR16 *Useful; SHELL_VAR_CHECK_CODE RetCode; ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Enable tab key which can pause the output // EnableOutputTabPause(); // // Register our string package with HII and return the handle to it. // If previously registered we will simply receive the handle // Status = LibInitializeStrings (&HiiHandle, STRING_ARRAY_NAME, &EfiDateGuid); if (EFI_ERROR (Status)) { return Status; } if (!EFI_PROPER_VERSION (0, 99)) { PrintToken ( STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT), HiiHandle, L"date", EFI_VERSION_0_99 ); Status = EFI_UNSUPPORTED; goto Done; } RetCode = LibCheckVariables (SI, DateCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiHandle, L"date", Useful); break; case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiHandle, L"date", Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Done; } // // Out put help. // if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiHandle); } else if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"date"); Status = EFI_INVALID_PARAMETER; } else { PrintToken (STRING_TOKEN (STR_DATE_VERBOSE_HELP), HiiHandle); Status = EFI_SUCCESS; } goto Done; } if (ChkPck.ValueCount == 0) { Status = RT->GetTime (&Time, NULL); if (!EFI_ERROR (Status)) { PrintToken ( STRING_TOKEN (STR_DATE_PRINTDATE), HiiHandle, (UINTN) Time.Month, (UINTN) Time.Day, (UINTN) Time.Year ); } else { PrintToken (STRING_TOKEN (STR_DATE_CLOCK_NOT_FUNC), HiiHandle); } goto Done; } if (ChkPck.ValueCount > 1) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"date"); Status = EFI_INVALID_PARAMETER; goto Done; } // // Get current time // Status = RT->GetTime (&Time, NULL); if (EFI_ERROR (Status)) { // // Error in GetTime, so set all fields of Timer to default value. // Time.Second = 0; Time.Minute = 0; Time.Hour = 0; Time.Day = 1; Time.Month = 1; Time.Year = 2001; } // // Init start number of argument and // offset position in argument string // Offset = 0; // // Get month // if (!GetNumber (ChkPck.VarList->VarStr, &Offset, &Data, FALSE)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"date", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } if (Data < 1 || Data > 12) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"date", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } Time.Month = (UINT8) Data; // // Get day // if (!GetNumber (ChkPck.VarList->VarStr, &Offset, &Data, FALSE)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"date", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } if (Data < 1 || Data > 31) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"date", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } Time.Day = (UINT8) Data; // // Get year. // if (!GetNumber (ChkPck.VarList->VarStr, &Offset, &Data, TRUE)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"date", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } // // Minimal year number supported is 1998 // if (Data < 100) { Data = Data + 1900; if (Data < 1998) { Data = Data + 100; } } if (Data < 1998 || Data > 2099) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"date", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } Time.Year = (UINT16) Data; if (!ValidDay (Time)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"date", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } Status = RT->SetTime (&Time); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_DATE_CLOCK_NOT_FUNC), HiiHandle); } Done: LibCheckVarFreeVarList (&ChkPck); LibUnInitializeStrings (); return Status; }
EFI_STATUS SEnvCmdSA ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable, IN EFI_LIST_ENTRY *Head, IN EFI_GUID *Guid, IN CHAR16 *CmdName, IN UINT16 VHlpToken ) /*++ Routine Description: Code for shell "set" & "alias" command Arguments: ImageHandle - The image handle SystemTable - The system table Head - The variable list head Guid - The guid CmdName - The command name VHlpToken - The help token Returns: --*/ { EFI_LIST_ENTRY *Link; VARIABLE_ID *Var; VARIABLE_ID *Found; CHAR16 *Name; CHAR16 *Value; UINTN SLen; UINTN Len; BOOLEAN Delete; EFI_STATUS Status; BOOLEAN Volatile; UINTN Index; SHELL_VAR_CHECK_CODE RetCode; CHAR16 *Useful; SHELL_VAR_CHECK_PACKAGE ChkPck; SHELL_ARG_LIST *ArgItem; EFI_SHELL_APP_INIT (ImageHandle, SystemTable); Status = LibFilterNullArgs (); if (EFI_ERROR (Status)) { goto Quit; } ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); ArgItem = NULL; RetCode = LibCheckVariables (SI, VarCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckConflict: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_FLAG_CONFLICT), HiiEnvHandle, CmdName, Useful); break; case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiEnvHandle, CmdName, Useful); break; case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiEnvHandle, CmdName, Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Quit; } // // Initializing variable to aVOID level 4 warning // Name = NULL; Value = NULL; Delete = FALSE; Status = EFI_SUCCESS; Found = NULL; Var = NULL; Volatile = FALSE; // // Crack arguments // if (ChkPck.ValueCount > 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle); goto Quit; } if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } PrintToken (VHlpToken, HiiEnvHandle); Status = EFI_SUCCESS; goto Quit; } if (LibCheckVarGetFlag (&ChkPck, L"-d") != NULL) { if (ChkPck.ValueCount > 1) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } else if (ChkPck.ValueCount < 1) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } Delete = TRUE; } if (LibCheckVarGetFlag (&ChkPck, L"-v") != NULL) { if (ChkPck.ValueCount < 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } Volatile = TRUE; } ArgItem = GetFirstArg (&ChkPck); if (NULL != ArgItem) { if (SEnvGetCmdDispath (ArgItem->VarStr) && (StriCmp (CmdName, L"alias") == 0)) { PrintToken (STRING_TOKEN (STR_SHELLENV_VAR_INTERNAL_COMAMND), HiiEnvHandle, CmdName, ArgItem->VarStr); Status = EFI_INVALID_PARAMETER; goto Quit; } else if (StrSubCmp (L"*", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"?", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"<", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L">", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"#", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L":", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"^", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"%", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"/", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"|", ArgItem->VarStr, 1) == TRUE || StrSubCmp (L"\"", ArgItem->VarStr, 1) == TRUE ) { // // we donot allow *,?,<,>,#,:,^,%,/,|," in alias or variable name // PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiEnvHandle, CmdName, ArgItem->VarStr); Status = EFI_INVALID_PARAMETER; goto Quit; } else { Name = ArgItem->VarStr; } ArgItem = GetNextArg (ArgItem); } if (NULL != ArgItem) { Value = ArgItem->VarStr; } if (Delete && Value) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, CmdName); Status = EFI_INVALID_PARAMETER; goto Quit; } if (Name != NULL) { for (Index = 0; mSpecVarTable[Index].CmdName != NULL; Index++) { if (StriCmp (mSpecVarTable[Index].CmdName, CmdName) == 0 && StriCmp (mSpecVarTable[Index].VarName, Name) == 0 && mSpecVarTable[Index].SpecCheckFun != NULL ) { Status = mSpecVarTable[Index].SpecCheckFun (Value, Delete, Volatile); if (EFI_ERROR (Status)) { goto Quit; } } } } // // Process // AcquireLock (&SEnvLock); if (!Name) { // // dump the list // SEnvSortVarList (Head); SLen = 0; for (Link = Head->Flink; Link != Head; Link = Link->Flink) { Var = CR (Link, VARIABLE_ID, Link, VARIABLE_SIGNATURE); if (_IsReserved (Var->Name, CmdName)) { continue; } Len = StrLen (Var->Name); if (Len > SLen) { SLen = Len; } } for (Link = Head->Flink; Link != Head; Link = Link->Flink) { // // Break the execution? // if (GetExecutionBreak ()) { goto Done; } Var = CR (Link, VARIABLE_ID, Link, VARIABLE_SIGNATURE); if (_IsReserved (Var->Name, CmdName)) { continue; } if (Var->Flags & VAR_ID_NON_VOL) { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_DUMP_VAR_LIST), HiiEnvHandle, L' ', SLen, Var->Name, Var->u.Str ); } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_DUMP_VAR_LIST), HiiEnvHandle, L'*', SLen, Var->Name, Var->u.Str ); } } } else { // // Find the specified value // Found = SEnvFindVar (Head, Name); if (Found && Delete) { // // Remove it from the store // Status = RT->SetVariable (Found->Name, Guid, 0, 0, NULL); if (Status == EFI_NOT_FOUND) { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_NOT_FOUND), HiiEnvHandle, CmdName, Found->Name ); } } else if (Value) { // // Add it to the store // if (Found && ((Volatile && (Found->Flags & VAR_ID_NON_VOL)) || (!Volatile && !(Found->Flags & VAR_ID_NON_VOL)))) { if (Found->Flags & VAR_ID_NON_VOL) { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_ALREADY_EXISTS_NONVOLATILE), HiiEnvHandle, CmdName, Found->Name ); } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_ALREADY_EXISTS_VOLATILE), HiiEnvHandle, CmdName, Found->Name ); } Found = NULL; Status = EFI_ACCESS_DENIED; } else { Status = SEnvAddVar ( Head, Guid, Found ? Found->Name : Name, (UINT8 *) Value, StrSize (Value), Volatile ); } } else { if (Found) { if (Found->Flags & VAR_ID_NON_VOL) { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_DISPLAY_VAR), HiiEnvHandle, L' ', Found->Name, Found->u.Str ); } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_DISPLAY_VAR), HiiEnvHandle, L'*', Found->Name, Found->u.Str ); } } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_VAR_NOT_FOUND), HiiEnvHandle, CmdName, Name ); } Found = NULL; } // // Remove the old in memory copy if there was one // if (Found && !EFI_ERROR (Status)) { RemoveEntryList (&Found->Link); FreePool (Found); } } Done: ReleaseLock (&SEnvLock); Quit: LibCheckVarFreeVarList (&ChkPck); return Status; }
EFI_STATUS GuidMain ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Code for external shell "guid" command. Arguments: ImageHandle - The image handle SystemTable - The system table Returns: --*/ { PROTOCOL_INFO *Prot; UINTN Len; UINTN SLen; EFI_STATUS Status; SHELL_VAR_CHECK_CODE RetCode; CHAR16 *Useful; SHELL_VAR_CHECK_PACKAGE ChkPck; ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Enable tab key which can pause the output // EnableOutputTabPause(); Status = LibInitializeStrings (&HiiHandle, STRING_ARRAY_NAME, &EfiGuidGuid); if (EFI_ERROR (Status)) { return Status; } if (!EFI_PROPER_VERSION (0, 99)) { PrintToken ( STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT), HiiHandle, L"guid", EFI_VERSION_0_99 ); Status = EFI_UNSUPPORTED; goto Done; } // // Initializing variable to aVOID level 4 warning // RetCode = LibCheckVariables (SI, GuidCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiHandle, L"guid", Useful); break; case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiHandle, L"guid", Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Done; } if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?")) { if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"guid"); Status = EFI_INVALID_PARAMETER; } else { PrintToken (STRING_TOKEN (STR_GUID_VERBOSEHELP), HiiHandle); Status = EFI_SUCCESS; } goto Done; } if (ChkPck.ValueCount > 0) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"guid"); Status = EFI_INVALID_PARAMETER; goto Done; } // // Find the protocol entry for this id // Status = EFI_SUCCESS; SLen = 0; Prot = NULL; ShellInitProtocolInfoEnumerator (); do { Status = ShellNextProtocolInfo (&Prot); if (Prot == NULL && Status == EFI_SUCCESS) { break; } Len = StrLen (Prot->IdString); if (StrLen (Prot->IdString) > SLen) { SLen = Len; } } while (Prot != NULL); ShellResetProtocolInfoEnumerator (); do { Status = ShellNextProtocolInfo (&Prot); if (Prot == NULL && Status == EFI_SUCCESS) { break; } // // Can't use Lib function to dump the guid as it may lookup the // "short name" for it // if (GetExecutionBreak ()) { Status = EFI_ABORTED; break; } PrintToken ( STRING_TOKEN (STR_SHELLENV_PROTID_FOURTEEN_VARS), HiiHandle, SLen, Prot->IdString, Prot->ProtocolId.Data1, Prot->ProtocolId.Data2, Prot->ProtocolId.Data3, Prot->ProtocolId.Data4[0], Prot->ProtocolId.Data4[1], Prot->ProtocolId.Data4[2], Prot->ProtocolId.Data4[3], Prot->ProtocolId.Data4[4], Prot->ProtocolId.Data4[5], Prot->ProtocolId.Data4[6], Prot->ProtocolId.Data4[7], (Prot->DumpToken || Prot->DumpInfo) ? L'*' : L' ' ); } while (Prot != NULL); ShellCloseProtocolInfoEnumerator (); Done: LibCheckVarFreeVarList (&ChkPck); LibUnInitializeStrings (); return Status; }
EFI_STATUS InitializeComp ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Command entry point. Compares the contents of two files. Arguments: ImageHandle The image handle. SystemTable The system table. Returns: EFI_SUCCESS - The command completed successfully EFI_INVALID_PARAMETER - Input command arguments error EFI_OUT_OF_RESOURCES - Out of memory Other - Misc error --*/ { CHAR16 **Argv; UINTN Argc; EFI_LIST_ENTRY File1List; EFI_LIST_ENTRY File2List; SHELL_FILE_ARG *File1Arg; SHELL_FILE_ARG *File2Arg; UINTN Size; UINTN ReadSize; UINT8 *File1Buffer; UINT8 *File2Buffer; UINTN NotTheSameCount; EFI_STATUS Status; UINTN Index; UINTN Count; UINTN Address; CHAR16 *ScanFile; CHAR16 *Useful; SHELL_ARG_LIST *Item; SHELL_VAR_CHECK_CODE RetCode; SHELL_VAR_CHECK_PACKAGE ChkPck; // // Local variable initializations // File1Arg = NULL; File2Arg = NULL; ReadSize = 0; File1Buffer = NULL; File2Buffer = NULL; Address = 0; InitializeListHead (&File1List); InitializeListHead (&File2List); ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); // // We are not being installed as an internal command driver, initialize // as an nshell app and run // EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Enable tab key which can pause the output // EnableOutputTabPause(); // // Register our string package with HII and return the handle to it. // If previously registered we will simply receive the handle // Status = LibInitializeStrings (&HiiCompHandle, STRING_ARRAY_NAME, &EfiCompGuid); if (EFI_ERROR (Status)) { return Status; } if (!EFI_PROPER_VERSION (0, 99)) { PrintToken ( STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT), HiiCompHandle, L"comp", EFI_VERSION_0_99 ); Status = EFI_UNSUPPORTED; goto Done; } Argv = SI->Argv; Argc = SI->Argc; RetCode = LibCheckVariables (SI, CompCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiCompHandle, L"comp", Useful); break; case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiCompHandle, L"comp", Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Done; } // // Out put help. // if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiCompHandle, L"comp"); Status = EFI_INVALID_PARAMETER; } else { PrintToken (STRING_TOKEN (STR_HELPINFO_COMP_VERBOSEHELP), HiiCompHandle); Status = EFI_SUCCESS; } goto Done; } // // Parse command line arguments // for (Index = 1; Index < Argc; Index += 1) { if (StrLen (Argv[Index]) == 0) { PrintToken (STRING_TOKEN (STR_COMP_ZERO_LENGTH_ARG), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } } // // verify number of arguments // if (ChkPck.ValueCount < 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiCompHandle, L"comp"); Status = EFI_INVALID_PARAMETER; goto Done; } else if (ChkPck.ValueCount > 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiCompHandle, L"comp"); Status = EFI_INVALID_PARAMETER; goto Done; } // // multiple files // Item = ChkPck.VarList; ScanFile = Item->VarStr; while (*ScanFile) { if ('*' == *ScanFile || '?' == *ScanFile) { break; } ScanFile++; } if (*ScanFile) { PrintToken (STRING_TOKEN (STR_COMP_FIRST_MULT_FILES), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } // // validate first file // Status = ShellFileMetaArg (Item->VarStr, &File1List); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, Item->VarStr, Status); goto Done; } // // empty list // if (IsListEmpty (&File1List)) { Status = EFI_NOT_FOUND; PrintToken (STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, Item->VarStr, Status); goto Done; } File1Arg = CR ( File1List.Flink, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE ); // // Open error // if (EFI_ERROR (File1Arg->Status) || !File1Arg->Handle) { PrintToken ( STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, File1Arg->FullName, File1Arg->Status ); Status = File1Arg->Status; goto Done; } // // directory // if (File1Arg->Info && (File1Arg->Info->Attribute & EFI_FILE_DIRECTORY)) { PrintToken (STRING_TOKEN (STR_COMP_FIRST_DIR), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } Item = Item->Next; // // multiple files // ScanFile = Item->VarStr; while (*ScanFile) { if ('*' == *ScanFile || '?' == *ScanFile) { break; } ScanFile++; } if (*ScanFile) { PrintToken (STRING_TOKEN (STR_COMP_SECOND_MULT_FILES), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } // // Validate second file // Status = ShellFileMetaArg (Item->VarStr, &File2List); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, Item->VarStr, Status); goto Done; } // // empty list // if (IsListEmpty (&File2List)) { Status = EFI_NOT_FOUND; PrintToken (STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, Item->VarStr, Status); goto Done; } File2Arg = CR ( File2List.Flink, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE ); // // open error // if (EFI_ERROR (File2Arg->Status) || !File2Arg->Handle) { PrintToken ( STRING_TOKEN (STR_COMP_CANNOT_OPEN), HiiCompHandle, File2Arg->FullName, File2Arg->Status ); Status = File2Arg->Status; goto Done; } // // directory // if (File2Arg->Info && (File2Arg->Info->Attribute & EFI_FILE_DIRECTORY)) { PrintToken (STRING_TOKEN (STR_COMP_SECOND_DIR), HiiCompHandle); Status = EFI_INVALID_PARAMETER; goto Done; } // // Allocate buffers for both files // File1Buffer = AllocatePool (BLOCK_SIZE); File2Buffer = AllocatePool (BLOCK_SIZE); if (!File1Buffer || !File2Buffer) { PrintToken (STRING_TOKEN (STR_COMP_OUT_OF_MEM), HiiCompHandle); Status = EFI_OUT_OF_RESOURCES; goto Done; } // // Compare files // PrintToken (STRING_TOKEN (STR_COMP_COMPARE), HiiCompHandle, File1Arg->FullName, File2Arg->FullName); // // Set positions to head // Status = File1Arg->Handle->SetPosition (File1Arg->Handle, 0); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_COMP_SET_FILE_ERROR), HiiCompHandle, File1Arg->FullName, Status); goto Done; } Status = File2Arg->Handle->SetPosition (File2Arg->Handle, 0); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_COMP_SET_FILE_ERROR), HiiCompHandle, File2Arg->FullName, Status); goto Done; } // // Read blocks one by one from both files and compare each pair of blocks // Size = BLOCK_SIZE; NotTheSameCount = 0; while (Size > 0 && NotTheSameCount < 10) { // // Break the execution? // if (GetExecutionBreak ()) { goto Done; } // // Read a block from first file // Size = BLOCK_SIZE; Status = File1Arg->Handle->Read ( File1Arg->Handle, &Size, File1Buffer ); if (EFI_ERROR (Status)) { PrintToken ( STRING_TOKEN (STR_COMP_READ_FILE_ERROR), HiiCompHandle, File1Arg->FullName, Status ); NotTheSameCount++; break; } // // Read a block from second file // ReadSize = BLOCK_SIZE; Status = File2Arg->Handle->Read ( File2Arg->Handle, &ReadSize, File2Buffer ); if (EFI_ERROR (Status)) { PrintToken ( STRING_TOKEN (STR_COMP_READ_FILE_ERROR), HiiCompHandle, File2Arg->FullName, Status ); NotTheSameCount++; break; } if (ReadSize != Size) { PrintToken ( STRING_TOKEN (STR_COMP_MISMATCH), HiiCompHandle, NotTheSameCount + 1 ); NotTheSameCount++; break; } // // Diff the buffer // for (Index = 0; (Index < Size) && (NotTheSameCount < 10); Index++) { if (File1Buffer[Index] != File2Buffer[Index]) { for (Count = 1; Count < 0x20 && (Index + Count) < Size; Count++) { if (File1Buffer[Index + Count] == File2Buffer[Index + Count]) { break; } } PrintToken (STRING_TOKEN (STR_COMP_DIFFERENCE_FILE1), HiiCompHandle, NotTheSameCount + 1, File1Arg->FullName); DumpHex (1, Address + Index, Count, &File1Buffer[Index]); PrintToken (STRING_TOKEN (STR_COMP_FILE2), HiiCompHandle, File2Arg->FullName); DumpHex (1, Address + Index, Count, &File2Buffer[Index]); Print (L"\n"); NotTheSameCount++; Index += Count - 1; } } Address += Size; } // // Results // if (!NotTheSameCount) { PrintToken (STRING_TOKEN (STR_COMP_NO_DIFFERENCE), HiiCompHandle); } else { PrintToken (STRING_TOKEN (STR_COMP_DIFFERENCE), HiiCompHandle); Status = EFI_ABORTED; } Done: if (File1Buffer) { FreePool (File1Buffer); } if (File2Buffer) { FreePool (File2Buffer); } ShellFreeFileList (&File1List); ShellFreeFileList (&File2List); LibCheckVarFreeVarList (&ChkPck); LibUnInitializeStrings (); // // Shell command always succeeds // return Status; }
EFI_STATUS EFIAPI SEnvCmdGoto ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Transfers execution of batch file to location following a label (:labelname). Arguments: ImageHandle The image handle SystemTable The system table Returns: EFI_SUCCESS The command finished sucessfully EFI_UNSUPPORTED Unsupported EFI_INVALID_PARAMETER Invalid parameter EFI_OUT_OF_RESOURCES Out of resources --*/ { EFI_STATUS Status; EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Output help // if (SI->Argc == 2) { if (StriCmp (SI->Argv[1], L"-?") == 0) { if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle); } else { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_VERBOSE_HELP), HiiEnvHandle); } return EFI_SUCCESS; } } else if (SI->Argc == 3) { if ((StriCmp (SI->Argv[1], L"-?") == 0 && StriCmp (SI->Argv[2], L"-b") == 0) || (StriCmp (SI->Argv[2], L"-?") == 0 && StriCmp (SI->Argv[1], L"-b") == 0) ) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle); } else { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_VERBOSE_HELP), HiiEnvHandle); } return EFI_SUCCESS; } } if (!SEnvBatchIsActive ()) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_ONLY_SUPPORTED_SCRIPT), HiiEnvHandle); return EFI_UNSUPPORTED; } if (SI->Argc > 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_TOO_MANY_ARGS), HiiEnvHandle, SEnvGetLineNumber ()); SEnvSetBatchAbort (); return EFI_INVALID_PARAMETER; } if (SI->Argc < 2) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_TOO_FEW_ARGS), HiiEnvHandle, SEnvGetLineNumber ()); SEnvSetBatchAbort (); return EFI_INVALID_PARAMETER; } TargetLabel = StrDuplicate (SI->Argv[1]); if (TargetLabel == NULL) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_OUT_OF_RESOURCES), HiiEnvHandle); SEnvSetBatchAbort (); return EFI_OUT_OF_RESOURCES; } SEnvBatchSetGotoActive (); Status = SEnvBatchResetJumpStmt (); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GOTO_CANNOT_EXECUTE_SCRIPT), HiiEnvHandle, Status); SEnvSetBatchAbort (); return Status; } return Status; }
EFI_STATUS SEnvCmdEcho ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Shell command "echo". Arguments: ImageHandle - The image handle SystemTable - The system table Returns: --*/ { EFI_STATUS Status; SHELL_VAR_CHECK_CODE RetCode; CHAR16 *Useful; SHELL_VAR_CHECK_PACKAGE ChkPck; SHELL_ARG_LIST *Item; BOOLEAN PageBreak; EFI_SHELL_APP_INIT (ImageHandle, SystemTable); if (!EFI_PROPER_VERSION (0, 99)) { PrintToken ( STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT), HiiEnvHandle, L"echo", EFI_VERSION_0_99 ); Status = EFI_UNSUPPORTED; goto Done; } Status = EFI_SUCCESS; PageBreak = FALSE; ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); // // No args: print status // One arg, either -on or -off: set console echo flag // Otherwise: echo all the args. Shell parser will expand any args or vars. // RetCode = LibCheckVariables (SI, EchoCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiEnvHandle, L"echo", Useful); break; case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiEnvHandle, L"echo", Useful); break; case VarCheckConflict: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_FLAG_CONFLICT), HiiEnvHandle, L"echo", Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Done; } if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); PageBreak = TRUE; } // // Out put help. // if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiEnvHandle); } else if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, L"echo"); Status = EFI_INVALID_PARAMETER; } else { PrintToken (STRING_TOKEN (STR_SHELLENV_ECHO_VERBOSE_HELP), HiiEnvHandle); } goto Done; } if (LibCheckVarGetFlag (&ChkPck, L"-on") != NULL) { if (ChkPck.ValueCount != 0) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, L"echo"); Status = EFI_INVALID_PARAMETER; goto Done; } else { SEnvBatchSetEcho (TRUE); } } else if (LibCheckVarGetFlag (&ChkPck, L"-off") != NULL) { if (ChkPck.ValueCount != 0) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiEnvHandle, L"echo"); Status = EFI_INVALID_PARAMETER; goto Done; } else { SEnvBatchSetEcho (FALSE); } } if ((ChkPck.FlagCount == 0 || (1 == ChkPck.FlagCount && PageBreak)) && ChkPck.ValueCount == 0) { PrintToken (STRING_TOKEN (STR_SHELLENV_ECHO_ECHO_IS), HiiEnvHandle, (SEnvBatchGetEcho () ? L"on" : L"off")); } else if (ChkPck.ValueCount > 0) { Item = GetFirstArg (&ChkPck); for (;;) { Print (L"%s", Item->VarStr); Item = GetNextArg (Item); if (!Item) { break; } Print (L" "); } Print (L"\n"); } Done: LibCheckVarFreeVarList (&ChkPck); return Status; }
EFI_STATUS StallForKey ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_STATUS Status; UINTN Argc; CHAR16 **Argv; UINTN Seconds; EFI_EVENT TimerEvent; EFI_EVENT WaitList[2]; UINTN WaitIndex; EFI_INPUT_KEY Key; // // Initialize libraries // EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Process the arguments // Argc = SI->Argc; Argv = SI->Argv; Seconds = DEFAULT_WAIT_TIME; if (Argc > 1) { Seconds = Atoi (Argv[1]); } // // Create timer event // Status = BS->CreateEvent ( EFI_EVENT_TIMER, 0, NULL, NULL, &TimerEvent ); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Create event. %a:%d:%r\n", __FILE__, __LINE__, Status)); return Status; } // // Set up the timer // Status = BS->SetTimer ( TimerEvent, TimerPeriodic, 10000000 // 1 second ); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Set timer. %a:%d:%r\n", __FILE__, __LINE__, Status)); BS->CloseEvent (TimerEvent); return Status; } // // Set up waiting list // WaitList[0] = ST->ConIn->WaitForKey; WaitList[1] = TimerEvent; // // Do it until timeout // while (Seconds != 0) { // // Print the prompt information (The last blank char is used to clean up // the last string. Don't remove it.) // Print (L"Press any key within %d seconds \r", Seconds); // // Wait for timeout or key input // Status = BS->WaitForEvent ( 2, WaitList, &WaitIndex ); if (EFI_ERROR (Status)) { DEBUG ((EFI_D_ERROR, "Wait for event. %a:%d:%r\n", __FILE__, __LINE__, Status)); break; } // // Check the triggered event // if (WaitIndex == 0) { // // Key input event is triggered // Key.ScanCode = SCAN_NULL; Status = ST->ConIn->ReadKeyStroke (ST->ConIn, &Key); if (!EFI_ERROR (Status)) { break; } DEBUG ((EFI_D_ERROR, "Read key stroke. %a:%d:%r\n", __FILE__, __LINE__, Status)); } else { // // Timer event is triggered // Seconds --; } } // // Close the timer event // BS->CloseEvent (TimerEvent); // // Done // if (Seconds == 0) { return EFI_TIMEOUT; } else { return EFI_SUCCESS; } }
EFI_STATUS EFIAPI InitializeTime ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: time [hh:mm:ss] Arguments: ImageHandle - The image handle SystemTable - The system table Returns: --*/ { EFI_STATUS Status; EFI_TIME Time; UINTN Offset; UINTN Data; EFI_HII_HANDLE HiiHandle; INT16 nValue; CHAR16 wchSign; SHELL_VAR_CHECK_CODE RetCode; CHAR16 *Useful; SHELL_VAR_CHECK_PACKAGE ChkPck; ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Enable tab key which can pause the output // EnableOutputTabPause(); // // Register our string package with HII and return the handle to it. // If previously registered we will simply receive the handle // wchSign = L'+'; Status = LibInitializeStrings (&HiiHandle, STRING_ARRAY_NAME, &EfiTimeGuid); if (EFI_ERROR (Status)) { return Status; } if (!EFI_PROPER_VERSION (0, 99)) { PrintToken ( STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT), HiiHandle, L"time", EFI_VERSION_0_99 ); Status = EFI_UNSUPPORTED; goto Done; } RetCode = LibCheckVariables (SI, TimeCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiHandle, L"time", Useful); break; case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiHandle, L"time", Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Done; } // // Out put help. // if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"time"); Status = EFI_INVALID_PARAMETER; } else { if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiHandle); } else { PrintToken (STRING_TOKEN (STR_TIME_VERBOSE_HELP), HiiHandle); } Status = EFI_SUCCESS; } goto Done; } if (ChkPck.ValueCount > 1) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"time"); Status = EFI_INVALID_PARAMETER; goto Done; } if (ChkPck.ValueCount == 0) { Status = RT->GetTime (&Time, NULL); if (!EFI_ERROR (Status)) { if (Time.TimeZone < 0) { nValue = -Time.TimeZone; } else { nValue = Time.TimeZone; wchSign = L'-'; } PrintToken ( STRING_TOKEN (STR_TIME_THREE_VARS), HiiHandle, (UINTN) Time.Hour, (UINTN) Time.Minute, (UINTN) Time.Second, wchSign, nValue / 60, nValue % 60 ); Status = EFI_SUCCESS; goto Done; } PrintToken (STRING_TOKEN (STR_TIME_CLOCK_NOT_FUNC), HiiHandle, L"time"); goto Done; } // // Get current time // Status = RT->GetTime (&Time, NULL); if (EFI_ERROR (Status)) { // // Error in GetTime, so set all fields of Timer to default value. // Time.Second = 0; Time.Minute = 0; Time.Hour = 0; Time.Day = 1; Time.Month = 1; Time.Year = 2001; } Offset = 0; // // Offset in argument string // // Get hour // if (!GetNumber (ChkPck.VarList->VarStr, &Offset, &Data, FALSE)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"time", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } if (Data < 0 || Data > 23) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"time", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } Time.Hour = (UINT8) Data; // // Get minute // if (!GetNumber (ChkPck.VarList->VarStr, &Offset, &Data, FALSE)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"time", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } if (Data < 0 || Data > 59) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"time", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } Time.Minute = (UINT8) Data; // // Get second // if (!GetNumber (ChkPck.VarList->VarStr, &Offset, &Data, TRUE)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"time", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } if (Data < 0 || Data > 59) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"time", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } Time.Second = (UINT8) Data; Status = RT->SetTime (&Time); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_TIME_CLOCK_NOT_FUNC), HiiHandle, L"time"); } Done: LibCheckVarFreeVarList (&ChkPck); LibUnInitializeStrings (); return Status; }
EFI_STATUS InitializeSct ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Entry point of SCT. Arguments: ImageHandle - The image handle. SystemTable - The system table. Returns: EFI_SUCCESS - Successfully. OTHERS - Something failed. --*/ { EFI_STATUS Status; // // Initialize libraries // EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Initialize the framework table // Status = InitializeFrameworkTable (ImageHandle, SystemTable); if (EFI_ERROR (Status)) { Print (L"ERROR: Cannot initialize the framework table. Status - %r\n", Status); return Status; } // // Parse the command line // Status = ParseCommandLine (ImageHandle); if (EFI_ERROR (Status)) { Print (L"ERROR: Invalid command line. Status - %r\n", Status); FreeFrameworkTable (); return Status; } // // Invoke the SCT main function to do the operations // Status = SctMainFunc (); if (EFI_ERROR (Status)) { Print (L"ERROR: Cannot do the operations. Status - %r\n", Status); FreeFrameworkTable (); return Status; } // // Free the framework table // Status = FreeFrameworkTable (); if (EFI_ERROR (Status)) { Print (L"ERROR: Cannot free the framework table. Status - %r\n", Status); return Status; } // // Done // Print (L"Done!\n"); return EFI_SUCCESS; }
EFI_STATUS OpeninfoMain ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Code for external shell "openinfo" command. Arguments: ImageHandle - The image handle SystemTable - The system table Returns: EFI_INVALID_PARAMETER - Invalid Parameter --*/ { EFI_STATUS Status; UINTN HandleIndex; EFI_HANDLE DumpHandle; PROTOCOL_INFO *Prot; UINTN Index; UINTN Count; VOID *Interface; EFI_OPEN_PROTOCOL_INFORMATION_ENTRY *OpenBuffer; UINTN OpenBufferCount; EFI_DRIVER_BINDING_PROTOCOL *DriverBinding; SHELL_VAR_CHECK_CODE RetCode; CHAR16 *Useful; UINTN ItemValue; SHELL_VAR_CHECK_PACKAGE ChkPck; ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Enable tab key which can pause the output // EnableOutputTabPause(); Status = LibInitializeStrings (&HiiHandle, STRING_ARRAY_NAME, &EfiOpeninfoGuid); if (EFI_ERROR (Status)) { return Status; } if (!EFI_PROPER_VERSION (1, 10)) { PrintToken ( STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT), HiiHandle, L"openinfo", EFI_VERSION_1_10 ); Status = EFI_UNSUPPORTED; goto Done; } RetCode = LibCheckVariables (SI, OpeninfoCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiHandle, L"openinfo", Useful); break; case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiHandle, L"openinfo", Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Done; } // // Out put help. // if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"openinfo"); Status = EFI_INVALID_PARAMETER; } else { PrintToken (STRING_TOKEN (STR_HELPINFO_OPENINFO_VERBOSEHELP), HiiHandle); Status = EFI_SUCCESS; } goto Done; } if (ChkPck.ValueCount < 1) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_FEW), HiiHandle, L"openinfo", Useful); Status = EFI_INVALID_PARAMETER; goto Done; } if (ChkPck.ValueCount > 1) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"openinfo", Useful); Status = EFI_INVALID_PARAMETER; goto Done; } ItemValue = (UINTN) StrToUIntegerBase ((ChkPck.VarList->VarStr), 16, &Status); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"openinfo", ChkPck.VarList->VarStr); Status = EFI_INVALID_PARAMETER; goto Done; } // // Setup Handle and Protocol Globals // ShellInitProtocolInfoEnumerator (); HandleIndex = ShellHandleNoFromIndex (ItemValue); if (HandleIndex == 0) { PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_OPENINFO_HANDLE_OUT_OF_RANGE), HiiHandle, L"openinfo", ItemValue); Status = EFI_INVALID_PARAMETER; goto Done; } DumpHandle = ShellHandleFromIndex (HandleIndex - 1); PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_NHANDLE), HiiHandle, HandleIndex, DumpHandle); do { Status = ShellNextProtocolInfo (&Prot); if (Prot == NULL && Status == EFI_SUCCESS) { break; } for (Index = 0; Index < Prot->NoHandles; Index++) { if (GetExecutionBreak ()) { Status = EFI_ABORTED; break; } if (Prot->Handles[Index] == DumpHandle) { // // This handle supports this protocol, dump it // PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NEWLINE), HiiHandle, Prot->IdString); Status = BS->OpenProtocolInformation ( DumpHandle, &Prot->ProtocolId, &OpenBuffer, &OpenBufferCount ); if (!EFI_ERROR (Status)) { for (Count = 0; Count < OpenBufferCount; Count++) { // // Print Image info. // if (ShellHandleToIndex (OpenBuffer[Count].ControllerHandle) == 0) { PrintToken ( STRING_TOKEN (STR_SHELLENV_PROTID_DRV_CTRL_CNT), HiiHandle, ShellHandleToIndex (OpenBuffer[Count].AgentHandle), OpenBuffer[Count].OpenCount ); } else { PrintToken ( STRING_TOKEN (STR_SHELLENV_PROTID_DRV_CTRL_CNT_2), HiiHandle, ShellHandleToIndex (OpenBuffer[Count].AgentHandle), ShellHandleToIndex (OpenBuffer[Count].ControllerHandle), OpenBuffer[Count].OpenCount ); } // // Handle different conditions // switch (OpenBuffer[Count].Attributes) { case EFI_OPEN_PROTOCOL_BY_HANDLE_PROTOCOL: PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NO_SPACES), HiiHandle, L"HandProt "); break; case EFI_OPEN_PROTOCOL_GET_PROTOCOL: PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NO_SPACES), HiiHandle, L"GetProt "); break; case EFI_OPEN_PROTOCOL_TEST_PROTOCOL: PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NO_SPACES), HiiHandle, L"TestProt "); break; case EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER: PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NO_SPACES), HiiHandle, L"Child "); break; case EFI_OPEN_PROTOCOL_BY_DRIVER: PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NO_SPACES), HiiHandle, L"Driver "); break; case EFI_OPEN_PROTOCOL_EXCLUSIVE: PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NO_SPACES), HiiHandle, L"Exclusive"); break; case EFI_OPEN_PROTOCOL_BY_DRIVER | EFI_OPEN_PROTOCOL_EXCLUSIVE: PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NO_SPACES), HiiHandle, L"DriverEx "); break; default: PrintToken (STRING_TOKEN (STR_SHELLENV_PROTID_ONE_VAR_HS_NO_SPACES), HiiHandle, L"Unknown "); break; } // // Dump image token info // Status = BS->HandleProtocol ( OpenBuffer[Count].AgentHandle, &gEfiDriverBindingProtocolGuid, (VOID **) &DriverBinding ); if (!EFI_ERROR (Status)) { Status = BS->HandleProtocol ( DriverBinding->ImageHandle, &gEfiLoadedImageProtocolGuid, (VOID **) &Interface ); if (!EFI_ERROR (Status)) { ImageTok (DriverBinding->ImageHandle, Interface); } } Print (L"\n"); } FreePool (OpenBuffer); } } } } while (Prot != NULL); Done: ShellCloseProtocolInfoEnumerator (); LibCheckVarFreeVarList (&ChkPck); LibUnInitializeStrings (); return Status; }
EFI_STATUS EFIAPI InitializeAttrib ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) /*++ Routine Description: Command entry point. Parses command line arguments and calls internal function to perform actual action. Arguments: ImageHandle The image handle. SystemTable The system table. Returns: EFI_SUCCESS - Command completed successfully EFI_INVALID_PARAMETER - Command usage error Other value - Unknown error --*/ { UINTN Index; EFI_LIST_ENTRY FileList; EFI_LIST_ENTRY *Link; SHELL_FILE_ARG *Arg; UINT64 Remove; UINT64 Add; EFI_STATUS Status; SHELL_VAR_CHECK_CODE RetCode; CHAR16 *Useful; SHELL_ARG_LIST *Item; SHELL_VAR_CHECK_PACKAGE ChkPck; ZeroMem (&ChkPck, sizeof (SHELL_VAR_CHECK_PACKAGE)); // // We are no being installed as an internal command driver, initialize // as an nshell app and run // EFI_SHELL_APP_INIT (ImageHandle, SystemTable); // // Enable tab key which can pause the output // EnableOutputTabPause(); Status = LibFilterNullArgs (); if (EFI_ERROR (Status)) { return Status; } // // Register our string package with HII and return the handle to it. // If previously registered we will simply receive the handle // EFI_SHELL_STR_INIT (HiiHandle, STRING_ARRAY_NAME, EfiAttribGuid); if (!EFI_PROPER_VERSION (0, 99)) { PrintToken ( STRING_TOKEN (STR_SHELLENV_GNC_COMMAND_NOT_SUPPORT), HiiHandle, L"attrib", EFI_VERSION_0_99 ); Status = EFI_UNSUPPORTED; goto Quit; } RetCode = LibCheckVariables (SI, AttribCheckList, &ChkPck, &Useful); if (VarCheckOk != RetCode) { switch (RetCode) { case VarCheckConflict: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_FLAG_CONFLICT), HiiHandle, L"attrib", Useful); break; case VarCheckDuplicate: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_DUP_FLAG), HiiHandle, L"attrib", Useful); break; case VarCheckUnknown: PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_UNKNOWN_FLAG), HiiHandle, L"attrib", Useful); break; default: break; } Status = EFI_INVALID_PARAMETER; goto Quit; } // // Out put help. // if (LibCheckVarGetFlag (&ChkPck, L"-b") != NULL) { EnablePageBreak (DEFAULT_INIT_ROW, DEFAULT_AUTO_LF); } if (LibCheckVarGetFlag (&ChkPck, L"-?") != NULL) { if (IS_OLD_SHELL) { PrintToken (STRING_TOKEN (STR_NO_HELP), HiiHandle); goto Quit; } if (ChkPck.ValueCount > 0 || ChkPck.FlagCount > 2 || (2 == ChkPck.FlagCount && !LibCheckVarGetFlag (&ChkPck, L"-b")) ) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_TOO_MANY), HiiHandle, L"attrib"); Status = EFI_INVALID_PARAMETER; } else { PrintToken (STRING_TOKEN (STR_ATTRIB_VERBOSE_HELP), HiiHandle); Status = EFI_SUCCESS; } goto Quit; } // // Local Variable Initializations // InitializeListHead (&FileList); Link = NULL; Arg = NULL; Remove = 0; Add = 0; // // Parse command line arguments // Item = GetFirstFlag (&ChkPck); for (Index = 0; Index < ChkPck.FlagCount; Index += 1) { if (Item->FlagStr[0] == '-') { // // Attributes to remove // Status = AttribSet (&Item->FlagStr[1], &Remove); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"attrib", Item->FlagStr); goto Done; } } else if (Item->FlagStr[0] == '+') { // // Attributes to Add // Status = AttribSet (&Item->FlagStr[1], &Add); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_SHELLENV_GNC_INVALID_ARG), HiiHandle, L"attrib", Item->FlagStr); goto Done; } } else { // // we should never get here // ASSERT (FALSE); } Item = GetNextArg (Item); } Item = GetFirstArg (&ChkPck); for (Index = 0; Index < ChkPck.ValueCount; Index += 1) { Status = ShellFileMetaArg (Item->VarStr, &FileList); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_ATTRIB_CANNOT_OPEN), HiiHandle, L"attrib", Item->VarStr, Status); goto Done; } Item = GetNextArg (Item); } // // if no file is specified, get the whole directory // if (IsListEmpty (&FileList)) { Status = ShellFileMetaArg (L"*", &FileList); if (EFI_ERROR (Status)) { PrintToken (STRING_TOKEN (STR_ATTRIB_CANNOT_OPEN_DIR), HiiHandle, L"attrib", Status); goto Done; } } ShellDelDupFileArg (&FileList); // // Attrib each file // for (Link = FileList.Flink; Link != &FileList; Link = Link->Flink) { // // Break the execution? // if (GetExecutionBreak ()) { goto Done; } Arg = CR (Link, SHELL_FILE_ARG, Link, SHELL_FILE_ARG_SIGNATURE); Status = AttribFile (Arg, Remove, Add); } Done: ShellFreeFileList (&FileList); Quit: LibCheckVarFreeVarList (&ChkPck); LibUnInitializeStrings (); return Status; }