3 * Copyright (C) 1998-2003 Brian Palmer <brianp@sginet.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 ///////////////////////////////////////////////////////////////////////////////////////
25 // This structure describes a cached block element. The disk is divided up into
26 // cache blocks. For disks which LBA is not supported each block is the size of
27 // one track. This will force the cache manager to make track sized reads, and
28 // therefore maximizes throughput. For disks which support LBA the block size
29 // is 64k because they have no cylinder, head, or sector boundaries.
31 ///////////////////////////////////////////////////////////////////////////////////////
34 LIST_ENTRY ListEntry
; // Doubly linked list synchronization member
36 ULONG BlockNumber
; // Track index for CHS, 64k block index for LBA
37 BOOLEAN LockedInCache
; // Indicates that this block is locked in cache memory
38 ULONG AccessCount
; // Access count for this block
40 PVOID BlockData
; // Pointer to block data
42 } CACHE_BLOCK
, *PCACHE_BLOCK
;
44 ///////////////////////////////////////////////////////////////////////////////////////
46 // This structure describes a cached drive. It contains the BIOS drive number
47 // and indicates whether or not LBA is supported. If LBA is not supported then
48 // the drive's geometry is described here.
50 ///////////////////////////////////////////////////////////////////////////////////////
56 ULONG BlockSize
; // Block size (in sectors)
57 LIST_ENTRY CacheBlockHead
; // Contains CACHE_BLOCK structures
59 } CACHE_DRIVE
, *PCACHE_DRIVE
;
62 ///////////////////////////////////////////////////////////////////////////////////////
66 ///////////////////////////////////////////////////////////////////////////////////////
67 extern CACHE_DRIVE CacheManagerDrive
;
68 extern BOOLEAN CacheManagerInitialized
;
69 extern ULONG CacheBlockCount
;
70 extern ULONG CacheSizeLimit
;
71 extern ULONG CacheSizeCurrent
;
73 ///////////////////////////////////////////////////////////////////////////////////////
77 ///////////////////////////////////////////////////////////////////////////////////////
78 PCACHE_BLOCK
CacheInternalGetBlockPointer(PCACHE_DRIVE CacheDrive
, ULONG BlockNumber
); // Returns a pointer to a CACHE_BLOCK structure given a block number
79 PCACHE_BLOCK
CacheInternalFindBlock(PCACHE_DRIVE CacheDrive
, ULONG BlockNumber
); // Searches the block list for a particular block
80 PCACHE_BLOCK
CacheInternalAddBlockToCache(PCACHE_DRIVE CacheDrive
, ULONG BlockNumber
); // Adds a block to the cache's block list
81 BOOLEAN
CacheInternalFreeBlock(PCACHE_DRIVE CacheDrive
); // Removes a block from the cache's block list & frees the memory
82 VOID
CacheInternalCheckCacheSizeLimits(PCACHE_DRIVE CacheDrive
); // Checks the cache size limits to see if we can add a new block, if not calls CacheInternalFreeBlock()
83 VOID
CacheInternalDumpBlockList(PCACHE_DRIVE CacheDrive
); // Dumps the list of cached blocks to the debug output port
84 VOID
CacheInternalOptimizeBlockList(PCACHE_DRIVE CacheDrive
, PCACHE_BLOCK CacheBlock
); // Moves the specified block to the head of the list
87 BOOLEAN
CacheInitializeDrive(UCHAR DriveNumber
);
88 VOID
CacheInvalidateCacheData(VOID
);
89 BOOLEAN
CacheReadDiskSectors(UCHAR DiskNumber
, ULONGLONG StartSector
, ULONG SectorCount
, PVOID Buffer
);
90 BOOLEAN
CacheForceDiskSectorsIntoCache(UCHAR DiskNumber
, ULONGLONG StartSector
, ULONG SectorCount
);
91 BOOLEAN
CacheReleaseMemory(ULONG MinimumAmountToRelease
);