]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c
ShellPkg/Dp: Add null pointer check
[mirror_edk2.git] / ShellPkg / Library / UefiShellDriver1CommandsLib / Devices.c
index a6e27e93dac620566f063a1cfc13ffdac6f048a5..b725178ebd151cf4e43e589320a3a710c3b45acc 100644 (file)
@@ -1,7 +1,8 @@
 /** @file\r
   Main file for devices shell Driver1 function.\r
 \r
-  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
+  (C) Copyright 2012-2015 Hewlett-Packard Development Company, L.P.<BR>\r
+  Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
 /**\r
   Get lots of info about a device from its handle.\r
 \r
-  @param[in] TheHandle      The device handle to get info on.\r
-  @param[in,out] Type       On successful return R, B, or D (root, bus, or \r
-                            device) will be placed in this buffer.\r
-  @param[in,out] Cfg        On successful return this buffer will be \r
-                            TRUE if the handle has configuration, FALSE\r
-                            otherwise.\r
-  @param[in,out] Diag       On successful return this buffer will be \r
-                            TRUE if the handle has disgnostics, FALSE\r
-                            otherwise.\r
-  @param[in,out] Parents    On successful return this buffer will be \r
-                            contain the number of parent handles.\r
-  @param[in,out] Devices    On successful return this buffer will be \r
-                            contain the number of devices controlled.\r
-  @param[in,out] Children   On successful return this buffer will be \r
-                            contain the number of child handles.\r
-  @param[out] Name          The pointer to a buffer that will be allocated\r
-                            and contain the string name of the handle.\r
-                            The caller must free this memory.\r
-  @param[in] Language       The language code as defined by the UEFI spec.\r
+  @param[in] TheHandle       The device handle to get info on.\r
+  @param[in, out] Type       On successful return R, B, or D (root, bus, or \r
+                             device) will be placed in this buffer.\r
+  @param[in, out] Cfg        On successful return this buffer will be \r
+                             TRUE if the handle has configuration, FALSE\r
+                             otherwise.\r
+  @param[in, out] Diag       On successful return this buffer will be \r
+                             TRUE if the handle has disgnostics, FALSE\r
+                             otherwise.\r
+  @param[in, out] Parents    On successful return this buffer will be \r
+                             contain the number of parent handles.\r
+  @param[in, out] Devices    On successful return this buffer will be \r
+                             contain the number of devices controlled.\r
+  @param[in, out] Children   On successful return this buffer will be \r
+                             contain the number of child handles.\r
+  @param[out] Name           The pointer to a buffer that will be allocated\r
+                             and contain the string name of the handle.\r
+                             The caller must free this memory.\r
+  @param[in] Language        The language code as defined by the UEFI spec.\r
 \r
   @retval EFI_SUCCESS           The info is there.\r
   @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
 **/\r
 EFI_STATUS\r
-EFIAPI\r
 GetDeviceHandleInfo (\r
   IN EFI_HANDLE   TheHandle,\r
   IN OUT CHAR16   *Type,\r
@@ -114,6 +114,7 @@ GetDeviceHandleInfo (
 }\r
 \r
 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
+  {L"-sfo", TypeFlag},\r
   {L"-l", TypeValue},\r
   {NULL, TypeMax}\r
   };\r
@@ -146,9 +147,11 @@ ShellCommandRunDevices (
   UINTN               Children;\r
   CHAR16              *Name;\r
   CONST CHAR16        *Lang;\r
+  BOOLEAN             SfoFlag;\r
 \r
   ShellStatus         = SHELL_SUCCESS;\r
   Language            = NULL;\r
+  SfoFlag             = FALSE;\r
 \r
   //\r
   // initialize the shell lib (we must be in non-auto-init...)\r
@@ -165,7 +168,7 @@ ShellCommandRunDevices (
   Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
   if (EFI_ERROR(Status)) {\r
     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, L"devices", ProblemParam);  \r
       FreePool(ProblemParam);\r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
@@ -179,7 +182,7 @@ ShellCommandRunDevices (
       //\r
       // error for too many parameters\r
       //\r
-      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);\r
+      ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle, L"devices");  \r
       ShellStatus = SHELL_INVALID_PARAMETER;\r
     } else {\r
       //\r
@@ -195,7 +198,7 @@ ShellCommandRunDevices (
 //        AsciiSPrint(Language, 10, "en-us");\r
       } else {\r
         ASSERT(Language == NULL);\r
-        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l");\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"devices",  L"-l");  \r
         ShellCommandLineFreeVarList (Package);\r
         return (SHELL_INVALID_PARAMETER);\r
       }\r
@@ -203,8 +206,14 @@ ShellCommandRunDevices (
 \r
       //\r
       // Print Header\r
+\r
       //\r
-      ShellPrintHiiEx(-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);\r
+      if (ShellCommandLineGetFlag (Package, L"-sfo")) {\r
+        ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_GEN_SFO_HEADER), gShellDriver1HiiHandle, L"devices");\r
+        SfoFlag = TRUE;\r
+      } else {\r
+        ShellPrintHiiEx (-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);\r
+      }\r
 \r
       //\r
       // loop through each handle\r
@@ -222,16 +231,16 @@ ShellCommandRunDevices (
         Name = NULL;\r
         Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);\r
         if (Name != NULL && (Parents != 0 || Devices != 0 || Children != 0)) {\r
-          ShellPrintHiiEx(\r
+          ShellPrintHiiEx (\r
             -1,\r
             -1,\r
             Language,\r
-            STRING_TOKEN (STR_DEVICES_ITEM_LINE),\r
+            SfoFlag?STRING_TOKEN (STR_DEVICES_ITEM_LINE_SFO):STRING_TOKEN (STR_DEVICES_ITEM_LINE),\r
             gShellDriver1HiiHandle,\r
-            ConvertHandleToHandleIndex(*HandleListWalker),\r
+            ConvertHandleToHandleIndex (*HandleListWalker),\r
             Type,\r
-            Cfg?L'X':L'-',\r
-            Diag?L'X':L'-',\r
+            Cfg?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'),\r
+            Diag?(SfoFlag?L'Y':L'X'):(SfoFlag?L'N':L'-'),\r
             Parents,\r
             Devices,\r
             Children,\r
@@ -240,6 +249,11 @@ ShellCommandRunDevices (
         if (Name != NULL) {\r
           FreePool(Name);\r
         }\r
+        if (ShellGetExecutionBreakFlag ()) {\r
+          ShellStatus = SHELL_ABORTED;\r
+          break;\r
+        }\r
+        \r
       }\r
 \r
       if (HandleList != NULL) {\r