]> glassweightruler.freedombox.rocks Git - Ventoy.git/blob - EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/VtoyUtil/VtoyDrv.c
1.1.07 release
[Ventoy.git] / EDK2 / edk2_mod / edk2-edk2-stable201911 / MdeModulePkg / Application / VtoyUtil / VtoyDrv.c
1 /******************************************************************************
2 * VtoyDrv.c
3 *
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 3 of the
9 * License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #include <Uefi.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PrintLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/BaseMemoryLib.h>
26 #include <Library/DevicePathLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiRuntimeServicesTableLib.h>
30 #include <Library/UefiApplicationEntryPoint.h>
31 #include <Protocol/LoadedImage.h>
32 #include <Guid/FileInfo.h>
33 #include <Guid/FileSystemInfo.h>
34 #include <Protocol/BlockIo.h>
35 #include <Protocol/RamDisk.h>
36 #include <Protocol/SimpleFileSystem.h>
37 #include <VtoyUtil.h>
38
39 STATIC UINTN g_EfiDriverNameCnt = 0;
40 STATIC CHAR16 *g_EfiDriverNameList[1024] = { NULL };
41
42 STATIC EFI_STATUS AddEfiDriverName(IN CHAR16 *DriverName)
43 {
44 UINTN i = 0;
45
46 if (g_EfiDriverNameCnt >= 1024)
47 {
48 return EFI_OUT_OF_RESOURCES;
49 }
50
51 for (i = 0; i < g_EfiDriverNameCnt; i++)
52 {
53 if (g_EfiDriverNameList[i] && StrCmp(g_EfiDriverNameList[i], DriverName) == 0)
54 {
55 break;
56 }
57 }
58
59 if (i >= g_EfiDriverNameCnt)
60 {
61 g_EfiDriverNameList[g_EfiDriverNameCnt] = DriverName;
62 g_EfiDriverNameCnt++;
63 }
64
65 return EFI_SUCCESS;
66 }
67
68 EFI_STATUS ShowEfiDrivers(IN EFI_HANDLE ImageHandle, IN CONST CHAR16 *CmdLine)
69 {
70 UINTN i = 0;
71 UINTN Count = 0;
72 CHAR16 *DriverName = NULL;
73 EFI_HANDLE *Handles = NULL;
74 EFI_STATUS Status = EFI_SUCCESS;
75 EFI_COMPONENT_NAME_PROTOCOL *NameProtocol = NULL;
76 EFI_COMPONENT_NAME2_PROTOCOL *Name2Protocol = NULL;
77
78 (VOID)ImageHandle;
79 (VOID)CmdLine;
80
81 Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentName2ProtocolGuid,
82 NULL, &Count, &Handles);
83 if (EFI_ERROR(Status))
84 {
85 return Status;
86 }
87
88 for (i = 0; i < Count; i++)
89 {
90 Status = gBS->HandleProtocol(Handles[i], &gEfiComponentName2ProtocolGuid, (VOID **)&Name2Protocol);
91 if (EFI_ERROR(Status))
92 {
93 continue;
94 }
95
96 DriverName = NULL;
97 Status = VtoyGetComponentName(2, Name2Protocol, &DriverName);
98 if ((!EFI_ERROR(Status)) && (DriverName))
99 {
100 AddEfiDriverName(DriverName);
101 }
102 }
103
104 Count = 0;
105 FreePool(Handles);
106 Handles = NULL;
107
108 Status = gBS->LocateHandleBuffer(ByProtocol, &gEfiComponentNameProtocolGuid,
109 NULL, &Count, &Handles);
110 if (EFI_ERROR(Status))
111 {
112 return Status;
113 }
114
115 for (i = 0; i < Count; i++)
116 {
117 Status = gBS->HandleProtocol(Handles[i], &gEfiComponentNameProtocolGuid, (VOID **)&NameProtocol);
118 if (EFI_ERROR(Status))
119 {
120 continue;
121 }
122
123 DriverName = NULL;
124 Status = VtoyGetComponentName(1, Name2Protocol, &DriverName);
125 if ((!EFI_ERROR(Status)) && (DriverName))
126 {
127 AddEfiDriverName(DriverName);
128 }
129 }
130
131 FreePool(Handles);
132
133 for (i = 0; i < g_EfiDriverNameCnt; i++)
134 {
135 Printf("%2d %s\n", i, g_EfiDriverNameList[i]);
136 }
137
138 return EFI_SUCCESS;
139 }
140