| 171 | |
| 172 | |
| 173 | static std::unique_ptr<std::string> getExternalErrorBehaviour(const MountInfo& mount) { |
| 174 | const auto& fs = mount.getFsType(); |
| 175 | if (fs != "ext2" && fs != "ext3" && fs != "ext4") |
| 176 | return nullptr; |
| 177 | std::ifstream mntsrc(mount.getMountSource(), std::ios::binary); |
| 178 | if (!mntsrc || !mntsrc.is_open()) |
| 179 | return nullptr; |
| 180 | uint16_t magic; |
| 181 | mntsrc.seekg(EXT_SUPERBLOCK_OFFSET + EXT_MAGIC_OFFSET, std::ios::beg); |
| 182 | mntsrc.read(reinterpret_cast<char *>(&magic), sizeof(magic)); |
| 183 | if (!mntsrc || mntsrc.gcount() != sizeof(magic)) |
| 184 | return nullptr; |
| 185 | magic = le16toh(magic); |
| 186 | if (magic != EXT_MAGIC) |
| 187 | return nullptr; |
| 188 | uint16_t errors; |
| 189 | mntsrc.seekg(EXT_SUPERBLOCK_OFFSET + EXT_ERRORS_OFFSET, std::ios::beg); |
| 190 | mntsrc.read(reinterpret_cast<char *>(&errors), sizeof(errors)); |
| 191 | if (!mntsrc || mntsrc.gcount() != sizeof(errors)) |
| 192 | return nullptr; |
| 193 | errors = le16toh(errors); |
| 194 | switch (errors) |
| 195 | { |
| 196 | case 1: |
| 197 | return std::make_unique<std::string>("continue"); |
| 198 | case 2: |
| 199 | return std::make_unique<std::string>("remount-ro"); |
| 200 | case 3: |
| 201 | return std::make_unique<std::string>("panic"); |
| 202 | default: |
| 203 | return nullptr; |
| 204 | } |
| 205 | return nullptr; |
| 206 | } |
| 207 | |
| 208 | static void doumount(const std::string& mntPnt); |
| 209 | |