:: Re: [Dng] Purpose of all this compl…
Página Principal
Delete this message
Reply to this message
Autor: karl
Data:  
Para: dng
Tópicos Novos: [Dng] libsysdev preview
Assunto: Re: [Dng] Purpose of all this complicated device management?
Isaac Dunham:
> On Sat, Jan 17, 2015 at 08:06:05PM +0100, karl@??? wrote:

...
> > One use case I could find useful is to have an xdev that I could
> > run from-time-to-time to check if I'm missing something in /dev.
>
> For what it's worth, I've used "busybox mdev -s" for this purpose.
> Note that it *creates* devices, rather than outputting a list of
> filenames with attributes.


Ok, something like:
find /sys/devices/ -name dev | while read a; do printf "%3d, %3d\t" `cat $a | tr ':' ' '`; dirname $a; done

> > 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

> Your proposed command that would "scan lspci" is roughly equivalent to
> either of these command lines:
> find /sys -name modalias | xargs sort -u | xargs resolve_modalias
> find /sys -name uevent -exec sed -ne 's/^MODALIAS=//p' + | \
>     sort -u | xargs resolve_modalias

>
> where resolve_modalias is a command that finds all entries in
> /lib/modules/`uname -r`/modules.alias expanding to match each
> argument.
> Sample:
> $ resolve_modalias pci:v00008086d000027D8sv00001025sd0000015Bbc04sc03i00
> snd_hda_intel
>
> I've implemented resolve_modalias in the past, and there have been
> similar commands written elsewhere.


Ok, got it, scanning /sys in some ways.

> But really, your requests are very close to the standard usage for mdev.
> Substitute "modprobe -abq" for "resolve_modalias", and the command line
> above is the standard way to autoload drivers.


I don't have much interest in the "auto" part of the loading process.

Regards,
/Karl Hammar

-----------------------------------------------------------------------
Aspö Data
Lilla Aspö 148
S-742 94 Östhammar
Sweden
+46 173 140 57