]> Git Repo - linux.git/blob - drivers/staging/erofs/erofs_fs.h
powerpc: split compat syscall table out from native table
[linux.git] / drivers / staging / erofs / erofs_fs.h
1 /* SPDX-License-Identifier: GPL-2.0 OR Apache-2.0
2  *
3  * linux/drivers/staging/erofs/erofs_fs.h
4  *
5  * Copyright (C) 2017-2018 HUAWEI, Inc.
6  *             http://www.huawei.com/
7  * Created by Gao Xiang <[email protected]>
8  *
9  * This file is dual-licensed; you may select either the GNU General Public
10  * License version 2 or Apache License, Version 2.0. See the file COPYING
11  * in the main directory of the Linux distribution for more details.
12  */
13 #ifndef __EROFS_FS_H
14 #define __EROFS_FS_H
15
16 /* Enhanced(Extended) ROM File System */
17 #define EROFS_SUPER_MAGIC_V1    0xE0F5E1E2
18 #define EROFS_SUPER_OFFSET      1024
19
20 struct erofs_super_block {
21 /*  0 */__le32 magic;           /* in the little endian */
22 /*  4 */__le32 checksum;        /* crc32c(super_block) */
23 /*  8 */__le32 features;
24 /* 12 */__u8 blkszbits;         /* support block_size == PAGE_SIZE only */
25 /* 13 */__u8 reserved;
26
27 /* 14 */__le16 root_nid;
28 /* 16 */__le64 inos;            /* total valid ino # (== f_files - f_favail) */
29
30 /* 24 */__le64 build_time;      /* inode v1 time derivation */
31 /* 32 */__le32 build_time_nsec;
32 /* 36 */__le32 blocks;          /* used for statfs */
33 /* 40 */__le32 meta_blkaddr;
34 /* 44 */__le32 xattr_blkaddr;
35 /* 48 */__u8 uuid[16];          /* 128-bit uuid for volume */
36 /* 64 */__u8 volume_name[16];   /* volume name */
37
38 /* 80 */__u8 reserved2[48];     /* 128 bytes */
39 } __packed;
40
41 #define __EROFS_BIT(_prefix, _cur, _pre)        enum {  \
42         _prefix ## _cur ## _BIT = _prefix ## _pre ## _BIT + \
43                 _prefix ## _pre ## _BITS }
44
45 /*
46  * erofs inode data mapping:
47  * 0 - inode plain without inline data A:
48  * inode, [xattrs], ... | ... | no-holed data
49  * 1 - inode VLE compression B:
50  * inode, [xattrs], extents ... | ...
51  * 2 - inode plain with inline data C:
52  * inode, [xattrs], last_inline_data, ... | ... | no-holed data
53  * 3~7 - reserved
54  */
55 enum {
56         EROFS_INODE_LAYOUT_PLAIN,
57         EROFS_INODE_LAYOUT_COMPRESSION,
58         EROFS_INODE_LAYOUT_INLINE,
59         EROFS_INODE_LAYOUT_MAX
60 };
61 #define EROFS_I_VERSION_BITS            1
62 #define EROFS_I_DATA_MAPPING_BITS       3
63
64 #define EROFS_I_VERSION_BIT             0
65 __EROFS_BIT(EROFS_I_, DATA_MAPPING, VERSION);
66
67 struct erofs_inode_v1 {
68 /*  0 */__le16 i_advise;
69
70 /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
71 /*  2 */__le16 i_xattr_icount;
72 /*  4 */__le16 i_mode;
73 /*  6 */__le16 i_nlink;
74 /*  8 */__le32 i_size;
75 /* 12 */__le32 i_reserved;
76 /* 16 */union {
77                 /* file total compressed blocks for data mapping 1 */
78                 __le32 compressed_blocks;
79                 __le32 raw_blkaddr;
80
81                 /* for device files, used to indicate old/new device # */
82                 __le32 rdev;
83         } i_u __packed;
84 /* 20 */__le32 i_ino;           /* only used for 32-bit stat compatibility */
85 /* 24 */__le16 i_uid;
86 /* 26 */__le16 i_gid;
87 /* 28 */__le32 i_checksum;
88 } __packed;
89
90 /* 32 bytes on-disk inode */
91 #define EROFS_INODE_LAYOUT_V1   0
92 /* 64 bytes on-disk inode */
93 #define EROFS_INODE_LAYOUT_V2   1
94
95 struct erofs_inode_v2 {
96         __le16 i_advise;
97
98         /* 1 header + n-1 * 4 bytes inline xattr to keep continuity */
99         __le16 i_xattr_icount;
100         __le16 i_mode;
101         __le16 i_reserved;      /* 8 bytes */
102         __le64 i_size;          /* 16 bytes */
103         union {
104                 /* file total compressed blocks for data mapping 1 */
105                 __le32 compressed_blocks;
106                 __le32 raw_blkaddr;
107
108                 /* for device files, used to indicate old/new device # */
109                 __le32 rdev;
110         } i_u __packed;
111
112         /* only used for 32-bit stat compatibility */
113         __le32 i_ino;           /* 24 bytes */
114
115         __le32 i_uid;
116         __le32 i_gid;
117         __le64 i_ctime;         /* 32 bytes */
118         __le32 i_ctime_nsec;
119         __le32 i_nlink;
120         __u8   i_reserved2[12];
121         __le32 i_checksum;      /* 64 bytes */
122 } __packed;
123
124 #define EROFS_MAX_SHARED_XATTRS         (128)
125 /* h_shared_count between 129 ... 255 are special # */
126 #define EROFS_SHARED_XATTR_EXTENT       (255)
127
128 /*
129  * inline xattrs (n == i_xattr_icount):
130  * erofs_xattr_ibody_header(1) + (n - 1) * 4 bytes
131  *          12 bytes           /                   \
132  *                            /                     \
133  *                           /-----------------------\
134  *                           |  erofs_xattr_entries+ |
135  *                           +-----------------------+
136  * inline xattrs must starts in erofs_xattr_ibody_header,
137  * for read-only fs, no need to introduce h_refcount
138  */
139 struct erofs_xattr_ibody_header {
140         __le32 h_checksum;
141         __u8   h_shared_count;
142         __u8   h_reserved[7];
143         __le32 h_shared_xattrs[0];      /* shared xattr id array */
144 } __packed;
145
146 /* Name indexes */
147 #define EROFS_XATTR_INDEX_USER              1
148 #define EROFS_XATTR_INDEX_POSIX_ACL_ACCESS  2
149 #define EROFS_XATTR_INDEX_POSIX_ACL_DEFAULT 3
150 #define EROFS_XATTR_INDEX_TRUSTED           4
151 #define EROFS_XATTR_INDEX_LUSTRE            5
152 #define EROFS_XATTR_INDEX_SECURITY          6
153
154 /* xattr entry (for both inline & shared xattrs) */
155 struct erofs_xattr_entry {
156         __u8   e_name_len;      /* length of name */
157         __u8   e_name_index;    /* attribute name index */
158         __le16 e_value_size;    /* size of attribute value */
159         /* followed by e_name and e_value */
160         char   e_name[0];       /* attribute name */
161 } __packed;
162
163 #define ondisk_xattr_ibody_size(count)  ({\
164         u32 __count = le16_to_cpu(count); \
165         ((__count) == 0) ? 0 : \
166         sizeof(struct erofs_xattr_ibody_header) + \
167                 sizeof(__u32) * ((__count) - 1); })
168
169 #define EROFS_XATTR_ALIGN(size) round_up(size, sizeof(struct erofs_xattr_entry))
170 #define EROFS_XATTR_ENTRY_SIZE(entry) EROFS_XATTR_ALIGN( \
171         sizeof(struct erofs_xattr_entry) + \
172         (entry)->e_name_len + le16_to_cpu((entry)->e_value_size))
173
174 /* have to be aligned with 8 bytes on disk */
175 struct erofs_extent_header {
176         __le32 eh_checksum;
177         __le32 eh_reserved[3];
178 } __packed;
179
180 /*
181  * Z_EROFS Variable-sized Logical Extent cluster type:
182  *    0 - literal (uncompressed) cluster
183  *    1 - compressed cluster (for the head logical cluster)
184  *    2 - compressed cluster (for the other logical clusters)
185  *
186  * In detail,
187  *    0 - literal (uncompressed) cluster,
188  *        di_advise = 0
189  *        di_clusterofs = the literal data offset of the cluster
190  *        di_blkaddr = the blkaddr of the literal cluster
191  *
192  *    1 - compressed cluster (for the head logical cluster)
193  *        di_advise = 1
194  *        di_clusterofs = the decompressed data offset of the cluster
195  *        di_blkaddr = the blkaddr of the compressed cluster
196  *
197  *    2 - compressed cluster (for the other logical clusters)
198  *        di_advise = 2
199  *        di_clusterofs =
200  *           the decompressed data offset in its own head cluster
201  *        di_u.delta[0] = distance to its corresponding head cluster
202  *        di_u.delta[1] = distance to its corresponding tail cluster
203  *                (di_advise could be 0, 1 or 2)
204  */
205 enum {
206         Z_EROFS_VLE_CLUSTER_TYPE_PLAIN,
207         Z_EROFS_VLE_CLUSTER_TYPE_HEAD,
208         Z_EROFS_VLE_CLUSTER_TYPE_NONHEAD,
209         Z_EROFS_VLE_CLUSTER_TYPE_RESERVED,
210         Z_EROFS_VLE_CLUSTER_TYPE_MAX
211 };
212
213 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS        2
214 #define Z_EROFS_VLE_DI_CLUSTER_TYPE_BIT         0
215
216 struct z_erofs_vle_decompressed_index {
217         __le16 di_advise;
218         /* where to decompress in the head cluster */
219         __le16 di_clusterofs;
220
221         union {
222                 /* for the head cluster */
223                 __le32 blkaddr;
224                 /*
225                  * for the rest clusters
226                  * eg. for 4k page-sized cluster, maximum 4K*64k = 256M)
227                  * [0] - pointing to the head cluster
228                  * [1] - pointing to the tail cluster
229                  */
230                 __le16 delta[2];
231         } di_u __packed;                /* 8 bytes */
232 } __packed;
233
234 #define Z_EROFS_VLE_EXTENT_ALIGN(size) round_up(size, \
235         sizeof(struct z_erofs_vle_decompressed_index))
236
237 /* dirent sorts in alphabet order, thus we can do binary search */
238 struct erofs_dirent {
239         __le64 nid;     /*  0, node number */
240         __le16 nameoff; /*  8, start offset of file name */
241         __u8 file_type; /* 10, file type */
242         __u8 reserved;  /* 11, reserved */
243 } __packed;
244
245 /* file types used in inode_info->flags */
246 enum {
247         EROFS_FT_UNKNOWN,
248         EROFS_FT_REG_FILE,
249         EROFS_FT_DIR,
250         EROFS_FT_CHRDEV,
251         EROFS_FT_BLKDEV,
252         EROFS_FT_FIFO,
253         EROFS_FT_SOCK,
254         EROFS_FT_SYMLINK,
255         EROFS_FT_MAX
256 };
257
258 #define EROFS_NAME_LEN      255
259
260 /* check the EROFS on-disk layout strictly at compile time */
261 static inline void erofs_check_ondisk_layout_definitions(void)
262 {
263         BUILD_BUG_ON(sizeof(struct erofs_super_block) != 128);
264         BUILD_BUG_ON(sizeof(struct erofs_inode_v1) != 32);
265         BUILD_BUG_ON(sizeof(struct erofs_inode_v2) != 64);
266         BUILD_BUG_ON(sizeof(struct erofs_xattr_ibody_header) != 12);
267         BUILD_BUG_ON(sizeof(struct erofs_xattr_entry) != 4);
268         BUILD_BUG_ON(sizeof(struct erofs_extent_header) != 16);
269         BUILD_BUG_ON(sizeof(struct z_erofs_vle_decompressed_index) != 8);
270         BUILD_BUG_ON(sizeof(struct erofs_dirent) != 12);
271
272         BUILD_BUG_ON(BIT(Z_EROFS_VLE_DI_CLUSTER_TYPE_BITS) <
273                      Z_EROFS_VLE_CLUSTER_TYPE_MAX - 1);
274 }
275
276 #endif
277
This page took 0.048222 seconds and 4 git commands to generate.