mirror of
https://github.com/systemd/systemd.git
synced 2025-01-11 09:18:07 +03:00
builtin: move usb-db, pci-db to builtins
This commit is contained in:
parent
86a0d004c3
commit
3cf5266b02
26
Makefile.am
26
Makefile.am
@ -151,6 +151,9 @@ dist_udevrules_DATA = \
|
|||||||
rules/rules.d/60-persistent-input.rules \
|
rules/rules.d/60-persistent-input.rules \
|
||||||
rules/rules.d/60-persistent-alsa.rules \
|
rules/rules.d/60-persistent-alsa.rules \
|
||||||
rules/rules.d/60-persistent-storage.rules \
|
rules/rules.d/60-persistent-storage.rules \
|
||||||
|
rules/rules.d/75-net-description.rules \
|
||||||
|
rules/rules.d/75-tty-description.rules \
|
||||||
|
rules/rules.d/78-sound-card.rules \
|
||||||
rules/rules.d/80-drivers.rules \
|
rules/rules.d/80-drivers.rules \
|
||||||
rules/rules.d/95-udev-late.rules
|
rules/rules.d/95-udev-late.rules
|
||||||
|
|
||||||
@ -209,6 +212,7 @@ udev_common_sources = \
|
|||||||
udev/udev-builtin.c \
|
udev/udev-builtin.c \
|
||||||
udev/udev-builtin-blkid.c \
|
udev/udev-builtin-blkid.c \
|
||||||
udev/udev-builtin-firmware.c \
|
udev/udev-builtin-firmware.c \
|
||||||
|
udev/udev-builtin-hwdb.c \
|
||||||
udev/udev-builtin-input_id.c \
|
udev/udev-builtin-input_id.c \
|
||||||
udev/udev-builtin-kmod.c \
|
udev/udev-builtin-kmod.c \
|
||||||
udev/udev-builtin-path_id.c \
|
udev/udev-builtin-path_id.c \
|
||||||
@ -225,7 +229,8 @@ udev_common_LDADD = \
|
|||||||
|
|
||||||
udev_common_CPPFLAGS = \
|
udev_common_CPPFLAGS = \
|
||||||
$(AM_CPPFLAGS) \
|
$(AM_CPPFLAGS) \
|
||||||
-DFIRMWARE_PATH="$(FIRMWARE_PATH)"
|
-DFIRMWARE_PATH="$(FIRMWARE_PATH)" \
|
||||||
|
-DUSB_DATABASE=\"$(USB_DATABASE)\" -DPCI_DATABASE=\"$(PCI_DATABASE)\"
|
||||||
|
|
||||||
udev_udevd_SOURCES = \
|
udev_udevd_SOURCES = \
|
||||||
$(udev_common_sources) \
|
$(udev_common_sources) \
|
||||||
@ -505,25 +510,6 @@ INSTALL_EXEC_HOOKS += libgudev-install-move-hook
|
|||||||
UNINSTALL_EXEC_HOOKS += libgudev-uninstall-move-hook
|
UNINSTALL_EXEC_HOOKS += libgudev-uninstall-move-hook
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if ENABLE_HWDB
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# usb/pci-db - read vendor/device string database
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
extras_usb_db_usb_db_SOURCES = extras/usb-db/usb-db.c
|
|
||||||
extras_usb_db_usb_db_CPPFLAGS = $(AM_CPPFLAGS) -DUSB_DATABASE=\"$(USB_DATABASE)\" -DBUILD_FOR_USB
|
|
||||||
extras_usb_db_usb_db_LDADD = libudev/libudev-private.la
|
|
||||||
libexec_PROGRAMS += extras/usb-db/usb-db
|
|
||||||
dist_udevrules_DATA += \
|
|
||||||
rules/rules.d/75-net-description.rules \
|
|
||||||
rules/rules.d/75-tty-description.rules \
|
|
||||||
rules/rules.d/78-sound-card.rules
|
|
||||||
|
|
||||||
extras_usb_db_pci_db_SOURCES = extras/usb-db/usb-db.c
|
|
||||||
extras_usb_db_pci_db_CPPFLAGS = $(AM_CPPFLAGS) -DPCI_DATABASE=\"$(PCI_DATABASE)\" -DBUILD_FOR_PCI
|
|
||||||
extras_usb_db_pci_db_LDADD = libudev/libudev-private.la
|
|
||||||
libexec_PROGRAMS += extras/usb-db/pci-db
|
|
||||||
endif
|
|
||||||
|
|
||||||
if ENABLE_KEYMAP
|
if ENABLE_KEYMAP
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# keymap - map custom hardware's multimedia keys
|
# keymap - map custom hardware's multimedia keys
|
||||||
|
78
configure.ac
78
configure.ac
@ -20,9 +20,42 @@ AC_PREFIX_DEFAULT([/usr])
|
|||||||
AC_PATH_PROG([XSLTPROC], [xsltproc])
|
AC_PATH_PROG([XSLTPROC], [xsltproc])
|
||||||
|
|
||||||
AC_SEARCH_LIBS([clock_gettime], [rt], [], [AC_MSG_ERROR([POSIX RT library not found])])
|
AC_SEARCH_LIBS([clock_gettime], [rt], [], [AC_MSG_ERROR([POSIX RT library not found])])
|
||||||
|
|
||||||
PKG_CHECK_MODULES(BLKID, blkid >= 2.20)
|
PKG_CHECK_MODULES(BLKID, blkid >= 2.20)
|
||||||
|
|
||||||
PKG_CHECK_MODULES(KMOD, libkmod >= 2)
|
PKG_CHECK_MODULES(KMOD, libkmod >= 2)
|
||||||
|
|
||||||
|
if test "x$cross_compiling" = "xno" ; then
|
||||||
|
AC_CHECK_FILES([/usr/share/pci.ids], [pciids=/usr/share/pci.ids])
|
||||||
|
AC_CHECK_FILES([/usr/share/hwdata/pci.ids], [pciids=/usr/share/hwdata/pci.ids])
|
||||||
|
AC_CHECK_FILES([/usr/share/misc/pci.ids], [pciids=/usr/share/misc/pci.ids])
|
||||||
|
fi
|
||||||
|
|
||||||
|
AC_ARG_WITH(usb-ids-path,
|
||||||
|
[AS_HELP_STRING([--with-usb-ids-path=DIR], [Path to usb.ids file])],
|
||||||
|
[USB_DATABASE=${withval}],
|
||||||
|
[if test -n "$usbids" ; then
|
||||||
|
USB_DATABASE="$usbids"
|
||||||
|
else
|
||||||
|
PKG_CHECK_MODULES(USBUTILS, usbutils >= 0.82)
|
||||||
|
AC_SUBST([USB_DATABASE], [$($PKG_CONFIG --variable=usbids usbutils)])
|
||||||
|
fi])
|
||||||
|
AC_MSG_CHECKING([for USB database location])
|
||||||
|
AC_MSG_RESULT([$USB_DATABASE])
|
||||||
|
AC_SUBST(USB_DATABASE)
|
||||||
|
|
||||||
|
AC_ARG_WITH(pci-ids-path,
|
||||||
|
[AS_HELP_STRING([--with-pci-ids-path=DIR], [Path to pci.ids file])],
|
||||||
|
[PCI_DATABASE=${withval}],
|
||||||
|
[if test -n "$pciids" ; then
|
||||||
|
PCI_DATABASE="$pciids"
|
||||||
|
else
|
||||||
|
AC_MSG_ERROR([pci.ids not found, try --with-pci-ids-path=])
|
||||||
|
fi])
|
||||||
|
AC_MSG_CHECKING([for PCI database location])
|
||||||
|
AC_MSG_RESULT([$PCI_DATABASE])
|
||||||
|
AC_SUBST(PCI_DATABASE)
|
||||||
|
|
||||||
AC_ARG_WITH([rootprefix],
|
AC_ARG_WITH([rootprefix],
|
||||||
AS_HELP_STRING([--with-rootprefix=DIR], [rootfs directory prefix for config files and kernel modules]),
|
AS_HELP_STRING([--with-rootprefix=DIR], [rootfs directory prefix for config files and kernel modules]),
|
||||||
[], [with_rootprefix=$prefix])
|
[], [with_rootprefix=$prefix])
|
||||||
@ -103,46 +136,6 @@ AS_IF([test "x$enable_introspection" = "xyes"], [
|
|||||||
AM_CONDITIONAL([ENABLE_INTROSPECTION], [test "x$enable_introspection" = "xyes"])
|
AM_CONDITIONAL([ENABLE_INTROSPECTION], [test "x$enable_introspection" = "xyes"])
|
||||||
AM_CONDITIONAL([ENABLE_GUDEV], [test "x$enable_gudev" = "xyes"])
|
AM_CONDITIONAL([ENABLE_GUDEV], [test "x$enable_gudev" = "xyes"])
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
# usb/pci-db - read vendor/device string database
|
|
||||||
# ------------------------------------------------------------------------------
|
|
||||||
AC_ARG_ENABLE([hwdb],
|
|
||||||
AS_HELP_STRING([--disable-hwdb], [disable hardware database support @<:@default=enabled@:>@]),
|
|
||||||
[], [enable_hwdb=yes])
|
|
||||||
AS_IF([test "x$enable_hwdb" = "xyes"], [
|
|
||||||
if test "x$cross_compiling" = "xno" ; then
|
|
||||||
AC_CHECK_FILES([/usr/share/pci.ids], [pciids=/usr/share/pci.ids])
|
|
||||||
AC_CHECK_FILES([/usr/share/hwdata/pci.ids], [pciids=/usr/share/hwdata/pci.ids])
|
|
||||||
AC_CHECK_FILES([/usr/share/misc/pci.ids], [pciids=/usr/share/misc/pci.ids])
|
|
||||||
fi
|
|
||||||
|
|
||||||
AC_ARG_WITH(usb-ids-path,
|
|
||||||
[AS_HELP_STRING([--with-usb-ids-path=DIR], [Path to usb.ids file])],
|
|
||||||
[USB_DATABASE=${withval}],
|
|
||||||
[if test -n "$usbids" ; then
|
|
||||||
USB_DATABASE="$usbids"
|
|
||||||
else
|
|
||||||
PKG_CHECK_MODULES(USBUTILS, usbutils >= 0.82)
|
|
||||||
AC_SUBST([USB_DATABASE], [$($PKG_CONFIG --variable=usbids usbutils)])
|
|
||||||
fi])
|
|
||||||
AC_MSG_CHECKING([for USB database location])
|
|
||||||
AC_MSG_RESULT([$USB_DATABASE])
|
|
||||||
AC_SUBST(USB_DATABASE)
|
|
||||||
|
|
||||||
AC_ARG_WITH(pci-ids-path,
|
|
||||||
[AS_HELP_STRING([--with-pci-ids-path=DIR], [Path to pci.ids file])],
|
|
||||||
[PCI_DATABASE=${withval}],
|
|
||||||
[if test -n "$pciids" ; then
|
|
||||||
PCI_DATABASE="$pciids"
|
|
||||||
else
|
|
||||||
AC_MSG_ERROR([pci.ids not found, try --with-pci-ids-path=])
|
|
||||||
fi])
|
|
||||||
AC_MSG_CHECKING([for PCI database location])
|
|
||||||
AC_MSG_RESULT([$PCI_DATABASE])
|
|
||||||
AC_SUBST(PCI_DATABASE)
|
|
||||||
])
|
|
||||||
AM_CONDITIONAL([ENABLE_HWDB], [test "x$enable_hwdb" = "xyes"])
|
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# keymap - map custom hardware's multimedia keys
|
# keymap - map custom hardware's multimedia keys
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
@ -241,6 +234,8 @@ AC_MSG_RESULT([
|
|||||||
include_prefix: ${INCLUDE_PREFIX}
|
include_prefix: ${INCLUDE_PREFIX}
|
||||||
systemdsystemunitdir: ${systemdsystemunitdir}
|
systemdsystemunitdir: ${systemdsystemunitdir}
|
||||||
firmware path: ${FIRMWARE_PATH}
|
firmware path: ${FIRMWARE_PATH}
|
||||||
|
usb.ids: ${USB_DATABASE}
|
||||||
|
pci.ids: ${PCI_DATABASE}
|
||||||
|
|
||||||
compiler: ${CC}
|
compiler: ${CC}
|
||||||
cflags: ${CFLAGS}
|
cflags: ${CFLAGS}
|
||||||
@ -255,9 +250,6 @@ AC_MSG_RESULT([
|
|||||||
gudev: ${enable_gudev}
|
gudev: ${enable_gudev}
|
||||||
gintrospection: ${enable_introspection}
|
gintrospection: ${enable_introspection}
|
||||||
keymap: ${enable_keymap}
|
keymap: ${enable_keymap}
|
||||||
hwdb: ${enable_hwdb}
|
|
||||||
usb.ids: ${USB_DATABASE}
|
|
||||||
pci.ids: ${PCI_DATABASE}
|
|
||||||
mtd_probe: ${enable_mtd_probe}
|
mtd_probe: ${enable_mtd_probe}
|
||||||
rule_generator: ${enable_rule_generator}
|
rule_generator: ${enable_rule_generator}
|
||||||
udev_acl: ${enable_udev_acl}
|
udev_acl: ${enable_udev_acl}
|
||||||
|
2
extras/usb-db/.gitignore
vendored
2
extras/usb-db/.gitignore
vendored
@ -1,2 +0,0 @@
|
|||||||
usb-db
|
|
||||||
pci-db
|
|
@ -4,11 +4,11 @@ ACTION=="remove", GOTO="net_end"
|
|||||||
SUBSYSTEM!="net", GOTO="net_end"
|
SUBSYSTEM!="net", GOTO="net_end"
|
||||||
|
|
||||||
SUBSYSTEMS=="usb", ENV{ID_MODEL}=="", IMPORT{builtin}="usb_id"
|
SUBSYSTEMS=="usb", ENV{ID_MODEL}=="", IMPORT{builtin}="usb_id"
|
||||||
SUBSYSTEMS=="usb", ENV{ID_MODEL_FROM_DATABASE}=="", IMPORT{program}="usb-db %p"
|
SUBSYSTEMS=="usb", IMPORT{builtin}="usb-db"
|
||||||
SUBSYSTEMS=="usb", ATTRS{idVendor}!="", ATTRS{idProduct}!="", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}"
|
SUBSYSTEMS=="usb", ATTRS{idVendor}!="", ATTRS{idProduct}!="", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}"
|
||||||
SUBSYSTEMS=="usb", GOTO="net_end"
|
SUBSYSTEMS=="usb", GOTO="net_end"
|
||||||
|
|
||||||
SUBSYSTEMS=="pci", ENV{ID_MODEL_FROM_DATABASE}=="", IMPORT{program}="pci-db %p"
|
SUBSYSTEMS=="pci", IMPORT{builtin}="pci-db"
|
||||||
SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}"
|
SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}"
|
||||||
|
|
||||||
LABEL="net_end"
|
LABEL="net_end"
|
||||||
|
@ -4,11 +4,11 @@ ACTION=="remove", GOTO="tty_end"
|
|||||||
SUBSYSTEM!="tty", GOTO="tty_end"
|
SUBSYSTEM!="tty", GOTO="tty_end"
|
||||||
|
|
||||||
SUBSYSTEMS=="usb", ENV{ID_MODEL}=="", IMPORT{builtin}="usb_id"
|
SUBSYSTEMS=="usb", ENV{ID_MODEL}=="", IMPORT{builtin}="usb_id"
|
||||||
SUBSYSTEMS=="usb", ENV{ID_MODEL_FROM_DATABASE}=="", IMPORT{program}="usb-db %p"
|
SUBSYSTEMS=="usb", IMPORT{builtin}="usb-db"
|
||||||
SUBSYSTEMS=="usb", ATTRS{idVendor}!="", ATTRS{idProduct}!="", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}"
|
SUBSYSTEMS=="usb", ATTRS{idVendor}!="", ATTRS{idProduct}!="", ENV{ID_VENDOR_ID}="$attr{idVendor}", ENV{ID_MODEL_ID}="$attr{idProduct}"
|
||||||
SUBSYSTEMS=="usb", GOTO="tty_end"
|
SUBSYSTEMS=="usb", GOTO="tty_end"
|
||||||
|
|
||||||
SUBSYSTEMS=="pci", ENV{ID_MODEL_FROM_DATABASE}=="", IMPORT{program}="pci-db %p"
|
SUBSYSTEMS=="pci", IMPORT{builtin}="pci-db"
|
||||||
SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}"
|
SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}"
|
||||||
|
|
||||||
LABEL="tty_end"
|
LABEL="tty_end"
|
||||||
|
@ -38,10 +38,10 @@ KERNEL!="card*", GOTO="sound_end"
|
|||||||
ENV{SOUND_INITIALIZED}="1"
|
ENV{SOUND_INITIALIZED}="1"
|
||||||
|
|
||||||
SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id"
|
SUBSYSTEMS=="usb", IMPORT{builtin}="usb_id"
|
||||||
SUBSYSTEMS=="usb", ENV{ID_VENDOR_FROM_DATABASE}=="", IMPORT{program}="usb-db %p"
|
SUBSYSTEMS=="usb", IMPORT{builtin}="usb-db"
|
||||||
SUBSYSTEMS=="usb", GOTO="skip_pci"
|
SUBSYSTEMS=="usb", GOTO="skip_pci"
|
||||||
|
|
||||||
SUBSYSTEMS=="pci", ENV{ID_VENDOR_FROM_DATABASE}=="", IMPORT{program}="pci-db %p"
|
SUBSYSTEMS=="pci", IMPORT{builtin}="pci-db"
|
||||||
SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}"
|
SUBSYSTEMS=="pci", ENV{ID_BUS}="pci", ENV{ID_VENDOR_ID}="$attr{vendor}", ENV{ID_MODEL_ID}="$attr{device}"
|
||||||
|
|
||||||
LABEL="skip_pci"
|
LABEL="skip_pci"
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
/*
|
/*
|
||||||
|
* usb-db, pci-db - lookup vendor/product database
|
||||||
|
*
|
||||||
* Copyright (C) 2009 Lennart Poettering <lennart@poettering.net>
|
* Copyright (C) 2009 Lennart Poettering <lennart@poettering.net>
|
||||||
|
* Copyright (C) 2011 Kay Sievers <kay.sievers@vrfy.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* modify it under the terms of the GNU General Public License as
|
* it under the terms of the GNU General Public License as published by
|
||||||
* published by the Free Software Foundation; either version 2 of the
|
* the Free Software Foundation, either version 2 of the License, or
|
||||||
* License, or (at your option) any later version.
|
* (at your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful,
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
* General Public License for more details:
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -19,23 +25,7 @@
|
|||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include <libudev.h>
|
#include "udev.h"
|
||||||
|
|
||||||
#if defined(BUILD_FOR_USB)
|
|
||||||
# define DATABASE USB_DATABASE
|
|
||||||
# define SUBSYSTEM "usb"
|
|
||||||
# define DEVTYPE "usb_device"
|
|
||||||
# define VENDOR_ATTR "idVendor"
|
|
||||||
# define PRODUCT_ATTR "idProduct"
|
|
||||||
#elif defined(BUILD_FOR_PCI)
|
|
||||||
# define DATABASE PCI_DATABASE
|
|
||||||
# define SUBSYSTEM "pci"
|
|
||||||
# define DEVTYPE NULL
|
|
||||||
# define VENDOR_ATTR "vendor"
|
|
||||||
# define PRODUCT_ATTR "device"
|
|
||||||
#else
|
|
||||||
# error "Are you havin' a laugh?"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int get_id_attr(
|
static int get_id_attr(
|
||||||
struct udev_device *parent,
|
struct udev_device *parent,
|
||||||
@ -64,17 +54,19 @@ static int get_id_attr(
|
|||||||
|
|
||||||
static int get_vid_pid(
|
static int get_vid_pid(
|
||||||
struct udev_device *parent,
|
struct udev_device *parent,
|
||||||
|
const char *vendor_attr,
|
||||||
|
const char *product_attr,
|
||||||
uint16_t *vid,
|
uint16_t *vid,
|
||||||
uint16_t *pid) {
|
uint16_t *pid) {
|
||||||
|
|
||||||
if (get_id_attr(parent, VENDOR_ATTR, vid) < 0)
|
if (get_id_attr(parent, vendor_attr, vid) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
else if (*vid <= 0) {
|
else if (*vid <= 0) {
|
||||||
fprintf(stderr, "Invalid vendor id.\n");
|
fprintf(stderr, "Invalid vendor id.\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_id_attr(parent, PRODUCT_ATTR, pid) < 0)
|
if (get_id_attr(parent, product_attr, pid) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -89,12 +81,10 @@ static void rstrip(char *n) {
|
|||||||
|
|
||||||
#define HEXCHARS "0123456789abcdefABCDEF"
|
#define HEXCHARS "0123456789abcdefABCDEF"
|
||||||
#define WHITESPACE " \t\n\r"
|
#define WHITESPACE " \t\n\r"
|
||||||
|
static int lookup_vid_pid(const char *database,
|
||||||
static int lookup_vid_pid(
|
uint16_t vid, uint16_t pid,
|
||||||
uint16_t vid,
|
char **vendor, char **product)
|
||||||
uint16_t pid,
|
{
|
||||||
char **vendor,
|
|
||||||
char **product) {
|
|
||||||
|
|
||||||
FILE *f;
|
FILE *f;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -103,8 +93,8 @@ static int lookup_vid_pid(
|
|||||||
|
|
||||||
*vendor = *product = NULL;
|
*vendor = *product = NULL;
|
||||||
|
|
||||||
if (!(f = fopen(DATABASE, "r"))) {
|
if (!(f = fopen(database, "rme"))) {
|
||||||
fprintf(stderr, "Failed to open database file "DATABASE": %s\n", strerror(errno));
|
fprintf(stderr, "Failed to open database file '%s': %s\n", database, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,64 +191,62 @@ static struct udev_device *find_device(struct udev_device *dev, const char *subs
|
|||||||
}
|
}
|
||||||
return dev;
|
return dev;
|
||||||
try_parent:
|
try_parent:
|
||||||
return udev_device_get_parent_with_subsystem_devtype(dev, SUBSYSTEM, DEVTYPE);
|
return udev_device_get_parent_with_subsystem_devtype(dev, subsys, devtype);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char*argv[]) {
|
|
||||||
|
|
||||||
struct udev *udev = NULL;
|
static int builtin_db(struct udev_device *dev, bool test,
|
||||||
int ret = 1;
|
const char *database,
|
||||||
char *sp;
|
const char *vendor_attr, const char *product_attr,
|
||||||
struct udev_device *dev = NULL, *parent = NULL;
|
const char *subsys, const char *devtype)
|
||||||
|
{
|
||||||
|
struct udev_device *parent;
|
||||||
uint16_t vid = 0, pid = 0;
|
uint16_t vid = 0, pid = 0;
|
||||||
char *vendor = NULL, *product = NULL;
|
char *vendor = NULL, *product = NULL;
|
||||||
|
|
||||||
if (argc < 2) {
|
parent = find_device(dev, subsys, devtype);
|
||||||
fprintf(stderr, "Need to pass sysfs path.\n");
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(udev = udev_new()))
|
|
||||||
goto finish;
|
|
||||||
|
|
||||||
if (asprintf(&sp, "%s%s", udev_get_sys_path(udev), argv[1]) < 0) {
|
|
||||||
fprintf(stderr, "Failed to allocate sysfs path.\n");
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
dev = udev_device_new_from_syspath(udev, sp);
|
|
||||||
free(sp);
|
|
||||||
|
|
||||||
if (!dev) {
|
|
||||||
fprintf(stderr, "Failed to access %s.\n", argv[1]);
|
|
||||||
goto finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
parent = find_device(dev, SUBSYSTEM, DEVTYPE);
|
|
||||||
if (!parent) {
|
if (!parent) {
|
||||||
fprintf(stderr, "Failed to find device.\n");
|
fprintf(stderr, "Failed to find device.\n");
|
||||||
goto finish;
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_vid_pid(parent, &vid, &pid) < 0)
|
if (get_vid_pid(parent, vendor_attr, product_attr, &vid, &pid) < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
if (lookup_vid_pid(vid, pid, &vendor, &product) < 0)
|
if (lookup_vid_pid(database, vid, pid, &vendor, &product) < 0)
|
||||||
goto finish;
|
goto finish;
|
||||||
|
|
||||||
if (vendor)
|
if (vendor)
|
||||||
printf("ID_VENDOR_FROM_DATABASE=%s\n", vendor);
|
udev_builtin_add_property(dev, test, "ID_VENDOR_FROM_DATABASE", vendor);
|
||||||
|
|
||||||
if (product)
|
if (product)
|
||||||
printf("ID_MODEL_FROM_DATABASE=%s\n", product);
|
udev_builtin_add_property(dev, test, "ID_MODEL_FROM_DATABASE", product);
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
finish:
|
finish:
|
||||||
udev_device_unref(dev);
|
|
||||||
udev_unref(udev);
|
|
||||||
free(vendor);
|
free(vendor);
|
||||||
free(product);
|
free(product);
|
||||||
|
return 0;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int builtin_usb_db(struct udev_device *dev, int argc, char *argv[], bool test)
|
||||||
|
{
|
||||||
|
return builtin_db(dev, test, USB_DATABASE, "idVendor", "idProduct", "usb", "usb_device");
|
||||||
|
}
|
||||||
|
|
||||||
|
static int builtin_pci_db(struct udev_device *dev, int argc, char *argv[], bool test)
|
||||||
|
{
|
||||||
|
return builtin_db(dev, test, PCI_DATABASE, "vendor", "device", "pci", NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct udev_builtin udev_builtin_usb_db = {
|
||||||
|
.name = "usb-db",
|
||||||
|
.cmd = builtin_usb_db,
|
||||||
|
.help = "USB vendor/product database",
|
||||||
|
.run_once = true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const struct udev_builtin udev_builtin_pci_db = {
|
||||||
|
.name = "pci-db",
|
||||||
|
.cmd = builtin_pci_db,
|
||||||
|
.help = "PCI vendor/product database",
|
||||||
|
.run_once = true,
|
||||||
|
};
|
@ -31,6 +31,8 @@ static const struct udev_builtin *builtins[] = {
|
|||||||
[UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
|
[UDEV_BUILTIN_INPUT_ID] = &udev_builtin_input_id,
|
||||||
[UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
|
[UDEV_BUILTIN_KMOD] = &udev_builtin_kmod,
|
||||||
[UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
|
[UDEV_BUILTIN_PATH_ID] = &udev_builtin_path_id,
|
||||||
|
[UDEV_BUILTIN_PCI_DB] = &udev_builtin_pci_db,
|
||||||
|
[UDEV_BUILTIN_USB_DB] = &udev_builtin_usb_db,
|
||||||
[UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
|
[UDEV_BUILTIN_USB_ID] = &udev_builtin_usb_id,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -138,6 +138,8 @@ enum udev_builtin_cmd {
|
|||||||
UDEV_BUILTIN_INPUT_ID,
|
UDEV_BUILTIN_INPUT_ID,
|
||||||
UDEV_BUILTIN_KMOD,
|
UDEV_BUILTIN_KMOD,
|
||||||
UDEV_BUILTIN_PATH_ID,
|
UDEV_BUILTIN_PATH_ID,
|
||||||
|
UDEV_BUILTIN_PCI_DB,
|
||||||
|
UDEV_BUILTIN_USB_DB,
|
||||||
UDEV_BUILTIN_USB_ID,
|
UDEV_BUILTIN_USB_ID,
|
||||||
UDEV_BUILTIN_MAX
|
UDEV_BUILTIN_MAX
|
||||||
};
|
};
|
||||||
@ -155,6 +157,8 @@ extern const struct udev_builtin udev_builtin_firmware;
|
|||||||
extern const struct udev_builtin udev_builtin_input_id;
|
extern const struct udev_builtin udev_builtin_input_id;
|
||||||
extern const struct udev_builtin udev_builtin_kmod;
|
extern const struct udev_builtin udev_builtin_kmod;
|
||||||
extern const struct udev_builtin udev_builtin_path_id;
|
extern const struct udev_builtin udev_builtin_path_id;
|
||||||
|
extern const struct udev_builtin udev_builtin_pci_db;
|
||||||
|
extern const struct udev_builtin udev_builtin_usb_db;
|
||||||
extern const struct udev_builtin udev_builtin_usb_id;
|
extern const struct udev_builtin udev_builtin_usb_id;
|
||||||
int udev_builtin_init(struct udev *udev);
|
int udev_builtin_init(struct udev *udev);
|
||||||
void udev_builtin_exit(struct udev *udev);
|
void udev_builtin_exit(struct udev *udev);
|
||||||
|
Loading…
Reference in New Issue
Block a user