]>
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 This program and the accompanying materials are licensed and made available
6 under the terms and conditions of the BSD License which accompanies this
7 distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 Free the directory structure and release the memory.
22 @param ODir - The directory to be freed.
34 // Release Directory Entry Nodes
36 while (!IsListEmpty (&ODir
->ChildList
)) {
37 DirEnt
= DIRENT_FROM_LINK (ODir
->ChildList
.ForwardLink
);
38 RemoveEntryList (&DirEnt
->Link
);
40 // Make sure the OFile has been closed
42 ASSERT (DirEnt
->OFile
== NULL
);
43 FatFreeDirEnt (DirEnt
);
51 Allocate the directory structure.
53 @param OFile - The corresponding OFile.
64 ODir
= AllocateZeroPool (sizeof (FAT_ODIR
));
67 // Initialize the directory entry list
69 ODir
->Signature
= FAT_ODIR_SIGNATURE
;
70 InitializeListHead (&ODir
->ChildList
);
71 ODir
->CurrentCursor
= &ODir
->ChildList
;
79 Discard the directory structure when an OFile will be freed.
80 Volume will cache this directory if the OFile does not represent a deleted file.
82 @param OFile - The OFile whose directory structure is to be discarded.
93 Volume
= OFile
->Volume
;
95 if (!OFile
->DirEnt
->Invalid
) {
97 // If OFile does not represent a deleted file, then we will cache the directory
98 // We use OFile's first cluster as the directory's tag
100 ODir
->DirCacheTag
= OFile
->FileCluster
;
101 InsertHeadList (&Volume
->DirCacheList
, &ODir
->DirCacheLink
);
102 if (Volume
->DirCacheCount
== FAT_MAX_DIR_CACHE_COUNT
) {
104 // Replace the least recent used directory
106 ODir
= ODIR_FROM_DIRCACHELINK (Volume
->DirCacheList
.BackLink
);
107 RemoveEntryList (&ODir
->DirCacheLink
);
110 // No need to find a replace
112 Volume
->DirCacheCount
++;
117 // Release ODir Structure
127 Request the directory structure when an OFile is newly generated.
128 If the directory structure is cached by volume, then just return this directory;
129 Otherwise, allocate a new one for OFile.
131 @param OFile - The OFile which requests directory structure.
142 FAT_ODIR
*CurrentODir
;
143 LIST_ENTRY
*CurrentODirLink
;
145 Volume
= OFile
->Volume
;
147 DirCacheTag
= OFile
->FileCluster
;
148 for (CurrentODirLink
= Volume
->DirCacheList
.ForwardLink
;
149 CurrentODirLink
!= &Volume
->DirCacheList
;
150 CurrentODirLink
= CurrentODirLink
->ForwardLink
152 CurrentODir
= ODIR_FROM_DIRCACHELINK (CurrentODirLink
);
153 if (CurrentODir
->DirCacheTag
== DirCacheTag
) {
154 RemoveEntryList (&CurrentODir
->DirCacheLink
);
155 Volume
->DirCacheCount
--;
163 // This directory is not cached, then allocate a new one
165 ODir
= FatAllocateODir (OFile
);
173 Clean up all the cached directory structures when the volume is going to be abandoned.
175 @param Volume - FAT file system volume.
179 FatCleanupODirCache (
180 IN FAT_VOLUME
*Volume
184 while (Volume
->DirCacheCount
> 0) {
185 ODir
= ODIR_FROM_DIRCACHELINK (Volume
->DirCacheList
.BackLink
);
186 RemoveEntryList (&ODir
->DirCacheLink
);
188 Volume
->DirCacheCount
--;