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"
35 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(mountmgr
);
40 #ifdef HAVE_DISKARBITRATION_DISKARBITRATION_H
42 #include <DiskArbitration/DiskArbitration.h>
44 static void appeared_callback( DADiskRef disk
, void *context
)
46 CFDictionaryRef dict
= DADiskCopyDescription( disk
);
49 char mount_point
[PATH_MAX
];
50 const char *type
= NULL
;
54 /* ignore non-removable devices */
55 if (!(ref
= CFDictionaryGetValue( dict
, CFSTR("DAMediaRemovable") )) ||
56 !CFBooleanGetValue( ref
)) goto done
;
59 if (!(ref
= CFDictionaryGetValue( dict
, CFSTR("DAMediaBSDName") ))) goto done
;
60 strcpy( device
, "/dev/r" );
61 CFStringGetCString( ref
, device
+ 6, sizeof(device
) - 6, kCFStringEncodingASCII
);
63 if ((ref
= CFDictionaryGetValue( dict
, CFSTR("DAVolumePath") )))
64 CFURLGetFileSystemRepresentation( ref
, true, (UInt8
*)mount_point
, sizeof(mount_point
) );
68 if ((ref
= CFDictionaryGetValue( dict
, CFSTR("DAVolumeKind") )))
70 if (!CFStringCompare( ref
, CFSTR("cd9660"), 0 ) ||
71 !CFStringCompare( ref
, CFSTR("udf"), 0 ))
75 TRACE( "got mount notification for '%s' on '%s'\n", device
, mount_point
);
77 add_dos_device( device
, device
, mount_point
, type
);
82 static void changed_callback( DADiskRef disk
, CFArrayRef keys
, void *context
)
84 appeared_callback( disk
, context
);
87 static void disappeared_callback( DADiskRef disk
, void *context
)
89 CFDictionaryRef dict
= DADiskCopyDescription( disk
);
95 /* ignore non-removable devices */
96 if (!(ref
= CFDictionaryGetValue( dict
, CFSTR("DAMediaRemovable") )) ||
97 !CFBooleanGetValue( ref
)) goto done
;
100 if (!(ref
= CFDictionaryGetValue( dict
, CFSTR("DAMediaBSDName") ))) goto done
;
101 strcpy( device
, "/dev/r" );
102 CFStringGetCString( ref
, device
+ 6, sizeof(device
) - 6, kCFStringEncodingASCII
);
104 TRACE( "got unmount notification for '%s'\n", device
);
106 remove_dos_device( device
);
111 static DWORD WINAPI
runloop_thread( void *arg
)
113 DASessionRef session
= DASessionCreate( NULL
);
115 if (!session
) return 1;
117 DASessionScheduleWithRunLoop( session
, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode
);
118 DARegisterDiskAppearedCallback( session
, kDADiskDescriptionMatchVolumeMountable
,
119 appeared_callback
, NULL
);
120 DARegisterDiskDisappearedCallback( session
, kDADiskDescriptionMatchVolumeMountable
,
121 disappeared_callback
, NULL
);
122 DARegisterDiskDescriptionChangedCallback( session
, kDADiskDescriptionMatchVolumeMountable
,
123 kDADiskDescriptionWatchVolumePath
, changed_callback
, NULL
);
125 DASessionUnscheduleFromRunLoop( session
, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode
);
126 CFRelease( session
);
130 void initialize_diskarbitration(void)
134 if (!(handle
= CreateThread( NULL
, 0, runloop_thread
, NULL
, 0, NULL
))) return;
135 CloseHandle( handle
);
138 #else /* HAVE_DISKARBITRATION_DISKARBITRATION_H */
140 void initialize_diskarbitration(void)
142 TRACE( "Skipping, Disk Arbitration support not compiled in\n" );
145 #endif /* HAVE_DISKARBITRATION_DISKARBITRATION_H */