OS X memory card driver.
This commit is contained in:
@@ -11,6 +11,7 @@ struct UsbStorageDevice
|
|||||||
iBus = -1;
|
iBus = -1;
|
||||||
iPort = -1;
|
iPort = -1;
|
||||||
iLevel = -1;
|
iLevel = -1;
|
||||||
|
iRefNum = -1;
|
||||||
sDevice = "";
|
sDevice = "";
|
||||||
sSerial = "<none>"; // be different than a card with no serial
|
sSerial = "<none>"; // be different than a card with no serial
|
||||||
sOsMountDir = "";
|
sOsMountDir = "";
|
||||||
@@ -27,6 +28,7 @@ struct UsbStorageDevice
|
|||||||
int iBus;
|
int iBus;
|
||||||
int iPort;
|
int iPort;
|
||||||
int iLevel;
|
int iLevel;
|
||||||
|
int iRefNum;
|
||||||
CString sSerial;
|
CString sSerial;
|
||||||
CString sDevice;
|
CString sDevice;
|
||||||
CString sOsMountDir; // WITHOUT trailing slash
|
CString sOsMountDir; // WITHOUT trailing slash
|
||||||
|
|||||||
@@ -0,0 +1,98 @@
|
|||||||
|
#include "global.h"
|
||||||
|
#include "MemoryCardDriverThreaded_OSX.h"
|
||||||
|
#include "archutils/Darwin/DarwinMCHelpers.h"
|
||||||
|
#include "Foreach.h"
|
||||||
|
#include "RageUtil.h"
|
||||||
|
#include "RageLog.h"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
|
|
||||||
|
void MemoryCardDriverThreaded_OSX::Flush( UsbStorageDevice *pDevice )
|
||||||
|
{
|
||||||
|
if( pDevice->iRefNum == -1 )
|
||||||
|
return;
|
||||||
|
|
||||||
|
ParamBlockRec pb;
|
||||||
|
|
||||||
|
memset( &pb, 0, sizeof(pb) );
|
||||||
|
pb.volumeParam.ioNamePtr = NULL;
|
||||||
|
pb.volumeParam.ioVRefNum = pDevice->iRefNum;
|
||||||
|
|
||||||
|
if( PBFlushVolSync(&pb) != noErr )
|
||||||
|
LOG->Warn( "Failed to flush the memory card." );
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryCardDriverThreaded_OSX::GetUSBStorageDevices( vector<UsbStorageDevice>& vDevicesOut )
|
||||||
|
{
|
||||||
|
LOG->Trace( "GetUSBStorageDevices." );
|
||||||
|
vector<CString> vDevicePaths;
|
||||||
|
|
||||||
|
DarwinMCHelpers::GetRemovableDevicePaths( vDevicePaths );
|
||||||
|
FOREACH( CString, vDevicePaths, i )
|
||||||
|
{
|
||||||
|
vDevicesOut.push_back( UsbStorageDevice() );
|
||||||
|
|
||||||
|
const CString& path = *i;
|
||||||
|
UsbStorageDevice& usbd = vDevicesOut.back();
|
||||||
|
|
||||||
|
LOG->Trace( "Found memory card at path: %s.", path.c_str() );
|
||||||
|
usbd.SetOsMountDir( path );
|
||||||
|
|
||||||
|
// Find volume size.
|
||||||
|
XVolumeParam param;
|
||||||
|
Str255 name; // A pascal string.
|
||||||
|
const CString& base = Basename(path);
|
||||||
|
|
||||||
|
memset( ¶m, 0, sizeof(param) );
|
||||||
|
name[0] = min( base.length(), size_t(255) );
|
||||||
|
strncpy( (char *)&name[1], base, name[0] );
|
||||||
|
param.ioNamePtr = name;
|
||||||
|
param.ioVolIndex = -1; // Use ioNamePtr to find the volume.
|
||||||
|
|
||||||
|
if( PBXGetVolInfoSync(¶m) == noErr )
|
||||||
|
{
|
||||||
|
usbd.iVolumeSizeMB = param.ioVTotalBytes >> 20;
|
||||||
|
usbd.iRefNum = param.ioVRefNum;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
usbd.SetError( "Failed to get volume info." );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MemoryCardDriverThreaded_OSX::TestWrite( UsbStorageDevice *pDevice )
|
||||||
|
{
|
||||||
|
if( access(pDevice->sOsMountDir, W_OK) )
|
||||||
|
{
|
||||||
|
pDevice->SetError( "Write test failed." );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) 2005 Steve Checkoway
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||||
|
* whom the Software is furnished to do so, provided that the above
|
||||||
|
* copyright notice(s) and this permission notice appear in all copies of
|
||||||
|
* the Software and that both the above copyright notice(s) and this
|
||||||
|
* permission notice appear in supporting documentation.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||||
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||||
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||||
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||||
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
#ifndef MEMORY_CARD_DRIVER_THREADED_OSX
|
||||||
|
#define MEMORY_CARD_DRIVER_THREADED_OSX
|
||||||
|
|
||||||
|
#include "MemoryCardDriver.h"
|
||||||
|
|
||||||
|
class MemoryCardDriverThreaded_OSX : public MemoryCardDriver
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool Mount( UsbStorageDevice *pDevice ) { return true; }
|
||||||
|
void Unmount( UsbStorageDevice *pDevice ) { }
|
||||||
|
void Flush( UsbStorageDevice *pDevice );
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void GetUSBStorageDevices( vector<UsbStorageDevice>& vStorageDevicesOut );
|
||||||
|
bool TestWrite( UsbStorageDevice *pDevice );
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifdef ARCH_MEMORY_CARD_DRIVER
|
||||||
|
#error "More than one MemoryCardDriver selected!"
|
||||||
|
#endif
|
||||||
|
#define ARCH_MEMORY_CARD_DRIVER MemoryCardDriverThreaded_OSX
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) 2005 Steve Checkoway
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||||
|
* whom the Software is furnished to do so, provided that the above
|
||||||
|
* copyright notice(s) and this permission notice appear in all copies of
|
||||||
|
* the Software and that both the above copyright notice(s) and this
|
||||||
|
* permission notice appear in supporting documentation.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||||
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||||
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||||
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||||
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef DARWIN_MC_HELPERS
|
||||||
|
#define DARWIN_MC_HELPERS
|
||||||
|
|
||||||
|
namespace DarwinMCHelpers
|
||||||
|
{
|
||||||
|
void GetRemovableDevicePaths( vector<CString> vDevicePaths );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (c) 2005 Steve Checkoway
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
* copy of this software and associated documentation files (the
|
||||||
|
* "Software"), to deal in the Software without restriction, including
|
||||||
|
* without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
* distribute, and/or sell copies of the Software, and to permit persons to
|
||||||
|
* whom the Software is furnished to do so, provided that the above
|
||||||
|
* copyright notice(s) and this permission notice appear in all copies of
|
||||||
|
* the Software and that both the above copyright notice(s) and this
|
||||||
|
* permission notice appear in supporting documentation.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
|
||||||
|
* THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
|
||||||
|
* INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
|
||||||
|
* OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
||||||
|
* OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||||
|
* OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||||
|
* PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
Reference in New Issue
Block a user