| 50 | } |
| 51 | |
| 52 | bool IsEroFS(const fextl::string& Filename) { |
| 53 | // v1 of EroFS has a 128byte header |
| 54 | // This lives within a fixed offset inside of the first superblock of the file |
| 55 | // Each superblock is 4096bytes |
| 56 | // |
| 57 | // We only care about the uint32_t at the start of this offset which is the cookie |
| 58 | struct EroFSHeader { |
| 59 | uint32_t Magic; |
| 60 | // Additional data after this if necessary in the future. |
| 61 | }; |
| 62 | |
| 63 | constexpr size_t HEADER_OFFSET = 1024; |
| 64 | constexpr uint32_t COOKIE_MAGIC_V1 = 0xE0F5E1E2; |
| 65 | |
| 66 | EroFSHeader Header {}; |
| 67 | int fd = open(Filename.c_str(), O_RDONLY | O_CLOEXEC); |
| 68 | if (fd == -1) { |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | if (pread(fd, reinterpret_cast<char*>(&Header), sizeof(EroFSHeader), HEADER_OFFSET) != sizeof(EroFSHeader)) { |
| 73 | close(fd); |
| 74 | return false; |
| 75 | } |
| 76 | |
| 77 | close(fd); |
| 78 | |
| 79 | return Header.Magic == COOKIE_MAGIC_V1; |
| 80 | } |
| 81 | } // namespace FEX::FormatCheck |
no test coverage detected