/* Read next Long Allocation Descriptor from a given file's data. */
EFI_STATUS GetLongAdFromAds(IN VOID *Data, IN OUT UINT64 *Offset, IN UINT64 Length, OUT UDF_LONG_ALLOCATION_DESCRIPTOR **FoundLongAd)
/* Read next Long Allocation Descriptor from a given file's data. */
EFI_STATUS GetLongAdFromAds(IN VOID *Data, IN OUT UINT64 *Offset, IN UINT64 Length, OUT UDF_LONG_ALLOCATION_DESCRIPTOR **FoundLongAd)
{
  UDF_LONG_ALLOCATION_DESCRIPTOR  *LongAd;
  UDF_EXTENT_FLAGS                ExtentFlags;
  for ( ; ;) {
    if (*Offset >= Length) {
      return EFI_DEVICE_ERROR;
    }
    LongAd =
      (UDF_LONG_ALLOCATION_DESCRIPTOR *)((UINT8 *)Data + *Offset);
    ExtentFlags = GET_EXTENT_FLAGS (LongAdsSequence, LongAd);
    if ((ExtentFlags == ExtentIsNextExtent) ||
        (ExtentFlags == ExtentRecordedAndAllocated))
    {
      break;
    }
    *Offset += AD_LENGTH (LongAdsSequence);
  }
  *FoundLongAd = LongAd;
  return EFI_SUCCESS;
}