Qt 4.8
Public Types | Public Functions | Static Public Functions | Public Variables | Protected Functions | List of all members
QFSFileEnginePrivate Class Reference

#include <qfsfileengine_p.h>

Inheritance diagram for QFSFileEnginePrivate:
QAbstractFileEnginePrivate

Public Types

enum  LastIOCommand { IOFlushCommand, IOReadCommand, IOWriteCommand }
 

Public Functions

bool closeFdFh ()
 
bool doStat (QFileSystemMetaData::MetaDataFlags flags) const
 
bool flushFh ()
 
bool isSymlink () const
 
ucharmap (qint64 offset, qint64 size, QFile::MemoryMapFlags flags)
 
bool nativeClose ()
 
bool nativeFlush ()
 
int nativeHandle () const
 
bool nativeIsSequential () const
 
bool nativeOpen (QIODevice::OpenMode openMode)
 
qint64 nativePos () const
 
qint64 nativeRead (char *data, qint64 maxlen)
 
qint64 nativeReadLine (char *data, qint64 maxlen)
 
bool nativeSeek (qint64)
 
qint64 nativeSize () const
 
qint64 nativeWrite (const char *data, qint64 len)
 
bool openFd (QIODevice::OpenMode flags, int fd)
 Opens the file descriptor fd to the file engine, using the open mode flags. More...
 
bool openFh (QIODevice::OpenMode flags, FILE *fh)
 Opens the file handle fh using the open mode flags. More...
 
qint64 posFdFh () const
 
qint64 readFdFh (char *data, qint64 maxlen)
 
qint64 readLineFdFh (char *data, qint64 maxlen)
 
bool seekFdFh (qint64)
 
bool unmap (uchar *ptr)
 
qint64 writeFdFh (const char *data, qint64 len)
 
- Public Functions inherited from QAbstractFileEnginePrivate
 QAbstractFileEnginePrivate ()
 
virtual ~QAbstractFileEnginePrivate ()
 

Static Public Functions

static QString longFileName (const QString &path)
 

Public Variables

bool closeFileHandle
 
uint could_stat: 1
 
int fd
 
FILE * fh
 
DWORD fileAttrib
 
QFileSystemEntry fileEntry
 
HANDLE fileHandle
 
uint is_sequential: 2
 
bool lastFlushFailed
 
LastIOCommand lastIOCommand
 
HANDLE mapHandle
 
QHash< uchar *, DWORD > maps
 
QFileSystemMetaData metaData
 
QIODevice::OpenMode openMode
 
uint tried_stat: 1
 
- Public Variables inherited from QAbstractFileEnginePrivate
QString errorString
 
QFile::FileError fileError
 
QAbstractFileEngineq_ptr
 

Protected Functions

QAbstractFileEngine::FileFlags getPermissions (QAbstractFileEngine::FileFlags type) const
 
void init ()
 
 QFSFileEnginePrivate ()
 

Detailed Description

Definition at line 81 of file qfsfileengine_p.h.

Enumerations

◆ LastIOCommand

Enumerator
IOFlushCommand 
IOReadCommand 
IOWriteCommand 

Definition at line 171 of file qfsfileengine_p.h.

Constructors and Destructors

◆ QFSFileEnginePrivate()

QFSFileEnginePrivate::QFSFileEnginePrivate ( )
protected

Definition at line 107 of file qfsfileengine.cpp.

Functions

◆ closeFdFh()

bool QFSFileEnginePrivate::closeFdFh ( )
Warning
This function is not part of the public interface.

Definition at line 387 of file qfsfileengine.cpp.

Referenced by longFileName(), and nativeClose().

