Skip to content

Commit

Permalink
[FREELDR] Load Hardware IDs from txtsetup.sif ([HardwareIdsDatabase] …
Browse files Browse the repository at this point in the history
…section) to allocated in memory Database. SetupBlock->HardwareIdDatabase point on Head it.
  • Loading branch information
vgalnt authored and AmineKhaldi committed Feb 3, 2017
1 parent b1be7a0 commit 2a1811e
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions reactos/boot/freeldr/freeldr/ntldr/setupldr.c
Expand Up @@ -27,6 +27,7 @@

DBG_DEFAULT_CHANNEL(WINDOWS);
#define TAG_BOOT_OPTIONS 'pOtB'
#define TAG_HARDWARE_ID 'dIwH'

void
WinLdrSetupMachineDependent(PLOADER_PARAMETER_BLOCK LoaderBlock);
Expand Down Expand Up @@ -133,6 +134,82 @@ SetupLdrScanBootDrivers(PLIST_ENTRY BootDriverListHead, HINF InfHandle, LPCSTR S
} while (InfFindNextLine(&InfContext, &InfContext));
}

static VOID
SetupLdrLoadHardwareIdsDatabase(PSETUP_LOADER_BLOCK SetupBlock, HINF InfHandle, LPCSTR SearchPath)
{
INFCONTEXT InfContext;
LPCSTR Id;
LPCSTR DriverName;
SIZE_T Size;
PVOID Temp;
PPNP_HARDWARE_ID HardwareId;
PPNP_HARDWARE_ID HeadHardwareId;
PPNP_HARDWARE_ID LastHardwareId = 0;

/*
typedef struct _PNP_HARDWARE_ID
{
struct _PNP_HARDWARE_ID *Next;
PCHAR Id;
PCHAR DriverName;
PCHAR ClassGuid;

This comment has been minimized.

Copy link
@learn-more

learn-more Feb 18, 2017

Should we also initialize ClassGuid?
(Atleast set it to NULL!)

} PNP_HARDWARE_ID, *PPNP_HARDWARE_ID;
*/

/* Open inf section */
if (!InfFindFirstLine(InfHandle, "HardwareIdsDatabase", NULL, &InfContext))
return;

This comment has been minimized.

Copy link
@learn-more

learn-more Feb 18, 2017

Is this ever supposed to fail?
If not, might be nice printing a message.


/* Load all HardwareIds */
do
{
if (InfGetDataField(&InfContext, 0, &Id) &&
InfGetDataField(&InfContext, 1, &DriverName))
{
/* Allocate and initialize the new struct _PNP_HARDWARE_ID */
Size = sizeof(PNP_HARDWARE_ID);
HardwareId = FrLdrHeapAlloc(Size, TAG_HARDWARE_ID);
if (HardwareId == NULL)
return;

memset(HardwareId, 0, Size);

/* For link field */
if(LastHardwareId)
LastHardwareId->Next = (PPNP_HARDWARE_ID)((ULONG)HardwareId | 0x80000000);
else
HeadHardwareId = (PPNP_HARDWARE_ID)((ULONG)HardwareId | 0x80000000); //first record

This comment has been minimized.

Copy link
@learn-more

learn-more Feb 18, 2017

Why the | 0x80000000 ?

Asides from that, if the order does not matter, a single linked list can be constructed easier like this:

head = NULL, node;
do {
    node = alloc();
    node->next = head;
    head = node;
} while (whatever);

/* DPRINT */
//ERR("SetupLdrLoadHardwareIdsDatabase: HardwareId - %p\n", HardwareId);

LastHardwareId = HardwareId;

/* Allocate and copy name Id */
Size = strlen(Id) + 1;
Temp = FrLdrHeapAlloc(Size, TAG_HARDWARE_ID);
if (Temp == NULL)
return;

memmove(Temp, Id, Size);

HardwareId->Id = (PCHAR)((ULONG)Temp | 0x80000000);

/* Allocate and copy driver name */
Size = strlen(DriverName) + 1;
Temp = FrLdrHeapAlloc(Size, TAG_HARDWARE_ID);
if (Temp == NULL)
return;

memmove(Temp, DriverName, Size);

HardwareId->DriverName = (PCHAR)((ULONG)Temp | 0x80000000);
}
} while (InfFindNextLine(&InfContext, &InfContext));

SetupBlock->HardwareIdDatabase = (PPNP_HARDWARE_ID)((ULONG)HeadHardwareId | 0x80000000);
}

VOID
LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem,
IN USHORT OperatingSystemVersion)
Expand Down Expand Up @@ -328,6 +405,9 @@ LoadReactOSSetup(IN OperatingSystemItem* OperatingSystem,
/* Get a list of boot drivers */
SetupLdrScanBootDrivers(&LoaderBlock->BootDriverListHead, InfHandle, BootPath);

/* Load HardwareIds Database */
SetupLdrLoadHardwareIdsDatabase(SetupBlock, InfHandle, BootPath);

/* Close the inf file */
InfCloseFile(InfHandle);

Expand Down

0 comments on commit 2a1811e

Please sign in to comment.