Create a character device-driven process in the dev directory

Source: Internet
Author: User

1.struct file_operations character Device file interface

   1:  staticint mpu_open (structstruct file *file)
   2:  {    
   3:      return 0;
   4:  }
   5:  
   6:  
   7:  
   8:  staticint mpu_close (structstruct file *file)
   9:  {
  Ten:      return 0;
One   :  }
  :  
  :  
A   :  staticlongstructintlong Arg)
  :  {
+   :      return 0;
  :  }
  :  
  :  static ssize_t mpu_read (structchar __user *buffer, size_t size, loff_t *off)
  :  {
  :      return 0;
  :  }
At   :  
  :  static ssize_t mpu_write (structconstchar __ User *buffer, size_t size, loff_t *off)
  :  {
  :      return 0;
  :  }
Structure
   1:  struct file_operations mpu_ops = {
   2:      . Owner =  This_module,
   3:      . Open =   Mpu_open,
   4:      . unlocked_ioctl =  Mpu_ioctl,
   5:      
   6:      . Read = Mpu_read,
   7:      . Write = Mpu_write,
   8:  };
2. Registering the character device framework with the kernel
   1:  //register character device  according to device number and device name
   2:      "Dt-mpu", &mpu_ops);   
   3:      if (Ret < 0) {  
   4:          PRINTK ("Unable to register character device%d!\n", 253);  
   5:          return ret;  
   6:      }  
3. Register a class under/sys/class
   1:  "Dt-mpu"
   2:      if (!mcls) {
   3:          printk ("class_create dt-mpu failure...\n");
   4:          goto un_register;
   5:      }

4. Create a Dt-mpu device file in the/dev/directory

//Create a device node with the node named Device_name    "Dt-mpu");    if (!dev) {        PRINTK ("device_create dt-mpu failure...\n");        goto des_class;    }

Create a character device-driven process in the dev directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.