diff options
| -rw-r--r-- | include/fs/extfs.hpp | 25 | ||||
| -rw-r--r-- | src/extsh.cpp | 8 | ||||
| -rw-r--r-- | src/fs/extfs.cpp | 10 |
3 files changed, 41 insertions, 2 deletions
diff --git a/include/fs/extfs.hpp b/include/fs/extfs.hpp index 6430fe2..fb8f044 100644 --- a/include/fs/extfs.hpp +++ b/include/fs/extfs.hpp @@ -52,6 +52,31 @@ namespace fs */ bool open() const; + /** + * @brief Get the label of the file system + * + * The ext2/3/4 file systems allow the use of a label for human readable identification of a file system. Because they are + * user configurable, there are no guarantees on whether or not the label is unique. Thus, a file system should never be + * identified solely by its label. + * + * @return A #std::string containing the file system label. The string might be empty if no label is set. + * + * @since 1.0 + */ + std::string label() const; + + /** + * @brief Check if the file system has a label + * + * ext2/3/4 file systems may or may not have a label. If a label is present, it has a maximum length of 15 character in + * ISO-Latin-1 encoding. + * + * @return @p true, iff. the file system has a @p non-null label configured, @p false otherwise + * + * @since 1.0 + */ + bool has_label() const; + private: std::fstream m_stream{}; detail::extfs_superblock m_primarySuperblock{}; diff --git a/src/extsh.cpp b/src/extsh.cpp index 87df7d3..07a7d47 100644 --- a/src/extsh.cpp +++ b/src/extsh.cpp @@ -10,10 +10,14 @@ int main(int argc, char const * argv[]) if(disk.open()) { - std::clog << "[EXT2] Successfully opened ext*fs at: '" << path << "'\n"; + std::clog << "[EXTSH] Successfully opened ext*fs at: '" << path << "'\n"; + if(disk.has_label()) + { + std::clog << "[EXTSH] The filesystem is labeled '" << disk.label() << "'\n"; + } } else { - std::clog << "[EXT2] Failed to open ext*fs at: '" << path << "'\n"; + std::clog << "[EXTSH] Failed to open ext*fs at: '" << path << "'\n"; } } diff --git a/src/fs/extfs.cpp b/src/fs/extfs.cpp index 55cffd8..671124d 100644 --- a/src/fs/extfs.cpp +++ b/src/fs/extfs.cpp @@ -32,4 +32,14 @@ namespace fs return m_stream && m_primarySuperblock.magic_number == kExtfsMagic; } + std::string extfs::label() const + { + return std::string{m_primarySuperblock.label.cbegin(), m_primarySuperblock.label.cend()}; + } + + bool extfs::has_label() const + { + return m_primarySuperblock.label[0]; + } + } |
