]> mj.ucw.cz Git - pciutils.git/commitdiff
Get rid of workarounds for Linux systems without pread/pwrite
authorMartin Mares <mj@ucw.cz>
Fri, 29 Dec 2023 14:23:00 +0000 (15:23 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 29 Dec 2023 14:27:19 +0000 (15:27 +0100)
Many things have changed since we introduced work-arounds for Linux
systems with missing pread/pwrite in 1999 (if you are curious, it was
in commit bc6346df8d89ece4814be7dff951ec1a7d259938).

I believe that it is supported by all reasonably recent Linux systems
now. After all, pread() was already defined by POSIX.1-2001.

This should also fix problems with musl libc mentioned in GitHub
issue #158.

lib/Makefile
lib/pci.h
lib/pread.h [deleted file]
lib/proc.c
lib/sysfs.c

index 64d742fed3dd1520812512324fe26dcba86c3bc7..a89ac14e42cb9a1354a6d445d7123b7df3e4070c 100644 (file)
@@ -125,8 +125,8 @@ params.o: params.c $(INCL)
 i386-ports.o: i386-ports.c $(INCL) i386-io-hurd.h i386-io-linux.h i386-io-sunos.h i386-io-windows.h i386-io-cygwin.h
 mmio-ports.o: mmio-ports.c $(INCL)
 ecam.o: ecam.c $(INCL)
-proc.o: proc.c $(INCL) pread.h
-sysfs.o: sysfs.c $(INCL) pread.h
+proc.o: proc.c $(INCL)
+sysfs.o: sysfs.c $(INCL)
 generic.o: generic.c $(INCL)
 emulated.o: emulated.c $(INCL)
 syscalls.o: syscalls.c $(INCL)
index 2322bf73be8433875c8f4dde629f21d34aafbd47..0b27dc3ba428c639cfe50a606fb324d304bb10f1 100644 (file)
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -87,7 +87,6 @@ struct pci_access {
   struct udev_hwdb *id_udev_hwdb;
   int fd;                              /* proc/sys: fd for config space */
   int fd_rw;                           /* proc/sys: fd opened read-write */
-  int fd_pos;                          /* proc/sys: current position */
   int fd_vpd;                          /* sys: fd for VPD */
   struct pci_dev *cached_dev;          /* proc/sys: device the fds are for */
   void *aux;                           /* Auxiliary data for use by the back-end */
diff --git a/lib/pread.h b/lib/pread.h
deleted file mode 100644 (file)
index 99a91b2..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- *     The PCI Library -- Portable interface to pread() and pwrite()
- *
- *     Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
- *
- *     Can be freely distributed and used under the terms of the GNU GPL v2+
- *
- *     SPDX-License-Identifier: GPL-2.0-or-later
- */
-
-/*
- *  We'd like to use pread/pwrite for configuration space accesses, but
- *  unfortunately it isn't simple at all since all libc's until glibc 2.1
- *  don't define it.
- */
-
-#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ > 0
-/* glibc 2.1 or newer -> pread/pwrite supported automatically */
-
-#elif defined(i386) && defined(__GLIBC__)
-/* glibc 2.0 on i386 -> call syscalls directly */
-#include <asm/unistd.h>
-#include <syscall-list.h>
-#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
-/* In all other cases we use lseek/read/write instead to be safe */
-#define make_rw_glue(op) \
-       static int do_##op(struct pci_dev *d, int fd, void *buf, size_t size, int where)        \
-       {                                                                                       \
-         struct pci_access *a = d->access;                                                     \
-         int r;                                                                                \
-         if (a->fd_pos != where && lseek(fd, where, SEEK_SET) < 0)                             \
-           return -1;                                                                          \
-         r = op(fd, buf, size);                                                                \
-         if (r < 0)                                                                            \
-           a->fd_pos = -1;                                                                     \
-         else                                                                                  \
-           a->fd_pos = where + r;                                                              \
-         return r;                                                                             \
-       }
-make_rw_glue(read)
-make_rw_glue(write)
-#define PCI_HAVE_DO_READ
-#endif
-
-#ifndef PCI_HAVE_DO_READ
-#define do_read(d,f,b,l,p) pread(f,b,l,p)
-#define do_write(d,f,b,l,p) pwrite(f,b,l,p)
-#endif
index 2eb5dc5b43e3c8612f05660b6924e8e1aac97e83..429cea6904db321b11be6dd5bee15fb4c85f4e66 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     The PCI Library -- Configuration Access via /proc/bus/pci
  *
- *     Copyright (c) 1997--2003 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 1997--2023 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL v2+.
  *
@@ -19,7 +19,6 @@
 #include <sys/types.h>
 
 #include "internal.h"
-#include "pread.h"
 
 static void
 proc_config(struct pci_access *a)
@@ -162,7 +161,6 @@ proc_setup(struct pci_dev *d, int rw)
       if (a->fd < 0)
        a->warning("Cannot open %s", buf);
       a->cached_dev = d;
-      a->fd_pos = 0;
     }
   return a->fd;
 }
