LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Detecting a USB device which is write protected (https://www.linuxquestions.org/questions/linux-newbie-8/detecting-a-usb-device-which-is-write-protected-4175478450/)

shedevil 09-25-2013 03:23 AM

Detecting a USB device which is write protected
 
Hi,

I would like to display a message to the user if he plugs in a write protected flash drive. Is there any linux command that I can use to detect a write protected USB device. I do not want to use "dmesg" and poll for the device.

Please help.

EDDY1 09-25-2013 08:19 AM

I believe that if you remove the operator from plugdev in /etc/group it stops access.

rtmistler 09-25-2013 08:33 AM

I don't have any write protect-able USB sticks so I couldn't test to see how they'd appear.

What I can say is that a USB thumb stick on my system appears in the /sys/block hierarchy and in viewing the "ro" file, it shows zero. Since my stick is read-write, then my assumption is that this file would show a one if the stick were read-only; a.k.a. write-protected.

Code:

cd /sys/block/sdf
me@my-desktop:/sys/block/sdf$ ls
alignment_offset  bdi  capability  dev  device  ext_range  holders  inflight  power  queue  range  removable  ro  sdf1  size  slaves  stat  subsystem  trace  uevent
me@my-desktop:/sys/block/sdf$ cat ro
0

But wouldn't the user figure this out eventually? Why bother to hold their hand so much. Once they try to write to it, won't it gripe at them at that point? Or am I missing something?


All times are GMT -5. The time now is 04:40 PM.