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