| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qstorageinfo_unix.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||
| 2 | - | |||||||||||||||||||
| 3 | - | |||||||||||||||||||
| 4 | - | |||||||||||||||||||
| 5 | - | |||||||||||||||||||
| 6 | class QStorageIterator | - | ||||||||||||||||||
| 7 | { | - | ||||||||||||||||||
| 8 | public: | - | ||||||||||||||||||
| 9 | QStorageIterator(); | - | ||||||||||||||||||
| 10 | ~QStorageIterator(); | - | ||||||||||||||||||
| 11 | - | |||||||||||||||||||
| 12 | inline bool isValid() const; | - | ||||||||||||||||||
| 13 | inline bool next(); | - | ||||||||||||||||||
| 14 | inline QString rootPath() const; | - | ||||||||||||||||||
| 15 | inline QByteArray fileSystemType() const; | - | ||||||||||||||||||
| 16 | inline QByteArray device() const; | - | ||||||||||||||||||
| 17 | private: | - | ||||||||||||||||||
| 18 | FILE *fp; | - | ||||||||||||||||||
| 19 | mntent mnt; | - | ||||||||||||||||||
| 20 | QByteArray buffer; | - | ||||||||||||||||||
| 21 | - | |||||||||||||||||||
| 22 | - | |||||||||||||||||||
| 23 | - | |||||||||||||||||||
| 24 | - | |||||||||||||||||||
| 25 | - | |||||||||||||||||||
| 26 | - | |||||||||||||||||||
| 27 | - | |||||||||||||||||||
| 28 | }; | - | ||||||||||||||||||
| 29 | - | |||||||||||||||||||
| 30 | template <typename String> | - | ||||||||||||||||||
| 31 | static bool isParentOf(const String &parent, const QString &dirName) | - | ||||||||||||||||||
| 32 | { | - | ||||||||||||||||||
| 33 | return executed 942 times by 1 test: dirName.startsWith(parent) &&return dirName.startsWith(parent) && (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || parent.size() == 1);Executed by:
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 | ||||||||||||||||||
| 34 | (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 | ||||||||||||||||||
| 35 | 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 | ||||||||||||||||||
| 36 | } | - | ||||||||||||||||||
| 37 | - | |||||||||||||||||||
| 38 | static bool shouldIncludeFs(const QStorageIterator &it) | - | ||||||||||||||||||
| 39 | { | - | ||||||||||||||||||
| 40 | QString mountDir = it.rootPath(); | - | ||||||||||||||||||
| 41 | if (isParentOf(QLatin1String("/dev"), mountDir)
| 10-50 | ||||||||||||||||||
| 42 | || isParentOf(QLatin1String("/proc"), mountDir)
| 4-46 | ||||||||||||||||||
| 43 | || isParentOf(QLatin1String("/sys"), mountDir)
| 18-28 | ||||||||||||||||||
| 44 | || isParentOf(QLatin1String("/var/run"), mountDir)
| 0-18 | ||||||||||||||||||
| 45 | || isParentOf(QLatin1String("/var/lock"), mountDir)
| 0-18 | ||||||||||||||||||
| 46 | return executed 42 times by 1 test: false;return false;Executed by:
executed 42 times by 1 test: return false;Executed by:
| 42 | ||||||||||||||||||
| 47 | } | - | ||||||||||||||||||
| 48 | - | |||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | if (it.fileSystemType() == "rootfs"
| 2-16 | ||||||||||||||||||
| 51 | return executed 2 times by 1 test: false;return false;Executed by:
executed 2 times by 1 test: return false;Executed by:
| 2 | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | - | |||||||||||||||||||
| 55 | return executed 16 times by 1 test: true;return true;Executed by:
executed 16 times by 1 test: return true;Executed by:
| 16 | ||||||||||||||||||
| 56 | } | - | ||||||||||||||||||
| 57 | static const char pathMounted[] = "/etc/mtab"; | - | ||||||||||||||||||
| 58 | static const int bufferSize = 1024; | - | ||||||||||||||||||
| 59 | - | |||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | inline QStorageIterator::QStorageIterator() : | - | ||||||||||||||||||
| 62 | buffer(QByteArray(bufferSize, 0)) | - | ||||||||||||||||||
| 63 | { | - | ||||||||||||||||||
| 64 | fp = ::setmntent(pathMounted, "r"); | - | ||||||||||||||||||
| 65 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | inline QStorageIterator::~QStorageIterator() | - | ||||||||||||||||||
| 68 | { | - | ||||||||||||||||||
| 69 | if (fp
| 0-27 | ||||||||||||||||||
| 70 | :: executed 27 times by 1 test: endmntent(fp);::endmntent(fp);Executed by:
executed 27 times by 1 test: ::endmntent(fp);Executed by:
| 27 | ||||||||||||||||||
| 71 | } executed 27 times by 1 test: end of blockExecuted by:
| 27 | ||||||||||||||||||
| 72 | - | |||||||||||||||||||
| 73 | inline bool QStorageIterator::isValid() const | - | ||||||||||||||||||
| 74 | { | - | ||||||||||||||||||
| 75 | return executed 27 times by 1 test: fp != nullptr;return fp != nullptr;Executed by:
executed 27 times by 1 test: return fp != nullptr;Executed by:
| 27 | ||||||||||||||||||
| 76 | } | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | inline bool QStorageIterator::next() | - | ||||||||||||||||||
| 79 | { | - | ||||||||||||||||||
| 80 | return executed 837 times by 1 test: ::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != nullptr;return ::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != nullptr;Executed by:
executed 837 times by 1 test: return ::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != nullptr;Executed by:
| 837 | ||||||||||||||||||
| 81 | } | - | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | inline QString QStorageIterator::rootPath() const | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 | return executed 826 times by 1 test: QFile::decodeName(mnt.mnt_dir);return QFile::decodeName(mnt.mnt_dir);Executed by:
executed 826 times by 1 test: return QFile::decodeName(mnt.mnt_dir);Executed by:
| 826 | ||||||||||||||||||
| 86 | } | - | ||||||||||||||||||
| 87 | - | |||||||||||||||||||
| 88 | inline QByteArray QStorageIterator::fileSystemType() const | - | ||||||||||||||||||
| 89 | { | - | ||||||||||||||||||
| 90 | return executed 768 times by 1 test: QByteArray(mnt.mnt_type);return QByteArray(mnt.mnt_type);Executed by:
executed 768 times by 1 test: return QByteArray(mnt.mnt_type);Executed by:
| 768 | ||||||||||||||||||
| 91 | } | - | ||||||||||||||||||
| 92 | - | |||||||||||||||||||
| 93 | inline QByteArray QStorageIterator::device() const | - | ||||||||||||||||||
| 94 | { | - | ||||||||||||||||||
| 95 | return executed 51 times by 1 test: QByteArray(mnt.mnt_fsname);return QByteArray(mnt.mnt_fsname);Executed by:
executed 51 times by 1 test: return QByteArray(mnt.mnt_fsname);Executed by:
| 51 | ||||||||||||||||||
| 96 | } | - | ||||||||||||||||||
| 97 | void QStorageInfoPrivate::initRootPath() | - | ||||||||||||||||||
| 98 | { | - | ||||||||||||||||||
| 99 | rootPath = QFileInfo(rootPath).canonicalFilePath(); | - | ||||||||||||||||||
| 100 | - | |||||||||||||||||||
| 101 | if (rootPath.isEmpty()
| 0-25 | ||||||||||||||||||
| 102 | return; never executed: return; | 0 | ||||||||||||||||||
| 103 | - | |||||||||||||||||||
| 104 | QStorageIterator it; | - | ||||||||||||||||||
| 105 | if (!it.isValid()
| 0-25 | ||||||||||||||||||
| 106 | rootPath = ([]() -> 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 never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }());return qstring_literal_temp; | 0 | ||||||||||||||||||
| 107 | return; never executed: return; | 0 | ||||||||||||||||||
| 108 | } | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | int maxLength = 0; | - | ||||||||||||||||||
| 111 | const QString oldRootPath = rootPath; | - | ||||||||||||||||||
| 112 | rootPath.clear(); | - | ||||||||||||||||||
| 113 | - | |||||||||||||||||||
| 114 | while (it.next()
| 25-750 | ||||||||||||||||||
| 115 | const QString mountDir = it.rootPath(); | - | ||||||||||||||||||
| 116 | const QByteArray fsName = it.fileSystemType(); | - | ||||||||||||||||||
| 117 | - | |||||||||||||||||||
| 118 | if (isParentOf(mountDir, oldRootPath)
| 25-674 | ||||||||||||||||||
| 119 | maxLength = mountDir.length(); | - | ||||||||||||||||||
| 120 | rootPath = mountDir; | - | ||||||||||||||||||
| 121 | device = it.device(); | - | ||||||||||||||||||
| 122 | fileSystemType = fsName; | - | ||||||||||||||||||
| 123 | } executed 51 times by 1 test: end of blockExecuted by:
| 51 | ||||||||||||||||||
| 124 | } executed 750 times by 1 test: end of blockExecuted by:
| 750 | ||||||||||||||||||
| 125 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 126 | - | |||||||||||||||||||
| 127 | static inline QString retrieveLabel(const QByteArray &device) | - | ||||||||||||||||||
| 128 | { | - | ||||||||||||||||||
| 129 | - | |||||||||||||||||||
| 130 | static const char pathDiskByLabel[] = "/dev/disk/by-label"; | - | ||||||||||||||||||
| 131 | - | |||||||||||||||||||
| 132 | QFileInfo devinfo(QFile::decodeName(device)); | - | ||||||||||||||||||
| 133 | QString devicePath = devinfo.canonicalFilePath(); | - | ||||||||||||||||||
| 134 | - | |||||||||||||||||||
| 135 | QDirIterator it(QLatin1String(pathDiskByLabel), QDir::NoDotAndDotDot); | - | ||||||||||||||||||
| 136 | while (it.hasNext()
| 0-25 | ||||||||||||||||||
| 137 | it.next(); | - | ||||||||||||||||||
| 138 | QFileInfo fileInfo(it.fileInfo()); | - | ||||||||||||||||||
| 139 | if (fileInfo.isSymLink()
| 0 | ||||||||||||||||||
| 140 | return never executed: fileInfo.fileName();return fileInfo.fileName();never executed: return fileInfo.fileName(); | 0 | ||||||||||||||||||
| 141 | } never executed: end of block | 0 | ||||||||||||||||||
| 142 | return executed 25 times by 1 test: QString();return QString();Executed by:
executed 25 times by 1 test: return QString();Executed by:
| 25 | ||||||||||||||||||
| 143 | } | - | ||||||||||||||||||
| 144 | - | |||||||||||||||||||
| 145 | void QStorageInfoPrivate::doStat() | - | ||||||||||||||||||
| 146 | { | - | ||||||||||||||||||
| 147 | initRootPath(); | - | ||||||||||||||||||
| 148 | if (rootPath.isEmpty()
| 0-25 | ||||||||||||||||||
| 149 | return; never executed: return; | 0 | ||||||||||||||||||
| 150 | - | |||||||||||||||||||
| 151 | retrieveVolumeInfo(); | - | ||||||||||||||||||
| 152 | name = retrieveLabel(device); | - | ||||||||||||||||||
| 153 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 154 | - | |||||||||||||||||||
| 155 | void QStorageInfoPrivate::retrieveVolumeInfo() | - | ||||||||||||||||||
| 156 | { | - | ||||||||||||||||||
| 157 | struct statvfs64 statfs_buf; | - | ||||||||||||||||||
| 158 | int result; | - | ||||||||||||||||||
| 159 | do { result = ::statvfs64(QFile::encodeName(rootPath).constData(), &statfs_buf); } executed 25 times by 1 test: while (result == -1end of blockExecuted by:
| 0-25 | ||||||||||||||||||
| 160 | if (result == 0
| 0-25 | ||||||||||||||||||
| 161 | valid = true; | - | ||||||||||||||||||
| 162 | ready = true; | - | ||||||||||||||||||
| 163 | - | |||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | - | |||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | bytesTotal = statfs_buf.f_blocks * statfs_buf.f_frsize; | - | ||||||||||||||||||
| 170 | bytesFree = statfs_buf.f_bfree * statfs_buf.f_frsize; | - | ||||||||||||||||||
| 171 | bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize; | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | blockSize = statfs_buf.f_bsize; | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | - | |||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | - | |||||||||||||||||||
| 178 | - | |||||||||||||||||||
| 179 | readOnly = (statfs_buf.f_flag & ST_RDONLY) != 0; | - | ||||||||||||||||||
| 180 | - | |||||||||||||||||||
| 181 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 182 | } executed 25 times by 1 test: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 183 | - | |||||||||||||||||||
| 184 | QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes() | - | ||||||||||||||||||
| 185 | { | - | ||||||||||||||||||
| 186 | QStorageIterator it; | - | ||||||||||||||||||
| 187 | if (!it.isValid()
| 0-2 | ||||||||||||||||||
| 188 | return never executed: QList<QStorageInfo>() << root();return QList<QStorageInfo>() << root();never executed: return QList<QStorageInfo>() << root(); | 0 | ||||||||||||||||||
| 189 | - | |||||||||||||||||||
| 190 | QList<QStorageInfo> volumes; | - | ||||||||||||||||||
| 191 | - | |||||||||||||||||||
| 192 | while (it.next()
| 2-60 | ||||||||||||||||||
| 193 | if (!shouldIncludeFs(it)
| 16-44 | ||||||||||||||||||
| 194 | continue; executed 44 times by 1 test: continue;Executed by:
| 44 | ||||||||||||||||||
| 195 | - | |||||||||||||||||||
| 196 | const QString mountDir = it.rootPath(); | - | ||||||||||||||||||
| 197 | QStorageInfo info(mountDir); | - | ||||||||||||||||||
| 198 | if (info.bytesTotal() == 0
| 6-10 | ||||||||||||||||||
| 199 | continue; executed 6 times by 1 test: continue;Executed by:
| 6 | ||||||||||||||||||
| 200 | volumes.append(info); | - | ||||||||||||||||||
| 201 | } executed 10 times by 1 test: end of blockExecuted by:
| 10 | ||||||||||||||||||
| 202 | - | |||||||||||||||||||
| 203 | return executed 2 times by 1 test: volumes;return volumes;Executed by:
executed 2 times by 1 test: return volumes;Executed by:
| 2 | ||||||||||||||||||
| 204 | } | - | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | QStorageInfo QStorageInfoPrivate::root() | - | ||||||||||||||||||
| 207 | { | - | ||||||||||||||||||
| 208 | return executed 1 time by 1 test: 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); returnreturn 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: qstring_literal_temp;return qstring_literal_temp;Executed by:
executed 1 time by 1 test: }()));return qstring_literal_temp;Executed by:
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:
| 1 | ||||||||||||||||||
| 209 | } | - | ||||||||||||||||||
| 210 | - | |||||||||||||||||||
| 211 | - | |||||||||||||||||||
| Switch to Source code | Preprocessed file |