X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fproc.c;h=f493e491e771684c0ebd0e87843d3319bf89f7cb;hb=dc01dd60affb4688453f8b7204af66246f0850db;hp=5edc7b0be7992658f52777ada06080fe6da838a4;hpb=e95c8373b24e4069cbcc387a4246616f7f92bb1b;p=pciutils.git diff --git a/lib/proc.c b/lib/proc.c index 5edc7b0..f493e49 100644 --- a/lib/proc.c +++ b/lib/proc.c @@ -1,9 +1,7 @@ /* - * $Id: proc.c,v 1.4 1999/07/07 11:23:12 mj Exp $ - * * The PCI Library -- Configuration Access via /proc/bus/pci * - * Copyright (c) 1997--1999 Martin Mares + * Copyright (c) 1997--2003 Martin Mares * * Can be freely distributed and used under the terms of the GNU GPL. */ @@ -18,47 +16,12 @@ #include #include "internal.h" - -#include -#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 1 -#include -#endif - -/* - * As libc doesn't support pread/pwrite yet, we have to call them directly - * or use lseek/read/write instead. - */ -#if !(defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0) - -#if defined(__GLIBC__) && !(defined(__powerpc__) && __GLIBC__ == 2 && __GLIBC_MINOR__ == 0) -#ifndef SYS_pread -#define SYS_pread 180 -#endif -static int -pread(unsigned int fd, void *buf, size_t size, loff_t where) -{ - return syscall(SYS_pread, fd, buf, size, where); -} - -#ifndef SYS_pwrite -#define SYS_pwrite 181 -#endif -static int -pwrite(unsigned int fd, void *buf, size_t size, loff_t where) -{ - return syscall(SYS_pwrite, fd, buf, size, where); -} -#else -static _syscall4(int, pread, unsigned int, fd, void *, buf, size_t, size, loff_t, where); -static _syscall4(int, pwrite, unsigned int, fd, void *, buf, size_t, size, loff_t, where); -#endif - -#endif +#include "pread.h" static void proc_config(struct pci_access *a) { - a->method_params[PCI_ACCESS_PROC_BUS_PCI] = PATH_PROC_BUS_PCI; + a->method_params[PCI_ACCESS_PROC_BUS_PCI] = PCI_PATH_PROC_BUS_PCI; } static int @@ -95,7 +58,7 @@ static void proc_scan(struct pci_access *a) { FILE *f; - char buf[256]; + char buf[512]; if (snprintf(buf, sizeof(buf), "%s/devices", a->method_params[PCI_ACCESS_PROC_BUS_PCI]) == sizeof(buf)) a->error("File name too long"); @@ -107,12 +70,8 @@ proc_scan(struct pci_access *a) struct pci_dev *d = pci_alloc_dev(a); unsigned int dfn, vend, cnt, known; - cnt = sscanf(buf, -#ifdef HAVE_LONG_ADDRESS - "%x %x %x %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx %llx", -#else - "%x %x %x %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx %lx", -#endif +#define F " " PCIADDR_T_FMT + cnt = sscanf(buf, "%x %x %x" F F F F F F F F F F F F F F, &dfn, &vend, &d->irq, @@ -130,6 +89,7 @@ proc_scan(struct pci_access *a) &d->size[4], &d->size[5], &d->rom_size); +#undef F if (cnt != 9 && cnt != 10 && cnt != 17) a->error("proc: parse error (read only %d items)", cnt); d->bus = dfn >> 8U; @@ -159,17 +119,21 @@ proc_setup(struct pci_dev *d, int rw) if (a->cached_dev != d || a->fd_rw < rw) { - char buf[256]; + char buf[1024]; + int e; if (a->fd >= 0) close(a->fd); - if (snprintf(buf, sizeof(buf), "%s/%02x/%02x.%d", a->method_params[PCI_ACCESS_PROC_BUS_PCI], - d->bus, d->dev, d->func) == sizeof(buf)) + e = snprintf(buf, sizeof(buf), "%s/%02x/%02x.%d", + a->method_params[PCI_ACCESS_PROC_BUS_PCI], + d->bus, d->dev, d->func); + if (e < 0 || e >= (int) sizeof(buf)) a->error("File name too long"); a->fd_rw = a->writeable || rw; a->fd = open(buf, a->fd_rw ? O_RDWR : O_RDONLY); if (a->fd < 0) a->warning("Cannot open %s", buf); a->cached_dev = d; + a->fd_pos = 0; } return a->fd; } @@ -182,17 +146,14 @@ proc_read(struct pci_dev *d, int pos, byte *buf, int len) if (fd < 0) return 0; - res = pread(fd, buf, len, pos); + res = do_read(d, fd, buf, len, pos); if (res < 0) { d->access->warning("proc_read: read failed: %s", strerror(errno)); return 0; } else if (res != len) - { - d->access->warning("proc_read: tried to read %d bytes at %d, but got only %d", len, pos, res); - return 0; - } + return 0; return 1; } @@ -204,7 +165,7 @@ proc_write(struct pci_dev *d, int pos, byte *buf, int len) if (fd < 0) return 0; - res = pwrite(fd, buf, len, pos); + res = do_write(d, fd, buf, len, pos); if (res < 0) { d->access->warning("proc_write: write failed: %s", strerror(errno)); @@ -212,7 +173,7 @@ proc_write(struct pci_dev *d, int pos, byte *buf, int len) } else if (res != len) { - d->access->warning("proc_write: tried to write %d bytes at %d, but got only %d", len, pos, res); + d->access->warning("proc_write: tried to write %d bytes at %d, but only %d succeeded", len, pos, res); return 0; } return 1; @@ -226,7 +187,7 @@ proc_cleanup_dev(struct pci_dev *d) } struct pci_methods pm_linux_proc = { - "/proc/bus/pci", + "Linux-proc", proc_config, proc_detect, proc_init,