LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

Rep: Reputation: Disabled
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.
 
Old 09-25-2013, 09:19 AM   #2
EDDY1
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
rtmistler
Moderator
 
Registered: Mar 2011
Location: Sutton, MA. USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu
Posts: 4,087
Blog Entries: 10

Rep: Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521Reputation: 1521
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?
 
  


Reply


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 9 11-08-2016 09:07 PM
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


All times are GMT -5. The time now is 10:06 AM.

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