0

Here is the problem, when I use the NSTask to unmount the current USB drive it will give me following error:

    2013-06-03 09:39:41.096 NAME[1028:303] in moving file view controller
    dyld: DYLD_ environment variables being ignored because main executable    
    (/usr/sbin/diskutil) has __RESTRICT/__restrict section 
    Unmount of disk1 failed: at least one volume could not be unmounted

I have partition for my mac so disk1 I think is mac os. Here is the function that I use to unmount my drive:

    //When I call this function by passing all of these arguments:
    NSArray* arrayForCloseUSBDrive = [[NSArray arrayWithObjects:@"diskutil", @"unmountDisk",@"/Volumes/AAA/",nil]autorelease];
    [Utility handleDrive:@"/usr/bin/env" arrayArguments:arrayForCloseUSBDrive];

    //It will start run this function in Utility class:
    +(void)handleDrive:(NSString*)launchPath arrayArguments:(NSArray*)array
   {
      NSTask *task = [NSTask new];
      [task setLaunchPath:launchPath];
      [task setArguments:array];

      NSPipe *pipe = [NSPipe pipe];
      [task setStandardOutput:pipe];

      [task launch];
      [task waitUntilExit];
   }
YU FENG
  • 888
  • 1
  • 12
  • 29
  • 1
    Why not use one of the native `-unmount*` methods in `NSWorkspace`? – Gerd K Jun 03 '13 at 14:48
  • I tried but it does not work either. Actually, when I tried in terminal to unmountDisk, it still gives me error says "Unmount of disk1 failed: at least one volume could not be unmounted" – YU FENG Jun 03 '13 at 15:47
  • So you need to find out why you can not unmount it. Was the volume mounted by the current user? Are there still any files from that volume opened? In terminal, `fuser -uc /Volumes/MyMountPoint` will show you processes and the user owning them that have files opened on that file system. As long as any files are opened, the file system can not be unmounted. – Gerd K Jun 03 '13 at 16:48
  • @GerdK you should turn that comment into an answer! – Monolo Jun 17 '13 at 16:44

1 Answers1

1

Find out why you can not unmount it:

  • Was the volume mounted by the current user?

  • Are there still any files from that volume opened? In terminal, fuser -uc /Volumes/MyMountPoint will show you processes and the user owning them that have files opened on that file system. As long as any files are opened, the file system can not be unmounted.

Gerd K
  • 2,933
  • 1
  • 20
  • 23