4#include "qplatformdefs.h"
5#include "private/qabstractfileengine_p.h"
6#include "private/qfiledevice_p.h"
7#include "private/qfsfileengine_p.h"
8#include "private/qcore_unix_p.h"
13#ifndef QT_NO_FSFILEENGINE
24#if defined(Q_OS_MACOS)
25# include <private/qcore_mac_p.h>
37 int oflags = QT_OPEN_RDONLY;
38#ifdef QT_LARGEFILE_SUPPORT
39 oflags |= QT_OPEN_LARGEFILE;
43 oflags = QT_OPEN_RDWR;
45 oflags = QT_OPEN_WRONLY;
48 oflags |= QT_OPEN_CREAT;
51 oflags |= QT_OPEN_TRUNC;
54 oflags |= QT_OPEN_APPEND;
57 oflags |= QT_OPEN_EXCL;
65#if QT_CONFIG(translation)
76 std::optional<QFile::Permissions> permissions)
78 return nativeOpenImpl(
openMode, permissions ? QtPrivate::toMode_t(*permissions) : 0666);
84bool QFSFileEnginePrivate::nativeOpenImpl(QIODevice::OpenMode openMode, mode_t
mode)
89 "QFSFileEngine no longer supports buffered mode; upper layer must buffer");
96 }
while (
fd == -1 && errno == EINTR);
120 ret = QT_LSEEK(
fd, 0, SEEK_END);
121 }
while (
ret == -1 && errno == EINTR);
162#if defined(_POSIX_SYNCHRONIZED_IO) && _POSIX_SYNCHRONIZED_IO > 0
180 size_t readBytes = 0;
181 int oldFlags = fcntl(QT_FILENO(
fh), F_GETFL);
182 for (
int i = 0;
i < 2; ++
i) {
184 if ((oldFlags & O_NONBLOCK) == 0)
185 fcntl(QT_FILENO(
fh), F_SETFL, oldFlags | O_NONBLOCK);
190 read = fread(
data + readBytes, 1,
size_t(
len - readBytes),
fh);
191 }
while (
read == 0 && !feof(
fh) && errno == EINTR);
202 if ((oldFlags & O_NONBLOCK) == 0) {
203 fcntl(QT_FILENO(
fh), F_SETFL, oldFlags);
204 if (readBytes == 0) {
207 readByte = fgetc(
fh);
208 }
while (readByte == -1 && errno == EINTR);
209 if (readByte != -1) {
219 if ((oldFlags & O_NONBLOCK) == 0) {
220 fcntl(QT_FILENO(
fh), F_SETFL, oldFlags);
222 if (readBytes == 0 && !feof(
fh)) {
270 return fh ? fileno(
fh) :
fd;
322 localFd = QT_FILENO(
fh);
351 QAbstractFileEngine::FileFlags
ret = { };
358 QFileSystemMetaData::MetaDataFlags queryFlags = { };
360 queryFlags |= QFileSystemMetaData::MetaDataFlags(
uint(
type.toInt()))
379 exists =
d->doStat(queryFlags);
382 if (!exists && !
d->metaData.isLink())
386 ret |= FileFlags(
uint(
d->metaData.permissions().toInt()));
389 if (
d->metaData.isAlias()) {
395 if (
d->metaData.isFile()) {
397 }
else if (
d->metaData.isDirectory()) {
408 if (!
d->metaData.wasDeleted())
410 if (
d->fileEntry.isRoot())
412 else if (
d->metaData.isHidden())
434 return d->fileEntry.fileName();
436 return d->fileEntry.path();
448 if (
d->isSymlink()) {
450 return entry.filePath();
454 if (
d->isSymlink()) {
456 return entry.filePath();
465 return d->fileEntry.filePath();
472 return fp.isEmpty() ||
fp.at(0) != u
'/';
478 static const uint nobodyID = (
uint) -2;
481 return d->metaData.ownerId(own);
518 ret = QT_FTRUNCATE(
d->fd,
size) == 0;
520 ret = QT_FTRUNCATE(QT_FILENO(
d->fh),
size) == 0;
522 ret = QT_TRUNCATE(
d->fileEntry.nativeFilePath().constData(),
size) == 0;
549 qint64 maxFileOffset = std::numeric_limits<QT_OFF_T>::max();
550#if (defined(Q_OS_LINUX) || defined(Q_OS_ANDROID)) && Q_PROCESSOR_WORDSIZE == 4
558 maxFileOffset =
qMin((
Q_INT64_C(1) << (32+12)) - 1, maxFileOffset);
567 if (offset < 0 || offset > maxFileOffset
577 qWarning(
"QFSFileEngine::map: Mapping a file beyond its size is not portable");
583 int sharemode = MAP_SHARED;
585 sharemode = MAP_PRIVATE;
589#if defined(Q_OS_INTEGRITY)
590 int pageSize = sysconf(_SC_PAGESIZE);
592 int pageSize = getpagesize();
594 int extra =
offset % pageSize;
601 size_t realSize = (size_t)
size + extra;
602 QT_OFF_T realOffset = QT_OFF_T(
offset);
603 realOffset &= ~(QT_OFF_T(pageSize - 1));
605 void *mapAddress = QT_MMAP((
void*)
nullptr, realSize,
632#if !defined(Q_OS_INTEGRITY)
641 size_t len =
it->length;
662 int srcfd =
d->nativeHandle();
663 int dstfd =
target->handle();
664 return QFileSystemEngine::cloneFile(srcfd, dstfd,
d->metaData);
\inmodule QtCore \reentrant
FileOwner
\value OwnerUser The user who owns the file.
FileTime
These are used by the fileTime() function.
void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
FileName
These values are used to request a file name in a particular format.
QFile::FileError error() const
Returns the QFile::FileError that resulted from the last failed operation.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
\inmodule QtCore\reentrant
qint64 nativeRead(char *data, qint64 maxlen)
qint64 readFdFh(char *data, qint64 maxlen)
QHash< uchar *, StartAndLength > maps
qint64 writeFdFh(const char *data, qint64 len)
QIODevice::OpenMode openMode
QFileSystemEntry fileEntry
qint64 nativeSize() const
bool doStat(QFileSystemMetaData::MetaDataFlags flags=QFileSystemMetaData::PosixStatFlags) const
bool nativeOpen(QIODevice::OpenMode openMode, std::optional< QFile::Permissions > permissions)
QFileSystemMetaData metaData
static bool openModeCanCreate(QIODevice::OpenMode openMode)
bool isSequentialFdFh() const
qint64 readLineFdFh(char *data, qint64 maxlen)
bool nativeIsSequential() const
qint64 nativeWrite(const char *data, qint64 len)
uchar * map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
qint64 nativeReadLine(char *data, qint64 maxlen)
static QFileInfoList drives()
For Windows, returns the list of drives in the file system as a list of QFileInfo objects.
QString fileName(FileName file) const override
\reimp
uint ownerId(FileOwner) const override
In Unix, if stat() is successful, the uid is returned if own is the owner.
static QString currentPath(const QString &path=QString())
For Unix, returns the current working directory for the file engine.
bool cloneTo(QAbstractFileEngine *target) override
\reimp
bool setSize(qint64 size) override
\reimp
bool setPermissions(uint perms) override
\reimp
bool caseSensitive() const override
Returns false for Windows, true for Unix.
static QString rootPath()
Returns the root path.
QByteArray id() const override
bool link(const QString &newName) override
Creates a link from the file currently specified by fileName() to newName.
bool isRelativePath() const override
\reimp
bool setFileTime(const QDateTime &newDate, FileTime time) override
\reimp
FileFlags fileFlags(FileFlags type) const override
\reimp
QString owner(FileOwner) const override
\reimp
\inmodule QtCore \reentrant
static bool setFileTime(const QFileSystemEntry &entry, const QDateTime &newDate, QAbstractFileEngine::FileTime whatTime, QSystemError &error)
static QFileSystemEntry getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data)
static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
static QByteArray id(const QFileSystemEntry &entry)
static QFileSystemEntry getRawLinkPath(const QFileSystemEntry &link, QFileSystemMetaData &data)
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
static QString bundleName(const QFileSystemEntry &)
static bool createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data=nullptr)
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
static QString resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
static QString resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
static QFileSystemEntry currentPath()
Q_AUTOTEST_EXPORT NativePath nativeFilePath() const
Q_AUTOTEST_EXPORT bool isEmpty() const
Q_AUTOTEST_EXPORT QString filePath() const
iterator find(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
QSet< QString >::iterator it
Combined button and popup list for selecting options.
#define EINTR_LOOP(var, cmd)
static QT_BEGIN_NAMESPACE int openModeToOpenFlags(QIODevice::OpenMode mode)
static QString msgOpenDirectory()
Q_DECL_COLD_FUNCTION Q_CORE_EXPORT QString qt_error_string(int errorCode=-1)
static ControlElement< T > * ptr(QWidget *widget)
constexpr const T & qMin(const T &a, const T &b)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint GLsizei const GLchar * message
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
#define Q_ASSERT_X(cond, x, msg)
#define QT_TRANSLATE_NOOP(scope, x)
unsigned long long quint64
ReturnedValue read(const char *data)