/** Helper macro for stringification. */
#define FSW_EFI_STRINGIFY(x) #x
/** Expands to the EFI driver name given the file system type name. */
-#define FSW_EFI_DRIVER_NAME(t) L"rEFInd 0.7.0 " FSW_EFI_STRINGIFY(t) L" File System Driver"
+#define FSW_EFI_DRIVER_NAME(t) L"rEFInd 0.7.8 " FSW_EFI_STRINGIFY(t) L" File System Driver"
// function prototypes
#define NUM_CACHES 2 /* Don't increase without modifying fsw_efi_read_block() */
static struct cache_data Caches[NUM_CACHES];
+static int LastRead = -1;
/**
* Interface structure for the EFI Driver Binding protocol.
//#include "OverrideFunctions-kabyl.edk2.c.include"
+static VOID EFIAPI fsw_efi_clear_cache(VOID) {
+ int i;
+
+ // clear the cache
+ for (i = 0; i < NUM_CACHES; i++) {
+ if (Caches[i].Cache != NULL) {
+ FreePool(Caches[i].Cache);
+ Caches[i].Cache = NULL;
+ } // if
+ Caches[i].CacheStart = 0;
+ Caches[i].CacheValid = FALSE;
+ Caches[i].Volume = NULL;
+ }
+ LastRead = -1;
+} // VOID EFIAPI fsw_efi_clear_cache();
+
/**
* Image entry point. Installs the Driver Binding and Component Name protocols
* on the image's handle. Actually mounting a file system is initiated through
EFI_STATUS Status;
EFI_FILE_IO_INTERFACE *FileSystem;
FSW_VOLUME_DATA *Volume;
- int i;
#if DEBUG_LEVEL
Print(L"fsw_efi_DriverBinding_Stop\n");
ControllerHandle);
// clear the cache
- for (i = 0; i < NUM_CACHES; i++) {
- if (Caches[i].Cache != NULL) {
- FreePool(Caches[i].Cache);
- Caches[i].Cache = NULL;
- } // if
- }
+ fsw_efi_clear_cache();
+
return Status;
}
*/
fsw_status_t fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void *buffer) {
- static int LastRead = -1;
int i, ReadCache = -1;
FSW_VOLUME_DATA *Volume = (FSW_VOLUME_DATA *)vol->host_data;
EFI_STATUS Status = EFI_SUCCESS;
// Initialize static data structures, if necessary....
if (LastRead < 0) {
- for (i = 0; i < NUM_CACHES; i++) {
- Caches[i].Cache = NULL;
- Caches[i].CacheStart = 0;
- Caches[i].CacheValid = FALSE;
- Caches[i].Volume = NULL;
- } // for
+ fsw_efi_clear_cache();
} // if
// Look for a cache hit on the current query....
i = 0;
do {
if ((Caches[i].Volume == Volume) &&
+ (Caches[i].CacheValid == TRUE) &&
(StartRead >= Caches[i].CacheStart) &&
((StartRead + vol->phys_blocksize) <= (Caches[i].CacheStart + CACHE_SIZE))) {
ReadCache = i;
if (LastRead == -1)
LastRead = 1;
ReadCache = 1 - LastRead; // NOTE: If NUM_CACHES > 2, this must become more complex
+ Caches[ReadCache].CacheValid = FALSE;
if (Caches[ReadCache].Cache == NULL)
Caches[ReadCache].Cache = AllocatePool(CACHE_SIZE);
if (Caches[ReadCache].Cache != NULL) {
} // if cache memory allocated
} // if (ReadCache < 0)
- if (Caches[ReadCache].Cache != NULL) {
+ if (Caches[ReadCache].Cache != NULL && Caches[ReadCache].CacheValid == TRUE) {
CopyMem(buffer, &Caches[ReadCache].Cache[StartRead - Caches[ReadCache].CacheStart], vol->phys_blocksize);
} else {
ReadOneBlock = TRUE;
vol->phys_blocksize,
buffer);
}
+ Volume->LastIOStatus = Status;
return Status;
} // fsw_status_t *fsw_efi_read_block()
Print(L"fsw_efi_FileSystem_OpenVolume\n");
#endif
+ fsw_efi_clear_cache();
Status = fsw_efi_dnode_to_FileHandle(Volume->vol->root, Root);
return Status;