blob: 85898bf6c4e5eb2f9d4472252d98a0c8f46da196 [file] [log] [blame]
Lorenz Brun378a4452021-01-26 13:47:41 +01001// 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
17package erofs
18
Serge Bazanski216fe7b2021-05-21 18:36:16 +020019// 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 Brun378a4452021-01-26 13:47:41 +010022
Serge Bazanski216fe7b2021-05-21 18:36:16 +020023// 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 Brun378a4452021-01-26 13:47:41 +010026var Magic = [4]byte{0xe2, 0xe1, 0xf5, 0xe0}
27
28const blockSizeBits = 12
29const BlockSize = 1 << blockSizeBits
30
31// Defined in @linux//include/linux:fs_types.h starting at FT_UNKNOWN
32const (
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
44const (
45 inodeFlatPlain = 0
46 inodeFlatCompressionLegacy = 1
47 inodeFlatInline = 2
48 inodeFlatCompression = 3
49)
50
51// struct erofs_dirent
52type directoryEntryRaw struct {
53 NodeNumber uint64
54 NameStartOffset uint16
55 FileType uint8
56 Reserved uint8
57}
58
59// struct erofs_super_block
60type 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
80type 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
95const (
96 vleClusterTypePlain = iota << 12
97 vleClusterTypeHead
98 vleClusterTypeNonhead
99)