@@ -175,7 +173,7 @@ proc_read(struct pci_dev *d, int pos, byte *buf, int len)
 
   if (fd < 0)
     return 0;
-  res = do_read(d, fd, buf, len, pos);
+  res = pread(fd, buf, len, pos);
   if (res < 0)
     {
       d->access->warning("proc_read: read failed: %s", strerror(errno));
@@ -194,7 +192,7 @@ proc_write(struct pci_dev *d, int pos, byte *buf, int len)
 
   if (fd < 0)
     return 0;
-  res = do_write(d, fd, buf, len, pos);
+  res = pwrite(fd, buf, len, pos);
   if (res < 0)
     {
       d->access->warning("proc_write: write failed: %s", strerror(errno));
index 0a4604bd6b35e80e50b2b2cef361f23e383829fd..cd2379ee5dc9723d75f7ceffdd55d783e91431d3 100644 (file)
@@ -2,7 +2,7 @@
  *     The PCI Library -- Configuration Access via /sys/bus/pci
  *
  *     Copyright (c) 2003 Matthew Wilcox <matthew@wil.cx>
- *     Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
+ *     Copyright (c) 1997--2023 Martin Mares <mj@ucw.cz>
  *
  *     Can be freely distributed and used under the terms of the GNU GPL v2+.
  *
@@ -22,7 +22,6 @@
 #include <sys/types.h>
 
 #include "internal.h"
-#include "pread.h"
 
 static void
 sysfs_config(struct pci_access *a)
@@ -524,7 +523,6 @@ sysfs_setup(struct pci_dev *d, int intent)
       a->fd = open(namebuf, a->fd_rw ? O_RDWR : O_RDONLY);
       if (a->fd < 0)
        a->warning("Cannot open %s", namebuf);
-      a->fd_pos = 0;
     }
   return a->fd;
 }
@@ -536,7 +534,7 @@ static int sysfs_read(struct pci_dev *d, int pos, byte *buf, int len)
 
   if (fd < 0)
     return 0;
-  res = do_read(d, fd, buf, len, pos);
+  res = pread(fd, buf, len, pos);
   if (res < 0)
     {
       d->access->warning("sysfs_read: read failed: %s", strerror(errno));
@@ -554,7 +552,7 @@ static int sysfs_write(struct pci_dev *d, int pos, byte *buf, int len)
 
   if (fd < 0)
     return 0;
-  res = do_write(d, fd, buf, len, pos);
+  res = pwrite(fd, buf, len, pos);
   if (res < 0)
     {
       d->access->warning("sysfs_write: write failed: %s", strerror(errno));
@@ -568,17 +566,6 @@ static int sysfs_write(struct pci_dev *d, int pos, byte *buf, int len)
   return 1;
 }
 
-#ifdef PCI_HAVE_DO_READ
-
-/* pread() is not available and do_read() only works for a single fd, so we
- * cannot implement read_vpd properly. */
-static int sysfs_read_vpd(struct pci_dev *d UNUSED, int pos UNUSED, byte *buf UNUSED, int len UNUSED)
-{
-  return 0;
-}
-
-#else /* !PCI_HAVE_DO_READ */
-
 static int sysfs_read_vpd(struct pci_dev *d, int pos, byte *buf, int len)
 {
   int fd = sysfs_setup(d, SETUP_READ_VPD);
@@ -597,8 +584,6 @@ static int sysfs_read_vpd(struct pci_dev *d, int pos, byte *buf, int len)
   return 1;
 }
 
-#endif /* PCI_HAVE_DO_READ */
-
 static void sysfs_cleanup_dev(struct pci_dev *d)
 {
   struct pci_access *a = d->access;