Fix background mode in osx.

This commit is contained in:
Jason Ferrara 2012-05-09 20:37:46 +00:00
parent a21fe32630
commit c90b86b9b7
10 changed files with 61 additions and 35 deletions

View File

@ -11,8 +11,12 @@ without warranty of any kind.
Requirements for building
=========================
FUSE, libmtp, and libmagic development libraries and headers.
And install of gcc that supported the C++11 standard.
FUSE, libmtp, and libmagic (file-devel in Fedora yum and file in macports)
development libraries and headers.
An install of gcc that supports the C++11 standard.
The build has been tested under Fedora 16 with the requirements installed via
yum and under Mac OS X Lion with the requirements installed via macports.
Basic Installation
==================

4
NEWS
View File

@ -1,3 +1,7 @@
5/9/2012
v0.2 released. Now works under Mac OS X.
5/7/2012
Initial 0.1 release.

2
README
View File

@ -2,7 +2,7 @@ jmtpfs:
jmtpfs is a FUSE and libmtp based filesystem for accessing MTP (Media Transfer
Protocol) devices. It was specifically designed for exchaning files between
Linux systems and newer Android devices that support MTP but not USB Mass
Linux (and Mac OS X) systems and newer Android devices that support MTP but not USB Mass
Storage.
The goal is to create a well behaved filesystem, allowing tools like find and

1
configure vendored
View File

@ -2765,7 +2765,6 @@ am__tar='${AMTAR} chof - "$$tardir"'; am__untar='${AMTAR} xf -'
AX_CXX_COMPILE_STDCXX_0X
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'

View File

@ -7,7 +7,6 @@ AC_INIT(jmtpfs, 1.0)
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE()
AX_CXX_COMPILE_STDCXX_0X
AC_PROG_CXX

View File

