本文介绍了写入“应用程序/八位位组流".Linux上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究应阻止某些USB设备的应用程序.

I am working on application which should block some USB devices.

我找到了一种方法来进行阻止.问题是,因为它写在此处,我需要写一些字符串放入/sys/bus/usb/drivers_probe 文件中.提到的文件是 application/octet-stream ,我找不到一种方法来读取或写入此文件.

I have found a way how could be blocking done. Problem is, as it's written here, that I need to write some string into /sys/bus/usb/drivers_probe file. Mentioned file is application/octet-stream and I can't find a way how to read or write to this file.

我已经尝试使用sudo或root身份尝试过 vim echo hexdump ,但是每次我得到权限被拒绝"没有这样的设备" 消息.我没有在我的应用程序使用的C/C ++中尝试过,但是我想它会带来相同的结果.

I have tried vim, echo, hexdump with sudo or as root, but every time I get "Permission denied" or "No such device" message. I did not tried it in C/C++, which is my app using, but I guess it would bring same result.

有人可以帮助我了解内核开发人员写该文件的意图吗?

Can anyone help me understand how kernel developers meant writing to that file?

推荐答案

如果收到权限被拒绝",则表示您没有使用root特权打开文件:

If you get "Permission denied", it means you are not opening the file with root privileges:

$ sudo echo 4-1 > /sys/bus/usb/drivers_probe
bash: /sys/bus/usb/drivers_probe: Permission denied

$ echo 4-1 | sudo tee /sys/bus/usb/drivers_probe > /dev/null
(no error)

如果你得到No such device",这意味着你写错了字符串:

If you get "No such device", it means you are writing the wrong string:

$ echo 'foobar' | sudo tee /sys/bus/usb/drivers_probe > /dev/null
tee: /sys/bus/usb/drivers_probe: No such device

$ echo '3-1.3.1:1.3' | sudo tee /sys/bus/usb/drivers_probe > /dev/null
(no error)

这篇关于写入“应用程序/八位位组流".Linux上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 15:18