15

I am beginner in device driver programming.

I don't get the difference between device drivers and device files in Linux.

Can anyone explain the difference?

Anthon
  • 79,293
MSB
  • 153

2 Answers2

16

A device driver is a piece of software that operates or controls a particular type of device. On modern, monolithic kernel operating systems these are typically part of the kernel. Many monolithic kernels, including Linux, have a modular design, allowing for executable modules to be loaded at runtime. Device drivers commonly utilize this feature, although nothing prevents the device drivers to be compiled into the kernel image.

A device file is an interface for a device driver that appears in a file system as if it were an ordinary file. In Unix-like operating systems, these are usually found under the /dev directory and are also called device nodes. A device file can represent character devices, which emit a stream data one character at a time, or block devices which allow random access to blocks of data.

Device nodes are created by the mknod system call. The kernel resource exposed by the device node is identified by a major and minor number. Typically the major number identifies the device driver and the minor number identifies a particular device the driver controls.

What the device file appears to contain depends on what the device drivers exposes through the device file. For instance, the character device file which represents the mouse, /dev/input/mice exposes the movement of the mouse as a character stream, whereas the block device file representing a hard disk, such as /dev/sda, exposes the addressable regions of memory of the device. Some devices files also take input, allowing user-space applications to communicate with the device by writing to its device file.

Thomas Nyman
  • 30,502
  • So device file is a interface between device driver and device?? – MSB Nov 19 '13 at 13:16
  • What does device file actually contains and what does it do?? – MSB Nov 19 '13 at 13:17
  • 3
    @MSB In Unix-like operating systems "Everything is a file". In accordance to this principle, device files are the file system representation of the devices connected to the computer. Their content depends on what the device drivers exposes through them. For instance, the character device which represents the mouse, /dev/input/mice exposes the movement of the mouse as a character stream, whereas the block device representing a hard disk, such as /dev/sda1, exposes the addressable regions of memory. – Thomas Nyman Nov 19 '13 at 13:29
  • 1
    The device file is the interface between programs and the device driver. The device driver is in the kernel; the programs (applications) are in user space. The way a program can access the driver in the kernel is via the appropriate device special file. – mpez0 Nov 19 '13 at 14:55
  • Are they also called "device special files"? See https://en.wikipedia.org/wiki/Device_file#Overview – robertspierre Mar 19 '24 at 00:22
-3

adding to what Thomas Nyman said,

before using any devices, it has to be mounted onto the filesystem objects, as everything in linux is a file, some of the devices internally are automatically mounted like usb, hard disk etc.

in order for the new devices to interact with system it has device driver a software program which makes use of device file.

so basically device file provides an interface to the device driver. you can write your own device driver in linux using c.