how to change the default mode of a linux device

来源:互联网 发布:学唱歌入门教程软件 编辑:程序博客网 时间:2024/05/18 02:31

加载完你自己开发的设备驱动之后,生成的设备在用户空间往往需要以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 permissionsdefault_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)