| Tim Windelschmidt | 6d33a43 | 2025-02-04 14:34:25 +0100 | [diff] [blame] | 1 | // Copyright The Monogon Project Authors. |
| Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 2 | // SPDX-License-Identifier: Apache-2.0 |
| Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 3 | |
| 4 | package erofs |
| 5 | |
| Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame] | 6 | // This file contains definitions coming from the in-Kernel implementation of |
| 7 | // the EROFS filesystem. All definitions come from @linux//fs/erofs:erofs_fs.h |
| 8 | // unless stated otherwise. |
| Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 9 | |
| Serge Bazanski | 216fe7b | 2021-05-21 18:36:16 +0200 | [diff] [blame] | 10 | // Magic contains the 4 magic bytes starting at position 1024 identifying an |
| 11 | // EROFS filesystem. Defined in @linux//include/uapi/linux/magic.h |
| 12 | // EROFS_SUPER_MAGIC_V1 |
| Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame] | 13 | var Magic = [4]byte{0xe2, 0xe1, 0xf5, 0xe0} |
| 14 | |
| 15 | const blockSizeBits = 12 |
| 16 | const BlockSize = 1 << blockSizeBits |
| 17 | |
| 18 | // Defined in @linux//include/linux:fs_types.h starting at FT_UNKNOWN |
| 19 | const ( |
| 20 | fileTypeUnknown = iota |
| 21 | fileTypeRegularFile |
| 22 | fileTypeDirectory |
| 23 | fileTypeCharacterDevice |
| 24 | fileTypeBlockDevice |
| 25 | fileTypeFIFO |
| 26 | fileTypeSocket |
| 27 | fileTypeSymbolicLink |
| 28 | ) |
| 29 | |
| 30 | // Anonymous enum starting at EROFS_INODE_FLAT_PLAIN |
| 31 | const ( |
| 32 | inodeFlatPlain = 0 |
| 33 | inodeFlatCompressionLegacy = 1 |
| 34 | inodeFlatInline = 2 |
| 35 | inodeFlatCompression = 3 |
| 36 | ) |
| 37 | |
| 38 | // struct erofs_dirent |
| 39 | type directoryEntryRaw struct { |
| 40 | NodeNumber uint64 |
| 41 | NameStartOffset uint16 |
| 42 | FileType uint8 |
| 43 | Reserved uint8 |
| 44 | } |
| 45 | |
| 46 | // struct erofs_super_block |
| 47 | type superblock struct { |
| 48 | Magic [4]byte |
| 49 | Checksum uint32 |
| 50 | FeatureCompat uint32 |
| 51 | BlockSizeBits uint8 |
| 52 | Reserved0 uint8 |
| 53 | RootNodeNumber uint16 |
| 54 | TotalInodes uint64 |
| 55 | BuildTimeSeconds uint64 |
| 56 | BuildTimeNanoseconds uint32 |
| 57 | Blocks uint32 |
| 58 | MetaStartAddr uint32 |
| 59 | SharedXattrStartAddr uint32 |
| 60 | UUID [16]byte |
| 61 | VolumeName [16]byte |
| 62 | FeaturesIncompatible uint32 |
| 63 | Reserved1 [44]byte |
| 64 | } |
| 65 | |
| 66 | // struct erofs_inode_compact |
| 67 | type inodeCompact struct { |
| 68 | Format uint16 |
| 69 | XattrCount uint16 |
| 70 | Mode uint16 |
| 71 | HardlinkCount uint16 |
| 72 | Size uint32 |
| 73 | Reserved0 uint32 |
| 74 | Union uint32 |
| 75 | InodeNumCompat uint32 |
| 76 | UID uint16 |
| 77 | GID uint16 |
| 78 | Reserved1 uint32 |
| 79 | } |
| 80 | |
| 81 | // Anonymous enum starting at Z_EROFS_VLE_CLUSTER_TYPE_PLAIN |
| 82 | const ( |
| 83 | vleClusterTypePlain = iota << 12 |
| 84 | vleClusterTypeHead |
| 85 | vleClusterTypeNonhead |
| 86 | ) |