From c90b86b9b7c87865c12a0069ca5e82ec84dc61f2 Mon Sep 17 00:00:00 2001 From: Jason Ferrara Date: Wed, 9 May 2012 20:37:46 +0000 Subject: [PATCH] Fix background mode in osx. --- INSTALL | 8 +++-- NEWS | 4 +++ README | 2 +- configure | 1 - configure.ac | 1 - src/ConnectedMtpDevices.cpp | 5 +++ src/ConnectedMtpDevices.h | 1 + src/MtpDevice.cpp | 6 ++++ src/MtpDevice.h | 3 ++ src/jmtpfs.cpp | 65 ++++++++++++++++++++----------------- 10 files changed, 61 insertions(+), 35 deletions(-) diff --git a/INSTALL b/INSTALL index 609ddfa..7c41418 100644 --- a/INSTALL +++ b/INSTALL @@ -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 ================== diff --git a/NEWS b/NEWS index 927f444..9ad0ab6 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +5/9/2012 + +v0.2 released. Now works under Mac OS X. + 5/7/2012 Initial 0.1 release. \ No newline at end of file diff --git a/README b/README index d70400f..4f6d5ad 100644 --- a/README +++ b/README @@ -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 diff --git a/configure b/configure index 38dc200..94503d5 100755 --- a/configure +++ b/configure @@ -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' diff --git a/configure.ac b/configure.ac index ab66a2c..c896409 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,6 @@ AC_INIT(jmtpfs, 1.0) AC_CANONICAL_SYSTEM AM_INIT_AUTOMAKE() -AX_CXX_COMPILE_STDCXX_0X AC_PROG_CXX diff --git a/src/ConnectedMtpDevices.cpp b/src/ConnectedMtpDevices.cpp index 51ebe73..aaa8210 100644 --- a/src/ConnectedMtpDevices.cpp +++ b/src/ConnectedMtpDevices.cpp @@ -56,6 +56,11 @@ MtpLibLock lock; return std::unique_ptr(new MtpDevice(m_devs[index])); } +LIBMTP_raw_device_t& ConnectedMtpDevices::GetRawDeviceEntry(int index) +{ + return m_devs[index]; +} + ConnectedMtpDevices::~ConnectedMtpDevices() { MtpLibLock lock; diff --git a/src/ConnectedMtpDevices.h b/src/ConnectedMtpDevices.h index b20de01..b0c1ba5 100644 --- a/src/ConnectedMtpDevices.h +++ b/src/ConnectedMtpDevices.h @@ -44,6 +44,7 @@ public: int NumDevices(); std::unique_ptr GetDevice(int index); ConnectedDeviceInfo GetDeviceInfo(int index); + LIBMTP_raw_device_t& GetRawDeviceEntry(int index); protected: static bool m_instantiated; diff --git a/src/MtpDevice.cpp b/src/MtpDevice.cpp index f7dbae7..e5be121 100644 --- a/src/MtpDevice.cpp +++ b/src/MtpDevice.cpp @@ -20,6 +20,7 @@ */ #include "MtpDevice.h" #include "MtpLibLock.h" +#include "ConnectedMtpDevices.h" #include #include #include @@ -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 MtpDevice::GetStorageDevices() { MtpLibLock lock; + std::cout << "get storage devices " << std::endl; if (LIBMTP_Get_Storage(m_mtpdevice, LIBMTP_STORAGE_SORTBY_NOTSORTED)) { CheckErrors(true); diff --git a/src/MtpDevice.h b/src/MtpDevice.h index e108d4e..b8a6154 100644 --- a/src/MtpDevice.h +++ b/src/MtpDevice.h @@ -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]; }; diff --git a/src/jmtpfs.cpp b/src/jmtpfs.cpp index 3d68247..056f2df 100644 --- a/src/jmtpfs.cpp +++ b/src/jmtpfs.cpp @@ -32,7 +32,7 @@ #include #include -#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 currentDevice; MtpMetadataCache* metadataCache; std::unique_ptr 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 device; std::unique_ptr 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(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;