Difference between Device file and device drivers

23,690

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.

Share:
23,690
MSB
Author by

MSB

Updated on September 18, 2022

Comments

  • MSB
    MSB over 1 year

    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?

  • MSB
    MSB over 10 years
    So device file is a interface between device driver and device??
  • MSB
    MSB over 10 years
    What does device file actually contains and what does it do??
  • Thomas Nyman
    Thomas Nyman over 10 years
    @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.
  • mpez0
    mpez0 over 10 years
    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.