Linux中的设备节点访问权限 [英] Device node access permissions in Linux

查看:1024
本文介绍了Linux中的设备节点访问权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为嵌入式android编写char设备驱动程序. 设备模块将自身注册为char设备,并在/dev下创建相应的设备节点.问题是此设备的访问权限是root用户,我无法从android应用程序(JNI)读取它.在运行应用程序之前,我必须手动"chmod + r"设备.如何确定动态创建的设备节点的访问权限?

I'm writing a char device driver for embedded android. The device module, register itself as a char device, and a corresponding device node is created under /dev . The problem is that the access permissions for this device is for root, and I can't read it from android applications (JNI). I have to manually "chmod +r" the device before running the application. How can I decide the access permission of a dynamically created device node ?

推荐答案

如果您的设备使用管理该设备上的权限.

If your device registers itself using udev, which is the most likely case, then you can create a custom udev rule to manage the permissions on this device.

例如,此规则将rw-rw-rw-权限分配给属于USB供应商0bb4的设备:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"

For example, this rule assigns rw-rw-rw- permissions to a device belonging to the USB vendor 0bb4:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"

这篇关于Linux中的设备节点访问权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