/* Format the last component of a canonical pathname into a caller-provided CHAR16 array. */
EFI_STATUS VirtioFsGetBasename(IN CHAR8 *Path, OUT CHAR16 *Basename OPTIONAL, IN OUT UINTN *BasenameSize)
/* Format the last component of a canonical pathname into a caller-provided CHAR16 array. */
EFI_STATUS VirtioFsGetBasename(IN CHAR8 *Path, OUT CHAR16 *Basename OPTIONAL, IN OUT UINTN *BasenameSize)
{
  UINTN  AllocSize;
  UINTN  LastComponent;
  UINTN  Idx;
  UINTN  PathSize;
  AllocSize = *BasenameSize;
  LastComponent = MAX_UINTN;
  for (Idx = 0; Path[Idx] != '\0'; Idx++) {
    if (Path[Idx] == '/') {
      LastComponent = Idx;
    }
  }
  PathSize = Idx + 1;
  ASSERT (LastComponent < MAX_UINTN);
  LastComponent++;
  *BasenameSize = (PathSize - LastComponent) * sizeof Basename[0];
  if (*BasenameSize > AllocSize) {
    return EFI_BUFFER_TOO_SMALL;
  }
  for (Idx = LastComponent; Idx < PathSize; Idx++) {
    Basename[Idx - LastComponent] = Path[Idx];
  }
  return EFI_SUCCESS;
}