From 25a0147f614e66b6063f3b1fb4453ae748f774e7 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 10 Oct 2018 09:52:35 +0800 Subject: [PATCH 1/2] Add SMB2 magic number Closes #9671. --- src/base/utils/fs.cpp | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/base/utils/fs.cpp b/src/base/utils/fs.cpp index a889ac4a5..e4d361795 100644 --- a/src/base/utils/fs.cpp +++ b/src/base/utils/fs.cpp @@ -315,18 +315,22 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path) #if defined(Q_OS_MAC) || defined(Q_OS_OPENBSD) // XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined? - return ((strncmp(buf.f_fstypename, "nfs", sizeof(buf.f_fstypename)) == 0) - || (strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0) + return ((strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0) + || (strncmp(buf.f_fstypename, "nfs", sizeof(buf.f_fstypename)) == 0) || (strncmp(buf.f_fstypename, "smbfs", sizeof(buf.f_fstypename)) == 0)); #else - // usually defined in /usr/include/linux/magic.h - const unsigned long CIFS_MAGIC_NUMBER = 0xFF534D42; - const unsigned long NFS_SUPER_MAGIC = 0x6969; - const unsigned long SMB_SUPER_MAGIC = 0x517B; - - return ((buf.f_type == CIFS_MAGIC_NUMBER) - || (buf.f_type == NFS_SUPER_MAGIC) - || (buf.f_type == SMB_SUPER_MAGIC)); + // Magic number references: + // 1. /usr/include/linux/magic.h + // 2. https://github.com/coreutils/coreutils/blob/master/src/stat.c + switch (buf.f_type) { + case 0xFF534D42: // CIFS_MAGIC_NUMBER + case 0x6969: // NFS_SUPER_MAGIC + case 0x517B: // SMB_SUPER_MAGIC + case 0xFE534D42: // S_MAGIC_SMB2 + return true; + default: + return false; + } #endif } #endif From 9b552c463fefa548e43e79839548e44c280b74b6 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 10 Oct 2018 10:25:24 +0800 Subject: [PATCH 2/2] Add FileSystemWatcher log messages --- src/base/filesystemwatcher.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/base/filesystemwatcher.cpp b/src/base/filesystemwatcher.cpp index 9ce72bbb1..550a7f6a0 100644 --- a/src/base/filesystemwatcher.cpp +++ b/src/base/filesystemwatcher.cpp @@ -40,6 +40,7 @@ #include "base/bittorrent/magneturi.h" #include "base/bittorrent/torrentinfo.h" #include "base/global.h" +#include "base/logger.h" #include "base/preferences.h" #include "base/utils/fs.h" @@ -83,8 +84,7 @@ void FileSystemWatcher::addPath(const QString &path) // Check if the path points to a network file system or not if (Utils::Fs::isNetworkFileSystem(path)) { // Network mode - qDebug("Network folder detected: %s", qUtf8Printable(path)); - qDebug("Using file polling mode instead of inotify..."); + LogMsg(tr("Watching remote folder: \"%1\"").arg(Utils::Fs::toNativePath(path))); m_watchedFolders << dir; m_watchTimer.start(WATCH_INTERVAL); @@ -93,7 +93,7 @@ void FileSystemWatcher::addPath(const QString &path) #endif // Normal mode - qDebug("FS Watcher is watching %s in normal mode", qUtf8Printable(path)); + LogMsg(tr("Watching local folder: \"%1\"").arg(Utils::Fs::toNativePath(path))); QFileSystemWatcher::addPath(path); scanLocalFolder(path); }