diff --git a/src/engine/fsutils.cpp b/src/engine/fsutils.cpp index 46bb04bd..3f42f7f0 100644 --- a/src/engine/fsutils.cpp +++ b/src/engine/fsutils.cpp @@ -1,118 +1,85 @@ /* * Copyright (C) 2010 Tobias Koenig * Copyright (C) 2014 Daniel Vrátil * Copyright (C) 2015 Vishesh Handa * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "fsutils.h" #include #ifdef Q_OS_LINUX #include #include -#include #include #include #endif using namespace Baloo; -QString FSUtils::getDirectoryFileSystem(const QString &directory) -{ -#ifndef Q_OS_LINUX - return QString(); -#else - QString bestMatchPath; - QString bestMatchFS; - - FILE *mtab = setmntent("/etc/mtab", "r"); - if (!mtab) { - return QString(); - } - while (mntent *mnt = getmntent(mtab)) { - if (qstrcmp(mnt->mnt_type, MNTTYPE_IGNORE) == 0) { - continue; - } - - const QString dir = QString::fromLocal8Bit(mnt->mnt_dir); - if (!directory.startsWith(dir) || dir.length() < bestMatchPath.length()) { - continue; - } - - bestMatchPath = dir; - bestMatchFS = QString::fromLocal8Bit(mnt->mnt_type); - } - - endmntent(mtab); - - return bestMatchFS; -#endif -} - void FSUtils::disableCoW(const QString &path) { #ifndef Q_OS_LINUX Q_UNUSED(path); #else // from linux/fs.h, so that Baloo does not depend on Linux header files #ifndef FS_IOC_GETFLAGS #define FS_IOC_GETFLAGS _IOR('f', 1, long) #endif #ifndef FS_IOC_SETFLAGS #define FS_IOC_SETFLAGS _IOW('f', 2, long) #endif // Disable COW on file #ifndef FS_NOCOW_FL #define FS_NOCOW_FL 0x00800000 #endif ulong flags = 0; const int fd = open(qPrintable(path), O_RDONLY); if (fd == -1) { qWarning() << "Failed to open" << path << "to modify flags (" << errno << ")"; return; } if (ioctl(fd, FS_IOC_GETFLAGS, &flags) == -1) { const int errno_ioctl = errno; // ignore ENOTTY, filesystem does not support attrs (and likely neither supports COW) if (errno_ioctl != ENOTTY) { qWarning() << "ioctl error: failed to get file flags (" << errno_ioctl << ")"; } close(fd); return; } if (!(flags & FS_NOCOW_FL)) { flags |= FS_NOCOW_FL; if (ioctl(fd, FS_IOC_SETFLAGS, &flags) == -1) { const int errno_ioctl = errno; // ignore EOPNOTSUPP, returned on filesystems not supporting COW if (errno_ioctl != EOPNOTSUPP) { qWarning() << "ioctl error: failed to set file flags (" << errno_ioctl << ")"; } close(fd); return; } } close(fd); #endif } diff --git a/src/engine/fsutils.h b/src/engine/fsutils.h index ddd5712d..ae6642dd 100644 --- a/src/engine/fsutils.h +++ b/src/engine/fsutils.h @@ -1,47 +1,40 @@ /* * This file is part of the KDE Baloo Project * Copyright (C) 2015 Vishesh Handa * Copyright (C) 2010 Tobias Koenig * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . * */ #ifndef BALOO_ENGINE_FSUTILS_H #define BALOO_ENGINE_FSUTILS_H #include namespace Baloo { namespace FSUtils { -/** - * Returns name of filesystem that @p directory is stored on. This - * only works on Linux and returns empty string on other platforms or when it's - * unable to detect the filesystem. - */ -QString getDirectoryFileSystem(const QString &directory); - /** * Disables filesystem copy-on-write feature on given file or directory. * Only implemented on Linux and does nothing on other platforms. */ void disableCoW(const QString &path); } } #endif