diff --git a/src/simple-mtpfs-fuse.cpp b/src/simple-mtpfs-fuse.cpp index c6a9516..00c73f1 100644 --- a/src/simple-mtpfs-fuse.cpp +++ b/src/simple-mtpfs-fuse.cpp @@ -298,12 +298,6 @@ bool SMTPFileSystem::parseOptions(int argc, char **argv) return true; } - if (--m_options.m_device_no < 0) { - logerr("Device number must be positive number greater than 0.\n"); - m_options.m_good = false; - return false; - } - if (!m_options.m_mount_point) { logerr("Mount point missing.\n"); m_options.m_good = false; @@ -318,6 +312,8 @@ bool SMTPFileSystem::parseOptions(int argc, char **argv) fuse_opt_add_arg(&m_args, "-f"); } + --m_options.m_device_no; + #ifdef HAVE_LIBUSB1 // device file and -- device are mutually exclusive, fail if both set if (m_options.m_device_no && m_options.m_device_file) { @@ -388,18 +384,14 @@ bool SMTPFileSystem::exec() #ifdef HAVE_LIBUSB1 if (m_options.m_device_file) { // Try to use device file first, if provided - if (!m_device.connect(m_options.m_device_file)) { - logerr("Can not connect to device '", m_options.m_device_file, "'.\n"); + if (!m_device.connect(m_options.m_device_file)) return false; - } } else #endif // HAVE_LIBUSB1 { // Connect to MTP device by order number, if no device file supplied - if (!m_device.connect(m_options.m_device_no)) { - logerr("Can not connect to device no. ", m_options.m_device_no, ".\n"); + if (!m_device.connect(m_options.m_device_no)) return false; - } } m_device.enableMove(m_options.m_enable_move); if (fuse_main(m_args.argc, m_args.argv, &m_fuse_operations, nullptr) > 0) { diff --git a/src/simple-mtpfs-mtp-device.cpp b/src/simple-mtpfs-mtp-device.cpp index 4a940ed..9e9926f 100644 --- a/src/simple-mtpfs-mtp-device.cpp +++ b/src/simple-mtpfs-mtp-device.cpp @@ -63,9 +63,10 @@ bool MTPDevice::connect(int dev_no) StreamHelper::off(); LIBMTP_error_number_t err = LIBMTP_Detect_Raw_Devices( &raw_devices, &raw_devices_cnt); - StreamHelper::off(); + StreamHelper::on(); - if (dev_no > raw_devices_cnt) { + if (dev_no < 0 || dev_no >= raw_devices_cnt) { + logerr("Can not connect to device no. ", dev_no + 1, ".\n"); free(static_cast(raw_devices)); return false; } @@ -121,7 +122,7 @@ bool MTPDevice::connect(const std::string &dev_file) LIBMTP_raw_device_t *device = smtpfs_raw_device_new(dev_file); if (!device) { - logerr("Could not open such device '", dev_file, ".\n"); + logerr("Can not open such device '", dev_file, "'.\n"); return false; }