Browse Source

Merge pull request #9673 from Chocobo1/fs_watch

Add SMB2 magic number
adaptive-webui-19844
Mike Tzou 6 years ago committed by GitHub
parent
commit
fb8fad3fa1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      src/base/filesystemwatcher.cpp
  2. 24
      src/base/utils/fs.cpp

6
src/base/filesystemwatcher.cpp

@ -40,6 +40,7 @@
#include "base/bittorrent/magneturi.h" #include "base/bittorrent/magneturi.h"
#include "base/bittorrent/torrentinfo.h" #include "base/bittorrent/torrentinfo.h"
#include "base/global.h" #include "base/global.h"
#include "base/logger.h"
#include "base/preferences.h" #include "base/preferences.h"
#include "base/utils/fs.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 // Check if the path points to a network file system or not
if (Utils::Fs::isNetworkFileSystem(path)) { if (Utils::Fs::isNetworkFileSystem(path)) {
// Network mode // Network mode
qDebug("Network folder detected: %s", qUtf8Printable(path)); LogMsg(tr("Watching remote folder: \"%1\"").arg(Utils::Fs::toNativePath(path)));
qDebug("Using file polling mode instead of inotify...");
m_watchedFolders << dir; m_watchedFolders << dir;
m_watchTimer.start(WATCH_INTERVAL); m_watchTimer.start(WATCH_INTERVAL);
@ -93,7 +93,7 @@ void FileSystemWatcher::addPath(const QString &path)
#endif #endif
// Normal mode // 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); QFileSystemWatcher::addPath(path);
scanLocalFolder(path); scanLocalFolder(path);
} }

24
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) #if defined(Q_OS_MAC) || defined(Q_OS_OPENBSD)
// XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined? // XXX: should we make sure HAVE_STRUCT_FSSTAT_F_FSTYPENAME is defined?
return ((strncmp(buf.f_fstypename, "nfs", sizeof(buf.f_fstypename)) == 0) return ((strncmp(buf.f_fstypename, "cifs", sizeof(buf.f_fstypename)) == 0)
|| (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)); || (strncmp(buf.f_fstypename, "smbfs", sizeof(buf.f_fstypename)) == 0));
#else #else
// usually defined in /usr/include/linux/magic.h // Magic number references:
const unsigned long CIFS_MAGIC_NUMBER = 0xFF534D42; // 1. /usr/include/linux/magic.h
const unsigned long NFS_SUPER_MAGIC = 0x6969; // 2. https://github.com/coreutils/coreutils/blob/master/src/stat.c
const unsigned long SMB_SUPER_MAGIC = 0x517B; switch (buf.f_type) {
case 0xFF534D42: // CIFS_MAGIC_NUMBER
return ((buf.f_type == CIFS_MAGIC_NUMBER) case 0x6969: // NFS_SUPER_MAGIC
|| (buf.f_type == NFS_SUPER_MAGIC) case 0x517B: // SMB_SUPER_MAGIC
|| (buf.f_type == SMB_SUPER_MAGIC)); case 0xFE534D42: // S_MAGIC_SMB2
return true;
default:
return false;
}
#endif #endif
} }
#endif #endif

Loading…
Cancel
Save