Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qfsfileengine_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QFSFILEENGINE_P_H
5#define QFSFILEENGINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include "qplatformdefs.h"
19#include "QtCore/private/qabstractfileengine_p.h"
20#include <QtCore/private/qfilesystementry_p.h>
21#include <QtCore/private/qfilesystemmetadata_p.h>
22#include <qhash.h>
23
24#include <optional>
25
26#ifdef Q_OS_UNIX
27#include <sys/types.h> // for mode_t
28#endif
29
30#ifndef QT_NO_FSFILEENGINE
31
33
35{
36 bool ok;
37 QIODevice::OpenMode openMode;
39};
40Q_CORE_EXPORT ProcessOpenModeResult processOpenModeFlags(QIODevice::OpenMode mode);
41
43
44class Q_CORE_EXPORT QFSFileEngine : public QAbstractFileEngine
45{
46 Q_DECLARE_PRIVATE(QFSFileEngine)
47public:
49 explicit QFSFileEngine(const QString &file);
51
52 bool open(QIODevice::OpenMode openMode, std::optional<QFile::Permissions> permissions) override;
53 bool open(QIODevice::OpenMode flags, FILE *fh);
54 bool close() override;
55 bool flush() override;
56 bool syncToDisk() override;
57 qint64 size() const override;
58 qint64 pos() const override;
59 bool seek(qint64) override;
60 bool isSequential() const override;
61 bool remove() override;
62 bool copy(const QString &newName) override;
63
64 bool rename(const QString &newName) override
65 { return rename_helper(newName, Rename); }
66 bool renameOverwrite(const QString &newName) override
67 { return rename_helper(newName, RenameOverwrite); }
68
69 bool link(const QString &newName) override;
70 bool mkdir(const QString &dirName, bool createParentDirectories,
71 std::optional<QFile::Permissions> permissions) const override;
72 bool rmdir(const QString &dirName, bool recurseParentDirectories) const override;
73 bool setSize(qint64 size) override;
74 bool caseSensitive() const override;
75 bool isRelativePath() const override;
76 QStringList entryList(QDir::Filters filters, const QStringList &filterNames) const override;
77 FileFlags fileFlags(FileFlags type) const override;
78 bool setPermissions(uint perms) override;
79 QByteArray id() const override;
80 QString fileName(FileName file) const override;
81 uint ownerId(FileOwner) const override;
82 QString owner(FileOwner) const override;
83 bool setFileTime(const QDateTime &newDate, QFile::FileTime time) override;
84 QDateTime fileTime(QFile::FileTime time) const override;
85 void setFileName(const QString &file) override;
86 void setFileEntry(QFileSystemEntry &&entry);
87 int handle() const override;
88
89#ifndef QT_NO_FILESYSTEMITERATOR
90 IteratorUniquePtr beginEntryList(const QString &path, QDir::Filters filters,
91 const QStringList &filterNames) override;
92#endif
93
94 qint64 read(char *data, qint64 maxlen) override;
95 qint64 readLine(char *data, qint64 maxlen) override;
96 qint64 write(const char *data, qint64 len) override;
97 bool cloneTo(QAbstractFileEngine *target) override;
98
99 virtual bool isUnnamedFile() const
100 { return false; }
101
102 bool extension(Extension extension, const ExtensionOption *option = nullptr, ExtensionReturn *output = nullptr) override;
103 bool supportsExtension(Extension extension) const override;
104
105 //FS only!!
106 bool open(QIODevice::OpenMode flags, int fd);
107 bool open(QIODevice::OpenMode flags, int fd, QFile::FileHandleFlags handleFlags);
108 bool open(QIODevice::OpenMode flags, FILE *fh, QFile::FileHandleFlags handleFlags);
109 static bool setCurrentPath(const QString &path);
110 static QString currentPath(const QString &path = QString());
111 static QString homePath();
112 static QString rootPath();
113 static QString tempPath();
114 static QFileInfoList drives();
115
116protected:
118
119private:
120 enum RenameMode : int { Rename, RenameOverwrite };
121 bool rename_helper(const QString &newName, RenameMode mode);
122};
123
125{
126 Q_DECLARE_PUBLIC(QFSFileEngine)
127
128public:
129#ifdef Q_OS_WIN
130 static QString longFileName(const QString &path);
131#endif
132
134 QIODevice::OpenMode openMode;
135
136 bool nativeOpen(QIODevice::OpenMode openMode, std::optional<QFile::Permissions> permissions);
137 bool openFh(QIODevice::OpenMode flags, FILE *fh);
138 bool openFd(QIODevice::OpenMode flags, int fd);
139 bool nativeClose();
140 bool closeFdFh();
141 bool nativeFlush();
142 bool nativeSyncToDisk();
143 bool flushFh();
144 qint64 nativeSize() const;
145#ifndef Q_OS_WIN
146 qint64 sizeFdFh() const;
147#endif
148 qint64 nativePos() const;
149 qint64 posFdFh() const;
150 bool nativeSeek(qint64);
151 bool seekFdFh(qint64);
152 qint64 nativeRead(char *data, qint64 maxlen);
153 qint64 readFdFh(char *data, qint64 maxlen);
154 qint64 nativeReadLine(char *data, qint64 maxlen);
155 qint64 readLineFdFh(char *data, qint64 maxlen);
156 qint64 nativeWrite(const char *data, qint64 len);
157 qint64 writeFdFh(const char *data, qint64 len);
158 int nativeHandle() const;
159 bool nativeIsSequential() const;
160#ifndef Q_OS_WIN
161 bool isSequentialFdFh() const;
162#endif
163#ifdef Q_OS_WIN
164 bool nativeRenameOverwrite(const QFileSystemEntry &newEntry);
165#endif
166
167 uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
168 bool unmap(uchar *ptr);
169 void unmapAll();
170
172
173 FILE *fh;
174
175#ifdef Q_OS_WIN
176 HANDLE fileHandle;
177 HANDLE mapHandle;
178 QHash<uchar *, DWORD /* offset % AllocationGranularity */> maps;
179
180 mutable int cachedFd;
181 mutable DWORD fileAttrib;
182#else
184 int start; // offset % PageSize
185 size_t length; // length + offset % PageSize
186 };
187 QHash<uchar *, StartAndLength> maps;
188#endif
189 int fd;
190
192 {
195 IOWriteCommand
196 };
200
201 mutable uint is_sequential : 2;
202 mutable uint tried_stat : 1;
203 mutable uint need_lstat : 1;
204 mutable uint is_link : 1;
205
206#if defined(Q_OS_WIN)
207 bool doStat(QFileSystemMetaData::MetaDataFlags flags) const;
208#else
209 bool doStat(QFileSystemMetaData::MetaDataFlags flags = QFileSystemMetaData::PosixStatFlags) const;
210#endif
211 bool isSymlink() const;
212
213#if defined(Q_OS_WIN32)
214 int sysOpen(const QString &, int flags);
215#endif
216
217 static bool openModeCanCreate(QIODevice::OpenMode openMode)
218 {
219 // WriteOnly can create, but only when ExistingOnly isn't specified.
220 // ReadOnly by itself never creates.
221 return (openMode & QFile::WriteOnly) && !(openMode & QFile::ExistingOnly);
222 }
223protected:
225
226 void init();
227
228 QAbstractFileEngine::FileFlags getPermissions(QAbstractFileEngine::FileFlags type) const;
229
230#ifdef Q_OS_UNIX
231 bool nativeOpenImpl(QIODevice::OpenMode openMode, mode_t mode);
232#endif
233};
234
236
237#endif // QT_NO_FSFILEENGINE
238
239#endif // QFSFILEENGINE_P_H
\inmodule QtCore \reentrant
\inmodule QtCore
Definition qbytearray.h:57
\inmodule QtCore\reentrant
Definition qdatetime.h:283
QHash< uchar *, StartAndLength > maps
QIODevice::OpenMode openMode
QFileSystemEntry fileEntry
QFileSystemMetaData metaData
static bool openModeCanCreate(QIODevice::OpenMode openMode)
bool isSequentialFdFh() const
QAbstractFileEngine::FileFlags getPermissions(QAbstractFileEngine::FileFlags type) const
LastIOCommand lastIOCommand
\inmodule QtCore
bool rename(const QString &newName) override
Requests that the file be renamed to newName in the file system.
bool renameOverwrite(const QString &newName) override
virtual bool isUnnamedFile() const
\inmodule QtCore
Definition qhash.h:820
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
void extension()
[6]
Definition dialogs.cpp:230
QMap< QString, QString > map
[6]
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
Q_CORE_EXPORT ProcessOpenModeResult processOpenModeFlags(QIODevice::OpenMode mode)
static ControlElement< T > * ptr(QWidget *widget)
GLuint64 GLenum void * handle
GLenum mode
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint id
[7]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum type
GLenum target
GLbitfield flags
GLenum GLuint GLintptr offset
GLuint64 GLenum GLint fd
GLuint entry
GLsizei const GLchar *const * path
GLuint GLenum option
GLenum GLsizei len
#define Q_AUTOTEST_EXPORT
static QT_BEGIN_NAMESPACE void init(QTextBoundaryFinder::BoundaryType type, QStringView str, QCharAttributes *attributes)
unsigned char uchar
Definition qtypes.h:32
unsigned int uint
Definition qtypes.h:34
long long qint64
Definition qtypes.h:60
ReturnedValue read(const char *data)
QT_BEGIN_NAMESPACE typedef uchar * output
QFile file
[0]
file setFileName("readme.txt")
file open(QIODevice::ReadOnly)
gzip write("uncompressed data")
settings remove("monkey")
const QStringList filters({"Image files (*.png *.xpm *.jpg)", "Text files (*.txt)", "Any files (*)" })
[6]
QIODevice::OpenMode openMode