1 /* 2 * COPYRIGHT: See COPYING.ARM in the top level directory 3 * PROJECT: ReactOS UEFI Boot Library 4 * FILE: boot/environ/lib/io/blkcache.c 5 * PURPOSE: Boot Library Block Cache Management Routines 6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org) 7 */ 8 9 /* INCLUDES ******************************************************************/ 10 11 #include "bl.h" 12 13 /* DATA VARIABLES ************************************************************/ 14 15 ULONG BcpBlockAllocatorHandle; 16 ULONG BcpHashTableId; 17 18 /* FUNCTIONS *****************************************************************/ 19 20 NTSTATUS 21 BcpDestroy ( 22 VOID 23 ) 24 { 25 //BcpPurgeCacheEntries(); 26 //return BlpMmDeleteBlockAllocator(BcpBlockAllocatorHandle); 27 EfiPrintf(L"Destructor for block cache not yet implemented\r\n"); 28 return STATUS_NOT_IMPLEMENTED; 29 } 30 31 BOOLEAN 32 BcpCompareKey ( 33 _In_ PBL_HASH_ENTRY Entry1, 34 _In_ PBL_HASH_ENTRY Entry2 35 ) 36 { 37 PULONG Value1, Value2; 38 39 Value1 = Entry1->Value; 40 Value2 = Entry2->Value; 41 return Entry1->Size == Entry2->Size && Entry1->Flags == Entry2->Flags && *Value1 == *Value2 && Value1[1] == Value2[1] && Value1[2] == Value2[2]; 42 } 43 44 ULONG 45 BcpHashFunction ( 46 _In_ PBL_HASH_ENTRY Entry, 47 _In_ ULONG TableSize 48 ) 49 { 50 ULONG i, j, ValueHash; 51 PUCHAR ValueBuffer; 52 53 j = 0; 54 ValueHash = 0; 55 i = 0; 56 57 ValueBuffer = Entry->Value; 58 59 do 60 { 61 ValueHash += ValueBuffer[i++]; 62 } while (i < 8); 63 64 do 65 { 66 ValueHash += ValueBuffer[j++ + 8]; 67 } while (j < 4); 68 69 return ValueHash % TableSize; 70 } 71 72 NTSTATUS 73 BcInitialize ( 74 VOID 75 ) 76 { 77 NTSTATUS Status; 78 79 Status = BlHtCreate(50, BcpHashFunction, BcpCompareKey, &BcpHashTableId); 80 if (!NT_SUCCESS(Status)) 81 { 82 goto Quickie; 83 } 84 85 BcpBlockAllocatorHandle = BlpMmCreateBlockAllocator(); 86 if (BcpBlockAllocatorHandle == -1) 87 { 88 Status = STATUS_UNSUCCESSFUL; 89 goto Quickie; 90 } 91 92 Status = BlpIoRegisterDestroyRoutine(BcpDestroy); 93 if (Status >= 0) 94 { 95 return Status; 96 } 97 98 Quickie: 99 EfiPrintf(L"Failure path not yet implemented\r\n"); 100 #if 0 101 if (BcpHashTableId != -1) 102 { 103 BlHtDestroy(BcpHashTableId); 104 } 105 if (BcpBlockAllocatorHandle != -1) 106 { 107 BlpMmDeleteBlockAllocator(BcpBlockAllocatorHandle); 108 } 109 #endif 110 return Status; 111 } 112