Fix 32/64-bit issues with QFile::map/unmap() on *nix systems
[qt-netbsd.git] / src / corelib / io / qfsfileengine_p.h
blobee127c131325bb44ff9ca26437a33d9a464e2418
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the QtCore module of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #ifndef QFSFILEENGINE_P_H
43 #define QFSFILEENGINE_P_H
46 // W A R N I N G
47 // -------------
49 // This file is not part of the Qt API. It exists purely as an
50 // implementation detail. This header file may change from version to
51 // version without notice, or even be removed.
53 // We mean it.
56 #include "qplatformdefs.h"
57 #include "QtCore/qfsfileengine.h"
58 #include "private/qabstractfileengine_p.h"
59 #include <qhash.h>
61 #ifndef QT_NO_FSFILEENGINE
63 QT_BEGIN_NAMESPACE
65 #if defined(Q_OS_WINCE_STD) && _WIN32_WCE < 0x600
66 #define Q_USE_DEPRECATED_MAP_API 1
67 #endif
69 class QFSFileEnginePrivate : public QAbstractFileEnginePrivate
71 Q_DECLARE_PUBLIC(QFSFileEngine)
73 public:
74 #ifdef Q_WS_WIN
75 static QString longFileName(const QString &path);
76 #endif
77 static QString canonicalized(const QString &path);
79 QString filePath;
80 QByteArray nativeFilePath;
81 QIODevice::OpenMode openMode;
83 void nativeInitFileName();
84 bool nativeOpen(QIODevice::OpenMode openMode);
85 bool openFh(QIODevice::OpenMode flags, FILE *fh);
86 bool openFd(QIODevice::OpenMode flags, int fd);
87 bool nativeClose();
88 bool closeFdFh();
89 bool nativeFlush();
90 bool flushFh();
91 qint64 nativeSize() const;
92 qint64 sizeFdFh() const;
93 qint64 nativePos() const;
94 qint64 posFdFh() const;
95 bool nativeSeek(qint64);
96 bool seekFdFh(qint64);
97 qint64 nativeRead(char *data, qint64 maxlen);
98 qint64 readFdFh(char *data, qint64 maxlen);
99 qint64 nativeReadLine(char *data, qint64 maxlen);
100 qint64 readLineFdFh(char *data, qint64 maxlen);
101 qint64 nativeWrite(const char *data, qint64 len);
102 qint64 writeFdFh(const char *data, qint64 len);
103 int nativeHandle() const;
104 bool nativeIsSequential() const;
105 bool isSequentialFdFh() const;
107 uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
108 bool unmap(uchar *ptr);
110 FILE *fh;
111 #ifdef Q_WS_WIN
112 HANDLE fileHandle;
113 QHash<uchar *, QPair<int /*offset*/, HANDLE /*handle*/> > maps;
114 mutable int cachedFd;
115 mutable DWORD fileAttrib;
116 #else
117 QHash<uchar *, QPair<int /*offset % PageSize*/, size_t /*length + offset % PageSize*/> > maps;
118 mutable QT_STATBUF st;
119 #endif
120 int fd;
122 #ifdef Q_USE_DEPRECATED_MAP_API
123 void mapHandleClose();
124 HANDLE fileMapHandle;
125 #endif
127 enum LastIOCommand
129 IOFlushCommand,
130 IOReadCommand,
131 IOWriteCommand
133 LastIOCommand lastIOCommand;
134 bool lastFlushFailed;
135 bool closeFileHandle;
137 mutable uint is_sequential : 2;
138 mutable uint could_stat : 1;
139 mutable uint tried_stat : 1;
140 #if !defined(Q_OS_WINCE)
141 mutable uint need_lstat : 1;
142 mutable uint is_link : 1;
143 #endif
145 bool doStat() const;
146 bool isSymlink() const;
148 #if defined(Q_OS_WIN32)
149 int sysOpen(const QString &, int flags);
150 #endif
152 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
153 static void resolveLibs();
154 static bool resolveUNCLibs();
155 static bool uncListSharesOnServer(const QString &server, QStringList *list);
156 #endif
158 protected:
159 QFSFileEnginePrivate();
161 void init();
163 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
164 QAbstractFileEngine::FileFlags getPermissions() const;
165 #endif
168 QT_END_NAMESPACE
170 #endif // QT_NO_FSFILEENGINE
172 #endif // QFSFILEENGINE_P_H