]>
git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/DirectoryCache.c
2 Functions for directory cache operation.
4 Copyright (c) 2005, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
14 Free the directory structure and release the memory.
16 @param ODir - The directory to be freed.
28 // Release Directory Entry Nodes
30 while (!IsListEmpty (&ODir
->ChildList
)) {
31 DirEnt
= DIRENT_FROM_LINK (ODir
->ChildList
.ForwardLink
);
32 RemoveEntryList (&DirEnt
->Link
);
34 // Make sure the OFile has been closed
36 ASSERT (DirEnt
->OFile
== NULL
);
37 FatFreeDirEnt (DirEnt
);
45 Allocate the directory structure.
47 @param OFile - The corresponding OFile.
58 ODir
= AllocateZeroPool (sizeof (FAT_ODIR
));
61 // Initialize the directory entry list
63 ODir
->Signature
= FAT_ODIR_SIGNATURE
;
64 InitializeListHead (&ODir
->ChildList
);
65 ODir
->CurrentCursor
= &ODir
->ChildList
;
73 Discard the directory structure when an OFile will be freed.
74 Volume will cache this directory if the OFile does not represent a deleted file.
76 @param OFile - The OFile whose directory structure is to be discarded.
87 Volume
= OFile
->Volume
;
89 if (!OFile
->DirEnt
->Invalid
) {
91 // If OFile does not represent a deleted file, then we will cache the directory
92 // We use OFile's first cluster as the directory's tag
94 ODir
->DirCacheTag
= OFile
->FileCluster
;
95 InsertHeadList (&Volume
->DirCacheList
, &ODir
->DirCacheLink
);
96 if (Volume
->DirCacheCount
== FAT_MAX_DIR_CACHE_COUNT
) {
98 // Replace the least recent used directory
100 ODir
= ODIR_FROM_DIRCACHELINK (Volume
->DirCacheList
.BackLink
);
101 RemoveEntryList (&ODir
->DirCacheLink
);
104 // No need to find a replace
106 Volume
->DirCacheCount
++;
111 // Release ODir Structure
121 Request the directory structure when an OFile is newly generated.
122 If the directory structure is cached by volume, then just return this directory;
123 Otherwise, allocate a new one for OFile.
125 @param OFile - The OFile which requests directory structure.
136 FAT_ODIR
*CurrentODir
;
137 LIST_ENTRY
*CurrentODirLink
;
139 Volume
= OFile
->Volume
;
141 DirCacheTag
= OFile
->FileCluster
;
142 for (CurrentODirLink
= Volume
->DirCacheList
.ForwardLink
;
143 CurrentODirLink
!= &Volume
->DirCacheList
;
144 CurrentODirLink
= CurrentODirLink
->ForwardLink
146 CurrentODir
= ODIR_FROM_DIRCACHELINK (CurrentODirLink
);
147 if (CurrentODir
->DirCacheTag
== DirCacheTag
) {
148 RemoveEntryList (&CurrentODir
->DirCacheLink
);
149 Volume
->DirCacheCount
--;
157 // This directory is not cached, then allocate a new one
159 ODir
= FatAllocateODir (OFile
);
167 Clean up all the cached directory structures when the volume is going to be abandoned.
169 @param Volume - FAT file system volume.
173 FatCleanupODirCache (
174 IN FAT_VOLUME
*Volume
178 while (Volume
->DirCacheCount
> 0) {
179 ODir
= ODIR_FROM_DIRCACHELINK (Volume
->DirCacheList
.BackLink
);
180 RemoveEntryList (&ODir
->DirCacheLink
);
182 Volume
->DirCacheCount
--;