Lorenz Brun | 378a445 | 2021-01-26 13:47:41 +0100 | [diff] [blame^] | 1 | // Copyright 2020 The Monogon Project Authors. |
| 2 | // |
| 3 | // SPDX-License-Identifier: Apache-2.0 |
| 4 | // |
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | // you may not use this file except in compliance with the License. |
| 7 | // You may obtain a copy of the License at |
| 8 | // |
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | // |
| 11 | // Unless required by applicable law or agreed to in writing, software |
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | // See the License for the specific language governing permissions and |
| 15 | // limitations under the License. |
| 16 | |
| 17 | package erofs |
| 18 | |
| 19 | // This file contains definitions coming from the in-Kernel implementation of the EROFS filesystem. |
| 20 | // All definitions come from @linux//fs/erofs:erofs_fs.h unless stated otherwise. |
| 21 | |
| 22 | // Magic contains the 4 magic bytes starting at position 1024 identifying an EROFS filesystem. |
| 23 | // Defined in @linux//include/uapi/linux/magic.h EROFS_SUPER_MAGIC_V1 |
| 24 | var Magic = [4]byte{0xe2, 0xe1, 0xf5, 0xe0} |
| 25 | |
| 26 | const blockSizeBits = 12 |
| 27 | const BlockSize = 1 << blockSizeBits |
| 28 | |
| 29 | // Defined in @linux//include/linux:fs_types.h starting at FT_UNKNOWN |
| 30 | const ( |
| 31 | fileTypeUnknown = iota |
| 32 | fileTypeRegularFile |
| 33 | fileTypeDirectory |
| 34 | fileTypeCharacterDevice |
| 35 | fileTypeBlockDevice |
| 36 | fileTypeFIFO |
| 37 | fileTypeSocket |
| 38 | fileTypeSymbolicLink |
| 39 | ) |
| 40 | |
| 41 | // Anonymous enum starting at EROFS_INODE_FLAT_PLAIN |
| 42 | const ( |
| 43 | inodeFlatPlain = 0 |
| 44 | inodeFlatCompressionLegacy = 1 |
| 45 | inodeFlatInline = 2 |
| 46 | inodeFlatCompression = 3 |
| 47 | ) |
| 48 | |
| 49 | // struct erofs_dirent |
| 50 | type directoryEntryRaw struct { |
| 51 | NodeNumber uint64 |
| 52 | NameStartOffset uint16 |
| 53 | FileType uint8 |
| 54 | Reserved uint8 |
| 55 | } |
| 56 | |
| 57 | // struct erofs_super_block |
| 58 | type superblock struct { |
| 59 | Magic [4]byte |
| 60 | Checksum uint32 |
| 61 | FeatureCompat uint32 |
| 62 | BlockSizeBits uint8 |
| 63 | Reserved0 uint8 |
| 64 | RootNodeNumber uint16 |
| 65 | TotalInodes uint64 |
| 66 | BuildTimeSeconds uint64 |
| 67 | BuildTimeNanoseconds uint32 |
| 68 | Blocks uint32 |
| 69 | MetaStartAddr uint32 |
| 70 | SharedXattrStartAddr uint32 |
| 71 | UUID [16]byte |
| 72 | VolumeName [16]byte |
| 73 | FeaturesIncompatible uint32 |
| 74 | Reserved1 [44]byte |
| 75 | } |
| 76 | |
| 77 | // struct erofs_inode_compact |
| 78 | type inodeCompact struct { |
| 79 | Format uint16 |
| 80 | XattrCount uint16 |
| 81 | Mode uint16 |
| 82 | HardlinkCount uint16 |
| 83 | Size uint32 |
| 84 | Reserved0 uint32 |
| 85 | Union uint32 |
| 86 | InodeNumCompat uint32 |
| 87 | UID uint16 |
| 88 | GID uint16 |
| 89 | Reserved1 uint32 |
| 90 | } |
| 91 | |
| 92 | // Anonymous enum starting at Z_EROFS_VLE_CLUSTER_TYPE_PLAIN |
| 93 | const ( |
| 94 | vleClusterTypePlain = iota << 12 |
| 95 | vleClusterTypeHead |
| 96 | vleClusterTypeNonhead |
| 97 | ) |