Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP4:GA
dmidecode
util-let-callers-pass-an-offset-to-read_file.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File util-let-callers-pass-an-offset-to-read_file.patch of Package dmidecode
From: Jean Delvare <jdelvare@suse.de> Date: Tue, 11 Apr 2017 11:41:43 +0200 Subject: util: Let callers pass an offset to read_file Git-commit: 6d0486c40d1a68fa5c4c730531cbf32bfd9f76c4 Patch-mainline: 3.1 When reading from a dump file, read_file would be more convenient to use than mem_chunk, but it lacks an offset parameter. Signed-off-by: Jean Delvare <jdelvare@suse.de> --- dmidecode.c | 4 ++-- util.c | 14 +++++++++++--- util.h | 4 ++-- 3 files changed, 15 insertions(+), 7 deletions(-) --- a/dmidecode.c +++ b/dmidecode.c @@ -4644,7 +4644,7 @@ static void dmi_table(off_t base, u32 le * result of the kernel truncating the table on parse error. */ size_t size = len; - buf = read_file(&size, devmem); + buf = read_file(0, &size, devmem); if (!(opt.flags & FLAG_QUIET) && num && size != (size_t)len) { printf("Wrong DMI structures length: %u bytes " @@ -4946,7 +4946,7 @@ int main(int argc, char * const argv[]) */ size = 0x20; if (!(opt.flags & FLAG_NO_SYSFS) - && (buf = read_file(&size, SYS_ENTRY_FILE)) != NULL) + && (buf = read_file(0, &size, SYS_ENTRY_FILE)) != NULL) { if (!(opt.flags & FLAG_QUIET)) printf("Getting SMBIOS data from sysfs.\n"); --- a/util.c +++ b/util.c @@ -2,7 +2,7 @@ * Common "util" functions * This file is part of the dmidecode project. * - * Copyright (C) 2002-2015 Jean Delvare <jdelvare@suse.de> + * Copyright (C) 2002-2017 Jean Delvare <jdelvare@suse.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -89,7 +89,7 @@ int checksum(const u8 *buf, size_t len) } /* - * Reads all of file, up to max_len bytes. + * Reads all of file from given offset, up to max_len bytes. * A buffer of max_len bytes is allocated by this function, and * needs to be freed by the caller. * This provides a similar usage model to mem_chunk() @@ -98,7 +98,7 @@ int checksum(const u8 *buf, size_t len) * sets max_len to the length actually read. * */ -void *read_file(size_t *max_len, const char *filename) +void *read_file(off_t base, size_t *max_len, const char *filename) { int fd; size_t r2 = 0; @@ -116,6 +116,14 @@ void *read_file(size_t *max_len, const c return NULL; } + if (lseek(fd, base, SEEK_SET) == -1) + { + fprintf(stderr, "%s: ", filename); + perror("lseek"); + p = NULL; + goto out; + } + if ((p = malloc(*max_len)) == NULL) { perror("malloc"); --- a/util.h +++ b/util.h @@ -1,7 +1,7 @@ /* * This file is part of the dmidecode project. * - * Copyright (C) 2003-2015 Jean Delvare <jdelvare@suse.de> + * Copyright (C) 2003-2017 Jean Delvare <jdelvare@suse.de> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ #define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0])) int checksum(const u8 *buf, size_t len); -void *read_file(size_t *len, const char *filename); +void *read_file(off_t base, size_t *len, const char *filename); void *mem_chunk(off_t base, size_t len, const char *devmem); int write_dump(size_t base, size_t len, const void *data, const char *dumpfile, int add); u64 u64_range(u64 start, u64 end);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor