summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkhali <khali>2015-05-04 11:19:36 +0000
committerkhali <khali>2015-05-04 11:19:36 +0000
commiteb6ee0135eb393ef6d33a9956bd25be327af1b6d (patch)
tree711befb415118c5da77ac263b2913da9e1cf8d0c
parent0ac608d225950a2ad7ec1e88a6eef88ac0ab5215 (diff)
downloaddmidecode-eb6ee0135eb393ef6d33a9956bd25be327af1b6d.tar.gz
dmidecode: Move table decoding to a separate function
This will let us share more code between the decode and dump options.
-rw-r--r--CHANGELOG4
-rw-r--r--dmidecode.c104
2 files changed, 59 insertions, 49 deletions
diff --git a/CHANGELOG b/CHANGELOG
index fcb0ba4..343f695 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+2015-05-04 Jean Delvare <jdelvare@suse.de>
+
+ * dmidecode.c: Move table decoding to a separate function.
+
2015-04-28 Jean Delvare <jdelvare@suse.de>
* dmidecode.h, dmiopt.h: Fix sparse errors.
diff --git a/dmidecode.c b/dmidecode.c
index 5e34354..1c277e5 100644
--- a/dmidecode.c
+++ b/dmidecode.c
@@ -4373,59 +4373,11 @@ static void dmi_table_dump(off_t base, u32 len, const char *devmem)
free(buf);
}
-static void dmi_table(off_t base, u32 len, u16 num, u16 ver, const char *devmem,
- u32 flags)
+static void dmi_table_decode(u8 *buf, u32 len, u16 num, u16 ver, u32 flags)
{
- u8 *buf;
u8 *data;
int i = 0;
- if (ver > SUPPORTED_SMBIOS_VER && !(opt.flags & FLAG_QUIET))
- {
- printf("# SMBIOS implementations newer than version %u.%u are not\n"
- "# fully supported by this version of dmidecode.\n",
- SUPPORTED_SMBIOS_VER >> 8, SUPPORTED_SMBIOS_VER & 0xFF);
- }
-
- if (!(opt.flags & FLAG_QUIET))
- {
- if (opt.type == NULL)
- {
- if (num)
- printf("%u structures occupying %u bytes.\n",
- num, len);
- if (!(opt.flags & FLAG_FROM_DUMP))
- printf("Table at 0x%08llX.\n",
- (unsigned long long)base);
- }
- printf("\n");
- }
-
- /*
- * When we are reading the DMI table from sysfs, we want to print
- * the address of the table (done above), but the offset of the
- * data in the file is 0. When reading from /dev/mem, the offset
- * in the file is the address.
- */
- if (flags & FLAG_NO_FILE_OFFSET)
- base = 0;
-
- if (opt.flags & FLAG_DUMP_BIN)
- {
- dmi_table_dump(base, len, devmem);
- return;
- }
-
- if ((buf = mem_chunk(base, len, devmem)) == NULL)
- {
- fprintf(stderr, "Table is unreachable, sorry."
-#ifndef USE_MMAP
- " Try compiling dmidecode with -DUSE_MMAP."
-#endif
- "\n");
- return;
- }
-
data = buf;
while ((i < num || !num)
&& data + 4 <= buf + len) /* 4 is the length of an SMBIOS structure header */
@@ -4513,6 +4465,60 @@ static void dmi_table(off_t base, u32 len, u16 num, u16 ver, const char *devmem,
"announced, structures occupy %d bytes.\n",
len, (unsigned int)(data - buf));
}
+}
+
+static void dmi_table(off_t base, u32 len, u16 num, u16 ver, const char *devmem,
+ u32 flags)
+{
+ u8 *buf;
+
+ if (ver > SUPPORTED_SMBIOS_VER && !(opt.flags & FLAG_QUIET))
+ {
+ printf("# SMBIOS implementations newer than version %u.%u are not\n"
+ "# fully supported by this version of dmidecode.\n",
+ SUPPORTED_SMBIOS_VER >> 8, SUPPORTED_SMBIOS_VER & 0xFF);
+ }
+
+ if (!(opt.flags & FLAG_QUIET))
+ {
+ if (opt.type == NULL)
+ {
+ if (num)
+ printf("%u structures occupying %u bytes.\n",
+ num, len);
+ if (!(opt.flags & FLAG_FROM_DUMP))
+ printf("Table at 0x%08llX.\n",
+ (unsigned long long)base);
+ }
+ printf("\n");
+ }
+
+ /*
+ * When we are reading the DMI table from sysfs, we want to print
+ * the address of the table (done above), but the offset of the
+ * data in the file is 0. When reading from /dev/mem, the offset
+ * in the file is the address.
+ */
+ if (flags & FLAG_NO_FILE_OFFSET)
+ base = 0;
+
+ if (opt.flags & FLAG_DUMP_BIN)
+ {
+ dmi_table_dump(base, len, devmem);
+ return;
+ }
+
+ if ((buf = mem_chunk(base, len, devmem)) == NULL)
+ {
+ fprintf(stderr, "Table is unreachable, sorry."
+#ifndef USE_MMAP
+ " Try compiling dmidecode with -DUSE_MMAP."
+#endif
+ "\n");
+ return;
+ }
+
+ dmi_table_decode(buf, len, num, ver, flags);
free(buf);
}