14.gRT->GetNextVariableName API를 사용하여 모든 변수 이름 및 GUID 가져오기
이번 장에서는 런타임 변수를 모두 출력해보는 실습을 한다.
이를 위해서는 EFI Runtime Services의 GetNextVariableName() API 함수를 사용해야 한다.
GetNextVariableName()
Summary:
Enumerates the current variable names.
Prototype:
typedef
EFI_STATUS
GetNextVariableName (
IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid
);
Parameters:
VariableNameSize The size of the VariableName buffer. The size must be large
enough to fit input string supplied in VariableName buffer.
VariableName On input, supplies the last VariableName that was returned by
GetNextVariableName(). On output, returns the Nullterminated string
of the current variable.
VendorGuid On input, supplies the last VendorGuid that was returned by
GetNextVariableName(). On output, returns the VendorGuid
of the current variable.
Description
GetNextVariableName() is called multiple times to retrieve the VariableName and VendorGuid of all
variables currently available in the system. On each call to GetNextVariableName() the previous
results are passed into the interface, and on output the interface returns the next variable name data.
When the entire variable list has been returned, the error EFI_NOT_FOUND is returned.
Note that if EFI_BUFFER_TOO_SMALL is returned, the VariableName buffer was too small for the next
variable. When such an error occurs, the VariableNameSize is updated to reflect the size of buffer
needed. In all cases when calling GetNextVariableName() the VariableNameSize must not exceed the
actual buffer size that was allocated for VariableName. The VariableNameSize must not be smaller the size
of the variable name string passed to GetNextVariableName() on input in the VariableName buffer.
To start the search, a Null-terminated string is passed in VariableName; that is, VariableName is a pointer
to a Null character. This is always done on the initial call to GetNextVariableName(). When
VariableName is a pointer to a Null character, VendorGuid is ignored.
Status Codes Returned:
EFI_SUCCESS The function completed successfully.
EFI_NOT_FOUND The next variable was not found.
EFI_BUFFER_TOO_SMALL The VariableNameSize is too small for the result.
VariableNameSize has been updated with the size needed to complete the request.
...
이전에 gST/gBS를 얻기 위해 파일에 #include <Library/UefiBootServicesTableLib.h>를 포함했다. EFI Runtime Services Table에 대한 바로가기를 얻으려면 비슷한 헤더파일을 추가해야 한다.
AllocateZeroPool 은 UEFI 스펙에서 정의된 기능이 아니고 EDKII의 MemoryAllocationLib에서 사용자를 편하게 해주기 위해 만든 기능이다.
/** Allocates and zeros a buffer of type EfiBootServicesData. ...@param AllocationSize The number of bytes to allocate and zero.@return A pointer to the allocated buffer or NULL if allocation fails.**/VOID *EFIAPIAllocateZeroPool ( IN UINTN AllocationSize )
이 문자열은 변수 이름을 저장하기에 충분히 크지 않을 것이므로 적어도 첫 번째 호출에서는 확실하게 EFI_BUFFER_TOO_SMALL을 반환할 것이다.
이 경우 버퍼를 재할당해야 하는데 ReallocatePool 함수로 이를 수행할 수 있다.
ReallocatePool또한 EDKII의 MemoryAllocationLib에서 만들어진 함수이다.
/** Reallocates a buffer of type EfiBootServicesData. ...@param OldSize The size, in bytes, of OldBuffer.@param NewSize The size, in bytes, of the buffer to reallocate.@param OldBuffer The buffer to copy to the allocated buffer. This is an optional parameter that may be NULL.@return A pointer to the allocated buffer or NULL if allocation fails.**/VOID *EFIAPIReallocatePool ( IN UINTN OldSize, IN UINTN NewSize, IN VOID *OldBuffer OPTIONAL )