Commit | Line | Data |
---|---|---|
ccd979bd MF |
1 | /* -*- mode: c; c-basic-offset: 8; -*- |
2 | * vim: noexpandtab sw=8 ts=8 sts=0: | |
3 | * | |
4 | * ocfs2_fs.h | |
5 | * | |
6 | * On-disk structures for OCFS2. | |
7 | * | |
8 | * Copyright (C) 2002, 2004 Oracle. All rights reserved. | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or | |
11 | * modify it under the terms of the GNU General Public | |
12 | * License, version 2, as published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, | |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public | |
20 | * License along with this program; if not, write to the | |
21 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 | * Boston, MA 021110-1307, USA. | |
23 | */ | |
24 | ||
25 | #ifndef _OCFS2_FS_H | |
26 | #define _OCFS2_FS_H | |
27 | ||
28 | /* Version */ | |
29 | #define OCFS2_MAJOR_REV_LEVEL 0 | |
30 | #define OCFS2_MINOR_REV_LEVEL 90 | |
31 | ||
32 | /* | |
33 | * An OCFS2 volume starts this way: | |
34 | * Sector 0: Valid ocfs1_vol_disk_hdr that cleanly fails to mount OCFS. | |
35 | * Sector 1: Valid ocfs1_vol_label that cleanly fails to mount OCFS. | |
36 | * Block OCFS2_SUPER_BLOCK_BLKNO: OCFS2 superblock. | |
37 | * | |
38 | * All other structures are found from the superblock information. | |
39 | * | |
40 | * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a | |
41 | * blocksize of 2K, it is 4096 bytes into disk. | |
42 | */ | |
43 | #define OCFS2_SUPER_BLOCK_BLKNO 2 | |
44 | ||
45 | /* | |
46 | * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could | |
47 | * grow if needed. | |
48 | */ | |
49 | #define OCFS2_MIN_CLUSTERSIZE 4096 | |
50 | #define OCFS2_MAX_CLUSTERSIZE 1048576 | |
51 | ||
52 | /* | |
53 | * Blocks cannot be bigger than clusters, so the maximum blocksize is the | |
54 | * minimum cluster size. | |
55 | */ | |
56 | #define OCFS2_MIN_BLOCKSIZE 512 | |
57 | #define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE | |
58 | ||
59 | /* Filesystem magic number */ | |
60 | #define OCFS2_SUPER_MAGIC 0x7461636f | |
61 | ||
62 | /* Object signatures */ | |
63 | #define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2" | |
64 | #define OCFS2_INODE_SIGNATURE "INODE01" | |
65 | #define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01" | |
66 | #define OCFS2_GROUP_DESC_SIGNATURE "GROUP01" | |
5a7bc8eb | 67 | #define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01" |
87d35a74 | 68 | #define OCFS2_DIR_TRAILER_SIGNATURE "DIRTRL1" |
9b7895ef MF |
69 | #define OCFS2_DX_ROOT_SIGNATURE "DXDIR01" |
70 | #define OCFS2_DX_LEAF_SIGNATURE "DXLEAF1" | |
721f69c4 | 71 | #define OCFS2_REFCOUNT_BLOCK_SIGNATURE "REFCNT1" |
ccd979bd MF |
72 | |
73 | /* Compatibility flags */ | |
74 | #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \ | |
75 | ( OCFS2_SB(sb)->s_feature_compat & (mask) ) | |
76 | #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \ | |
77 | ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) ) | |
78 | #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \ | |
79 | ( OCFS2_SB(sb)->s_feature_incompat & (mask) ) | |
80 | #define OCFS2_SET_COMPAT_FEATURE(sb,mask) \ | |
81 | OCFS2_SB(sb)->s_feature_compat |= (mask) | |
82 | #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \ | |
83 | OCFS2_SB(sb)->s_feature_ro_compat |= (mask) | |
84 | #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \ | |
85 | OCFS2_SB(sb)->s_feature_incompat |= (mask) | |
86 | #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \ | |
87 | OCFS2_SB(sb)->s_feature_compat &= ~(mask) | |
88 | #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ | |
89 | OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask) | |
90 | #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \ | |
91 | OCFS2_SB(sb)->s_feature_incompat &= ~(mask) | |
92 | ||
a9772189 JB |
93 | #define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \ |
94 | | OCFS2_FEATURE_COMPAT_JBD2_SB) | |
dcd0538f | 95 | #define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \ |
15b1e36b | 96 | | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \ |
386a2ef8 | 97 | | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \ |
b61817e1 | 98 | | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \ |
8154da3d | 99 | | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \ |
9d28cfb7 | 100 | | OCFS2_FEATURE_INCOMPAT_XATTR \ |
3a8df2b9 | 101 | | OCFS2_FEATURE_INCOMPAT_META_ECC \ |
64871b8d | 102 | | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \ |
1a934c3e | 103 | | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \ |
98f486f2 SM |
104 | | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG \ |
105 | | OCFS2_FEATURE_INCOMPAT_CLUSTERINFO) | |
19ece546 JK |
106 | #define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \ |
107 | | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \ | |
108 | | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA) | |
ccd979bd MF |
109 | |
110 | /* | |
111 | * Heartbeat-only devices are missing journals and other files. The | |
112 | * filesystem driver can't load them, but the library can. Never put | |
113 | * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*. | |
114 | */ | |
115 | #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002 | |
116 | ||
8903901d MF |
117 | /* |
118 | * tunefs sets this incompat flag before starting the resize and clears it | |
119 | * at the end. This flag protects users from inadvertently mounting the fs | |
120 | * after an aborted run without fsck-ing. | |
121 | */ | |
122 | #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004 | |
ccd979bd | 123 | |
c271c5c2 SM |
124 | /* Used to denote a non-clustered volume */ |
125 | #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008 | |
126 | ||
8903901d MF |
127 | /* Support for sparse allocation in b-trees */ |
128 | #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010 | |
129 | ||
92e91ce2 MF |
130 | /* |
131 | * Tunefs sets this incompat flag before starting an operation which | |
132 | * would require cleanup on abort. This is done to protect users from | |
133 | * inadvertently mounting the fs after an aborted run without | |
134 | * fsck-ing. | |
135 | * | |
136 | * s_tunefs_flags on the super block describes precisely which | |
137 | * operations were in progress. | |
138 | */ | |
139 | #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020 | |
140 | ||
15b1e36b MF |
141 | /* Support for data packed into inode blocks */ |
142 | #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040 | |
143 | ||
b61817e1 JB |
144 | /* |
145 | * Support for alternate, userspace cluster stacks. If set, the superblock | |
146 | * field s_cluster_info contains a tag for the alternate stack in use as | |
147 | * well as the name of the cluster being joined. | |
148 | * mount.ocfs2 must pass in a matching stack name. | |
149 | * | |
150 | * If not set, the classic stack will be used. This is compatbile with | |
151 | * all older versions. | |
152 | */ | |
153 | #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080 | |
154 | ||
8154da3d TY |
155 | /* Support for the extended slot map */ |
156 | #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100 | |
157 | ||
158 | /* Support for extended attributes */ | |
159 | #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200 | |
160 | ||
9b7895ef MF |
161 | /* Support for indexed directores */ |
162 | #define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400 | |
163 | ||
ab552d54 JB |
164 | /* Metadata checksum and error correction */ |
165 | #define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800 | |
166 | ||
721f69c4 TM |
167 | /* Refcount tree support */ |
168 | #define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000 | |
169 | ||
4cbe4249 JB |
170 | /* Discontigous block groups */ |
171 | #define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000 | |
172 | ||
98f486f2 SM |
173 | /* |
174 | * Incompat bit to indicate useable clusterinfo with stackflags for all | |
175 | * cluster stacks (userspace adnd o2cb). If this bit is set, | |
176 | * INCOMPAT_USERSPACE_STACK becomes superfluous and thus should not be set. | |
177 | */ | |
178 | #define OCFS2_FEATURE_INCOMPAT_CLUSTERINFO 0x4000 | |
179 | ||
50af94b1 MF |
180 | /* |
181 | * backup superblock flag is used to indicate that this volume | |
182 | * has backup superblocks. | |
183 | */ | |
184 | #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001 | |
185 | ||
a9772189 JB |
186 | /* |
187 | * The filesystem will correctly handle journal feature bits. | |
188 | */ | |
189 | #define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002 | |
190 | ||
328d5752 MF |
191 | /* |
192 | * Unwritten extents support. | |
193 | */ | |
194 | #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001 | |
195 | ||
1a224ad1 JK |
196 | /* |
197 | * Maintain quota information for this filesystem | |
198 | */ | |
199 | #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002 | |
200 | #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004 | |
201 | ||
50af94b1 MF |
202 | /* The byte offset of the first backup block will be 1G. |
203 | * The following will be 4G, 16G, 64G, 256G and 1T. | |
204 | */ | |
205 | #define OCFS2_BACKUP_SB_START 1 << 30 | |
206 | ||
207 | /* the max backup superblock nums */ | |
208 | #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6 | |
209 | ||
92e91ce2 MF |
210 | /* |
211 | * Flags on ocfs2_super_block.s_tunefs_flags | |
212 | */ | |
213 | #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */ | |
214 | ||
ccd979bd MF |
215 | /* |
216 | * Flags on ocfs2_dinode.i_flags | |
217 | */ | |
218 | #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */ | |
219 | #define OCFS2_UNUSED2_FL (0x00000002) | |
220 | #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */ | |
221 | #define OCFS2_UNUSED3_FL (0x00000008) | |
222 | /* System inode flags */ | |
223 | #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */ | |
224 | #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */ | |
225 | #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */ | |
226 | #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */ | |
227 | #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */ | |
228 | #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */ | |
229 | #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */ | |
230 | #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */ | |
1a224ad1 | 231 | #define OCFS2_QUOTA_FL (0x00001000) /* Quota file */ |
06ee5c75 JQ |
232 | #define OCFS2_DIO_ORPHANED_FL (0X00002000) /* On the orphan list especially |
233 | * for dio */ | |
ccd979bd | 234 | |
15b1e36b MF |
235 | /* |
236 | * Flags on ocfs2_dinode.i_dyn_features | |
237 | * | |
238 | * These can change much more often than i_flags. When adding flags, | |
239 | * keep in mind that i_dyn_features is only 16 bits wide. | |
240 | */ | |
241 | #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */ | |
242 | #define OCFS2_HAS_XATTR_FL (0x0002) | |
243 | #define OCFS2_INLINE_XATTR_FL (0x0004) | |
244 | #define OCFS2_INDEXED_DIR_FL (0x0008) | |
721f69c4 | 245 | #define OCFS2_HAS_REFCOUNT_FL (0x0010) |
15b1e36b | 246 | |
ca4d147e | 247 | /* Inode attributes, keep in sync with EXT2 */ |
0000b862 TM |
248 | #define OCFS2_SECRM_FL FS_SECRM_FL /* Secure deletion */ |
249 | #define OCFS2_UNRM_FL FS_UNRM_FL /* Undelete */ | |
250 | #define OCFS2_COMPR_FL FS_COMPR_FL /* Compress file */ | |
251 | #define OCFS2_SYNC_FL FS_SYNC_FL /* Synchronous updates */ | |
252 | #define OCFS2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */ | |
253 | #define OCFS2_APPEND_FL FS_APPEND_FL /* writes to file may only append */ | |
254 | #define OCFS2_NODUMP_FL FS_NODUMP_FL /* do not dump file */ | |
255 | #define OCFS2_NOATIME_FL FS_NOATIME_FL /* do not update atime */ | |
256 | /* Reserved for compression usage... */ | |
257 | #define OCFS2_DIRTY_FL FS_DIRTY_FL | |
258 | #define OCFS2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */ | |
259 | #define OCFS2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */ | |
260 | #define OCFS2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */ | |
261 | /* End compression flags --- maybe not all used */ | |
262 | #define OCFS2_BTREE_FL FS_BTREE_FL /* btree format dir */ | |
263 | #define OCFS2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */ | |
264 | #define OCFS2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */ | |
265 | #define OCFS2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */ | |
266 | #define OCFS2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */ | |
267 | #define OCFS2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */ | |
268 | #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/ | |
269 | #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */ | |
270 | ||
271 | #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */ | |
272 | #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */ | |
ca4d147e | 273 | |
e48edee2 MF |
274 | /* |
275 | * Extent record flags (e_node.leaf.flags) | |
276 | */ | |
721f69c4 TM |
277 | #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but |
278 | * unwritten */ | |
279 | #define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference | |
280 | * counted in an associated | |
281 | * refcount tree */ | |
e48edee2 | 282 | |
ccd979bd MF |
283 | /* |
284 | * Journal Flags (ocfs2_dinode.id1.journal1.i_flags) | |
285 | */ | |
286 | #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */ | |
287 | ||
288 | /* | |
289 | * superblock s_state flags | |
290 | */ | |
291 | #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */ | |
292 | ||
293 | /* Limit of space in ocfs2_dir_entry */ | |
294 | #define OCFS2_MAX_FILENAME_LEN 255 | |
295 | ||
296 | /* Maximum slots on an ocfs2 file system */ | |
297 | #define OCFS2_MAX_SLOTS 255 | |
298 | ||
299 | /* Slot map indicator for an empty slot */ | |
300 | #define OCFS2_INVALID_SLOT -1 | |
301 | ||
302 | #define OCFS2_VOL_UUID_LEN 16 | |
303 | #define OCFS2_MAX_VOL_LABEL_LEN 64 | |
304 | ||
98f486f2 | 305 | /* The cluster stack fields */ |
b61817e1 JB |
306 | #define OCFS2_STACK_LABEL_LEN 4 |
307 | #define OCFS2_CLUSTER_NAME_LEN 16 | |
308 | ||
98f486f2 SM |
309 | /* Classic (historically speaking) cluster stack */ |
310 | #define OCFS2_CLASSIC_CLUSTER_STACK "o2cb" | |
311 | ||
ccd979bd MF |
312 | /* Journal limits (in bytes) */ |
313 | #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024) | |
ccd979bd | 314 | |
fdd77704 TY |
315 | /* |
316 | * Inline extended attribute size (in bytes) | |
317 | * The value chosen should be aligned to 16 byte boundaries. | |
318 | */ | |
319 | #define OCFS2_MIN_XATTR_INLINE_SIZE 256 | |
320 | ||
98f486f2 SM |
321 | /* |
322 | * Cluster info flags (ocfs2_cluster_info.ci_stackflags) | |
323 | */ | |
324 | #define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT (0x01) | |
325 | ||
ccd979bd MF |
326 | struct ocfs2_system_inode_info { |
327 | char *si_name; | |
328 | int si_iflags; | |
329 | int si_mode; | |
330 | }; | |
331 | ||
332 | /* System file index */ | |
333 | enum { | |
334 | BAD_BLOCK_SYSTEM_INODE = 0, | |
335 | GLOBAL_INODE_ALLOC_SYSTEM_INODE, | |
336 | SLOT_MAP_SYSTEM_INODE, | |
337 | #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE | |
338 | HEARTBEAT_SYSTEM_INODE, | |
339 | GLOBAL_BITMAP_SYSTEM_INODE, | |
1a224ad1 JK |
340 | USER_QUOTA_SYSTEM_INODE, |
341 | GROUP_QUOTA_SYSTEM_INODE, | |
342 | #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE | |
b4d693fc | 343 | #define OCFS2_FIRST_LOCAL_SYSTEM_INODE ORPHAN_DIR_SYSTEM_INODE |
ccd979bd MF |
344 | ORPHAN_DIR_SYSTEM_INODE, |
345 | EXTENT_ALLOC_SYSTEM_INODE, | |
346 | INODE_ALLOC_SYSTEM_INODE, | |
347 | JOURNAL_SYSTEM_INODE, | |
348 | LOCAL_ALLOC_SYSTEM_INODE, | |
349 | TRUNCATE_LOG_SYSTEM_INODE, | |
1a224ad1 JK |
350 | LOCAL_USER_QUOTA_SYSTEM_INODE, |
351 | LOCAL_GROUP_QUOTA_SYSTEM_INODE, | |
b4d693fc | 352 | #define OCFS2_LAST_LOCAL_SYSTEM_INODE LOCAL_GROUP_QUOTA_SYSTEM_INODE |
ccd979bd MF |
353 | NUM_SYSTEM_INODES |
354 | }; | |
7d8f9876 | 355 | #define NUM_GLOBAL_SYSTEM_INODES OCFS2_FIRST_LOCAL_SYSTEM_INODE |
b4d693fc TM |
356 | #define NUM_LOCAL_SYSTEM_INODES \ |
357 | (NUM_SYSTEM_INODES - OCFS2_FIRST_LOCAL_SYSTEM_INODE) | |
ccd979bd MF |
358 | |
359 | static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { | |
360 | /* Global system inodes (single copy) */ | |
361 | /* The first two are only used from userspace mfks/tunefs */ | |
362 | [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 }, | |
363 | [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, | |
364 | ||
365 | /* These are used by the running filesystem */ | |
366 | [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 }, | |
367 | [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 }, | |
368 | [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 }, | |
1a224ad1 JK |
369 | [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
370 | [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 }, | |
ccd979bd MF |
371 | |
372 | /* Slot-specific system inodes (one copy per slot) */ | |
373 | [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 }, | |
374 | [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, | |
375 | [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, | |
376 | [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 }, | |
377 | [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 }, | |
1a224ad1 JK |
378 | [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }, |
379 | [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 }, | |
380 | [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 }, | |
ccd979bd MF |
381 | }; |
382 | ||
383 | /* Parameter passed from mount.ocfs2 to module */ | |
384 | #define OCFS2_HB_NONE "heartbeat=none" | |
385 | #define OCFS2_HB_LOCAL "heartbeat=local" | |
2c442719 | 386 | #define OCFS2_HB_GLOBAL "heartbeat=global" |
ccd979bd MF |
387 | |
388 | /* | |
389 | * OCFS2 directory file types. Only the low 3 bits are used. The | |
390 | * other bits are reserved for now. | |
391 | */ | |
392 | #define OCFS2_FT_UNKNOWN 0 | |
393 | #define OCFS2_FT_REG_FILE 1 | |
394 | #define OCFS2_FT_DIR 2 | |
395 | #define OCFS2_FT_CHRDEV 3 | |
396 | #define OCFS2_FT_BLKDEV 4 | |
397 | #define OCFS2_FT_FIFO 5 | |
398 | #define OCFS2_FT_SOCK 6 | |
399 | #define OCFS2_FT_SYMLINK 7 | |
400 | ||
401 | #define OCFS2_FT_MAX 8 | |
402 | ||
403 | /* | |
404 | * OCFS2_DIR_PAD defines the directory entries boundaries | |
405 | * | |
406 | * NOTE: It must be a multiple of 4 | |
407 | */ | |
408 | #define OCFS2_DIR_PAD 4 | |
409 | #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1) | |
410 | #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name) | |
411 | #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \ | |
412 | OCFS2_DIR_ROUND) & \ | |
413 | ~OCFS2_DIR_ROUND) | |
e7c17e43 | 414 | #define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1) |
ccd979bd MF |
415 | |
416 | #define OCFS2_LINK_MAX 32000 | |
198a1ca3 MF |
417 | #define OCFS2_DX_LINK_MAX ((1U << 31) - 1U) |
418 | #define OCFS2_LINKS_HI_SHIFT 16 | |
e3a93c2d | 419 | #define OCFS2_DX_ENTRIES_MAX (0xffffffffU) |
ccd979bd MF |
420 | |
421 | #define S_SHIFT 12 | |
422 | static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = { | |
423 | [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE, | |
424 | [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR, | |
425 | [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV, | |
426 | [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV, | |
427 | [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO, | |
428 | [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK, | |
429 | [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK, | |
430 | }; | |
431 | ||
432 | ||
433 | /* | |
434 | * Convenience casts | |
435 | */ | |
436 | #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super)) | |
437 | ||
ab552d54 JB |
438 | /* |
439 | * Block checking structure. This is used in metadata to validate the | |
440 | * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all | |
441 | * zeros. | |
442 | */ | |
443 | struct ocfs2_block_check { | |
444 | /*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */ | |
445 | __le16 bc_ecc; /* Single-error-correction parity vector. | |
25985edc | 446 | This is a simple Hamming code dependent |
ab552d54 JB |
447 | on the blocksize. OCFS2's maximum |
448 | blocksize, 4K, requires 16 parity bits, | |
449 | so we fit in __le16. */ | |
450 | __le16 bc_reserved1; | |
451 | /*08*/ | |
452 | }; | |
453 | ||
ccd979bd MF |
454 | /* |
455 | * On disk extent record for OCFS2 | |
456 | * It describes a range of clusters on disk. | |
e48edee2 MF |
457 | * |
458 | * Length fields are divided into interior and leaf node versions. | |
459 | * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes. | |
ccd979bd MF |
460 | */ |
461 | struct ocfs2_extent_rec { | |
462 | /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */ | |
e48edee2 MF |
463 | union { |
464 | __le32 e_int_clusters; /* Clusters covered by all children */ | |
465 | struct { | |
466 | __le16 e_leaf_clusters; /* Clusters covered by this | |
467 | extent */ | |
468 | __u8 e_reserved1; | |
469 | __u8 e_flags; /* Extent flags */ | |
470 | }; | |
471 | }; | |
ccd979bd MF |
472 | __le64 e_blkno; /* Physical disk offset, in blocks */ |
473 | /*10*/ | |
474 | }; | |
475 | ||
476 | struct ocfs2_chain_rec { | |
477 | __le32 c_free; /* Number of free bits in this chain. */ | |
478 | __le32 c_total; /* Number of total bits in this chain */ | |
479 | __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */ | |
480 | }; | |
481 | ||
482 | struct ocfs2_truncate_rec { | |
483 | __le32 t_start; /* 1st cluster in this log */ | |
484 | __le32 t_clusters; /* Number of total clusters covered */ | |
485 | }; | |
486 | ||
487 | /* | |
488 | * On disk extent list for OCFS2 (node in the tree). Note that this | |
489 | * is contained inside ocfs2_dinode or ocfs2_extent_block, so the | |
490 | * offsets are relative to ocfs2_dinode.id2.i_list or | |
491 | * ocfs2_extent_block.h_list, respectively. | |
492 | */ | |
493 | struct ocfs2_extent_list { | |
494 | /*00*/ __le16 l_tree_depth; /* Extent tree depth from this | |
495 | point. 0 means data extents | |
496 | hang directly off this | |
dcd0538f MF |
497 | header (a leaf) |
498 | NOTE: The high 8 bits cannot be | |
499 | used - tree_depth is never that big. | |
500 | */ | |
ccd979bd MF |
501 | __le16 l_count; /* Number of extent records */ |
502 | __le16 l_next_free_rec; /* Next unused extent slot */ | |
503 | __le16 l_reserved1; | |
504 | __le64 l_reserved2; /* Pad to | |
505 | sizeof(ocfs2_extent_rec) */ | |
506 | /*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */ | |
507 | }; | |
508 | ||
509 | /* | |
510 | * On disk allocation chain list for OCFS2. Note that this is | |
511 | * contained inside ocfs2_dinode, so the offsets are relative to | |
512 | * ocfs2_dinode.id2.i_chain. | |
513 | */ | |
514 | struct ocfs2_chain_list { | |
515 | /*00*/ __le16 cl_cpg; /* Clusters per Block Group */ | |
516 | __le16 cl_bpc; /* Bits per cluster */ | |
517 | __le16 cl_count; /* Total chains in this list */ | |
518 | __le16 cl_next_free_rec; /* Next unused chain slot */ | |
519 | __le64 cl_reserved1; | |
520 | /*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */ | |
521 | }; | |
522 | ||
523 | /* | |
524 | * On disk deallocation log for OCFS2. Note that this is | |
525 | * contained inside ocfs2_dinode, so the offsets are relative to | |
526 | * ocfs2_dinode.id2.i_dealloc. | |
527 | */ | |
528 | struct ocfs2_truncate_log { | |
529 | /*00*/ __le16 tl_count; /* Total records in this log */ | |
530 | __le16 tl_used; /* Number of records in use */ | |
531 | __le32 tl_reserved1; | |
532 | /*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */ | |
533 | }; | |
534 | ||
535 | /* | |
536 | * On disk extent block (indirect block) for OCFS2 | |
537 | */ | |
538 | struct ocfs2_extent_block | |
539 | { | |
540 | /*00*/ __u8 h_signature[8]; /* Signature for verification */ | |
ab552d54 | 541 | struct ocfs2_block_check h_check; /* Error checking */ |
ccd979bd MF |
542 | /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this |
543 | extent_header belongs to */ | |
544 | __le16 h_suballoc_bit; /* Bit offset in suballocator | |
545 | block group */ | |
546 | __le32 h_fs_generation; /* Must match super block */ | |
547 | __le64 h_blkno; /* Offset on disk, in blocks */ | |
9cbc0123 JB |
548 | /*20*/ __le64 h_suballoc_loc; /* Suballocator block group this |
549 | eb belongs to. Only valid | |
550 | if allocated from a | |
551 | discontiguous block group */ | |
ccd979bd MF |
552 | __le64 h_next_leaf_blk; /* Offset on disk, in blocks, |
553 | of next leaf header pointing | |
554 | to data */ | |
555 | /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */ | |
556 | /* Actual on-disk size is one block */ | |
557 | }; | |
558 | ||
fb86b1f0 JB |
559 | /* |
560 | * On disk slot map for OCFS2. This defines the contents of the "slot_map" | |
386a2ef8 JB |
561 | * system file. A slot is valid if it contains a node number >= 0. The |
562 | * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty. | |
fb86b1f0 JB |
563 | */ |
564 | struct ocfs2_slot_map { | |
565 | /*00*/ __le16 sm_slots[0]; | |
566 | /* | |
567 | * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255, | |
568 | * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize. | |
569 | */ | |
570 | }; | |
571 | ||
386a2ef8 JB |
572 | struct ocfs2_extended_slot { |
573 | /*00*/ __u8 es_valid; | |
574 | __u8 es_reserved1[3]; | |
575 | __le32 es_node_num; | |
576 | /*10*/ | |
577 | }; | |
578 | ||
579 | /* | |
580 | * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP | |
581 | * is set. It separates out the valid marker from the node number, and | |
582 | * has room to grow. Unlike the old slot map, this format is defined by | |
583 | * i_size. | |
584 | */ | |
585 | struct ocfs2_slot_map_extended { | |
586 | /*00*/ struct ocfs2_extended_slot se_slots[0]; | |
587 | /* | |
588 | * Actual size is i_size of the slot_map system file. It should | |
589 | * match s_max_slots * sizeof(struct ocfs2_extended_slot) | |
590 | */ | |
591 | }; | |
592 | ||
98f486f2 SM |
593 | /* |
594 | * ci_stackflags is only valid if the incompat bit | |
595 | * OCFS2_FEATURE_INCOMPAT_CLUSTERINFO is set. | |
596 | */ | |
b61817e1 JB |
597 | struct ocfs2_cluster_info { |
598 | /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN]; | |
98f486f2 SM |
599 | union { |
600 | __le32 ci_reserved; | |
601 | struct { | |
602 | __u8 ci_stackflags; | |
603 | __u8 ci_reserved1; | |
604 | __u8 ci_reserved2; | |
605 | __u8 ci_reserved3; | |
606 | }; | |
607 | }; | |
b61817e1 JB |
608 | /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN]; |
609 | /*18*/ | |
610 | }; | |
611 | ||
ccd979bd MF |
612 | /* |
613 | * On disk superblock for OCFS2 | |
614 | * Note that it is contained inside an ocfs2_dinode, so all offsets | |
615 | * are relative to the start of ocfs2_dinode.id2. | |
616 | */ | |
617 | struct ocfs2_super_block { | |
618 | /*00*/ __le16 s_major_rev_level; | |
619 | __le16 s_minor_rev_level; | |
620 | __le16 s_mnt_count; | |
621 | __le16 s_max_mnt_count; | |
622 | __le16 s_state; /* File system state */ | |
623 | __le16 s_errors; /* Behaviour when detecting errors */ | |
624 | __le32 s_checkinterval; /* Max time between checks */ | |
625 | /*10*/ __le64 s_lastcheck; /* Time of last check */ | |
626 | __le32 s_creator_os; /* OS */ | |
627 | __le32 s_feature_compat; /* Compatible feature set */ | |
628 | /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */ | |
629 | __le32 s_feature_ro_compat; /* Readonly-compatible feature set */ | |
630 | __le64 s_root_blkno; /* Offset, in blocks, of root directory | |
631 | dinode */ | |
632 | /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system | |
633 | directory dinode */ | |
634 | __le32 s_blocksize_bits; /* Blocksize for this fs */ | |
635 | __le32 s_clustersize_bits; /* Clustersize for this fs */ | |
636 | /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts | |
637 | before tunefs required */ | |
92e91ce2 | 638 | __le16 s_tunefs_flag; |
cf1d6c76 | 639 | __le32 s_uuid_hash; /* hash value of uuid */ |
ccd979bd MF |
640 | __le64 s_first_cluster_group; /* Block offset of 1st cluster |
641 | * group header */ | |
642 | /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */ | |
643 | /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */ | |
98f486f2 SM |
644 | /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Only valid if either |
645 | userspace or clusterinfo | |
646 | INCOMPAT flag set. */ | |
8154da3d TY |
647 | /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size |
648 | for this fs*/ | |
649 | __le16 s_reserved0; | |
9b7895ef MF |
650 | __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash. |
651 | * s_uuid_hash serves as seed[3]. */ | |
652 | /*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */ | |
b61817e1 JB |
653 | /*140*/ |
654 | ||
655 | /* | |
656 | * NOTE: As stated above, all offsets are relative to | |
657 | * ocfs2_dinode.id2, which is at 0xC0 in the inode. | |
658 | * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within | |
659 | * our smallest blocksize, which is 512 bytes. To ensure this, | |
660 | * we reserve the space in s_reserved2. Anything past s_reserved2 | |
661 | * will not be available on the smallest blocksize. | |
662 | */ | |
ccd979bd MF |
663 | }; |
664 | ||
665 | /* | |
666 | * Local allocation bitmap for OCFS2 slots | |
667 | * Note that it exists inside an ocfs2_dinode, so all offsets are | |
668 | * relative to the start of ocfs2_dinode.id2. | |
669 | */ | |
670 | struct ocfs2_local_alloc | |
671 | { | |
672 | /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */ | |
673 | __le16 la_size; /* Size of included bitmap, in bytes */ | |
674 | __le16 la_reserved1; | |
675 | __le64 la_reserved2; | |
676 | /*10*/ __u8 la_bitmap[0]; | |
677 | }; | |
678 | ||
15b1e36b MF |
679 | /* |
680 | * Data-in-inode header. This is only used if i_dyn_features has | |
681 | * OCFS2_INLINE_DATA_FL set. | |
682 | */ | |
683 | struct ocfs2_inline_data | |
684 | { | |
685 | /*00*/ __le16 id_count; /* Number of bytes that can be used | |
686 | * for data, starting at id_data */ | |
687 | __le16 id_reserved0; | |
688 | __le32 id_reserved1; | |
689 | __u8 id_data[0]; /* Start of user data */ | |
690 | }; | |
691 | ||
ccd979bd MF |
692 | /* |
693 | * On disk inode for OCFS2 | |
694 | */ | |
695 | struct ocfs2_dinode { | |
696 | /*00*/ __u8 i_signature[8]; /* Signature for validation */ | |
697 | __le32 i_generation; /* Generation number */ | |
698 | __le16 i_suballoc_slot; /* Slot suballocator this inode | |
699 | belongs to */ | |
700 | __le16 i_suballoc_bit; /* Bit offset in suballocator | |
701 | block group */ | |
198a1ca3 | 702 | /*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */ |
fdd77704 | 703 | __le16 i_xattr_inline_size; |
ccd979bd MF |
704 | __le32 i_clusters; /* Cluster count */ |
705 | __le32 i_uid; /* Owner UID */ | |
706 | __le32 i_gid; /* Owning GID */ | |
707 | /*20*/ __le64 i_size; /* Size in bytes */ | |
708 | __le16 i_mode; /* File mode */ | |
709 | __le16 i_links_count; /* Links count */ | |
710 | __le32 i_flags; /* File flags */ | |
711 | /*30*/ __le64 i_atime; /* Access time */ | |
712 | __le64 i_ctime; /* Creation time */ | |
713 | /*40*/ __le64 i_mtime; /* Modification time */ | |
714 | __le64 i_dtime; /* Deletion time */ | |
715 | /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */ | |
716 | __le64 i_last_eb_blk; /* Pointer to last extent | |
717 | block */ | |
718 | /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */ | |
719 | __le32 i_atime_nsec; | |
720 | __le32 i_ctime_nsec; | |
721 | __le32 i_mtime_nsec; | |
fdd77704 | 722 | /*70*/ __le32 i_attr; |
50008630 TY |
723 | __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL |
724 | was set in i_flags */ | |
15b1e36b | 725 | __le16 i_dyn_features; |
fdd77704 | 726 | __le64 i_xattr_loc; |
ab552d54 | 727 | /*80*/ struct ocfs2_block_check i_check; /* Error checking */ |
9b7895ef | 728 | /*88*/ __le64 i_dx_root; /* Pointer to dir index root block */ |
721f69c4 | 729 | /*90*/ __le64 i_refcount_loc; |
9cbc0123 JB |
730 | __le64 i_suballoc_loc; /* Suballocator block group this |
731 | inode belongs to. Only valid | |
732 | if allocated from a | |
733 | discontiguous block group */ | |
06ee5c75 JQ |
734 | /*A0*/ __le16 i_dio_orphaned_slot; /* only used for append dio write */ |
735 | __le16 i_reserved1[3]; | |
736 | __le64 i_reserved2[2]; | |
ccd979bd MF |
737 | /*B8*/ union { |
738 | __le64 i_pad1; /* Generic way to refer to this | |
739 | 64bit union */ | |
740 | struct { | |
741 | __le64 i_rdev; /* Device number */ | |
742 | } dev1; | |
743 | struct { /* Info for bitmap system | |
744 | inodes */ | |
745 | __le32 i_used; /* Bits (ie, clusters) used */ | |
746 | __le32 i_total; /* Total bits (clusters) | |
747 | available */ | |
748 | } bitmap1; | |
749 | struct { /* Info for journal system | |
750 | inodes */ | |
751 | __le32 ij_flags; /* Mounted, version, etc. */ | |
c69991aa SM |
752 | __le32 ij_recovery_generation; /* Incremented when the |
753 | journal is recovered | |
754 | after an unclean | |
755 | shutdown */ | |
ccd979bd | 756 | } journal1; |
25985edc | 757 | } id1; /* Inode type dependent 1 */ |
ccd979bd MF |
758 | /*C0*/ union { |
759 | struct ocfs2_super_block i_super; | |
760 | struct ocfs2_local_alloc i_lab; | |
761 | struct ocfs2_chain_list i_chain; | |
762 | struct ocfs2_extent_list i_list; | |
763 | struct ocfs2_truncate_log i_dealloc; | |
15b1e36b | 764 | struct ocfs2_inline_data i_data; |
ccd979bd MF |
765 | __u8 i_symlink[0]; |
766 | } id2; | |
767 | /* Actual on-disk size is one block */ | |
768 | }; | |
769 | ||
770 | /* | |
771 | * On-disk directory entry structure for OCFS2 | |
772 | * | |
773 | * Packed as this structure could be accessed unaligned on 64-bit platforms | |
774 | */ | |
775 | struct ocfs2_dir_entry { | |
776 | /*00*/ __le64 inode; /* Inode number */ | |
777 | __le16 rec_len; /* Directory entry length */ | |
778 | __u8 name_len; /* Name length */ | |
779 | __u8 file_type; | |
780 | /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */ | |
781 | /* Actual on-disk length specified by rec_len */ | |
782 | } __attribute__ ((packed)); | |
783 | ||
87d35a74 MF |
784 | /* |
785 | * Per-block record for the unindexed directory btree. This is carefully | |
786 | * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are | |
787 | * mirrored. That way, the directory manipulation code needs a minimal amount | |
788 | * of update. | |
789 | * | |
790 | * NOTE: Keep this structure aligned to a multiple of 4 bytes. | |
791 | */ | |
792 | struct ocfs2_dir_block_trailer { | |
793 | /*00*/ __le64 db_compat_inode; /* Always zero. Was inode */ | |
794 | ||
795 | __le16 db_compat_rec_len; /* Backwards compatible with | |
796 | * ocfs2_dir_entry. */ | |
797 | __u8 db_compat_name_len; /* Always zero. Was name_len */ | |
798 | __u8 db_reserved0; | |
799 | __le16 db_reserved1; | |
800 | __le16 db_free_rec_len; /* Size of largest empty hole | |
801 | * in this block. (unused) */ | |
802 | /*10*/ __u8 db_signature[8]; /* Signature for verification */ | |
803 | __le64 db_reserved2; | |
804 | __le64 db_free_next; /* Next block in list (unused) */ | |
805 | /*20*/ __le64 db_blkno; /* Offset on disk, in blocks */ | |
806 | __le64 db_parent_dinode; /* dinode which owns me, in | |
807 | blocks */ | |
c175a518 | 808 | /*30*/ struct ocfs2_block_check db_check; /* Error checking */ |
87d35a74 MF |
809 | /*40*/ |
810 | }; | |
811 | ||
9b7895ef MF |
812 | /* |
813 | * A directory entry in the indexed tree. We don't store the full name here, | |
814 | * but instead provide a pointer to the full dirent in the unindexed tree. | |
815 | * | |
816 | * We also store name_len here so as to reduce the number of leaf blocks we | |
817 | * need to search in case of collisions. | |
818 | */ | |
819 | struct ocfs2_dx_entry { | |
820 | __le32 dx_major_hash; /* Used to find logical | |
821 | * cluster in index */ | |
822 | __le32 dx_minor_hash; /* Lower bits used to find | |
823 | * block in cluster */ | |
824 | __le64 dx_dirent_blk; /* Physical block in unindexed | |
825 | * tree holding this dirent. */ | |
826 | }; | |
827 | ||
828 | struct ocfs2_dx_entry_list { | |
829 | __le32 de_reserved; | |
830 | __le16 de_count; /* Maximum number of entries | |
831 | * possible in de_entries */ | |
832 | __le16 de_num_used; /* Current number of | |
833 | * de_entries entries */ | |
834 | struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries | |
835 | * in a packed array of | |
836 | * length de_num_used */ | |
837 | }; | |
838 | ||
4ed8a6bb MF |
839 | #define OCFS2_DX_FLAG_INLINE 0x01 |
840 | ||
9b7895ef MF |
841 | /* |
842 | * A directory indexing block. Each indexed directory has one of these, | |
843 | * pointed to by ocfs2_dinode. | |
844 | * | |
845 | * This block stores an indexed btree root, and a set of free space | |
846 | * start-of-list pointers. | |
847 | */ | |
848 | struct ocfs2_dx_root_block { | |
849 | __u8 dr_signature[8]; /* Signature for verification */ | |
850 | struct ocfs2_block_check dr_check; /* Error checking */ | |
851 | __le16 dr_suballoc_slot; /* Slot suballocator this | |
852 | * block belongs to. */ | |
853 | __le16 dr_suballoc_bit; /* Bit offset in suballocator | |
854 | * block group */ | |
855 | __le32 dr_fs_generation; /* Must match super block */ | |
856 | __le64 dr_blkno; /* Offset on disk, in blocks */ | |
857 | __le64 dr_last_eb_blk; /* Pointer to last | |
858 | * extent block */ | |
859 | __le32 dr_clusters; /* Clusters allocated | |
860 | * to the indexed tree. */ | |
4ed8a6bb MF |
861 | __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */ |
862 | __u8 dr_reserved0; | |
863 | __le16 dr_reserved1; | |
9b7895ef | 864 | __le64 dr_dir_blkno; /* Pointer to parent inode */ |
e3a93c2d MF |
865 | __le32 dr_num_entries; /* Total number of |
866 | * names stored in | |
867 | * this directory.*/ | |
868 | __le32 dr_reserved2; | |
e7c17e43 MF |
869 | __le64 dr_free_blk; /* Pointer to head of free |
870 | * unindexed block list. */ | |
9cbc0123 JB |
871 | __le64 dr_suballoc_loc; /* Suballocator block group |
872 | this root belongs to. | |
873 | Only valid if allocated | |
874 | from a discontiguous | |
875 | block group */ | |
876 | __le64 dr_reserved3[14]; | |
4ed8a6bb MF |
877 | union { |
878 | struct ocfs2_extent_list dr_list; /* Keep this aligned to 128 | |
879 | * bits for maximum space | |
880 | * efficiency. */ | |
881 | struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of | |
882 | * entries. We grow out | |
883 | * to extents if this | |
884 | * gets too big. */ | |
885 | }; | |
9b7895ef MF |
886 | }; |
887 | ||
888 | /* | |
889 | * The header of a leaf block in the indexed tree. | |
890 | */ | |
891 | struct ocfs2_dx_leaf { | |
892 | __u8 dl_signature[8];/* Signature for verification */ | |
893 | struct ocfs2_block_check dl_check; /* Error checking */ | |
894 | __le64 dl_blkno; /* Offset on disk, in blocks */ | |
895 | __le32 dl_fs_generation;/* Must match super block */ | |
896 | __le32 dl_reserved0; | |
897 | __le64 dl_reserved1; | |
898 | struct ocfs2_dx_entry_list dl_list; | |
899 | }; | |
900 | ||
4cbe4249 JB |
901 | /* |
902 | * Largest bitmap for a block (suballocator) group in bytes. This limit | |
903 | * does not affect cluster groups (global allocator). Cluster group | |
904 | * bitmaps run to the end of the block. | |
905 | */ | |
906 | #define OCFS2_MAX_BG_BITMAP_SIZE 256 | |
907 | ||
ccd979bd MF |
908 | /* |
909 | * On disk allocator group structure for OCFS2 | |
910 | */ | |
911 | struct ocfs2_group_desc | |
912 | { | |
913 | /*00*/ __u8 bg_signature[8]; /* Signature for validation */ | |
914 | __le16 bg_size; /* Size of included bitmap in | |
915 | bytes. */ | |
916 | __le16 bg_bits; /* Bits represented by this | |
917 | group. */ | |
918 | __le16 bg_free_bits_count; /* Free bits count */ | |
919 | __le16 bg_chain; /* What chain I am in. */ | |
920 | /*10*/ __le32 bg_generation; | |
921 | __le32 bg_reserved1; | |
922 | __le64 bg_next_group; /* Next group in my list, in | |
923 | blocks */ | |
924 | /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in | |
925 | blocks */ | |
926 | __le64 bg_blkno; /* Offset on disk, in blocks */ | |
ab552d54 JB |
927 | /*30*/ struct ocfs2_block_check bg_check; /* Error checking */ |
928 | __le64 bg_reserved2; | |
4cbe4249 JB |
929 | /*40*/ union { |
930 | __u8 bg_bitmap[0]; | |
931 | struct { | |
932 | /* | |
933 | * Block groups may be discontiguous when | |
934 | * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set. | |
935 | * The extents of a discontigous block group are | |
936 | * stored in bg_list. It is a flat list. | |
937 | * l_tree_depth must always be zero. A | |
938 | * discontiguous group is signified by a non-zero | |
939 | * bg_list->l_next_free_rec. Only block groups | |
940 | * can be discontiguous; Cluster groups cannot. | |
941 | * We've never made a block group with more than | |
942 | * 2048 blocks (256 bytes of bg_bitmap). This | |
943 | * codifies that limit so that we can fit bg_list. | |
944 | * bg_size of a discontiguous block group will | |
945 | * be 256 to match bg_bitmap_filler. | |
946 | */ | |
947 | __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE]; | |
948 | /*140*/ struct ocfs2_extent_list bg_list; | |
949 | }; | |
950 | }; | |
951 | /* Actual on-disk size is one block */ | |
ccd979bd MF |
952 | }; |
953 | ||
721f69c4 TM |
954 | struct ocfs2_refcount_rec { |
955 | /*00*/ __le64 r_cpos; /* Physical offset, in clusters */ | |
956 | __le32 r_clusters; /* Clusters covered by this extent */ | |
957 | __le32 r_refcount; /* Reference count of this extent */ | |
958 | /*10*/ | |
959 | }; | |
e73a819d | 960 | #define OCFS2_32BIT_POS_MASK (0xffffffffULL) |
721f69c4 TM |
961 | |
962 | #define OCFS2_REFCOUNT_LEAF_FL (0x00000001) | |
963 | #define OCFS2_REFCOUNT_TREE_FL (0x00000002) | |
964 | ||
965 | struct ocfs2_refcount_list { | |
966 | /*00*/ __le16 rl_count; /* Maximum number of entries possible | |
967 | in rl_records */ | |
968 | __le16 rl_used; /* Current number of used records */ | |
969 | __le32 rl_reserved2; | |
970 | __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */ | |
971 | /*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */ | |
972 | }; | |
973 | ||
974 | ||
975 | struct ocfs2_refcount_block { | |
976 | /*00*/ __u8 rf_signature[8]; /* Signature for verification */ | |
977 | __le16 rf_suballoc_slot; /* Slot suballocator this block | |
978 | belongs to */ | |
979 | __le16 rf_suballoc_bit; /* Bit offset in suballocator | |
980 | block group */ | |
981 | __le32 rf_fs_generation; /* Must match superblock */ | |
982 | /*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */ | |
983 | __le64 rf_parent; /* Parent block, only valid if | |
984 | OCFS2_REFCOUNT_LEAF_FL is set in | |
985 | rf_flags */ | |
986 | /*20*/ struct ocfs2_block_check rf_check; /* Error checking */ | |
987 | __le64 rf_last_eb_blk; /* Pointer to last extent block */ | |
988 | /*30*/ __le32 rf_count; /* Number of inodes sharing this | |
989 | refcount tree */ | |
990 | __le32 rf_flags; /* See the flags above */ | |
991 | __le32 rf_clusters; /* clusters covered by refcount tree. */ | |
992 | __le32 rf_cpos; /* cluster offset in refcount tree.*/ | |
993 | /*40*/ __le32 rf_generation; /* generation number. all be the same | |
994 | * for the same refcount tree. */ | |
995 | __le32 rf_reserved0; | |
9cbc0123 JB |
996 | __le64 rf_suballoc_loc; /* Suballocator block group this |
997 | refcount block belongs to. Only | |
998 | valid if allocated from a | |
999 | discontiguous block group */ | |
1000 | /*50*/ __le64 rf_reserved1[6]; | |
721f69c4 TM |
1001 | /*80*/ union { |
1002 | struct ocfs2_refcount_list rf_records; /* List of refcount | |
1003 | records */ | |
1004 | struct ocfs2_extent_list rf_list; /* Extent record list, | |
1005 | only valid if | |
1006 | OCFS2_REFCOUNT_TREE_FL | |
1007 | is set in rf_flags */ | |
1008 | }; | |
1009 | /* Actual on-disk size is one block */ | |
1010 | }; | |
1011 | ||
5a7bc8eb TM |
1012 | /* |
1013 | * On disk extended attribute structure for OCFS2. | |
1014 | */ | |
1015 | ||
1016 | /* | |
1017 | * ocfs2_xattr_entry indicates one extend attribute. | |
1018 | * | |
1019 | * Note that it can be stored in inode, one block or one xattr bucket. | |
1020 | */ | |
1021 | struct ocfs2_xattr_entry { | |
1022 | __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */ | |
8573f79d | 1023 | __le16 xe_name_offset; /* byte offset from the 1st entry in the |
5a7bc8eb TM |
1024 | local xattr storage(inode, xattr block or |
1025 | xattr bucket). */ | |
e9c54999 | 1026 | __u8 xe_name_len; /* xattr name len, doesn't include prefix. */ |
8573f79d TM |
1027 | __u8 xe_type; /* the low 7 bits indicate the name prefix |
1028 | * type and the highest bit indicates whether | |
5a7bc8eb TM |
1029 | * the EA is stored in the local storage. */ |
1030 | __le64 xe_value_size; /* real xattr value length. */ | |
1031 | }; | |
1032 | ||
1033 | /* | |
1034 | * On disk structure for xattr header. | |
1035 | * | |
1036 | * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in | |
1037 | * the local xattr storage. | |
1038 | */ | |
1039 | struct ocfs2_xattr_header { | |
1040 | __le16 xh_count; /* contains the count of how | |
1041 | many records are in the | |
1042 | local xattr storage. */ | |
0c044f0b TM |
1043 | __le16 xh_free_start; /* current offset for storing |
1044 | xattr. */ | |
1045 | __le16 xh_name_value_len; /* total length of name/value | |
1046 | length in this bucket. */ | |
8573f79d TM |
1047 | __le16 xh_num_buckets; /* Number of xattr buckets |
1048 | in this extent record, | |
1049 | only valid in the first | |
1050 | bucket. */ | |
ab552d54 JB |
1051 | struct ocfs2_block_check xh_check; /* Error checking |
1052 | (Note, this is only | |
1053 | used for xattr | |
1054 | buckets. A block uses | |
1055 | xb_check and sets | |
1056 | this field to zero.) */ | |
5a7bc8eb TM |
1057 | struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */ |
1058 | }; | |
1059 | ||
1060 | /* | |
1061 | * On disk structure for xattr value root. | |
1062 | * | |
8573f79d TM |
1063 | * When an xattr's value is large enough, it is stored in an external |
1064 | * b-tree like file data. The xattr value root points to this structure. | |
5a7bc8eb TM |
1065 | */ |
1066 | struct ocfs2_xattr_value_root { | |
1067 | /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */ | |
1068 | __le32 xr_reserved0; | |
1069 | __le64 xr_last_eb_blk; /* Pointer to last extent block */ | |
1070 | /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */ | |
1071 | }; | |
1072 | ||
1073 | /* | |
1074 | * On disk structure for xattr tree root. | |
1075 | * | |
1076 | * It is used when there are too many extended attributes for one file. These | |
1077 | * attributes will be organized and stored in an indexed-btree. | |
1078 | */ | |
1079 | struct ocfs2_xattr_tree_root { | |
1080 | /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */ | |
1081 | __le32 xt_reserved0; | |
1082 | __le64 xt_last_eb_blk; /* Pointer to last extent block */ | |
1083 | /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */ | |
1084 | }; | |
1085 | ||
cf1d6c76 TY |
1086 | #define OCFS2_XATTR_INDEXED 0x1 |
1087 | #define OCFS2_HASH_SHIFT 5 | |
1088 | #define OCFS2_XATTR_ROUND 3 | |
1089 | #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \ | |
1090 | ~(OCFS2_XATTR_ROUND)) | |
5a7bc8eb | 1091 | |
0c044f0b TM |
1092 | #define OCFS2_XATTR_BUCKET_SIZE 4096 |
1093 | #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \ | |
1094 | / OCFS2_MIN_BLOCKSIZE) | |
1095 | ||
5a7bc8eb TM |
1096 | /* |
1097 | * On disk structure for xattr block. | |
1098 | */ | |
1099 | struct ocfs2_xattr_block { | |
1100 | /*00*/ __u8 xb_signature[8]; /* Signature for verification */ | |
1101 | __le16 xb_suballoc_slot; /* Slot suballocator this | |
1102 | block belongs to. */ | |
1103 | __le16 xb_suballoc_bit; /* Bit offset in suballocator | |
1104 | block group */ | |
1105 | __le32 xb_fs_generation; /* Must match super block */ | |
1106 | /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */ | |
ab552d54 | 1107 | struct ocfs2_block_check xb_check; /* Error checking */ |
5a7bc8eb TM |
1108 | /*20*/ __le16 xb_flags; /* Indicates whether this block contains |
1109 | real xattr or a xattr tree. */ | |
1110 | __le16 xb_reserved0; | |
1111 | __le32 xb_reserved1; | |
9cbc0123 JB |
1112 | __le64 xb_suballoc_loc; /* Suballocator block group this |
1113 | xattr block belongs to. Only | |
1114 | valid if allocated from a | |
1115 | discontiguous block group */ | |
5a7bc8eb TM |
1116 | /*30*/ union { |
1117 | struct ocfs2_xattr_header xb_header; /* xattr header if this | |
1118 | block contains xattr */ | |
1119 | struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this | |
1120 | block cotains xattr | |
1121 | tree. */ | |
1122 | } xb_attrs; | |
1123 | }; | |
1124 | ||
1125 | #define OCFS2_XATTR_ENTRY_LOCAL 0x80 | |
1126 | #define OCFS2_XATTR_TYPE_MASK 0x7F | |
1127 | static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe, | |
1128 | int local) | |
1129 | { | |
1130 | if (local) | |
1131 | xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL; | |
1132 | else | |
1133 | xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL; | |
1134 | } | |
1135 | ||
1136 | static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe) | |
1137 | { | |
1138 | return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL; | |
1139 | } | |
1140 | ||
1141 | static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type) | |
1142 | { | |
1143 | xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK; | |
1144 | } | |
1145 | ||
1146 | static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe) | |
1147 | { | |
1148 | return xe->xe_type & OCFS2_XATTR_TYPE_MASK; | |
1149 | } | |
1150 | ||
9e33d69f JK |
1151 | /* |
1152 | * On disk structures for global quota file | |
1153 | */ | |
1154 | ||
1155 | /* Magic numbers and known versions for global quota files */ | |
1156 | #define OCFS2_GLOBAL_QMAGICS {\ | |
1157 | 0x0cf52470, /* USRQUOTA */ \ | |
1158 | 0x0cf52471 /* GRPQUOTA */ \ | |
1159 | } | |
1160 | ||
1161 | #define OCFS2_GLOBAL_QVERSIONS {\ | |
1162 | 0, \ | |
1163 | 0, \ | |
1164 | } | |
1165 | ||
1166 | ||
1167 | /* Each block of each quota file has a certain fixed number of bytes reserved | |
1168 | * for OCFS2 internal use at its end. OCFS2 can use it for things like | |
1169 | * checksums, etc. */ | |
1170 | #define OCFS2_QBLK_RESERVED_SPACE 8 | |
1171 | ||
1172 | /* Generic header of all quota files */ | |
1173 | struct ocfs2_disk_dqheader { | |
1174 | __le32 dqh_magic; /* Magic number identifying file */ | |
1175 | __le32 dqh_version; /* Quota format version */ | |
1176 | }; | |
1177 | ||
1178 | #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader)) | |
1179 | ||
1180 | /* Information header of global quota file (immediately follows the generic | |
1181 | * header) */ | |
1182 | struct ocfs2_global_disk_dqinfo { | |
1183 | /*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */ | |
1184 | __le32 dqi_igrace; /* Grace time for inode softlimit excess */ | |
1185 | __le32 dqi_syncms; /* Time after which we sync local changes to | |
1186 | * global quota file */ | |
1187 | __le32 dqi_blocks; /* Number of blocks in quota file */ | |
1188 | /*10*/ __le32 dqi_free_blk; /* First free block in quota file */ | |
1189 | __le32 dqi_free_entry; /* First block with free dquot entry in quota | |
1190 | * file */ | |
1191 | }; | |
1192 | ||
1193 | /* Structure with global user / group information. We reserve some space | |
1194 | * for future use. */ | |
1195 | struct ocfs2_global_disk_dqblk { | |
1196 | /*00*/ __le32 dqb_id; /* ID the structure belongs to */ | |
1197 | __le32 dqb_use_count; /* Number of nodes having reference to this structure */ | |
1198 | __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */ | |
1199 | /*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */ | |
1200 | __le64 dqb_curinodes; /* current # allocated inodes */ | |
1201 | /*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */ | |
1202 | __le64 dqb_bsoftlimit; /* preferred limit on disk space */ | |
1203 | /*30*/ __le64 dqb_curspace; /* current space occupied */ | |
1204 | __le64 dqb_btime; /* time limit for excessive disk use */ | |
1205 | /*40*/ __le64 dqb_itime; /* time limit for excessive inode use */ | |
1206 | __le64 dqb_pad1; | |
1207 | /*50*/ __le64 dqb_pad2; | |
1208 | }; | |
1209 | ||
1210 | /* | |
1211 | * On-disk structures for local quota file | |
1212 | */ | |
1213 | ||
1214 | /* Magic numbers and known versions for local quota files */ | |
1215 | #define OCFS2_LOCAL_QMAGICS {\ | |
1216 | 0x0cf524c0, /* USRQUOTA */ \ | |
1217 | 0x0cf524c1 /* GRPQUOTA */ \ | |
1218 | } | |
1219 | ||
1220 | #define OCFS2_LOCAL_QVERSIONS {\ | |
1221 | 0, \ | |
1222 | 0, \ | |
1223 | } | |
1224 | ||
1225 | /* Quota flags in dqinfo header */ | |
1226 | #define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\ | |
1227 | * quota has been cleanly turned off) */ | |
1228 | ||
1229 | #define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader)) | |
1230 | ||
1231 | /* Information header of local quota file (immediately follows the generic | |
1232 | * header) */ | |
1233 | struct ocfs2_local_disk_dqinfo { | |
1234 | __le32 dqi_flags; /* Flags for quota file */ | |
1235 | __le32 dqi_chunks; /* Number of chunks of quota structures | |
1236 | * with a bitmap */ | |
1237 | __le32 dqi_blocks; /* Number of blocks allocated for quota file */ | |
1238 | }; | |
1239 | ||
1240 | /* Header of one chunk of a quota file */ | |
1241 | struct ocfs2_local_disk_chunk { | |
1242 | __le32 dqc_free; /* Number of free entries in the bitmap */ | |
93654540 | 1243 | __u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding |
9e33d69f JK |
1244 | * chunk of quota file */ |
1245 | }; | |
1246 | ||
1247 | /* One entry in local quota file */ | |
1248 | struct ocfs2_local_disk_dqblk { | |
1249 | /*00*/ __le64 dqb_id; /* id this quota applies to */ | |
1250 | __le64 dqb_spacemod; /* Change in the amount of used space */ | |
1251 | /*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */ | |
1252 | }; | |
1253 | ||
ab552d54 JB |
1254 | |
1255 | /* | |
1256 | * The quota trailer lives at the end of each quota block. | |
1257 | */ | |
1258 | ||
1259 | struct ocfs2_disk_dqtrailer { | |
1260 | /*00*/ struct ocfs2_block_check dq_check; /* Error checking */ | |
1261 | /*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */ | |
1262 | }; | |
1263 | ||
1264 | static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize, | |
1265 | void *buf) | |
1266 | { | |
1267 | char *ptr = buf; | |
1268 | ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE; | |
1269 | ||
1270 | return (struct ocfs2_disk_dqtrailer *)ptr; | |
1271 | } | |
1272 | ||
ccd979bd MF |
1273 | #ifdef __KERNEL__ |
1274 | static inline int ocfs2_fast_symlink_chars(struct super_block *sb) | |
1275 | { | |
1276 | return sb->s_blocksize - | |
1277 | offsetof(struct ocfs2_dinode, id2.i_symlink); | |
1278 | } | |
1279 | ||
fdd77704 TY |
1280 | static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb, |
1281 | struct ocfs2_dinode *di) | |
1282 | { | |
1283 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); | |
1284 | ||
1285 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) | |
1286 | return sb->s_blocksize - | |
1287 | offsetof(struct ocfs2_dinode, id2.i_data.id_data) - | |
1288 | xattrsize; | |
1289 | else | |
1290 | return sb->s_blocksize - | |
1291 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); | |
1292 | } | |
1293 | ||
ccd979bd MF |
1294 | static inline int ocfs2_extent_recs_per_inode(struct super_block *sb) |
1295 | { | |
1296 | int size; | |
1297 | ||
1298 | size = sb->s_blocksize - | |
1299 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); | |
1300 | ||
1301 | return size / sizeof(struct ocfs2_extent_rec); | |
1302 | } | |
1303 | ||
fdd77704 TY |
1304 | static inline int ocfs2_extent_recs_per_inode_with_xattr( |
1305 | struct super_block *sb, | |
1306 | struct ocfs2_dinode *di) | |
1307 | { | |
1308 | int size; | |
1309 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); | |
1310 | ||
1311 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) | |
1312 | size = sb->s_blocksize - | |
1313 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs) - | |
1314 | xattrsize; | |
1315 | else | |
1316 | size = sb->s_blocksize - | |
1317 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); | |
1318 | ||
1319 | return size / sizeof(struct ocfs2_extent_rec); | |
1320 | } | |
1321 | ||
9b7895ef MF |
1322 | static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb) |
1323 | { | |
1324 | int size; | |
1325 | ||
1326 | size = sb->s_blocksize - | |
1327 | offsetof(struct ocfs2_dx_root_block, dr_list.l_recs); | |
1328 | ||
1329 | return size / sizeof(struct ocfs2_extent_rec); | |
1330 | } | |
1331 | ||
ccd979bd MF |
1332 | static inline int ocfs2_chain_recs_per_inode(struct super_block *sb) |
1333 | { | |
1334 | int size; | |
1335 | ||
1336 | size = sb->s_blocksize - | |
1337 | offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); | |
1338 | ||
1339 | return size / sizeof(struct ocfs2_chain_rec); | |
1340 | } | |
1341 | ||
1342 | static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb) | |
1343 | { | |
1344 | int size; | |
1345 | ||
1346 | size = sb->s_blocksize - | |
1347 | offsetof(struct ocfs2_extent_block, h_list.l_recs); | |
1348 | ||
1349 | return size / sizeof(struct ocfs2_extent_rec); | |
1350 | } | |
1351 | ||
798db35f JB |
1352 | static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb) |
1353 | { | |
1354 | int size; | |
1355 | ||
1356 | size = sb->s_blocksize - | |
1357 | offsetof(struct ocfs2_group_desc, bg_list.l_recs); | |
1358 | ||
1359 | return size / sizeof(struct ocfs2_extent_rec); | |
1360 | } | |
1361 | ||
9b7895ef MF |
1362 | static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb) |
1363 | { | |
1364 | int size; | |
1365 | ||
1366 | size = sb->s_blocksize - | |
1367 | offsetof(struct ocfs2_dx_leaf, dl_list.de_entries); | |
1368 | ||
1369 | return size / sizeof(struct ocfs2_dx_entry); | |
1370 | } | |
1371 | ||
4ed8a6bb MF |
1372 | static inline int ocfs2_dx_entries_per_root(struct super_block *sb) |
1373 | { | |
1374 | int size; | |
1375 | ||
1376 | size = sb->s_blocksize - | |
1377 | offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries); | |
1378 | ||
1379 | return size / sizeof(struct ocfs2_dx_entry); | |
1380 | } | |
1381 | ||
ccd979bd MF |
1382 | static inline u16 ocfs2_local_alloc_size(struct super_block *sb) |
1383 | { | |
1384 | u16 size; | |
1385 | ||
1386 | size = sb->s_blocksize - | |
1387 | offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); | |
1388 | ||
1389 | return size; | |
1390 | } | |
1391 | ||
4cbe4249 | 1392 | static inline int ocfs2_group_bitmap_size(struct super_block *sb, |
8571882c TM |
1393 | int suballocator, |
1394 | u32 feature_incompat) | |
ccd979bd | 1395 | { |
8571882c TM |
1396 | int size = sb->s_blocksize - |
1397 | offsetof(struct ocfs2_group_desc, bg_bitmap); | |
ccd979bd | 1398 | |
8571882c TM |
1399 | /* |
1400 | * The cluster allocator uses the entire block. Suballocators have | |
1401 | * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older | |
1402 | * code expects bg_size set to the maximum. Thus we must keep | |
1403 | * bg_size as-is unless discontig_bg is enabled. | |
1404 | */ | |
1405 | if (suballocator && | |
1406 | (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG)) | |
4cbe4249 | 1407 | size = OCFS2_MAX_BG_BITMAP_SIZE; |
ccd979bd MF |
1408 | |
1409 | return size; | |
1410 | } | |
1411 | ||
1412 | static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb) | |
1413 | { | |
1414 | int size; | |
1415 | ||
1416 | size = sb->s_blocksize - | |
1417 | offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); | |
1418 | ||
1419 | return size / sizeof(struct ocfs2_truncate_rec); | |
1420 | } | |
50af94b1 MF |
1421 | |
1422 | static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index) | |
1423 | { | |
1424 | u64 offset = OCFS2_BACKUP_SB_START; | |
1425 | ||
1426 | if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { | |
1427 | offset <<= (2 * index); | |
a8a75a20 | 1428 | offset >>= sb->s_blocksize_bits; |
50af94b1 MF |
1429 | return offset; |
1430 | } | |
1431 | ||
1432 | return 0; | |
1433 | ||
1434 | } | |
0c044f0b TM |
1435 | |
1436 | static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb) | |
1437 | { | |
1438 | int size; | |
1439 | ||
1440 | size = sb->s_blocksize - | |
1441 | offsetof(struct ocfs2_xattr_block, | |
1442 | xb_attrs.xb_root.xt_list.l_recs); | |
1443 | ||
1444 | return size / sizeof(struct ocfs2_extent_rec); | |
1445 | } | |
721f69c4 TM |
1446 | |
1447 | static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb) | |
1448 | { | |
1449 | int size; | |
1450 | ||
1451 | size = sb->s_blocksize - | |
1452 | offsetof(struct ocfs2_refcount_block, rf_list.l_recs); | |
1453 | ||
1454 | return size / sizeof(struct ocfs2_extent_rec); | |
1455 | } | |
1456 | ||
1457 | static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb) | |
1458 | { | |
1459 | int size; | |
1460 | ||
1461 | size = sb->s_blocksize - | |
1462 | offsetof(struct ocfs2_refcount_block, rf_records.rl_recs); | |
1463 | ||
1464 | return size / sizeof(struct ocfs2_refcount_rec); | |
1465 | } | |
e73a819d TM |
1466 | |
1467 | static inline u32 | |
1468 | ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec) | |
1469 | { | |
1470 | return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK; | |
1471 | } | |
ccd979bd MF |
1472 | #else |
1473 | static inline int ocfs2_fast_symlink_chars(int blocksize) | |
1474 | { | |
1475 | return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink); | |
1476 | } | |
1477 | ||
1097df3f TM |
1478 | static inline int ocfs2_max_inline_data_with_xattr(int blocksize, |
1479 | struct ocfs2_dinode *di) | |
15b1e36b | 1480 | { |
1097df3f TM |
1481 | if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL)) |
1482 | return blocksize - | |
1483 | offsetof(struct ocfs2_dinode, id2.i_data.id_data) - | |
1484 | di->i_xattr_inline_size; | |
1485 | else | |
1486 | return blocksize - | |
1487 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); | |
15b1e36b MF |
1488 | } |
1489 | ||
ccd979bd MF |
1490 | static inline int ocfs2_extent_recs_per_inode(int blocksize) |
1491 | { | |
1492 | int size; | |
1493 | ||
1494 | size = blocksize - | |
1495 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); | |
1496 | ||
1497 | return size / sizeof(struct ocfs2_extent_rec); | |
1498 | } | |
1499 | ||
1500 | static inline int ocfs2_chain_recs_per_inode(int blocksize) | |
1501 | { | |
1502 | int size; | |
1503 | ||
1504 | size = blocksize - | |
1505 | offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); | |
1506 | ||
1507 | return size / sizeof(struct ocfs2_chain_rec); | |
1508 | } | |
1509 | ||
1510 | static inline int ocfs2_extent_recs_per_eb(int blocksize) | |
1511 | { | |
1512 | int size; | |
1513 | ||
1514 | size = blocksize - | |
1515 | offsetof(struct ocfs2_extent_block, h_list.l_recs); | |
1516 | ||
1517 | return size / sizeof(struct ocfs2_extent_rec); | |
1518 | } | |
1519 | ||
798db35f JB |
1520 | static inline int ocfs2_extent_recs_per_gd(int blocksize) |
1521 | { | |
1522 | int size; | |
1523 | ||
1524 | size = blocksize - | |
1525 | offsetof(struct ocfs2_group_desc, bg_list.l_recs); | |
1526 | ||
1527 | return size / sizeof(struct ocfs2_extent_rec); | |
1528 | } | |
1529 | ||
ccd979bd MF |
1530 | static inline int ocfs2_local_alloc_size(int blocksize) |
1531 | { | |
1532 | int size; | |
1533 | ||
1534 | size = blocksize - | |
1535 | offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); | |
1536 | ||
1537 | return size; | |
1538 | } | |
1539 | ||
8571882c TM |
1540 | static inline int ocfs2_group_bitmap_size(int blocksize, |
1541 | int suballocator, | |
1542 | uint32_t feature_incompat) | |
ccd979bd | 1543 | { |
8571882c TM |
1544 | int size = sb->s_blocksize - |
1545 | offsetof(struct ocfs2_group_desc, bg_bitmap); | |
ccd979bd | 1546 | |
8571882c TM |
1547 | /* |
1548 | * The cluster allocator uses the entire block. Suballocators have | |
1549 | * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older | |
1550 | * code expects bg_size set to the maximum. Thus we must keep | |
1551 | * bg_size as-is unless discontig_bg is enabled. | |
1552 | */ | |
1553 | if (suballocator && | |
1554 | (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG)) | |
4cbe4249 | 1555 | size = OCFS2_MAX_BG_BITMAP_SIZE; |
ccd979bd MF |
1556 | |
1557 | return size; | |
1558 | } | |
1559 | ||
1560 | static inline int ocfs2_truncate_recs_per_inode(int blocksize) | |
1561 | { | |
1562 | int size; | |
1563 | ||
1564 | size = blocksize - | |
1565 | offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); | |
1566 | ||
1567 | return size / sizeof(struct ocfs2_truncate_rec); | |
1568 | } | |
50af94b1 MF |
1569 | |
1570 | static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index) | |
1571 | { | |
1572 | uint64_t offset = OCFS2_BACKUP_SB_START; | |
1573 | ||
1574 | if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { | |
1575 | offset <<= (2 * index); | |
1576 | offset /= blocksize; | |
1577 | return offset; | |
1578 | } | |
1579 | ||
1580 | return 0; | |
1581 | } | |
0c044f0b TM |
1582 | |
1583 | static inline int ocfs2_xattr_recs_per_xb(int blocksize) | |
1584 | { | |
1585 | int size; | |
1586 | ||
1587 | size = blocksize - | |
1588 | offsetof(struct ocfs2_xattr_block, | |
1589 | xb_attrs.xb_root.xt_list.l_recs); | |
1590 | ||
1591 | return size / sizeof(struct ocfs2_extent_rec); | |
1592 | } | |
ccd979bd MF |
1593 | #endif /* __KERNEL__ */ |
1594 | ||
1595 | ||
1596 | static inline int ocfs2_system_inode_is_global(int type) | |
1597 | { | |
1598 | return ((type >= 0) && | |
1599 | (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)); | |
1600 | } | |
1601 | ||
1602 | static inline int ocfs2_sprintf_system_inode_name(char *buf, int len, | |
1603 | int type, int slot) | |
1604 | { | |
1605 | int chars; | |
1606 | ||
1607 | /* | |
1608 | * Global system inodes can only have one copy. Everything | |
1609 | * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode | |
1610 | * list has a copy per slot. | |
1611 | */ | |
1612 | if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE) | |
fe9f3877 | 1613 | chars = snprintf(buf, len, "%s", |
ccd979bd MF |
1614 | ocfs2_system_inodes[type].si_name); |
1615 | else | |
1616 | chars = snprintf(buf, len, | |
1617 | ocfs2_system_inodes[type].si_name, | |
1618 | slot); | |
1619 | ||
1620 | return chars; | |
1621 | } | |
1622 | ||
1623 | static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de, | |
1624 | umode_t mode) | |
1625 | { | |
1626 | de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; | |
1627 | } | |
1628 | ||
af2bf0d8 TM |
1629 | static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd) |
1630 | { | |
1631 | if ((offsetof(struct ocfs2_group_desc, bg_bitmap) + | |
1632 | le16_to_cpu(gd->bg_size)) != | |
1633 | offsetof(struct ocfs2_group_desc, bg_list)) | |
1634 | return 0; | |
1635 | /* | |
1636 | * Only valid to check l_next_free_rec if | |
1637 | * bg_bitmap + bg_size == bg_list. | |
1638 | */ | |
1639 | if (!gd->bg_list.l_next_free_rec) | |
1640 | return 0; | |
1641 | return 1; | |
1642 | } | |
ccd979bd MF |
1643 | #endif /* _OCFS2_FS_H */ |
1644 |