1

How do I unmount a network volume?

NSWorkspace thinks they're neither removable nor unmountable. unmountAndEjectDeviceAtPath: @"/Volumes/the network volume in question" causes nothing whatsoever to happen. There's probably some easy way to do this, sitting right under my nose, but I can't find it.

I don't want to resort to making an Applescript telling the Finder to Eject network volumes and calling it from Cocoa because that's just incredibly icky.

(my dev platform is Tiger, by the way)

sarnold
  • 102,305
  • 22
  • 181
  • 238
user512530
  • 15
  • 1
  • 4
  • Are you trying to programmatically unmount the device in Objective-C? If so, please make that clearer in your question, since your question does not really read like a programming question right now. – Matt Ball Sep 27 '11 at 00:49

2 Answers2

0

You can also use diskutil which handles more situations than unmount():

std::string command = std::string("diskutil unmount \"") + currentMountPoint + "\"";
int ret = system( command.c_str() );

Note the double quotes around the mount point, most likely something like /Volumes/Untitled, but also something like /Volumes/NO NAME

Jason Harrison
  • 922
  • 9
  • 27
0

Is calling unmount(2) fair-game? (How odd, most Unix systems name the system call umount(), not unmount(), and the manpage frequently calls it umount() despite the name and Synopsis sections fairly clearly using unmount().)

Is the mount in use by anything else? Check lsof(1) or fuser(1) output to see which processes, if any, have that filesystem currently open. (Maybe adding a simple chdir("/"); just before your unmount call would do it?)

sarnold
  • 102,305
  • 22
  • 181
  • 238
  • Yes! Thank you! `unmount("/Volumes/theVolume",0)` works flawlessly. Easy and right under my nose indeed. Duh. After reading your answer I also discovered that the terminal commands `umount /Volumes/theVolume` or simply `umount theVolume` also work and could be executed through Cocoa using `NSTask`, but `unmount()` is much neater. Stupid `NSWorkspace`. Sheesh. – user512530 Sep 28 '11 at 00:18
  • Please share the link to the documentation. The link available in the answer is unavailable – Arun D Dec 02 '22 at 09:44
  • @ArunD how rude of Apple to break my links from a dozen years ago :) https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man2/unmount.2.html – sarnold Dec 02 '22 at 19:39
  • Thanks for updating the link :) But not sure if this method still works :( For me, nothing happens when I call the unmount() method – Arun D Dec 06 '22 at 11:01
  • @ArunD it's probably best to start a new question with a small example program that shows the problem -- that'll get far more people looking at it, and it'll include people with far more MacOS experience than I've got. My advice in the meantime is to check the kernel message buffer, maybe use ktruss or dtruss or whatever to trace your program, double-check all error returns, etc. "The usual stuff". :) Good luck! – sarnold Dec 06 '22 at 19:47