43 #include "qplatformdefs.h" 45 #include "private/qfsfileengine_p.h" 51 #include "private/qmutexpool_p.h" 56 #if !defined(Q_OS_WINCE) 57 # include <sys/types.h> 59 # include <winioctl.h> 69 #define SECURITY_WIN32 73 #define PATH_MAX FILENAME_MAX 78 #if !defined(Q_OS_WINCE) 79 static inline bool isUncPath(
const QString &path)
96 #if !defined(Q_OS_WINCE) 98 if (isUncPath(absPath)) {
102 return prefix + absPath;
116 DWORD shareMode = FILE_SHARE_READ | FILE_SHARE_WRITE;
118 int accessRights = 0;
120 accessRights |= GENERIC_READ;
122 accessRights |= GENERIC_WRITE;
124 SECURITY_ATTRIBUTES securityAtts = {
sizeof(SECURITY_ATTRIBUTES), NULL,
FALSE };
134 FILE_ATTRIBUTE_NORMAL,
161 if (
fh ||
fd != -1) {
170 if (cachedFd != -1) {
171 if (::_close(cachedFd) && !::CloseHandle(
fileHandle)) {
226 #if defined(Q_OS_WINCE) 229 QT_OFF_T oldPos = QT_FTELL(
fh);
230 QT_FSEEK(
fh, 0, SEEK_END);
232 QT_FSEEK(
fh, oldPos, SEEK_SET);
233 if (fileSize == -1) {
265 if (
fh ||
fd != -1) {
274 #if !defined(Q_OS_WINCE) 275 LARGE_INTEGER currentFilePos;
276 LARGE_INTEGER offset;
278 if (!::SetFilePointerEx(
fileHandle, offset, ¤tFilePos, FILE_CURRENT)) {
283 return qint64(currentFilePos.QuadPart);
285 LARGE_INTEGER filepos;
286 filepos.HighPart = 0;
287 DWORD newFilePointer = SetFilePointer(
fileHandle, 0, &filepos.HighPart, FILE_CURRENT);
288 if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
293 filepos.LowPart = newFilePointer;
294 return filepos.QuadPart;
305 if (
fh ||
fd != -1) {
310 #if !defined(Q_OS_WINCE) 311 LARGE_INTEGER currentFilePos;
312 LARGE_INTEGER offset;
313 offset.QuadPart = pos;
314 if (!::SetFilePointerEx(
fileHandle, offset, ¤tFilePos, FILE_BEGIN)) {
321 DWORD newFilePointer;
322 LARGE_INTEGER *li =
reinterpret_cast<LARGE_INTEGER*
>(&pos);
323 newFilePointer = SetFilePointer(
fileHandle, li->LowPart, &li->HighPart, FILE_BEGIN);
324 if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
340 if (
fh ||
fd != -1) {
354 DWORD bytesToRead = DWORD(maxlen);
358 static const DWORD maxBlockSize = 32 * 1024 * 1024;
362 DWORD
blockSize = qMin<DWORD>(bytesToRead, maxBlockSize);
364 if (!ReadFile(
fileHandle,
data + totalRead, blockSize, &bytesRead, NULL)) {
365 if (totalRead == 0) {
374 totalRead += bytesRead;
375 bytesToRead -= bytesRead;
376 }
while (totalRead < maxlen);
387 if (
fh ||
fd != -1) {
397 return q->QAbstractFileEngine::readLine(
data, maxlen);
407 if (
fh ||
fd != -1) {
416 qint64 bytesToWrite = DWORD(len);
420 static const DWORD maxBlockSize = 32 * 1024 * 1024;
424 DWORD
blockSize = qMin<DWORD>(bytesToWrite, maxBlockSize);
426 if (!WriteFile(
fileHandle,
data + totalWritten, blockSize, &bytesWritten, NULL)) {
427 if (totalWritten == 0) {
434 if (bytesWritten == 0)
436 totalWritten += bytesWritten;
437 bytesToWrite -= bytesWritten;
438 }
while (totalWritten < len);
439 return qint64(totalWritten);
448 return fh ? QT_FILENO(
fh) :
fd;
470 #if !defined(Q_OS_WINCE) 473 handle = (
HANDLE)_get_osfhandle(
fh ? QT_FILENO(
fh) :
fd);
474 if (handle == INVALID_HANDLE_VALUE)
477 DWORD fileType = GetFileType(handle);
478 return (fileType == FILE_TYPE_CHAR)
479 || (fileType == FILE_TYPE_PIPE);
537 #if !defined(Q_OS_WINCE) 540 if (fileName.
length() >= 2 &&
580 #if !defined(Q_OS_WINCE) 581 #if defined(Q_OS_WIN32) 583 #elif defined(Q_OS_OS2EMX) 585 if (DosQueryCurrentDisk(&cur, &driveBits) != NO_ERROR)
587 driveBits &= 0x3ffffff;
589 char driveName[] =
"A:/";
595 driveBits = driveBits >> 1;
609 #if !defined(Q_OS_WINCE) 612 localFd = QT_FILENO(
fh);
626 #if !defined(Q_OS_WINCE) 627 #if !defined(QT_NO_LIBRARY) && !defined(Q_CC_MWERKS) 634 bool neededCoInit =
false;
636 HRESULT hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (
void **)&psl);
638 if (hres == CO_E_NOTINITIALIZED) {
641 hres = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, IID_IShellLink, (
void **)&psl);
644 if (SUCCEEDED(hres)) {
646 if (SUCCEEDED(hres)) {
648 if (SUCCEEDED(hres)) {
650 hres = psl->QueryInterface(IID_IPersistFile, (
void **)&ppf);
651 if (SUCCEEDED(hres)) {
652 hres = ppf->Save((
wchar_t*)linkName.
utf16(),
TRUE);
671 #endif // QT_NO_LIBRARY 681 bool ret = SUCCEEDED(SHCreateShortcut((
wchar_t*)linkName.
utf16(), (
wchar_t*)orgName.
utf16()));
698 QAbstractFileEngine::FileFlags ret = 0;
700 if (type & FlagsMask)
701 ret |= LocalDiskFlag;
705 QFileSystemMetaData::MetaDataFlags queryFlags = 0;
707 queryFlags |= QFileSystemMetaData::MetaDataFlags(
uint(type))
711 if (type & TypesMask)
718 if (type & FlagsMask)
724 exists =
d->doStat(queryFlags);
727 if (exists && (type & PermsMask))
728 ret |= FileFlags(
uint(
d->metaData.permissions()));
730 if (type & TypesMask) {
731 if ((type & LinkType) &&
d->metaData.isLegacyLink())
733 if (
d->metaData.isDirectory()) {
734 ret |= DirectoryType;
739 if (type & FlagsMask) {
740 if (
d->metaData.exists()) {
742 if (
d->fileEntry.isRoot())
744 else if (
d->metaData.isHidden())
754 if (file == BaseName) {
755 return d->fileEntry.fileName();
756 }
else if (file == PathName) {
757 return d->fileEntry.path();
758 }
else if (file == AbsoluteName || file == AbsolutePathName) {
761 if (!isRelativePath()) {
762 #if !defined(Q_OS_WINCE) 763 if (
d->fileEntry.filePath().startsWith(
QLatin1Char(
'/')) ||
764 d->fileEntry.filePath().size() == 2 ||
765 (
d->fileEntry.filePath().size() > 2 &&
d->fileEntry.filePath().at(2) !=
QLatin1Char(
'/')) ||
773 ret =
d->fileEntry.filePath();
792 if (file == AbsolutePathName) {
799 return ret.
left(slash > 0 ? slash : 1);
802 }
else if (file == CanonicalName || file == CanonicalPathName) {
803 if (!(fileFlags(ExistsFlag) & ExistsFlag))
807 if (file == CanonicalPathName)
810 }
else if (file == LinkName) {
812 }
else if (file == BundleName) {
815 return d->fileEntry.filePath();
822 return d->fileEntry.isRelative();
827 static const uint nobodyID = (
uint) -2;
851 if (
d->fileHandle != INVALID_HANDLE_VALUE ||
d->fd != -1 ||
d->fh) {
854 #if !defined(Q_OS_WINCE) 855 if (fh == INVALID_HANDLE_VALUE) {
857 fh = (
HANDLE)_get_osfhandle(QT_FILENO(
d->fh));
859 fh = (
HANDLE)_get_osfhandle(
d->fd);
862 if (fh == INVALID_HANDLE_VALUE)
864 qint64 currentPos = pos();
866 if (seek(size) && SetEndOfFile(fh)) {
867 seek(
qMin(currentPos, size));
875 if (!
d->fileEntry.isEmpty()) {
877 QFile file(
d->fileEntry.filePath());
879 bool ret = file.
resize(size);
894 return d->metaData.fileTime(time);
908 if (offset == 0 && size == 0) {
918 if (handle == INVALID_HANDLE_VALUE &&
fh)
919 handle = (
HANDLE)::_get_osfhandle(QT_FILENO(
fh));
922 #ifdef Q_USE_DEPRECATED_MAP_API 930 FILE_ATTRIBUTE_NORMAL,
935 handle = INVALID_HANDLE_VALUE;
938 if (handle == INVALID_HANDLE_VALUE) {
945 mapHandle = ::CreateFileMapping(handle, 0, protection, 0, 0, 0);
948 #ifdef Q_USE_DEPRECATED_MAP_API 949 ::CloseHandle(handle);
960 DWORD offsetHi = offset >> 32;
961 DWORD offsetLo = offset &
Q_UINT64_C(0xffffffff);
963 ::GetSystemInfo(&sysinfo);
964 DWORD mask = sysinfo.dwAllocationGranularity - 1;
965 DWORD extra = offset & mask;
970 LPVOID mapAddress = ::MapViewOfFile(
mapHandle, access,
971 offsetHi, offsetLo, size + extra);
973 uchar *address = extra +
static_cast<uchar*
>(mapAddress);
974 maps[address] = extra;
978 switch(GetLastError()) {
979 case ERROR_ACCESS_DENIED:
982 case ERROR_INVALID_PARAMETER:
1001 if (!UnmapViewOfFile(start)) {
1007 if (maps.isEmpty()) {
uchar * map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
static QString fromWCharArray(const wchar_t *, int size=-1)
Returns a copy of the string, where the encoding of string depends on the size of wchar...
void setError(QFile::FileError error, const QString &str)
Sets the error type to error, and the error string to errorString.
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
static QString currentPath(const QString &path=QString())
For Unix, returns the current working directory for the file engine.
QString qt_error_string(int errorCode)
static bool setPermissions(const QFileSystemEntry &entry, QFile::Permissions permissions, QSystemError &error, QFileSystemMetaData *data=0)
bool isLetter() const
Returns true if the character is a letter (Letter_* categories); otherwise returns false...
bool isRelativePath() const
Reimplemented Function
Q_DECL_CONSTEXPR const T & qMin(const T &a, const T &b)
#define QT_END_NAMESPACE
This macro expands to.
static QString tempPath()
Returns the temporary path (i.
static QString rootPath()
int remove(const Key &key)
Removes all the items that have the key from the hash.
const QChar at(int i) const
Returns the character at the given index position in the string.
bool rmdir(const QString &dirName, bool recurseParentDirectories) const
Reimplemented Function
bool copy(const QString &newName)
For windows, copy the file to file copyName.
FileFlags fileFlags(FileFlags type) const
Reimplemented Function
QString & replace(int i, int len, QChar after)
int length() const
Returns the number of characters in this string.
QString & prepend(QChar c)
QString toUpper() const Q_REQUIRED_RESULT
Returns an uppercase copy of the string.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
static bool setCurrentPath(const QString &path)
Sets the current path (e.
qint64 writeFdFh(const char *data, qint64 len)
The QString class provides a Unicode character string.
static QString currentPath()
Returns the absolute path of the application's current directory.
bool resize(qint64 sz)
Sets the file size (in bytes) sz.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
static QString longFileName(const QString &path)
QIODevice::OpenMode openMode
static QFileSystemEntry currentPath()
NativePath nativeFilePath() const
bool rename(const QString &newName)
Reimplemented Function
void append(const T &t)
Inserts value at the end of the list.
bool flush()
Reimplemented Function
QString owner(FileOwner) const
Reimplemented Function
#define QT_BEGIN_NAMESPACE
This macro expands to.
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static QString tempPath()
qint64 nativeSize() const
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
int access(const char *, int)
bool setPermissions(uint perms)
Reimplemented Function
int size() const
Returns the number of characters in this string.
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
static QString homePath()
Returns the home path of the current user.
bool caseSensitive() const
Returns true for Windows, false for Unix.
static QFileInfoList drives()
For Windows, returns the list of drives in the file system as a list of QFileInfo objects...
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
qint64 nativeRead(char *data, qint64 maxlen)
#define FALSE
Synonym for false.
QString fileName(FileName file) const
Reimplemented Function
QHash< uchar *, DWORD > maps
QChar toUpper() const
Returns the uppercase equivalent if the character is lowercase or titlecase; otherwise returns the ch...
bool link(const QString &newName)
Creates a link from the file currently specified by fileName() to newName.
const T * ptr(const T &t)
qint64 nativeReadLine(char *data, qint64 maxlen)
bool doStat(QFileSystemMetaData::MetaDataFlags flags) const
static QString cleanPath(const QString &path)
Removes all multiple directory separators "/" and resolves any "."s or ".."s found in the path...
static QString nativeAbsoluteFilePath(const QString &path)
static QFileSystemEntry getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data)
QFileSystemEntry fileEntry
bool nativeIsSequential() const
static bool createDirectory(const QFileSystemEntry &entry, bool createParents)
#define TRUE
Synonym for true.
QFileSystemMetaData metaData
static bool setCurrentPath(const QFileSystemEntry &entry)
QString & append(QChar c)
The QDateTime class provides date and time functions.
The QFile class provides an interface for reading from and writing to files.
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
static bool removeFile(const QFileSystemEntry &entry, QSystemError &error)
static QString homePath()
static QString rootPath()
Returns the root path.
bool nativeOpen(QIODevice::OpenMode openMode)
char toLatin1() const
Returns the Latin-1 character equivalent to the QChar, or 0.
qint64 readLineFdFh(char *data, qint64 maxlen)
uint ownerId(FileOwner) const
In Unix, if stat() is successful, the uid is returned if own is the owner.
qint64 nativeWrite(const char *data, qint64 len)
QDateTime fileTime(FileTime time) const
Reimplemented Function
static QString owner(const QFileSystemEntry &entry, QAbstractFileEngine::FileOwner own)
static bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
bool remove()
Reimplemented Function
MemoryMapFlags
This enum describes special options that may be used by the map() function.
static QString fromNativeSeparators(const QString &pathName)
Returns pathName using '/' as file separator.
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
bool endsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string ends with s; otherwise returns false.
The QFileInfo class provides system-independent file information.
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
static QString fileName(const QString &fileUrl)
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
bool mkdir(const QString &dirName, bool createParentDirectories) const
Reimplemented Function
bool setSize(qint64 size)
Reimplemented Function
static QFileSystemEntry canonicalName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
const ushort * utf16() const
Returns the QString as a '\0\'-terminated array of unsigned shorts.
qint64 readFdFh(char *data, qint64 maxlen)
The QFSFileEngine class implements Qt's default file engine.