# devfs type ACTION with udev

## SimonKellett

I am now using udev and K2.6.10. What I want is the functionality of devfs whereby when a program tries to access a device the correct modules are loaded that produce that device file (configured by hand).

E.g. when accessing /dev/ppp load ppp_generic and for /dev/snd load snd etc.

But this is not covered by hotplugging as the devices are always there !!

----------

## DrWoland

 *SimonKellett wrote:*   

> I am now using udev and K2.6.10. What I want is the functionality of devfs whereby when a program tries to access a device the correct modules are loaded that produce that device file (configured by hand).
> 
> E.g. when accessing /dev/ppp load ppp_generic and for /dev/snd load snd etc.
> 
> But this is not covered by hotplugging as the devices are always there !!

 

Uhhhh you got that backwards broly, the devices ARENT always there in udev... they're always there in devfs. Did you disable loading the device tarball in /etc/conf.d/rc?

----------

## SimonKellett

 *DrWoland wrote:*   

> Uhhhh you got that backwards broly, the devices ARENT always there in udev... they're always there in devfs.

 

Sorry: my mistake: what I meant was that the devices themselves are *physically* there, not the device file. Eg my sound card is in there all the time, so there is no "hotplug event" to trigger the loading of modules. (yes: I could autoload evverything but I am a tidy guy  :Smile: 

 *Quote:*   

> Did you disable loading the device tarball in /etc/conf.d/rc?

 

Yes

----------

## MighMoS

I seem to recall udev stating that it wasn't its job to autoload modules (I'm going strictly from memory, though).  If you're a tidy guy, and the sound card isn't leaving, I must ask why is it built as a module at all?

----------

## SimonKellett

 *MighMoS wrote:*   

> I seem to recall udev stating that it wasn't its job to autoload modules

 

Correct: that is why I need an alternative !!

 *Quote:*   

> If you're a tidy guy, and the sound card isn't leaving, I must ask why is it built as a module at all?

 

So that most of the time the kernel code is not loaded and so not using memory, then when I do  want sound I load the module and off I go !!

