{"id":7580,"date":"2022-02-18T11:03:30","date_gmt":"2022-02-18T11:03:30","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=7580"},"modified":"2023-02-07T17:12:34","modified_gmt":"2023-02-07T11:42:34","slug":"character-device-registration","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/","title":{"rendered":"Linux Device Driver Programming Lecture 31- Character device registration"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 31px; border-width: 0px; line-height: 50px;\"><span style=\"font-weight: 400; color: #000080;\"><b>Character device registration<\/b><\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">In our previous article, We finished our very first task, that is creating a device&nbsp;<\/span><span style=\"font-weight: 400;\">number (as shown in Figure 1).<\/span><\/span><\/p>\n<figure id=\"attachment_7583\" aria-describedby=\"caption-attachment-7583\" style=\"width: 702px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"size-full wp-image-7583\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-1-20.png\" alt=\"Figure 1.Kernel APIs and utilities to be used in driver code\" width=\"702\" height=\"262\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20.png 702w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20-300x112.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20-600x224.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20-120x45.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20-500x187.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20-700x262.png 700w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20-200x75.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20-400x149.png 400w\" sizes=\"(max-width: 702px) 100vw, 702px\" \/><figcaption id=\"caption-attachment-7583\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Kernel APIs and utilities to be used in driver code<\/span><\/figcaption><\/figure>\n<p>&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s go to our next step that is we have to now do a character device registration. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">How many devices are we handling? <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">There&#8217;s only one device. One pseudo character device. That&#8217;s why you have to call cdev_add() one time. That would make a character device registration with a VFS. This registration is very important. Otherwise, the user-level system calls will not get connected to the file operation methods of the driver. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">As you may be guessing, for this cdev_add(), you have to mention the driver&#8217;s file operation methods. With that, you have to register. We have to use cdev_init() and cdev_add().<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s first explore a what is cdev_init. cdev_init is used to initialize a cdev structure(Figure 2).<\/span><\/p>\n<figure id=\"attachment_7605\" aria-describedby=\"caption-attachment-7605\" style=\"width: 577px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\" wp-image-7605\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-2-24.png\" alt=\"Figure 2. Initializing a cdev structure\" width=\"577\" height=\"199\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-24.png 774w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-24-300x103.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-24-768x265.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-24-600x207.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-24-120x41.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-24-500x172.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-24-200x69.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-2-24-400x138.png 400w\" sizes=\"(max-width: 577px) 100vw, 577px\" \/><figcaption id=\"caption-attachment-7605\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Initializing a cdev structure<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">It has got two input arguments. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Look at the second argument. That is a file_operations. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">By using this pointer, you have to mention your driver&#8217;s file operation methods or system call handler&#8217;s Like system call handlers for open, read, write, seek, etc. This is a cdev structure. <\/span><span style=\"font-weight: 400; color: #000000;\">Here you have to pass a pointer to a cdev structure. Since we are handling only one device, we should create a one variable of type struct cdev.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_7584\" aria-describedby=\"caption-attachment-7584\" style=\"width: 739px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-7584\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-3-20.png\" alt=\"Figure 3.Example\" width=\"739\" height=\"309\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-20.png 739w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-20-300x125.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-20-600x251.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-20-120x50.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-20-500x209.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-20-200x84.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-3-20-400x167.png 400w\" sizes=\"(max-width: 739px) 100vw, 739px\" \/><figcaption id=\"caption-attachment-7584\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Example<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here is an example, as shown in Figure 3. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You have to create two variables. Let&#8217;s say, eeprom_fops. This is a variable of type struct file operations. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">After that, you have to initialize this file operation variable with your driver&#8217;s file operation methods. You have to populate the function pointers of your driver&#8217;s file operation methods. <\/span><span style=\"font-weight: 400; color: #000000;\">And after that, you have to create one more variable, that is, a cdev variable.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\"> For example, here, I have created eeprom_cdev. This is a variable of type struct cdev. If you are managing a 10 devices, then you may have to create 10 cdev variables. But, in this case, we are handling only one device, I would create only the cdev variable. And then, by using cdev_init, you have to pass the pointers of those a variables.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, now the cdev_init is a kernel API, which is implemented in char_dev.c.<\/span><\/p>\n<figure id=\"attachment_7585\" aria-describedby=\"caption-attachment-7585\" style=\"width: 774px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7585\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-4-17.png\" alt=\"Figure 4. cdev_init\" width=\"774\" height=\"359\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-4-17.png 774w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-4-17-300x139.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-4-17-768x356.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-4-17-600x278.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-4-17-120x56.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-4-17-500x232.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-4-17-200x93.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-4-17-400x186.png 400w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><figcaption id=\"caption-attachment-7585\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. cdev_init<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And this is what it does. You can see here cdev has a field called &#8216;ops&#8217;, that is, operations. And cdev_init() function just initializes that field to this pointer what you send here.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_7586\" aria-describedby=\"caption-attachment-7586\" style=\"width: 695px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7586\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-5-15.png\" alt=\"Figure 5. Cdev structure\" width=\"695\" height=\"368\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-5-15.png 695w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-5-15-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-5-15-600x318.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-5-15-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-5-15-500x265.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-5-15-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-5-15-400x212.png 400w\" sizes=\"(max-width: 695px) 100vw, 695px\" \/><figcaption id=\"caption-attachment-7586\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Cdev structure<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">This is a cdev structure, actually. You can see that the cdev structure has this field &#8216;ops&#8217;. This is a pointer to the file operation structure of the driver. So, the cdev_init() just initializes this field.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And after that, in this cdev structure, you have to initialize one more field, that is module owner field. This field should be initialized with a pointer to the module that owns this structure. It should usually be initialized to a macro called this module. This field is used to prevent a module from being unloaded while the structure is still in use. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s see, what is this THIS_MODULE macro. So, THIS_MODULE is a macro which resolves into &#8220;pointer to a struct module variable, which corresponds to our current module&#8221;.<\/span><\/p>\n<figure id=\"attachment_7587\" aria-describedby=\"caption-attachment-7587\" style=\"width: 409px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-7587\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-6-12.png\" alt=\"Figure 6.THIS_MODULE\" width=\"409\" height=\"190\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-6-12.png 409w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-6-12-300x139.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-6-12-120x56.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-6-12-200x93.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-6-12-400x186.png 400w\" sizes=\"(max-width: 409px) 100vw, 409px\" \/><figcaption id=\"caption-attachment-7587\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6.THIS_MODULE<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Basically, this *owner field in cdev structure is used to identify the current module, which owns this structure. You can find this macro in <\/span><b>linux\/export.h<\/b><span style=\"font-weight: 400;\">. Look at that macro. That macro is nothing but an address. So, an address to this variable of type struct module.<\/span><\/span><\/p>\n<figure id=\"attachment_7588\" aria-describedby=\"caption-attachment-7588\" style=\"width: 802px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7588 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-7-9.png\" alt=\"Character device registration\" width=\"802\" height=\"424\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9.png 802w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9-300x159.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9-768x406.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9-600x317.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9-120x63.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9-500x264.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9-400x211.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-7-9-800x423.png 800w\" sizes=\"(max-width: 802px) 100vw, 802px\" \/><figcaption id=\"caption-attachment-7588\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. command nm main.ko<\/span><\/figcaption><\/figure>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\">&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">If you go back to our earlier project, that is hello_world. Here, let&#8217;s run the nm command to read all the symbols of the final kernel module, that is, main.ko. You see here __this_module, this is actually a variable of type struct module. We didn&#8217;t use this variable.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\"> Who added it? <\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">This gets added when we compile our kernel module. So, the build system adds this a variable.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If you want to see that, you can open main.mod.c. Just open main.mod.c as shown in Figure 8, and here it is.<\/span><\/p>\n<figure id=\"attachment_7589\" aria-describedby=\"caption-attachment-7589\" style=\"width: 613px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7589 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-8-7.png\" alt=\"Character device registration\" width=\"613\" height=\"340\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-8-7.png 613w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-8-7-300x166.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-8-7-600x333.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-8-7-120x67.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-8-7-500x277.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-8-7-200x111.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-8-7-400x222.png 400w\" sizes=\"(max-width: 613px) 100vw, 613px\" \/><figcaption id=\"caption-attachment-7589\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Open main.mod.c<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">The build system added this variable. Basically, what you are doing is, you are just assigning the address of this variable to the owner field. Whenever you use any kernel data structure such as cdev or&nbsp; file operations, and you see the owners field, then you should initialize that field to the macro, that is THIS_MODULE.<\/span><\/p>\n<figure id=\"attachment_7590\" aria-describedby=\"caption-attachment-7590\" style=\"width: 730px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7590 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-9-6.png\" alt=\"Character device registration\" width=\"730\" height=\"334\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-9-6.png 730w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-9-6-300x137.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-9-6-600x275.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-9-6-120x55.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-9-6-500x229.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-9-6-200x92.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-9-6-400x183.png 400w\" sizes=\"(max-width: 730px) 100vw, 730px\" \/><figcaption id=\"caption-attachment-7590\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. File operation structure<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We actually explore the cdev structure. Let&#8217;s look at file operation structure(shown in Figure 9) . The file operation structure, this structure definition you can find in linux\/fs.h.VFS file operation structure and it has various member elements. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Basically, all are function pointer variables. All these function pointer variables needs to be initialized with your drivers a file operation methods. We will not be using all the member elements here. So, we will be using open, read, write, and lseek for this exercise.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And look at the first member elements, that is, struct module owner. This again needs to be initialized with the macro THIS_MODULE. Now, let&#8217;s get back to the driver file.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">We have to use cdev_init(). Let&#8217;s create two variables, as shown in Figure 10.<\/span><\/p>\n<figure id=\"attachment_7591\" aria-describedby=\"caption-attachment-7591\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7591 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-10-6.png\" alt=\"Character device registration\" width=\"800\" height=\"452\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-10-6.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-10-6-300x170.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-10-6-768x434.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-10-6-600x339.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-10-6-120x68.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-10-6-500x283.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-10-6-200x113.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-10-6-400x226.png 400w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><figcaption id=\"caption-attachment-7591\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Create two variable and include header files<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s create cdev variable. struct cdev,&nbsp; let me call it as pcd pseudo character device cdev. After that, file operations of the driver. For this struct file_operations&nbsp; pcd_fops. We have to initialize this file operations a variable. Let&#8217;s do that in a moment, don&#8217;t worry. <\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">And now, let&#8217;s include the appropriate header files. The header files we should be using is cdev.h. For the cdev we have to use&nbsp; #include &lt;linux\/cdev.h&gt; and for the file operation it is fs.h.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">After that, let&#8217;s finish our cdev_init(). So, it needs address of cdev structure. That is pcd_cdev, and address of our file operations, pcd_fops. So, this is our second step. And you also know that our cdev structure has owner field. right? that needs to be initialized. So, we forgot that.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Let&#8217;s do that. pcd_cdev.owner=THIS_MODULE as Figure 11.<\/span><\/p>\n<figure id=\"attachment_7592\" aria-describedby=\"caption-attachment-7592\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-7592 size-full\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/02\/Figure-11-5.png\" alt=\"Character device registration\" width=\"800\" height=\"419\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-11-5.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-11-5-300x157.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-11-5-768x402.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-11-5-600x314.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-11-5-120x63.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-11-5-500x262.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-11-5-200x105.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-11-5-400x210.png 400w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><figcaption id=\"caption-attachment-7592\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 11. Initialize the cdev structure with fops<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You can do that here.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 20px; line-height: 25px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\">lick here:&nbsp;<\/span><\/span><span style=\"color: #3366ff;\"><a style=\"color: #3366ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Character device registration &nbsp; &nbsp; In our previous article, We finished our very first task, that is creating a device&nbsp;number (as shown in Figure 1). &nbsp; Let&#8217;s go to our next step that is we have to now do a character device registration. How many devices are we handling? There&#8217;s only one device. One [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":7583,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[18],"class_list":["post-7580","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-linux-device-driver-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Character device registration | Linux Device Driver Programming<\/title>\n<meta name=\"description\" content=\"Character device registration. How many devices are we handling? There&#039;s only one device. One pseudo character device. cdev_add()\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/character-device-registration\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Character device registration | Linux Device Driver Programming\" \/>\n<meta property=\"og:description\" content=\"Character device registration. How many devices are we handling? There&#039;s only one device. One pseudo character device. cdev_add()\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/character-device-registration\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-02-18T11:03:30+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-07T11:42:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20.png\" \/>\n\t<meta property=\"og:image:width\" content=\"702\" \/>\n\t<meta property=\"og:image:height\" content=\"262\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Linux Device Driver Programming Lecture 31- Character device registration\",\"datePublished\":\"2022-02-18T11:03:30+00:00\",\"dateModified\":\"2023-02-07T11:42:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/\"},\"wordCount\":1226,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Figure-1-20.png\",\"keywords\":[\"Linux Device Driver Programming Tutorial\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/\",\"name\":\"Character device registration | Linux Device Driver Programming\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Figure-1-20.png\",\"datePublished\":\"2022-02-18T11:03:30+00:00\",\"dateModified\":\"2023-02-07T11:42:34+00:00\",\"description\":\"Character device registration. How many devices are we handling? There's only one device. One pseudo character device. cdev_add()\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Figure-1-20.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/Figure-1-20.png\",\"width\":702,\"height\":262,\"caption\":\"Figure 1.Kernel APIs and utilities to be used in driver code\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/character-device-registration\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Device Driver Programming Lecture 31- Character device registration\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Character device registration | Linux Device Driver Programming","description":"Character device registration. How many devices are we handling? There's only one device. One pseudo character device. cdev_add()","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/","og_locale":"en_US","og_type":"article","og_title":"Character device registration | Linux Device Driver Programming","og_description":"Character device registration. How many devices are we handling? There's only one device. One pseudo character device. cdev_add()","og_url":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-02-18T11:03:30+00:00","article_modified_time":"2023-02-07T11:42:34+00:00","og_image":[{"width":702,"height":262,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Linux Device Driver Programming Lecture 31- Character device registration","datePublished":"2022-02-18T11:03:30+00:00","dateModified":"2023-02-07T11:42:34+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/"},"wordCount":1226,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20.png","keywords":["Linux Device Driver Programming Tutorial"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/character-device-registration\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/","url":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/","name":"Character device registration | Linux Device Driver Programming","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20.png","datePublished":"2022-02-18T11:03:30+00:00","dateModified":"2023-02-07T11:42:34+00:00","description":"Character device registration. How many devices are we handling? There's only one device. One pseudo character device. cdev_add()","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/character-device-registration\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/02\/Figure-1-20.png","width":702,"height":262,"caption":"Figure 1.Kernel APIs and utilities to be used in driver code"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/character-device-registration\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux Device Driver Programming Lecture 31- Character device registration"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7580","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=7580"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7580\/revisions"}],"predecessor-version":[{"id":11272,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/7580\/revisions\/11272"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/7583"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=7580"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=7580"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=7580"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}