diff options
author | khali <khali> | 2004-11-20 20:43:07 +0000 |
---|---|---|
committer | khali <khali> | 2004-11-20 20:43:07 +0000 |
commit | 765126efeedf3c1eae0ef1425e5b1505c4009604 (patch) | |
tree | 679ca94923b125dc45d5e7a6deb30432298d4f97 /ownership.c | |
parent | 4106698be99fdbed4d0a6bfd77f874e35b1e21b7 (diff) | |
download | dmidecode-765126efeedf3c1eae0ef1425e5b1505c4009604.tar.gz |
Make use of mem_chunk().
Diffstat (limited to 'ownership.c')
-rw-r--r-- | ownership.c | 78 |
1 files changed, 17 insertions, 61 deletions
diff --git a/ownership.c b/ownership.c index 2d41a23..d667b55 100644 --- a/ownership.c +++ b/ownership.c @@ -1,7 +1,7 @@ /* * Compaq Ownership Tag * - * (C) 2003 Jean Delvare <khali@linux-fr.org> + * (C) 2003-2004 Jean Delvare <khali@linux-fr.org> * * 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 @@ -29,39 +29,24 @@ * http://h18000.www1.hp.com/support/techpubs/technical_reference_guides/113a1097.html */ -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> #include "types.h" #include "util.h" -static void ownership(int fd, u32 base, const char *pname, const char *devmem) +static void ownership(u32 base, const char *pname, const char *devmem) { u8 *buf; int i; - - if((buf=malloc(0x51))==NULL) - { - perror(pname); - return; - } - + /* read the ownership tag */ - if(lseek(fd, (off_t)base, SEEK_SET)==-1) + if((buf=mem_chunk(base, 0x51, devmem))==NULL) { - perror(devmem); + perror(pname); return; } - if(myread(fd, buf, 0x50, devmem)==-1) - { - free(buf); - exit(1); - } /* chop the trailing garbage */ i=0x4f; @@ -110,9 +95,8 @@ static u32 decode(const u8 *p) int main(int argc, const char *argv[]) { - u8 buf[16]; - int fd; - off_t fp=0xE0000; + u8 *buf; + off_t fp; const char *devmem="/dev/mem"; int ok=0; @@ -124,60 +108,32 @@ int main(int argc, const char *argv[]) if(argc>=2) devmem=argv[1]; - if((fd=open(devmem, O_RDONLY))==-1 || lseek(fd, fp, SEEK_SET)==-1) - { - perror(devmem); + + if((buf=mem_chunk(0xE0000, 0x20000, devmem))==NULL) exit(1); - } - while(!ok && fp<0xFFFFF) + for(fp=0; !ok && fp<=0x1FFF0; fp+=16) { - if(myread(fd, buf, 16, devmem)==-1) - exit(1); - - if(memcmp((char *)buf, "32OS", 4)==0) + u8 *p=buf+fp; + + if(memcmp((char *)p, "32OS", 4)==0) { - off_t len=buf[4]*10+5; - u8 *p; + off_t len=p[4]*10+5; - if(fp+len-1<=0xFFFFF) + if(fp+len-1<=0x1FFFF) { u32 base; - if((p=malloc(len))==NULL) - { - perror("malloc"); - exit(1); - } - - memcpy(p, buf, 16); - if(len>16) - { - /* buffer completion */ - if(myread(fd, p+16, len-16, devmem)==-1) - { - free(p); - exit(1); - } - } if((base=decode(p))) { ok=1; - ownership(fd, base, argv[0], devmem); + ownership(base, argv[0], devmem); } - else - lseek(fd, fp+16, SEEK_SET); - free(p); } } - fp+=16; } - if(close(fd)==-1) - { - perror(devmem); - exit(1); - } + free(buf); return 0; } |