-/**\r
-\r
- Get the full size of SMBIOS structure including optional strings that follow the formatted structure.\r
- @note: This function is copy from SmbiosDxe in MdeModulePkg.\r
-\r
- @param[in] This The EFI_SMBIOS_PROTOCOL instance.\r
- @param[in] Head Pointer to the beginning of SMBIOS structure.\r
- @param[out] Size The returned size.\r
- @param[out] NumberOfStrings The returned number of optional strings that follow the formatted structure.\r
-\r
- @retval EFI_SUCCESS Size returned in Size.\r
- @retval EFI_INVALID_PARAMETER Input SMBIOS structure mal-formed or Size is NULL.\r
-\r
-**/\r
-EFI_STATUS\r
-EFIAPI\r
-GetSmbiosStructureSize (\r
- IN CONST EFI_SMBIOS_PROTOCOL *This,\r
- IN EFI_SMBIOS_TABLE_HEADER *Head,\r
- OUT UINTN *Size,\r
- OUT UINTN *NumberOfStrings\r
- )\r
-{\r
- UINTN FullSize;\r
- UINTN StrLen;\r
- UINTN MaxLen;\r
- INT8* CharInStr;\r
-\r
- if (Size == NULL || NumberOfStrings == NULL) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- FullSize = Head->Length;\r
- CharInStr = (INT8*)Head + Head->Length;\r
- *Size = FullSize;\r
- *NumberOfStrings = 0;\r
- StrLen = 0;\r
-\r
- //\r
- // look for the two consecutive zeros, check the string limit by the way.\r
- //\r
- while (*CharInStr != 0 || *(CharInStr+1) != 0) {\r
- if (*CharInStr == 0) {\r
- *Size += 1;\r
- CharInStr++;\r
- }\r
-\r
- if (This->MajorVersion < 2 || (This->MajorVersion == 2 && This->MinorVersion < 7)) {\r
- MaxLen = SMBIOS_STRING_MAX_LENGTH;\r
- } else if (This->MajorVersion < 3) {\r
- //\r
- // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string.\r
- // However, the length of the entire structure table (including all strings) must be reported\r
- // in the Structure Table Length field of the SMBIOS Structure Table Entry Point,\r
- // which is a WORD field limited to 65,535 bytes.\r
- //\r
- MaxLen = SMBIOS_TABLE_MAX_LENGTH;\r
- } else {\r
- //\r
- // SMBIOS 3.0 defines the Structure table maximum size as DWORD field limited to 0xFFFFFFFF bytes.\r
- // Locate the end of string as long as possible.\r
- //\r
- MaxLen = SMBIOS_3_0_TABLE_MAX_LENGTH;\r
- }\r
-\r
- for (StrLen = 0 ; StrLen < MaxLen; StrLen++) {\r
- if (*(CharInStr+StrLen) == 0) {\r
- break;\r
- }\r
- }\r
-\r
- if (StrLen == MaxLen) {\r
- return EFI_INVALID_PARAMETER;\r
- }\r
-\r
- //\r
- // forward the pointer\r
- //\r
- CharInStr += StrLen;\r
- *Size += StrLen;\r
- *NumberOfStrings += 1;\r
- }\r
-\r
- //\r
- // count ending two zeros.\r
- //\r
- *Size += 2;\r
- return EFI_SUCCESS;\r
-}\r