Skip to content

Instantly share code, notes, and snippets.

@Calrion
Created December 8, 2011 04:32
Show Gist options
  • Save Calrion/1446123 to your computer and use it in GitHub Desktop.
Save Calrion/1446123 to your computer and use it in GitHub Desktop.
Mount Stop Daemon (for Mac OS X)

Mount Stop Daemon

Mount Stop Daemon is a command-line utility for Mac OS X that prevents volumes from being automatically mounted. Any and all new volumes will not be automatically mounted while mountstopd is running.

Usage

There are no command-line options to worry about. Run mountstopd before connecting a volume to your Mac and it won't be automatically mounted. If you want the drive to be mounted, you'll need to do it yourself using the mount command. See the mount(8) manual page for more information.

This is useful if you want to specify particular non-default options when mounting a drive, such as mounting read-only.

Compilation

The following instructions have been supplied by the author:

? cc main.c -o mountstopd -framework Foundation \
-framework DiskArbitration

Source

The source code and compilation instructions were obtained from the following answer post on SuperUser:

License

All StackOverflow site posts are published under the CC-Wiki license.

This documentation written by Greg Waterhouse (Calrion), also licensed under CC-Wiki.

Published as a GitHub Gist: https://gist.github.com/1446123

#include <CoreFoundation/CoreFoundation.h>
#include <DiskArbitration/DiskArbitration.h>
DADissenterRef BlockMount(DADiskRef disk, void *context)
{
DADissenterRef dissenter = DADissenterCreate(kCFAllocatorDefault, kDAReturnNotPermitted, CFSTR("forbidden!"));
return dissenter;
}
int main (int argc, const char * argv[])
{
DAApprovalSessionRef session = DAApprovalSessionCreate (kCFAllocatorDefault);
if (!session)
{
fprintf(stderr, "failed to create Disk Arbitration session");
}
else
{
DARegisterDiskMountApprovalCallback(session, NULL, BlockMount, NULL);
DAApprovalSessionScheduleWithRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
while (true) {
CFRunLoopRunInMode(kCFRunLoopDefaultMode, 60 /* seconds */, false);
}
DAApprovalSessionUnscheduleFromRunLoop(session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);
DAUnregisterApprovalCallback(session, BlockMount, NULL);
CFRelease(session);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment