Skip to content

Commit 68fb365

Browse files
kapinterQt Cherry-pick Bot
authored andcommitted
Fix VxWorks POSIX access() behavior
On VxWorks POSIX access() returns always false if it is called on file which is not on POSIX file system, like DOSFS for example. Qt for VxWorks 5.15 had similar patch omitting all access() calls and returning true. This fix takes it a step further and checks if the file is on POSIX filesystem or if it is DOSFS with read-only setting or not, in case omitting access() call and returning true. Failure became visible using QTranslator::load() method on DOSFS mmc card. Task-number: QTBUG-134627 Pick-to: 6.8 Change-Id: I9c257d3cba1a2b976f2775ad129aae0e09f68ffd Reviewed-by: Thiago Macieira <[email protected]> (cherry picked from commit fd73b22) Reviewed-by: Qt Cherry-pick Bot <[email protected]>
1 parent 9909c89 commit 68fb365

File tree

1 file changed

+41
-3
lines changed

1 file changed

+41
-3
lines changed

src/corelib/io/qfilesystemengine_unix.cpp

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@
6969
#endif
7070
#endif
7171

72+
#if defined(Q_OS_VXWORKS)
73+
# include <sys/statfs.h>
74+
# if __has_include(<dosFsLib.h>)
75+
# include <dosFsLib.h>
76+
# endif
77+
#endif
78+
7279
#if defined(Q_OS_ANDROID)
7380
// statx() is disabled on Android because quite a few systems
7481
// come with sandboxes that kill applications that make system calls outside a
@@ -331,8 +338,15 @@ flagsFromStMode(mode_t mode, [[maybe_unused]] quint64 attributes)
331338
#ifdef UF_HIDDEN
332339
if (attributes & UF_HIDDEN)
333340
entryFlags |= QFileSystemMetaData::HiddenAttribute;
341+
#elif defined(Q_OS_VXWORKS) && __has_include(<dosFsLib.h>)
342+
if (attributes & DOS_ATTR_RDONLY) {
343+
// on a DOS FS, stat() always returns 0777 bits set in st_mode
344+
// when DOS FS is read only the write permissions are removed
345+
entryFlags &= ~QFileSystemMetaData::OwnerWritePermission;
346+
entryFlags &= ~QFileSystemMetaData::GroupWritePermission;
347+
entryFlags &= ~QFileSystemMetaData::OtherWritePermission;
348+
}
334349
#endif
335-
336350
return entryFlags;
337351
}
338352

@@ -476,8 +490,9 @@ void QFileSystemMetaData::fillFromStatBuf(const QT_STATBUF &statBuffer)
476490
quint64 attributes = 0;
477491
#if defined(UF_SETTABLE) // BSDs (incl. Darwin)
478492
attributes = statBuffer.st_flags;
493+
#elif defined(Q_OS_VXWORKS) && __has_include(<dosFsLib.h>)
494+
attributes = statBuffer.st_attrib;
479495
#endif
480-
481496
// Permissions
482497
MetaDataFlags flags = flagsFromStMode(statBuffer.st_mode, attributes);
483498
entryFlags |= flags;
@@ -990,6 +1005,30 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
9901005

9911006
// third, we try access(2)
9921007
if (what & (QFileSystemMetaData::UserPermissions | QFileSystemMetaData::ExistsAttribute)) {
1008+
#if defined(Q_OS_VXWORKS)
1009+
// on VxWorks if the filesystem is not POSIX, access() always returns false, despite the
1010+
// file is readable
1011+
struct statfs statBuf;
1012+
if (statfs(nativeFilePath, &statBuf) != 0) {
1013+
what &= ~QFileSystemMetaData::LinkType; // don't clear link: could be broken symlink
1014+
data.clearFlags(what);
1015+
return false;
1016+
}
1017+
if (statBuf.f_type != NFSV2_MAGIC && statBuf.f_type != NFSV3_MAGIC &&
1018+
statBuf.f_type != HRFS_MAGIC) {
1019+
#if __has_include(<dosFsLib.h>)
1020+
if (data.entryFlags & QFileSystemMetaData::OwnerWritePermission) {
1021+
data.entryFlags |= QFileSystemMetaData::UserWritePermission;
1022+
}
1023+
if (data.entryFlags & QFileSystemMetaData::OwnerExecutePermission) {
1024+
data.entryFlags |= QFileSystemMetaData::UserExecutePermission;
1025+
}
1026+
#endif
1027+
data.entryFlags |= QFileSystemMetaData::UserReadPermission |
1028+
QFileSystemMetaData::ExistsAttribute;
1029+
return true;
1030+
}
1031+
#endif
9931032
// calculate user permissions
9941033
auto checkAccess = [&](QFileSystemMetaData::MetaDataFlag flag, int mode) {
9951034
if (entryErrno != 0 || (what & flag) == 0)
@@ -1001,7 +1040,6 @@ bool QFileSystemEngine::fillMetaData(const QFileSystemEntry &entry, QFileSystemM
10011040
entryErrno = errno;
10021041
}
10031042
};
1004-
10051043
checkAccess(QFileSystemMetaData::UserReadPermission, R_OK);
10061044
checkAccess(QFileSystemMetaData::UserWritePermission, W_OK);
10071045
checkAccess(QFileSystemMetaData::UserExecutePermission, X_OK);

0 commit comments

Comments
 (0)