X-Git-Url: https://code.delx.au/refind/blobdiff_plain/69be20dc8a21b0cb76686c20a36d6c374ba320d8..6ca3056aca9ce090d2f0f7cbf32cdf2323252abf:/filesystems/fsw_efi.c diff --git a/filesystems/fsw_efi.c b/filesystems/fsw_efi.c index f2cb4fe..5ef49be 100644 --- a/filesystems/fsw_efi.c +++ b/filesystems/fsw_efi.c @@ -43,6 +43,8 @@ #ifdef __MAKEWITH_GNUEFI #include "edk2/DriverBinding.h" #include "edk2/ComponentName.h" +#else +#define REFIND_EFI_COMPONENT_NAME_PROTOCOL EFI_COMPONENT_NAME_PROTOCOL #endif #include "../include/refit_call_wrapper.h" @@ -66,9 +68,9 @@ } EFI_GUID gEfiDriverBindingProtocolGuid = EFI_DRIVER_BINDING_PROTOCOL_GUID; -EFI_GUID gEfiComponentNameProtocolGuid = EFI_COMPONENT_NAME_PROTOCOL_GUID; -extern EFI_GUID gEfiDiskIoProtocolGuid = EFI_DISK_IO_PROTOCOL_GUID; -extern EFI_GUID gEfiBlockIoProtocolGuid = EFI_BLOCK_IO_PROTOCOL_GUID; +EFI_GUID gEfiComponentNameProtocolGuid = REFIND_EFI_COMPONENT_NAME_PROTOCOL_GUID; +EFI_GUID gEfiDiskIoProtocolGuid = EFI_DISK_IO_PROTOCOL_GUID; +EFI_GUID gEfiBlockIoProtocolGuid = EFI_BLOCK_IO_PROTOCOL_GUID; EFI_GUID gEfiFileInfoGuid = EFI_FILE_INFO_ID; EFI_GUID gEfiFileSystemInfoGuid = EFI_FILE_SYSTEM_INFO_ID; EFI_GUID gEfiFileSystemVolumeLabelInfoIdGuid = EFI_FILE_SYSTEM_VOLUME_LABEL_INFO_ID; @@ -78,7 +80,7 @@ EFI_GUID gEfiFileSystemVolumeLabelInfoIdGuid = EFI_FILE_SYSTEM_VOLUME_LABEL_INFO /** 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.8.4 " FSW_EFI_STRINGIFY(t) L" File System Driver" +#define FSW_EFI_DRIVER_NAME(t) L"rEFInd 0.10.3 " FSW_EFI_STRINGIFY(t) L" File System Driver" // function prototypes @@ -93,19 +95,19 @@ EFI_STATUS EFIAPI fsw_efi_DriverBinding_Stop(IN EFI_DRIVER_BINDING_PROTOCOL *T IN UINTN NumberOfChildren, IN EFI_HANDLE *ChildHandleBuffer); -EFI_STATUS EFIAPI fsw_efi_ComponentName_GetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL *This, +EFI_STATUS EFIAPI fsw_efi_ComponentName_GetDriverName(IN REFIND_EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName); -EFI_STATUS EFIAPI fsw_efi_ComponentName_GetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL *This, +EFI_STATUS EFIAPI fsw_efi_ComponentName_GetControllerName(IN REFIND_EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, OUT CHAR16 **ControllerName); -void fsw_efi_change_blocksize(struct fsw_volume *vol, +void EFIAPI fsw_efi_change_blocksize(struct fsw_volume *vol, fsw_u32 old_phys_blocksize, fsw_u32 old_log_blocksize, fsw_u32 new_phys_blocksize, fsw_u32 new_log_blocksize); -fsw_status_t fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void *buffer); +fsw_status_t EFIAPI fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void *buffer); EFI_STATUS fsw_efi_map_status(fsw_status_t fsw_status, FSW_VOLUME_DATA *Volume); @@ -175,7 +177,7 @@ EFI_DRIVER_BINDING_PROTOCOL fsw_efi_DriverBinding_table = { * Interface structure for the EFI Component Name protocol. */ -EFI_COMPONENT_NAME_PROTOCOL fsw_efi_ComponentName_table = { +REFIND_EFI_COMPONENT_NAME_PROTOCOL fsw_efi_ComponentName_table = { fsw_efi_ComponentName_GetDriverName, fsw_efi_ComponentName_GetControllerName, (CHAR8*) "eng" @@ -221,7 +223,7 @@ EFI_STATUS EFIAPI fsw_efi_main(IN EFI_HANDLE ImageHandle, { EFI_STATUS Status; -#ifndef HOST_EFI_EDK2 +#ifndef __MAKEWITH_TIANO // Not available in EDK2 toolkit InitializeLib(ImageHandle, SystemTable); #endif @@ -391,7 +393,6 @@ EFI_STATUS EFIAPI fsw_efi_DriverBinding_Start(IN EFI_DRIVER_BINDING_PROTOCOL *T This->DriverBindingHandle, ControllerHandle); } - return Status; } @@ -466,7 +467,7 @@ EFI_STATUS EFIAPI fsw_efi_DriverBinding_Stop(IN EFI_DRIVER_BINDING_PROTOCOL *T * based on the file system type actually used in compilation. */ -EFI_STATUS EFIAPI fsw_efi_ComponentName_GetDriverName(IN EFI_COMPONENT_NAME_PROTOCOL *This, +EFI_STATUS EFIAPI fsw_efi_ComponentName_GetDriverName(IN REFIND_EFI_COMPONENT_NAME_PROTOCOL *This, IN CHAR8 *Language, OUT CHAR16 **DriverName) { @@ -485,7 +486,7 @@ EFI_STATUS EFIAPI fsw_efi_ComponentName_GetDriverName(IN EFI_COMPONENT_NAME_PRO * because this is not a "bus" driver in the sense of the EFI Driver Model. */ -EFI_STATUS EFIAPI fsw_efi_ComponentName_GetControllerName(IN EFI_COMPONENT_NAME_PROTOCOL *This, +EFI_STATUS EFIAPI fsw_efi_ComponentName_GetControllerName(IN REFIND_EFI_COMPONENT_NAME_PROTOCOL *This, IN EFI_HANDLE ControllerHandle, IN EFI_HANDLE ChildHandle OPTIONAL, IN CHAR8 *Language, @@ -499,7 +500,7 @@ EFI_STATUS EFIAPI fsw_efi_ComponentName_GetControllerName(IN EFI_COMPONENT_NAME * when the file system driver changes the block sizes for the volume. */ -void fsw_efi_change_blocksize(struct fsw_volume *vol, +void EFIAPI fsw_efi_change_blocksize(struct fsw_volume *vol, fsw_u32 old_phys_blocksize, fsw_u32 old_log_blocksize, fsw_u32 new_phys_blocksize, fsw_u32 new_log_blocksize) { @@ -517,12 +518,12 @@ void fsw_efi_change_blocksize(struct fsw_volume *vol, * disk. */ -fsw_status_t fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void *buffer) { +fsw_status_t EFIAPI fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void *buffer) { int i, ReadCache = -1; FSW_VOLUME_DATA *Volume = (FSW_VOLUME_DATA *)vol->host_data; EFI_STATUS Status = EFI_SUCCESS; BOOLEAN ReadOneBlock = FALSE; - fsw_u64 StartRead = phys_bno * vol->phys_blocksize; + UINT64 StartRead = (UINT64) phys_bno * (UINT64) vol->phys_blocksize; if (buffer == NULL) return (fsw_status_t) EFI_BAD_BUFFER_SIZE; @@ -536,7 +537,7 @@ fsw_status_t fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void * i = 0; do { if ((Caches[i].Volume == Volume) && - (Caches[i].CacheValid == TRUE) && + (Caches[i].CacheValid == TRUE) && (StartRead >= Caches[i].CacheStart) && ((StartRead + vol->phys_blocksize) <= (Caches[i].CacheStart + CACHE_SIZE))) { ReadCache = i; @@ -553,8 +554,18 @@ fsw_status_t fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void * if (Caches[ReadCache].Cache == NULL) Caches[ReadCache].Cache = AllocatePool(CACHE_SIZE); if (Caches[ReadCache].Cache != NULL) { + // TODO: Below call hangs on my 32-bit Mac Mini when compiled with GNU-EFI. + // The same binary is fine under VirtualBox, and the same call is fine when + // compiled with Tianocore. Further clue: Omitting "Status =" avoids the + // hang but produces a failure to mount the filesystem, even when the same + // change is made to later similar call. Calling Volume->DiskIo->ReadDisk() + // directly (without refit_call5_wrapper()) changes nothing. Placing Print() + // statements at the start and end of the function, and before and after the + // ReadDisk() call, suggests that when it fails, the program is executing + // code starting mid-function, so there seems to be something messed up in + // the way the function is being called. FIGURE THIS OUT! Status = refit_call5_wrapper(Volume->DiskIo->ReadDisk, Volume->DiskIo, Volume->MediaId, - StartRead, CACHE_SIZE, Caches[ReadCache].Cache); + StartRead, (UINTN) CACHE_SIZE, (VOID*) Caches[ReadCache].Cache); if (!EFI_ERROR(Status)) { Caches[ReadCache].CacheStart = StartRead; Caches[ReadCache].CacheValid = TRUE; @@ -568,7 +579,7 @@ fsw_status_t fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void * } // if cache memory allocated } // if (ReadCache < 0) - if (Caches[ReadCache].Cache != NULL && Caches[ReadCache].CacheValid == TRUE) { + if (Caches[ReadCache].Cache != NULL && Caches[ReadCache].CacheValid == TRUE && vol->phys_blocksize > 0) { CopyMem(buffer, &Caches[ReadCache].Cache[StartRead - Caches[ReadCache].CacheStart], vol->phys_blocksize); } else { ReadOneBlock = TRUE; @@ -577,8 +588,8 @@ fsw_status_t fsw_efi_read_block(struct fsw_volume *vol, fsw_u64 phys_bno, void * if (ReadOneBlock) { // Something's failed, so try a simple disk read of one block.... Status = refit_call5_wrapper(Volume->DiskIo->ReadDisk, Volume->DiskIo, Volume->MediaId, phys_bno * vol->phys_blocksize, - vol->phys_blocksize, - buffer); + (UINTN) vol->phys_blocksize, + (VOID*) buffer); } Volume->LastIOStatus = Status; @@ -1087,7 +1098,7 @@ EFI_STATUS fsw_efi_dnode_getinfo(IN FSW_FILE_DATA *File, * appropriate member of the EFI_FILE_INFO structure that we're filling. */ -static void fsw_efi_store_time_posix(struct fsw_dnode_stat *sb, int which, fsw_u32 posix_time) +void fsw_store_time_posix(struct fsw_dnode_stat *sb, int which, fsw_u32 posix_time) { EFI_FILE_INFO *FileInfo = (EFI_FILE_INFO *)sb->host_data; @@ -1105,7 +1116,7 @@ static void fsw_efi_store_time_posix(struct fsw_dnode_stat *sb, int which, fsw_u * adjustments to the EFI_FILE_INFO structure that we're filling. */ -static void fsw_efi_store_attr_posix(struct fsw_dnode_stat *sb, fsw_u16 posix_mode) +void fsw_store_attr_posix(struct fsw_dnode_stat *sb, fsw_u16 posix_mode) { EFI_FILE_INFO *FileInfo = (EFI_FILE_INFO *)sb->host_data; @@ -1113,6 +1124,13 @@ static void fsw_efi_store_attr_posix(struct fsw_dnode_stat *sb, fsw_u16 posix_mo FileInfo->Attribute |= EFI_FILE_READ_ONLY; } +void fsw_store_attr_efi(struct fsw_dnode_stat *sb, fsw_u16 attr) +{ + EFI_FILE_INFO *FileInfo = (EFI_FILE_INFO *)sb->host_data; + + FileInfo->Attribute |= attr; +} + /** * Common function to fill an EFI_FILE_INFO with information about a dnode. */ @@ -1158,8 +1176,6 @@ EFI_STATUS fsw_efi_dnode_fill_FileInfo(IN FSW_VOLUME_DATA *Volume, // get the missing info from the fs driver ZeroMem(&sb, sizeof(struct fsw_dnode_stat)); - sb.store_time_posix = fsw_efi_store_time_posix; - sb.store_attr_posix = fsw_efi_store_attr_posix; sb.host_data = FileInfo; Status = fsw_efi_map_status(fsw_dnode_stat(dno, &sb), Volume); if (EFI_ERROR(Status))