{"id":9008,"date":"2022-04-12T04:13:04","date_gmt":"2022-04-12T04:13:04","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=9008"},"modified":"2023-01-16T15:37:07","modified_gmt":"2023-01-16T10:07:07","slug":"linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/","title":{"rendered":"Linux Device Driver Programming Lecture 55| Pcd driver with multiple devices code implementation part-7"},"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: 30px; border-width: 0px; line-height: 50px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>Pcd driver with multiple devices code implementation part-7<\/strong><\/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=\"font-weight: 400; color: #000000;\">In this article, let&#8217;s include a check_permission functionality to our driver. First of all, whenever the user application tries to open your device file, it actually uses open system call.<\/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;\">If you just closely observe this open system call(as shown in Figure 1), you can see that there is a field to indicate flag. What are these flags?<\/span><\/p>\n<figure id=\"attachment_9011\" aria-describedby=\"caption-attachment-9011\" style=\"width: 933px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-9011 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-1-9.png\" alt=\"Figure 1. Open system call man page check_perminssion function\" width=\"933\" height=\"428\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9.png 933w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9-300x138.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9-768x352.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9-600x275.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9-120x55.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9-500x229.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9-200x92.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9-400x183.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-1-9-800x367.png 800w\" sizes=\"(max-width: 933px) 100vw, 933px\" \/><figcaption id=\"caption-attachment-9011\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Open system call man page<\/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;\">These flags could be, as this man page says here, the argument flags must include one of the following access modes.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_9012\" aria-describedby=\"caption-attachment-9012\" style=\"width: 931px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-9012 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-2-6.png\" alt=\"Figure 2. Open system call man page check_perminssion function\" width=\"931\" height=\"438\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6.png 931w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6-300x141.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6-768x361.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6-600x282.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6-120x56.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6-500x235.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6-200x94.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6-400x188.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-2-6-800x376.png 800w\" sizes=\"(max-width: 931px) 100vw, 931px\" \/><figcaption id=\"caption-attachment-9012\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Open system call man page<\/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;\">That means the user application is going to indicate the access modes in the flags field, the access modes could be read-only, write-only, or read-write.<\/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;\">When this&nbsp; system call is issued, your driver&#8217;s open method gets called. And this access mode is supplied to your open method through the file pointer. That means if you check the struct file, a data structure. Because, as you know, that your drivers open method gets a pointer to this a struct file kernel object.<\/span><\/p>\n<figure id=\"attachment_9013\" aria-describedby=\"caption-attachment-9013\" style=\"width: 919px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"size-full wp-image-9013\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-3-5.png\" alt=\"Figure 3. Struct file\" width=\"919\" height=\"434\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5.png 919w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5-300x142.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5-768x363.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5-600x283.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5-120x57.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5-500x236.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5-200x94.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5-400x189.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-3-5-800x378.png 800w\" sizes=\"(max-width: 919px) 100vw, 919px\" \/><figcaption id=\"caption-attachment-9013\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. Struct file<\/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 a field f_mode. So, this access mode is actually stored in the field&nbsp; f_mode in the struct file kernel object.<\/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;\">That means, in your drivers open method, you should check this field.<\/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 understand how to decode this field. Remember that this is one of the fields of struct file defined in&nbsp; linux\/fs.h.<\/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=\"color: #000000;\"><span style=\"font-weight: 400;\">You can check this field in your driver to understand access mode requested from the user space application. f_mode has bit fields to indicate access modes read or write.&nbsp;<\/span><span style=\"font-weight: 400;\">In order to decode that bit fields, you have to use these macros. FMODE_READ and FMODE_WRITE.<\/span><\/span><\/p>\n<figure id=\"attachment_9014\" aria-describedby=\"caption-attachment-9014\" style=\"width: 932px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9014 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-4-5.png\" alt=\"check_perminssion function\" width=\"932\" height=\"428\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5.png 932w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5-300x138.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5-768x353.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5-600x276.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5-120x55.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5-500x230.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5-200x92.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5-400x184.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-4-5-800x367.png 800w\" sizes=\"(max-width: 932px) 100vw, 932px\" \/><figcaption id=\"caption-attachment-9014\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. FMODE_READ and FMODE_WRITE macros<\/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;\">These macros actually defined here, as shown in Figure 4. You have to use these macros. FMODE_READ and FMODE_WRITE.<\/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;\">Now, let&#8217;s see how to decode this field.<\/span><\/p>\n<figure id=\"attachment_9015\" aria-describedby=\"caption-attachment-9015\" style=\"width: 820px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9015 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-5-5.png\" alt=\"check_perminssion function\" width=\"820\" height=\"291\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5.png 820w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5-300x106.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5-768x273.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5-600x213.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5-120x43.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5-500x177.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5-200x71.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5-400x142.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5-800x284.png 800w\" sizes=\"(max-width: 820px) 100vw, 820px\" \/><figcaption id=\"caption-attachment-9015\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Decoding F_mode field<\/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;\">Suppose, in your driver, you access the file pointer, and then you get the f_mode field.&nbsp;<\/span><span style=\"font-weight: 400; color: #000000;\">You have to do a bitwise&nbsp; &amp; here. If you do bitwise &amp; with this macro, then if it is true, if the result is true, then that means the file is opened for just read or read-write. This macro checks whether the read bit is set or not in this access mode field.<\/span><\/p>\n<figure id=\"attachment_9016\" aria-describedby=\"caption-attachment-9016\" style=\"width: 804px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9016\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-6-5.png\" alt=\"Figure 6. File is opened for just read or read-write\" width=\"804\" height=\"94\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5.png 804w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5-300x35.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5-768x90.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5-600x70.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5-120x14.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5-500x58.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5-200x23.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5-400x47.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-6-5-800x94.png 800w\" sizes=\"(max-width: 804px) 100vw, 804px\" \/><figcaption id=\"caption-attachment-9016\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. File is opened for just read or read-write<\/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;\">And similarly, if you do this if you use the macro WRITE, and if you do bitwise &amp; operation with this value, then if this is true, then the file is opened for just write or read-write.<\/span><\/p>\n<figure id=\"attachment_9017\" aria-describedby=\"caption-attachment-9017\" style=\"width: 859px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9017\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-7-5.png\" alt=\"Figure 7. File is opened for just write or read-write\" width=\"859\" height=\"81\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5.png 859w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5-300x28.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5-768x72.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5-600x57.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5-120x11.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5-500x47.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5-200x19.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5-400x38.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-7-5-800x75.png 800w\" sizes=\"(max-width: 859px) 100vw, 859px\" \/><figcaption id=\"caption-attachment-9017\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. File is opened for just write or read-write<\/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=\"color: #000000;\"><span style=\"font-weight: 400;\">If you want to check exclusively for read-only, then you should be doing something like this.&nbsp;<\/span><span style=\"font-weight: 400;\">First, check whether it is opened for read. If this is true and you have to use here logical &amp;&amp; &nbsp; and it shouldn&#8217;t be open for&nbsp; WRITE. That&#8217;s why this field must be false.<\/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; color: #000000;\">So, if this is false and the negation of false becomes true. Then only you can conclude that the file is opened for read-only.<\/span><\/p>\n<figure id=\"attachment_9018\" aria-describedby=\"caption-attachment-9018\" style=\"width: 672px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-9018\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-8-5.png\" alt=\"Figure 8. File is opened for read-only\" width=\"672\" height=\"134\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-5.png 672w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-5-300x60.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-5-600x120.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-5-120x24.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-5-500x100.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-5-669x134.png 669w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-5-200x40.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-8-5-400x80.png 400w\" sizes=\"(max-width: 672px) 100vw, 672px\" \/><figcaption id=\"caption-attachment-9018\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. File is opened for read-only<\/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=\"color: #000000;\"><span style=\"font-weight: 400;\">I hope you get this logic.&nbsp; The same logic we are going to use in our check_permission function.&nbsp;<\/span><span style=\"font-weight: 400;\">Let&#8217;s get back to our editor, and let&#8217;s start coding. Now, let&#8217;s implement this check_permission. For this function.<\/span><\/span><\/p>\n<figure id=\"attachment_9019\" aria-describedby=\"caption-attachment-9019\" style=\"width: 755px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9019 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-9-5.png\" alt=\"Implementation of check_permission()\" width=\"755\" height=\"323\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-5.png 755w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-5-300x128.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-5-600x257.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-5-120x51.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-5-500x214.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-5-200x86.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-9-5-400x171.png 400w\" sizes=\"(max-width: 755px) 100vw, 755px\" \/><figcaption id=\"caption-attachment-9019\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 9. Implementation of check_permission()<\/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=\"color: #000000;\"><span style=\"font-weight: 400;\">I&#8217;m going to pass two arguments. One is device&nbsp; permission_field. So, that I can get by&nbsp;&nbsp;<\/span><span style=\"font-weight: 400;\">pcdev_data-&gt;perm field. And after that, I&#8217;m going to pass another argument that is&nbsp;<\/span><span style=\"font-weight: 400;\">the f_mode field of the file pointer.<\/span><\/span><\/p>\n<figure id=\"attachment_9020\" aria-describedby=\"caption-attachment-9020\" style=\"width: 755px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9020 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-10-3.png\" alt=\"Passing two argument to the check_perminssion function\" width=\"755\" height=\"363\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-3.png 755w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-3-300x144.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-3-600x288.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-3-120x58.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-3-500x240.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-3-200x96.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-10-3-400x192.png 400w\" sizes=\"(max-width: 755px) 100vw, 755px\" \/><figcaption id=\"caption-attachment-9020\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 10. Passing two argument to the check_perminssion<\/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;\">Let&#8217;s go to the check_permission, which is right here. And let&#8217;s create some receiving variables, I call it as dev_perm, and I would call it as mode, or access mode, or something. acc _mode. What are our device permissions? Read-only, write-only, and read-write. Let&#8217;s create some macros to define that. #define, let me create one macro&nbsp; RDONLY, and the value is 0x1. Just assumed values, you can give whatever you want. WRONLY 0x10. And #define RDWR 0x11<\/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 me cut this code, and I would paste here. We would have created these macros when we initialized this structure. Here, in the permission field, let&#8217;s use those macros.&nbsp; RDONLY, this is WRONLY, and this is RDWR.<\/span><\/p>\n<figure id=\"attachment_9021\" aria-describedby=\"caption-attachment-9021\" style=\"width: 753px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9021 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-11-3.png\" alt=\"Implementation of check_permission()\" width=\"753\" height=\"595\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-3.png 753w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-3-300x237.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-3-600x474.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-3-120x95.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-3-500x395.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-3-200x158.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-11-3-400x316.png 400w\" sizes=\"(max-width: 753px) 100vw, 753px\" \/><figcaption id=\"caption-attachment-9021\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 11. Creating a macro RDONLY,WRONLY and RDWR<\/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;\">Let&#8217;s get back to the function. First, you have to check. If the device permission is, if it is read-write, then you need not to check the access mode. Just return 0.<\/span><\/p>\n<figure id=\"attachment_9022\" aria-describedby=\"caption-attachment-9022\" style=\"width: 757px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-9022 size-full\" src=\"https:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/04\/Figure-12-3.png\" alt=\"check_permission function\" width=\"757\" height=\"377\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-3.png 757w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-3-300x149.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-3-600x299.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-3-120x60.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-3-500x249.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-3-200x100.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-12-3-400x199.png 400w\" sizes=\"(max-width: 757px) 100vw, 757px\" \/><figcaption id=\"caption-attachment-9022\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 12. Check_permission function<\/span><\/figcaption><\/figure>\n<p class=\"\" 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;\">if(dev_perm == RDONLY), then you have to check the access mode. Let me write like this. if(dev_perm== RDONLY) and logical &amp;&amp;. So, you have to use the access mode, acc_mode, decode it. Decode with a FMODE_READ. If this is true, and you have to use one more logical &amp;&amp;. The write bit field should be 0. You should confirm that. Because this is only for read-only.&nbsp;<\/span><span style=\"font-weight: 400;\">And acc_mode. Check for write field, FMODE_WRITE. This becomes a complex comparison.&nbsp;<\/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; color: #000000;\">So, let&#8217;s do one thing. Let&#8217;s put this in a separate parenthesis.&nbsp;&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=\"color: #000000;\"><span style=\"font-weight: 400;\">Let me explain once again.&nbsp; if(dev_perm == RDONLY) &amp;&amp; if the file is opened for read&nbsp;<\/span><span style=\"font-weight: 400;\">and if the file is not opened for write. That you should confirm. That&#8217;s why I should use&nbsp;<\/span><span style=\"font-weight: 400;\">Negation. So, if the file is not opened for write, then negation of that would become true, then we can confirm that this is the read-only access. If this whole statement is true, then we just return 0.<\/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=\"color: #000000;\"><span style=\"font-weight: 400;\">And similarly, you have to do it for write-only. Let me copy these two. Let&#8217;s do for write-only.&nbsp;<\/span><span style=\"font-weight: 400;\">If the device permission&nbsp; is write-only, and access mode&nbsp; compare with write and make sure that it is not opened for read. So, this ensures read-only access. Otherwise, just return -EPERM.<\/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=\"color: #000000;\"><span style=\"font-weight: 400;\">This would be our check_permission function, and with this change, we are ready to test now.&nbsp;<\/span><span style=\"font-weight: 400;\">First of all, let&#8217;s confirm whether this builds or not. Complete up to here and in the next article, let&#8217;s test it. I&#8217;ll see you in the next article.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 20px; line-height: 25px;\" 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; Pcd driver with multiple devices code implementation part-7 &nbsp; &nbsp; In this article, let&#8217;s include a check_permission functionality to our driver. First of all, whenever the user application tries to open your device file, it actually uses open system call. If you just closely observe this open system call(as shown in Figure 1), you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9015,"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-9008","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>Pcd driver with multiple devices code implementation part-7<\/title>\n<meta name=\"description\" content=\"Pcd driver with multiple devices code implementation part-7. Let&#039;s include a check_permission function to our driver. Open system call\" \/>\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\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pcd driver with multiple devices code implementation part-7\" \/>\n<meta property=\"og:description\" content=\"Pcd driver with multiple devices code implementation part-7. Let&#039;s include a check_permission function to our driver. Open system call\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/\" \/>\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-04-12T04:13:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-16T10:07:07+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5.png\" \/>\n\t<meta property=\"og:image:width\" content=\"820\" \/>\n\t<meta property=\"og:image:height\" content=\"291\" \/>\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\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Linux Device Driver Programming Lecture 55| Pcd driver with multiple devices code implementation part-7\",\"datePublished\":\"2022-04-12T04:13:04+00:00\",\"dateModified\":\"2023-01-16T10:07:07+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/\"},\"wordCount\":1237,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-5-5.png\",\"keywords\":[\"Linux Device Driver Programming Tutorial\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/\",\"name\":\"Pcd driver with multiple devices code implementation part-7\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-5-5.png\",\"datePublished\":\"2022-04-12T04:13:04+00:00\",\"dateModified\":\"2023-01-16T10:07:07+00:00\",\"description\":\"Pcd driver with multiple devices code implementation part-7. Let's include a check_permission function to our driver. Open system call\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-5-5.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/Figure-5-5.png\",\"width\":820,\"height\":291,\"caption\":\"Figure 5. Decoding F_mode field\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Linux Device Driver Programming Lecture 55| Pcd driver with multiple devices code implementation part-7\"}]},{\"@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":"Pcd driver with multiple devices code implementation part-7","description":"Pcd driver with multiple devices code implementation part-7. Let's include a check_permission function to our driver. Open system call","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\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/","og_locale":"en_US","og_type":"article","og_title":"Pcd driver with multiple devices code implementation part-7","og_description":"Pcd driver with multiple devices code implementation part-7. Let's include a check_permission function to our driver. Open system call","og_url":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-04-12T04:13:04+00:00","article_modified_time":"2023-01-16T10:07:07+00:00","og_image":[{"width":820,"height":291,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5.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\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Linux Device Driver Programming Lecture 55| Pcd driver with multiple devices code implementation part-7","datePublished":"2022-04-12T04:13:04+00:00","dateModified":"2023-01-16T10:07:07+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/"},"wordCount":1237,"commentCount":0,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5.png","keywords":["Linux Device Driver Programming Tutorial"],"articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/","url":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/","name":"Pcd driver with multiple devices code implementation part-7","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5.png","datePublished":"2022-04-12T04:13:04+00:00","dateModified":"2023-01-16T10:07:07+00:00","description":"Pcd driver with multiple devices code implementation part-7. Let's include a check_permission function to our driver. Open system call","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/04\/Figure-5-5.png","width":820,"height":291,"caption":"Figure 5. Decoding F_mode field"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/linux-device-driver-programming-lecture-55-pcd-driver-with-multiple-devices-code-implementation-part-7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Linux Device Driver Programming Lecture 55| Pcd driver with multiple devices code implementation part-7"}]},{"@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\/9008","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=9008"}],"version-history":[{"count":5,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/9008\/revisions"}],"predecessor-version":[{"id":13638,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/9008\/revisions\/13638"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/9015"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=9008"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=9008"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=9008"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}