2006-10-03 14:54:16 +02:00
|
|
|
/*
|
|
|
|
* Devices support using the MacOS Disk Arbitration library.
|
|
|
|
*
|
|
|
|
* Copyright 2006 Alexandre Julliard
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
2008-03-04 07:58:32 +01:00
|
|
|
#include "mountmgr.h"
|
2008-10-21 15:01:52 +02:00
|
|
|
#include "wine/debug.h"
|
2006-10-03 14:54:16 +02:00
|
|
|
|
2008-03-04 07:58:32 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mountmgr);
|
2006-10-03 14:54:16 +02:00
|
|
|
|
2006-11-05 21:03:46 +01:00
|
|
|
#ifdef HAVE_DISKARBITRATION_DISKARBITRATION_H
|
2006-10-03 14:54:16 +02:00
|
|
|
|
|
|
|
#include <DiskArbitration/DiskArbitration.h>
|
|
|
|
|
|
|
|
static void appeared_callback( DADiskRef disk, void *context )
|
|
|
|
{
|
|
|
|
CFDictionaryRef dict = DADiskCopyDescription( disk );
|
|
|
|
const void *ref;
|
|
|
|
char device[64];
|
|
|
|
char mount_point[PATH_MAX];
|
2009-07-20 16:11:17 +02:00
|
|
|
GUID guid, *guid_ptr = NULL;
|
2008-11-12 10:47:49 +01:00
|
|
|
enum device_type type = DEVICE_UNKNOWN;
|
2006-10-03 14:54:16 +02:00
|
|
|
|
|
|
|
if (!dict) return;
|
|
|
|
|
|
|
|
/* ignore non-removable devices */
|
|
|
|
if (!(ref = CFDictionaryGetValue( dict, CFSTR("DAMediaRemovable") )) ||
|
2007-02-07 17:11:52 +01:00
|
|
|
!CFBooleanGetValue( ref )) goto done;
|
2006-10-03 14:54:16 +02:00
|
|
|
|
2009-07-20 16:11:17 +02:00
|
|
|
if ((ref = CFDictionaryGetValue( dict, CFSTR("DAVolumeUUID") )))
|
|
|
|
{
|
|
|
|
CFUUIDBytes bytes = CFUUIDGetUUIDBytes( ref );
|
|
|
|
memcpy( &guid, &bytes, sizeof(guid) );
|
|
|
|
guid_ptr = &guid;
|
|
|
|
}
|
|
|
|
|
2006-10-03 14:54:16 +02:00
|
|
|
/* get device name */
|
2007-02-07 17:11:52 +01:00
|
|
|
if (!(ref = CFDictionaryGetValue( dict, CFSTR("DAMediaBSDName") ))) goto done;
|
2006-10-03 14:54:16 +02:00
|
|
|
strcpy( device, "/dev/r" );
|
|
|
|
CFStringGetCString( ref, device + 6, sizeof(device) - 6, kCFStringEncodingASCII );
|
|
|
|
|
|
|
|
if ((ref = CFDictionaryGetValue( dict, CFSTR("DAVolumePath") )))
|
|
|
|
CFURLGetFileSystemRepresentation( ref, true, (UInt8 *)mount_point, sizeof(mount_point) );
|
|
|
|
else
|
|
|
|
mount_point[0] = 0;
|
|
|
|
|
|
|
|
if ((ref = CFDictionaryGetValue( dict, CFSTR("DAVolumeKind") )))
|
|
|
|
{
|
|
|
|
if (!CFStringCompare( ref, CFSTR("cd9660"), 0 ) ||
|
|
|
|
!CFStringCompare( ref, CFSTR("udf"), 0 ))
|
2008-11-12 10:47:49 +01:00
|
|
|
type = DEVICE_CDROM;
|
2006-10-03 14:54:16 +02:00
|
|
|
}
|
|
|
|
|
2009-07-20 16:11:17 +02:00
|
|
|
TRACE( "got mount notification for '%s' on '%s' uuid %s\n",
|
|
|
|
device, mount_point, wine_dbgstr_guid(guid_ptr) );
|
2006-10-03 14:54:16 +02:00
|
|
|
|
2009-07-20 16:11:17 +02:00
|
|
|
add_dos_device( -1, device, device, mount_point, type, guid_ptr );
|
2007-02-07 17:11:52 +01:00
|
|
|
done:
|
2006-10-03 14:54:16 +02:00
|
|
|
CFRelease( dict );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void changed_callback( DADiskRef disk, CFArrayRef keys, void *context )
|
|
|
|
{
|
|
|
|
appeared_callback( disk, context );
|
|
|
|
}
|
|
|
|
|
|
|
|
static void disappeared_callback( DADiskRef disk, void *context )
|
|
|
|
{
|
|
|
|
CFDictionaryRef dict = DADiskCopyDescription( disk );
|
|
|
|
const void *ref;
|
|
|
|
char device[100];
|
|
|
|
|
|
|
|
if (!dict) return;
|
|
|
|
|
|
|
|
/* ignore non-removable devices */
|
|
|
|
if (!(ref = CFDictionaryGetValue( dict, CFSTR("DAMediaRemovable") )) ||
|
2007-02-07 17:11:52 +01:00
|
|
|
!CFBooleanGetValue( ref )) goto done;
|
2006-10-03 14:54:16 +02:00
|
|
|
|
|
|
|
/* get device name */
|
2007-02-07 17:11:52 +01:00
|
|
|
if (!(ref = CFDictionaryGetValue( dict, CFSTR("DAMediaBSDName") ))) goto done;
|
2006-10-03 14:54:16 +02:00
|
|
|
strcpy( device, "/dev/r" );
|
|
|
|
CFStringGetCString( ref, device + 6, sizeof(device) - 6, kCFStringEncodingASCII );
|
|
|
|
|
2008-03-04 07:58:32 +01:00
|
|
|
TRACE( "got unmount notification for '%s'\n", device );
|
2006-10-03 14:54:16 +02:00
|
|
|
|
2008-10-23 15:44:18 +02:00
|
|
|
remove_dos_device( -1, device );
|
2007-02-07 17:11:52 +01:00
|
|
|
done:
|
2006-10-03 14:54:16 +02:00
|
|
|
CFRelease( dict );
|
|
|
|
}
|
|
|
|
|
|
|
|
static DWORD WINAPI runloop_thread( void *arg )
|
|
|
|
{
|
|
|
|
DASessionRef session = DASessionCreate( NULL );
|
|
|
|
|
|
|
|
if (!session) return 1;
|
|
|
|
|
|
|
|
DASessionScheduleWithRunLoop( session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode );
|
|
|
|
DARegisterDiskAppearedCallback( session, kDADiskDescriptionMatchVolumeMountable,
|
|
|
|
appeared_callback, NULL );
|
|
|
|
DARegisterDiskDisappearedCallback( session, kDADiskDescriptionMatchVolumeMountable,
|
|
|
|
disappeared_callback, NULL );
|
|
|
|
DARegisterDiskDescriptionChangedCallback( session, kDADiskDescriptionMatchVolumeMountable,
|
|
|
|
kDADiskDescriptionWatchVolumePath, changed_callback, NULL );
|
|
|
|
CFRunLoopRun();
|
|
|
|
DASessionUnscheduleFromRunLoop( session, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode );
|
|
|
|
CFRelease( session );
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void initialize_diskarbitration(void)
|
|
|
|
{
|
|
|
|
HANDLE handle;
|
|
|
|
|
|
|
|
if (!(handle = CreateThread( NULL, 0, runloop_thread, NULL, 0, NULL ))) return;
|
|
|
|
CloseHandle( handle );
|
|
|
|
}
|
|
|
|
|
2006-11-05 21:03:46 +01:00
|
|
|
#else /* HAVE_DISKARBITRATION_DISKARBITRATION_H */
|
2006-10-03 14:54:16 +02:00
|
|
|
|
|
|
|
void initialize_diskarbitration(void)
|
|
|
|
{
|
2008-03-04 07:58:32 +01:00
|
|
|
TRACE( "Skipping, Disk Arbitration support not compiled in\n" );
|
2006-10-03 14:54:16 +02:00
|
|
|
}
|
|
|
|
|
2006-11-05 21:03:46 +01:00
|
|
|
#endif /* HAVE_DISKARBITRATION_DISKARBITRATION_H */
|