1

Folks, i wrote a char driver for my i2c device. It is working on Android 4.0.3 using Linux kernel 3.0.8.

When I try to access the driver using ioctl() with my native Android app. I get a permission denied error.

If I create the device file using the following command I don't get the permission error.

mknod /dev/barcodescan c 100 0

I don't want to have to manually issue this command all the time but instead that the module does it on startup. I wrote the following code but I get a permission denied error. How can I setup permission in this code?

ret= register_chrdev(MAJOR_NUMBER,"barcode",&fops );

if(ret) {   
   pr_info(KERN_ERR "%s:register chrdev failed\n",__FILE__);    
   return ret;
}

i2c_dev_class = class_create(THIS_MODULE,"barcode");

if (IS_ERR(i2c_dev_class)) {        
   ret = PTR_ERR(i2c_dev_class);        
   class_destroy(i2c_dev_class);    
}

1 Answers1

1

I assume that you are building your own Android image.

In that case, you need to edit init.rc to add lines like this to make sure that your device node is automatically created at boot:

mknod /dev/barcodescan c 100 0
chown system system /dev/barcodescan

You may want to change system:system to some other account and/or add more permissions with chmod, for example using chmod 666, but this is not recommended.

mvp
  • 111,019
  • 13
  • 122
  • 148