Making and Accessing the Scanner Devices

The Scanner HOWTO
Prev |  | Next

# 3. Making and Accessing the Scanner Devices

The following section applies to all hardware types. Some specifics with regard to scanner interface types are mentioned in the paragraphs at the end of this section.

## 3.1. Device Filesystem and Udev

Devfs, or 'device filesystem' has been an option in the Linux kernel since the late 2.2-series. Devfsd, the device filesystem daemon, creates and removes devices on your system dynamically without the need to manually create devices. If you are running devfsd/devfs you can probably skip the following sections as the process of creating device nodes will be done for you and it's simply a matter of finding the appropriate device node in `/dev`.

Devfs does not obviate the need to change permissions of devices for access by users.

Beginning in the 2.6-series kernel devfs has been deprecated in favor of a userspace daemon known as udev, though devfs remains as an option. You can find information on udev here.

## 3.2. Creating Devices Manually

If you are running a system with correctly configured devfs, udev or libusb, you can skip this step and go to Section 4. There are two ways to accomplish the creation of necessary devices manually. One is to use MAKEDEV and the other is to create the device nodes at the command line.

The MAKEDEV script is the easier of the two methods, the executable of which may be located in `/dev` or the usual places for storing binary executables (`/bin`,`/sbin` and so on). I direct you to man MAKEDEV, and would caution you to pay attention to the device-specific command options so that you can be sure the major and minor numbers are correct (see the next paragraph for more on this and why it is important, especially if MAKEDEV doesn't work or you prefer doing things the hard way).

A device can be created as a block (such as a drive), a fifo (file-in-file-out or pipe, as in xconsole) or a character device, which represents other hardware. Each device has a major and a minor number "coordinate" to tell the kernel what it is and where to access it. These numbers are not arbitrary.

### 3.2.1. SCSI Devices

If you are running a 2.4-series kernel you should consider becoming familiar with SCSI proc interface access, and whichever kernel you are running, you should read man sane-scsi before reading further. When the system boots up, generic SCSI device files are mapped on `/dev/sgN`, where N is a numeric value starting at zero. The major and minor numbers for SCSI devices are 21 and 0,1,2,3... respectively. You can find out what devices are loaded already with ls -l /dev/sg*, which should yield output similar to this:

    crw-------   1 root   sys     21,  0 Jan 06  2003 /dev/sg0
    crw-------   1 root   sys     21,  0 Jan 06  2003 /dev/sg1
    crw-------   1 root   sys     21,  0 Jan 06  2003 /dev/sg2
    crw-------   1 root   sys     21,  0 Jan 06  2003 /dev/sg3
    crw-------   1 root   sys     21,  0 Jan 06  2003 /dev/sg4
    crw-------   1 root   sys     21,  0 Jan 06  2003 /dev/sg5

You will need to make a `/dev/scanner` symbolic link to an existing device (for reasons clarified later). For example, if your scanner is connected to the first scsi-bus (and lun and target) of your SCSI host device, you should link it to the corresponding device:

    #  ln -s /dev/sg0 /dev/scanner

### 3.2.2. Manually creating USB Devices

Again, you can skip this step if using libusb. USB scanner devices have the major number 180 and minor 48, 49, etc., up to 63. First, check `/dev` to see what directory your distribution lays out its USB directory devices in, as some distributions might have these devices `scanner0, scanner1...`etc., within `/dev/usb` or as `usbscanner0, usbscanner1...` and so on, in the base `/dev/` directory. If you find that in the `/dev/` directory the scanner devices have already been made for you then your work is done. If not, you will need to create them yourself. As root, make a character device for your scanner like so:

    # mknod /dev/usbscanner0 c 180 48

...or if your distribution has a '/dev/usb' subdirectory:

    # mknod /dev/usb/scanner0 c 180 48

### 3.2.3. Manually creating Parallel Port Devices

Follow the example outlined in the above section to create the following generic parport devices:

    crw-------    1 root     root      99,   0 Jun 24 13:47 parport0
    crw-------    1 root     root      99,   1 Jun 24 13:47 parport1
    crw-------    1 root     root      99,   2 Jun 24 13:47 parport2
    crw-------    1 root     root      99,   3 Jun 24 13:47 parport3
    crw-r-----    1 root     root       1,   4 Jan  1  1970 port

You may also need to create `/dev/port` and/or `/dev/parport` depending on the backend you will use, so be prepared to return to this step if your application dictates it.

## 3.3. Groups and Permissions

It is a good idea to be sure that your user account can access the device once all modules are loaded and device nodes created. The most security-conscious way to do that is to add scanner access to a particular group. On my system, the members of the group 'scanner' are allowed to use the scanner. The way to accomplish this is to first change the ownership of the devices in `/dev` like so (as root):

    # chown root.scanner /dev/usb/scanner*

...where root.scanner are the owner and group the device will now belong to. Obviously the specific command will vary by your system and the type of device, whether `/dev/sg*` on SCSI scanners, etc. It is important that you change the ownership of the device node itself and not the symlink; symlinks' ownerships are affected only by changing the parent devices or files they point to.

To see if your user account is a member of the group in question, as root issue the following command: grep -e scanner /etc/group. You should see something like the following:

    scanner:x:103:

...where '103' is the group number. Since no members follow the last colon in the 'scanner' group we can add them, let's say user 'jhs' with the command

    # adduser jhs scanner

After this it's simply a matter of allowing read and write access for the user in question of the device like so:

    # chmod g+rw /dev/usb/scanner0

...where g+rw means add read and write access for group. See the documentation for chmod (man chmod or info chmod) for further info.

Prev | Home | Next
General Support and Interface Type |  | SANE