
Feb 07, '11 07:30:00AM • Contributed by: lsloan
I wanted to prevent Mac OS X from writing those files to MS-DOS filesystems at all, but I couldn't find a way to do that. My second thought was to write an AppleScript that would execute whenever the eject operation was requested, deleting the dot files, but I couldn't find a way to do that, either. So, being an old UNIX guy, I decided to try going down to that level and writing a wrapper script for umount, the program that does a lot of the work when ejecting (or 'unmounting') a filesystem.
This has worked out for me very well, but this solution might not be for everybody. This hint will explain how to install a umount wrapper script, but great care must be taken while doing so. You'll be using Terminal.app, working as the root user, and moving important OS utilities. A mistake in these steps could cause a lot of trouble for you.
To install the wrapper:
- Run Terminal.app.
- At the shell prompt in Terminal, run this command to become root:
sudo -s
You will be prompted to enter your own password. You must be an Admin user in order to do this. - Go to the /sbin directory and move the original umount utility to a different name. Use this command:
cd /sbin; mv umount umount-orig - Put the following script into a file named umount in the /sbin directory. The best way is to paste this into a text editor and save it as umount:
#!/bin/sh -- loggerTag='umount-wrapper' ( if [ "$@" ]; then for i in "$@"; do echo $i done fstype=`diskutil info "$1" | sed 's/ //g' | grep '^Type:' | cut -d':' -f2` echo "fstype is ${fstype}" if [ "$fstype" = "msdos" ]; then echo cleaning msdos filesystem... find "$1" -depth -name '.[^.]*' -print -exec /bin/rm -fr {} \; else echo not msdos, skipping to umount... fi fi ) | logger -st $loggerTag /sbin/umount-orig "$@"
- Just to make sure things are correct, set the permissions and owners of the umount files:
chmod 555 /sbin/umount*; chown root:wheel /sbin/umount* - You're done! Exit Terminal.app now, just to be safe.
This may be obvious, but if you intentionally copy dot files (like your .bashrc file) to your MS-DOS filesystem, they will be deleted when you eject the filesystem. A couple possible ways to prevent this would be to put your dot files into a ZIP file or change this script to be more specific about which files it deletes.
In my opinion, Apple should put an option into the OS to not put its special dot files onto MS-DOS filesystems and the option should be enabled by default. Users that then need those dot files can then disable the option.
[crarko adds: I haven't tested this one. Please be careful with this one if you try it. There are a couple of earlier hints that cover similar territory as this one.
Note: Correction made to the script per the author to add the -fr command to the line:
find "$1" -depth -name '.[^.]*' -print -exec /bin/rm -fr {} \;.]