Editing FAT32 file attributes
Here's a quick and useful tactic for dealing with file attributes on FAT32 drives. I got the idea from this post on the Ubuntu blog
My new MP3 player (which I'll be blogging about when I have more time) uses a FAT32 filesystem. I needed to change the attributes on some of file attributes so that it would show the media folders but hide the system folders. Why I needed to do that is another story. Anyway, the point is that there was no obvious way to do this from Linux and since charging the MP3 player seems to reset these attributes, I didn't want to have to rely on a Windows machine being handy.
After way more Googling than I thought necessary, I discovered that you can do this with good old mtools. The really old-school people in the audience will probably remember them from the days when floppy disks were still in common use. Well, it turns out that they can be used with USB mass storage devices too.
The first step, after installing mtools of course, is to set up a drive letter for your USB device in your ~/.mtoolsrc file. This can be done by adding something like the following:
drive s: file="/dev/sdb1"
The first line associates the S: drive letter with the device file for my player. The mtools_skip_check line suppresses errors which, I believe, arise from the fact that this is a USB device, not an actual floppy disk. Either that, or there's something about the FAT that mtools doesn't like, but can still work with.
Once that's set up, I was able to simply use
mattrib to change the file attributes and [cdoe]mdir[/code] to show the attribute-sensitive directory listing. The actual commands look something like this:
mattrib +h S:/TMP
mattrib -h S:/MUSIC
Note the use of the S: drive letter to prefix paths on the root of the device. The
-h flags turn the hidden attribute on and off respectively. Also note that you can have the device mounted while doing this - mtools doesn't need exclusive access as far as I know.
Eventually, I'll be scripting this so that I can (hopefully) run it automatically after charging my player. Ideally, that script would include some HAL or udev magic to detect the dynamically assigned device node and add that to the mtoolsrc file. When I get around to writing that, I'll post the result.
You can reply to this entry by leaving a comment below. You can send TrackBack pings to this URL. This entry accepts Pingbacks from other blogs. You can follow comments on this entry by subscribing to the RSS feed.
C, F, L, R » Examen (Saturday, 2010 July 31)
One thing that is useful to know in case the trainers come to you looking for help with their virus-addled USB drives. A fairly common thing these viruses do is mark the directories as hidden and then create files with identical names. It wouldn’t be a big deal except the computers that are locked down administratively aren’t allowed to show hidden files, so you have to use your own laptop. Naturally Linux completely ignores the "hidden" attribute on files, but you can use mtools to change the attributes, even on a USB drive, by creating a mtoolsrc file like this or, I think, directly using mattrib -i /dev/sdb1 or whatever. To remove system and hidden on everything, which is probably what you want to do: mattrib -S -H -/ S:/.Pingback: Diego Escalante Urrelo: Removing the hidden/system bit of vfat/fat32 files on GNU/Linux | Linux-Support.com
After some googling I got this solved by using mtools:Pingback: Removing the hidden/system bit of vfat/fat32 files on GNU/Linux | Diego Escalante Urrelo
After some googling I got this solved by using mtools: