Detect if USB Flash Drive is Write Protected

Hi,

I'd like to know how an application program running as root can detect if a USB flash drive is write protected. I am using kernel 2.6.8. When I plug in a write protected USB flash drive I see messages on the console indicating that it is write protected, but I am able to successfully mount the flash drive as rw and open a file for writing without getting an error for either of these. If the file is small I don't see an error message on the console until I close the file. For larger files the error messages appear on the console when the buffer is flushed.

What I'd like to be able to do is use a system call or ioctl to determine if the USB flash drive is write protected and then display an error dialog on the screen, but I haven't been able to find anything related to this on the internet.

I'd also like to be able to detect when the USB flash drive is removed without it having been unmounted so that I can warn the user of what was done.

If it matters the embedded system I am programming is running an ARM

920T processor with a Phillips ISP1362BD USB contoller chip.

Any help will be greatly appreciated.

Reply to
rwcooper
Loading thread data ...

That's a kernel bug. For 2.4 kernels, if you try to open a write protected media for writing, if would fail immediately.

Reply to
linnix

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.