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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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.
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.