]>
git.proxmox.com Git - mirror_edk2.git/blob - FatPkg/EnhancedFatDxe/DirectoryCache.c
3 Copyright (c) 2005, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 Functions for directory cache operation
36 Free the directory structure and release the memory.
40 ODir - The directory to be freed.
51 // Release Directory Entry Nodes
53 while (!IsListEmpty (&ODir
->ChildList
)) {
54 DirEnt
= DIRENT_FROM_LINK (ODir
->ChildList
.ForwardLink
);
55 RemoveEntryList (&DirEnt
->Link
);
57 // Make sure the OFile has been closed
59 ASSERT (DirEnt
->OFile
== NULL
);
60 FatFreeDirEnt (DirEnt
);
75 Allocate the directory structure.
79 OFile - The corresponding OFile.
89 ODir
= AllocateZeroPool (sizeof (FAT_ODIR
));
92 // Initialize the directory entry list
94 ODir
->Signature
= FAT_ODIR_SIGNATURE
;
95 InitializeListHead (&ODir
->ChildList
);
96 ODir
->CurrentCursor
= &ODir
->ChildList
;
110 Discard the directory structure when an OFile will be freed.
111 Volume will cache this directory if the OFile does not represent a deleted file.
115 OFile - The OFile whose directory structure is to be discarded.
126 Volume
= OFile
->Volume
;
128 if (!OFile
->DirEnt
->Invalid
) {
130 // If OFile does not represent a deleted file, then we will cache the directory
131 // We use OFile's first cluster as the directory's tag
133 ODir
->DirCacheTag
= OFile
->FileCluster
;
134 InsertHeadList (&Volume
->DirCacheList
, &ODir
->DirCacheLink
);
135 if (Volume
->DirCacheCount
== FAT_MAX_DIR_CACHE_COUNT
) {
137 // Replace the least recent used directory
139 ODir
= ODIR_FROM_DIRCACHELINK (Volume
->DirCacheList
.BackLink
);
140 RemoveEntryList (&ODir
->DirCacheLink
);
143 // No need to find a replace
145 Volume
->DirCacheCount
++;
150 // Release ODir Structure
165 Request the directory structure when an OFile is newly generated.
166 If the directory structure is cached by volume, then just return this directory;
167 Otherwise, allocate a new one for OFile.
171 OFile - The OFile which requests directory structure.
182 FAT_ODIR
*CurrentODir
;
183 LIST_ENTRY
*CurrentODirLink
;
185 Volume
= OFile
->Volume
;
187 DirCacheTag
= OFile
->FileCluster
;
188 for (CurrentODirLink
= Volume
->DirCacheList
.ForwardLink
;
189 CurrentODirLink
!= &Volume
->DirCacheList
;
190 CurrentODirLink
= CurrentODirLink
->ForwardLink
192 CurrentODir
= ODIR_FROM_DIRCACHELINK (CurrentODirLink
);
193 if (CurrentODir
->DirCacheTag
== DirCacheTag
) {
194 RemoveEntryList (&CurrentODir
->DirCacheLink
);
195 Volume
->DirCacheCount
--;
203 // This directory is not cached, then allocate a new one
205 ODir
= FatAllocateODir (OFile
);
212 FatCleanupODirCache (
213 IN FAT_VOLUME
*Volume
219 Clean up all the cached directory structures when the volume is going to be abandoned.
223 Volume - FAT file system volume.
232 while (Volume
->DirCacheCount
> 0) {
233 ODir
= ODIR_FROM_DIRCACHELINK (Volume
->DirCacheList
.BackLink
);
234 RemoveEntryList (&ODir
->DirCacheLink
);
236 Volume
->DirCacheCount
--;