Writing to a “application/octet-stream” file on linux

試著忘記壹切 提交于 2021-02-11 18:21:20

问题


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

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.

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?


回答1:


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)

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)


来源:https://stackoverflow.com/questions/60725279/writing-to-a-application-octet-stream-file-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!