您的位置:首页 > 运维架构 > Linux

how to change the default mode of a linux device

2013-09-12 10:05 671 查看
加载完你自己开发的设备驱动之后,生成的设备在用户空间往往需要以root方式才能访问,这样在用gui程序进行设备访问之前,必须改变设备的权限(chmod),或者所属用户和组(chown),gui程序才能有权限去打开那个设备,或者就需要在终端中将GUI程序以sudo方式运行,这样稍显麻烦,下面介绍一种直接修改生成设备默认属性的方式实现。

在/etc/udev/rules.d目录下创建规则文件10-myrule.rules

文件内容如下:

KERNEL=="pdusb0", NAME="pdusb0", MODE="0777"

其中KERNEL是匹配键,NAME和MODE是赋值键。

重新插上设备,出现设备pdusb0,权限为777,用户空间app能顺利访问该设备

参考文章:

udev has rules for permissions, you need to create them under
/etc/udev/rules.d


First try this:

In the file
/etc/udev/udev.conf
,
add this line:
# My default permissions
default_mode="0660"


If this doesn't work add a rule in /etc/udev/rules.d, more on that here :http://www.reactivated.net/writing_udev_rules.html

http://stackoverflow.com/questions/11846594/how-can-i-programmatically-set-permissions-on-my-char-device
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: