问题
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