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