Better LBA support
[reactos.git] / freeldr / freeldr / cache / cm.h
1 /*
2 * FreeLoader
3 * Copyright (C) 1998-2002 Brian Palmer <brianp@sginet.com>
4 *
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.
9 *
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21 #include <freeldr.h>
22 #include <rtl.h>
23 #include <disk.h>
24
25 #ifndef __CM_H
26 #define __CM_H
27
28 ///////////////////////////////////////////////////////////////////////////////////////
29 //
30 // This structure describes a cached block element. The disk is divided up into
31 // cache blocks. For disks which LBA is not supported each block is the size of
32 // one track. This will force the cache manager to make track sized reads, and
33 // therefore maximizes throughput. For disks which support LBA the block size
34 // is 64k because they have no cylinder, head, or sector boundaries.
35 //
36 ///////////////////////////////////////////////////////////////////////////////////////
37 typedef struct
38 {
39 LIST_ITEM ListEntry; // Doubly linked list synchronization member
40
41 ULONG BlockNumber; // Track index for CHS, 64k block index for LBA
42 BOOL LockedInCache; // Indicates that this block is locked in cache memory
43 ULONG AccessCount; // Access count for this block
44
45 PVOID BlockData; // Pointer to block data
46
47 } CACHE_BLOCK, *PCACHE_BLOCK;
48
49 ///////////////////////////////////////////////////////////////////////////////////////
50 //
51 // This structure describes a cached drive. It contains the BIOS drive number
52 // and indicates whether or not LBA is supported. If LBA is not supported then
53 // the drive's geometry is described here.
54 //
55 ///////////////////////////////////////////////////////////////////////////////////////
56 typedef struct
57 {
58 ULONG DriveNumber;
59 BOOL LbaSupported;
60 GEOMETRY DriveGeometry;
61
62 ULONG BlockSize; // Block size (in sectors)
63 PCACHE_BLOCK CacheBlockHead;
64
65 } CACHE_DRIVE, *PCACHE_DRIVE;
66
67
68 ///////////////////////////////////////////////////////////////////////////////////////
69 //
70 // Internal data
71 //
72 ///////////////////////////////////////////////////////////////////////////////////////
73 extern CACHE_DRIVE CacheManagerDrive;
74 extern BOOL CacheManagerInitialized;
75 extern ULONG CacheBlockCount;
76 extern ULONG CacheSizeLimit;
77 extern ULONG CacheSizeCurrent;
78
79 ///////////////////////////////////////////////////////////////////////////////////////
80 //
81 // Internal functions
82 //
83 ///////////////////////////////////////////////////////////////////////////////////////
84 PCACHE_BLOCK CacheInternalGetBlockPointer(PCACHE_DRIVE CacheDrive, ULONG BlockNumber); // Returns a pointer to a CACHE_BLOCK structure given a block number
85 PCACHE_BLOCK CacheInternalFindBlock(PCACHE_DRIVE CacheDrive, ULONG BlockNumber); // Searches the block list for a particular block
86 PCACHE_BLOCK CacheInternalAddBlockToCache(PCACHE_DRIVE CacheDrive, ULONG BlockNumber); // Adds a block to the cache's block list
87 BOOL CacheInternalFreeBlock(PCACHE_DRIVE CacheDrive); // Removes a block from the cache's block list & frees the memory
88 VOID CacheInternalCheckCacheSizeLimits(PCACHE_DRIVE CacheDrive); // Checks the cache size limits to see if we can add a new block, if not calls CacheInternalFreeBlock()
89 VOID CacheInternalDumpBlockList(PCACHE_DRIVE CacheDrive); // Dumps the list of cached blocks to the debug output port
90 VOID CacheInternalOptimizeBlockList(PCACHE_DRIVE CacheDrive, PCACHE_BLOCK CacheBlock); // Moves the specified block to the head of the list
91
92
93 #endif // defined __CM_H