/* Request the directory structure when an OFile is newly generated. If the directory structure is cached by volume, then just return this directory; Otherwise, allocate a new one for OFile. */
VOID FatRequestODir(IN FAT_OFILE *OFile)
/* Request the directory structure when an OFile is newly generated. If the directory structure is cached by volume, then just return this directory; Otherwise, allocate a new one for OFile. */
VOID FatRequestODir(IN FAT_OFILE *OFile)
{
  UINTN       DirCacheTag;
  FAT_VOLUME  *Volume;
  FAT_ODIR    *ODir;
  FAT_ODIR    *CurrentODir;
  LIST_ENTRY  *CurrentODirLink;
  Volume      = OFile->Volume;
  ODir        = NULL;
  DirCacheTag = OFile->FileCluster;
  for (CurrentODirLink  = Volume->DirCacheList.ForwardLink;
       CurrentODirLink != &Volume->DirCacheList;
       CurrentODirLink  = CurrentODirLink->ForwardLink
       )
  {
    CurrentODir = ODIR_FROM_DIRCACHELINK (CurrentODirLink);
    if (CurrentODir->DirCacheTag == DirCacheTag) {
      RemoveEntryList (&CurrentODir->DirCacheLink);
      Volume->DirCacheCount--;
      ODir = CurrentODir;
      break;
    }
  }
  if (ODir == NULL) {
    ODir = FatAllocateODir (OFile);
  }
  OFile->ODir = ODir;
}