Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-25-2013, 04:23 AM   #1
LQ Newbie
Registered: Sep 2013
Posts: 1

Rep: Reputation: Disabled
Detecting a USB device which is write protected


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.
Old 09-25-2013, 09:19 AM   #2
LQ Addict
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,838

Rep: Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649Reputation: 649
I believe that if you remove the operator from plugdev in /etc/group it stops access.
Old 09-25-2013, 09:33 AM   #3
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 5,844
Blog Entries: 12

Rep: Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010Reputation: 2010
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.

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
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?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
mount: block device is write-protected, mounting read-only xpucto Linux - Server 10 02-01-2017 03:16 AM
How to determine if USB flash drive is write protected richw42 Programming 2 07-02-2012 05:32 PM
[SOLVED] samba mount: block device is write-protected, onlystream Linux - Newbie 1 03-31-2012 01:30 PM
USB Write-Protected (Read-Only Mode) After GParted Install jay_pablo_69 Ubuntu 2 11-01-2011 04:20 PM
USB flash write protected vijayabcdef Linux - Hardware 4 09-14-2011 12:00 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:35 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration