1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2003 Waldo Bastian <bastian@kde.org>
4 SPDX-FileCopyrightText: 2007 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-only
7*/
8
9#ifndef KMOUNTPOINT_H
10#define KMOUNTPOINT_H
11
12#include "kiocore_export.h"
13
14#include <QExplicitlySharedDataPointer>
15#include <QStringList>
16
17#include <memory>
18#include <sys/types.h> // dev_t among other definitions
19
20class KMountPointPrivate;
21
22/*!
23 * \class KMountPoint
24 * \inmodule KIOCore
25 *
26 * \brief The KMountPoint class provides information about mounted and unmounted disks.
27 *
28 * It provides a system independent interface to fstab.
29 */
30class KIOCORE_EXPORT KMountPoint : public QSharedData
31{
32public:
33 using Ptr = QExplicitlySharedDataPointer<KMountPoint>;
34
35 /*!
36 * List of mount points.
37 * \inmodule KIOCore
38 */
39 class KIOCORE_EXPORT List : public QList<Ptr>
40 {
41 public:
42 List();
43 /*!
44 * Find the mountpoint on which resides \a path
45 * For instance if /home is a separate partition, findByPath("/home/user/blah")
46 * will return /home
47 *
48 * \a path the path to check
49 *
50 * Returns the mount point of the given file
51 */
52 Ptr findByPath(const QString &path) const;
53
54 /*!
55 * Returns the mount point associated with \a device,
56 * i.e. the one where mountedFrom() == \a device
57 * (after symlink resolution).
58 *
59 * Returns the mountpoint, or \c nullptr if this device doesn't exist or isn't mounted
60 */
61 Ptr findByDevice(const QString &device) const;
62 };
63
64public:
65 /*!
66 * Flags that specify which additional details should be fetched for each mountpoint.
67 *
68 * \value BasicInfoNeeded Only the basic details: mountedFrom, mountPoint, mountType.
69 * \value NeedMountOptions Also fetch the options used when mounting, see KMountPoint::mountOptions().
70 * \value NeedRealDeviceName Also fetch the device name (with symlinks resolved), see KMountPoint::realDeviceName().
71 */
72 enum DetailsNeededFlag {
73 BasicInfoNeeded = 0,
74 NeedMountOptions = 1,
75 NeedRealDeviceName = 2,
76 };
77 Q_DECLARE_FLAGS(DetailsNeededFlags, DetailsNeededFlag)
78
79 /*!
80 * This function gives a list of all possible mountpoints. (fstab)
81 *
82 * \a infoNeeded Flags that specify which additional information
83 * should be fetched.
84 */
85 static List possibleMountPoints(DetailsNeededFlags infoNeeded = BasicInfoNeeded);
86
87 /*!
88 * Returns a list of all current mountpoints.
89 *
90 * \a infoNeeded Flags that specify which additional information
91 * should be fetched.
92 *
93 * \note This method will return an empty list on Android
94 */
95 static List currentMountPoints(DetailsNeededFlags infoNeeded = BasicInfoNeeded);
96
97 /*!
98 * Where this filesystem gets mounted from.
99 * This can refer to a device, a remote server or something else.
100 */
101 QString mountedFrom() const;
102
103 /*!
104 * Returns \c true if this mount point represents a network filesystem (e.g.\ NFS,
105 * CIFS, etc.), otherwise returns \c false.
106 *
107 * \since 5.86
108 */
109 bool isOnNetwork() const;
110
111 /*!
112 * Returns the device ID (dev_t, major, minor) of this mount point. This
113 * ID is unique per device (including network mounts).
114 *
115 * \since 5.86
116 */
117 dev_t deviceId() const;
118
119 /*!
120 * Canonical name of the device where the filesystem got mounted from.
121 * (Or empty, if not a device)
122 * Only available when the NeedRealDeviceName flag was set.
123 */
124 QString realDeviceName() const;
125
126 /*!
127 * Path where the filesystem is mounted (if you used currentMountPoints()),
128 * or can be mounted (if you used possibleMountPoints()).
129 */
130 QString mountPoint() const;
131
132 /*!
133 * Type of filesystem
134 */
135 QString mountType() const;
136
137 /*!
138 * Options used to mount the filesystem.
139 * Only available if the NeedMountOptions flag was set.
140 */
141 QStringList mountOptions() const;
142
143 /*!
144 * Returns \c true if the filesystem is "probably" slow, e.g. a network mount,
145 * \c false otherwise.
146 */
147 bool probablySlow() const;
148
149 /*!
150 * \value SupportsChmod
151 * \value SupportsChown
152 * \value SupportsUTime
153 * \value SupportsSymlinks
154 * \value CaseInsensitive
155 */
156 enum FileSystemFlag {
157 SupportsChmod,
158 SupportsChown,
159 SupportsUTime,
160 SupportsSymlinks,
161 CaseInsensitive,
162 };
163
164 /*!
165 * Checks the capabilities of the filesystem.
166 *
167 * \a flag the flag to check
168 *
169 * Returns \c true if the filesystem has that flag, false if not
170 *
171 * The available flags are:
172 * \list
173 * \li SupportsChmod: returns true if the filesystem supports chmod
174 * (e.g. msdos filesystems return false)
175 * \li SupportsChown: returns true if the filesystem supports chown
176 * (e.g. msdos filesystems return false)
177 * \li SupportsUtime: returns true if the filesystems supports utime
178 * (e.g. msdos filesystems return false)
179 * \li SupportsSymlinks: returns true if the filesystems supports symlinks
180 * (e.g. msdos filesystems return false)
181 * \li CaseInsensitive: returns true if the filesystem treats
182 * "foo" and "FOO" as being the same file (true for msdos filesystems)
183 * \endlist
184 */
185 bool testFileSystemFlag(FileSystemFlag flag) const;
186
187 ~KMountPoint();
188
189private:
190 KIOCORE_NO_EXPORT KMountPoint();
191
192 friend KIOCORE_EXPORT QDebug operator<<(QDebug debug, const Ptr &mp);
193
194 friend KMountPointPrivate;
195 std::unique_ptr<KMountPointPrivate> d;
196};
197
198KIOCORE_EXPORT QDebug operator<<(QDebug debug, const KMountPoint::Ptr &mp);
199
200Q_DECLARE_OPERATORS_FOR_FLAGS(KMountPoint::DetailsNeededFlags)
201
202#endif // KMOUNTPOINT_H
203

source code of kio/src/core/kmountpoint.h