LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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, 03: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, 08:19 AM   #2
EDDY1
LQ Addict
 
Registered: Mar 2010
Location: Oakland,Ca
Distribution: wins7, Debian wheezy
Posts: 6,841

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, 08:33 AM   #3
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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



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 02:16 AM
How to determine if USB flash drive is write protected richw42 Programming 2 07-02-2012 04:32 PM
[SOLVED] samba mount: block device is write-protected, onlystream Linux - Newbie 1 03-31-2012 12:30 PM
USB Write-Protected (Read-Only Mode) After GParted Install jay_pablo_69 Ubuntu 2 11-01-2011 03:20 PM
USB flash write protected vijayabcdef Linux - Hardware 4 09-14-2011 11:00 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

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
Open Source Consulting | Domain Registration