Qt 4.8
qfilesystemmetadata_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QFILESYSTEMMETADATA_P_H_INCLUDED
43 #define QFILESYSTEMMETADATA_P_H_INCLUDED
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
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.
52 //
53 // We mean it.
54 //
55 
56 #include "qplatformdefs.h"
57 #include <QtCore/qglobal.h>
58 #include <QtCore/qdatetime.h>
59 #include <QtCore/qabstractfileengine.h>
60 
61 // Platform-specific includes
62 #if defined(Q_OS_WIN)
63 #ifndef IO_REPARSE_TAG_SYMLINK
64 #define IO_REPARSE_TAG_SYMLINK (0xA000000CL)
65 #endif
66 #elif defined(Q_OS_SYMBIAN)
67 #include <f32file.h>
68 #include <QtCore/private/qdatetime_p.h>
69 #endif
70 
72 
73 class QFileSystemEngine;
74 
76 {
77 public:
79  : knownFlagsMask(0)
80  {
81  }
82 
83  enum MetaDataFlag {
84  // Permissions, overlaps with QFile::Permissions
85  OtherReadPermission = 0x00000004, OtherWritePermission = 0x00000002, OtherExecutePermission = 0x00000001,
86  GroupReadPermission = 0x00000040, GroupWritePermission = 0x00000020, GroupExecutePermission = 0x00000010,
87  UserReadPermission = 0x00000400, UserWritePermission = 0x00000200, UserExecutePermission = 0x00000100,
88  OwnerReadPermission = 0x00004000, OwnerWritePermission = 0x00002000, OwnerExecutePermission = 0x00001000,
89 
94 
98 
100 
101  // Type
102 #ifdef Q_OS_SYMBIAN
103  LinkType = 0,
104 #else
105  LinkType = 0x00010000,
106 #endif
107  FileType = 0x00020000,
108  DirectoryType = 0x00040000,
109 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC)
110  BundleType = 0x00080000,
111  AliasType = 0x08000000,
112 #else
113  BundleType = 0x0,
114  AliasType = 0x0,
115 #endif
116 #if defined(Q_OS_WIN)
117  WinLnkType = 0x08000000, // Note: Uses the same position for AliasType on Mac
118 #else
119  WinLnkType = 0x0,
120 #endif
121  SequentialType = 0x00800000, // Note: overlaps with QAbstractFileEngine::RootFlag
122 
124 
126 
127  // Attributes
128  HiddenAttribute = 0x00100000,
129  SizeAttribute = 0x00200000, // Note: overlaps with QAbstractFileEngine::LocalDiskFlag
130  ExistsAttribute = 0x00400000,
131 
133 
134  // Times
135  CreationTime = 0x01000000, // Note: overlaps with QAbstractFileEngine::Refresh
136  ModificationTime = 0x02000000,
137  AccessTime = 0x04000000,
138 
140 
141  // Owner IDs
142  UserId = 0x10000000,
143  GroupId = 0x20000000,
144 
146 
156 
163 #if defined(Q_OS_WIN)
170 #endif
171 
172  AllMetaDataFlags = 0xFFFFFFFF
173 
174  };
175  Q_DECLARE_FLAGS(MetaDataFlags, MetaDataFlag)
176 
177  bool hasFlags(MetaDataFlags flags) const
178  {
179  return ((knownFlagsMask & flags) == flags);
180  }
181 
182  MetaDataFlags missingFlags(MetaDataFlags flags)
183  {
184  return flags & ~knownFlagsMask;
185  }
186 
187  void clear()
188  {
189  knownFlagsMask = 0;
190  }
191 
192  void clearFlags(MetaDataFlags flags = AllMetaDataFlags)
193  {
194  knownFlagsMask &= ~flags;
195  }
196 
197  bool exists() const { return (entryFlags & ExistsAttribute); }
198 
199  bool isLink() const { return (entryFlags & LinkType); }
200  bool isFile() const { return (entryFlags & FileType); }
201  bool isDirectory() const { return (entryFlags & DirectoryType); }
202  bool isBundle() const;
203  bool isAlias() const;
204  bool isLegacyLink() const { return (entryFlags & LegacyLinkType); }
205  bool isSequential() const { return (entryFlags & SequentialType); }
206  bool isHidden() const { return (entryFlags & HiddenAttribute); }
207 #if defined(Q_OS_WIN)
208  bool isLnkFile() const { return (entryFlags & WinLnkType); }
209 #else
210  bool isLnkFile() const { return false; }
211 #endif
212 
213  qint64 size() const { return size_; }
214 
215  QFile::Permissions permissions() const { return QFile::Permissions(Permissions & entryFlags); }
216 
217  QDateTime creationTime() const;
218  QDateTime modificationTime() const;
219  QDateTime accessTime() const;
220 
222  uint userId() const;
223  uint groupId() const;
225 
226 #ifdef Q_OS_UNIX
227  void fillFromStatBuf(const QT_STATBUF &statBuffer);
228  void fillFromDirEnt(const QT_DIRENT &statBuffer);
229 #endif
230 #ifdef Q_OS_SYMBIAN
231  void fillFromTEntry(const TEntry& entry);
232  void fillFromVolumeInfo(const TVolumeInfo& info);
233 #endif
234 
235 #if defined(Q_OS_WIN)
236  inline void fillFromFileAttribute(DWORD fileAttribute, bool isDriveRoot = false);
237  inline void fillFromFindData(WIN32_FIND_DATA &findData, bool setLinkType = false, bool isDriveRoot = false);
238  inline void fillFromFindInfo(BY_HANDLE_FILE_INFORMATION &fileInfo);
239 #endif
240 private:
241  friend class QFileSystemEngine;
242 
243  MetaDataFlags knownFlagsMask;
244  MetaDataFlags entryFlags;
245 
247 
248  // Platform-specific data goes here:
249 #if defined(Q_OS_WIN)
251  FILETIME creationTime_;
252  FILETIME lastAccessTime_;
253  FILETIME lastWriteTime_;
254 #elif defined(Q_OS_SYMBIAN)
255  TTime modificationTime_;
256 #else
258  time_t modificationTime_;
259  time_t accessTime_;
260 
261  uint userId_;
262  uint groupId_;
263 #endif
264 
265 };
266 
267 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileSystemMetaData::MetaDataFlags)
268 
269 #if !defined(QWS) && !defined(Q_WS_QPA) && defined(Q_OS_MAC)
270 inline bool QFileSystemMetaData::isBundle() const { return (entryFlags & BundleType); }
271 inline bool QFileSystemMetaData::isAlias() const { return (entryFlags & AliasType); }
272 #else
273 inline bool QFileSystemMetaData::isBundle() const { return false; }
274 inline bool QFileSystemMetaData::isAlias() const { return false; }
275 #endif
276 
277 #if (defined(Q_OS_UNIX) && !defined (Q_OS_SYMBIAN)) || defined (Q_OS_WIN)
279 {
280  switch (time) {
282  return modificationTime();
283 
285  return accessTime();
286 
288  return creationTime();
289  }
290 
291  return QDateTime();
292 }
293 #endif
294 
295 #if defined(Q_OS_UNIX) && !defined (Q_OS_SYMBIAN)
297 inline QDateTime QFileSystemMetaData::modificationTime() const { return QDateTime::fromTime_t(modificationTime_); }
298 inline QDateTime QFileSystemMetaData::accessTime() const { return QDateTime::fromTime_t(accessTime_); }
299 
300 inline uint QFileSystemMetaData::userId() const { return userId_; }
301 inline uint QFileSystemMetaData::groupId() const { return groupId_; }
302 
304 {
305  if (owner == QAbstractFileEngine::OwnerUser)
306  return userId();
307  else
308  return groupId();
309 }
310 #endif
311 
312 #ifdef Q_OS_SYMBIAN
314 inline QDateTime QFileSystemMetaData::modificationTime() const { return qt_symbian_TTime_To_QDateTime(modificationTime_); }
316 
318 {
319  Q_UNUSED(time);
320  return modificationTime();
321 }
322 inline uint QFileSystemMetaData::userId() const { return (uint) -2; }
323 inline uint QFileSystemMetaData::groupId() const { return (uint) -2; }
325 {
326  Q_UNUSED(owner);
327  return (uint) -2;
328 }
329 #endif
330 
331 #if defined(Q_OS_WIN)
332 inline uint QFileSystemMetaData::userId() const { return (uint) -2; }
333 inline uint QFileSystemMetaData::groupId() const { return (uint) -2; }
335 {
336  if (owner == QAbstractFileEngine::OwnerUser)
337  return userId();
338  else
339  return groupId();
340 }
341 
342 inline void QFileSystemMetaData::fillFromFileAttribute(DWORD fileAttribute,bool isDriveRoot)
343 {
344  fileAttribute_ = fileAttribute;
345  // Ignore the hidden attribute for drives.
346  if (!isDriveRoot && (fileAttribute_ & FILE_ATTRIBUTE_HIDDEN))
348  entryFlags |= ((fileAttribute & FILE_ATTRIBUTE_DIRECTORY) ? DirectoryType: FileType);
351 }
352 
353 inline void QFileSystemMetaData::fillFromFindData(WIN32_FIND_DATA &findData, bool setLinkType, bool isDriveRoot)
354 {
355  fillFromFileAttribute(findData.dwFileAttributes, isDriveRoot);
356  creationTime_ = findData.ftCreationTime;
357  lastAccessTime_ = findData.ftLastAccessTime;
358  lastWriteTime_ = findData.ftLastWriteTime;
359  if (fileAttribute_ & FILE_ATTRIBUTE_DIRECTORY) {
360  size_ = 0;
361  } else {
362  size_ = findData.nFileSizeHigh;
363  size_ <<= 32;
364  size_ += findData.nFileSizeLow;
365  }
367  if (setLinkType) {
369  entryFlags &= ~LinkType;
370 #if !defined(Q_OS_WINCE)
371  if ((fileAttribute_ & FILE_ATTRIBUTE_REPARSE_POINT)
372  && findData.dwReserved0 == IO_REPARSE_TAG_SYMLINK) {
373  entryFlags |= LinkType;
374  }
375 #endif
376 
377  }
378 }
379 
380 inline void QFileSystemMetaData::fillFromFindInfo(BY_HANDLE_FILE_INFORMATION &fileInfo)
381 {
382  fillFromFileAttribute(fileInfo.dwFileAttributes);
383  creationTime_ = fileInfo.ftCreationTime;
384  lastAccessTime_ = fileInfo.ftLastAccessTime;
385  lastWriteTime_ = fileInfo.ftLastWriteTime;
386  if (fileAttribute_ & FILE_ATTRIBUTE_DIRECTORY) {
387  size_ = 0;
388  } else {
389  size_ = fileInfo.nFileSizeHigh;
390  size_ <<= 32;
391  size_ += fileInfo.nFileSizeLow;
392  }
394 }
395 #endif
396 
398 
399 #endif // include guard
void fillFromFindInfo(BY_HANDLE_FILE_INFORMATION &fileInfo)
void fillFromFileAttribute(DWORD fileAttribute, bool isDriveRoot=false)
static mach_timebase_info_data_t info
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define Q_DECLARE_FLAGS(Flags, Enum)
The Q_DECLARE_FLAGS() macro expands to.
Definition: qglobal.h:2348
QFile::Permissions permissions() const
static QWidget * owner
QDateTime modificationTime() const
void fillFromFindData(WIN32_FIND_DATA &findData, bool setLinkType=false, bool isDriveRoot=false)
uint ownerId(QAbstractFileEngine::FileOwner owner) const
#define IO_REPARSE_TAG_SYMLINK
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
The Q_DECLARE_OPERATORS_FOR_FLAGS() macro declares global operator|() functions for Flags...
Definition: qglobal.h:2355
unsigned long time_t
unsigned int uint
Definition: qglobal.h:996
bool hasFlags(MetaDataFlags flags) const
QDateTime fileTime(QAbstractFileEngine::FileTime time) const
__int64 qint64
Definition: qglobal.h:942
FileTime
These are used by the fileTime() function.
The QDateTime class provides date and time functions.
Definition: qdatetime.h:216
void clearFlags(MetaDataFlags flags=AllMetaDataFlags)
static QDateTime fromTime_t(uint secsSince1Jan1970UTC)
Returns a datetime whose date and time are the number of seconds that have passed since 1970-01-01T00...
Definition: qdatetime.cpp:3369
MetaDataFlags missingFlags(MetaDataFlags flags)
QDateTime creationTime() const
#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
void fillFromDirEnt(const QT_DIRENT &statBuffer)
void fillFromStatBuf(const QT_STATBUF &statBuffer)