1 /******************************************************************************
4 * Copyright (c) 2020, longpanda <admin@ventoy.net>
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.
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.
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/>.
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>
39 STATIC UINTN g_EfiDriverNameCnt
= 0;
40 STATIC CHAR16
*g_EfiDriverNameList
[1024] = { NULL
};
42 STATIC EFI_STATUS
AddEfiDriverName(IN CHAR16
*DriverName
)
46 if (g_EfiDriverNameCnt
>= 1024)
48 return EFI_OUT_OF_RESOURCES
;
51 for (i
= 0; i
< g_EfiDriverNameCnt
; i
++)
53 if (g_EfiDriverNameList
[i
] && StrCmp(g_EfiDriverNameList
[i
], DriverName
) == 0)
59 if (i
>= g_EfiDriverNameCnt
)
61 g_EfiDriverNameList
[g_EfiDriverNameCnt
] = DriverName
;
68 EFI_STATUS
ShowEfiDrivers(IN EFI_HANDLE ImageHandle
, IN CONST CHAR16
*CmdLine
)
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
;
81 Status
= gBS
->LocateHandleBuffer(ByProtocol
, &gEfiComponentName2ProtocolGuid
,
82 NULL
, &Count
, &Handles
);
83 if (EFI_ERROR(Status
))
88 for (i
= 0; i
< Count
; i
++)
90 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiComponentName2ProtocolGuid
, (VOID
**)&Name2Protocol
);
91 if (EFI_ERROR(Status
))
97 Status
= VtoyGetComponentName(2, Name2Protocol
, &DriverName
);
98 if ((!EFI_ERROR(Status
)) && (DriverName
))
100 AddEfiDriverName(DriverName
);
108 Status
= gBS
->LocateHandleBuffer(ByProtocol
, &gEfiComponentNameProtocolGuid
,
109 NULL
, &Count
, &Handles
);
110 if (EFI_ERROR(Status
))
115 for (i
= 0; i
< Count
; i
++)
117 Status
= gBS
->HandleProtocol(Handles
[i
], &gEfiComponentNameProtocolGuid
, (VOID
**)&NameProtocol
);
118 if (EFI_ERROR(Status
))
124 Status
= VtoyGetComponentName(1, Name2Protocol
, &DriverName
);
125 if ((!EFI_ERROR(Status
)) && (DriverName
))
127 AddEfiDriverName(DriverName
);
133 for (i
= 0; i
< g_EfiDriverNameCnt
; i
++)
135 Printf("%2d %s\n", i
, g_EfiDriverNameList
[i
]);