| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qstorageinfo_unix.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2014 Ivan Komissarov <ABBAPOH@gmail.com> | - | ||||||||||||
| 4 | ** Copyright (C) 2016 Intel Corporation. | - | ||||||||||||
| 5 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
| 6 | ** | - | ||||||||||||
| 7 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||
| 8 | ** | - | ||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 16 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
| 17 | ** | - | ||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 20 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
| 22 | ** packaging of this file. Please review the following information to | - | ||||||||||||
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
| 25 | ** | - | ||||||||||||
| 26 | ** GNU General Public License Usage | - | ||||||||||||
| 27 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
| 28 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
| 29 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
| 30 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
| 32 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
| 33 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
| 36 | ** | - | ||||||||||||
| 37 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 38 | ** | - | ||||||||||||
| 39 | ****************************************************************************/ | - | ||||||||||||
| 40 | - | |||||||||||||
| 41 | #include "qstorageinfo_p.h" | - | ||||||||||||
| 42 | - | |||||||||||||
| 43 | #include <QtCore/qdiriterator.h> | - | ||||||||||||
| 44 | #include <QtCore/qfileinfo.h> | - | ||||||||||||
| 45 | #include <QtCore/qtextstream.h> | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | #include <QtCore/private/qcore_unix_p.h> | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | #include <errno.h> | - | ||||||||||||
| 50 | #include <sys/stat.h> | - | ||||||||||||
| 51 | - | |||||||||||||
| 52 | #if defined(Q_OS_BSD4) | - | ||||||||||||
| 53 | # include <sys/mount.h> | - | ||||||||||||
| 54 | # include <sys/statvfs.h> | - | ||||||||||||
| 55 | #elif defined(Q_OS_ANDROID) | - | ||||||||||||
| 56 | # include <sys/mount.h> | - | ||||||||||||
| 57 | # include <sys/vfs.h> | - | ||||||||||||
| 58 | # include <mntent.h> | - | ||||||||||||
| 59 | #elif defined(Q_OS_LINUX) || defined(Q_OS_HURD) | - | ||||||||||||
| 60 | # include <mntent.h> | - | ||||||||||||
| 61 | # include <sys/statvfs.h> | - | ||||||||||||
| 62 | #elif defined(Q_OS_SOLARIS) | - | ||||||||||||
| 63 | # include <sys/mnttab.h> | - | ||||||||||||
| 64 | # include <sys/statvfs.h> | - | ||||||||||||
| 65 | #elif defined(Q_OS_HAIKU) | - | ||||||||||||
| 66 | # include <Directory.h> | - | ||||||||||||
| 67 | # include <Path.h> | - | ||||||||||||
| 68 | # include <Volume.h> | - | ||||||||||||
| 69 | # include <VolumeRoster.h> | - | ||||||||||||
| 70 | # include <fs_info.h> | - | ||||||||||||
| 71 | # include <sys/statvfs.h> | - | ||||||||||||
| 72 | #else | - | ||||||||||||
| 73 | # include <sys/statvfs.h> | - | ||||||||||||
| 74 | #endif | - | ||||||||||||
| 75 | - | |||||||||||||
| 76 | #if defined(Q_OS_BSD4) | - | ||||||||||||
| 77 | # if defined(Q_OS_NETBSD) | - | ||||||||||||
| 78 | # define QT_STATFSBUF struct statvfs | - | ||||||||||||
| 79 | # define QT_STATFS ::statvfs | - | ||||||||||||
| 80 | # else | - | ||||||||||||
| 81 | # define QT_STATFSBUF struct statfs | - | ||||||||||||
| 82 | # define QT_STATFS ::statfs | - | ||||||||||||
| 83 | # endif | - | ||||||||||||
| 84 | - | |||||||||||||
| 85 | # if !defined(ST_RDONLY) | - | ||||||||||||
| 86 | # define ST_RDONLY MNT_RDONLY | - | ||||||||||||
| 87 | # endif | - | ||||||||||||
| 88 | # if !defined(_STATFS_F_FLAGS) && !defined(Q_OS_NETBSD) | - | ||||||||||||
| 89 | # define _STATFS_F_FLAGS 1 | - | ||||||||||||
| 90 | # endif | - | ||||||||||||
| 91 | #elif defined(Q_OS_ANDROID) | - | ||||||||||||
| 92 | # define QT_STATFS ::statfs | - | ||||||||||||
| 93 | # define QT_STATFSBUF struct statfs | - | ||||||||||||
| 94 | # if !defined(ST_RDONLY) | - | ||||||||||||
| 95 | # define ST_RDONLY 1 // hack for missing define on Android | - | ||||||||||||
| 96 | # endif | - | ||||||||||||
| 97 | #elif defined(Q_OS_HAIKU) | - | ||||||||||||
| 98 | # define QT_STATFSBUF struct statvfs | - | ||||||||||||
| 99 | # define QT_STATFS ::statvfs | - | ||||||||||||
| 100 | #else | - | ||||||||||||
| 101 | # if defined(QT_LARGEFILE_SUPPORT) | - | ||||||||||||
| 102 | # define QT_STATFSBUF struct statvfs64 | - | ||||||||||||
| 103 | # define QT_STATFS ::statvfs64 | - | ||||||||||||
| 104 | # else | - | ||||||||||||
| 105 | # define QT_STATFSBUF struct statvfs | - | ||||||||||||
| 106 | # define QT_STATFS ::statvfs | - | ||||||||||||
| 107 | # endif // QT_LARGEFILE_SUPPORT | - | ||||||||||||
| 108 | #endif // Q_OS_BSD4 | - | ||||||||||||
| 109 | - | |||||||||||||
| 110 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 111 | - | |||||||||||||
| 112 | class QStorageIterator | - | ||||||||||||
| 113 | { | - | ||||||||||||
| 114 | public: | - | ||||||||||||
| 115 | QStorageIterator(); | - | ||||||||||||
| 116 | ~QStorageIterator(); | - | ||||||||||||
| 117 | - | |||||||||||||
| 118 | inline bool isValid() const; | - | ||||||||||||
| 119 | inline bool next(); | - | ||||||||||||
| 120 | inline QString rootPath() const; | - | ||||||||||||
| 121 | inline QByteArray fileSystemType() const; | - | ||||||||||||
| 122 | inline QByteArray device() const; | - | ||||||||||||
| 123 | private: | - | ||||||||||||
| 124 | #if defined(Q_OS_BSD4) | - | ||||||||||||
| 125 | QT_STATFSBUF *stat_buf; | - | ||||||||||||
| 126 | int entryCount; | - | ||||||||||||
| 127 | int currentIndex; | - | ||||||||||||
| 128 | #elif defined(Q_OS_SOLARIS) | - | ||||||||||||
| 129 | FILE *fp; | - | ||||||||||||
| 130 | mnttab mnt; | - | ||||||||||||
| 131 | #elif defined(Q_OS_ANDROID) | - | ||||||||||||
| 132 | QFile file; | - | ||||||||||||
| 133 | QByteArray m_rootPath; | - | ||||||||||||
| 134 | QByteArray m_fileSystemType; | - | ||||||||||||
| 135 | QByteArray m_device; | - | ||||||||||||
| 136 | #elif defined(Q_OS_LINUX) || defined(Q_OS_HURD) | - | ||||||||||||
| 137 | FILE *fp; | - | ||||||||||||
| 138 | mntent mnt; | - | ||||||||||||
| 139 | QByteArray buffer; | - | ||||||||||||
| 140 | #elif defined(Q_OS_HAIKU) | - | ||||||||||||
| 141 | BVolumeRoster m_volumeRoster; | - | ||||||||||||
| 142 | - | |||||||||||||
| 143 | QByteArray m_rootPath; | - | ||||||||||||
| 144 | QByteArray m_fileSystemType; | - | ||||||||||||
| 145 | QByteArray m_device; | - | ||||||||||||
| 146 | #endif | - | ||||||||||||
| 147 | }; | - | ||||||||||||
| 148 | - | |||||||||||||
| 149 | template <typename String> | - | ||||||||||||
| 150 | static bool isParentOf(const String &parent, const QString &dirName) | - | ||||||||||||
| 151 | { | - | ||||||||||||
| 152 | return dirName.startsWith(parent) && executed 942 times by 1 test: return dirName.startsWith(parent) && (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || parent.size() == 1);Executed by:
| 942 | ||||||||||||
| 153 | (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || executed 942 times by 1 test: return dirName.startsWith(parent) && (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || parent.size() == 1);Executed by:
| 942 | ||||||||||||
| 154 | parent.size() == 1); executed 942 times by 1 test: return dirName.startsWith(parent) && (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || parent.size() == 1);Executed by:
| 942 | ||||||||||||
| 155 | } | - | ||||||||||||
| 156 | - | |||||||||||||
| 157 | static bool shouldIncludeFs(const QStorageIterator &it) | - | ||||||||||||
| 158 | { | - | ||||||||||||
| 159 | /* | - | ||||||||||||
| 160 | * This function implements a heuristic algorithm to determine whether a | - | ||||||||||||
| 161 | * given mount should be reported to the user. Our objective is to list | - | ||||||||||||
| 162 | * only entries that the end-user would find useful. | - | ||||||||||||
| 163 | * | - | ||||||||||||
| 164 | * We therefore ignore: | - | ||||||||||||
| 165 | * - mounted in /dev, /proc, /sys: special mounts | - | ||||||||||||
| 166 | * (this will catch /sys/fs/cgroup, /proc/sys/fs/binfmt_misc, /dev/pts, | - | ||||||||||||
| 167 | * some of which are tmpfs on Linux) | - | ||||||||||||
| 168 | * - mounted in /var/run or /var/lock: most likely pseudofs | - | ||||||||||||
| 169 | * (on earlier systemd versions, /var/run was a bind-mount of /run, so | - | ||||||||||||
| 170 | * everything would be unnecessarily duplicated) | - | ||||||||||||
| 171 | * - filesystem type is "rootfs": artifact of the root-pivot on some Linux | - | ||||||||||||
| 172 | * initrd | - | ||||||||||||
| 173 | * - if the filesystem total size is zero, it's a pseudo-fs (not checked here). | - | ||||||||||||
| 174 | */ | - | ||||||||||||
| 175 | - | |||||||||||||
| 176 | QString mountDir = it.rootPath(); | - | ||||||||||||
| 177 | if (isParentOf(QLatin1String("/dev"), mountDir)
| 10-50 | ||||||||||||
| 178 | || isParentOf(QLatin1String("/proc"), mountDir)
| 4-46 | ||||||||||||
| 179 | || isParentOf(QLatin1String("/sys"), mountDir)
| 18-28 | ||||||||||||
| 180 | || isParentOf(QLatin1String("/var/run"), mountDir)
| 0-18 | ||||||||||||
| 181 | || isParentOf(QLatin1String("/var/lock"), mountDir)) {
| 0-18 | ||||||||||||
| 182 | return false; executed 42 times by 1 test: return false;Executed by:
| 42 | ||||||||||||
| 183 | } | - | ||||||||||||
| 184 | - | |||||||||||||
| 185 | #ifdef Q_OS_LINUX | - | ||||||||||||
| 186 | if (it.fileSystemType() == "rootfs")
| 2-16 | ||||||||||||
| 187 | return false; executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||
| 188 | #endif | - | ||||||||||||
| 189 | - | |||||||||||||
| 190 | // size checking in mountedVolumes() | - | ||||||||||||
| 191 | return true; executed 16 times by 1 test: return true;Executed by:
| 16 | ||||||||||||
| 192 | } | - | ||||||||||||
| 193 | - | |||||||||||||
| 194 | #if defined(Q_OS_BSD4) | - | ||||||||||||
| 195 | - | |||||||||||||
| 196 | inline QStorageIterator::QStorageIterator() | - | ||||||||||||
| 197 | : entryCount(::getmntinfo(&stat_buf, 0)), | - | ||||||||||||
| 198 | currentIndex(-1) | - | ||||||||||||
| 199 | { | - | ||||||||||||
| 200 | } | - | ||||||||||||
| 201 | - | |||||||||||||
| 202 | inline QStorageIterator::~QStorageIterator() | - | ||||||||||||
| 203 | { | - | ||||||||||||
| 204 | } | - | ||||||||||||
| 205 | - | |||||||||||||
| 206 | inline bool QStorageIterator::isValid() const | - | ||||||||||||
| 207 | { | - | ||||||||||||
| 208 | return entryCount != -1; | - | ||||||||||||
| 209 | } | - | ||||||||||||
| 210 | - | |||||||||||||
| 211 | inline bool QStorageIterator::next() | - | ||||||||||||
| 212 | { | - | ||||||||||||
| 213 | return ++currentIndex < entryCount; | - | ||||||||||||
| 214 | } | - | ||||||||||||
| 215 | - | |||||||||||||
| 216 | inline QString QStorageIterator::rootPath() const | - | ||||||||||||
| 217 | { | - | ||||||||||||
| 218 | return QFile::decodeName(stat_buf[currentIndex].f_mntonname); | - | ||||||||||||
| 219 | } | - | ||||||||||||
| 220 | - | |||||||||||||
| 221 | inline QByteArray QStorageIterator::fileSystemType() const | - | ||||||||||||
| 222 | { | - | ||||||||||||
| 223 | return QByteArray(stat_buf[currentIndex].f_fstypename); | - | ||||||||||||
| 224 | } | - | ||||||||||||
| 225 | - | |||||||||||||
| 226 | inline QByteArray QStorageIterator::device() const | - | ||||||||||||
| 227 | { | - | ||||||||||||
| 228 | return QByteArray(stat_buf[currentIndex].f_mntfromname); | - | ||||||||||||
| 229 | } | - | ||||||||||||
| 230 | - | |||||||||||||
| 231 | #elif defined(Q_OS_SOLARIS) | - | ||||||||||||
| 232 | - | |||||||||||||
| 233 | static const char pathMounted[] = "/etc/mnttab"; | - | ||||||||||||
| 234 | - | |||||||||||||
| 235 | inline QStorageIterator::QStorageIterator() | - | ||||||||||||
| 236 | { | - | ||||||||||||
| 237 | const int fd = qt_safe_open(pathMounted, O_RDONLY); | - | ||||||||||||
| 238 | fp = ::fdopen(fd, "r"); | - | ||||||||||||
| 239 | } | - | ||||||||||||
| 240 | - | |||||||||||||
| 241 | inline QStorageIterator::~QStorageIterator() | - | ||||||||||||
| 242 | { | - | ||||||||||||
| 243 | if (fp) | - | ||||||||||||
| 244 | ::fclose(fp); | - | ||||||||||||
| 245 | } | - | ||||||||||||
| 246 | - | |||||||||||||
| 247 | inline bool QStorageIterator::isValid() const | - | ||||||||||||
| 248 | { | - | ||||||||||||
| 249 | return fp != Q_NULLPTR; | - | ||||||||||||
| 250 | } | - | ||||||||||||
| 251 | - | |||||||||||||
| 252 | inline bool QStorageIterator::next() | - | ||||||||||||
| 253 | { | - | ||||||||||||
| 254 | return ::getmntent(fp, &mnt) == 0; | - | ||||||||||||
| 255 | } | - | ||||||||||||
| 256 | - | |||||||||||||
| 257 | inline QString QStorageIterator::rootPath() const | - | ||||||||||||
| 258 | { | - | ||||||||||||
| 259 | return QFile::decodeName(mnt.mnt_mountp); | - | ||||||||||||
| 260 | } | - | ||||||||||||
| 261 | - | |||||||||||||
| 262 | inline QByteArray QStorageIterator::fileSystemType() const | - | ||||||||||||
| 263 | { | - | ||||||||||||
| 264 | return QByteArray(mnt.mnt_fstype); | - | ||||||||||||
| 265 | } | - | ||||||||||||
| 266 | - | |||||||||||||
| 267 | inline QByteArray QStorageIterator::device() const | - | ||||||||||||
| 268 | { | - | ||||||||||||
| 269 | return QByteArray(mnt.mnt_mntopts); | - | ||||||||||||
| 270 | } | - | ||||||||||||
| 271 | - | |||||||||||||
| 272 | #elif defined(Q_OS_ANDROID) | - | ||||||||||||
| 273 | - | |||||||||||||
| 274 | static const QLatin1String pathMounted("/proc/mounts"); | - | ||||||||||||
| 275 | - | |||||||||||||
| 276 | inline QStorageIterator::QStorageIterator() | - | ||||||||||||
| 277 | { | - | ||||||||||||
| 278 | file.setFileName(pathMounted); | - | ||||||||||||
| 279 | file.open(QIODevice::ReadOnly | QIODevice::Text); | - | ||||||||||||
| 280 | } | - | ||||||||||||
| 281 | - | |||||||||||||
| 282 | inline QStorageIterator::~QStorageIterator() | - | ||||||||||||
| 283 | { | - | ||||||||||||
| 284 | } | - | ||||||||||||
| 285 | - | |||||||||||||
| 286 | inline bool QStorageIterator::isValid() const | - | ||||||||||||
| 287 | { | - | ||||||||||||
| 288 | return file.isOpen(); | - | ||||||||||||
| 289 | } | - | ||||||||||||
| 290 | - | |||||||||||||
| 291 | inline bool QStorageIterator::next() | - | ||||||||||||
| 292 | { | - | ||||||||||||
| 293 | QList<QByteArray> data; | - | ||||||||||||
| 294 | do { | - | ||||||||||||
| 295 | const QByteArray line = file.readLine(); | - | ||||||||||||
| 296 | data = line.split(' '); | - | ||||||||||||
| 297 | } while (data.count() < 3 && !file.atEnd()); | - | ||||||||||||
| 298 | - | |||||||||||||
| 299 | if (file.atEnd()) | - | ||||||||||||
| 300 | return false; | - | ||||||||||||
| 301 | m_device = data.at(0); | - | ||||||||||||
| 302 | m_rootPath = data.at(1); | - | ||||||||||||
| 303 | m_fileSystemType = data.at(2); | - | ||||||||||||
| 304 | - | |||||||||||||
| 305 | return true; | - | ||||||||||||
| 306 | } | - | ||||||||||||
| 307 | - | |||||||||||||
| 308 | inline QString QStorageIterator::rootPath() const | - | ||||||||||||
| 309 | { | - | ||||||||||||
| 310 | return QFile::decodeName(m_rootPath); | - | ||||||||||||
| 311 | } | - | ||||||||||||
| 312 | - | |||||||||||||
| 313 | inline QByteArray QStorageIterator::fileSystemType() const | - | ||||||||||||
| 314 | { | - | ||||||||||||
| 315 | return m_fileSystemType; | - | ||||||||||||
| 316 | } | - | ||||||||||||
| 317 | - | |||||||||||||
| 318 | inline QByteArray QStorageIterator::device() const | - | ||||||||||||
| 319 | { | - | ||||||||||||
| 320 | return m_device; | - | ||||||||||||
| 321 | } | - | ||||||||||||
| 322 | - | |||||||||||||
| 323 | #elif defined(Q_OS_LINUX) || defined(Q_OS_HURD) | - | ||||||||||||
| 324 | - | |||||||||||||
| 325 | static const char pathMounted[] = "/etc/mtab"; | - | ||||||||||||
| 326 | static const int bufferSize = 1024; // 2 paths (mount point+device) and metainfo; | - | ||||||||||||
| 327 | // should be enough | - | ||||||||||||
| 328 | - | |||||||||||||
| 329 | inline QStorageIterator::QStorageIterator() : | - | ||||||||||||
| 330 | buffer(QByteArray(bufferSize, 0)) | - | ||||||||||||
| 331 | { | - | ||||||||||||
| 332 | fp = ::setmntent(pathMounted, "r"); | - | ||||||||||||
| 333 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||
| 334 | - | |||||||||||||
| 335 | inline QStorageIterator::~QStorageIterator() | - | ||||||||||||
| 336 | { | - | ||||||||||||
| 337 | if (fp)
| 0-27 | ||||||||||||
| 338 | ::endmntent(fp); executed 27 times by 1 test: ::endmntent(fp);Executed by:
| 27 | ||||||||||||
| 339 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||
| 340 | - | |||||||||||||
| 341 | inline bool QStorageIterator::isValid() const | - | ||||||||||||
| 342 | { | - | ||||||||||||
| 343 | return fp != Q_NULLPTR; executed 27 times by 1 test: return fp != nullptr;Executed by:
| 27 | ||||||||||||
| 344 | } | - | ||||||||||||
| 345 | - | |||||||||||||
| 346 | inline bool QStorageIterator::next() | - | ||||||||||||
| 347 | { | - | ||||||||||||
| 348 | return ::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != Q_NULLPTR; executed 837 times by 1 test: return ::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != nullptr;Executed by:
| 837 | ||||||||||||
| 349 | } | - | ||||||||||||
| 350 | - | |||||||||||||
| 351 | inline QString QStorageIterator::rootPath() const | - | ||||||||||||
| 352 | { | - | ||||||||||||
| 353 | return QFile::decodeName(mnt.mnt_dir); executed 826 times by 1 test: return QFile::decodeName(mnt.mnt_dir);Executed by:
| 826 | ||||||||||||
| 354 | } | - | ||||||||||||
| 355 | - | |||||||||||||
| 356 | inline QByteArray QStorageIterator::fileSystemType() const | - | ||||||||||||
| 357 | { | - | ||||||||||||
| 358 | return QByteArray(mnt.mnt_type); executed 768 times by 1 test: return QByteArray(mnt.mnt_type);Executed by:
| 768 | ||||||||||||
| 359 | } | - | ||||||||||||
| 360 | - | |||||||||||||
| 361 | inline QByteArray QStorageIterator::device() const | - | ||||||||||||
| 362 | { | - | ||||||||||||
| 363 | return QByteArray(mnt.mnt_fsname); executed 51 times by 1 test: return QByteArray(mnt.mnt_fsname);Executed by:
| 51 | ||||||||||||
| 364 | } | - | ||||||||||||
| 365 | - | |||||||||||||
| 366 | #elif defined(Q_OS_HAIKU) | - | ||||||||||||
| 367 | inline QStorageIterator::QStorageIterator() | - | ||||||||||||
| 368 | { | - | ||||||||||||
| 369 | } | - | ||||||||||||
| 370 | - | |||||||||||||
| 371 | inline QStorageIterator::~QStorageIterator() | - | ||||||||||||
| 372 | { | - | ||||||||||||
| 373 | } | - | ||||||||||||
| 374 | - | |||||||||||||
| 375 | inline bool QStorageIterator::isValid() const | - | ||||||||||||
| 376 | { | - | ||||||||||||
| 377 | return true; | - | ||||||||||||
| 378 | } | - | ||||||||||||
| 379 | - | |||||||||||||
| 380 | inline bool QStorageIterator::next() | - | ||||||||||||
| 381 | { | - | ||||||||||||
| 382 | BVolume volume; | - | ||||||||||||
| 383 | - | |||||||||||||
| 384 | if (m_volumeRoster.GetNextVolume(&volume) != B_OK) | - | ||||||||||||
| 385 | return false; | - | ||||||||||||
| 386 | - | |||||||||||||
| 387 | BDirectory directory; | - | ||||||||||||
| 388 | if (volume.GetRootDirectory(&directory) != B_OK) | - | ||||||||||||
| 389 | return false; | - | ||||||||||||
| 390 | - | |||||||||||||
| 391 | const BPath path(&directory); | - | ||||||||||||
| 392 | - | |||||||||||||
| 393 | fs_info fsInfo; | - | ||||||||||||
| 394 | memset(&fsInfo, 0, sizeof(fsInfo)); | - | ||||||||||||
| 395 | - | |||||||||||||
| 396 | if (fs_stat_dev(volume.Device(), &fsInfo) != 0) | - | ||||||||||||
| 397 | return false; | - | ||||||||||||
| 398 | - | |||||||||||||
| 399 | m_rootPath = path.Path(); | - | ||||||||||||
| 400 | m_fileSystemType = QByteArray(fsInfo.fsh_name); | - | ||||||||||||
| 401 | - | |||||||||||||
| 402 | const QByteArray deviceName(fsInfo.device_name); | - | ||||||||||||
| 403 | m_device = (deviceName.isEmpty() ? QByteArray::number(qint32(volume.Device())) : deviceName); | - | ||||||||||||
| 404 | - | |||||||||||||
| 405 | return true; | - | ||||||||||||
| 406 | } | - | ||||||||||||
| 407 | - | |||||||||||||
| 408 | inline QString QStorageIterator::rootPath() const | - | ||||||||||||
| 409 | { | - | ||||||||||||
| 410 | return QFile::decodeName(m_rootPath); | - | ||||||||||||
| 411 | } | - | ||||||||||||
| 412 | - | |||||||||||||
| 413 | inline QByteArray QStorageIterator::fileSystemType() const | - | ||||||||||||
| 414 | { | - | ||||||||||||
| 415 | return m_fileSystemType; | - | ||||||||||||
| 416 | } | - | ||||||||||||
| 417 | - | |||||||||||||
| 418 | inline QByteArray QStorageIterator::device() const | - | ||||||||||||
| 419 | { | - | ||||||||||||
| 420 | return m_device; | - | ||||||||||||
| 421 | } | - | ||||||||||||
| 422 | - | |||||||||||||
| 423 | #else | - | ||||||||||||
| 424 | - | |||||||||||||
| 425 | inline QStorageIterator::QStorageIterator() | - | ||||||||||||
| 426 | { | - | ||||||||||||
| 427 | } | - | ||||||||||||
| 428 | - | |||||||||||||
| 429 | inline QStorageIterator::~QStorageIterator() | - | ||||||||||||
| 430 | { | - | ||||||||||||
| 431 | } | - | ||||||||||||
| 432 | - | |||||||||||||
| 433 | inline bool QStorageIterator::isValid() const | - | ||||||||||||
| 434 | { | - | ||||||||||||
| 435 | return false; | - | ||||||||||||
| 436 | } | - | ||||||||||||
| 437 | - | |||||||||||||
| 438 | inline bool QStorageIterator::next() | - | ||||||||||||
| 439 | { | - | ||||||||||||
| 440 | return false; | - | ||||||||||||
| 441 | } | - | ||||||||||||
| 442 | - | |||||||||||||
| 443 | inline QString QStorageIterator::rootPath() const | - | ||||||||||||
| 444 | { | - | ||||||||||||
| 445 | return QString(); | - | ||||||||||||
| 446 | } | - | ||||||||||||
| 447 | - | |||||||||||||
| 448 | inline QByteArray QStorageIterator::fileSystemType() const | - | ||||||||||||
| 449 | { | - | ||||||||||||
| 450 | return QByteArray(); | - | ||||||||||||
| 451 | } | - | ||||||||||||
| 452 | - | |||||||||||||
| 453 | inline QByteArray QStorageIterator::device() const | - | ||||||||||||
| 454 | { | - | ||||||||||||
| 455 | return QByteArray(); | - | ||||||||||||
| 456 | } | - | ||||||||||||
| 457 | - | |||||||||||||
| 458 | #endif | - | ||||||||||||
| 459 | - | |||||||||||||
| 460 | void QStorageInfoPrivate::initRootPath() | - | ||||||||||||
| 461 | { | - | ||||||||||||
| 462 | rootPath = QFileInfo(rootPath).canonicalFilePath(); | - | ||||||||||||
| 463 | - | |||||||||||||
| 464 | if (rootPath.isEmpty())
| 0-25 | ||||||||||||
| 465 | return; never executed: return; | 0 | ||||||||||||
| 466 | - | |||||||||||||
| 467 | QStorageIterator it; | - | ||||||||||||
| 468 | if (!it.isValid()) {
| 0-25 | ||||||||||||
| 469 | rootPath = QStringLiteral("/"); never executed: return qstring_literal_temp; | 0 | ||||||||||||
| 470 | return; never executed: return; | 0 | ||||||||||||
| 471 | } | - | ||||||||||||
| 472 | - | |||||||||||||
| 473 | int maxLength = 0; | - | ||||||||||||
| 474 | const QString oldRootPath = rootPath; | - | ||||||||||||
| 475 | rootPath.clear(); | - | ||||||||||||
| 476 | - | |||||||||||||
| 477 | while (it.next()) {
| 25-750 | ||||||||||||
| 478 | const QString mountDir = it.rootPath(); | - | ||||||||||||
| 479 | const QByteArray fsName = it.fileSystemType(); | - | ||||||||||||
| 480 | // we try to find most suitable entry | - | ||||||||||||
| 481 | if (isParentOf(mountDir, oldRootPath) && maxLength < mountDir.length()) {
| 25-674 | ||||||||||||
| 482 | maxLength = mountDir.length(); | - | ||||||||||||
| 483 | rootPath = mountDir; | - | ||||||||||||
| 484 | device = it.device(); | - | ||||||||||||
| 485 | fileSystemType = fsName; | - | ||||||||||||
| 486 | } executed 51 times by 1 test: end of blockExecuted by:
| 51 | ||||||||||||
| 487 | } executed 750 times by 1 test: end of blockExecuted by:
| 750 | ||||||||||||
| 488 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||
| 489 | - | |||||||||||||
| 490 | static inline QString retrieveLabel(const QByteArray &device) | - | ||||||||||||
| 491 | { | - | ||||||||||||
| 492 | #ifdef Q_OS_LINUX | - | ||||||||||||
| 493 | static const char pathDiskByLabel[] = "/dev/disk/by-label"; | - | ||||||||||||
| 494 | - | |||||||||||||
| 495 | QFileInfo devinfo(QFile::decodeName(device)); | - | ||||||||||||
| 496 | QString devicePath = devinfo.canonicalFilePath(); | - | ||||||||||||
| 497 | - | |||||||||||||
| 498 | QDirIterator it(QLatin1String(pathDiskByLabel), QDir::NoDotAndDotDot); | - | ||||||||||||
| 499 | while (it.hasNext()) {
| 0-25 | ||||||||||||
| 500 | it.next(); | - | ||||||||||||
| 501 | QFileInfo fileInfo(it.fileInfo()); | - | ||||||||||||
| 502 | if (fileInfo.isSymLink() && fileInfo.symLinkTarget() == devicePath)
| 0 | ||||||||||||
| 503 | return fileInfo.fileName(); never executed: return fileInfo.fileName(); | 0 | ||||||||||||
| 504 | } never executed: end of block | 0 | ||||||||||||
| 505 | #elif defined Q_OS_HAIKU | - | ||||||||||||
| 506 | fs_info fsInfo; | - | ||||||||||||
| 507 | memset(&fsInfo, 0, sizeof(fsInfo)); | - | ||||||||||||
| 508 | - | |||||||||||||
| 509 | int32 pos = 0; | - | ||||||||||||
| 510 | dev_t dev; | - | ||||||||||||
| 511 | while ((dev = next_dev(&pos)) >= 0) { | - | ||||||||||||
| 512 | if (fs_stat_dev(dev, &fsInfo) != 0) | - | ||||||||||||
| 513 | continue; | - | ||||||||||||
| 514 | - | |||||||||||||
| 515 | if (qstrcmp(fsInfo.device_name, device.constData()) == 0) | - | ||||||||||||
| 516 | return QString::fromLocal8Bit(fsInfo.volume_name); | - | ||||||||||||
| 517 | } | - | ||||||||||||
| 518 | #else | - | ||||||||||||
| 519 | Q_UNUSED(device); | - | ||||||||||||
| 520 | #endif | - | ||||||||||||
| 521 | - | |||||||||||||
| 522 | return QString(); executed 25 times by 1 test: return QString();Executed by:
| 25 | ||||||||||||
| 523 | } | - | ||||||||||||
| 524 | - | |||||||||||||
| 525 | void QStorageInfoPrivate::doStat() | - | ||||||||||||
| 526 | { | - | ||||||||||||
| 527 | initRootPath(); | - | ||||||||||||
| 528 | if (rootPath.isEmpty())
| 0-25 | ||||||||||||
| 529 | return; never executed: return; | 0 | ||||||||||||
| 530 | - | |||||||||||||
| 531 | retrieveVolumeInfo(); | - | ||||||||||||
| 532 | name = retrieveLabel(device); | - | ||||||||||||
| 533 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||
| 534 | - | |||||||||||||
| 535 | void QStorageInfoPrivate::retrieveVolumeInfo() | - | ||||||||||||
| 536 | { | - | ||||||||||||
| 537 | QT_STATFSBUF statfs_buf; | - | ||||||||||||
| 538 | int result; | - | ||||||||||||
| 539 | EINTR_LOOP(result, QT_STATFS(QFile::encodeName(rootPath).constData(), &statfs_buf)); executed 25 times by 1 test: end of blockExecuted by:
| 0-25 | ||||||||||||
| 540 | if (result == 0) {
| 0-25 | ||||||||||||
| 541 | valid = true; | - | ||||||||||||
| 542 | ready = true; | - | ||||||||||||
| 543 | - | |||||||||||||
| 544 | #if defined(Q_OS_INTEGRITY) || (defined(Q_OS_BSD4) && !defined(Q_OS_NETBSD)) | - | ||||||||||||
| 545 | bytesTotal = statfs_buf.f_blocks * statfs_buf.f_bsize; | - | ||||||||||||
| 546 | bytesFree = statfs_buf.f_bfree * statfs_buf.f_bsize; | - | ||||||||||||
| 547 | bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_bsize; | - | ||||||||||||
| 548 | #else | - | ||||||||||||
| 549 | bytesTotal = statfs_buf.f_blocks * statfs_buf.f_frsize; | - | ||||||||||||
| 550 | bytesFree = statfs_buf.f_bfree * statfs_buf.f_frsize; | - | ||||||||||||
| 551 | bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize; | - | ||||||||||||
| 552 | #endif | - | ||||||||||||
| 553 | blockSize = statfs_buf.f_bsize; | - | ||||||||||||
| 554 | #if defined(Q_OS_ANDROID) || defined(Q_OS_BSD4) || defined(Q_OS_INTEGRITY) | - | ||||||||||||
| 555 | #if defined(_STATFS_F_FLAGS) | - | ||||||||||||
| 556 | readOnly = (statfs_buf.f_flags & ST_RDONLY) != 0; | - | ||||||||||||
| 557 | #endif | - | ||||||||||||
| 558 | #else | - | ||||||||||||
| 559 | readOnly = (statfs_buf.f_flag & ST_RDONLY) != 0; | - | ||||||||||||
| 560 | #endif | - | ||||||||||||
| 561 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||
| 562 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||
| 563 | - | |||||||||||||
| 564 | QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes() | - | ||||||||||||
| 565 | { | - | ||||||||||||
| 566 | QStorageIterator it; | - | ||||||||||||
| 567 | if (!it.isValid())
| 0-2 | ||||||||||||
| 568 | return QList<QStorageInfo>() << root(); never executed: return QList<QStorageInfo>() << root(); | 0 | ||||||||||||
| 569 | - | |||||||||||||
| 570 | QList<QStorageInfo> volumes; | - | ||||||||||||
| 571 | - | |||||||||||||
| 572 | while (it.next()) {
| 2-60 | ||||||||||||
| 573 | if (!shouldIncludeFs(it))
| 16-44 | ||||||||||||
| 574 | continue; executed 44 times by 1 test: continue;Executed by:
| 44 | ||||||||||||
| 575 | - | |||||||||||||
| 576 | const QString mountDir = it.rootPath(); | - | ||||||||||||
| 577 | QStorageInfo info(mountDir); | - | ||||||||||||
| 578 | if (info.bytesTotal() == 0)
| 6-10 | ||||||||||||
| 579 | continue; executed 6 times by 1 test: continue;Executed by:
| 6 | ||||||||||||
| 580 | volumes.append(info); | - | ||||||||||||
| 581 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||
| 582 | - | |||||||||||||
| 583 | return volumes; executed 2 times by 1 test: return volumes;Executed by:
| 2 | ||||||||||||
| 584 | } | - | ||||||||||||
| 585 | - | |||||||||||||
| 586 | QStorageInfo QStorageInfoPrivate::root() | - | ||||||||||||
| 587 | { | - | ||||||||||||
| 588 | return QStorageInfo(QStringLiteral("/")); executed 1 time by 1 test: return QStorageInfo(([]() -> QString { enum { Size = sizeof(u"" "/")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "/" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return qstring_literal_temp; }()));Executed by:
executed 1 time by 1 test: return qstring_literal_temp;Executed by:
| 1 | ||||||||||||
| 589 | } | - | ||||||||||||
| 590 | - | |||||||||||||
| 591 | QT_END_NAMESPACE | - | ||||||||||||
| Source code | Switch to Preprocessed file |