简体   繁体   English

lm75内核模块在用户空间中可用

[英]lm75 kernel module available in userspace

I'm using the lm75 kernel module to interact with a sensor on a custom board. 我正在使用lm75内核模块与自定义板上的传感器进行交互。 Every things works fine, I have my device mounted in /sys/bus/i2c/devices/5-0048. 一切正常,我将设备安装在/ sys / bus / i2c / devices / 5-0048中。 But I would like to let the user set the max temp hysteresis so in other words let the user write into the temp_max_hyst file. 但是我想让用户设置最大温度滞后,换句话说,就是让用户写入temp_max_hyst文件。 The permission for this file is read only except for root 该文件的权限是只读的,root用户除外

My question is, is there any way to mount my device in /dev? 我的问题是,有什么方法可以在/ dev中挂载设备?

Mounting isn't the right term here so you won't find anything searching for that. 在这里安装不是正确的术语,因此您将找不到任何搜索内容。 Block devices with file systems are mounted on directories, which then become mount points . 具有文件系统的块设备安装在目录上,然后成为安装点

Here the device 5-0048 is bound to the driver lm75. 此处,设备5-0048 绑定到驱动程序lm75。 You'd find the device is there, assuming it appears in the device tree or board info, whether or not the lm75 driver exists. 假设lm75驱动程序是否存在,您就会发现该设备在那儿,假设它出现在设备树或主板信息中。 If and when the lm75 driver binds to the device, it creates a new device of class hwmon . 如果并且当lm75驱动程序绑定到设备时,它将创建类hwmon的新设备。 It is that device which has attributes , like temp_max_hyst , that you are interested in. 您感兴趣的是具有temp_max_hyst属性的设备。

What you see in /dev are known as device nodes . 您在/ dev中看到的被称为设备节点 While many devices, once bound to a driver, will have a device node created to interact with the device, this doesn't have to happen. 尽管许多设备一旦绑定到驱动程序,就会创建一个设备节点来与该设备进行交互,但这并不一定要发生。 There are probably a bunch of devices that appear in /sys/class/regulator or /sys/class/net that have no nodes in /dev associated with them. /sys/class/regulator/sys/class/net中可能出现一堆设备,在/dev中没有与之关联的节点。

Drivers of type hwmon, like lm75, don't normally create any device nodes to provide a char device or block device userspace interface to the hardware. hwmon类型的驱动程序(例如lm75)通常不会创建任何设备节点来为硬件提供char设备或块设备用户空间接口。 So there is nothing to appear in dev for this device. 因此,此设备的开发人员中没有任何内容。 The attributes of the hwmon device are all you get. 您将获得hwmon设备的属性。

But your problem has a simple solution. 但是您的问题有一个简单的解决方案。 As root, just chmod a+w temp_max_hyst or chown user_account temp_max_hyst or (this is probably best) chmod g+w temp_max_hyst ; chgrp hw_access_group temp_max_hyst 作为root用户,只需chmod a+w temp_max_hystchown user_account temp_max_hyst或(可能最好) chmod g+w temp_max_hyst ; chgrp hw_access_group temp_max_hyst chmod g+w temp_max_hyst ; chgrp hw_access_group temp_max_hyst and add the user to a group hw_access_group. chmod g+w temp_max_hyst ; chgrp hw_access_group temp_max_hyst并将用户添加到组hw_access_group中。 You could use an existing group, there might be one named wheel or adm that would be used for something like this, or make a new one just for hwmon access. 您可以使用现有的组,可能有一个名为wheeladm名称可用于此类操作,或者仅创建一个用于hwmon访问的名称。

Of course this won't persist across a reboot, as sysfs is not a real file system on disk. 当然,由于sysfs不是磁盘上的真实文件系统,因此重启后这种情况不会持续。 To make the change persistent, the best way is to create a udev rule that automatically effects the chmod/chown when it detects the hwmon device. 为了使更改持久,最好的方法是创建一个udev规则,该规则会在chmod / chown检测到hwmon设备时自动生效。 It's the hwmon device you care about here, not the i2c device. 这里是您关心的hwmon设备,而不是i2c设备。 Try running udevadm info -a /sys/class/hwmon/hwmon0 . 尝试运行udevadm info -a /sys/class/hwmon/hwmon0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM