42 #include "qplatformdefs.h" 44 #include "private/qfsfileengine_p.h" 45 #include "private/qcore_unix_p.h" 49 #ifndef QT_NO_FSFILEENGINE 59 #if defined(Q_OS_SYMBIAN) 60 # include <sys/syslimits.h> 62 # include <pathinfo.h> 63 # include "private/qcore_symbian_p.h" 66 #if !defined(QWS) && defined(Q_OS_MAC) 67 # include <private/qcore_mac_p.h> 72 #if defined(Q_OS_SYMBIAN) 115 if (flags & QIODevice::ReadOnly)
120 if (flags & QIODevice::ReadOnly)
124 #if defined(__GLIBC__) && (__GLIBC__ * 0x100 + __GLIBC_MINOR__) >= 0x0207 143 int oflags = QT_OPEN_RDONLY;
144 #ifdef QT_LARGEFILE_SUPPORT 145 oflags |= QT_OPEN_LARGEFILE;
149 oflags = QT_OPEN_RDWR | QT_OPEN_CREAT;
151 oflags = QT_OPEN_WRONLY | QT_OPEN_CREAT;
155 oflags |= QT_OPEN_APPEND;
156 }
else if (mode & QFile::WriteOnly) {
158 oflags |= QT_OPEN_TRUNC;
176 return fd != -1 &&
fcntl(fd, F_SETFD, FD_CLOEXEC) != -1;
192 RFs& fs = qt_s60GetRFs();
194 TUint symbianMode = 0;
197 symbianMode |= EFileRead;
199 symbianMode |= EFileWrite;
201 symbianMode |= EFileStreamText;
204 if (openMode & QIODevice::WriteOnly)
205 symbianMode |= 0x00001000;
209 if (openMode & QIODevice::WriteOnly)
210 symbianMode |= 0x00000800;
219 symbianMode |= EFileShareReadersOrWriters;
226 r = symbianFile.Replace(fs, qt_QString2TPtrC(fn), symbianMode);
228 r = symbianFile.Open(fs, qt_QString2TPtrC(fn), symbianMode);
229 if (r == KErrNotFound && (openMode & QIODevice::WriteOnly)) {
230 r = symbianFile.Create(fs, qt_QString2TPtrC(fn), symbianMode);
235 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API 240 r = symbianFile.Size(size);
242 if (openMode & QIODevice::Append)
243 symbianFilePos = size;
269 bool QFSFileEngine::open(QIODevice::OpenMode openMode,
const RFile &file, QFile::FileHandleFlags handleFlags)
282 d->lastFlushFailed =
false;
284 d->fileEntry.clear();
289 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API 291 d->symbianFile =
static_cast<const RFile64&
>(file);
293 d->symbianFile = file;
296 d->symbianFilePos = 0;
297 if (openMode & QFile::Append) {
299 ret =
d->symbianFile.Size(
d->symbianFilePos);
302 ret =
d->symbianFile.Seek(ESeekCurrent,
d->symbianFilePos);
305 if (ret != KErrNone) {
309 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API 310 d->symbianFile = RFile64();
312 d->symbianFile = RFile();
319 TInt err =
d->symbianFile.FullName(fn);
323 d->fileEntry.clear();
341 }
while (
fd == -1 &&
errno == EINTR);
365 ret = QT_LSEEK(
fd, 0, SEEK_END);
366 }
while (ret == -1 &&
errno == EINTR);
382 }
while (!
fh &&
errno == EINTR);
408 ret = QT_FSEEK(
fh, 0, SEEK_END);
409 }
while (ret == -1 &&
errno == EINTR);
441 if (symbianFile.SubSessionHandle())
442 return (KErrNone == symbianFile.Flush());
455 if (symbianFile.SubSessionHandle()) {
461 TPtr8
ptr(reinterpret_cast<TUint8*>(data), static_cast<TInt>(len));
462 TInt r = symbianFile.Read(symbianFilePos, ptr);
468 symbianFilePos += ptr.Length();
469 return qint64(ptr.Length());
473 size_t readBytes = 0;
474 int oldFlags =
fcntl(QT_FILENO(
fh), F_GETFL);
475 for (
int i = 0; i < 2; ++i) {
477 if ((oldFlags & O_NONBLOCK) == 0)
478 fcntl(QT_FILENO(
fh), F_SETFL, oldFlags | O_NONBLOCK);
483 read = fread(data + readBytes, 1,
size_t(len - readBytes),
fh);
484 }
while (read == 0 && !feof(
fh) &&
errno == EINTR);
495 if ((oldFlags & O_NONBLOCK) == 0) {
496 fcntl(QT_FILENO(
fh), F_SETFL, oldFlags);
497 if (readBytes == 0) {
500 readByte = fgetc(
fh);
501 }
while (readByte == -1 &&
errno == EINTR);
502 if (readByte != -1) {
503 *data =
uchar(readByte);
512 if ((oldFlags & O_NONBLOCK) == 0) {
513 fcntl(QT_FILENO(
fh), F_SETFL, oldFlags);
515 if (readBytes == 0 && !feof(
fh)) {
541 if (symbianFile.SubSessionHandle()) {
547 const TPtrC8
ptr(reinterpret_cast<const TUint8*>(data), static_cast<TInt>(len));
548 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API 555 TInt r = symbianFile.Seek(ESeekEnd, eofpos);
556 if (r == KErrNone && symbianFilePos > eofpos) {
559 r = symbianFile.SetSize(symbianFilePos);
563 r = symbianFile.Write(symbianFilePos, ptr);
569 symbianFilePos += len;
583 if (symbianFile.SubSessionHandle()) {
584 return symbianFilePos;
597 if (symbianFile.SubSessionHandle()) {
598 #ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API 604 symbianFilePos = pos;
616 return fh ? fileno(
fh) :
fd;
619 #if defined(Q_OS_SYMBIAN) && !defined(QT_SYMBIAN_USE_NATIVE_FILEMAP) 620 int QFSFileEnginePrivate::getMapHandle()
622 if (symbianFile.SubSessionHandle()) {
624 if (fileHandleForMaps < 0) {
629 return fileHandleForMaps;
641 if (symbianFile.SubSessionHandle())
644 return isSequentialFdFh();
698 if (symbianFile.SubSessionHandle()) {
699 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API 704 TInt err = symbianFile.Size(size);
705 if(err != KErrNone) {
727 #if defined(Q_OS_SYMBIAN) 762 #if defined(Q_OS_SYMBIAN) 763 TDriveList driveList;
764 RFs rfs = qt_s60GetRFs();
765 TInt err = rfs.DriveList(driveList);
766 if (err == KErrNone) {
767 char driveName[] =
"A:/";
769 for (
char i = 0; i < KMaxDrives; i++) {
771 driveName[0] =
'A' + i;
776 qWarning(
"QFSFileEngine::drives: Getting drives failed");
791 localFd = QT_FILENO(
fh);
820 QAbstractFileEngine::FileFlags ret = 0;
822 if (type & FlagsMask)
823 ret |= LocalDiskFlag;
827 QFileSystemMetaData::MetaDataFlags queryFlags = 0;
829 queryFlags |= QFileSystemMetaData::MetaDataFlags(
uint(type))
832 if (type & TypesMask)
839 if (type & FlagsMask)
845 exists =
d->doStat(queryFlags);
848 if (!exists && !
d->metaData.isLink())
851 if (exists && (type & PermsMask))
852 ret |= FileFlags(
uint(
d->metaData.permissions()));
854 if (type & TypesMask) {
855 if (
d->metaData.isAlias()) {
858 if ((type & LinkType) &&
d->metaData.isLink())
861 if (
d->metaData.isFile()) {
863 }
else if (
d->metaData.isDirectory()) {
864 ret |= DirectoryType;
865 if ((type & BundleType) &&
d->metaData.isBundle())
872 if (type & FlagsMask) {
875 if (
d->fileEntry.isRoot())
877 else if (
d->metaData.isHidden())
887 if (file == BundleName) {
889 }
else if (file == BaseName) {
890 return d->fileEntry.fileName();
891 }
else if (file == PathName) {
892 return d->fileEntry.path();
893 }
else if (file == AbsoluteName || file == AbsolutePathName) {
895 if (file == AbsolutePathName) {
899 }
else if (file == CanonicalName || file == CanonicalPathName) {
901 if (file == CanonicalPathName)
904 }
else if (file == LinkName) {
905 if (
d->isSymlink()) {
911 return d->fileEntry.filePath();
917 #if defined(Q_OS_SYMBIAN) 918 return isRelativePathSymbian(
d->fileEntry.filePath());
920 return d->fileEntry.filePath().length() ?
d->fileEntry.filePath()[0] !=
QLatin1Char(
'/') :
true;
927 static const uint nobodyID = (
uint) -2;
930 return d->metaData.ownerId(own);
938 if (own == OwnerUser)
964 if (
d->symbianFile.SubSessionHandle()) {
965 TInt err =
d->symbianFile.SetSize(size);
966 ret = (err == KErrNone);
967 if (ret &&
d->symbianFilePos > size)
968 d->symbianFilePos = size;
970 else if (
d->fd != -1)
971 ret = QT_FTRUNCATE(
d->fd, size) == 0;
973 ret = QT_FTRUNCATE(QT_FILENO(
d->fh), size) == 0;
976 QString symbianFilename(
d->fileEntry.nativeFilePath());
977 err = tmp.Open(qt_s60GetRFs(), qt_QString2TPtrC(symbianFilename), EFileWrite);
980 err = tmp.SetSize(size);
983 ret = (err == KErrNone);
1001 ret = QT_FTRUNCATE(
d->fd, size) == 0;
1003 ret = QT_FTRUNCATE(QT_FILENO(
d->fh), size) == 0;
1005 ret = QT_TRUNCATE(
d->fileEntry.nativeFilePath().constData(), size) == 0;
1017 return d->metaData.fileTime(time);
1031 if (offset < 0 || offset !=
qint64(QT_OFF_T(offset))
1040 && (QT_OFF_T(size) >
metaData.
size() - QT_OFF_T(offset)))
1041 qWarning(
"QFSFileEngine::map: Mapping a file beyond its size is not portable");
1047 #if defined(Q_OS_INTEGRITY) 1048 int pageSize = sysconf(_SC_PAGESIZE);
1050 int pageSize = getpagesize();
1052 int extra = offset % pageSize;
1059 size_t realSize = (size_t)size + extra;
1060 QT_OFF_T realOffset = QT_OFF_T(offset);
1061 realOffset &= ~(QT_OFF_T(pageSize - 1));
1063 #ifdef QT_SYMBIAN_USE_NATIVE_FILEMAP 1064 TInt nativeMapError = KErrNone;
1066 TUint mode(EFileMapRemovableMedia);
1067 TUint64 nativeOffset = offset & ~(mapping.PageSizeInBytes() - 1);
1070 if (openMode & QIODevice::WriteOnly)
1071 mode |= EFileMapWrite;
1072 if (symbianFile.SubSessionHandle()) {
1073 nativeMapError = mapping.Open(symbianFile, nativeOffset, size, mode);
1077 TUint filemode = EFileShareReadersOrWriters | EFileRead;
1078 if (openMode & QIODevice::WriteOnly)
1079 filemode |= EFileWrite;
1080 nativeMapError = mapping.Open(qt_s60GetRFs(), qt_QString2TPtrC(fn), filemode, nativeOffset, size, mode);
1082 if (nativeMapError == KErrNone) {
1083 QScopedResource<RFileMap>
ptr(mapping);
1084 uchar *address = mapping.Base() + (offset - nativeOffset);
1090 switch (nativeMapError) {
1091 case KErrAccessDenied:
1092 case KErrPermissionDenied:
1105 TRAPD(err, mapAddress = QT_MMAP((
void*)0, realSize,
1106 access, MAP_SHARED, getMapHandle(), realOffset));
1107 if (err != KErrNone) {
1108 qWarning(
"OpenC bug: leave from mmap %d", err);
1113 void *mapAddress = QT_MMAP((
void*)0, realSize,
1117 uchar *address = extra +
static_cast<uchar*
>(mapAddress);
1142 #if !defined(Q_OS_INTEGRITY) 1149 #ifdef QT_SYMBIAN_USE_NATIVE_FILEMAP 1151 TInt err = mapping.Flush();
1161 size_t len =
maps[
ptr].second;
1162 if (-1 == munmap(start, len)) {
1176 #endif // QT_NO_FSFILEENGINE uchar * map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
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
#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
static QString resolveGroupName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
The QByteArray class provides an array of bytes.
int length() const
Returns the number of characters in this string.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
FileName
These values are used to request a file name in a particular format.
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.
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
const T value(const Key &key) const
Returns the value associated with the key.
QIODevice::OpenMode openMode
static QFileSystemEntry currentPath()
NativePath nativeFilePath() const
bool rename(const QString &newName)
Reimplemented Function
static QString toString(Register *reg, int type, bool *ok=0)
void append(const T &t)
Inserts value at the end of the list.
QString owner(FileOwner) const
Reimplemented Function
#define QT_BEGIN_NAMESPACE
This macro expands to.
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
static bool removeDirectory(const QFileSystemEntry &entry, bool removeEmptyParents)
static bool renameFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
static QString tempPath()
static QString resolveUserName(const QFileSystemEntry &entry, QFileSystemMetaData &data)
qint64 nativeSize() const
int access(const char *, int)
bool setPermissions(uint perms)
Reimplemented Function
static QString homePath()
Returns the home path of the current user.
bool open(QIODevice::OpenMode openMode)
Reimplemented Function
Q_CORE_EXPORT void qWarning(const char *,...)
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)
qint64 nativeRead(char *data, qint64 maxlen)
QString fileName(FileName file) const
Reimplemented Function
QHash< uchar *, DWORD > maps
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 QFileSystemEntry getLinkTarget(const QFileSystemEntry &link, QFileSystemMetaData &data)
QFileSystemEntry fileEntry
FileTime
These are used by the fileTime() function.
bool nativeIsSequential() const
static bool createDirectory(const QFileSystemEntry &entry, bool createParents)
static QString bundleName(const QFileSystemEntry &entry)
QFileSystemMetaData metaData
const char * constData() const
Returns a pointer to the data stored in the byte array.
static bool setCurrentPath(const QFileSystemEntry &entry)
static bool createLink(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
The QDateTime class provides date and time functions.
static bool removeFile(const QFileSystemEntry &entry, QSystemError &error)
static QMap< QByteArray, int > mapping
static QString homePath()
static QString rootPath()
Returns the root path.
bool nativeOpen(QIODevice::OpenMode openMode)
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 bool copyFile(const QFileSystemEntry &source, const QFileSystemEntry &target, QSystemError &error)
T take(const Key &key)
Removes the item with the key key from the map and returns the value associated with it...
bool remove()
Reimplemented Function
MemoryMapFlags
This enum describes special options that may be used by the map() function.
FileError
This enum describes the errors that may be returned by the error() function.
The QFileInfo class provides system-independent file information.
static int openModeToOpenFlags(QIODevice::OpenMode mode)
Returns the stdio open flags corresponding to a QIODevice::OpenMode.
static QByteArray openModeToFopenMode(QIODevice::OpenMode flags, const QFileSystemEntry &fileEntry, QFileSystemMetaData &metaData)
Returns the stdlib open string corresponding to a QIODevice::OpenMode.
#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.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
bool mkdir(const QString &dirName, bool createParentDirectories) const
Reimplemented Function
bool setSize(qint64 size)
Reimplemented Function
static bool setCloseOnExec(int fd)
Sets the file descriptor to close on exec.
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.