File indexing completed on 2024-04-28 05:45:44
0001 /* 0002 SPDX-FileCopyrightText: 2017-2020 Andrius Štikonas <andrius@stikonas.eu> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #ifndef KPMCORE_FSTAB_H 0008 #define KPMCORE_FSTAB_H 0009 0010 #include "util/libpartitionmanagerexport.h" 0011 0012 #include <memory> 0013 0014 #include <QList> 0015 #include <QString> 0016 0017 struct FstabEntryPrivate; 0018 0019 /** Base class for fstab handling. 0020 0021 FstabEntry stores a single line of /etc/fstab file which can be a comment 0022 0023 @author Andrius Štikonas <andrius@stikonas.eu> 0024 */ 0025 0026 class LIBKPMCORE_EXPORT FstabEntry 0027 { 0028 public: 0029 enum class Type { deviceNode, uuid, label, partlabel, partuuid, comment, other }; 0030 0031 FstabEntry(const QString& fsSpec, const QString& mountPoint, const QString& type, const QString& options, int dumpFreq = 0, int passNumber = 0, const QString& comment = QString()); 0032 0033 /** 0034 * @return the fs_spec field of fstab entry 0035 */ 0036 const QString& fsSpec() const; 0037 0038 /** 0039 * @return the device node corresponding to fs_spec entry 0040 */ 0041 const QString& deviceNode() const; 0042 0043 /** 0044 * @return the mount point (target) for the file system 0045 */ 0046 const QString& mountPoint() const; 0047 0048 /** 0049 * @return the type of the file system 0050 */ 0051 const QString& type() const; 0052 0053 /** 0054 * @return the mount options associated with the file system 0055 */ 0056 const QStringList& options() const; 0057 0058 /** 0059 * @return the mount options associated with the file system 0060 */ 0061 const QString optionsString() const; 0062 0063 /** 0064 * @return the fs_freq field of fstab entry 0065 */ 0066 int dumpFreq() const; 0067 0068 /** 0069 * @return the fs_passno field of fstab entry 0070 */ 0071 int passNumber() const; 0072 0073 /** 0074 * @return commented part of the line in fstab file 0075 */ 0076 const QString& comment() const; 0077 0078 /** 0079 * @return the type of fstab entry, e.g. device node or UUID or comment only 0080 */ 0081 Type entryType() const; 0082 0083 /** 0084 * @param s the new value for the fs_spec field of fstab entry 0085 */ 0086 void setFsSpec(const QString& s); 0087 0088 /** 0089 * @param s the new value for the mount point 0090 */ 0091 void setMountPoint(const QString& s); 0092 0093 /** 0094 * @param s the new list with the mount options 0095 */ 0096 void setOptions(const QStringList& s); 0097 0098 /** 0099 * @param s the new value for the dump frequency 0100 */ 0101 void setDumpFreq(int s); 0102 0103 /** 0104 * @param s the new value for the pass number 0105 */ 0106 void setPassNumber(int s); 0107 0108 private: 0109 std::shared_ptr<FstabEntryPrivate> d; 0110 }; 0111 0112 typedef QList<FstabEntry> FstabEntryList; 0113 0114 QString escapeSpaces(const QString& mountPoint); 0115 QString unescapeSpaces(const QString& mountPoint); 0116 0117 LIBKPMCORE_EXPORT FstabEntryList readFstabEntries(const QString& fstabPath = QStringLiteral("/etc/fstab")); 0118 LIBKPMCORE_EXPORT QStringList possibleMountPoints(const QString& deviceNode, const QString& fstabPath = QStringLiteral("/etc/fstab")); 0119 LIBKPMCORE_EXPORT QString generateFstab(const FstabEntryList& fstabEntries); 0120 LIBKPMCORE_EXPORT bool writeMountpoints(const FstabEntryList& fstabEntries); 0121 0122 #endif