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 762 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)
dirName.startsWith(parent)Description
TRUEevaluated 92 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 670 times by 1 test
Evaluated by:
  • tst_QStorageInfo
&&
executed 762 times by 1 test: return dirName.startsWith(parent) && (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || parent.size() == 1);
Executed by:
  • tst_QStorageInfo
92-762
34 (dirName.size() == parent.size()
dirName.size()... parent.size()Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 68 times by 1 test
Evaluated by:
  • tst_QStorageInfo
|| dirName.at(parent.size()) == QLatin1Char('/')
dirName.at(par...atin1Char('/')Description
TRUEevaluated 40 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 28 times by 1 test
Evaluated by:
  • tst_QStorageInfo
||
executed 762 times by 1 test: return dirName.startsWith(parent) && (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || parent.size() == 1);
Executed by:
  • tst_QStorageInfo
24-762
35 parent.size() == 1
parent.size() == 1Description
TRUEevaluated 28 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEnever evaluated
);
executed 762 times by 1 test: return dirName.startsWith(parent) && (dirName.size() == parent.size() || dirName.at(parent.size()) == QLatin1Char('/') || parent.size() == 1);
Executed by:
  • tst_QStorageInfo
0-762
36}-
37-
38static bool isPseudoFs(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 true;
Executed by:
  • tst_QStorageInfo
true;
executed 42 times by 1 test: return true;
Executed by:
  • tst_QStorageInfo
42
47 }-
48-
49 QByteArray type = it.fileSystemType();-
50 if (type == "tmpfs"
type == "tmpfs"Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 12 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
6-12
51 return
executed 6 times by 1 test: return false;
Executed by:
  • tst_QStorageInfo
false;
executed 6 times by 1 test: return false;
Executed by:
  • tst_QStorageInfo
6
52-
53 if (type == "rootfs"
type == "rootfs"Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QStorageInfo
|| type == "rpc_pipefs"
type == "rpc_pipefs"Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
2-10
54 return
executed 4 times by 1 test: return true;
Executed by:
  • tst_QStorageInfo
true;
executed 4 times by 1 test: return true;
Executed by:
  • tst_QStorageInfo
4
55-
56-
57 if (!it.device().startsWith('/')
!it.device().startsWith('/')Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 4 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
4
58 return
executed 4 times by 1 test: return true;
Executed by:
  • tst_QStorageInfo
true;
executed 4 times by 1 test: return true;
Executed by:
  • tst_QStorageInfo
4
59-
60 return
executed 4 times by 1 test: return false;
Executed by:
  • tst_QStorageInfo
false;
executed 4 times by 1 test: return false;
Executed by:
  • tst_QStorageInfo
4
61}-
62static const char pathMounted[] = "/etc/mtab";-
63static const int bufferSize = 1024;-
64-
65-
66inline QStorageIterator::QStorageIterator() :-
67 buffer(QByteArray(bufferSize, 0))-
68{-
69 fp = ::setmntent(pathMounted, "r");-
70}
executed 21 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
21
71-
72inline QStorageIterator::~QStorageIterator()-
73{-
74 if (fp
fpDescription
TRUEevaluated 21 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEnever evaluated
)
0-21
75 ::
executed 21 times by 1 test: ::endmntent(fp);
Executed by:
  • tst_QStorageInfo
endmntent(fp);
executed 21 times by 1 test: ::endmntent(fp);
Executed by:
  • tst_QStorageInfo
21
76}
executed 21 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
21
77-
78inline bool QStorageIterator::isValid() const-
79{-
80 return
executed 21 times by 1 test: return fp != nullptr;
Executed by:
  • tst_QStorageInfo
fp != nullptr;
executed 21 times by 1 test: return fp != nullptr;
Executed by:
  • tst_QStorageInfo
21
81}-
82-
83inline bool QStorageIterator::next()-
84{-
85 return
executed 651 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 651 times by 1 test: return ::getmntent_r(fp, &mnt, buffer.data(), buffer.size()) != nullptr;
Executed by:
  • tst_QStorageInfo
651
86}-
87-
88inline QString QStorageIterator::rootPath() const-
89{-
90 return
executed 640 times by 1 test: return QFile::decodeName(mnt.mnt_dir);
Executed by:
  • tst_QStorageInfo
QFile::decodeName(mnt.mnt_dir);
executed 640 times by 1 test: return QFile::decodeName(mnt.mnt_dir);
Executed by:
  • tst_QStorageInfo
640
91}-
92-
93inline QByteArray QStorageIterator::fileSystemType() const-
94{-
95 return
executed 588 times by 1 test: return QByteArray(mnt.mnt_type);
Executed by:
  • tst_QStorageInfo
QByteArray(mnt.mnt_type);
executed 588 times by 1 test: return QByteArray(mnt.mnt_type);
Executed by:
  • tst_QStorageInfo
588
96}-
97-
98inline QByteArray QStorageIterator::device() const-
99{-
100 return
executed 39 times by 1 test: return QByteArray(mnt.mnt_fsname);
Executed by:
  • tst_QStorageInfo
QByteArray(mnt.mnt_fsname);
executed 39 times by 1 test: return QByteArray(mnt.mnt_fsname);
Executed by:
  • tst_QStorageInfo
39
101}-
102void QStorageInfoPrivate::initRootPath()-
103{-
104 rootPath = QFileInfo(rootPath).canonicalFilePath();-
105-
106 if (rootPath.isEmpty()
rootPath.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
0-19
107 return;
never executed: return;
0
108-
109 QStorageIterator it;-
110 if (!it.isValid()
!it.isValid()Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
0-19
111 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
112 return;
never executed: return;
0
113 }-
114-
115 int maxLength = 0;-
116 const QString oldRootPath = rootPath;-
117 rootPath.clear();-
118-
119 while (it.next()
it.next()Description
TRUEevaluated 570 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
19-570
120 const QString mountDir = it.rootPath();-
121 const QByteArray fsName = it.fileSystemType();-
122-
123 if (isParentOf(mountDir, oldRootPath)
isParentOf(mou..., oldRootPath)Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 520 times by 1 test
Evaluated by:
  • tst_QStorageInfo
&& maxLength < mountDir.length()
maxLength < mountDir.length()Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
19-520
124 maxLength = mountDir.length();-
125 rootPath = mountDir;-
126 device = it.device();-
127 fileSystemType = fsName;-
128 }
executed 31 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
31
129 }
executed 570 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
570
130}
executed 19 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
19
131-
132static inline QString retrieveLabel(const QByteArray &device)-
133{-
134-
135 static const char pathDiskByLabel[] = "/dev/disk/by-label";-
136-
137 QFileInfo devinfo(QFile::decodeName(device));-
138 QString devicePath = devinfo.canonicalFilePath();-
139-
140 QDirIterator it(QLatin1String(pathDiskByLabel), QDir::NoDotAndDotDot);-
141 while (it.hasNext()
it.hasNext()Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QStorageInfo
) {
0-19
142 it.next();-
143 QFileInfo fileInfo(it.fileInfo());-
144 if (fileInfo.isSymLink()
fileInfo.isSymLink()Description
TRUEnever evaluated
FALSEnever evaluated
&& fileInfo.symLinkTarget() == devicePath
fileInfo.symLi... == devicePathDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
145 return
never executed: return fileInfo.fileName();
fileInfo.fileName();
never executed: return fileInfo.fileName();
0
146 }
never executed: end of block
0
147 return
executed 19 times by 1 test: return QString();
Executed by:
  • tst_QStorageInfo
QString();
executed 19 times by 1 test: return QString();
Executed by:
  • tst_QStorageInfo
19
148}-
149-
150void QStorageInfoPrivate::doStat()-
151{-
152 initRootPath();-
153 if (rootPath.isEmpty()
rootPath.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 19 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
0-19
154 return;
never executed: return;
0
155-
156 retrieveVolumeInfo();-
157 name = retrieveLabel(device);-
158}
executed 19 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
19
159-
160void QStorageInfoPrivate::retrieveVolumeInfo()-
161{-
162 struct statvfs64 statfs_buf;-
163 int result;-
164 do { result = ::statvfs64(QFile::encodeName(rootPath).constData(), &statfs_buf); }
executed 19 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
while (result == -1
result == -1Description
TRUEnever evaluated
FALSEevaluated 19 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-19
165 if (result == 0
result == 0Description
TRUEevaluated 19 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEnever evaluated
) {
0-19
166 valid = true;-
167 ready = true;-
168-
169-
170-
171-
172-
173-
174 bytesTotal = statfs_buf.f_blocks * statfs_buf.f_frsize;-
175 bytesFree = statfs_buf.f_bfree * statfs_buf.f_frsize;-
176 bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize;-
177-
178 blockSize = statfs_buf.f_bsize;-
179-
180-
181-
182-
183-
184 readOnly = (statfs_buf.f_flag & ST_RDONLY) != 0;-
185-
186 }
executed 19 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
19
187}
executed 19 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
19
188-
189QList<QStorageInfo> QStorageInfoPrivate::mountedVolumes()-
190{-
191 QStorageIterator it;-
192 if (!it.isValid()
!it.isValid()Description
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
0-2
193 return
never executed: return QList<QStorageInfo>() << root();
QList<QStorageInfo>() << root();
never executed: return QList<QStorageInfo>() << root();
0
194-
195 QList<QStorageInfo> volumes;-
196-
197 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
198 if (isPseudoFs(it)
isPseudoFs(it)Description
TRUEevaluated 50 times by 1 test
Evaluated by:
  • tst_QStorageInfo
FALSEevaluated 10 times by 1 test
Evaluated by:
  • tst_QStorageInfo
)
10-50
199 continue;
executed 50 times by 1 test: continue;
Executed by:
  • tst_QStorageInfo
50
200-
201 const QString mountDir = it.rootPath();-
202 volumes.append(QStorageInfo(mountDir));-
203 }
executed 10 times by 1 test: end of block
Executed by:
  • tst_QStorageInfo
10
204-
205 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
206}-
207-
208QStorageInfo QStorageInfoPrivate::root()-
209{-
210 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
211}-
212-
213-
Switch to Source codePreprocessed file

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