cant read content from USB in Linux.

People don’t seem to know the solution for this issue stackoverflow.com/questions/3278 … irusb-path , so I thought some folks here might be of help.

I have a Panda app running in a media player device. The last thing I want is users to not be able to play media from their USB because for some reason it became “read-only”.
Has anyone ever encountered this?
Error message is simply

OS Error: [Errno 13] Permission denied: media/myName/usbName'

Not like I’m writing anything to it, doesn’t even allow to read. Only way to get rid of that issue is to partition it then format it, but it keeps coming back. My USB sticks aren’t old and are Sandisk, a typical USB stick…
I can read from it in Linux and Windows just fine, problem happens with Python.

OK, figured out the issue: USB sticks don’t get “unmounted” in Linux when I pull them out without unmounting myself first. Since there is no desktop/monitor/keyboard-mouse I can’t really do that.

Instead of doing (‘media/myName/’ + os.listdir(‘media/myName’)[0] now I attempt to do listdir() on every folder in os.listdir(‘media/myName’) in a try/except statement. This is far from perfect and I don’t know if it won’t cause a crash from something else soon.

Could you perhaps use “os.system(…)” to unmount the drive once it’s removed? (I don’t know whether you have a means of detecting the removal of the drive.)

(Indeed, unless you’re confident that nothing on the drive is being accessed (whether by your program or otherwise) at the point at which the drive is removed, it might be wise–if feasible–to unmount the drive before removal.)

(By the way, the link in your initial post doesn’t seem to work any more, at least as of time of writing–it produces a page that indicates that the question was removed by the author.)

I tried subprocess.call([‘umount’, i]) ,but it didn’t do anything (remains in list). I think os.system(’’) is equivalent. “umount” is also available in the module “sh”.
Unless the “umount” Linux command is not the correct one for unmounting, I don’t know what else to do.

When the USB drive is ejected (cleanly or not), it should no longer be mounted at all. Perhaps you created directories and files in /media/myName while it was unmounted, which get hidden as soon as a USB stick is mounted to that location? Just a guess.

You may also have to add the user account to an appropriate group for it to be able to access automounted files. Once again, I’m not sure about that because I don’t use automount on my Linux system.

You mean the system has to unmount any ejected USB drive automatically?
Doesn’t seem to happen to me all the time. I think mostly when the user turns off the media player device (long press shutdown) while the USB is plugged in.

I don’t get it. What gets hidden? Files and folders added to the USB while it is unmounted? But I shouldn’t have had access to the folder when it was unmounted right (and that folder would have to be removed, right)?

I have added my user to the “dialout” group so I can access Arduino in “/dev/ttyUSB0”. Didn’t seem to need that for USB drives though in any case.