@ -56,6 +56,11 @@ MtpLibLock lock;
return std::unique_ptr<MtpDevice>(new MtpDevice(m_devs[index]));
}
LIBMTP_raw_device_t& ConnectedMtpDevices::GetRawDeviceEntry(int index)
{
return m_devs[index];
}
ConnectedMtpDevices::~ConnectedMtpDevices()
{
MtpLibLock lock;

View File

@ -44,6 +44,7 @@ public:
int NumDevices();
std::unique_ptr<MtpDevice> GetDevice(int index);
ConnectedDeviceInfo GetDeviceInfo(int index);
LIBMTP_raw_device_t& GetRawDeviceEntry(int index);
protected:
static bool m_instantiated;

View File

@ -20,6 +20,7 @@
*/
#include "MtpDevice.h"
#include "MtpLibLock.h"
#include "ConnectedMtpDevices.h"
#include <sys/stat.h>
#include <unistd.h>
#include <algorithm>
@ -62,9 +63,13 @@ MtpDevice::MtpDevice(LIBMTP_raw_device_t& rawDevice)
{
MtpLibLock lock;
std::cout << "opening device" << std::endl;
m_mtpdevice = LIBMTP_Open_Raw_Device_Uncached(&rawDevice);
if (m_mtpdevice == 0)
throw MtpErrorCantOpenDevice();
m_busLocation = rawDevice.bus_location;
m_devnum = rawDevice.devnum;
LIBMTP_Clear_Errorstack(m_mtpdevice);
m_magicCookie = magic_open(MAGIC_MIME_TYPE);
if (m_magicCookie == 0)
@ -104,6 +109,7 @@ std::vector<MtpStorageInfo> MtpDevice::GetStorageDevices()
{
MtpLibLock lock;
std::cout << "get storage devices " << std::endl;
if (LIBMTP_Get_Storage(m_mtpdevice, LIBMTP_STORAGE_SORTBY_NOTSORTED))
{
CheckErrors(true);

View File

@ -132,9 +132,12 @@ public:
void SetObjectProperty(uint32_t id, LIBMTP_property_t property, const std::string& value);
static LIBMTP_filetype_t PropertyTypeFromMimeType(const std::string& mimeType);
protected:
void CheckErrors(bool throwEvenIfNoError);
LIBMTP_mtpdevice_t* m_mtpdevice;
uint32_t m_busLocation;
uint8_t m_devnum;
magic_t m_magicCookie;
char m_magicBuffer[MAGIC_BUFFER_SIZE];
};

View File

@ -32,7 +32,7 @@
#include <iomanip>
#include <assert.h>
#define JMTPFS_VERSION "0.1"
#define JMTPFS_VERSION "0.2"
using namespace std;
@ -68,8 +68,9 @@ RecursiveMutex globalLock;
return -EIO; \
}
MtpDevice* currentDevice;
int requestedBusLocation=-1;
int requestedDevnum=-1;
std::unique_ptr<MtpDevice> currentDevice;
MtpMetadataCache* metadataCache;
std::unique_ptr<MtpNode> getNode(const FilesystemPath& path)
@ -268,6 +269,32 @@ extern "C" int jmtpfs_statfs(const char *pathStr, struct statvfs *stat)
FUSE_ERROR_BLOCK_END
}
extern "C" void* jmtpfs_init(struct fuse_conn_info *conn)
{
currentDevice = 0;
ConnectedMtpDevices devices;
if (devices.NumDevices()==0)
{
std::cerr << "No mtp devices found." << std::endl;
throw std::runtime_error("No mtp devices found");
}
for(int i = 0; i<devices.NumDevices(); i++)
{
ConnectedDeviceInfo devInfo = devices.GetDeviceInfo(i);
if (((devInfo.bus_location == requestedBusLocation) &&
(devInfo.devnum == requestedDevnum)) ||
(requestedBusLocation == -1) || (requestedDevnum == -1))
{
currentDevice = devices.GetDevice(i);
break;
}
}
if (currentDevice == 0)
{
std::cerr << "Requested device not found" << std::endl;
throw std::runtime_error("Requested device not found");
}
}
struct jmtpfs_options
{
@ -296,7 +323,6 @@ static struct fuse_operations jmtpfs_oper = {
int main(int argc, char *argv[])
{
std::unique_ptr<MtpDevice> device;
std::unique_ptr<MtpMetadataCache> cache;
LIBMTP_Init();
@ -314,6 +340,7 @@ int main(int argc, char *argv[])
jmtpfs_oper.flush = jmtpfs_flush;
jmtpfs_oper.rename = jmtpfs_rename;
jmtpfs_oper.statfs = jmtpfs_statfs;
jmtpfs_oper.init = jmtpfs_init;
jmtpfs_options options;
@ -344,8 +371,8 @@ int main(int argc, char *argv[])
return 0;
}
int requestedBusLocation=-1;
int requestedDevnum=-1;
requestedBusLocation=-1;
requestedDevnum=-1;
if (options.device)
{
std::string devstr(options.device);
@ -375,30 +402,6 @@ int main(int argc, char *argv[])
}
else
{
currentDevice = 0;
ConnectedMtpDevices devices;
if (devices.NumDevices()==0)
{
std::cerr << "No mtp devices found." << std::endl;
return -1;
}
for(int i = 0; i<devices.NumDevices(); i++)
{
ConnectedDeviceInfo devInfo = devices.GetDeviceInfo(i);
if (((devInfo.bus_location == requestedBusLocation) &&
(devInfo.devnum == requestedDevnum)) ||
(requestedBusLocation == -1) || (requestedDevnum == -1))
{
device = devices.GetDevice(i);
currentDevice = device.get();
break;
}
}
if (currentDevice == 0)
{
std::cerr << "Requested device not found" << std::endl;
return -1;
}
cache = std::unique_ptr<MtpMetadataCache>(new MtpMetadataCache);
metadataCache = cache.get();
}
@ -409,6 +412,8 @@ int main(int argc, char *argv[])
}
int result = fuse_main(args.argc, args.argv, &jmtpfs_oper, 0);
currentDevice.reset();
if (options.displayHelp)
{
std::cout << std::endl << "jmtpfs options:" << std::endl;