diff --git a/man/simple-mtpfs.1 b/man/simple-mtpfs.1 index 4b3ae09..470a48e 100644 --- a/man/simple-mtpfs.1 +++ b/man/simple-mtpfs.1 @@ -30,7 +30,7 @@ print version .SS "SIMPLE-MTPFS options:" .TP \fB\-l\fR \fB\-\-list\-devices\fR -list available MTP devices +list available MTP devices. Supports \fB\fR option .TP \fB\-\-device\fR select device no. to mount diff --git a/src/simple-mtpfs-fuse.cpp b/src/simple-mtpfs-fuse.cpp index 46c3d90..bda3cd2 100644 --- a/src/simple-mtpfs-fuse.cpp +++ b/src/simple-mtpfs-fuse.cpp @@ -180,15 +180,16 @@ int SMTPFileSystem::SMTPFileSystemOptions::opt_proc(void *data, const char *arg, SMTPFileSystemOptions *options = static_cast(data); if (key == FUSE_OPT_KEY_NONOPT) { - if (options->m_mount_point && !options->m_device_file) { - options->m_device_file = options->m_mount_point; - options->m_mount_point = nullptr; - } else if (options->m_mount_point && options->m_device_file) { + if (options->m_mount_point && options->m_device_file) { // Unknown positional argument supplied return -1; } + if (options->m_device_file) { + fuse_opt_add_opt(&options->m_mount_point, arg); + return 0; + } - fuse_opt_add_opt(&options->m_mount_point, arg); + fuse_opt_add_opt(&options->m_device_file, arg); return 0; } return 1; @@ -287,6 +288,11 @@ bool SMTPFileSystem::parseOptions(int argc, char **argv) return true; } + if (m_options.m_device_file && !m_options.m_mount_point) { + m_options.m_mount_point = m_options.m_device_file; + m_options.m_device_file = nullptr; + } + if (!m_options.m_mount_point) { logerr("Mount point missing.\n"); m_options.m_good = false; @@ -326,7 +332,7 @@ void SMTPFileSystem::printHelp() const << " -V --version print version\n\n" << "simple-mtpfs options:\n" << " -v --verbose verbose output, implies -f\n" - << " -l --list-devices print available devices\n" + << " -l --list-devices print available devices. Supports option\n" << " --device select a device number to mount\n" << " -o enable-move enable the move operations\n\n"; fuse_opt_add_arg(&args, m_args.argv[0]); @@ -350,7 +356,9 @@ void SMTPFileSystem::printVersion() const bool SMTPFileSystem::listDevices() const { - return MTPDevice::listDevices(m_options.m_verbose); + const std::string dev_file = m_options.m_device_file ? m_options.m_device_file : ""; + + return MTPDevice::listDevices(m_options.m_verbose, dev_file); } bool SMTPFileSystem::exec() diff --git a/src/simple-mtpfs-mtp-device.cpp b/src/simple-mtpfs-mtp-device.cpp index a95db41..e447441 100644 --- a/src/simple-mtpfs-mtp-device.cpp +++ b/src/simple-mtpfs-mtp-device.cpp @@ -646,10 +646,11 @@ MTPDevice::Capabilities MTPDevice::getCapabilities(const MTPDevice &device) return capabilities; } -bool MTPDevice::listDevices(bool verbose) +bool MTPDevice::listDevices(bool verbose, const std::string &dev_file) { int raw_devices_cnt; LIBMTP_raw_device_t *raw_devices; + std::string dev_path; // Do not output LIBMTP debug stuff StreamHelper::off(); @@ -663,7 +664,18 @@ bool MTPDevice::listDevices(bool verbose) return false; } + if (!dev_file.empty()) { + dev_path = smtpfs_realpath(dev_file); + if (dev_path.empty()) { + std::cerr << "Can not open such device '" << dev_file << "'.\n"; + return false; + } + } + for (int i = 0; i < raw_devices_cnt; ++i) { + if (!dev_file.empty() && + dev_path != smtpfs_usb_devpath(raw_devices[i].bus_location, raw_devices[i].devnum)) + continue; std::cout << i + 1 << ": " << (raw_devices[i].device_entry.vendor ? raw_devices[i].device_entry.vendor : "Unknown vendor ") << (raw_devices[i].device_entry.product ? raw_devices[i].device_entry.product : "Unknown product") diff --git a/src/simple-mtpfs-mtp-device.h b/src/simple-mtpfs-mtp-device.h index c7776e6..f81a447 100644 --- a/src/simple-mtpfs-mtp-device.h +++ b/src/simple-mtpfs-mtp-device.h @@ -85,7 +85,7 @@ public: Capabilities getCapabilities() const; - static bool listDevices(bool verbose = false); + static bool listDevices(bool verbose, const std::string &dev_file); private: void criticalEnter() { m_device_mutex.lock(); }