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?
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?
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.
/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
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.