From b3eb951d18abfa48bb88b5039521d79103a6a322 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Fri, 13 Oct 2023 11:16:46 -0700 Subject: [PATCH] QStorageInfo/Linux: switch the non-Android version to also use statfs() It's the actual system call on Linux, inspired by the 4.4BSD call of the same name (and our BSD code also uses statfs(), except for NetBSD, but it probably could use statfs() there too). statvfs() wasn't introduced until POSIX.1-2001, though glibc added it in 1998 for version 2.1 and Bionic only for NDK version 19 in 2019. So we could merge the Android code to the POSIX version, but it's easier to merge the non-Android code to the raw system call. Change-Id: I8f3ce163ccc5408cac39fffd178dbd83567a78d5 Reviewed-by: Fabian Kosmale Reviewed-by: Ahmad Samir Reviewed-by: Qt CI Bot --- src/corelib/io/qstorageinfo_linux.cpp | 33 +++---------------- .../corelib/io/qstorageinfo/CMakeLists.txt | 1 + .../io/qstorageinfo/tst_qstorageinfo.cpp | 4 +++ 3 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/corelib/io/qstorageinfo_linux.cpp b/src/corelib/io/qstorageinfo_linux.cpp index 7475f3d416..54b487e83f 100644 --- a/src/corelib/io/qstorageinfo_linux.cpp +++ b/src/corelib/io/qstorageinfo_linux.cpp @@ -10,24 +10,8 @@ #include #include -#if defined(Q_OS_ANDROID) -# include -# include -# define QT_STATFS ::statfs -# define QT_STATFSBUF struct statfs -# if !defined(ST_RDONLY) -# define ST_RDONLY 1 // hack for missing define on Android -# endif -#else -# include -# if defined(QT_LARGEFILE_SUPPORT) -# define QT_STATFSBUF struct statvfs64 -# define QT_STATFS ::statvfs64 -# else -# define QT_STATFSBUF struct statvfs -# define QT_STATFS ::statvfs -# endif // QT_LARGEFILE_SUPPORT -#endif +#include +#include QT_BEGIN_NAMESPACE @@ -160,9 +144,9 @@ void QStorageInfoPrivate::doStat() void QStorageInfoPrivate::retrieveVolumeInfo() { - QT_STATFSBUF statfs_buf; + struct statfs64 statfs_buf; int result; - EINTR_LOOP(result, QT_STATFS(QFile::encodeName(rootPath).constData(), &statfs_buf)); + EINTR_LOOP(result, statfs64(QFile::encodeName(rootPath).constData(), &statfs_buf)); if (result == 0) { valid = true; ready = true; @@ -171,14 +155,7 @@ void QStorageInfoPrivate::retrieveVolumeInfo() bytesFree = statfs_buf.f_bfree * statfs_buf.f_frsize; bytesAvailable = statfs_buf.f_bavail * statfs_buf.f_frsize; blockSize = int(statfs_buf.f_bsize); - -#if defined(Q_OS_ANDROID) -#if defined(_STATFS_F_FLAGS) - readOnly = (statfs_buf.f_flags & ST_RDONLY) != 0; -#endif -#else - readOnly = (statfs_buf.f_flag & ST_RDONLY) != 0; -#endif + readOnly = (statfs_buf.f_flags & MS_RDONLY) != 0; } } diff --git a/tests/auto/corelib/io/qstorageinfo/CMakeLists.txt b/tests/auto/corelib/io/qstorageinfo/CMakeLists.txt index 45631c1c2c..acbd90cb45 100644 --- a/tests/auto/corelib/io/qstorageinfo/CMakeLists.txt +++ b/tests/auto/corelib/io/qstorageinfo/CMakeLists.txt @@ -16,4 +16,5 @@ qt_internal_add_test(tst_qstorageinfo tst_qstorageinfo.cpp LIBRARIES Qt::CorePrivate + Qt::TestPrivate ) diff --git a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp index 38976d5ad1..5c375d12ef 100644 --- a/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp +++ b/tests/auto/corelib/io/qstorageinfo/tst_qstorageinfo.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "private/qemulationdetector_p.h" #include @@ -148,6 +149,9 @@ void tst_QStorageInfo::currentStorage() void tst_QStorageInfo::storageList_data() { + if (QTestPrivate::isRunningArmOnX86()) + QSKIP("QEMU appears not to emulate the system calls correctly."); + QStorageInfo root = QStorageInfo::root(); QList volumes = QStorageInfo::mountedVolumes();