388 {
390  if (fd == -1 && !fh
391 #ifdef Q_OS_SYMBIAN
392  && !symbianFile.SubSessionHandle()
393 #ifndef QT_SYMBIAN_USE_NATIVE_FILEMAP
394  && fileHandleForMaps == -1
395 #endif
396 #endif
397  )
398  return false;
399 
400  // Flush the file if it's buffered, and if the last flush didn't fail.
401  bool flushed = !fh || (!lastFlushFailed && q->flush());
402  bool closed = true;
403  tried_stat = 0;
404 
405 #if defined(Q_OS_SYMBIAN) && !defined(QT_SYMBIAN_USE_NATIVE_FILEMAP)
406  // Map handle is always owned by us so always close it
407  if (fileHandleForMaps >= 0) {
408  QT_CLOSE(fileHandleForMaps);
409  fileHandleForMaps = -1;
410  }
411 #endif
412 
413  // Close the file if we created the handle.
414  if (closeFileHandle) {
415  int ret;
416  do {
417 #ifdef Q_OS_SYMBIAN
418  if (symbianFile.SubSessionHandle()) {
419  symbianFile.Close();
420  ret = 0;
421  } else
422 #endif
423  if (fh) {
424  // Close buffered file.
425  ret = fclose(fh) != 0 ? -1 : 0;
426  } else {
427  // Close unbuffered file.
428  ret = QT_CLOSE(fd);
429  }
430  } while (ret == -1 && errno == EINTR);
431 
432  // We must reset these guys regardless; calling close again after a
433  // failed close causes crashes on some systems.
434  fh = 0;
435  fd = -1;
436  closed = (ret == 0);
437  }
438 
439  // Report errors.
440  if (!flushed || !closed) {
441  if (flushed) {
442  // If not flushed, we want the flush error to fall through.
444  }
445  return false;
446  }
447 
448  return true;
449 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
#define Q_Q(Class)
Definition: qglobal.h:2483
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60
#define QT_CLOSE
Definition: qcore_unix_p.h:304

◆ doStat()

bool QFSFileEnginePrivate::doStat ( QFileSystemMetaData::MetaDataFlags  flags) const

Definition at line 784 of file qfsfileengine_unix.cpp.

Referenced by longFileName(), and map().

785 {
786  if (!tried_stat || !metaData.hasFlags(flags)) {
787  tried_stat = 1;
788 
789  int localFd = fd;
790  if (fh && fileEntry.isEmpty())
791  localFd = QT_FILENO(fh);
792  if (localFd != -1)
794 
795  if (metaData.missingFlags(flags) && !fileEntry.isEmpty())
797  }
798 
799  return metaData.exists();
800 }
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
bool hasFlags(MetaDataFlags flags) const
QFileSystemEntry fileEntry
QFileSystemMetaData metaData
MetaDataFlags missingFlags(MetaDataFlags flags)

◆ flushFh()

bool QFSFileEnginePrivate::flushFh ( )
Warning
This function is not part of the public interface.

Definition at line 468 of file qfsfileengine.cpp.

Referenced by longFileName(), and nativeFlush().

469 {
471 
472  // Never try to flush again if the last flush failed. Otherwise you can
473  // get crashes on some systems (AIX).
474  if (lastFlushFailed)
475  return false;
476 
477  int ret = fflush(fh);
478 
479  lastFlushFailed = (ret != 0);
481 
482  if (ret != 0) {
483  q->setError(errno == ENOSPC ? QFile::ResourceError : QFile::WriteError,
485  return false;
486  }
487  return true;
488 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
LastIOCommand lastIOCommand
#define Q_Q(Class)
Definition: qglobal.h:2483
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ getPermissions()

QAbstractFileEngine::FileFlags QFSFileEnginePrivate::getPermissions ( QAbstractFileEngine::FileFlags  type) const
protected
Warning
This function is not part of the public interface.

◆ init()

void QFSFileEnginePrivate::init ( )
protected
Warning
This function is not part of the public interface.

Definition at line 115 of file qfsfileengine.cpp.

Referenced by QFSFileEnginePrivate().

116 {
117  is_sequential = 0;
118  tried_stat = 0;
119 #if !defined(Q_OS_WINCE)
120  need_lstat = 1;
121  is_link = 0;
122 #endif
124  fd = -1;
125  fh = 0;
126 #if defined (Q_OS_SYMBIAN)
127  symbianFilePos = 0;
128 #if !defined(QT_SYMBIAN_USE_NATIVE_FILEMAP)
129  fileHandleForMaps = -1;
130 #endif
131 #endif
133  lastFlushFailed = false;
134  closeFileHandle = false;
135 #ifdef Q_OS_WIN
137  fileHandle = INVALID_HANDLE_VALUE;
138  mapHandle = NULL;
139 #ifndef Q_OS_WINCE
140  cachedFd = -1;
141 #endif
142 #endif
143 }
LastIOCommand lastIOCommand
#define INVALID_FILE_ATTRIBUTES
QIODevice::OpenMode openMode

◆ isSymlink()

bool QFSFileEnginePrivate::isSymlink ( ) const

Definition at line 802 of file qfsfileengine_unix.cpp.

803 {
806 
807  return metaData.isLink();
808 }
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
bool hasFlags(MetaDataFlags flags) const
QFileSystemEntry fileEntry
QFileSystemMetaData metaData

◆ longFileName()

QString QFSFileEnginePrivate::longFileName ( const QString path)
static
Warning
This function is not part of the public interface.

Definition at line 90 of file qfsfileengine_win.cpp.

Referenced by isDirPath(), mkDir(), qt_create_pipe(), QFileSystemEntry::resolveNativeFilePath(), and rmDir().

91 {
92  if (path.startsWith(QLatin1String("\\\\.\\")))
93  return path;
94 
96 #if !defined(Q_OS_WINCE)
97  QString prefix = QLatin1String("\\\\?\\");
98  if (isUncPath(absPath)) {
99  prefix.append(QLatin1String("UNC\\")); // "\\\\?\\UNC\\"
100  absPath.remove(0, 2);
101  }
102  return prefix + absPath;
103 #else
104  return absPath;
105 #endif
106 }
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
static QString nativeAbsoluteFilePath(const QString &path)
QString & append(QChar c)
Definition: qstring.cpp:1777
QString & remove(int i, int len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition: qstring.cpp:1867

◆ map()

uchar * QFSFileEnginePrivate::map ( qint64  offset,
qint64  size,
QFile::MemoryMapFlags  flags 
)

Definition at line 1022 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

1023 {
1024  Q_Q(QFSFileEngine);
1025  Q_UNUSED(flags);
1026  if (openMode == QIODevice::NotOpen) {
1027  q->setError(QFile::PermissionsError, qt_error_string(int(EACCES)));
1028  return 0;
1029  }
1030 
1031  if (offset < 0 || offset != qint64(QT_OFF_T(offset))
1032  || size < 0 || quint64(size) > quint64(size_t(-1))) {
1033  q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL)));
1034  return 0;
1035  }
1036 
1037  // If we know the mapping will extend beyond EOF, fail early to avoid
1038  // undefined behavior. Otherwise, let mmap have its say.
1040  && (QT_OFF_T(size) > metaData.size() - QT_OFF_T(offset)))
1041  qWarning("QFSFileEngine::map: Mapping a file beyond its size is not portable");
1042 
1043  int access = 0;
1044  if (openMode & QIODevice::ReadOnly) access |= PROT_READ;
1045  if (openMode & QIODevice::WriteOnly) access |= PROT_WRITE;
1046 
1047 #if defined(Q_OS_INTEGRITY)
1048  int pageSize = sysconf(_SC_PAGESIZE);
1049 #else
1050  int pageSize = getpagesize();
1051 #endif
1052  int extra = offset % pageSize;
1053 
1054  if (quint64(size + extra) > quint64((size_t)-1)) {
1055  q->setError(QFile::UnspecifiedError, qt_error_string(int(EINVAL)));
1056  return 0;
1057  }
1058 
1059  size_t realSize = (size_t)size + extra;
1060  QT_OFF_T realOffset = QT_OFF_T(offset);
1061  realOffset &= ~(QT_OFF_T(pageSize - 1));
1062 
1063 #ifdef QT_SYMBIAN_USE_NATIVE_FILEMAP
1064  TInt nativeMapError = KErrNone;
1065  RFileMap mapping;
1066  TUint mode(EFileMapRemovableMedia);
1067  TUint64 nativeOffset = offset & ~(mapping.PageSizeInBytes() - 1);
1068 
1069  //If the file was opened for write or read/write, then open the map for read/write
1070  if (openMode & QIODevice::WriteOnly)
1071  mode |= EFileMapWrite;
1072  if (symbianFile.SubSessionHandle()) {
1073  nativeMapError = mapping.Open(symbianFile, nativeOffset, size, mode);
1074  } else {
1075  //map file by name if we don't have a native handle
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);
1081  }
1082  if (nativeMapError == KErrNone) {
1083  QScopedResource<RFileMap> ptr(mapping); //will call Close if adding to mapping throws an exception
1084  uchar *address = mapping.Base() + (offset - nativeOffset);
1085  maps[address] = mapping;
1086  ptr.take();
1087  return address;
1088  }
1089  QFile::FileError reportedError = QFile::UnspecifiedError;
1090  switch (nativeMapError) {
1091  case KErrAccessDenied:
1092  case KErrPermissionDenied:
1093  reportedError = QFile::PermissionsError;
1094  break;
1095  case KErrNoMemory:
1096  reportedError = QFile::ResourceError;
1097  break;
1098  }
1099  q->setError(reportedError, QSystemError(nativeMapError, QSystemError::NativeError).toString());
1100  return 0;
1101 #else
1102 #ifdef Q_OS_SYMBIAN
1103  //older phones & emulator don't support native mapping, so need to keep the open C way around for those.
1104  void *mapAddress;
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);
1109  mapAddress = MAP_FAILED;
1110  errno = EINVAL;
1111  }
1112 #else
1113  void *mapAddress = QT_MMAP((void*)0, realSize,
1114  access, MAP_SHARED, nativeHandle(), realOffset);
1115 #endif
1116  if (MAP_FAILED != mapAddress) {
1117  uchar *address = extra + static_cast<uchar*>(mapAddress);
1118  maps[address] = QPair<int,size_t>(extra, realSize);
1119  return address;
1120  }
1121 
1122  switch(errno) {
1123  case EBADF:
1124  q->setError(QFile::PermissionsError, qt_error_string(int(EACCES)));
1125  break;
1126  case ENFILE:
1127  case ENOMEM:
1128  q->setError(QFile::ResourceError, qt_error_string(int(errno)));
1129  break;
1130  case EINVAL:
1131  // size are out of bounds
1132  default:
1133  q->setError(QFile::UnspecifiedError, qt_error_string(int(errno)));
1134  break;
1135  }
1136  return 0;
1137 #endif
1138 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
#define MAP_FAILED
The QString class provides a Unicode character string.
Definition: qstring.h:83
QIODevice::OpenMode openMode
#define Q_Q(Class)
Definition: qglobal.h:2483
NativePath nativeFilePath() const
unsigned char uchar
Definition: qglobal.h:994
static QString toString(Register *reg, int type, bool *ok=0)
static QFileSystemEntry absoluteName(const QFileSystemEntry &entry)
unsigned __int64 quint64
Definition: qglobal.h:943
int access(const char *, int)
Q_CORE_EXPORT void qWarning(const char *,...)
QHash< uchar *, DWORD > maps
const T * ptr(const T &t)
__int64 qint64
Definition: qglobal.h:942
bool doStat(QFileSystemMetaData::MetaDataFlags flags) const
QFileSystemEntry fileEntry
QFileSystemMetaData metaData
static QMap< QByteArray, int > mapping
Definition: qaxserver.cpp:577
FileError
This enum describes the errors that may be returned by the error() function.
Definition: qfile.h:74
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ nativeClose()

bool QFSFileEnginePrivate::nativeClose ( )
Warning
This function is not part of the public interface.

Definition at line 429 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

430 {
431  return closeFdFh();
432 }

◆ nativeFlush()

bool QFSFileEnginePrivate::nativeFlush ( )
Warning
This function is not part of the public interface.

Definition at line 438 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

439 {
440 #ifdef Q_OS_SYMBIAN
441  if (symbianFile.SubSessionHandle())
442  return (KErrNone == symbianFile.Flush());
443 #endif
444  return fh ? flushFh() : fd != -1;
445 }

◆ nativeHandle()

int QFSFileEnginePrivate::nativeHandle ( ) const
Warning
This function is not part of the public interface.

Definition at line 614 of file qfsfileengine_unix.cpp.

Referenced by longFileName(), and map().

615 {
616  return fh ? fileno(fh) : fd;
617 }

◆ nativeIsSequential()

bool QFSFileEnginePrivate::nativeIsSequential ( ) const
Warning
This function is not part of the public interface.

Definition at line 638 of file qfsfileengine_unix.cpp.

Referenced by longFileName(), and nativeRead().

639 {
640 #ifdef Q_OS_SYMBIAN
641  if (symbianFile.SubSessionHandle())
642  return false;
643 #endif
644  return isSequentialFdFh();
645 }

