Contact us

Print

Determining device type

In this exercise you will determine if a device is a block device or a character device.

To determine a device type

1. Log on to your machine as root

2. cd to the /dev directory and list all its contents.

root@localhost /dev# ls -l
……..
brw-rw---- 1 root disk 3, 0 Apr 11 07:25 hda
brw-rw---- 1 root disk 3, 1 Apr 11 07:25 hda1
brw-rw---- 1 root disk 3, 10 Apr 11 07:25 hda10
brw-rw---- 1 root disk 3, 11 Apr 11 07:25 hda11
brw-rw---- 1 root disk 3, 12 Apr 11 07:25 hda12
………….

3. Take note of the entries in the far left of the first column.

4. To see the device type of the first IDE hard disk on the primary master. Type :

root@localhost dev# ls -l hda

brw-rw---- 1 root disk 3, 0 Apr 11 07:25 hda


The output of "ls -l hda" shows a letter "b" on the far left of the first column, which
means that your hard disk is a block device

The major device number for /dev/hda is shown in the 5th column. It is 3.

The minor device number for /dev/hda is shown in the 6th column. It is 0.

5. To see the device type for the first partition on /dev/hda. Type :

root@localhost dev# ls –l /dev/hda1

brw-rw---- 1 root disk 3, 1 Apr 11 07:25 /dev/hda1

From your output, what is the major number and minor number for /dev/hda1?


6. To see the device type for your mouse .Type :

root@localhost dev# ls -l /dev/input/mice

crw------- 1 root root 10, 1 Jun 18 16:03 /dev/input/mice

The output of "ls -l /dev/input/mice" shows a letter "c" on the far left of the first column, which means that your mouse is a character device.

From your output, what is the major number and minor number for /dev/input/mice?



7. You can also use the “file” command to find out the device type, the major and minor
numbers of a device.

root@localhost pub# file /dev/input/mice

/dev/input/mice: character special (13/63)


Device files allow access to hardware. To demonstrate this using your mouse, you will direct the input of “/dev/input/mice” (i.e. the mouse device) to your screen using the “cat /dev/input/mice” command. Moving the mouse after running this command will cause the mouse protocol commands to be written directly to your screen (it will look like garbage). This is an easy way to see if your mouse is working properly.


To demonstrate how Linux accesses device files

Exit the X Window environment before trying these steps.

1. Type :
root@localhost root# cat /dev/mouse

2. Move your mouse around a bit. What is the result of doing this?


3. How do you return to your shell?


Created by: system. Last Modification: Tuesday 25 of November, 2008 17:36:58 EST by admin.

...