comctl32/treeview: Correctly draw cut items.
[wine/multimedia.git] / dlls / mountmgr.sys / diskarb.c
blobd3912ca692a823dd51ea88d487caeb163b9a5939
1 /*
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
21 #include "config.h"
22 #include "wine/port.h"
24 #include <assert.h>
25 #include <errno.h>
26 #include <stdarg.h>
27 #include <stdio.h>
28 #include <sys/time.h>
30 #include "mountmgr.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 );
42 const void *ref;
43 char device[64];
44 char mount_point[PATH_MAX];
45 GUID guid, *guid_ptr = NULL;
46 enum device_type type = DEVICE_UNKNOWN;
48 if (!dict) return;
50 if ((ref = CFDictionaryGetValue( dict, CFSTR("DAVolumeUUID") )))
52 CFUUIDBytes bytes = CFUUIDGetUUIDBytes( ref );
53 memcpy( &guid, &bytes, sizeof(guid) );
54 guid_ptr = &guid;
57 /* get device name */
58 if (!(ref = CFDictionaryGetValue( dict, CFSTR("DAMediaBSDName") ))) goto done;
59 strcpy( device, "/dev/r" );
60 CFStringGetCString( ref, device + 6, sizeof(device) - 6, kCFStringEncodingASCII );
62 if ((ref = CFDictionaryGetValue( dict, CFSTR("DAVolumePath") )))
63 CFURLGetFileSystemRepresentation( ref, true, (UInt8 *)mount_point, sizeof(mount_point) );
64 else
65 mount_point[0] = 0;
67 if ((ref = CFDictionaryGetValue( dict, CFSTR("DAMediaKind") )))
69 if (!CFStringCompare( ref, CFSTR("IOCDMedia"), 0 ))
70 type = DEVICE_CDROM;
71 if (!CFStringCompare( ref, CFSTR("IODVDMedia"), 0 ) ||
72 !CFStringCompare( ref, CFSTR("IOBDMedia"), 0 ))
73 type = DEVICE_DVD;
74 if (!CFStringCompare( ref, CFSTR("IOMedia"), 0 ))
75 type = DEVICE_HARDDISK;
78 TRACE( "got mount notification for '%s' on '%s' uuid %s\n",
79 device, mount_point, wine_dbgstr_guid(guid_ptr) );
81 if ((ref = CFDictionaryGetValue( dict, CFSTR("DAMediaRemovable") )) && CFBooleanGetValue( ref ))
82 add_dos_device( -1, device, device, mount_point, type, guid_ptr );
83 else
84 if (guid_ptr) add_volume( device, device, mount_point, DEVICE_HARDDISK_VOL, guid_ptr );
86 done:
87 CFRelease( dict );
90 static void changed_callback( DADiskRef disk, CFArrayRef keys, void *context )
92 appeared_callback( disk, context );
95 static void disappeared_callback( DADiskRef disk, void *context )
97 CFDictionaryRef dict = DADiskCopyDescription( disk );
98 const void *ref;
99 char device[100];
101 if (!dict) return;
103 /* get device name */
104 if (!(ref = CFDictionaryGetValue( dict, CFSTR("DAMediaBSDName") ))) goto done;
105 strcpy( device, "/dev/r" );
106 CFStringGetCString( ref, device + 6, sizeof(device) - 6, kCFStringEncodingASCII );
108 TRACE( "got unmount notification for '%s'\n", device );
110 if ((ref = CFDictionaryGetValue( dict, CFSTR("DAMediaRemovable") )) && CFBooleanGetValue( ref ))
111 remove_dos_device( -1, device );
112 else
113 remove_volume( device );
115 done:
116 CFRelease( dict );
119 static DWORD WINAPI runloop_thread( void *arg )
121 DASessionRef session = DASessionCreate( NULL );
123 if (!session) return 1;
125 DASessionScheduleWithRunLoop( session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode );
126 DARegisterDiskAppearedCallback( session, kDADiskDescriptionMatchVolumeMountable,
127 appeared_callback, NULL );
128 DARegisterDiskDisappearedCallback( session, kDADiskDescriptionMatchVolumeMountable,
129 disappeared_callback, NULL );
130 DARegisterDiskDescriptionChangedCallback( session, kDADiskDescriptionMatchVolumeMountable,
131 kDADiskDescriptionWatchVolumePath, changed_callback, NULL );
132 CFRunLoopRun();
133 DASessionUnscheduleFromRunLoop( session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode );
134 CFRelease( session );
135 return 0;
138 void initialize_diskarbitration(void)
140 HANDLE handle;
142 if (!(handle = CreateThread( NULL, 0, runloop_thread, NULL, 0, NULL ))) return;
143 CloseHandle( handle );
146 #else /* HAVE_DISKARBITRATION_DISKARBITRATION_H */
148 void initialize_diskarbitration(void)
150 TRACE( "Skipping, Disk Arbitration support not compiled in\n" );
153 #endif /* HAVE_DISKARBITRATION_DISKARBITRATION_H */