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 @@ @@ -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) @@ -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) @@ -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);
}

24
src/base/utils/fs.cpp

@ -315,18 +315,22 @@ bool Utils::Fs::isNetworkFileSystem(const QString &path) @@ -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

Loading…
Cancel
Save