:: [Dng] libsysdev preview
Página Inicial
Delete this message
Reply to this message
Autor: Isaac Dunham
Data:  
Para: karl
CC: dng
Tópicos Antigos: Re: [Dng] Purpose of all this complicated device management?
Assunto: [Dng] libsysdev preview
On Sun, Jan 18, 2015 at 01:11:15PM +0100, karl@??? wrote:
> Isaac Dunham:
> > On Sat, Jan 17, 2015 at 08:06:05PM +0100, karl@??? wrote:
> > > Also a lib that maps major/minor to /dev/name and the like, a command
> > > that "scans lspci" and the like, and suggests kernel modules,
> > > which I then at my own discretion can add to /etc/modules.
> > > I.e. an udev that instead of taking over the system, gives me some
> > > tools I could use to examine a system.
> >
> > To map major/minor/devtype to /dev/name (note: /dev/zero has the same
> > major/minor as /dev/ram5; one is char, the other is block) you really
> > need to recurse through /dev and find the first file that matches.
> >
> > I could write a non-threadsafe version of said function using nftw()
> > in a day, I suppose; if I lift the dirtree code from toybox and patch
> > it to fit, it might be not be much more work...
> >
> > So does "libsysdev" sound like a good name, and
> > char * sysdev_getdevname(int major, int minor, int ischar);
> > seem like a good prototype?
>
> Yes.
>
> Mesa uses the name sysfs, which might be better than sysdev.
> The following two might be a good start:
>
> $ grep ^sysfs src/loader/loader.c
> sysfs_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
> sysfs_get_device_name_for_fd(int fd)
>
> and
>
> dev_node_from_fd(int fd, unsigned int *maj, unsigned int *min)
>
> libsysfs seems to be taken:
> http://linux-diag.sourceforge.net/Sysfsutils.html
> http://storage.jak-stik.ac.id/linux/doc/sysfsutils/libsysfs.pdf


libsysfs, which is used by udev, has already taken the sysfs_ namespace.
I don't want to collide with that.

I'd like to provide something that can be utilized as a fallback when
libudev is missing/udev doesn't start.
Optimally, the API will be simple enough that developers then say
"And why aren't we using this *instead* of libudev?"

A preview is available at
https://github.com/idunham/libsysdev

There's a basic example at util/devinfo.c, and the header has comments
tersely explaining what inputs each function takes.

I wrote it so that the udev usage in xf86-input-evdev can be
replaced with more or less this:
    devfd = open(devicenode, O_RDONLY);
    if (devfd < 0)
        goto out;
    devpath = sysdev_devfd_to_syspath(devfd);
    if (devpath) {
    if (strstr(devpath, "LNXSYSTM"))
        rc = TRUE;
    free(devpath);
    }
    close(devfd);
out:
    return rc;


I have not yet tested that, however.

It builds with "make" (no ./configure).
It will build and install into /usr/{bin,lib,include} by default.
On debian, devuan, and related distros, you will need to install with:
make LIBDIR="/usr/lib/$TRIPLET" install
On non-pure64 64-bit installs of other distros, you will need to set
LIBDIR to point to the appropriate directory (lib32 or lib64).

Before I fix that, I'd like some pointers on how to pick up the
right triplet on multiarch and the right libdir on multilib.
(as a shell snippet).

I want to add a .pc file for pkg-config; I've delayed that to get the
code out as soon as possible.

Comments, requests, patches welcome; flames to /dev/null.

Thanks,
Isaac Dunham