MCPcopy Create free account
hub / github.com/MhmRdd/NoHello / getExternalErrorBehaviour

Function getExternalErrorBehaviour

module/src/main/cpp/nohello.cpp:173–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

171
172
173static 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
208static void doumount(const std::string& mntPnt);
209

Callers 1

remountFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected