Run `unsquashfs -s` and parse out compression + on-disk byte total.
(path: Path)
| 127 | |
| 128 | |
| 129 | def squashfs_metadata(path: Path) -> dict | None: |
| 130 | """Run `unsquashfs -s` and parse out compression + on-disk byte total.""" |
| 131 | try: |
| 132 | out = subprocess.check_output( |
| 133 | ["unsquashfs", "-s", str(path)], text=True, stderr=subprocess.STDOUT |
| 134 | ) |
| 135 | except (subprocess.CalledProcessError, FileNotFoundError) as e: |
| 136 | return {"error": str(e)} |
| 137 | |
| 138 | info: dict = {"compressed_bytes": path.stat().st_size} |
| 139 | for line in out.splitlines(): |
| 140 | m = re.match(r"\s*Compression\s+(\S+)", line) |
| 141 | if m: |
| 142 | info["compression"] = m.group(1) |
| 143 | m = re.match(r"\s*Block size\s+(\d+)", line) |
| 144 | if m: |
| 145 | info["block_size"] = int(m.group(1)) |
| 146 | m = re.match(r"\s*Number of inodes\s+(\d+)", line) |
| 147 | if m: |
| 148 | info["inode_count"] = int(m.group(1)) |
| 149 | return info |
| 150 | |
| 151 | |
| 152 | def kernel_caps(flash_mb: str, vendor: str, has_ubi: bool) -> dict[str, int]: |