◆ nativeOpen()

bool QFSFileEnginePrivate::nativeOpen ( QIODevice::OpenMode  openMode)
Warning
This function is not part of the public interface.

Definition at line 331 of file qfsfileengine_unix.cpp.

Referenced by longFileName(), and setCloseOnExec().

332 {
334 
336  int flags = openModeToOpenFlags(openMode);
337 
338  // Try to open the file in unbuffered mode.
339  do {
340  fd = QT_OPEN(fileEntry.nativeFilePath().constData(), flags, 0666);
341  } while (fd == -1 && errno == EINTR);
342 
343  // On failure, return and report the error.
344  if (fd == -1) {
345  q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
347  return false;
348  }
349 
350  if (!(openMode & QIODevice::WriteOnly)) {
351  // we don't need this check if we tried to open for writing because then
352  // we had received EISDIR anyway.
354  && metaData.isDirectory()) {
355  q->setError(QFile::OpenError, QLatin1String("file to open is a directory"));
356  QT_CLOSE(fd);
357  return false;
358  }
359  }
360 
361  // Seek to the end when in Append mode.
362  if (flags & QFile::Append) {
363  int ret;
364  do {
365  ret = QT_LSEEK(fd, 0, SEEK_END);
366  } while (ret == -1 && errno == EINTR);
367 
368  if (ret == -1) {
369  q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
370  qt_error_string(int(errno)));
371  return false;
372  }
373  }
374 
375  fh = 0;
376  } else {
378 
379  // Try to open the file in buffered mode.
380  do {
381  fh = QT_FOPEN(fileEntry.nativeFilePath().constData(), fopenMode.constData());
382  } while (!fh && errno == EINTR);
383 
384  // On failure, return and report the error.
385  if (!fh) {
386  q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
387  qt_error_string(int(errno)));
388  return false;
389  }
390 
391  if (!(openMode & QIODevice::WriteOnly)) {
392  // we don't need this check if we tried to open for writing because then
393  // we had received EISDIR anyway.
395  && metaData.isDirectory()) {
396  q->setError(QFile::OpenError, QLatin1String("file to open is a directory"));
397  fclose(fh);
398  return false;
399  }
400  }
401 
402  setCloseOnExec(fileno(fh)); // ignore failure
403 
404  // Seek to the end when in Append mode.
405  if (openMode & QIODevice::Append) {
406  int ret;
407  do {
408  ret = QT_FSEEK(fh, 0, SEEK_END);
409  } while (ret == -1 && errno == EINTR);
410 
411  if (ret == -1) {
412  q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
413  qt_error_string(int(errno)));
414  return false;
415  }
416  }
417 
418  fd = -1;
419  }
420 
421  closeFileHandle = true;
422  return true;
423 }
static bool fillMetaData(const QFileSystemEntry &entry, QFileSystemMetaData &data, QFileSystemMetaData::MetaDataFlags what)
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QIODevice::OpenMode openMode
#define Q_Q(Class)
Definition: qglobal.h:2483
NativePath nativeFilePath() const
QFileSystemEntry fileEntry
QFileSystemMetaData metaData
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
#define QT_OPEN
Definition: qcore_unix_p.h:186
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.
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712
static bool setCloseOnExec(int fd)
Sets the file descriptor to close on exec.
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60
#define QT_CLOSE
Definition: qcore_unix_p.h:304

◆ nativePos()

qint64 QFSFileEnginePrivate::nativePos ( ) const
Warning
This function is not part of the public interface.

