Character device 2026-11-05
A character device is a device interface accessed through a character-special device node. In the Linux model, the node's file metadata identifies character-device type and a represented device number; the device driver defines the supported read, write and control operations. The word character does not restrict the exchanged data to readable text.[ref]
Device file metadata in the Linux man-pages project. inode(7), file types and Device ID; mknod(2), S_IFCHR
A useful concrete example is
/dev/null. Data written to it are discarded, and a read returns zero bytes to indicate end of file. /dev/zero also discards writes but supplies zero-valued bytes on reads.[ref] These two interfaces have different behaviours even though both use character-special files.For an original byte-level trace, suppose an application successfully writes the three bytes
41 00 42 to /dev/null. A later read does not return those bytes: the interface is a data sink. A read requesting three bytes from /dev/zero, if completed without interruption, instead supplies 00 00 00. The embedded zero byte in the write and zero bytes in the read are ordinary binary values, not restrictions to a text alphabet.The familiar file descriptor operations provide a common access framework, but their meanings depend on the device. A video device node can offer format negotiation and buffer controls through Video4Linux; another character device may expose a stream. Character-device type alone does not promise ordinary-file storage, a particular message boundary or a useful seek operation.
The distinction from a block device concerns the interface category. A device node is the named file system object, while the character device is the interface it represents. Several nodes can identify the same represented interface, and a pathname's inode identity does not by itself identify a distinct physical peripheral.
Device number 2026-11-05
A device number identifies a device interface using a major device number and a minor device number. In the Linux interfaces discussed here, the combined value has type
dev_t; makedev combines the two components and major and minor recover them. The documented interpretation associates the major value with a device class and the minor value with an instance within that class.[ref]A device node also has an inode number, and its containing file system has a device identity of its own. The fields
st_ino, st_dev and st_rdev therefore answer different questions: which inode, which containing device, and which represented device for a device-special file.[ref]Device file metadata in the Linux man-pages project. inode(7), Inode number, Device where inode resides and Device ID
For an original metadata comparison, stipulate two character-special nodes in one file system with inode numbers 40 and 90, each representing major 240, minor 7. They are different named file-system objects representing the same interface in this example. A third node with major 240, minor 8 represents a different minor interface. The file type remains relevant: character and block device numbers are not equated solely by matching two integers.
Combining the components is not decimal concatenation. The pairs and both become the character string
123 if their decimal spellings are joined without a separator. The structured pairs are nevertheless different. The appropriate dev_t conversion preserves their distinct components rather than imposing that ambiguous textual encoding.For valid supported component values, the intended round trips areUse the defined conversion interface rather than assuming a particular in-memory packing. The device number is an interface identifier; it is not automatically a serial number, a stable physical-device identity or the process-local file descriptor returned by opening the node.
Dynamic character-device number allocation 2026-11-05
Dynamic character-device number allocation asks the Linux kernel to reserve a range of character-device numbers while choosing its major device number at runtime. The API is
alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, const char *name). It returns zero on success or a negative error code; the first assigned combined device number is written through dev. The return status is not the allocated major number.[ref]Character-device number registration in the Linux kernel documentation. Char devices, alloc_chrdev_region, parameters and return convention
For an original request, suppose
alloc_chrdev_region(&first, 5, 3, "sample") succeeds and the returned first has major . Its reserved identifiers are , and , not . If one illustrative successful run returned major 243, the caller would use 243; another allocation can return a different major. This is a hypothetical range example, not a kernel operation executed here.Keep
first and the successful reservation count for cleanup. If a later initialization step fails, unregister_chrdev_region(first, 3) releases this reservation; it must not be treated as ownership of every minor under the returned major. Unwinding a failed character-device registration releases only resources actually acquired.Number reservation is separate from associating file operations with a live character-device object and from creating a device node. The related
cdev_add operation makes a registered object live; its name or bookkeeping label does not itself establish a pathname under /dev.[ref]Character-device number registration in the Linux kernel documentation. Char devices, cdev_add, __register_chrdev name description and unregister_chrdev_region
Removal must also respect existing users.
cdev_del prevents new opens, but already open file descriptors can still call device operations, so deleting the registration alone does not prove that backing state can be freed immediately.[ref]Character-device number registration in the Linux kernel documentation. Char devices, cdev_del lifetime note
A dynamic number is a reserved interface identifier, not a persistent hardware identity or an inode number. Linux device-number allocation 2026-11-05
Linux device-number allocation assigns or reserves the numerical identifiers through which device-special interfaces are registered. The relevant identity includes device type together with major device number and minor device number. It is distinct from naming a device node, assigning its inode number, or obtaining a process-local file descriptor.
The kernel's allocated-device list records established assignments. For example, character major 1 includes minor 3 for
/dev/null and minor 5 for /dev/zero. The same integer major 1 has a separate block-device allocation for RAM disks. These entries concern different interface namespaces, not interchangeable interpretations of a single untyped integer.[ref]Linux allocated devices in the Linux kernel documentation. Entry 1, character memory devices and block RAM disks
For character devices, the kernel API separates requesting a particular range with
register_chrdev_region from dynamic character-device number allocation with alloc_chrdev_region. The latter receives a first minor and count, chooses the major dynamically, and returns the first assigned combined device number. The caller must check whether reservation succeeded.[ref]Character-device number registration in the Linux kernel documentation. Char devices, register_chrdev_region and alloc_chrdev_region
An original allocation example requests four minor values starting at 20. If the returned major is , the reserved range in this example isIt does not contain . Code should use the returned rather than guess a major from an earlier machine or boot. A numerical allocation can serve software interfaces as well as physical hardware, so four minors do not necessarily imply four physical peripherals.
Reserving numbers is only one step. The character-device object must also be associated with its operations and added to the kernel;
cdev_add makes it live. Separately, userspace needs an appropriate device node or other naming arrangement. The registration name used for bookkeeping is not itself a pathname under /dev.[ref]Character-device number registration in the Linux kernel documentation. Char devices, cdev_init, cdev_add and __register_chrdev name description
This separation explains a common diagnostic trap. Creating a node containing a chosen major/minor pair does not reserve that range or supply a working device driver. Conversely, allocating a range does not make every invented pathname reach it. Inspect the actual registered interface, file type and stored device number together when identifying a device.
The allocation is also not a persistent hardware serial number. Dynamic assignment can differ between configurations or registration histories. Releasing a number range with
unregister_chrdev_region returns the reservation; a complete driver teardown must also handle the device object's lifetime and existing users. The kernel documentation notes that deleting a character-device object prevents new opens while operations on already open descriptors can remain possible.[ref]Character-device number registration in the Linux kernel documentation. Char devices, unregister_chrdev_region and cdev_del lifetime note
Video device node 2026-11-05
A video device node is a device node through which an application accesses a supported video or metadata interface in Video4Linux. A conventional path is
/dev/video0, but the name identifies a kernel interface rather than a persistent physical-camera identity. Device drivers register the interfaces, and applications open them to obtain file descriptors for the appropriate operations.[ref]A single hardware peripheral can expose several interfaces. Conversely, a path numbered zero can refer to different hardware after discovery order changes. The kernel documentation identifies
/dev/v4l/by-id/ and /dev/v4l/by-path/ links as alternatives for identifying devices independently of transient numbering.[ref]Opening devices and querying capabilities in the Linux Kernel video API documentation. §1.1.2, naming notes and example device links
For an original selection example, suppose cameras A and B are discovered in that order and receive paths
/dev/video0 and /dev/video1. On another boot B is discovered first, reversing those assignments. A configuration containing only /dev/video0 then selects a different camera while remaining a valid path. Identifying the intended hardware and querying the opened interface's capabilities addresses two separate questions.The returned file descriptor refers to an open instance; it is not the camera number. An application may receive descriptor 7 when opening
/dev/video0, and another application may also have a descriptor 7 referring to another object in its own descriptor table. File descriptors are local process handles, while the device path belongs to the file system namespace.Before interpreting data, query the interface with
VIDIOC_QUERYCAP and negotiate its supported pixel format. A video device node alone does not imply support for NV12M, a chosen image size or the V4L2 multi-planar API. The resulting image memory planes and video buffer payload must follow the actual negotiated interface.