]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c
udk2010.up2.shell initial release.
[mirror_edk2.git] / ShellPkg / Library / UefiShellDriver1CommandsLib / Devices.c
1 /** @file
2 Main file for devices shell Driver1 function.
3
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #include "UefiShellDriver1CommandsLib.h"
16
17 EFI_STATUS
18 EFIAPI
19 GetDeviceHandleInfo (
20 IN EFI_HANDLE TheHandle,
21 IN CHAR16 *Type,
22 IN BOOLEAN *Cfg,
23 IN BOOLEAN *Diag,
24 IN UINT8 *Parents,
25 IN UINT8 *Devices,
26 IN UINT8 *Children,
27 OUT CHAR16 **Name,
28 IN CONST CHAR8 *Language
29 ){
30 *Name = NULL;
31
32 gEfiShellProtocol->GetDeviceName(TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, Name);
33
34
35
36
37
38
39
40
41
42
43
44
45
46 return (EFI_SUCCESS);
47 }
48
49 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
50 {L"-l", TypeValue},
51 {NULL, TypeMax}
52 };
53
54 SHELL_STATUS
55 EFIAPI
56 ShellCommandRunDevices (
57 VOID *RESERVED
58 ) {
59 EFI_STATUS Status;
60 LIST_ENTRY *Package;
61 CHAR16 *ProblemParam;
62 SHELL_STATUS ShellStatus;
63 CHAR8 *Language;
64 EFI_HANDLE *HandleList;
65 EFI_HANDLE *HandleListWalker;
66 CHAR16 Type;
67 BOOLEAN Cfg;
68 BOOLEAN Diag;
69 UINT8 Parents;
70 UINT8 Devices;
71 UINT8 Children;
72 CHAR16 *Name;
73
74 ShellStatus = SHELL_SUCCESS;
75 Language = NULL;
76
77 //
78 // initialize the shell lib (we must be in non-auto-init...)
79 //
80 Status = ShellInitialize();
81 ASSERT_EFI_ERROR(Status);
82
83 Status = CommandInit();
84 ASSERT_EFI_ERROR(Status);
85
86 //
87 // parse the command line
88 //
89 Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);
90 if EFI_ERROR(Status) {
91 if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {
92 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);
93 FreePool(ProblemParam);
94 ShellStatus = SHELL_INVALID_PARAMETER;
95 } else {
96 ASSERT(FALSE);
97 }
98 } else {
99 //
100 // if more than 0 'value' parameters we have too many parameters
101 //
102 if (ShellCommandLineGetRawValue(Package, 1) != NULL){
103 //
104 // error for too many parameters
105 //
106 ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_TOO_MANY), gShellDriver1HiiHandle);
107 ShellStatus = SHELL_INVALID_PARAMETER;
108 } else {
109 //
110 // get the language if necessary
111 //
112 if (ShellCommandLineGetFlag(Package, L"-l") != FALSE) {
113 Language = AllocateZeroPool(StrSize(ShellCommandLineGetValue(Package, L"-l")));
114 AsciiSPrint(Language, StrSize(ShellCommandLineGetValue(Package, L"-l")), "%S", ShellCommandLineGetValue(Package, L"-l"));
115 }
116
117 //
118 // Print Header
119 //
120 ShellPrintHiiEx(-1, -1, Language, STRING_TOKEN (STR_DEVICES_HEADER_LINES), gShellDriver1HiiHandle);
121
122 //
123 // loop through each handle
124 //
125 HandleList = GetHandleListByPotocol(NULL);
126 ASSERT(HandleList != NULL);
127 for (HandleListWalker = HandleList
128 ; HandleListWalker != NULL && *HandleListWalker != NULL && !EFI_ERROR(Status)
129 ; HandleListWalker++
130 ){
131 //
132 // get all the info on each handle
133 //
134 Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);
135 if (Parents != 0 || Devices != 0 || Children != 0) {
136 ShellPrintHiiEx(
137 -1,
138 -1,
139 Language,
140 STRING_TOKEN (STR_DEVICES_ITEM_LINE),
141 gShellDriver1HiiHandle,
142 *HandleListWalker,
143 Type,
144 Cfg!=FALSE?L'X':L'-',
145 Diag!=FALSE?L'X':L'-',
146 Parents,
147 Devices,
148 Children,
149 Name);
150 }
151 if (Name != NULL) {
152 FreePool(Name);
153 }
154 }
155
156 if (HandleList != NULL) {
157 FreePool(HandleList);
158 }
159 }
160 ShellCommandLineFreeVarList (Package);
161 }
162 return (ShellStatus);
163 }
164