Definition at line 579 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

580 {
581 #ifdef Q_OS_SYMBIAN
582  const Q_Q(QFSFileEngine);
583  if (symbianFile.SubSessionHandle()) {
584  return symbianFilePos;
585  }
586 #endif
587  return posFdFh();
588 }
#define Q_Q(Class)
Definition: qglobal.h:2483
qint64 posFdFh() const
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ nativeRead()

qint64 QFSFileEnginePrivate::nativeRead ( char *  data,
qint64  len 
)
Warning
This function is not part of the public interface.

Definition at line 450 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

451 {
453 
454 #ifdef Q_OS_SYMBIAN
455  if (symbianFile.SubSessionHandle()) {
456  if(len > KMaxTInt) {
457  //this check is more likely to catch a corrupt length, since it isn't possible to allocate 2GB buffers (yet..)
458  q->setError(QFile::ReadError, QLatin1String("Maximum 2GB in single read on this platform"));
459  return -1;
460  }
461  TPtr8 ptr(reinterpret_cast<TUint8*>(data), static_cast<TInt>(len));
462  TInt r = symbianFile.Read(symbianFilePos, ptr);
463  if (r != KErrNone)
464  {
466  return -1;
467  }
468  symbianFilePos += ptr.Length();
469  return qint64(ptr.Length());
470  }
471 #endif
472  if (fh && nativeIsSequential()) {
473  size_t readBytes = 0;
474  int oldFlags = fcntl(QT_FILENO(fh), F_GETFL);
475  for (int i = 0; i < 2; ++i) {
476  // Unix: Make the underlying file descriptor non-blocking
477  if ((oldFlags & O_NONBLOCK) == 0)
478  fcntl(QT_FILENO(fh), F_SETFL, oldFlags | O_NONBLOCK);
479 
480  // Cross platform stdlib read
481  size_t read = 0;
482  do {
483  read = fread(data + readBytes, 1, size_t(len - readBytes), fh);
484  } while (read == 0 && !feof(fh) && errno == EINTR);
485  if (read > 0) {
486  readBytes += read;
487  break;
488  } else {
489  if (readBytes)
490  break;
491  readBytes = read;
492  }
493 
494  // Unix: Restore the blocking state of the underlying socket
495  if ((oldFlags & O_NONBLOCK) == 0) {
496  fcntl(QT_FILENO(fh), F_SETFL, oldFlags);
497  if (readBytes == 0) {
498  int readByte = 0;
499  do {
500  readByte = fgetc(fh);
501  } while (readByte == -1 && errno == EINTR);
502  if (readByte != -1) {
503  *data = uchar(readByte);
504  readBytes += 1;
505  } else {
506  break;
507  }
508  }
509  }
510  }
511  // Unix: Restore the blocking state of the underlying socket
512  if ((oldFlags & O_NONBLOCK) == 0) {
513  fcntl(QT_FILENO(fh), F_SETFL, oldFlags);
514  }
515  if (readBytes == 0 && !feof(fh)) {
516  // if we didn't read anything and we're not at EOF, it must be an error
517  q->setError(QFile::ReadError, qt_error_string(int(errno)));
518  return -1;
519  }
520  return readBytes;
521  }
522 
523  return readFdFh(data, len);
524 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_Q(Class)
Definition: qglobal.h:2483
unsigned char uchar
Definition: qglobal.h:994
static QString toString(Register *reg, int type, bool *ok=0)
static const char * data(const QByteArray &arr)
const T * ptr(const T &t)
__int64 qint64
Definition: qglobal.h:942
int fcntl(int, int,...)
int errno
qint64 readFdFh(char *data, qint64 maxlen)
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ nativeReadLine()

qint64 QFSFileEnginePrivate::nativeReadLine ( char *  data,
qint64  maxlen 
)
Warning
This function is not part of the public interface.

Definition at line 529 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

530 {
531  return readLineFdFh(data, maxlen);
532 }
static const char * data(const QByteArray &arr)
qint64 readLineFdFh(char *data, qint64 maxlen)

◆ nativeSeek()

bool QFSFileEnginePrivate::nativeSeek ( qint64  pos)
Warning
This function is not part of the public interface.

Definition at line 593 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

594 {
595 #ifdef Q_OS_SYMBIAN
597  if (symbianFile.SubSessionHandle()) {
598 #ifndef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
599  if(pos > KMaxTInt) {
600  q->setError(QFile::PositionError, QLatin1String("Maximum 2GB file position on this platform"));
601  return false;
602  }
603 #endif
604  symbianFilePos = pos;
605  return true;
606  }
607 #endif
608  return seekFdFh(pos);
609 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
#define Q_Q(Class)
Definition: qglobal.h:2483
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ nativeSize()

qint64 QFSFileEnginePrivate::nativeSize ( ) const

Definition at line 694 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

695 {
696 #ifdef Q_OS_SYMBIAN
697  const Q_Q(QFSFileEngine);
698  if (symbianFile.SubSessionHandle()) {
699 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
700  qint64 size;
701 #else
702  TInt size;
703 #endif
704  TInt err = symbianFile.Size(size);
705  if(err != KErrNone) {
707  return 0;
708  }
709  return size;
710  }
711 #endif
712  return sizeFdFh();
713 }
#define Q_Q(Class)
Definition: qglobal.h:2483
__int64 qint64
Definition: qglobal.h:942
QString toString()
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ nativeWrite()

qint64 QFSFileEnginePrivate::nativeWrite ( const char *  data,
qint64  len 
)
Warning
This function is not part of the public interface.

Definition at line 537 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

538 {
539 #ifdef Q_OS_SYMBIAN
541  if (symbianFile.SubSessionHandle()) {
542  if(len > KMaxTInt) {
543  //this check is more likely to catch a corrupt length, since it isn't possible to allocate 2GB buffers (yet..)
544  q->setError(QFile::WriteError, QLatin1String("Maximum 2GB in single write on this platform"));
545  return -1;
546  }
547  const TPtrC8 ptr(reinterpret_cast<const TUint8*>(data), static_cast<TInt>(len));
548 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
549  TInt64 eofpos = 0;
550 #else
551  TInt eofpos = 0;
552 #endif
553  //The end of file position is not cached because QFile is read/write sharable, therefore another
554  //process may have altered the file size.
555  TInt r = symbianFile.Seek(ESeekEnd, eofpos);
556  if (r == KErrNone && symbianFilePos > eofpos) {
557  //seek position is beyond end of file so file needs to be extended before write.
558  //note that SetSize does not zero-initialise (c.f. posix lseek)
559  r = symbianFile.SetSize(symbianFilePos);
560  }
561  if (r == KErrNone) {
562  //write to specific position in the file (i.e. use our own cursor rather than calling seek)
563  r = symbianFile.Write(symbianFilePos, ptr);
564  }
565  if (r != KErrNone) {
567  return -1;
568  }
569  symbianFilePos += len;
570  return len;
571  }
572 #endif
573  return writeFdFh(data, len);
574 }
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
qint64 writeFdFh(const char *data, qint64 len)
#define Q_Q(Class)
Definition: qglobal.h:2483
static QString toString(Register *reg, int type, bool *ok=0)
static const char * data(const QByteArray &arr)
const T * ptr(const T &t)
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ openFd()

bool QFSFileEnginePrivate::openFd ( QIODevice::OpenMode  flags,
int  fd 
)

Opens the file descriptor fd to the file engine, using the open mode flags.

Definition at line 347 of file qfsfileengine.cpp.

348 {
350  this->fd = fd;
351  fh = 0;
352 
353  // Seek to the end when in Append mode.
354  if (openMode & QFile::Append) {
355  int ret;
356  do {
357  ret = QT_LSEEK(fd, 0, SEEK_END);
358  } while (ret == -1 && errno == EINTR);
359 
360  if (ret == -1) {
361  q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
362  qt_error_string(int(errno)));
363 
365  this->fd = -1;
366 
367  return false;
368  }
369  }
370 
371  return true;
372 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
QIODevice::OpenMode openMode
#define Q_Q(Class)
Definition: qglobal.h:2483
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ openFh()

bool QFSFileEnginePrivate::openFh ( QIODevice::OpenMode  flags,
FILE *  fh 
)

Opens the file handle fh using the open mode flags.

Definition at line 275 of file qfsfileengine.cpp.

276 {
278  this->fh = fh;
279  fd = -1;
280 
281  // Seek to the end when in Append mode.
282  if (openMode & QIODevice::Append) {
283  int ret;
284  do {
285  ret = QT_FSEEK(fh, 0, SEEK_END);
286  } while (ret != 0 && errno == EINTR);
287 
288  if (ret != 0) {
289  q->setError(errno == EMFILE ? QFile::ResourceError : QFile::OpenError,
290  qt_error_string(int(errno)));
291 
293  this->fh = 0;
294 
295  return false;
296  }
297  }
298 
299  return true;
300 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
QIODevice::OpenMode openMode
#define Q_Q(Class)
Definition: qglobal.h:2483
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ posFdFh()

qint64 QFSFileEnginePrivate::posFdFh ( ) const
Warning
This function is not part of the public interface.

Definition at line 528 of file qfsfileengine.cpp.

Referenced by longFileName(), and nativePos().

529 {
530  if (fh)
531  return qint64(QT_FTELL(fh));
532  return QT_LSEEK(fd, 0, SEEK_CUR);
533 }
__int64 qint64
Definition: qglobal.h:942

◆ readFdFh()

qint64 QFSFileEnginePrivate::readFdFh ( char *  data,
qint64  len 
)
Warning
This function is not part of the public interface.

Definition at line 612 of file qfsfileengine.cpp.

Referenced by longFileName(), and nativeRead().

613 {
615 
616  if (len < 0 || len != qint64(size_t(len))) {
617  q->setError(QFile::ReadError, qt_error_string(EINVAL));
618  return -1;
619  }
620 
621  qint64 readBytes = 0;
622  bool eof = false;
623 
624  if (fh) {
625  // Buffered stdlib mode.
626 
627  size_t result;
628  bool retry = true;
629  do {
630  result = fread(data + readBytes, 1, size_t(len - readBytes), fh);
631  eof = feof(fh);
632  if (retry && eof && result == 0) {
633  // On Mac OS, this is needed, e.g., if a file was written to
634  // through another stream since our last read. See test
635  // tst_QFile::appendAndRead
636  QT_FSEEK(fh, QT_FTELL(fh), SEEK_SET); // re-sync stream.
637  retry = false;
638  continue;
639  }
640  readBytes += result;
641  } while (!eof && (result == 0 ? errno == EINTR : readBytes < len));
642 
643  } else if (fd != -1) {
644  // Unbuffered stdio mode.
645 
646 #ifdef Q_OS_WIN
647  int result;
648 #else
649  ssize_t result;
650 #endif
651  do {
652  result = QT_READ(fd, data + readBytes, size_t(len - readBytes));
653  } while ((result == -1 && errno == EINTR)
654  || (result > 0 && (readBytes += result) < len));
655 
656  eof = !(result == -1);
657  }
658 
659  if (!eof && readBytes == 0) {
660  readBytes = -1;
661  q->setError(QFile::ReadError, qt_error_string(errno));
662  }
663 
664  return readBytes;
665 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
#define QT_READ
Definition: qcore_unix_p.h:280
#define Q_Q(Class)
Definition: qglobal.h:2483
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ readLineFdFh()

qint64 QFSFileEnginePrivate::readLineFdFh ( char *  data,
qint64  maxlen 
)
Warning
This function is not part of the public interface.

Definition at line 688 of file qfsfileengine.cpp.

Referenced by longFileName(), and nativeReadLine().

689 {
691  if (!fh)
692  return q->QAbstractFileEngine::readLine(data, maxlen);
693 
694  QT_OFF_T oldPos = 0;
695 #ifdef Q_OS_WIN
696  bool seq = q->isSequential();
697  if (!seq)
698 #endif
699  oldPos = QT_FTELL(fh);
700 
701  // QIODevice::readLine() passes maxlen - 1 to QFile::readLineData()
702  // because it has made space for the '\0' at the end of data. But fgets
703  // does the same, so we'd get two '\0' at the end - passing maxlen + 1
704  // solves this.
705  if (!fgets(data, int(maxlen + 1), fh)) {
706  if (!feof(fh))
707  q->setError(QFile::ReadError, qt_error_string(int(errno)));
708  return -1; // error
709  }
710 
711 #ifdef Q_OS_WIN
712  if (seq)
713  return qstrlen(data);
714 #endif
715 
716  qint64 lineLength = QT_FTELL(fh) - oldPos;
717  return lineLength > 0 ? lineLength : qstrlen(data);
718 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
#define Q_Q(Class)
Definition: qglobal.h:2483
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
uint qstrlen(const char *str)
Definition: qbytearray.h:79
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ seekFdFh()

bool QFSFileEnginePrivate::seekFdFh ( qint64  pos)
Warning
This function is not part of the public interface.

Definition at line 547 of file qfsfileengine.cpp.

Referenced by longFileName(), and nativeSeek().

548 {
550 
551  // On Windows' stdlib implementation, the results of calling fread and
552  // fwrite are undefined if not called either in sequence, or if preceded
553  // with a call to fflush().
555  return false;
556 
557  if (pos < 0 || pos != qint64(QT_OFF_T(pos)))
558  return false;
559 
560  if (fh) {
561  // Buffered stdlib mode.
562  int ret;
563  do {
564  ret = QT_FSEEK(fh, QT_OFF_T(pos), SEEK_SET);
565  } while (ret != 0 && errno == EINTR);
566 
567  if (ret != 0) {
568  q->setError(QFile::ReadError, qt_error_string(int(errno)));
569  return false;
570  }
571  } else {
572  // Unbuffered stdio mode.
573  if (QT_LSEEK(fd, QT_OFF_T(pos), SEEK_SET) == -1) {
574  qWarning() << "QFile::at: Cannot set file position" << pos;
576  return false;
577  }
578  }
579  return true;
580 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
LastIOCommand lastIOCommand
#define Q_Q(Class)
Definition: qglobal.h:2483
Q_CORE_EXPORT void qWarning(const char *,...)
__int64 qint64
Definition: qglobal.h:942
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ unmap()

bool QFSFileEnginePrivate::unmap ( uchar ptr)

Definition at line 1140 of file qfsfileengine_unix.cpp.

Referenced by longFileName().

1141 {
1142 #if !defined(Q_OS_INTEGRITY)
1143  Q_Q(QFSFileEngine);
1144  if (!maps.contains(ptr)) {
1145  q->setError(QFile::PermissionsError, qt_error_string(EACCES));
1146  return false;
1147  }
1148 
1149 #ifdef QT_SYMBIAN_USE_NATIVE_FILEMAP
1150  RFileMap mapping = maps.value(ptr);
1151  TInt err = mapping.Flush();
1152  mapping.Close();
1153  maps.remove(ptr);
1154  if (err) {
1156  return false;
1157  }
1158  return true;
1159 #else
1160  uchar *start = ptr - maps[ptr].first;
1161  size_t len = maps[ptr].second;
1162  if (-1 == munmap(start, len)) {
1164  return false;
1165  }
1166  maps.remove(ptr);
1167  return true;
1168 #endif
1169 #else
1170  return false;
1171 #endif
1172 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
int remove(const Key &key)
Removes all the items that have the key from the hash.
Definition: qhash.h:784
bool contains(const Key &key) const
Returns true if the hash contains an item with the key; otherwise returns false.
Definition: qhash.h:872
const T value(const Key &key) const
Returns the value associated with the key.
Definition: qhash.h:606
#define Q_Q(Class)
Definition: qglobal.h:2483
unsigned char uchar
Definition: qglobal.h:994
static QString toString(Register *reg, int type, bool *ok=0)
QHash< uchar *, DWORD > maps
const T * ptr(const T &t)
static QMap< QByteArray, int > mapping
Definition: qaxserver.cpp:577
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

◆ writeFdFh()

qint64 QFSFileEnginePrivate::writeFdFh ( const char *  data,
qint64  len 
)
Warning
This function is not part of the public interface.

Definition at line 741 of file qfsfileengine.cpp.

Referenced by longFileName(), and nativeWrite().

742 {
744 
745  if (len < 0 || len != qint64(size_t(len))) {
746  q->setError(QFile::WriteError, qt_error_string(EINVAL));
747  return -1;
748  }
749 
750  qint64 writtenBytes = 0;
751 
752  if (fh) {
753  // Buffered stdlib mode.
754 
755  size_t result;
756  do {
757  result = fwrite(data + writtenBytes, 1, size_t(len - writtenBytes), fh);
758  writtenBytes += result;
759  } while (result == 0 ? errno == EINTR : writtenBytes < len);
760 
761  } else if (fd != -1) {
762  // Unbuffered stdio mode.
763 
764 #ifdef Q_OS_WIN
765  int result;
766 #else
767  ssize_t result;
768 #endif
769  do {
770  result = QT_WRITE(fd, data + writtenBytes, size_t(len - writtenBytes));
771  } while ((result == -1 && errno == EINTR)
772  || (result > 0 && (writtenBytes += result) < len));
773  }
774 
775  if (len && writtenBytes == 0) {
776  writtenBytes = -1;
778  }
779 
780  return writtenBytes;
781 }
QString qt_error_string(int errorCode)
Definition: qglobal.cpp:2600
#define Q_Q(Class)
Definition: qglobal.h:2483
static const char * data(const QByteArray &arr)
__int64 qint64
Definition: qglobal.h:942
#define QT_WRITE
Definition: qcore_unix_p.h:289
int errno
The QFSFileEngine class implements Qt&#39;s default file engine.
Definition: qfsfileengine.h:60

Properties

◆ closeFileHandle

bool QFSFileEnginePrivate::closeFileHandle

Definition at line 179 of file qfsfileengine_p.h.

Referenced by init(), nativeOpen(), and setCloseOnExec().

◆ could_stat

uint QFSFileEnginePrivate::could_stat
mutable

Definition at line 182 of file qfsfileengine_p.h.

◆ fd

int QFSFileEnginePrivate::fd

◆ fh

FILE* QFSFileEnginePrivate::fh

◆ fileAttrib

DWORD QFSFileEnginePrivate::fileAttrib
mutable

Definition at line 163 of file qfsfileengine_p.h.

Referenced by init().

◆ fileEntry

QFileSystemEntry QFSFileEnginePrivate::fileEntry

◆ fileHandle

HANDLE QFSFileEnginePrivate::fileHandle

Definition at line 155 of file qfsfileengine_p.h.

Referenced by init(), and longFileName().

◆ is_sequential

uint QFSFileEnginePrivate::is_sequential
mutable

Definition at line 181 of file qfsfileengine_p.h.

Referenced by init().

◆ lastFlushFailed

bool QFSFileEnginePrivate::lastFlushFailed

Definition at line 178 of file qfsfileengine_p.h.

Referenced by init().

◆ lastIOCommand

LastIOCommand QFSFileEnginePrivate::lastIOCommand

Definition at line 177 of file qfsfileengine_p.h.

Referenced by init().

◆ mapHandle

HANDLE QFSFileEnginePrivate::mapHandle

Definition at line 156 of file qfsfileengine_p.h.

Referenced by init(), and longFileName().

◆ maps

QHash<uchar *, DWORD > QFSFileEnginePrivate::maps

Definition at line 157 of file qfsfileengine_p.h.

Referenced by longFileName(), map(), and unmap().

◆ metaData

QFileSystemMetaData QFSFileEnginePrivate::metaData
mutable

Definition at line 123 of file qfsfileengine_p.h.

Referenced by doStat(), isSymlink(), longFileName(), map(), and nativeOpen().

◆ openMode

QIODevice::OpenMode QFSFileEnginePrivate::openMode

Definition at line 91 of file qfsfileengine_p.h.

Referenced by init(), longFileName(), and setCloseOnExec().

◆ tried_stat

uint QFSFileEnginePrivate::tried_stat
mutable

Definition at line 183 of file qfsfileengine_p.h.

Referenced by doStat(), init(), and longFileName().


The documentation for this class was generated from the following files: