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