2 * Devices support using the MacOS Disk Arbitration library.
4 * Copyright 2006 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(mountmgr
);
35 #ifdef HAVE_DISKARBITRATION_DISKARBITRATION_H
37 #include <DiskArbitration/DiskArbitration.h>
39 static void appeared_callback( DADiskRef disk
, void *context
)
41 CFDictionaryRef dict
= DADiskCopyDescription( disk
);
44 char mount_point
[PATH_MAX
];
45 DWORD type
= DRIVE_UNKNOWN
;
49 /* ignore non-removable devices */
50 if (!(ref
= CFDictionaryGetValue( dict
, CFSTR("DAMediaRemovable") )) ||
51 !CFBooleanGetValue( ref
)) goto done
;
54 if (!(ref
= CFDictionaryGetValue( dict
, CFSTR("DAMediaBSDName") ))) goto done
;
55 strcpy( device
, "/dev/r" );
56 CFStringGetCString( ref
, device
+ 6, sizeof(device
) - 6, kCFStringEncodingASCII
);
58 if ((ref
= CFDictionaryGetValue( dict
, CFSTR("DAVolumePath") )))
59 CFURLGetFileSystemRepresentation( ref
, true, (UInt8
*)mount_point
, sizeof(mount_point
) );
63 if ((ref
= CFDictionaryGetValue( dict
, CFSTR("DAVolumeKind") )))
65 if (!CFStringCompare( ref
, CFSTR("cd9660"), 0 ) ||
66 !CFStringCompare( ref
, CFSTR("udf"), 0 ))
70 TRACE( "got mount notification for '%s' on '%s'\n", device
, mount_point
);
72 add_dos_device( device
, device
, mount_point
, type
);
77 static void changed_callback( DADiskRef disk
, CFArrayRef keys
, void *context
)
79 appeared_callback( disk
, context
);
82 static void disappeared_callback( DADiskRef disk
, void *context
)
84 CFDictionaryRef dict
= DADiskCopyDescription( disk
);
90 /* ignore non-removable devices */
91 if (!(ref
= CFDictionaryGetValue( dict
, CFSTR("DAMediaRemovable") )) ||
92 !CFBooleanGetValue( ref
)) goto done
;
95 if (!(ref
= CFDictionaryGetValue( dict
, CFSTR("DAMediaBSDName") ))) goto done
;
96 strcpy( device
, "/dev/r" );
97 CFStringGetCString( ref
, device
+ 6, sizeof(device
) - 6, kCFStringEncodingASCII
);
99 TRACE( "got unmount notification for '%s'\n", device
);
101 remove_dos_device( device
);
106 static DWORD WINAPI
runloop_thread( void *arg
)
108 DASessionRef session
= DASessionCreate( NULL
);
110 if (!session
) return 1;
112 DASessionScheduleWithRunLoop( session
, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode
);
113 DARegisterDiskAppearedCallback( session
, kDADiskDescriptionMatchVolumeMountable
,
114 appeared_callback
, NULL
);
115 DARegisterDiskDisappearedCallback( session
, kDADiskDescriptionMatchVolumeMountable
,
116 disappeared_callback
, NULL
);
117 DARegisterDiskDescriptionChangedCallback( session
, kDADiskDescriptionMatchVolumeMountable
,
118 kDADiskDescriptionWatchVolumePath
, changed_callback
, NULL
);
120 DASessionUnscheduleFromRunLoop( session
, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode
);
121 CFRelease( session
);
125 void initialize_diskarbitration(void)
129 if (!(handle
= CreateThread( NULL
, 0, runloop_thread
, NULL
, 0, NULL
))) return;
130 CloseHandle( handle
);
133 #else /* HAVE_DISKARBITRATION_DISKARBITRATION_H */
135 void initialize_diskarbitration(void)
137 TRACE( "Skipping, Disk Arbitration support not compiled in\n" );
140 #endif /* HAVE_DISKARBITRATION_DISKARBITRATION_H */