From 93d3cafa85b8334235267d46a650e60acd9bf4ba Mon Sep 17 00:00:00 2001 From: Alex Ionescu Date: Thu, 7 Jan 2016 05:14:26 +0000 Subject: [PATCH] [BOOTLIB]: Cleanup some debug prints. [BOOTLIB]: Fix two big device I/O bugs (it's a miracle it worked) [BOOTLIB]: Use defined constants and comment some more device I/O code. svn path=/trunk/; revision=70515 --- reactos/boot/environ/app/bootmgr/bootmgr.c | 12 ++-- reactos/boot/environ/lib/io/device.c | 66 ++++++++++++++-------- reactos/boot/environ/lib/io/etfs.c | 2 - reactos/boot/environ/lib/io/fat.c | 21 +++---- reactos/boot/environ/lib/io/file.c | 3 +- 5 files changed, 59 insertions(+), 45 deletions(-) diff --git a/reactos/boot/environ/app/bootmgr/bootmgr.c b/reactos/boot/environ/app/bootmgr/bootmgr.c index f439449874a..3a6cb39963f 100644 --- a/reactos/boot/environ/app/bootmgr/bootmgr.c +++ b/reactos/boot/environ/app/bootmgr/bootmgr.c @@ -315,7 +315,10 @@ BmFwInitializeBootDirectoryPath ( DeviceHandle = -1; /* Try to open the boot device */ - Status = BlpDeviceOpen(BlpBootDevice, 1u, 0, &DeviceHandle); + Status = BlpDeviceOpen(BlpBootDevice, + BL_DEVICE_READ_ACCESS, + 0, + &DeviceHandle); if (!NT_SUCCESS(Status)) { EfiPrintf(L"Device open failed: %lx\r\n", Status); @@ -327,7 +330,6 @@ BmFwInitializeBootDirectoryPath ( BcdDirectory = BcdPath.Buffer; if (!NT_SUCCESS(Status)) { - EfiPrintf(L"path failed: %lx\n", Status); goto Quickie; } @@ -351,8 +353,10 @@ BmFwInitializeBootDirectoryPath ( wcsncat(FinalPath, L"\\BCD", FinalSize / sizeof(WCHAR)); /* Try to open the file */ - EfiPrintf(L"Opening: %s\r\n", FinalPath); - Status = BlFileOpen(DeviceHandle, FinalPath, 1, &FileHandle); + Status = BlFileOpen(DeviceHandle, + FinalPath, + BL_FILE_READ_ACCESS, + &FileHandle); if (!NT_SUCCESS(Status)) { BootDirectory = BcdDirectory; diff --git a/reactos/boot/environ/lib/io/device.c b/reactos/boot/environ/lib/io/device.c index 38e59a53d3b..4dff2b55377 100644 --- a/reactos/boot/environ/lib/io/device.c +++ b/reactos/boot/environ/lib/io/device.c @@ -603,28 +603,32 @@ BlDeviceSetInformation ( { PBL_DEVICE_ENTRY DeviceEntry; - if (!(DeviceInformation)) + /* This parameter is not optional */ + if (!DeviceInformation) { return STATUS_INVALID_PARAMETER; } + /* Make sure the device ID is valid */ if (DmTableEntries <= DeviceId) { return STATUS_INVALID_PARAMETER; } + /* Get the device entry */ DeviceEntry = DmDeviceTable[DeviceId]; if (!DeviceEntry) { return STATUS_INVALID_PARAMETER; } - if (!(DeviceEntry->Flags & 1)) + /* Make sure the device is open */ + if (!(DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED)) { return STATUS_INVALID_PARAMETER; } - DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType; + /* Set the device information */ return DeviceEntry->Callbacks.SetInformation(DeviceEntry, DeviceInformation); } @@ -636,27 +640,32 @@ BlDeviceGetInformation ( { PBL_DEVICE_ENTRY DeviceEntry; - if (!(DeviceInformation)) + /* This parameter is not optional */ + if (!DeviceInformation) { return STATUS_INVALID_PARAMETER; } + /* Make sure the device ID is valid */ if (DmTableEntries <= DeviceId) { return STATUS_INVALID_PARAMETER; } + /* Get the device entry */ DeviceEntry = DmDeviceTable[DeviceId]; if (!DeviceEntry) { return STATUS_INVALID_PARAMETER; } - if (!(DeviceEntry->Flags & 1)) + /* Make sure the device is open */ + if (!(DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED)) { return STATUS_INVALID_PARAMETER; } + /* Return the device information */ DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType; return DeviceEntry->Callbacks.GetInformation(DeviceEntry, DeviceInformation); } @@ -666,40 +675,51 @@ BlDeviceRead ( _In_ ULONG DeviceId, _In_ PVOID Buffer, _In_ ULONG Size, - _Out_ PULONG BytesRead + _Out_opt_ PULONG BytesRead ) { PBL_DEVICE_ENTRY DeviceEntry; NTSTATUS Status; ULONG BytesTransferred; + /* Make sure we have a buffer, and the device ID is valid */ if (!(Buffer) || (DmTableEntries <= DeviceId)) { return STATUS_INVALID_PARAMETER; } + /* Get the device entry for it */ DeviceEntry = DmDeviceTable[DeviceId]; if (!DeviceEntry) { return STATUS_INVALID_PARAMETER; } - if (!(DeviceEntry->Flags & 1) || !(DeviceEntry->Flags & 2)) + /* Make sure this is a device opened for read access */ + if (!(DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED) || + !(DeviceEntry->Flags & BL_DEVICE_ENTRY_READ_ACCESS)) { return STATUS_INVALID_PARAMETER; } - Status = DeviceEntry->Callbacks.Read(DeviceEntry, Buffer, Size, &BytesTransferred); + /* Issue the read */ + Status = DeviceEntry->Callbacks.Read(DeviceEntry, + Buffer, + Size, + &BytesTransferred); if (!DeviceEntry->Unknown) { + /* Update performance counters */ DmDeviceIoInformation.ReadCount += BytesTransferred; } + /* Return back how many bytes were read, if caller wants to know */ if (BytesRead) { *BytesRead = BytesTransferred; } + /* Return read result */ return Status; } @@ -744,7 +764,7 @@ BlpDeviceCompare ( /* Assume failure */ DeviceMatch = FALSE; - /* Check if the two devices exist and are identical in typ */ + /* Check if the two devices exist and are identical in type */ if ((Device1) && (Device2) && (Device1->DeviceType == Device2->DeviceType)) { /* Take the bigger of the two sizes */ @@ -753,8 +773,8 @@ BlpDeviceCompare ( { /* Compare the two devices up to their size */ if (RtlEqualMemory(&Device1->Local, - &Device2->Local, - DeviceSize - FIELD_OFFSET(BL_DEVICE_DESCRIPTOR, Local))) + &Device2->Local, + DeviceSize - FIELD_OFFSET(BL_DEVICE_DESCRIPTOR, Local))) { /* They match! */ DeviceMatch = TRUE; @@ -1173,7 +1193,7 @@ BlockIoEfiCreateDeviceEntry ( Status = BlockIoEfiGetDeviceInformation(IoDeviceEntry); if (NT_SUCCESS(Status)) { - /* We have a fully constructed device, reuturn it */ + /* We have a fully constructed device, return it */ *DeviceEntry = IoDeviceEntry; return STATUS_SUCCESS; } @@ -1287,7 +1307,6 @@ BlockIoFirmwareOpen ( /* Does this device match what we're looking for? */ DeviceMatch = BlpDeviceCompare(DeviceEntry->DeviceDescriptor, Device); - EfiPrintf(L"Device match: %d\r\n", DeviceMatch); if (DeviceMatch) { /* Yep, return the data back */ @@ -1477,8 +1496,8 @@ DeviceTableCompare ( ) { BOOLEAN Found; - PBL_DEVICE_DESCRIPTOR Device = (PBL_DEVICE_DESCRIPTOR)Entry; - PBL_DEVICE_ENTRY DeviceEntry = (PBL_DEVICE_ENTRY)Argument1; + PBL_DEVICE_DESCRIPTOR Device = (PBL_DEVICE_DESCRIPTOR)Argument1; + PBL_DEVICE_ENTRY DeviceEntry = (PBL_DEVICE_ENTRY)Entry; ULONG Flags = *(PULONG)Argument2; ULONG Unknown = *(PULONG)Argument3; @@ -1492,8 +1511,8 @@ DeviceTableCompare ( if (DeviceEntry->Unknown == Unknown) { /* Compare flags */ - if ((!(Flags & 1) || (DeviceEntry->Flags & 2)) && - (!(Flags & 2) || (DeviceEntry->Flags & 4))) + if ((!(Flags & BL_DEVICE_READ_ACCESS) || (DeviceEntry->Flags & BL_DEVICE_ENTRY_READ_ACCESS)) && + (!(Flags & BL_DEVICE_WRITE_ACCESS) || (DeviceEntry->Flags & BL_DEVICE_ENTRY_WRITE_ACCESS))) { /* And more flags */ if (((Flags & 8) || !(DeviceEntry->Flags & 8)) && @@ -1540,7 +1559,7 @@ DeviceTablePurge ( NTSTATUS Status; /* Check if the device is opened */ - if (DeviceEntry->Flags & 1) + if (DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED) { /* It is, so can't purge it */ Status = STATUS_UNSUCCESSFUL; @@ -1700,7 +1719,6 @@ BlockIopInitialize ( return Status; } - BOOLEAN BlockIoDeviceTableCompare ( _In_ PVOID Entry, @@ -1736,7 +1754,6 @@ BlockIoOpen ( if (!NT_SUCCESS(Status)) { /* Failed to initialize block I/O */ - EfiPrintf(L"Block I/O Init failed\r\n"); return Status; } } @@ -1769,7 +1786,7 @@ BlockIoOpen ( if (FoundDeviceEntry) { /* We already found a device, so copy its device data and callbacks */ - EfiPrintf(L"Device entry found: %p\r\n", FoundDeviceEntry); + //EfiPrintf(L"Block I/O Device entry found: %p\r\n", FoundDeviceEntry); RtlCopyMemory(BlockDevice, FoundDeviceEntry->DeviceSpecificData, sizeof(*BlockDevice)); RtlCopyMemory(&DeviceEntry->Callbacks, &FoundDeviceEntry->Callbacks, @@ -1873,7 +1890,7 @@ BlDeviceClose ( } /* Make sure the device is active */ - if (!(DeviceEntry->Flags & 1)) + if (!(DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED)) { return STATUS_INVALID_PARAMETER; } @@ -1883,7 +1900,7 @@ BlDeviceClose ( if (!DeviceEntry->ReferenceCount) { /* Mark the device as inactive */ - DeviceEntry->Flags = ~1; + DeviceEntry->Flags = ~BL_DEVICE_ENTRY_OPENED; } /* We're good */ @@ -1964,10 +1981,9 @@ BlpDeviceOpen ( if (DeviceEntry) { /* Return it, taking a reference on it */ - EfiPrintf(L"Device found: %p\r\n", DeviceEntry); *DeviceId = DeviceEntry->DeviceId; ++DeviceEntry->ReferenceCount; - DeviceEntry->Flags |= 1; + DeviceEntry->Flags |= BL_DEVICE_ENTRY_OPENED; return STATUS_SUCCESS; } diff --git a/reactos/boot/environ/lib/io/etfs.c b/reactos/boot/environ/lib/io/etfs.c index eddf2bb9c04..a41a27f96bc 100644 --- a/reactos/boot/environ/lib/io/etfs.c +++ b/reactos/boot/environ/lib/io/etfs.c @@ -565,7 +565,6 @@ EtfsOpen ( FALSE); if (!NT_SUCCESS(Status)) { - EfiPrintf(L"no dirent found: %lx\r\n", Status); return Status; } @@ -761,7 +760,6 @@ EtfspCheckEtfs ( /* Return back to the caller */ *VolumeDescriptor = IsoVd; *VolumeIsIso = IsIso; - EfiPrintf(L"Recognized!!!\r\n"); return STATUS_SUCCESS; } diff --git a/reactos/boot/environ/lib/io/fat.c b/reactos/boot/environ/lib/io/fat.c index 28ed72925d4..14e9ecebca8 100644 --- a/reactos/boot/environ/lib/io/fat.c +++ b/reactos/boot/environ/lib/io/fat.c @@ -32,8 +32,6 @@ FatMount ( PACKED_BOOT_SECTOR FatBootSector; BIOS_PARAMETER_BLOCK BiosBlock; - EfiPrintf(L"FAT Mount on Device %d\r\n", DeviceId); - /* Capture thing */ BlDeviceGetInformation(DeviceId, &DeviceInformation); UnknownFlag = DeviceInformation.BlockDeviceInfo.Unknown; @@ -67,16 +65,15 @@ FatMount ( } EfiPrintf(L"Jump: %lx Bytes Per Sector: %d Sectors Per Cluster: %d Reserved: %d Fats: %d Sectors: %d Large Sectors: %d Media: %lx RootEntries: %d\r\n", - FatBootSector.Jump[0], - BiosBlock.BytesPerSector, - BiosBlock.SectorsPerCluster, - BiosBlock.ReservedSectors, - BiosBlock.Fats, - BiosBlock.Sectors, - BiosBlock.LargeSectors, - BiosBlock.Media, - BiosBlock.RootEntries); - + FatBootSector.Jump[0], + BiosBlock.BytesPerSector, + BiosBlock.SectorsPerCluster, + BiosBlock.ReservedSectors, + BiosBlock.Fats, + BiosBlock.Sectors, + BiosBlock.LargeSectors, + BiosBlock.Media, + BiosBlock.RootEntries); return STATUS_NOT_IMPLEMENTED; } diff --git a/reactos/boot/environ/lib/io/file.c b/reactos/boot/environ/lib/io/file.c index 0984354e985..ffa1ba1ae44 100644 --- a/reactos/boot/environ/lib/io/file.c +++ b/reactos/boot/environ/lib/io/file.c @@ -323,7 +323,6 @@ FileIoOpen ( &Unknown); if (FileEntry) { - EfiPrintf(L"Entry exists: %p\n", FileEntry); goto FileOpened; } @@ -525,7 +524,7 @@ BlFileOpen ( if (NT_SUCCESS(Status)) { /* Return the file ID back to the caller */ - EfiPrintf(L"File opened: %lx\r\n", FileEntry->FileId); + EfiPrintf(L"File %s opened: %lx\r\n", FileName, FileEntry->FileId); *FileId = FileEntry->FileId; }