hwapetro.blogg.se

Creating character device in linux
Creating character device in linux










creating character device in linux

What is Character Device in Linux?Ī character device is a type of storage device that holds data. The struct cdev has a field named owner, which must be set to THIS_MODULE. You must also include linux/cdev.h in your code to properly represent a character device. The mknod(2) syscall creates a new device file. The first step in creating a character device is creating a file that describes the device. You can use the struct cdev macro to create a char device, but be sure to include both the major and minor fields. Using the i_cdev field in the inode structure will give you access to the character device. The private_data field is used to store device-specific data, which can be used in read and write routines. The inode structure has more fields than the file itself, and is used internally by the kernel to represent files.












Creating character device in linux