[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
This commit is contained in:
Alex Ionescu 2016-01-07 05:14:26 +00:00
parent 69dbd65521
commit 93d3cafa85
5 changed files with 59 additions and 45 deletions

View file

@ -315,7 +315,10 @@ BmFwInitializeBootDirectoryPath (
DeviceHandle = -1; DeviceHandle = -1;
/* Try to open the boot device */ /* 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)) if (!NT_SUCCESS(Status))
{ {
EfiPrintf(L"Device open failed: %lx\r\n", Status); EfiPrintf(L"Device open failed: %lx\r\n", Status);
@ -327,7 +330,6 @@ BmFwInitializeBootDirectoryPath (
BcdDirectory = BcdPath.Buffer; BcdDirectory = BcdPath.Buffer;
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
EfiPrintf(L"path failed: %lx\n", Status);
goto Quickie; goto Quickie;
} }
@ -351,8 +353,10 @@ BmFwInitializeBootDirectoryPath (
wcsncat(FinalPath, L"\\BCD", FinalSize / sizeof(WCHAR)); wcsncat(FinalPath, L"\\BCD", FinalSize / sizeof(WCHAR));
/* Try to open the file */ /* Try to open the file */
EfiPrintf(L"Opening: %s\r\n", FinalPath); Status = BlFileOpen(DeviceHandle,
Status = BlFileOpen(DeviceHandle, FinalPath, 1, &FileHandle); FinalPath,
BL_FILE_READ_ACCESS,
&FileHandle);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
BootDirectory = BcdDirectory; BootDirectory = BcdDirectory;

View file

@ -603,28 +603,32 @@ BlDeviceSetInformation (
{ {
PBL_DEVICE_ENTRY DeviceEntry; PBL_DEVICE_ENTRY DeviceEntry;
if (!(DeviceInformation)) /* This parameter is not optional */
if (!DeviceInformation)
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
/* Make sure the device ID is valid */
if (DmTableEntries <= DeviceId) if (DmTableEntries <= DeviceId)
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
/* Get the device entry */
DeviceEntry = DmDeviceTable[DeviceId]; DeviceEntry = DmDeviceTable[DeviceId];
if (!DeviceEntry) if (!DeviceEntry)
{ {
return STATUS_INVALID_PARAMETER; 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 STATUS_INVALID_PARAMETER;
} }
DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType; /* Set the device information */
return DeviceEntry->Callbacks.SetInformation(DeviceEntry, DeviceInformation); return DeviceEntry->Callbacks.SetInformation(DeviceEntry, DeviceInformation);
} }
@ -636,27 +640,32 @@ BlDeviceGetInformation (
{ {
PBL_DEVICE_ENTRY DeviceEntry; PBL_DEVICE_ENTRY DeviceEntry;
if (!(DeviceInformation)) /* This parameter is not optional */
if (!DeviceInformation)
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
/* Make sure the device ID is valid */
if (DmTableEntries <= DeviceId) if (DmTableEntries <= DeviceId)
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
/* Get the device entry */
DeviceEntry = DmDeviceTable[DeviceId]; DeviceEntry = DmDeviceTable[DeviceId];
if (!DeviceEntry) if (!DeviceEntry)
{ {
return STATUS_INVALID_PARAMETER; 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 STATUS_INVALID_PARAMETER;
} }
/* Return the device information */
DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType; DeviceInformation->DeviceType = DeviceEntry->DeviceDescriptor->DeviceType;
return DeviceEntry->Callbacks.GetInformation(DeviceEntry, DeviceInformation); return DeviceEntry->Callbacks.GetInformation(DeviceEntry, DeviceInformation);
} }
@ -666,40 +675,51 @@ BlDeviceRead (
_In_ ULONG DeviceId, _In_ ULONG DeviceId,
_In_ PVOID Buffer, _In_ PVOID Buffer,
_In_ ULONG Size, _In_ ULONG Size,
_Out_ PULONG BytesRead _Out_opt_ PULONG BytesRead
) )
{ {
PBL_DEVICE_ENTRY DeviceEntry; PBL_DEVICE_ENTRY DeviceEntry;
NTSTATUS Status; NTSTATUS Status;
ULONG BytesTransferred; ULONG BytesTransferred;
/* Make sure we have a buffer, and the device ID is valid */
if (!(Buffer) || (DmTableEntries <= DeviceId)) if (!(Buffer) || (DmTableEntries <= DeviceId))
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
/* Get the device entry for it */
DeviceEntry = DmDeviceTable[DeviceId]; DeviceEntry = DmDeviceTable[DeviceId];
if (!DeviceEntry) if (!DeviceEntry)
{ {
return STATUS_INVALID_PARAMETER; 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; 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) if (!DeviceEntry->Unknown)
{ {
/* Update performance counters */
DmDeviceIoInformation.ReadCount += BytesTransferred; DmDeviceIoInformation.ReadCount += BytesTransferred;
} }
/* Return back how many bytes were read, if caller wants to know */
if (BytesRead) if (BytesRead)
{ {
*BytesRead = BytesTransferred; *BytesRead = BytesTransferred;
} }
/* Return read result */
return Status; return Status;
} }
@ -744,7 +764,7 @@ BlpDeviceCompare (
/* Assume failure */ /* Assume failure */
DeviceMatch = FALSE; 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)) if ((Device1) && (Device2) && (Device1->DeviceType == Device2->DeviceType))
{ {
/* Take the bigger of the two sizes */ /* Take the bigger of the two sizes */
@ -753,8 +773,8 @@ BlpDeviceCompare (
{ {
/* Compare the two devices up to their size */ /* Compare the two devices up to their size */
if (RtlEqualMemory(&Device1->Local, if (RtlEqualMemory(&Device1->Local,
&Device2->Local, &Device2->Local,
DeviceSize - FIELD_OFFSET(BL_DEVICE_DESCRIPTOR, Local))) DeviceSize - FIELD_OFFSET(BL_DEVICE_DESCRIPTOR, Local)))
{ {
/* They match! */ /* They match! */
DeviceMatch = TRUE; DeviceMatch = TRUE;
@ -1173,7 +1193,7 @@ BlockIoEfiCreateDeviceEntry (
Status = BlockIoEfiGetDeviceInformation(IoDeviceEntry); Status = BlockIoEfiGetDeviceInformation(IoDeviceEntry);
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* We have a fully constructed device, reuturn it */ /* We have a fully constructed device, return it */
*DeviceEntry = IoDeviceEntry; *DeviceEntry = IoDeviceEntry;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
@ -1287,7 +1307,6 @@ BlockIoFirmwareOpen (
/* Does this device match what we're looking for? */ /* Does this device match what we're looking for? */
DeviceMatch = BlpDeviceCompare(DeviceEntry->DeviceDescriptor, Device); DeviceMatch = BlpDeviceCompare(DeviceEntry->DeviceDescriptor, Device);
EfiPrintf(L"Device match: %d\r\n", DeviceMatch);
if (DeviceMatch) if (DeviceMatch)
{ {
/* Yep, return the data back */ /* Yep, return the data back */
@ -1477,8 +1496,8 @@ DeviceTableCompare (
) )
{ {
BOOLEAN Found; BOOLEAN Found;
PBL_DEVICE_DESCRIPTOR Device = (PBL_DEVICE_DESCRIPTOR)Entry; PBL_DEVICE_DESCRIPTOR Device = (PBL_DEVICE_DESCRIPTOR)Argument1;
PBL_DEVICE_ENTRY DeviceEntry = (PBL_DEVICE_ENTRY)Argument1; PBL_DEVICE_ENTRY DeviceEntry = (PBL_DEVICE_ENTRY)Entry;
ULONG Flags = *(PULONG)Argument2; ULONG Flags = *(PULONG)Argument2;
ULONG Unknown = *(PULONG)Argument3; ULONG Unknown = *(PULONG)Argument3;
@ -1492,8 +1511,8 @@ DeviceTableCompare (
if (DeviceEntry->Unknown == Unknown) if (DeviceEntry->Unknown == Unknown)
{ {
/* Compare flags */ /* Compare flags */
if ((!(Flags & 1) || (DeviceEntry->Flags & 2)) && if ((!(Flags & BL_DEVICE_READ_ACCESS) || (DeviceEntry->Flags & BL_DEVICE_ENTRY_READ_ACCESS)) &&
(!(Flags & 2) || (DeviceEntry->Flags & 4))) (!(Flags & BL_DEVICE_WRITE_ACCESS) || (DeviceEntry->Flags & BL_DEVICE_ENTRY_WRITE_ACCESS)))
{ {
/* And more flags */ /* And more flags */
if (((Flags & 8) || !(DeviceEntry->Flags & 8)) && if (((Flags & 8) || !(DeviceEntry->Flags & 8)) &&
@ -1540,7 +1559,7 @@ DeviceTablePurge (
NTSTATUS Status; NTSTATUS Status;
/* Check if the device is opened */ /* Check if the device is opened */
if (DeviceEntry->Flags & 1) if (DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED)
{ {
/* It is, so can't purge it */ /* It is, so can't purge it */
Status = STATUS_UNSUCCESSFUL; Status = STATUS_UNSUCCESSFUL;
@ -1700,7 +1719,6 @@ BlockIopInitialize (
return Status; return Status;
} }
BOOLEAN BOOLEAN
BlockIoDeviceTableCompare ( BlockIoDeviceTableCompare (
_In_ PVOID Entry, _In_ PVOID Entry,
@ -1736,7 +1754,6 @@ BlockIoOpen (
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
/* Failed to initialize block I/O */ /* Failed to initialize block I/O */
EfiPrintf(L"Block I/O Init failed\r\n");
return Status; return Status;
} }
} }
@ -1769,7 +1786,7 @@ BlockIoOpen (
if (FoundDeviceEntry) if (FoundDeviceEntry)
{ {
/* We already found a device, so copy its device data and callbacks */ /* 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(BlockDevice, FoundDeviceEntry->DeviceSpecificData, sizeof(*BlockDevice));
RtlCopyMemory(&DeviceEntry->Callbacks, RtlCopyMemory(&DeviceEntry->Callbacks,
&FoundDeviceEntry->Callbacks, &FoundDeviceEntry->Callbacks,
@ -1873,7 +1890,7 @@ BlDeviceClose (
} }
/* Make sure the device is active */ /* Make sure the device is active */
if (!(DeviceEntry->Flags & 1)) if (!(DeviceEntry->Flags & BL_DEVICE_ENTRY_OPENED))
{ {
return STATUS_INVALID_PARAMETER; return STATUS_INVALID_PARAMETER;
} }
@ -1883,7 +1900,7 @@ BlDeviceClose (
if (!DeviceEntry->ReferenceCount) if (!DeviceEntry->ReferenceCount)
{ {
/* Mark the device as inactive */ /* Mark the device as inactive */
DeviceEntry->Flags = ~1; DeviceEntry->Flags = ~BL_DEVICE_ENTRY_OPENED;
} }
/* We're good */ /* We're good */
@ -1964,10 +1981,9 @@ BlpDeviceOpen (
if (DeviceEntry) if (DeviceEntry)
{ {
/* Return it, taking a reference on it */ /* Return it, taking a reference on it */
EfiPrintf(L"Device found: %p\r\n", DeviceEntry);
*DeviceId = DeviceEntry->DeviceId; *DeviceId = DeviceEntry->DeviceId;
++DeviceEntry->ReferenceCount; ++DeviceEntry->ReferenceCount;
DeviceEntry->Flags |= 1; DeviceEntry->Flags |= BL_DEVICE_ENTRY_OPENED;
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }

View file

@ -565,7 +565,6 @@ EtfsOpen (
FALSE); FALSE);
if (!NT_SUCCESS(Status)) if (!NT_SUCCESS(Status))
{ {
EfiPrintf(L"no dirent found: %lx\r\n", Status);
return Status; return Status;
} }
@ -761,7 +760,6 @@ EtfspCheckEtfs (
/* Return back to the caller */ /* Return back to the caller */
*VolumeDescriptor = IsoVd; *VolumeDescriptor = IsoVd;
*VolumeIsIso = IsIso; *VolumeIsIso = IsIso;
EfiPrintf(L"Recognized!!!\r\n");
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }

View file

@ -32,8 +32,6 @@ FatMount (
PACKED_BOOT_SECTOR FatBootSector; PACKED_BOOT_SECTOR FatBootSector;
BIOS_PARAMETER_BLOCK BiosBlock; BIOS_PARAMETER_BLOCK BiosBlock;
EfiPrintf(L"FAT Mount on Device %d\r\n", DeviceId);
/* Capture thing */ /* Capture thing */
BlDeviceGetInformation(DeviceId, &DeviceInformation); BlDeviceGetInformation(DeviceId, &DeviceInformation);
UnknownFlag = DeviceInformation.BlockDeviceInfo.Unknown; 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", 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], FatBootSector.Jump[0],
BiosBlock.BytesPerSector, BiosBlock.BytesPerSector,
BiosBlock.SectorsPerCluster, BiosBlock.SectorsPerCluster,
BiosBlock.ReservedSectors, BiosBlock.ReservedSectors,
BiosBlock.Fats, BiosBlock.Fats,
BiosBlock.Sectors, BiosBlock.Sectors,
BiosBlock.LargeSectors, BiosBlock.LargeSectors,
BiosBlock.Media, BiosBlock.Media,
BiosBlock.RootEntries); BiosBlock.RootEntries);
return STATUS_NOT_IMPLEMENTED; return STATUS_NOT_IMPLEMENTED;
} }

View file

@ -323,7 +323,6 @@ FileIoOpen (
&Unknown); &Unknown);
if (FileEntry) if (FileEntry)
{ {
EfiPrintf(L"Entry exists: %p\n", FileEntry);
goto FileOpened; goto FileOpened;
} }
@ -525,7 +524,7 @@ BlFileOpen (
if (NT_SUCCESS(Status)) if (NT_SUCCESS(Status))
{ {
/* Return the file ID back to the caller */ /* 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; *FileId = FileEntry->FileId;
} }