MCPcopy Create free account
hub / github.com/FEX-Emu/FEX / IsSquashFS

Function IsSquashFS

Source/Common/FileFormatCheck.cpp:10–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

8
9namespace FEX::FormatCheck {
10bool IsSquashFS(const fextl::string& Filename) {
11 // If it is a regular file then we need to check if it is a valid archive
12 struct SquashFSHeader {
13 uint32_t magic;
14 uint32_t inode_count;
15 uint32_t mtime;
16 uint32_t block_size;
17 uint32_t fragment_entry_count;
18 uint16_t compression_id;
19 uint16_t block_log;
20 uint16_t flags;
21 uint16_t id_count;
22 uint16_t version_major;
23 uint16_t version_minor;
24 uint64_t More[8]; // More things that don't matter to us
25 };
26
27 SquashFSHeader Header {};
28 int fd = open(Filename.c_str(), O_RDONLY | O_CLOEXEC);
29 if (fd == -1) {
30 return false;
31 }
32
33 if (pread(fd, reinterpret_cast<char*>(&Header), sizeof(SquashFSHeader), 0) != sizeof(SquashFSHeader)) {
34 close(fd);
35 return false;
36 }
37
38 close(fd);
39
40 // Make sure the cookie matches
41 if (Header.magic == 0x73717368) {
42 // Sanity check the version
43 uint32_t version = (uint32_t)Header.version_major << 16 | Header.version_minor;
44 if (version >= 0x00040000) {
45 // Everything is sane, we can add it
46 return true;
47 }
48 }
49 return false;
50}
51
52bool IsEroFS(const fextl::string& Filename) {
53 // v1 of EroFS has a 128byte header

Callers 3

UnmountRootFSFunction · 0.85
InitializeSquashFSFunction · 0.85
ReloadMethod · 0.85

Calls 1

closeFunction · 0.85

Tested by

no test coverage detected