old-www/HOWTO/Scanner-HOWTO/dev-intro.html

547 lines
11 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Making and Accessing the Scanner Devices</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="The Scanner HOWTO"
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="General Support and Interface Type"
HREF="interfaces.html"><LINK
REL="NEXT"
TITLE="SANE"
HREF="sane.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>The Scanner HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="interfaces.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="sane.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="DEV-INTRO"
></A
>3. Making and Accessing the Scanner Devices</H1
><P
>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.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DEVFSD"
></A
>3.1. Device Filesystem and Udev</H2
><P
><A
HREF="http://www.atnf.csiro.au/~rgooch/linux/docs/devfs.html"
TARGET="_top"
>Devfs</A
>, 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 <TT
CLASS="FILENAME"
>/dev</TT
>.</P
><P
>Devfs does not obviate the need to change permissions of devices for access by users.</P
><P
>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 <A
HREF="http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev-FAQ"
TARGET="_top"
>here</A
>.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="DEV-MANUAL"
></A
>3.2. Creating Devices Manually</H2
><P
>If you are running a system with correctly configured devfs, udev or libusb, you can skip this step and go to <A
HREF="sane.html"
>Section 4</A
>.
There are two ways to accomplish the creation of necessary devices manually. One is to use <B
CLASS="COMMAND"
>MAKEDEV</B
> and the other is to create the device nodes at the command line. </P
><P
>The <B
CLASS="COMMAND"
>MAKEDEV</B
> script is the easier of the two methods, the executable of which may be located in <TT
CLASS="FILENAME"
>/dev</TT
> or the usual places for storing binary executables (<TT
CLASS="FILENAME"
>/bin</TT
>,<TT
CLASS="FILENAME"
>/sbin</TT
> and so on).
I direct you to <B
CLASS="COMMAND"
>man MAKEDEV</B
>, 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 <B
CLASS="COMMAND"
>MAKEDEV</B
> doesn't work or you prefer doing things the hard way).</P
><P
>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 <SPAN
CLASS="QUOTE"
>"coordinate"</SPAN
> to tell the kernel what it is and where to access it.
These numbers are not arbitrary.</P
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="SCSI-MANUAL-DEV"
></A
>3.2.1. SCSI Devices</H3
><P
>If you are running a 2.4-series kernel you should consider becoming familiar with <A
HREF="http://tldp.org/HOWTO/SCSI-2.4-HOWTO/mlproc.html"
TARGET="_top"
>SCSI proc interface access</A
>, and whichever kernel you are running, you should read <B
CLASS="COMMAND"
>man sane-scsi</B
> before reading further.
When the system boots up, generic SCSI device files are mapped on <TT
CLASS="FILENAME"
>/dev/sgN</TT
>, 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 <B
CLASS="COMMAND"
>ls -l /dev/sg*</B
>, which should yield output similar to this:</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>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</PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>You will need to make a <TT
CLASS="FILENAME"
>/dev/scanner</TT
> 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:</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
># ln -s /dev/sg0 /dev/scanner</PRE
></FONT
></TD
></TR
></TABLE
></P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="USB-MANUAL"
></A
>3.2.2. Manually creating USB Devices</H3
><P
>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 <TT
CLASS="FILENAME"
>/dev</TT
> to see what directory your distribution lays out its USB directory devices in, as some distributions might have these devices <TT
CLASS="FILENAME"
>scanner0, scanner1...</TT
>etc., within <TT
CLASS="FILENAME"
>/dev/usb</TT
> or as <TT
CLASS="FILENAME"
>usbscanner0, usbscanner1...</TT
> and so on, in the base <TT
CLASS="FILENAME"
>/dev/</TT
> directory.
If you find that in the <TT
CLASS="FILENAME"
>/dev/</TT
> 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:</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
># mknod /dev/usbscanner0 c 180 48</PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>...or if your distribution has a '/dev/usb' subdirectory:</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
># mknod /dev/usb/scanner0 c 180 48</PRE
></FONT
></TD
></TR
></TABLE
></P
></DIV
><DIV
CLASS="SECT3"
><H3
CLASS="SECT3"
><A
NAME="PARPORT-MANUAL"
></A
>3.2.3. Manually creating Parallel Port Devices</H3
><P
>Follow the example outlined in the above section to create the following generic parport devices:</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>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</PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>You may also need to create <TT
CLASS="FILENAME"
>/dev/port</TT
> and/or <TT
CLASS="FILENAME"
>/dev/parport</TT
> depending on the backend you will use, so be prepared to return to this step if your application dictates it.</P
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="PERMISSIONS"
></A
>3.3. Groups and Permissions</H2
><P
>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 <TT
CLASS="FILENAME"
>/dev</TT
> like so (as root):</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
># chown root.scanner /dev/usb/scanner*</PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>...where <B
CLASS="COMMAND"
>root.scanner</B
> 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 <TT
CLASS="FILENAME"
>/dev/sg*</TT
> 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.</P
><P
>To see if your user account is a member of the group in question, as root issue the following command: <B
CLASS="COMMAND"
>grep -e scanner /etc/group</B
>.
You should see something like the following:</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
>scanner:x:103:</PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>...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</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
># adduser jhs scanner </PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>After this it's simply a matter of allowing read and write access for the user in question of the device like so:</P
><P
><TABLE
BORDER="1"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="SCREEN"
># chmod g+rw /dev/usb/scanner0</PRE
></FONT
></TD
></TR
></TABLE
></P
><P
>...where <B
CLASS="COMMAND"
>g+rw</B
> means add <B
CLASS="COMMAND"
>r</B
>ead and <B
CLASS="COMMAND"
>w</B
>rite access for <B
CLASS="COMMAND"
>g</B
>roup.
See the documentation for chmod (<B
CLASS="COMMAND"
>man chmod</B
> or <B
CLASS="COMMAND"
>info chmod</B
>) for further info.</P
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="interfaces.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="sane.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>General Support and Interface Type</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>SANE</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>