4#include "qplatformdefs.h"
5#include "private/qabstractfileengine_p.h"
6#include "private/qfiledevice_p.h"
7#include "private/qfsfileengine_p.h"
33#define PATH_MAX FILENAME_MAX
43 return (
path.startsWith(
"\\\\"_L1)
44 &&
path.size() > 2 &&
path.at(2) != u
'.');
52 if (
path.startsWith(
"\\\\.\\"_L1))
55 QString absPath = QFileSystemEngine::nativeAbsoluteFilePath(
path);
61 return prefix + absPath;
68 std::optional<QFile::Permissions> permissions)
73 DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
77 accessRights |= GENERIC_READ;
79 accessRights |= GENERIC_WRITE;
89 if (!nativePermissions.isOk())
95 nativePermissions.securityAttributes(),
97 FILE_ATTRIBUTE_NORMAL,
101 if (fileHandle == INVALID_HANDLE_VALUE) {
119 if (
fh ||
fd != -1) {
127 if (cachedFd != -1) {
128 if (::_close(cachedFd) && !::CloseHandle(fileHandle)) {
134 fileHandle = INVALID_HANDLE_VALUE;
140 if ((fileHandle == INVALID_HANDLE_VALUE || !::CloseHandle(fileHandle))) {
144 fileHandle = INVALID_HANDLE_VALUE;
172 if (
fh ||
fd != -1) {
176 return FlushFileBuffers(fileHandle);
214 if (
fh ||
fd != -1) {
220 if (fileHandle == INVALID_HANDLE_VALUE)
223 LARGE_INTEGER currentFilePos;
226 if (!::SetFilePointerEx(fileHandle,
offset, ¤tFilePos, FILE_CURRENT)) {
231 return qint64(currentFilePos.QuadPart);
241 if (
fh ||
fd != -1) {
246 LARGE_INTEGER currentFilePos;
249 if (!::SetFilePointerEx(fileHandle,
offset, ¤tFilePos, FILE_BEGIN)) {
264 if (
fh ||
fd != -1) {
275 if (fileHandle == INVALID_HANDLE_VALUE)
278 qint64 bytesToRead = maxlen;
282 static const qint64 maxBlockSize = 32 * 1024 * 1024;
288 if (!ReadFile(fileHandle,
data + totalRead,
blockSize, &bytesRead, NULL)) {
289 if (totalRead == 0) {
298 totalRead += bytesRead;
299 bytesToRead -= bytesRead;
300 }
while (totalRead < maxlen);
311 if (
fh ||
fd != -1) {
317 if (fileHandle == INVALID_HANDLE_VALUE)
321 return q->QAbstractFileEngine::readLine(
data, maxlen);
331 if (
fh ||
fd != -1) {
337 if (fileHandle == INVALID_HANDLE_VALUE)
346 const DWORD currentBlockSize = DWORD(
qMin(bytesToWrite,
qint64(32 * 1024 * 1024)));
348 if (!WriteFile(fileHandle,
data + totalWritten, currentBlockSize, &
bytesWritten, NULL)) {
349 if (totalWritten == 0) {
360 }
while (totalWritten <
len);
361 return qint64(totalWritten);
370 return fh ? QT_FILENO(
fh) :
fd;
391 if (
handle == INVALID_HANDLE_VALUE)
399bool QFSFileEnginePrivate::nativeRenameOverwrite(
const QFileSystemEntry &newEntry)
401 if (fileHandle == INVALID_HANDLE_VALUE)
403 const QString newFilePath = newEntry.nativeFilePath();
404 const size_t nameByteLength = newFilePath.
length() *
sizeof(wchar_t);
405 if (nameByteLength +
sizeof(
wchar_t) > std::numeric_limits<DWORD>::max())
408 constexpr size_t RenameInfoSize =
sizeof(FILE_RENAME_INFO);
409 const size_t renameDataSize = RenameInfoSize + nameByteLength +
sizeof(wchar_t);
410 QVarLengthArray<char>
v(
qsizetype(renameDataSize), 0);
413 auto renameInfoRAII =
qScopeGuard([&] { std::destroy_at(renameInfo); });
414 renameInfo->ReplaceIfExists = TRUE;
415 renameInfo->RootDirectory =
nullptr;
416 renameInfo->FileNameLength = DWORD(nameByteLength);
417 memcpy(renameInfo->FileName, newFilePath.data(), nameByteLength);
419 bool res = SetFileInformationByHandle(fileHandle, FileRenameInfo, renameInfo,
420 DWORD(renameDataSize));
422 DWORD
error = GetLastError();
439 int drv =
fileName.toUpper().at(0).toLatin1() -
'A' + 1;
440 if (_getdrive() !=
drv) {
450 if (
ret.length() >= 2 &&
ret[1] == u
':')
451 ret[0] =
ret.at(0).toUpper();
458 DWORD fileSystemFlags;
459 const UINT driveType = GetDriveType(
path);
460 return (driveType != DRIVE_REMOVABLE && driveType != DRIVE_CDROM)
461 || GetVolumeInformation(
path,
nullptr, 0,
nullptr,
nullptr,
462 &fileSystemFlags,
nullptr, 0) == TRUE;
468 const UINT oldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
470 wchar_t driveName[] = L
"A:\\";
476 driveBits = driveBits >> 1;
478 ::SetErrorMode(oldErrorMode);
489 localFd = QT_FILENO(
fh);
520 QAbstractFileEngine::FileFlags
ret;
527 QFileSystemMetaData::MetaDataFlags queryFlags;
529 queryFlags |= QFileSystemMetaData::MetaDataFlags::fromInt(
type.toInt())
546 exists =
d->doStat(queryFlags);
550 ret |= FileFlags::fromInt(
d->metaData.permissions().toInt());
555 if (
d->metaData.isDirectory()) {
562 if (
d->metaData.exists()) {
566 if (
d->fileEntry.isRoot())
568 else if (
d->metaData.isHidden())
579 if (
h == INVALID_HANDLE_VALUE) {
581 if (
d->fh &&
d->fileEntry.isEmpty())
582 localFd = QT_FILENO(
d->fh);
584 h =
HANDLE(_get_osfhandle(localFd));
586 if (
h != INVALID_HANDLE_VALUE)
598 return d->fileEntry.fileName();
600 return d->fileEntry.path();
606 }
else if (
ret.startsWith(u
'/')
609 || (
ret.size() > 2 &&
ret.at(2) != u
'/')
621 if (
ret.at(0) != u
'/') {
627 ret[0] =
ret.at(0).toUpper();
631 int slash =
ret.lastIndexOf(u
'/');
634 if (
ret.at(0) != u
'/' && slash == 2)
636 return ret.left(slash > 0 ? slash : 1);
649 return entry.filePath();
665 return d->fileEntry.filePath();
672 return d->fileEntry.isRelative();
677 static const uint nobodyID = (
uint) -2;
684 return QFileSystemEngine::owner(
d->fileEntry, own);
705 if (
d->fileHandle != INVALID_HANDLE_VALUE ||
d->fd != -1 ||
d->fh) {
708 if (fh == INVALID_HANDLE_VALUE) {
710 fh = (
HANDLE)_get_osfhandle(QT_FILENO(
d->fh));
712 fh = (
HANDLE)_get_osfhandle(
d->fd);
714 if (fh == INVALID_HANDLE_VALUE)
718 if (
seek(
size) && SetEndOfFile(fh)) {
727 if (!
d->fileEntry.isEmpty()) {
755 if (
handle == INVALID_HANDLE_VALUE) {
757 handle =
reinterpret_cast<HANDLE>(::_get_osfhandle(QT_FILENO(
d->fh)));
758 else if (
d->fd != -1)
762 if (
handle == INVALID_HANDLE_VALUE) {
778 QFile::MemoryMapFlags
flags)
806 if (mapHandle == NULL) {
810 if (
handle == INVALID_HANDLE_VALUE &&
fh)
813#ifdef Q_USE_DEPRECATED_MAP_API
821 FILE_ATTRIBUTE_NORMAL,
826 handle = INVALID_HANDLE_VALUE;
829 if (
handle == INVALID_HANDLE_VALUE) {
836 mapHandle = ::CreateFileMapping(
handle, 0, protection, 0, 0, 0);
837 if (mapHandle == NULL) {
839#ifdef Q_USE_DEPRECATED_MAP_API
846 DWORD offsetHi =
offset >> 32;
849 ::GetSystemInfo(&sysinfo);
850 DWORD
mask = sysinfo.dwAllocationGranularity - 1;
856 LPVOID mapAddress = ::MapViewOfFile(mapHandle,
access,
857 offsetHi, offsetLo,
size + extra);
864 switch(GetLastError()) {
865 case ERROR_ACCESS_DENIED:
868 case ERROR_INVALID_PARAMETER:
874 ::CloseHandle(mapHandle);
888 if (!UnmapViewOfFile(
start)) {
894 if (
maps.isEmpty()) {
895 ::CloseHandle(mapHandle);
\inmodule QtCore \reentrant
void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
QFile::FileError error() const
Returns the QFile::FileError that resulted from the last failed operation.
\inmodule QtCore\reentrant
static QString fromNativeSeparators(const QString &pathName)
static QString cleanPath(const QString &path)
Returns path with directory separators normalized (that is, platform-native separators converted to "...
static QString currentPath()
Returns the absolute path of the application's current directory.
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)
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.
bool setFileTime(const QDateTime &newDate, QFile::FileTime time) override
\reimp
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
qint64 pos() const override
\reimp
bool caseSensitive() const override
Returns false for Windows, true for Unix.
QByteArray id() const override
bool seek(qint64) override
\reimp
bool link(const QString &newName) override
Creates a link from the file currently specified by fileName() to newName.
bool isRelativePath() const override
\reimp
FileFlags fileFlags(FileFlags type) const override
\reimp
QString owner(FileOwner) const override
\reimp
bool flush() override
\reimp
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 bool createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static QFileSystemEntry getJunctionTarget(const QFileSystemEntry &link, QFileSystemMetaData &data)
static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data=nullptr)
static bool setFileTime(const QFileSystemEntry &entry, const QDateTime &newDate, QFile::FileTime whatTime, QSystemError &error)
static QFileSystemEntry currentPath()
Q_AUTOTEST_EXPORT NativePath nativeFilePath() const
Q_AUTOTEST_EXPORT bool isEmpty() const
QFILE_MAYBE_NODISCARD bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool resize(qint64 sz) override
\reimp
QString errorString() const
Returns a human-readable description of the last device error that occurred.
iterator find(const T &value)
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromWCharArray(const wchar_t *string, qsizetype size=-1)
QString & append(QChar c)
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
qsizetype length() const noexcept
Returns the number of characters in this string.
static Q_CORE_EXPORT QString stdString(int errorCode=-1)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
T * construct_at(T *ptr, Args &&... args)
DBusConnection const char DBusError * error
static bool isDriveReady(const wchar_t *path)
static bool isUncPath(const QString &path)
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 GLsizei GLuint GLint * bytesWritten
GLsizei const GLfloat * v
[13]
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLenum GLsizei const GLchar * buf
GLenum GLuint GLintptr offset
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
GLfloat GLfloat GLfloat GLfloat h
GLuint GLuint64EXT address
GLdouble GLdouble GLdouble GLdouble q
GLsizei const GLchar *const * path
QScopeGuard< typename std::decay< F >::type > qScopeGuard(F &&f)
[qScopeGuard]
static FileType fileType(const QFileInfo &fi)