title: How can I prevent ejection of a disk during an operation on Mac OS X?
body: <p>I have a long-running task that performs a series of file operations on mounted USB drives and I want to prevent users from ejecting the drive from Finder (or elsewhere) while this happens.  There is a Cancel button that allows the task to be ended at any time.</p>
  
  <p>I had assumed that keeping a file handle open on the mounted volume for the duration of the task would do the trick, but it hasn't worked.</p>
  
  <p>This is what I tried (error handling removed):</p>
  
  <pre><code>NSString *tempFilePath = @"/Volumes/myVolume/.myTempFile";
  if ([[NSFileManager defaultManager] fileExistsAtPath:tempFilePath] == NO) {
      [[NSFileManager defaultManager] createFileAtPath:tempFilePath contents:nil attributes:nil]
  }
  
  _tempFile = [NSFileHandle fileHandleForWritingAtPath:tempFilePath];
  </code></pre>
  
  <p>Any ideas about what I can do to ensure that the volume is prevented from ejecting?</p>