Author: ion
Date: Thu Jan  7 05:14:26 2016
New Revision: 70515

URL: http://svn.reactos.org/svn/reactos?rev=70515&view=rev
Log:
[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.

Modified:
    trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
    trunk/reactos/boot/environ/lib/io/device.c
    trunk/reactos/boot/environ/lib/io/etfs.c
    trunk/reactos/boot/environ/lib/io/fat.c
    trunk/reactos/boot/environ/lib/io/file.c

Modified: trunk/reactos/boot/environ/app/bootmgr/bootmgr.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/app/bootmgr/bootmgr.c?rev=70515&r1=70514&r2=70515&view=diff
==============================================================================
--- trunk/reactos/boot/environ/app/bootmgr/bootmgr.c    [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/app/bootmgr/bootmgr.c    [iso-8859-1] Thu Jan  7 
05:14:26 2016
@@ -315,7 +315,10 @@
     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 @@
     BcdDirectory = BcdPath.Buffer;
     if (!NT_SUCCESS(Status))
     {
-        EfiPrintf(L"path failed: %lx\n", Status);
         goto Quickie;
     }
 
@@ -351,8 +353,10 @@
     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;

Modified: trunk/reactos/boot/environ/lib/io/device.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/device.c?rev=70515&r1=70514&r2=70515&view=diff
==============================================================================
--- trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/device.c  [iso-8859-1] Thu Jan  7 
05:14:26 2016
@@ -603,28 +603,32 @@
 {
     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 @@
 {
     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 @@
     _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 @@
     /* 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 @@
         {
             /* 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 @@
         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 @@
 
         /* 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 @@
     )
 {
     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 @@
         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 @@
     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 @@
     return Status;
 }
 
-
 BOOLEAN
 BlockIoDeviceTableCompare (
     _In_ PVOID Entry,
@@ -1736,7 +1754,6 @@
         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 @@
     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 @@
     }
 
     /* 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 @@
     if (!DeviceEntry->ReferenceCount)
     {
         /* Mark the device as inactive */
-        DeviceEntry->Flags = ~1;
+        DeviceEntry->Flags = ~BL_DEVICE_ENTRY_OPENED;
     }
 
     /* We're good */
@@ -1964,10 +1981,9 @@
     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;
     }
 

Modified: trunk/reactos/boot/environ/lib/io/etfs.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/etfs.c?rev=70515&r1=70514&r2=70515&view=diff
==============================================================================
--- trunk/reactos/boot/environ/lib/io/etfs.c    [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/etfs.c    [iso-8859-1] Thu Jan  7 
05:14:26 2016
@@ -565,7 +565,6 @@
                                         FALSE);
     if (!NT_SUCCESS(Status))
     {
-        EfiPrintf(L"no dirent found: %lx\r\n", Status);
         return Status;
     }
 
@@ -761,7 +760,6 @@
     /* Return back to the caller */
     *VolumeDescriptor = IsoVd;
     *VolumeIsIso = IsIso;
-    EfiPrintf(L"Recognized!!!\r\n");
     return STATUS_SUCCESS;
 }
 

Modified: trunk/reactos/boot/environ/lib/io/fat.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/fat.c?rev=70515&r1=70514&r2=70515&view=diff
==============================================================================
--- trunk/reactos/boot/environ/lib/io/fat.c     [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/fat.c     [iso-8859-1] Thu Jan  7 
05:14:26 2016
@@ -32,8 +32,6 @@
     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 @@
     }
 
     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;
 }
 

Modified: trunk/reactos/boot/environ/lib/io/file.c
URL: 
http://svn.reactos.org/svn/reactos/trunk/reactos/boot/environ/lib/io/file.c?rev=70515&r1=70514&r2=70515&view=diff
==============================================================================
--- trunk/reactos/boot/environ/lib/io/file.c    [iso-8859-1] (original)
+++ trunk/reactos/boot/environ/lib/io/file.c    [iso-8859-1] Thu Jan  7 
05:14:26 2016
@@ -323,7 +323,6 @@
                                                 &Unknown);
     if (FileEntry)
     {
-        EfiPrintf(L"Entry exists: %p\n", FileEntry);
         goto FileOpened;
     }
 
@@ -525,7 +524,7 @@
     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;
     }
 


Reply via email to