-
Notifications
You must be signed in to change notification settings - Fork 0
/
eam.c
52 lines (42 loc) · 1.42 KB
/
eam.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <mach/mach_port.h>
#include <mach/mach_interface.h>
#include <mach/mach_init.h>
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <IOKit/IOMessage.h>
io_connect_t root_port; // a reference to the Root Power Domain IOService
void
MySleepCallBack( void * refCon, io_service_t service, natural_t messageType, void * messageArgument )
{
switch ( messageType )
{
case kIOMessageSystemWillSleep:
system("/usr/sbin/diskutil unmount /Volumes/External");
IOAllowPowerChange( root_port, (long)messageArgument );
break;
case kIOMessageSystemHasPoweredOn:
system("/usr/sbin/diskutil mount disk4s2");
IOAllowPowerChange( root_port, (long)messageArgument );
break;
default:
break;
}
}
int main( int argc, char **argv )
{
IONotificationPortRef notifyPortRef;
io_object_t notifierObject;
void* refCon;
root_port = IORegisterForSystemPower( refCon, ¬ifyPortRef, MySleepCallBack, ¬ifierObject );
if ( root_port == 0 )
{
printf("IORegisterForSystemPower failed\n");
return 1;
}
// add the notification port to the application runloop
CFRunLoopAddSource( CFRunLoopGetCurrent(), IONotificationPortGetRunLoopSource(notifyPortRef), kCFRunLoopCommonModes );
CFRunLoopRun();
return (0);
}