typedef struct _BL_DEVICE_IO_INFORMATION
{
- ULONG Unknown0;
- ULONG Unknown1;
- ULONG Unknown2;
- ULONG Unknown3;
+ ULONGLONG ReadCount;
+ ULONGLONG WriteCount;
} BL_DEVICE_IO_INFORMATION, *PBL_DEVICE_IO_INFORMATION;
LIST_ENTRY DmRegisteredDevices;
_Out_ PBL_DEVICE_INFORMATION DeviceInformation
);
+NTSTATUS
+BlockIoSetInformation (
+ _In_ PBL_DEVICE_ENTRY DeviceEntry,
+ _Out_ PBL_DEVICE_INFORMATION DeviceInformation
+ );
+
BL_DEVICE_CALLBACKS BlockIoDeviceFunctionTable =
{
NULL,
NULL,
NULL,
NULL,
- BlockIoGetInformation
+ BlockIoGetInformation,
+ BlockIoSetInformation
};
+NTSTATUS
+BlockIoSetInformation (
+ _In_ PBL_DEVICE_ENTRY DeviceEntry,
+ _Out_ PBL_DEVICE_INFORMATION DeviceInformation
+ )
+{
+ PBL_BLOCK_DEVICE BlockDevice;
+ ULONGLONG Offset;
+
+ BlockDevice = DeviceEntry->DeviceSpecificData;
+
+ Offset = DeviceInformation->BlockDeviceInfo.Block * BlockDevice->BlockSize + DeviceInformation->BlockDeviceInfo.Offset;
+ if (Offset > ((BlockDevice->MaxBlock + 1) * BlockDevice->BlockSize - 1))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ BlockDevice->Block = Offset / BlockDevice->BlockSize;
+ BlockDevice->Offset = Offset % BlockDevice->BlockSize;
+ BlockDevice->Unknown = DeviceInformation->BlockDeviceInfo.Unknown;
+ return STATUS_SUCCESS;
+}
+
NTSTATUS
BlockIoGetInformation (
_In_ PBL_DEVICE_ENTRY DeviceEntry,
return STATUS_SUCCESS;
}
+NTSTATUS
+BlDeviceSetInformation (
+ _In_ ULONG DeviceId,
+ _Out_ PBL_DEVICE_INFORMATION DeviceInformation
+ )
+{
+ PBL_DEVICE_ENTRY DeviceEntry;
+
+ if (!(DeviceInformation))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ if (DmTableEntries <= DeviceId)
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ DeviceEntry = DmDeviceTable[DeviceId];
+ if (!DeviceEntry)
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ if (!(DeviceEntry->Flags & 1))
+ {
+ return STATUS_INVALID_PARAMETER;
+ }
+
+ DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType;
+ return DeviceEntry->Callbacks.SetInformation(DeviceEntry, DeviceInformation);
+}
+
NTSTATUS
BlDeviceGetInformation (
_In_ ULONG DeviceId,
return DeviceEntry->Callbacks.GetInformation(DeviceEntry, DeviceInformation);
}
+NTSTATUS
+BlDeviceRead (
+ _In_ ULONG DeviceId,
+ _In_ PVOID Buffer,
+ _In_ ULONG Size,
+ _Out_ PULONG BytesRead
+ )
+{
+ PBL_DEVICE_ENTRY DeviceEntry; // ecx@3
+ NTSTATUS Status;
+ ULONG BytesTransferred;
+
+ if (Buffer
+ && DmTableEntries > DeviceId
+ && (DeviceEntry = DmDeviceTable[DeviceId]) != 0
+ && DeviceEntry->Flags & 1
+ && DeviceEntry->Flags & 2)
+ {
+ EfiPrintf(L"Calling read...\r\n");
+ Status = DeviceEntry->Callbacks.Read(DeviceEntry, Buffer, Size, &BytesTransferred);
+
+ if (!DeviceEntry->Unknown)
+ {
+ DmDeviceIoInformation.ReadCount += BytesTransferred;
+ }
+
+ if (BytesRead)
+ {
+ *BytesRead = BytesTransferred;
+ }
+ }
+ else
+ {
+ Status = STATUS_INVALID_PARAMETER;
+ }
+ return Status;
+}
+
+NTSTATUS
+BlDeviceReadAtOffset (
+ _In_ ULONG DeviceId,
+ _In_ ULONG Size,
+ _In_ ULONGLONG Offset,
+ _In_ PVOID Buffer,
+ _Out_ PULONG BytesRead
+ )
+{
+ NTSTATUS Status;
+ BL_DEVICE_INFORMATION DeviceInformation;
+
+ Status = BlDeviceGetInformation(DeviceId, &DeviceInformation);
+ if (Status >= 0)
+ {
+ DeviceInformation.BlockDeviceInfo.Block = Offset / DeviceInformation.BlockDeviceInfo.BlockSize;
+ DeviceInformation.BlockDeviceInfo.Offset = Offset % DeviceInformation.BlockDeviceInfo.BlockSize;
+ Status = BlDeviceSetInformation(DeviceId, &DeviceInformation);
+
+ if (NT_SUCCESS(Status))
+ {
+ EfiPrintf(L"Block: %d Offset: %d\r\n", DeviceInformation.BlockDeviceInfo.Block, DeviceInformation.BlockDeviceInfo.Offset);
+ Status = BlDeviceRead(DeviceId, Buffer, Size, BytesRead);
+ }
+ }
+ return Status;
+}
+
+
BOOLEAN
BlpDeviceCompare (
_In_ PBL_DEVICE_DESCRIPTOR Device1,
InitializeListHead(&DmRegisteredDevices);
/* Initialize device information */
- DmDeviceIoInformation.Unknown0 = 0;
- DmDeviceIoInformation.Unknown1 = 0;
- DmDeviceIoInformation.Unknown2 = 0;
- DmDeviceIoInformation.Unknown3 = 0;
+ DmDeviceIoInformation.ReadCount = 0;
+ DmDeviceIoInformation.WriteCount = 0;
/* Allocate the device table */
DmDeviceTable = BlMmAllocateHeap(DmTableEntries * sizeof(PVOID));
/* INCLUDES ******************************************************************/
#include "bl.h"
+#include "..\drivers\filesystems\fs_rec\fs_rec.h"
/* DATA VARIABLES ************************************************************/
_Out_ PBL_FILE_ENTRY* FileEntry
)
{
- EfiPrintf(L"FAT Mount on Device %d TODO\r\n", DeviceId);
+ BL_DEVICE_INFORMATION DeviceInformation;
+ ULONG UnknownFlag;
+ NTSTATUS Status;
+ PACKED_BOOT_SECTOR FatBootSector;
+
+ EfiPrintf(L"FAT Mount on Device %d\r\n", DeviceId);
+
+ /* Capture thing */
+ BlDeviceGetInformation(DeviceId, &DeviceInformation);
+ UnknownFlag = DeviceInformation.BlockDeviceInfo.Unknown;
+
+ /* Set thing to 1 */
+ DeviceInformation.BlockDeviceInfo.Unknown |= 1;
+ BlDeviceSetInformation(DeviceId, &DeviceInformation);
+
+ /* Read the boot sector */
+ EfiPrintf(L"Reading fat boot sector...\r\n");
+ Status = BlDeviceReadAtOffset(DeviceId,
+ sizeof(FatBootSector),
+ 0,
+ &FatBootSector,
+ NULL);
+
+ /* Restore thing back */
+ DeviceInformation.BlockDeviceInfo.Unknown = UnknownFlag;
+ BlDeviceSetInformation(DeviceId, &DeviceInformation);
+ if (!NT_SUCCESS(Status))
+ {
+ EfiPrintf(L"Failed reading drive: %lx\r\n", Status);
+ return Status;
+ }
+
+ EfiPrintf(L"Drive read\r\n");
EfiStall(3000000);
return STATUS_NOT_IMPLEMENTED;
}