I am trying to repair permissions on my external HD. I cannot empty my trash when it is plugged in, because I get a bunch of such file is in use. I read online that this might be resolved by repairing permissions on the drive. I am currently unable to unmount the drive because it is in use the second I restart or unplug and replug it in. I used lsof to see what is using it but I am unable to understand this and can't seem to find a clear guide to learn what this means. The output is below: COMMAND PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEmds      59 root   23r   DIR    1,9     1701    5 /Volumes/SEAGATEmds      59 root   31r   DIR    1,9     1701    5 /Volumes/SEAGATE Commandps ax | egrep '[ /](PID|mds)'OutputPID   TT  STAT      TIME COMMAND660   ??  Ss     0:12.49 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Support/mds673   ??  Ss     0:08.68 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Versions/A/Support/mds_storesCommand/usr/bin/sudo kill 660Output//new line$Command sudo lsof /dev/disk2s2Output COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAMEmds     1599 root   11r   DIR    1,8     1764    5 /Volumes/SEAGATEIn that orderIf I run the bash file several times in a row I can get PID   TT  STAT      TIME COMMAND1737   ??  Ss     0:00.69 /System/Library/Frameworks/CoreServices.framework/Frameworks/Metadata.framework/Support/mdsBut the drive is still locked by mdsJust to show that the exception was added, here are screenshots:
Mac drive in use, understanding lsof
mount;osx;macintosh;lsof
Too fast diagnosisI read online that this might be resolved by repairing permission on the drive.Unfortunatly, from the description of your problem, this is wrong. What need to be repaired is the filesystem on your external disk SEAGATE.Analysis of lsofThe output of your lsof command tells that the command mds (1st column) is actually reading your filesystem /volumes/SEAGATE (last colume).To learn more about this fantastic command, just read the manual which iscoming with MacOS X:man lsofmds is a MacOS X server in charge of providing an access to the metadataof all your filesystems. Its most important clients are Finder and Spotlight.If you can't eject your external disk, this is legitimate and due to mds still reading it. If you nonetheless extract it, you will surely corrupt its filesystem.Free and repair the filesystemNow that it is corrupted, here is how to fix this.Open System Preferences > Spotlightselect Privacy windowand add (+) your SEAGATE external disk to stop Spotlightto try to index it.If mds is still running:ps ax | egrep '[ /](PID|mds)'You will have to kill it:_pid_to_kill=`ps ax | egrep '[ /]mds' | awk '{print $1}'`if [ ${_pid_to_kill} ] ; then    echo ${_pid_to_kill} | while read _pid ; do        /usr/bin/sudo kill ${_pid}    donefiCheck with lsof that your SEAGATE disk is now free:lsof /Volumes/SEAGATEIf this is OK, GOTO 4.If killing mds doesn't free /Volumes/SEAGATE then there is anotherprocess accessing this filesystem through mds. (This might be an anti-virus or a crapware. And this is quite another size of investigation).In this case, the fast path will be to stop launchd from starting mds.Proceed as follows:cd /System/Library/LaunchDaemons/usr/bin/sudo launchctl unload com.apple.metadata.mds.plistCheck that you don't have anymore mds process:ps ax | egrep '[ /](PID|mds)'Check with lsof that your SEAGATE disk is now free:lsof /Volumes/SEAGATEThis should be OK, GOTO 4.Start Disk Utilityand check your disk SEAGATE.I suspect that some repairs will be needed.In this case repair it.Eject it, and check that you don't have any more any file in useerror message.Open System Preferences > Spotlightselect Privacy windowand remove (-) your SEAGATE external disk to permit Spotlightto index it.If you passed strep 3. where you had to stop launchd from starting mds you will have to enable this function back (otherwise a lot of thing managing your filesystem will fail).Proceed as follows:cd /System/Library/LaunchDaemons/usr/bin/sudo launchctl load com.apple.metadata.mds.plist