Author: ion
Date: Thu Sep 10 05:19:50 2015
New Revision: 69166
URL:
http://svn.reactos.org/svn/reactos?rev=69166&view=rev
Log:
[BOOTMGFW]:
- Implement read/offset-read frontend interface.
Modified:
trunk/reactos/boot/environ/include/bl.h
trunk/reactos/boot/environ/lib/io/device.c
trunk/reactos/boot/environ/lib/io/fat.c
Modified: trunk/reactos/boot/environ/include/bl.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/include/bl.h?…
==============================================================================
--- trunk/reactos/boot/environ/include/bl.h [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/include/bl.h [iso-8859-1] Thu Sep 10 05:19:50 2015
@@ -472,7 +472,10 @@
typedef
NTSTATUS
(*PBL_DEVICE_READ) (
- VOID
+ _In_ struct _BL_DEVICE_ENTRY* DeviceEntry,
+ _In_ PVOID Buffer,
+ _In_ ULONG Size,
+ _Out_ PULONG BytesRead
);
typedef
@@ -491,7 +494,8 @@
typedef
NTSTATUS
(*PBL_DEVICE_SET_INFORMATION) (
- VOID
+ _In_ struct _BL_DEVICE_ENTRY* DeviceEntry,
+ _In_ struct _BL_DEVICE_INFORMATION* DeviceInformation
);
typedef
@@ -894,6 +898,9 @@
BL_PARTITION_TYPE PartitionType;
ULONG BlockSize;
ULONG Alignment;
+ ULONGLONG MaxBlock;
+ ULONGLONG Offset;
+ ULONG Block;
struct
{
union
@@ -1481,6 +1488,21 @@
BlDeviceGetInformation (
_In_ ULONG DeviceId,
_Out_ PBL_DEVICE_INFORMATION DeviceInformation
+ );
+
+NTSTATUS
+BlDeviceSetInformation (
+ _In_ ULONG DeviceId,
+ _In_ PBL_DEVICE_INFORMATION DeviceInformation
+ );
+
+NTSTATUS
+BlDeviceReadAtOffset (
+ _In_ ULONG DeviceId,
+ _In_ ULONG Size,
+ _In_ ULONGLONG Offset,
+ _In_ PVOID Buffer,
+ _Out_ PULONG BytesRead
);
/* FILE I/O ROUTINES *********************************************************/
Modified: trunk/reactos/boot/environ/lib/io/device.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device…
==============================================================================
--- trunk/reactos/boot/environ/lib/io/device.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c [iso-8859-1] Thu Sep 10 05:19:50 2015
@@ -14,10 +14,8 @@
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;
@@ -69,6 +67,12 @@
_Out_ PBL_DEVICE_INFORMATION DeviceInformation
);
+NTSTATUS
+BlockIoSetInformation (
+ _In_ PBL_DEVICE_ENTRY DeviceEntry,
+ _Out_ PBL_DEVICE_INFORMATION DeviceInformation
+ );
+
BL_DEVICE_CALLBACKS BlockIoDeviceFunctionTable =
{
NULL,
@@ -76,8 +80,32 @@
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 (
@@ -97,6 +125,39 @@
}
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,
_Out_ PBL_DEVICE_INFORMATION DeviceInformation
@@ -128,6 +189,73 @@
DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType;
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 (
@@ -1496,10 +1624,8 @@
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));
Modified: trunk/reactos/boot/environ/lib/io/fat.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/fat.c?…
==============================================================================
--- trunk/reactos/boot/environ/lib/io/fat.c [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/fat.c [iso-8859-1] Thu Sep 10 05:19:50 2015
@@ -9,6 +9,7 @@
/* INCLUDES ******************************************************************/
#include "bl.h"
+#include "..\drivers\filesystems\fs_rec\fs_rec.h"
/* DATA VARIABLES ************************************************************/
@@ -25,7 +26,39 @@
_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;
}