1 | /* |
2 | This file is part of the KDE libraries |
3 | Copyright (c) 2003 Waldo Bastian <bastian@kde.org> |
4 | 2007 David Faure <faure@kde.org> |
5 | |
6 | This library is free software; you can redistribute it and/or |
7 | modify it under the terms of the GNU Library General Public |
8 | License version 2 as published by the Free Software Foundation. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | |
21 | #ifndef KMOUNTPOINT_H |
22 | #define KMOUNTPOINT_H |
23 | |
24 | #include <kdecore_export.h> |
25 | #include <ksharedptr.h> |
26 | |
27 | #include <QtCore/QStringList> |
28 | |
29 | /** |
30 | * The KMountPoint class provides information about mounted and unmounted disks. |
31 | * It provides a system independent interface to fstab. |
32 | * |
33 | * @author Waldo Bastian <bastian@kde.org> |
34 | */ |
35 | class KDECORE_EXPORT KMountPoint : public KShared |
36 | { |
37 | public: |
38 | typedef KSharedPtr<KMountPoint> Ptr; |
39 | /** |
40 | * List of mount points. |
41 | */ |
42 | class KDECORE_EXPORT List : public QList<Ptr> |
43 | { |
44 | public: |
45 | List(); |
46 | /** |
47 | * Find the mountpoint on which resides @p path |
48 | * For instance if /home is a separate partition, findByPath("/home/user/blah") |
49 | * will return /home |
50 | * @param path the path to check |
51 | * @return the mount point of the given file |
52 | */ |
53 | Ptr findByPath(const QString& path) const; |
54 | |
55 | /** |
56 | * Returns the mount point associated with @p device, |
57 | * i.e. the one where mountedFrom() == @p device |
58 | * (after symlink resolution). |
59 | * @return the mountpoint, or 0 if this device doesn't exist or isn't mounted |
60 | */ |
61 | Ptr findByDevice(const QString& device) const; |
62 | }; |
63 | public: |
64 | /** |
65 | * Flags that specify which additional details should be fetched for each mountpoint. |
66 | * BasicInfoNeeded: only the basic details: mountedFrom, mountPoint, mountType. |
67 | * NeedMountOptions: also fetch the options used when mounting, see mountOptions. |
68 | * NeedRealDeviceName: also fetch the device name (with symlinks resolved), see realDeviceName. |
69 | */ |
70 | enum DetailsNeededFlag { BasicInfoNeeded = 0, NeedMountOptions = 1, NeedRealDeviceName = 2 }; |
71 | Q_DECLARE_FLAGS(DetailsNeededFlags, DetailsNeededFlag) |
72 | |
73 | /** |
74 | * This function gives a list of all possible mountpoints. (fstab) |
75 | * @param infoNeeded Flags that specify which additional information |
76 | * should be fetched. |
77 | */ |
78 | static List possibleMountPoints(DetailsNeededFlags infoNeeded = BasicInfoNeeded); |
79 | |
80 | /** |
81 | * This function gives a list of all currently used mountpoints. (mtab) |
82 | * @param infoNeeded Flags that specify which additional information |
83 | * should be fetched. |
84 | */ |
85 | static List currentMountPoints(DetailsNeededFlags infoNeeded = BasicInfoNeeded); |
86 | |
87 | /** |
88 | * Where this filesystem gets mounted from. |
89 | * This can refer to a device, a remote server or something else. |
90 | */ |
91 | QString mountedFrom() const; |
92 | |
93 | /** |
94 | * Canonical name of the device where the filesystem got mounted from. |
95 | * (Or empty, if not a device) |
96 | * Only available when the NeedRealDeviceName flag was set. |
97 | */ |
98 | QString realDeviceName() const; |
99 | |
100 | /** |
101 | * Path where the filesystem is mounted or can be mounted. |
102 | */ |
103 | QString mountPoint() const; |
104 | |
105 | /** |
106 | * Type of filesystem |
107 | */ |
108 | QString mountType() const; |
109 | |
110 | /** |
111 | * Options used to mount the filesystem. |
112 | * Only available when the NeedMountOptions flag was set. |
113 | */ |
114 | QStringList mountOptions() const; |
115 | |
116 | /** |
117 | * Checks if the filesystem that is probably slow (network mounts). |
118 | * @return true if the filesystem is probably slow |
119 | */ |
120 | bool probablySlow() const; |
121 | |
122 | enum FileSystemFlag { SupportsChmod, SupportsChown, SupportsUTime, |
123 | SupportsSymlinks, CaseInsensitive }; |
124 | /** |
125 | * Checks the capabilities of the filesystem. |
126 | * @param flag the flag to check |
127 | * @return true if the filesystem has that flag, false if not |
128 | * |
129 | * The availables flags are: |
130 | * @li SupportsChmod: returns true if the filesystem supports chmod |
131 | * (e.g. msdos filesystems return false) |
132 | * @li SupportsChown: returns true if the filesystem supports chown |
133 | * (e.g. msdos filesystems return false) |
134 | * @li SupportsUtime: returns true if the filesystems supports utime |
135 | * (e.g. msdos filesystems return false) |
136 | * @li SupportsSymlinks: returns true if the filesystems supports symlinks |
137 | * (e.g. msdos filesystems return false) |
138 | * @li CaseInsensitive: returns true if the filesystem treats |
139 | * "foo" and "FOO" as being the same file (true for msdos systems) |
140 | * |
141 | */ |
142 | bool testFileSystemFlag(FileSystemFlag flag) const; |
143 | |
144 | /** |
145 | * Destructor |
146 | */ |
147 | ~KMountPoint(); |
148 | |
149 | private: |
150 | /** |
151 | * Constructor |
152 | */ |
153 | KMountPoint(); |
154 | |
155 | class Private; |
156 | Private * const d; |
157 | }; |
158 | |
159 | Q_DECLARE_OPERATORS_FOR_FLAGS(KMountPoint::DetailsNeededFlags) |
160 | |
161 | #endif // KMOUNTPOINT_H |
162 | |
163 | |