Querying WWAN iface name for each /dev/cdc-wdm device

Bjørn Mork bjorn at mork.no
Tue Jan 27 00:34:06 PST 2015


Aleksander Morgado <aleksander at aleksander.es> writes:
> On Mon, Jan 26, 2015 at 10:04 PM, Bjørn Mork <bjorn at mork.no> wrote:
>
>> No objection, but I believe this info is easy to get from sysfs without
>> any additional tools:
>>
>>  bjorn at nemi:~$ ls -l /sys/class/usbmisc/cdc-wdm0/device/net/
>>  total 0
>>  drwxr-xr-x 6 root root 0 Jan 26 22:00 wwan0
>
> Yeah, maybe for this specific case where we just want to query that
> device name once and we don't want udev events, it probably is worth
> to just parse the sysfs path directly... Or will we ever want to get
> udev events as well? E.g. Could the systemd network interface renames
> affect the logic?

sysfs will show the current kernel device name, so any renaming should
Just Work (tm).  Note that this also works the other way round.  So if
you wonder what the name of the control device is for network device
"bar", you can do:

 bjorn at nemi:~$ ls -l /sys/class/net/bar/device/usbmisc
 total 0
 drwxr-xr-x 3 root root 0 Jan 27 09:20 cdc-wdm0

The only undetected renaming issue I can think of is if someone renames
the file in /dev so it doesn't match the kernel device name. I don't
think that is very likely though, and IMHO it should not be supported.
You can do it, but then you're on your own...

But if you are going to be really, really prepared for anything, you
could check the major/minor numbers of the /dev file and look up the
associated kernel devices:

 bjorn at nemi:~$ ls -ln /dev/cdc-wdm0 
 ls: cannot access /dev/cdc-wdm0: No such file or directory
 bjorn at nemi:~$ ls -ln /dev/foo 
 crw-rw---- 1 0 20 180, 0 Jan 27 08:46 /dev/foo
 bjorn at nemi:~$ ls -ld /sys/dev/char/180:0/device/{usbmisc,net}/*
 drwxr-xr-x 6 root root 0 Jan 27 09:23 /sys/dev/char/180:0/device/net/bar
 drwxr-xr-x 3 root root 0 Jan 27 09:20 /sys/dev/char/180:0/device/usbmisc/cdc-wdm0


Bjørn


More information about the libqmi-devel mailing list