4#include "qplatformdefs.h"
5#include "private/qabstractfileengine_p.h"
6#include "private/qfiledevice_p.h"
7#include "private/qfsfileengine_p.h"
31#define PATH_MAX FILENAME_MAX
41 return (
path.startsWith(
"\\\\"_L1)
42 &&
path.size() > 2 &&
path.at(2) != u
'.');
50 if (
path.startsWith(
"\\\\.\\"_L1))
53 QString absPath = QFileSystemEngine::nativeAbsoluteFilePath(
path);
59 return prefix + absPath;
66 std::optional<QFile::Permissions> permissions)
71 DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
75 accessRights |= GENERIC_READ;
77 accessRights |= GENERIC_WRITE;
87 if (!nativePermissions.isOk())
93 nativePermissions.securityAttributes(),
95 FILE_ATTRIBUTE_NORMAL,
99 if (fileHandle == INVALID_HANDLE_VALUE) {
117 if (
fh ||
fd != -1) {
125 if (cachedFd != -1) {
126 if (::_close(cachedFd) && !::CloseHandle(fileHandle)) {
132 fileHandle = INVALID_HANDLE_VALUE;
138 if ((fileHandle == INVALID_HANDLE_VALUE || !::CloseHandle(fileHandle))) {
142 fileHandle = INVALID_HANDLE_VALUE;
170 if (
fh ||
fd != -1) {
174 return FlushFileBuffers(fileHandle);
212 if (
fh ||
fd != -1) {
218 if (fileHandle == INVALID_HANDLE_VALUE)
221 LARGE_INTEGER currentFilePos;
224 if (!::SetFilePointerEx(fileHandle,
offset, ¤tFilePos, FILE_CURRENT)) {
229 return qint64(currentFilePos.QuadPart);
239 if (
fh ||
fd != -1) {
244 LARGE_INTEGER currentFilePos;
247 if (!::SetFilePointerEx(fileHandle,
offset, ¤tFilePos, FILE_BEGIN)) {
262 if (
fh ||
fd != -1) {
273 if (fileHandle == INVALID_HANDLE_VALUE)
276 qint64 bytesToRead = maxlen;
280 static const qint64 maxBlockSize = 32 * 1024 * 1024;
286 if (!ReadFile(fileHandle,
data + totalRead,
blockSize, &bytesRead, NULL)) {
287 if (totalRead == 0) {
296 totalRead += bytesRead;
297 bytesToRead -= bytesRead;
298 }
while (totalRead < maxlen);
309 if (
fh ||
fd != -1) {
315 if (fileHandle == INVALID_HANDLE_VALUE)
319 return q->QAbstractFileEngine::readLine(
data, maxlen);
329 if (
fh ||
fd != -1) {
335 if (fileHandle == INVALID_HANDLE_VALUE)
344 const DWORD currentBlockSize = DWORD(
qMin(bytesToWrite,
qint64(32 * 1024 * 1024)));
346 if (!WriteFile(fileHandle,
data + totalWritten, currentBlockSize, &
bytesWritten, NULL)) {
347 if (totalWritten == 0) {
358 }
while (totalWritten <
len);
359 return qint64(totalWritten);
368 return fh ? QT_FILENO(
fh) :
fd;
389 if (
handle == INVALID_HANDLE_VALUE)
408 int drv =
fileName.toUpper().at(0).toLatin1() -
'A' + 1;
409 if (_getdrive() !=
drv) {
419 if (
ret.length() >= 2 &&
ret[1] == u
':')
420 ret[0] =
ret.at(0).toUpper();
427 DWORD fileSystemFlags;
428 const UINT driveType = GetDriveType(
path);
429 return (driveType != DRIVE_REMOVABLE && driveType != DRIVE_CDROM)
430 || GetVolumeInformation(
path,
nullptr, 0,
nullptr,
nullptr,
431 &fileSystemFlags,
nullptr, 0) == TRUE;
437 const UINT oldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOOPENFILEERRORBOX);
439 wchar_t driveName[] = L
"A:\\";
445 driveBits = driveBits >> 1;
447 ::SetErrorMode(oldErrorMode);
458 localFd = QT_FILENO(
fh);
489 QAbstractFileEngine::FileFlags
ret;
496 QFileSystemMetaData::MetaDataFlags queryFlags;
498 queryFlags |= QFileSystemMetaData::MetaDataFlags::fromInt(
type.toInt())
515 exists =
d->doStat(queryFlags);
519 ret |= FileFlags::fromInt(
d->metaData.permissions().toInt());
524 if (
d->metaData.isDirectory()) {
531 if (
d->metaData.exists()) {
535 if (
d->fileEntry.isRoot())
537 else if (
d->metaData.isHidden())
548 if (
h == INVALID_HANDLE_VALUE) {
550 if (
d->fh &&
d->fileEntry.isEmpty())
551 localFd = QT_FILENO(
d->fh);
553 h =
HANDLE(_get_osfhandle(localFd));
555 if (
h != INVALID_HANDLE_VALUE)
567 return d->fileEntry.fileName();
569 return d->fileEntry.path();
575 }
else if (
ret.startsWith(u
'/')
578 || (
ret.size() > 2 &&
ret.at(2) != u
'/')
590 if (
ret.at(0) != u
'/') {
596 ret[0] =
ret.at(0).toUpper();
600 int slash =
ret.lastIndexOf(u
'/');
603 if (
ret.at(0) != u
'/' && slash == 2)
605 return ret.left(slash > 0 ? slash : 1);
618 return entry.filePath();
634 return d->fileEntry.filePath();
641 return d->fileEntry.isRelative();
646 static const uint nobodyID = (
uint) -2;
653 return QFileSystemEngine::owner(
d->fileEntry, own);
674 if (
d->fileHandle != INVALID_HANDLE_VALUE ||
d->fd != -1 ||
d->fh) {
677 if (fh == INVALID_HANDLE_VALUE) {
679 fh = (
HANDLE)_get_osfhandle(QT_FILENO(
d->fh));
681 fh = (
HANDLE)_get_osfhandle(
d->fd);
683 if (fh == INVALID_HANDLE_VALUE)
687 if (
seek(
size) && SetEndOfFile(fh)) {
696 if (!
d->fileEntry.isEmpty()) {
724 if (
handle == INVALID_HANDLE_VALUE) {
726 handle =
reinterpret_cast<HANDLE>(::_get_osfhandle(QT_FILENO(
d->fh)));
727 else if (
d->fd != -1)
731 if (
handle == INVALID_HANDLE_VALUE) {
747 QFile::MemoryMapFlags
flags)
775 if (mapHandle == NULL) {
779 if (
handle == INVALID_HANDLE_VALUE &&
fh)
782#ifdef Q_USE_DEPRECATED_MAP_API
790 FILE_ATTRIBUTE_NORMAL,
795 handle = INVALID_HANDLE_VALUE;
798 if (
handle == INVALID_HANDLE_VALUE) {
805 mapHandle = ::CreateFileMapping(
handle, 0, protection, 0, 0, 0);
806 if (mapHandle == NULL) {
808#ifdef Q_USE_DEPRECATED_MAP_API
815 DWORD offsetHi =
offset >> 32;
818 ::GetSystemInfo(&sysinfo);
819 DWORD
mask = sysinfo.dwAllocationGranularity - 1;
825 LPVOID mapAddress = ::MapViewOfFile(mapHandle,
access,
826 offsetHi, offsetLo,
size + extra);
833 switch(GetLastError()) {
834 case ERROR_ACCESS_DENIED:
837 case ERROR_INVALID_PARAMETER:
843 ::CloseHandle(mapHandle);
857 if (!UnmapViewOfFile(
start)) {
863 if (
maps.isEmpty()) {
864 ::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
bool isValid() const
Returns true if this datetime represents a definite moment, otherwise false.
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.
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
bool setFileTime(const QDateTime &newDate, FileTime time) override
\reimp
FileFlags fileFlags(FileFlags type) const override
\reimp
QString owner(FileOwner) const override
\reimp
bool flush() 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 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 QFileSystemEntry currentPath()
Q_AUTOTEST_EXPORT NativePath nativeFilePath() const
Q_AUTOTEST_EXPORT bool isEmpty() const
Q_AUTOTEST_EXPORT QString filePath() const
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...
static Q_CORE_EXPORT QString stdString(int errorCode=-1)
QSet< QString >::iterator it
Combined button and popup list for selecting options.
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
GLuint64 GLenum void * handle
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLenum GLuint GLenum GLsizei const GLchar * buf
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
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
static FileType fileType(const QFileInfo &fi)