Line data Source code
1 : /* 2 : Copyright 2018-2024, Barcelona Supercomputing Center (BSC), Spain 3 : Copyright 2015-2024, Johannes Gutenberg Universitaet Mainz, Germany 4 : 5 : This software was partially supported by the 6 : EC H2020 funded project NEXTGenIO (Project ID: 671951, www.nextgenio.eu). 7 : 8 : This software was partially supported by the 9 : ADA-FS project under the SPPEXA project funded by the DFG. 10 : 11 : This file is part of GekkoFS. 12 : 13 : GekkoFS is free software: you can redistribute it and/or modify 14 : it under the terms of the GNU General Public License as published by 15 : the Free Software Foundation, either version 3 of the License, or 16 : (at your option) any later version. 17 : 18 : GekkoFS is distributed in the hope that it will be useful, 19 : but WITHOUT ANY WARRANTY; without even the implied warranty of 20 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 : GNU General Public License for more details. 22 : 23 : You should have received a copy of the GNU General Public License 24 : along with GekkoFS. If not, see <https://www.gnu.org/licenses/>. 25 : 26 : SPDX-License-Identifier: GPL-3.0-or-later 27 : */ 28 : 29 : #ifndef FS_METADATA_H 30 : #define FS_METADATA_H 31 : #pragma once 32 : 33 : 34 : #include <config.hpp> 35 : #include <sys/types.h> 36 : #include <sys/stat.h> 37 : #include <string> 38 : #include <cstdint> 39 : 40 : namespace gkfs::metadata { 41 : 42 : constexpr mode_t LINK_MODE = ((S_IRWXU | S_IRWXG | S_IRWXO) | S_IFLNK); 43 : 44 : uint16_t 45 : gen_unique_id(const std::string& path); 46 : 47 8512 : class Metadata { 48 : private: 49 : time_t atime_{}; // access time. gets updated on file access unless mounted 50 : // with noatime 51 : time_t mtime_{}; // modify time. gets updated when file content is modified. 52 : time_t ctime_{}; // change time. gets updated when the file attributes are 53 : // changed AND when file content is modified. 54 : mode_t mode_{}; 55 : nlink_t link_count_{}; // number of names for this inode (hardlinks) 56 : size_t size_{}; // size_ in bytes, might be computed instead of stored 57 : blkcnt_t blocks_{}; // allocated file system blocks_ 58 : #ifdef HAS_SYMLINKS 59 : std::string target_path_; // For links this is the path of the target file 60 : #ifdef HAS_RENAME 61 : std::string rename_path_; // In some cases fd is maintained so we need the 62 : // renamed path 63 : #endif 64 : #endif 65 : 66 : void 67 : init_time(); 68 : 69 : public: 70 1166 : Metadata() = default; 71 : 72 : explicit Metadata(mode_t mode); 73 : 74 : #ifdef HAS_SYMLINKS 75 : 76 : Metadata(mode_t mode, const std::string& target_path); 77 : 78 : #endif 79 : 80 : // Construct from a binary representation of the object 81 : explicit Metadata(const std::string& binary_str); 82 : 83 : std::string 84 : serialize() const; 85 : 86 : // currently unused 87 : void 88 : update_atime_now(); 89 : 90 : void 91 : update_mtime_now(); 92 : 93 : // Getter and Setter 94 : time_t 95 : atime() const; 96 : 97 : void 98 : atime(time_t atime_); 99 : 100 : time_t 101 : mtime() const; 102 : 103 : void 104 : mtime(time_t mtime_); 105 : 106 : time_t 107 : ctime() const; 108 : 109 : void 110 : ctime(time_t ctime_); 111 : 112 : mode_t 113 : mode() const; 114 : 115 : void 116 : mode(mode_t mode_); 117 : 118 : nlink_t 119 : link_count() const; 120 : 121 : void 122 : link_count(nlink_t link_count_); 123 : 124 : size_t 125 : size() const; 126 : 127 : void 128 : size(size_t size_); 129 : 130 : blkcnt_t 131 : blocks() const; 132 : 133 : void 134 : blocks(blkcnt_t blocks_); 135 : 136 : #ifdef HAS_SYMLINKS 137 : 138 : std::string 139 : target_path() const; 140 : 141 : void 142 : target_path(const std::string& target_path); 143 : 144 : bool 145 : is_link() const; 146 : 147 : #ifdef HAS_RENAME 148 : std::string 149 : rename_path() const; 150 : 151 : void 152 : rename_path(const std::string& rename_path); 153 : #endif // HAS_RENAME 154 : 155 : #endif // HAS_SYMLINKS 156 : }; 157 : 158 : } // namespace gkfs::metadata 159 : 160 : 161 : #endif // FS_METADATA_H