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