File indexing completed on 2024-12-22 04:35:00

0001 /*
0002     SPDX-FileCopyrightText: 2009 Nokia Corporation and /or its subsidiary(-ies).
0003     Contact: Qt Software Information (qt-info@nokia.com)
0004 
0005     This file is part of the QtCore module of the Qt Toolkit.
0006 
0007     $QT_BEGIN_LICENSE:LGPL$
0008     Commercial Usage
0009     Licensees holding valid Qt Commercial licenses may use this file in
0010     accordance with the Qt Commercial License Agreement provided with the
0011     Software or, alternatively, in accordance with the terms contained in
0012     a written agreement between you and Nokia.
0013 
0014     GNU Lesser General Public License Usage
0015     Alternatively, this file may be used under the terms of the GNU Lesser
0016     General Public License version 2.1 as published by the Free Software
0017     Foundation and appearing in the file LICENSE.LGPL included in the
0018     packaging of this file.  Please review the following information to
0019     ensure the GNU Lesser General Public License version 2.1 requirements
0020     will be met: https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
0021 
0022     In addition, as a special exception, Nokia gives you certain
0023     additional rights. These rights are described in the Nokia Qt LGPL
0024     Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
0025     package.
0026 
0027     GNU General Public License Usage
0028     Alternatively, this file may be used under the terms of the GNU
0029     General Public License version 3.0 as published by the Free Software
0030     Foundation and appearing in the file LICENSE.GPL included in the
0031     packaging of this file.  Please review the following information to
0032     ensure the GNU General Public License version 3.0 requirements will be
0033     met: https://www.gnu.org/licenses/gpl-3.0.html.
0034 
0035     If you are unsure which license is appropriate for your use, please
0036     contact the sales department at qt-sales@nokia.com.
0037     $QT_END_LICENSE$
0038 
0039 */
0040 
0041 #ifndef QFSFILEENGINE_P_H
0042 #define QFSFILEENGINE_P_H
0043 
0044 //
0045 //  W A R N I N G
0046 //  -------------
0047 //
0048 // This file is not part of the Qt API.  It exists purely as an
0049 // implementation detail.  This header file may change from version to
0050 // version without notice, or even be removed.
0051 //
0052 // We mean it.
0053 //
0054 
0055 #include "qplatformdefs.h"
0056 #include "qfsfileengine.h"
0057 #include "private/qabstractfileengine_p.h"
0058 #include <QHash>
0059 
0060 #include "k3b_export.h"
0061 
0062 #ifndef QT_NO_FSFILEENGINE
0063 
0064 QT_BEGIN_NAMESPACE
0065 
0066 #if defined(Q_OS_WINCE_STD) && _WIN32_WCE < 0x600
0067 #define Q_USE_DEPRECATED_MAP_API 1
0068 #endif
0069 
0070 class LIBK3B_EXPORT QFSFileEnginePrivate : public QAbstractFileEnginePrivate
0071 {
0072     Q_DECLARE_PUBLIC(QFSFileEngine)
0073 
0074 public:
0075 #ifdef Q_WS_WIN
0076     static QByteArray win95Name(const QString &path);
0077     static QString longFileName(const QString &path);
0078 #endif
0079     static QString canonicalized(const QString &path);
0080 
0081     QString filePath;
0082     QByteArray nativeFilePath;
0083     QIODevice::OpenMode openMode;
0084 
0085     void nativeInitFileName();
0086     bool nativeOpen(QIODevice::OpenMode openMode);
0087     bool openFh(QIODevice::OpenMode flags, FILE *fh);
0088     bool openFd(QIODevice::OpenMode flags, int fd);
0089     bool nativeClose();
0090     bool closeFdFh();
0091     bool nativeFlush();
0092     bool flushFh();
0093     qint64 nativeSize() const;
0094     qint64 sizeFdFh() const;
0095     qint64 nativePos() const;
0096     qint64 posFdFh() const;
0097     bool nativeSeek(qint64);
0098     bool seekFdFh(qint64);
0099     qint64 nativeRead(char *data, qint64 maxlen);
0100     qint64 readFdFh(char *data, qint64 maxlen);
0101     qint64 nativeReadLine(char *data, qint64 maxlen);
0102     qint64 readLineFdFh(char *data, qint64 maxlen);
0103     qint64 nativeWrite(const char *data, qint64 len);
0104     qint64 writeFdFh(const char *data, qint64 len);
0105     int nativeHandle() const;
0106     bool nativeIsSequential() const;
0107     bool isSequentialFdFh() const;
0108 
0109     uchar *map(qint64 offset, qint64 size, QFile::MemoryMapFlags flags);
0110     bool unmap(uchar *ptr);
0111 
0112     FILE *fh;
0113 #ifdef Q_WS_WIN
0114     HANDLE fileHandle;
0115     QHash<uchar *, QPair<int /*offset*/, HANDLE /*handle*/> > maps;
0116     mutable int cachedFd;
0117     mutable DWORD fileAttrib;
0118 #else
0119     QHash<uchar *, QPair<int /*offset*/, int /*handle|len*/> > maps;
0120     mutable QT_STATBUF st;
0121 #endif
0122     int fd;
0123 
0124 #ifdef Q_USE_DEPRECATED_MAP_API
0125     void mapHandleClose();
0126     HANDLE fileMapHandle;
0127 #endif
0128 
0129     enum LastIOCommand
0130     {
0131         IOFlushCommand,
0132         IOReadCommand,
0133         IOWriteCommand
0134     };
0135     LastIOCommand  lastIOCommand;
0136     bool lastFlushFailed;
0137     bool closeFileHandle;
0138 
0139     mutable uint is_sequential : 2;
0140     mutable uint could_stat : 1;
0141     mutable uint tried_stat : 1;
0142 #ifdef Q_OS_UNIX
0143     mutable uint need_lstat : 1;
0144     mutable uint is_link : 1;
0145 #endif
0146     bool doStat() const;
0147     bool isSymlink() const;
0148 
0149 #if defined(Q_OS_WIN32)
0150     int sysOpen(const QString &, int flags);
0151 #endif
0152 
0153 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
0154     static void resolveLibs();
0155     static bool resolveUNCLibs_NT();
0156     static bool resolveUNCLibs_9x();
0157     static bool uncListSharesOnServer(const QString &server, QStringList *list);
0158 #endif
0159 
0160 protected:
0161     QFSFileEnginePrivate();
0162 
0163     void init();
0164 
0165 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE)
0166     QAbstractFileEngine::FileFlags getPermissions() const;
0167     QString getLink() const;
0168 #endif
0169 };
0170 
0171 QT_END_NAMESPACE
0172 
0173 #endif // QT_NO_FSFILEENGINE
0174 
0175 #endif // QFSFILEENGINE_P_H