# Fixing device nodes



## robbak (Jun 1, 2012)

My system is driving a number of USB printers. The issue is that these printers nodes aren't fixed: they appear with different nodes, depending on what else is turned on.

The only partial fix is something like this in a /etc/devd.conf (or a local config file in /usr/local/etc/devd/). It creates a fixed link to the device in /dev. 

```
attach 100 {
        match "vendor" "0x04a9";
        match "product" "0x1051";
        action "ln -s /dev/$device-name /dev/canon";
};
```
This doesn't quite work for me: One of my printers needs to connect to /dev/unlpt_n_, the non-resetting node. If I connect to /ulpt_n_, I lose the last part of the first print when the second print causes the printer to reset. I can't see how to get devd to link to the unlpt device node. I tried to use the sh ${device-name#ulpt} to get just the number, but it looks like devd didn't understand it. Do *I* really have to get messy - call a script that can understand ${#}? I also don't know how happy CUPS will be connecting through a s*y*mlink.

Does anyone have a solution? The best solution would be to be able to reserve a u[n]lpt node for a named device, but I do not know if there is a way to do that.


----------



## wblock@ (Jun 1, 2012)

It would be really nice to have a file of vendor and product IDs and extra links that should be created.  Like /etc/devfs.conf, but for dynamic devices.  
	
	



```
# vendorid  productid   substitution    perm
0x04a9      0x1051      s/ulpt/unlpt/   0660
```

AFAIK, there currently is nothing set up for that, but it seems like a project that would not be too difficult.  In the meantime, action is already a script.  So:

```
action "$unlptdev = `echo $device-name | sed 's%^ulpt%unlpt%'` && ln -s /dev/$unlptdev /dev/canon";
```

Probably good to add one more && and set permissions on the new link.


----------



## robbak (Jun 2, 2012)

Hmm, that might be good, at the moment, I have this:
devd.conf:
	
	



```
attach 100 {
        match "vendor" "0x04a9";
        match "product" "0x1051";
        action "/usr/local/sbin/canon_simlink.sh $device-name";
};
detach 100 {
        match "vendor" "0x04a9";
        match "product" "0x1051";
        action "rm /dev/canon";
};
attach 100 {
        match "vendor" "0x04f9";
        match "product" "0x0033";
        action "ln -sf /dev/$device-name /dev/brother-laser";
};
detach 100 {
        match "vendor" "0x04f9";
        match "product" "0x0033";
        action "rm /dev/brother-laser";
```
and canon_simlink.sh (which I think I have spelt wrong: it's "symlink", isn't it?

```
#!/bin/sh
ln -fs /dev/unlpt${1#ulpt} /dev/canon
```
CUPS seems to be fine with it, although you have to edit /etc/cups/printers.conf to add the device node, as the http interface doesn't allow custom devices. My preferred solution would be for the devfs code to detect and record vendor, product and serials, and always give the same device node to the same device, but that's a SMOP, I guess.


----------