(Perhaps the saving of a few kb of memory is not worth the effort, or maybe it I install some more RAM, but then I would not learn anything  :Smile: 

----------

## DrWoland

 *SimonKellett wrote:*   

>  *MighMoS wrote:*   I seem to recall udev stating that it wasn't its job to autoload modules 
> 
> Correct: that is why I need an alternative !!
> 
>  *Quote:*   If you're a tidy guy, and the sound card isn't leaving, I must ask why is it built as a module at all? 
> ...

 

Well, if you don't want it loaded at all times, then why would you want udev to autoload it for you? You're contradicting yourself. If you just want the module loaded when you want sound, use 

```

modprobe name-of-the-module

```

when you want it loaded. I'm not sure I understand you correctly.

----------

## SimonKellett

 *DrWoland wrote:*   

> Well, if you don't want it loaded at all times, then why would you want udev to autoload it for you?

 

I never intended to say that I wanted udev to do it: "that is why I need an alternative"

 *Quote:*   

> If you just want the module loaded when you want sound, use 
> 
> ```
> 
> modprobe name-of-the-module
> ...

 

This is what I do at the moment: but with devfs it would recognise that /dev/snd was being accessed and then load the module for me.

It seems that udev now handles /dev creation, hotplugging will load a module when a *new* device is physically added, coldplugging or autoload loads modules at boot time, but I do not see what handles loading of modules (cleverly) as requested (in this case indirectly) by a user task trying to access the /dev file.

----------

## DrWoland

 *SimonKellett wrote:*   

>  *DrWoland wrote:*   Well, if you don't want it loaded at all times, then why would you want udev to autoload it for you? 
> 
> I never intended to say that I wanted udev to do it: "that is why I need an alternative"
> 
>  *Quote:*   If you just want the module loaded when you want sound, use 
> ...

 

You're a lazy ass bum. That is all. Go back to using ancient devfs  :Smile: 

----------

## SimonKellett

 *DrWoland wrote:*   

> You're a lazy ass bum. That is all. Go back to using ancient devfs 

 

That would be one point of view: another would be that I am interested in how things work  :Smile: 

----------

## MighMoS

So, excuse me for being stupid, but can you outline exactly what you want to happen?

----------

## SimonKellett

 *MighMoS wrote:*   

> So, excuse me for being stupid, but can you outline exactly what you want to happen?

 

For example my computer boots up with the onboard sound card physical present but the relevent sound modules NOT loaded. Maybe once a month I want sound from my computer so I start up my user application (eg mpg123 or realplayer) and when "the system" sees this application *trying* to access, for example, /dev/snd it auto-magically loads the sound modules that result in /dev/snd being available to the application. No root access required !!

With OSS/2.4.26 I had devfs running and the default rules, plus my "alias sound-slot-0 ymfpci" did this for me (ymfpci being the modules for my sound chipset.).

I know that I can work around the problem, but it seems to me that devfs is now deprecated, but udevfs+hotplug+coldplug does not replace all the functionality.

FWIW I have no special allegance to devfs or whatever, I am just curious how it is "supposed" to work, or what is available !!

----------

## mkrisch

i believe the "correct" method  is to add the modules you require to /etc/modules.autoload.d/kernel-2.6 (2.4 if that's what you are running).

that said, i find that my sound modules are automagically loaded, possibly as a result of /etc/init.d/alsasound?

----------

## Decibels

Part of the problem that I see with what you want is, that lot of software uses the sound card: System notifications like in KDE,.. portage beeps sometimes, video players like xine & mplayer, sound like xmms,... kmail notifies when mail arrives,...

Don't know of any userland program that will let you select from a list of apps that will or will not use the sound device. You can deactivate sound in a lot of them though, but individually. 

You could for example with kde add a command possibly to 'modprobe <module-name>' when this menu item is clicked (rmmod <module-name> when it exits though would be another matter). You could add a desktop shortcut to do the same thing, but again run into problems when closing app.

Short of writing your own daemon to load the sound modules when a certain app is started, and unload it when done, don't see any other way to do what you want.

----------

## dsd

the answer can be found in the udev FAQ

http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-FAQ

----------

## SimonKellett

 *Decibels wrote:*   

> Part of the problem that I see with what you want is, that lot of software uses the sound card... Don't know of any userland program that will let you select from a list of apps that will or will not use the sound device.
> 
> 

 

Not with my setup !! I do not use KDE or Gnome. My Userland setup is Fvwm2, xemacs (editting, email, usenet), firefox, mrxvt (Mainly because I like these apps., also because I only have 433Mhz and 160Mb to use !!).

Very, very occasionally I want sound and/or vision: then I use xine, mpg123, mutella (!) and I then want sound loaded.

But thanks for the suggested workarounds !

----------

## SimonKellett

 *dsd wrote:*   

> the answer can be found in the udev FAQ
> 
> http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-FAQ

 

Thanks for the reply: but I can not see the answer to my question.  I read the FAQ when I migrated to udev, and I just read through it carefully again. It mentions the functionality that I want, and why it is not in udev. This is *OK* by me (one app. one function). (I am not asking whether udev can do not I want, nor do I intend to request that udev do what I want. udev is fine.) But it does not seem to answer my question !!

It seems that I am supposed to replace devfs with udev, but it seems to me that udev + coldplug + hotplug <> devfs. I was hoping that the missing functionality (missing from my computer, not missing from udev) was provided by some *new* app / kernel feature that I am ignorant of.

----------

## bennettp

 *SimonKellett wrote:*   

> This is what I do at the moment: but with devfs it would recognise that /dev/snd was being accessed and then load the module for me.
> 
> It seems that udev now handles /dev creation, hotplugging will load a module when a *new* device is physically added, coldplugging or autoload loads modules at boot time, but I do not see what handles loading of modules (cleverly) as requested (in this case indirectly) by a user task trying to access the /dev file.

 

You're thinking about udev in the wrong way. Here's how udev differs from devfs: With devfs, when a user tries to access a device node (in /dev), devfs autoloads the module. Udev works differently: when a physical device is discovered, udev creates the appropriate device nodes. When the physical device is removed, the device nodes are removed.

How is hardware discovered? That's hotplug's job. For example, when you insert a usb flash drive, it is detected by hotplug. Hotplug then loads the needed modules (usb_storage), and calls udev to create the device nodes.

So, the short answer to your question is: hotplug handles loading of modules (cleverly), but not when a user requests a /dev file. The module is loaded when the physical device is discovered in the system.

----------

## SimonKellett

(I think I am not explaining myself correctly !!!)

 *bennettp wrote:*   

> 
> 
> You're thinking about udev in the wrong way.
> 
> 

 

No I am not !! I have *never* said that I expect or want udev to do what I want. I *have* said that I am using udev and that I want some functionality that was provided by devfs.

Clarification: I do [edit]not[/edit] want/expect udev to load any modules at anytime. I have no problem that udev does not load modules.

 *Quote:*   

> So, the short answer to your question is: hotplug handles loading of modules (cleverly), but not when a user requests a /dev file. The module is loaded when the physical device is discovered in the system.

 

No: this is not what I want  :Smile:  As I said earlier in the thread the device is NOT hotplugged: it is always available so there is no hotplug event to trigger the loading of a module.

But thanks for your reply, SimonLast edited by SimonKellett on Thu Feb 03, 2005 2:30 pm; edited 1 time in total

----------

## dsd

as of recent 2.6 releases, similar functionality is provided by the kernel. you just have to make the device node first.

see:

http://www.kroah.com/log/linux/kmod_part1.html?seemore=y

http://www.kroah.com/log/linux/kmod_part2.html?seemore=y

----------

## Decibels

 *SimonKellett wrote:*   

> Not with my setup !! I do not use KDE or Gnome. My Userland setup is Fvwm2, xemacs (editting, email, usenet), firefox, mrxvt (Mainly because I like these apps., also because I only have 433Mhz and 160Mb to use !!).

 

Hmm, wish you had mentioned that at first, probably wouldn't have bothered to respond.

DSD: I can see that Greg KH hasn't finished what you linked to. Is that going to provide the functionality he is looking for? Seems like he is looking for something that will load sound modules when, for example he picks xmms app to start, put not if some other app wants a sound module and he doesn't want it to.  

Maybe someone else is using another WM and other devices want the sound modules also, besides for example xmms. He would want to pick which apps can / can't use the sound modules. At least that is what I gather, maybe I am wrong cause others don't seem to be picking up on that.

----------

## SimonKellett

 *mkrisch wrote:*   

> that said, i find that my sound modules are automagically loaded, possibly as a result of /etc/init.d/alsasound?

 

This is a possibililty: I noticed my missing functionality when I wanted to connect to the internet and /dev/ppp was not available but assumed I would have the same problem with sound.

(I am moving from 2.4/OSS and although I have configured my 2.6.10 kernel for Alsa with OSS compatability I have not yet emerged/configured the Alsa tools. Having said that it would nice not to have Alsa running all the time: only when I want it.)

The same applies to my printer: I use it maybe once a month, so I do not have CUPs running by default: I start it when I need it (currently by a SETUID script to run /etc/init.d/cups start  :Smile: 

----------

## phixom

Have you tried coldplug? It should load the most necessary modules at startup.

phixom

----------

## dsd

 *Decibels wrote:*   

> DSD: I can see that Greg KH hasn't finished what you linked to. Is that going to provide the functionality he is looking for? Seems like he is looking for something that will load sound modules when, for example he picks xmms app to start, put not if some other app wants a sound module and he doesn't want it to.  

 

the functionality is already there, just he hasnt finished writing his explanation of how it works internally yet.

if i make a /dev/lp0 node with the correct major/minor numbers, (see /usr/src/linux/Documentation/devices.txt), and i try to access this node _without_ the module loaded, then magically the module gets loaded in the background.

----------

## SimonKellett

 *dsd wrote:*   

> as of recent 2.6 releases, similar functionality is provided by the kernel. you just have to make the device node first...

 

Thanks: I just had chance to try this and it works  :Smile: 

eg as root:

# mknod -m 660 /dev/dsp c 14 3

# chgrp audio /dev/dsp

And then as user I started mpg123 (by default it accesses /dev/dsp). The kernel loaded up all the sound modules, created some more /dev files and out comes the music  :Smile: 

Which leads to the question: how do I create this file at boot time. Do I add the above commands to a startup script, or can I configure the udev rules to do it for me ? (with the correct group setting and permissions ?)

TIA, Simon

----------

## dsd

udev doesnt do this. you'd need to script it elsewhere.

----------

## mkrisch

in /etc/conf.d/rc there's an option, RC_DEVICE_TARBALL:

# UDEV OPTION:

# Set to "yes" if you want to save /dev to a tarball on shutdown

# and restore it on startup.  This is useful if you have a lot of

# custom device nodes that udev does not handle/know about.

RC_DEVICE_TARBALL="yes"

that should save the ones you create manually.

----------

