Skip to content

Commit 3a7de6a

Browse files
committed
dmidecode: Add passing of flags parameter to dmi_table()
This allows dmi_table() to print the address that the table was read from, even when reading from a sysfs file. Previous to sysfs support, the address of the table was always the same as the offset within the file it was read from (usually /dev/mem.) For sysfs files that contain just the table at offset 0, we still want to pass the address and display that as normal, but read from offset 0 in the file. If the flag FLAG_NO_FILE_OFFSET is passed, dmi_table() uses 'base' as the DMI table address for display, but uses 0 as the file offset. Contributed by Roy Franz.
1 parent 2339e72 commit 3a7de6a

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
* util.c, util.h: Add utility function read_file, which reads an
44
entire binary file into a buffer.
5+
* dmidecode.c: Add passing of flags parameter to dmi_table.
56

67
2015-04-20 Jean Delvare <[email protected]>
78

dmidecode.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ static const char *bad_index = "<BAD INDEX>";
7171

7272
#define SUPPORTED_SMBIOS_VER 0x0208
7373

74+
#define FLAG_NO_FILE_OFFSET (1 << 0)
75+
7476
/*
7577
* Type-independant Stuff
7678
*/
@@ -4331,7 +4333,8 @@ static void dmi_table_dump(u32 base, u16 len, const char *devmem)
43314333
free(buf);
43324334
}
43334335

4334-
static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
4336+
static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem,
4337+
u32 flags)
43354338
{
43364339
u8 *buf;
43374340
u8 *data;
@@ -4362,6 +4365,15 @@ static void dmi_table(u32 base, u16 len, u16 num, u16 ver, const char *devmem)
43624365
printf("\n");
43634366
}
43644367

4368+
/*
4369+
* When we are reading the DMI table from sysfs, we want to print
4370+
* the address of the table (done above), but the offset of the
4371+
* data in the file is 0. When reading from /dev/mem, the offset
4372+
* in the file is the address.
4373+
*/
4374+
if (flags & FLAG_NO_FILE_OFFSET)
4375+
base = 0;
4376+
43654377
if ((buf = mem_chunk(base, len, devmem)) == NULL)
43664378
{
43674379
fprintf(stderr, "Table is unreachable, sorry."
@@ -4468,7 +4480,7 @@ static void overwrite_dmi_address(u8 *buf)
44684480
buf[0x0B] = 0;
44694481
}
44704482

4471-
static int smbios_decode(u8 *buf, const char *devmem)
4483+
static int smbios_decode(u8 *buf, const char *devmem, u32 flags)
44724484
{
44734485
u16 ver;
44744486

@@ -4500,7 +4512,7 @@ static int smbios_decode(u8 *buf, const char *devmem)
45004512
ver >> 8, ver & 0xFF);
45014513

45024514
dmi_table(DWORD(buf + 0x18), WORD(buf + 0x16), WORD(buf + 0x1C),
4503-
ver, devmem);
4515+
ver, devmem, flags);
45044516

45054517
if (opt.flags & FLAG_DUMP_BIN)
45064518
{
@@ -4518,7 +4530,7 @@ static int smbios_decode(u8 *buf, const char *devmem)
45184530
return 1;
45194531
}
45204532

4521-
static int legacy_decode(u8 *buf, const char *devmem)
4533+
static int legacy_decode(u8 *buf, const char *devmem, u32 flags)
45224534
{
45234535
if (!checksum(buf, 0x0F))
45244536
return 0;
@@ -4528,7 +4540,7 @@ static int legacy_decode(u8 *buf, const char *devmem)
45284540
buf[0x0E] >> 4, buf[0x0E] & 0x0F);
45294541

45304542
dmi_table(DWORD(buf + 0x08), WORD(buf + 0x06), WORD(buf + 0x0C),
4531-
((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem);
4543+
((buf[0x0E] & 0xF0) << 4) + (buf[0x0E] & 0x0F), devmem, flags);
45324544

45334545
if (opt.flags & FLAG_DUMP_BIN)
45344546
{
@@ -4646,12 +4658,12 @@ int main(int argc, char * const argv[])
46464658

46474659
if (memcmp(buf, "_SM_", 4) == 0)
46484660
{
4649-
if (smbios_decode(buf, opt.dumpfile))
4661+
if (smbios_decode(buf, opt.dumpfile, 0))
46504662
found++;
46514663
}
46524664
else if (memcmp(buf, "_DMI_", 5) == 0)
46534665
{
4654-
if (legacy_decode(buf, opt.dumpfile))
4666+
if (legacy_decode(buf, opt.dumpfile, 0))
46554667
found++;
46564668
}
46574669
goto done;
@@ -4674,7 +4686,7 @@ int main(int argc, char * const argv[])
46744686
goto exit_free;
46754687
}
46764688

4677-
if (smbios_decode(buf, opt.devmem))
4689+
if (smbios_decode(buf, opt.devmem, 0))
46784690
found++;
46794691
goto done;
46804692

@@ -4690,15 +4702,15 @@ int main(int argc, char * const argv[])
46904702
{
46914703
if (memcmp(buf + fp, "_SM_", 4) == 0 && fp <= 0xFFE0)
46924704
{
4693-
if (smbios_decode(buf+fp, opt.devmem))
4705+
if (smbios_decode(buf+fp, opt.devmem, 0))
46944706
{
46954707
found++;
46964708
fp += 16;
46974709
}
46984710
}
46994711
else if (memcmp(buf + fp, "_DMI_", 5) == 0)
47004712
{
4701-
if (legacy_decode(buf + fp, opt.devmem))
4713+
if (legacy_decode(buf + fp, opt.devmem, 0))
47024714
found++;
47034715
}
47044716
}

0 commit comments

Comments
 (0)