1 /*
2     SPDX-FileCopyrightText: 2009 Nokia Corporation and /or its subsidiary(-ies).
3     Contact: Qt Software Information (qt-info@nokia.com)
4 
5     This file is part of the QtCore module of the Qt Toolkit.
6 
7     $QT_BEGIN_LICENSE:LGPL$
8     Commercial Usage
9     Licensees holding valid Qt Commercial licenses may use this file in
10     accordance with the Qt Commercial License Agreement provided with the
11     Software or, alternatively, in accordance with the terms contained in
12     a written agreement between you and Nokia.
13 
14     GNU Lesser General Public License Usage
15     Alternatively, this file may be used under the terms of the GNU Lesser
16     General Public License version 2.1 as published by the Free Software
17     Foundation and appearing in the file LICENSE.LGPL included in the
18     packaging of this file.  Please review the following information to
19     ensure the GNU Lesser General Public License version 2.1 requirements
20     will be met: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
21 
22     In addition, as a special exception, Nokia gives you certain
23     additional rights. These rights are described in the Nokia Qt LGPL
24     Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
25     package.
26 
27     GNU General Public License Usage
28     Alternatively, this file may be used under the terms of the GNU
29     General Public License version 3.0 as published by the Free Software
30     Foundation and appearing in the file LICENSE.GPL included in the
31     packaging of this file.  Please review the following information to
32     ensure the GNU General Public License version 3.0 requirements will be
33     met: https://www.gnu.org/licenses/gpl-3.0.html.
34 
35     If you are unsure which license is appropriate for your use, please
36     contact the sales department at qt-sales@nokia.com.
37     $QT_END_LICENSE$
38 
39 */
40 
41 #ifndef QFSFILEENGINE_P_H
42 #define QFSFILEENGINE_P_H
43 
44 //
45 //  W A R N I N G
46 //  -------------
47 //
48 // This file is not part of the Qt API.  It exists purely as an
49 // implementation detail.  This header file may change from version to
50 // version without notice, or even be removed.
51 //
52 // We mean it.
53 //
54 
55 #include "qplatformdefs.h"
56 #include "qfsfileengine.h"
57 #include "private/qabstractfileengine_p.h"
58 #include <QHash>
59 
60 #include "k3b_export.h"
61 
62 #ifndef QT_NO_FSFILEENGINE
63 
64 QT_BEGIN_NAMESPACE
65 
66 #if defined(Q_OS_WINCE_STD) && _WIN32_WCE < 0x600
67 #define Q_USE_DEPRECATED_MAP_API 1
68 #endif
69 
70 class LIBK3B_EXPORT QFSFileEnginePrivate : public QAbstractFileEnginePrivate
71 {
72     Q_DECLARE_PUBLIC(QFSFileEngine)
73 
74 public:
75 #ifdef Q_WS_WIN
76     static QByteArray win95Name(const QString &path);
77     static QString longFileName(const QString &path);
78 #endif
79     static QString canonicalized(const QString &path);
80 
81     QString filePath;
82     QByteArray nativeFilePath;
83     QIODevice::OpenMode openMode;
84 
85     void nativeInitFileName();
86     bool nativeOpen(QIODevice::OpenMode openMode);
87     bool openFh(QIODevice::OpenMode flags, FILE *fh);
88     bool openFd(QIODevice::OpenMode flags, int fd);
89     bool nativeClose();
90     bool closeFdFh();
91     bool nativeFlush();
92     bool flushFh();
93     qint64 nativeSize() const;
94     qint64 sizeFdFh() const;
95     qint64 nativePos() const;
96     qint64 posFdFh() const;
97     bool nativeSeek(qint64);
98     bool seekFdFh(qint64);
99     qint64 nativeRead(char *data, qint64 maxlen);
100     qint64 readFdFh(char *data, qint64 maxlen);
101     qint64 nativeReadLine(char *data, qint64 maxlen);
102     qint64 readLineFdFh(char *data, qint64 maxlen);
103     qint64 nativeWrite(const char *data, qint64 len);
104     qint64 writeFdFh(const char *data, qint64 len);
105     int nativeHandle() const;
106     bool nativeIsSequential() const;
107     bool isSequentialFdFh() const;
108 
109     uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
110     bool unmap(uchar *ptr);
111 
112     FILE *fh;
113 #ifdef Q_WS_WIN
114     HANDLE fileHandle;
115     QHash<uchar *, QPair<int /*offset*/, HANDLE /*handle*/> > maps;
116     mutable int cachedFd;
117     mutable DWORD fileAttrib;
118 #else
119     QHash<uchar *, QPair<int /*offset*/, int /*handle|len*/> > maps;
120     mutable QT_STATBUF st;
121 #endif
122     int fd;
123 
124 #ifdef Q_USE_DEPRECATED_MAP_API
125     void mapHandleClose();
126     HANDLE fileMapHandle;
127 #endif
128 
129     enum LastIOCommand
130     {
131         IOFlushCommand,
132         IOReadCommand,
133         IOWriteCommand
134     };
135     LastIOCommand  lastIOCommand;
136     bool lastFlushFailed;
137     bool closeFileHandle;
138 
139     mutable uint is_sequential : 2;
140     mutable uint could_stat : 1;
141     mutable uint tried_stat : 1;
142 #ifdef Q_OS_UNIX
143     mutable uint need_lstat : 1;
144     mutable uint is_link : 1;
145 #endif
146     bool doStat() const;
147     bool isSymlink() const;
148 
149 #if defined(Q_OS_WIN32)
150     int sysOpen(const QString &, int flags);
151 #endif
152 
153 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
154     static void resolveLibs();
155     static bool resolveUNCLibs_NT();
156     static bool resolveUNCLibs_9x();
157     static bool uncListSharesOnServer(const QString &server, QStringList *list);
158 #endif
159 
160 protected:
161     QFSFileEnginePrivate();
162 
163     void init();
164 
165 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
166     QAbstractFileEngine::FileFlags getPermissions() const;
167     QString getLink() const;
168 #endif
169 };
170 
171 QT_END_NAMESPACE
172 
173 #endif // QT_NO_FSFILEENGINE
174 
175 #endif // QFSFILEENGINE_P_H
176