AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题

问题[sysfs](unix)

Martin Hope
Seamus
Asked: 2024-06-03 12:56:30 +0800 CST

为什么这个文件夹在“sysfs”中重复?

  • 6

我有一个运行“书虫”版本操作系统的 Raspberry Pi;操作系统的 64 位版本(如果有什么区别的话)。我已经安装了 SHT3X 温度和湿度传感器之一,它显然工作正常。它通过 I2C 接口(我相信是通道 0)连接/dev/i2c-0。我可以从文件中读取温度和湿度sysfs;我相信传感器工作正常。

我发现其中有两个相同的文件夹,sysfs其中包含 SHT3X 设备的相同输出和控制文件:

文件夹 1:/sys/devices/platform/soc/3f205000.i2c/i2c-0/0-0044/hwmon/hwmon2

$ ls -l
total 0
lrwxrwxrwx 1 root root    0 Jun  2 21:55 device -> ../../../0-0044
-rw-r--r-- 1 root root 4096 Jun  2 21:55 heater_enable
-r--r--r-- 1 root root 4096 Jun  2 21:55 humidity1_alarm
-r--r--r-- 1 root root 4096 Jun  2 21:55 humidity1_input
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_max
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_max_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_min
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_min_hyst
-r--r--r-- 1 root root 4096 Jun  2 21:55 name
lrwxrwxrwx 1 root root    0 Jun  2 21:55 of_node -> ../../../../../../../../firmware/devicetree/base/soc/i2c@7e205000/sht3x@44
drwxr-xr-x 2 root root    0 Jun  2 21:55 power
-rw-r--r-- 1 root root 4096 Jun  2 21:55 repeatability
lrwxrwxrwx 1 root root    0 Jun  2 21:55 subsystem -> ../../../../../../../../class/hwmon
-r--r--r-- 1 root root 4096 Jun  2 21:55 temp1_alarm
-r--r--r-- 1 root root 4096 Jun  2 21:55 temp1_input
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_max
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_max_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_min
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_min_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:52 uevent
-rw-r--r-- 1 root root 4096 Jun  2 21:55 update_interval

文件夹2:/sys/class/hwmon/hwmon2

$ ls -l
total 0
lrwxrwxrwx 1 root root    0 Jun  2 21:55 device -> ../../../0-0044
-rw-r--r-- 1 root root 4096 Jun  2 21:55 heater_enable
-r--r--r-- 1 root root 4096 Jun  2 21:55 humidity1_alarm
-r--r--r-- 1 root root 4096 Jun  2 21:55 humidity1_input
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_max
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_max_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_min
-rw-r--r-- 1 root root 4096 Jun  2 21:55 humidity1_min_hyst
-r--r--r-- 1 root root 4096 Jun  2 21:55 name
lrwxrwxrwx 1 root root    0 Jun  2 21:55 of_node -> ../../../../../../../../firmware/devicetree/base/soc/i2c@7e205000/sht3x@44
drwxr-xr-x 2 root root    0 Jun  2 21:55 power
-rw-r--r-- 1 root root 4096 Jun  2 21:55 repeatability
lrwxrwxrwx 1 root root    0 Jun  2 21:55 subsystem -> ../../../../../../../../class/hwmon
-r--r--r-- 1 root root 4096 Jun  2 21:55 temp1_alarm
-r--r--r-- 1 root root 4096 Jun  2 21:55 temp1_input
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_max
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_max_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_min
-rw-r--r-- 1 root root 4096 Jun  2 21:55 temp1_min_hyst
-rw-r--r-- 1 root root 4096 Jun  2 21:52 uevent
-rw-r--r-- 1 root root 4096 Jun  2 21:55 update_interval

还有更多;例如:

文件夹 3:/sys/devices/platform/soc/3f205000.i2c/i2c-0/0-0044/hwmon/hwmon2/subsystem/hwmon2

我意识到涉及符号链接,但是这些文件是否有真实/不可变的sysfs位置?我读过一些关于sysfs 1、2 的参考文献,但没有发现对这种明显重复的解释。有人可以解释一下明显的冗余,以及文件是否有不可变的位置吗?

sysfs
  • 1 个回答
  • 25 Views
Martin Hope
Peter Du
Asked: 2024-04-26 08:25:12 +0800 CST

sysfs 中的数字是以十进制还是十六进制表示的?

  • 5

我正在查看 sysfs 中的文件,特别是/sys/bus/usb/devices

文件包含小数字,表示为两个字符,例如“00”

