USB devices and their name in /dev

Is there a way in FreeBSD to ensure that, for example, a specific usb drive (or any device for that matter) is always configured as (for example) /dev/da1?
 
Not that I know of, but there are other ways to get a device to have an absolute name. You can label the filesystem with tunefs(8) or glabel(8), and then the label will show up in /dev/ufs/ or /dev/label. Examples here.

Or you can can use devd(8) to do something when a specific device is attached, like create a link with a specific name.
 
I've tried using tunefs -l label /dev/device but I get the following:
Code:
tunefs: /dev/da0s1d: failed to write superblock
 
If anyone can tell me how I would get the info for the following (from devd.conf man page):
Variables that can be used with the match statement
A partial list of variables and their possible values that can be used
together with the match statement.

Variable Description
bus Device name of parent bus.
cdev Device node path if one is created by the devfs(5) filesys-
tem.
cisproduct CIS-product.
cisvendor CIS-vendor.
class Device class.
device Device ID.
devclass Device Class (USB)
devsubclass Device Sub-class (USB)
device-name Name of attached/detached device.
endpoints Endpoint count (USB)
function Card functions.
interface Interface ID (USB)
intclass Interface Class (USB)
intprotocol Interface Protocol (USB)
intsubclass Interface Sub-class (USB)
manufacturer Manufacturer ID (pccard).
mode Peripheral mode (USB)
notify Match the value of the ``notify'' variable.
parent Parent device
port Hub port number (USB)
product Product ID (pccard/USB).
release Hardware revision (USB)
serial Serial Number (USB).
slot Card slot.
subvendor Sub-vendor ID.
subdevice Sub-device ID.
subsystem Matches a subsystem of a system, see below.
system Matches a system type, see below.
type Type of notification, see below.
vendor Vendor ID.

...specifically vendor, product, device-name, etc... something specific I can use to have devd run a script to make a symlink in /dev... I would like, for example a way of identifying my sony walkman and then having a script from devd run to make a symlink /dev/walkman to /dev/da1s1 (for example).
 
Here's an example:
Code:
attach 100 {
        device-name "ugen[0-9].[0-9]";
        match "vendor" "0x04b8";
        match "product" "0x010a";
        action "usb_devaddr=`echo $device-name | sed 's#^ugen##'` && \
                chown root:wheel /dev/usb/${usb_devaddr}.* && \
                chmod 0660 /dev/usb/${usb_devaddr}.* && \
                ln -s /dev/usb/${usb_devaddr} /dev/walkman";
};

(Untested, variation of one of my existing devices.) You'll have to change the vendor and product IDs for your device. And you need a detach entry to remove the link when you unplug the device.

Edit: no, this isn't going to work, at least not directly, because it needs to be a link to /dev/da*, not to /dev/usb/*. Use labels with tunefs(8).
 
ikbendeman said:
I've tried using tunefs -l label /dev/device but I get the following:
Code:
tunefs: /dev/da0s1d: failed to write superblock
I am not sure about the error (perhaps the filesystem is mounted?), but the labeling option is *capital* -L.
Read man pages very carefully. You will end up b0rking a system one day this way.
 
Beastie said:
I am not sure about the error (perhaps the filesystem is mounted?), but the labeling option is *capital* -L.
Read man pages very carefully. You will end up b0rking a system one day this way.

sorry I ran it with -L I just typed it wrong on the forums.
 
wblock said:
Here's an example:
Code:
attach 100 {
        device-name "ugen[0-9].[0-9]";
        match "vendor" "0x04b8";
        match "product" "0x010a";
        action "usb_devaddr=`echo $device-name | sed 's#^ugen##'` && \
                chown root:wheel /dev/usb/${usb_devaddr}.* && \
                chmod 0660 /dev/usb/${usb_devaddr}.* && \
                ln -s /dev/usb/${usb_devaddr} /dev/walkman";
};

(Untested, variation of one of my existing devices.) You'll have to change the vendor and product IDs for your device. And you need a detach entry to remove the link when you unplug the device.

Thanks for that, I just... where do you get the vendor and product flags? How do I figure those out?
 
Sorry, I just edited that to say it won't work for a disk device (or at least I haven't figured out the right way to do it). You can find vendor and product IDs from /var/log/messages or usbconfig(8), though.
 
Back
Top