qstorageinfo_unix.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qstorageinfo_unix.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6class QStorageIterator-
7{-
8public:-
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;-
17private:-
18 FILE *fp;-
19 mntent mnt;-
20 QByteArray buffer;-
21-
22-
23-
24-
25-
26-
27-
28};-
29-
30template <typename String>-
31static bool isParentOf(const String &parent, const QString &dirName)-
32{-
33 return
executed 942 times by 1 test: return dirName.startsWith(parent) && (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || parent.size() == 1);
Executed by:
  • tst_QStorageInfo
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:
  • tst_QStorageInfo
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:
  • tst_QStorageInfo
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:
  • tst_QStorageInfo
942
36}-
37-
38static bool shouldIncludeFs(const QStorageIterator &it)-
39{-
40 QString mountDir = it.rootPath();-
41 if (isParentOf(QLatin1String("/dev"), mountDir)
isParentOf(QLa...v"), mountDir)Description
TRUEevaluated 10 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 50 times by 1 test
Evaluated by:
  • tst_QStorageInfo
10-50
42 || isParentOf(QLatin1String("/proc"), mountDir)
isParentOf(QLa...c"), mountDir)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 46 times by 1 test
Evaluated by:
  • tst_QStorageInfo
4-46
43 || isParentOf(QLatin1String("/sys"), mountDir)
isParentOf(QLa...s"), mountDir)Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QStorageInfo
18-28
44 || isParentOf(QLatin1String("/var/run"), mountDir)
isParentOf(QLa...n"), mountDir)Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QStorageInfo
0-18
45 || isParentOf(QLatin1String("/var/lock"), mountDir)
isParentOf(QLa...k"), mountDir)Description
TRUEnever evaluated
FALSEevaluated 18 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
0-18
46 return
executed 42 times by 1 test: return false;
Executed by:
  • tst_QStorageInfo
false;
executed 42 times by 1 test: return false;
Executed by:
  • tst_QStorageInfo
42
47 }-
48-
49-
50 if (it.fileSystemType() == "rootfs"
it.fileSystemT...() == "rootfs"Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
2-16
51 return
executed 2 times by 1 test: return false;
Executed by:
  • tst_QStorageInfo
false;
executed 2 times by 1 test: return false;
Executed by:
  • tst_QStorageInfo
2
52-
53-
54-
55 return
executed 16 times by 1 test: return true;
Executed by:
  • tst_QStorageInfo
true;
executed 16 times by 1 test: return true;
Executed by:
  • tst_QStorageInfo
16
56}-
57static const char pathMounted[] = "/etc/mtab";-
58static const int bufferSize = 1024;-
59-
60-
61inline QStorageIterator::QStorageIterator() :-
62 buffer(QByteArray(bufferSize, 0))-
63{-
64 fp = ::setmntent(pathMounted, "r");-
65}
executed 27 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
27
66-
67inline QStorageIterator::~QStorageIterator()-
68{-
69 if (fp
fpDescription
TRUEevaluated 27 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEnever evaluated
)
0-27
70 ::
executed 27 times by 1 test: ::endmntent(fp);
Executed by:
  • tst_QStorageInfo
endmntent(fp);
executed 27 times by 1 test: ::endmntent(fp);
Executed by:
  • tst_QStorageInfo
27
71}
executed 27 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
27
72-
73inline bool QStorageIterator::isValid() const-
74{-
75 return
executed 27 times by 1 test: return fp != nullptr;
Executed by:
  • tst_QStorageInfo
fp != nullptr;
executed 27 times by 1 test: return fp != nullptr;
Executed by:
  • tst_QStorageInfo
27
76}-
77-
78inline bool QStorageIterator::next()-
79{-
80 return
executed 837 times by 1 test: return ::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != nullptr;
Executed by:
  • tst_QStorageInfo
::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != nullptr;
executed 837 times by 1 test: return ::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != nullptr;
Executed by:
  • tst_QStorageInfo
837
81}-
82-
83inline QString QStorageIterator::rootPath() const-
84{-
85 return
executed 826 times by 1 test: return QFile::decodeName(mnt.mnt_dir);
Executed by:
  • tst_QStorageInfo
QFile::decodeName(mnt.mnt_dir);
executed 826 times by 1 test: return QFile::decodeName(mnt.mnt_dir);
Executed by:
  • tst_QStorageInfo
826
86}-
87-
88inline QByteArray QStorageIterator::fileSystemType() const-
89{-
90 return
executed 768 times by 1 test: return QByteArray(mnt.mnt_type);
Executed by:
  • tst_QStorageInfo
QByteArray(mnt.mnt_type);
executed 768 times by 1 test: return QByteArray(mnt.mnt_type);
Executed by:
  • tst_QStorageInfo
768
91}-
92-
93inline QByteArray QStorageIterator::device() const-
94{-
95 return
executed 51 times by 1 test: return QByteArray(mnt.mnt_fsname);
Executed by:
  • tst_QStorageInfo
QByteArray(mnt.mnt_fsname);
executed 51 times by 1 test: return QByteArray(mnt.mnt_fsname);
Executed by:
  • tst_QStorageInfo
51
96}-
97void QStorageInfoPrivate::initRootPath()-
98{-
99 rootPath = QFileInfo(rootPath).canonicalFilePath();-
100-
101 if (rootPath.isEmpty()
rootPath.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
0-25
102 return;
never executed: return;
0
103-
104 QStorageIterator it;-
105 if (!it.isValid()
!it.isValid()Description
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
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: return qstring_literal_temp;
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()
it.next()Description
TRUEevaluated 750 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
25-750
115 const QString mountDir = it.rootPath();-
116 const QByteArray fsName = it.fileSystemType();-
117-
118 if (isParentOf(mountDir, oldRootPath)
isParentOf(mou..., oldRootPath)Description
TRUEevaluated 76 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 674 times by 1 test
Evaluated by:
  • tst_QStorageInfo
&& maxLength < mountDir.length()
maxLength < mountDir.length()Description
TRUEevaluated 51 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
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 block
Executed by:
  • tst_QStorageInfo
51
124 }
executed 750 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
750
125}
executed 25 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
25
126-
127static 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()
it.hasNext()Description
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
0-25
137 it.next();-
138 QFileInfo fileInfo(it.fileInfo());-
139 if (fileInfo.isSymLink()
fileInfo.isSymLink()Description
TRUEnever evaluated
FALSEnever evaluated
&& fileInfo.symLinkTarget() == devicePath
fileInfo.symLi... == devicePathDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
140 return
never executed: return fileInfo.fileName();
fileInfo.fileName();
never executed: return fileInfo.fileName();
0
141 }
never executed: end of block
0
142 return
executed 25 times by 1 test: return QString();
Executed by:
  • tst_QStorageInfo
QString();
executed 25 times by 1 test: return QString();
Executed by:
  • tst_QStorageInfo
25
143}-
144-
145void QStorageInfoPrivate::doStat()-
146{-
147 initRootPath();-
148 if (rootPath.isEmpty()
rootPath.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
0-25
149 return;
never executed: return;
0
150-
151 retrieveVolumeInfo();-
152 name = retrieveLabel(device);-
153}
executed 25 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
25
154-
155void 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: end of block
Executed by:
  • tst_QStorageInfo
while (result == -1
result == -1Description
TRUEnever evaluated
FALSEevaluated 25 times by 1 test
Evaluated by:
  • tst_QStorageInfo
&& (*
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEnever evaluated
__errno_location ()) == 4
(*__errno_location ()) == 4Description
TRUEnever evaluated
FALSEnever evaluated
);
0-25
160 if (result == 0
result == 0Description
TRUEevaluated 25 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEnever evaluated
) {
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 block
Executed by:
  • tst_QStorageInfo
25
182}
executed 25 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
25
183-
184QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()-
185{-
186 QStorageIterator it;-
187 if (!it.isValid()
!it.isValid()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
0-2
188 return
never executed: return QList<QStorageInfo>() << root();
QList<QStorageInfo>() << root();
never executed: return QList<QStorageInfo>() << root();
0
189-
190 QList<QStorageInfo> volumes;-
191-
192 while (it.next()
it.next()Description
TRUEevaluated 60 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
2-60
193 if (!shouldIncludeFs(it)
!shouldIncludeFs(it)Description
TRUEevaluated 44 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 16 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
16-44
194 continue;
executed 44 times by 1 test: continue;
Executed by:
  • tst_QStorageInfo
44
195-
196 const QString mountDir = it.rootPath();-
197 QStorageInfo info(mountDir);-
198 if (info.bytesTotal() == 0
info.bytesTotal() == 0Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
6-10
199 continue;
executed 6 times by 1 test: continue;
Executed by:
  • tst_QStorageInfo
6
200 volumes.append(info);-
201 }
executed 10 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
10
202-
203 return
executed 2 times by 1 test: return volumes;
Executed by:
  • tst_QStorageInfo
volumes;
executed 2 times by 1 test: return volumes;
Executed by:
  • tst_QStorageInfo
2
204}-
205-
206QStorageInfo QStorageInfoPrivate::root()-
207{-
208 return
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:
  • tst_QStorageInfo
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
executed 1 time by 1 test: return qstring_literal_temp;
Executed by:
  • tst_QStorageInfo
qstring_literal_temp;
executed 1 time by 1 test: return qstring_literal_temp;
Executed by:
  • tst_QStorageInfo
}()));
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:
  • tst_QStorageInfo
1
209}-
210-
211-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9