我的所有示例都包含“09”或更低的数字。

我正在编写一个脚本来解释这些,我不清楚我是否应该期望“0A”或“10”作为下一个值(即,它是十进制还是十六进制?)

我已经看到这些是内核 kobject 的视图,但我无法找到它们序列化的来源。

您能否告诉我这些数字(例如,bInterfaceNumber 中的数字)是十进制还是十六进制,还是根据具体情况而变化。如果确实有所不同,我可以在源代码中的哪个位置检查 sysfs 中的特定文件?

如果相关的话,我的电脑主要是 Ubuntu,20.04 和 22.04 的混合体。我查看了usb-devices脚本作为比较点,版本之间发生了变化,这让我对它想要做什么不太有信心。

sysfs
  • 1 个回答
  • 25 Views
Martin Hope
dcom-launch
Asked: 2022-02-02 10:35:20 +0800 CST

有什么方法可以使 sysfs 文件不可变?

  • 2

我试图让/sys/fs/selinux/enforce总是包含“1”,并防止它被改变。

我已经能够/etc/selinux/config通过运行来做到这一点chattr +i /etc/selinux/config

但是,当我在 selinux sysfs 中的文件上尝试此操作时,出现以下错误:

chattr: Inappropriate ioctl for device while reading flags on /sys/fs/selinux/enforce

我假设这是由于 sysfs 文件与实际文件不同。

任何已知的方法来实现相同的结果?

selinux sysfs
  • 1 个回答
  • 88 Views
Martin Hope
Ribo
Asked: 2018-12-28 06:53:08 +0800 CST

用户空间程序可以提供/实现 sysfs 或 procfs 文件以将数据传入和传出程序吗?

  • 4

/sys内核空间设备驱动程序通常实现通过或显示的目录和文件/proc。长期运行的用户空间程序也能做到这一点吗?

我有一个守护程序或长时间运行的程序,需要能够查询某些数据并在运行时由外部程序设置一些数据。
我可以做一个完整的套接字接口,但这对程序和外部请求者来说是很多开销。
正如 linux 内核开发人员发现的那样,使用“一切都是文件”模型对于调整内核设置很有用。我也想这样做。

有些人可能认为/sys目录是内核的神圣空间,但我没有看到什么是“系统”与其他一些服务/服务器/应用程序之间的重要界限。

使用 FUSE... 我决定使用 FUSE,即“用户空间中的文件系统”包 libfuse3.so。(在为它编写了一个包装器之后......)我可以定义一个结构数组,每个访问变量/文件一个:

struct fileObj files[] = {
  {"mode", mode, getFunc, putFunc},
  {"numbProcs", numbProcs, getFunc, putFunc},
  {"svrHostPort", hostPort, getFunc, putFunc},
  {"somethingWO", jakeBuf, NULL, putFunc},  // Write only file (why?)
  {"timestamp", NULL, getTimestampFunc, NULL},  // Returns timestamp, R/O
  {0}
};

FUSE 文件系统的挂载点是'/ssm/fuse'...'ls -l' 表明'files' 数组中的每个条目都显示为一个文件,一些 R/O,一些 R/W,一个 W /O。'get' 函数位置中的 'getTimestampFunc 表明可以将特殊函数与文件关联以执行计算响应。

ribo@box:~/c$ ls -l /ssm/fuse
total 0
-rw-r--r-- 1 ribo ribo 10 Dec 28 17:17 mode
-rw-r--r-- 1 ribo ribo  1 Dec 28 17:17 numbProcs
--w------- 1 ribo ribo  3 Dec 28 17:17 somethingWO
-rw-r--r-- 1 ribo ribo  5 Dec 28 17:17 svrHostPort
-r--r--r-- 1 ribo ribo 32 Dec 28 17:17 timestamp
ribo@box:~/c$ cat /ssm/fuse/timestamp
18/12/28 17:17:27ribo@box:~/c$cat  /ssm/fuse/mode
hyperSpeedribo@box:~/c$ echo slow >/ssm/fuse/mode
ribo@box:~/c$ cat  /ssm/fuse/mode
slow

'echo >' 显示将值传递到程序中。所以我很容易在程序运行时查看和查看程序的各种参数。

fuse sysfs
  • 2 个回答
  • 1870 Views
Martin Hope
Stonecraft
Asked: 2018-12-03 12:10:54 +0800 CST

为什么树不能完全列出 /sys/class/hwmon?我怎么能这样做?

  • 3

如果我理解正确的话,在 Linux 中,一切都是一条路径,一直延伸到每一块硬件。我正在尝试获取有关传感器结构的信息,所以我想我会使用树来映射我的 hwmon 目录中的所有内容。但是,tree 在此目录中的行为与我习惯的不同。

当我在普通目录上运行树时,我得到子目录结构而不使用 -R 或 -L 标志:

$ tree /home
/home
└── boss
    ├── clones
    ├── Desktop
    ├── Documents
    │   ├── modules.txt
    │   ├── old_docs
    │   │   └── assorted
    │   └── prepscript.txt
    ├── Downloads
    ├── Music
    ├── Pictures
    ├── Public
    ├── Templates
    └── Videos

12 directories, 2 files

但是我尝试对 HWmon 做同样的事情,即使我确实使用了 -R 标志并且即使有更深的东西,它也只会深入一层:

$ tree /sys/class/hwmon/
/sys/class/hwmon/
├── hwmon0 -> ../../devices/pci0000:40/0000:40:01.3/0000:43:00.0/hwmon/hwmon0
├── hwmon1 -> ../../devices/pci0000:00/0000:00:01.3/0000:09:00.0/hwmon/hwmon1
├── hwmon2 -> ../../devices/pci0000:40/0000:40:03.1/0000:44:00.0/hwmon/hwmon2
├── hwmon3 -> ../../devices/pci0000:00/0000:00:18.3/hwmon/hwmon3
├── hwmon4 -> ../../devices/pci0000:00/0000:00:19.3/hwmon/hwmon4
├── hwmon5 -> ../../devices/virtual/thermal/thermal_zone0/hwmon5
└── hwmon6 -> ../../devices/platform/nct6775.656/hwmon/hwmon6

7 directories, 0 files
$ tree /sys/class/hwmon/hwmon0
/sys/class/hwmon/hwmon0
├── device -> ../../../0000:43:00.0
├── fan1_input
├── name
├── power
│   ├── async
│   ├── autosuspend_delay_ms
│   ├── control
│   ├── runtime_active_kids
│   ├── runtime_active_time
│   ├── runtime_enabled
│   ├── runtime_status
│   ├── runtime_suspended_time
│   └── runtime_usage
├── pwm1
├── pwm1_enable
├── pwm1_max
├── pwm1_min
├── subsystem -> ../../../../../../class/hwmon
├── temp1_auto_point1_pwm
├── temp1_auto_point1_temp
├── temp1_auto_point1_temp_hyst
├── temp1_crit
├── temp1_crit_hyst
├── temp1_emergency
├── temp1_emergency_hyst
├── temp1_input
├── temp1_max
├── temp1_max_hyst
├── uevent
└── update_interval

3 directories, 27 files

是什么导致了这种行为差异,我可以得到所有设备的简单树吗?

sysfs tree
  • 1 个回答
  • 1430 Views
Martin Hope
David H Olson
Asked: 2018-05-19 09:05:35 +0800 CST

如何查找特定设备的 sysfs 目录?

  • 1

我有一个绑定到驱动程序的输入类设备(加速度计),该驱动程序公开了我需要从用户区访问的 sysfs 属性。使用 udev 规则,我提供了一个明确标识我的设备的别名,即ll /dev/input产量:

lrwxrwxrwx    1 root     root             6 May 18 13:47 accelerometer0 -> event0
drwxr-xr-x    2 root     root            60 May 18 13:47 by-path
crw-rw----    1 root     input      13,  64 May 18 13:47 event0
crw-rw----    1 root     input      13,  65 May 18 13:47 event1
crw-rw----    1 root     input      13,  66 May 18 13:47 event2

到目前为止,一切都很好:我可以open("/dev/input/accelerometer0")在我的用户空间代码中开始流式传输数据。但是,例如,更改数据速率,我需要写入pollrate_ms相关 sysfs 目录中的属性。一个ls /sys/class/input/产量:

event0  event1  event2  input0  input1  input2

我碰巧知道它pollrate_ms位于 中input0/device,但我需要以编程方式解决这个问题,特别是因为未来的更新可能会导致该编号发生变化。

我知道我可以使用libudev枚举/sys/class/input然后使用 for 循环来探索每个目录,直到找到包含pollrate_ms. 与通过 udev 规则明确识别设备的容易程度相比,这似乎是很多工作。

我错过了一个简单的方法还是我应该把它吸起来?

udev sysfs
  • 1 个回答
  • 1382 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve