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" |
ccd979bd MF |
68 | |
69 | /* Compatibility flags */ | |
70 | #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \ | |
71 | ( OCFS2_SB(sb)->s_feature_compat & (mask) ) | |
72 | #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \ | |
73 | ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) ) | |
74 | #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \ | |
75 | ( OCFS2_SB(sb)->s_feature_incompat & (mask) ) | |
76 | #define OCFS2_SET_COMPAT_FEATURE(sb,mask) \ | |
77 | OCFS2_SB(sb)->s_feature_compat |= (mask) | |
78 | #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \ | |
79 | OCFS2_SB(sb)->s_feature_ro_compat |= (mask) | |
80 | #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \ | |
81 | OCFS2_SB(sb)->s_feature_incompat |= (mask) | |
82 | #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \ | |
83 | OCFS2_SB(sb)->s_feature_compat &= ~(mask) | |
84 | #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ | |
85 | OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask) | |
86 | #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \ | |
87 | OCFS2_SB(sb)->s_feature_incompat &= ~(mask) | |
88 | ||
a9772189 JB |
89 | #define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \ |
90 | | OCFS2_FEATURE_COMPAT_JBD2_SB) | |
dcd0538f | 91 | #define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \ |
15b1e36b | 92 | | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \ |
386a2ef8 | 93 | | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \ |
b61817e1 | 94 | | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \ |
8154da3d TY |
95 | | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \ |
96 | | OCFS2_FEATURE_INCOMPAT_XATTR) | |
1a224ad1 | 97 | #define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN) |
ccd979bd MF |
98 | |
99 | /* | |
100 | * Heartbeat-only devices are missing journals and other files. The | |
101 | * filesystem driver can't load them, but the library can. Never put | |
102 | * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*. | |
103 | */ | |
104 | #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002 | |
105 | ||
8903901d MF |
106 | /* |
107 | * tunefs sets this incompat flag before starting the resize and clears it | |
108 | * at the end. This flag protects users from inadvertently mounting the fs | |
109 | * after an aborted run without fsck-ing. | |
110 | */ | |
111 | #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004 | |
ccd979bd | 112 | |
c271c5c2 SM |
113 | /* Used to denote a non-clustered volume */ |
114 | #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008 | |
115 | ||
8903901d MF |
116 | /* Support for sparse allocation in b-trees */ |
117 | #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010 | |
118 | ||
92e91ce2 MF |
119 | /* |
120 | * Tunefs sets this incompat flag before starting an operation which | |
121 | * would require cleanup on abort. This is done to protect users from | |
122 | * inadvertently mounting the fs after an aborted run without | |
123 | * fsck-ing. | |
124 | * | |
125 | * s_tunefs_flags on the super block describes precisely which | |
126 | * operations were in progress. | |
127 | */ | |
128 | #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020 | |
129 | ||
15b1e36b MF |
130 | /* Support for data packed into inode blocks */ |
131 | #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040 | |
132 | ||
b61817e1 JB |
133 | /* |
134 | * Support for alternate, userspace cluster stacks. If set, the superblock | |
135 | * field s_cluster_info contains a tag for the alternate stack in use as | |
136 | * well as the name of the cluster being joined. | |
137 | * mount.ocfs2 must pass in a matching stack name. | |
138 | * | |
139 | * If not set, the classic stack will be used. This is compatbile with | |
140 | * all older versions. | |
141 | */ | |
142 | #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080 | |
143 | ||
8154da3d TY |
144 | /* Support for the extended slot map */ |
145 | #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100 | |
146 | ||
147 | /* Support for extended attributes */ | |
148 | #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200 | |
149 | ||
50af94b1 MF |
150 | /* |
151 | * backup superblock flag is used to indicate that this volume | |
152 | * has backup superblocks. | |
153 | */ | |
154 | #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001 | |
155 | ||
a9772189 JB |
156 | /* |
157 | * The filesystem will correctly handle journal feature bits. | |
158 | */ | |
159 | #define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002 | |
160 | ||
328d5752 MF |
161 | /* |
162 | * Unwritten extents support. | |
163 | */ | |
164 | #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001 | |
165 | ||
1a224ad1 JK |
166 | /* |
167 | * Maintain quota information for this filesystem | |
168 | */ | |
169 | #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002 | |
170 | #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004 | |
171 | ||
50af94b1 MF |
172 | /* The byte offset of the first backup block will be 1G. |
173 | * The following will be 4G, 16G, 64G, 256G and 1T. | |
174 | */ | |
175 | #define OCFS2_BACKUP_SB_START 1 << 30 | |
176 | ||
177 | /* the max backup superblock nums */ | |
178 | #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6 | |
179 | ||
92e91ce2 MF |
180 | /* |
181 | * Flags on ocfs2_super_block.s_tunefs_flags | |
182 | */ | |
183 | #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */ | |
184 | ||
ccd979bd MF |
185 | /* |
186 | * Flags on ocfs2_dinode.i_flags | |
187 | */ | |
188 | #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */ | |
189 | #define OCFS2_UNUSED2_FL (0x00000002) | |
190 | #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */ | |
191 | #define OCFS2_UNUSED3_FL (0x00000008) | |
192 | /* System inode flags */ | |
193 | #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */ | |
194 | #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */ | |
195 | #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */ | |
196 | #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */ | |
197 | #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */ | |
198 | #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */ | |
199 | #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */ | |
200 | #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */ | |
1a224ad1 | 201 | #define OCFS2_QUOTA_FL (0x00001000) /* Quota file */ |
ccd979bd | 202 | |
15b1e36b MF |
203 | /* |
204 | * Flags on ocfs2_dinode.i_dyn_features | |
205 | * | |
206 | * These can change much more often than i_flags. When adding flags, | |
207 | * keep in mind that i_dyn_features is only 16 bits wide. | |
208 | */ | |
209 | #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */ | |
210 | #define OCFS2_HAS_XATTR_FL (0x0002) | |
211 | #define OCFS2_INLINE_XATTR_FL (0x0004) | |
212 | #define OCFS2_INDEXED_DIR_FL (0x0008) | |
213 | ||
ca4d147e HP |
214 | /* Inode attributes, keep in sync with EXT2 */ |
215 | #define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */ | |
216 | #define OCFS2_UNRM_FL (0x00000002) /* Undelete */ | |
217 | #define OCFS2_COMPR_FL (0x00000004) /* Compress file */ | |
218 | #define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */ | |
219 | #define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */ | |
220 | #define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */ | |
221 | #define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */ | |
222 | #define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */ | |
223 | #define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */ | |
224 | ||
225 | #define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */ | |
226 | #define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */ | |
227 | ||
e48edee2 MF |
228 | /* |
229 | * Extent record flags (e_node.leaf.flags) | |
230 | */ | |
231 | #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but | |
232 | * unwritten */ | |
233 | ||
ca4d147e HP |
234 | /* |
235 | * ioctl commands | |
236 | */ | |
237 | #define OCFS2_IOC_GETFLAGS _IOR('f', 1, long) | |
238 | #define OCFS2_IOC_SETFLAGS _IOW('f', 2, long) | |
586d232b MF |
239 | #define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int) |
240 | #define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int) | |
ca4d147e | 241 | |
b2580103 MF |
242 | /* |
243 | * Space reservation / allocation / free ioctls and argument structure | |
244 | * are designed to be compatible with XFS. | |
245 | * | |
246 | * ALLOCSP* and FREESP* are not and will never be supported, but are | |
247 | * included here for completeness. | |
248 | */ | |
249 | struct ocfs2_space_resv { | |
250 | __s16 l_type; | |
251 | __s16 l_whence; | |
252 | __s64 l_start; | |
253 | __s64 l_len; /* len == 0 means until end of file */ | |
254 | __s32 l_sysid; | |
255 | __u32 l_pid; | |
256 | __s32 l_pad[4]; /* reserve area */ | |
257 | }; | |
258 | ||
259 | #define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv) | |
260 | #define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv) | |
261 | #define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv) | |
262 | #define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv) | |
263 | #define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv) | |
264 | #define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv) | |
265 | #define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv) | |
266 | #define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv) | |
267 | ||
7909f2bf TM |
268 | /* Used to pass group descriptor data when online resize is done */ |
269 | struct ocfs2_new_group_input { | |
270 | __u64 group; /* Group descriptor's blkno. */ | |
271 | __u32 clusters; /* Total number of clusters in this group */ | |
272 | __u32 frees; /* Total free clusters in this group */ | |
273 | __u16 chain; /* Chain for this group */ | |
274 | __u16 reserved1; | |
275 | __u32 reserved2; | |
276 | }; | |
277 | ||
d659072f | 278 | #define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int) |
7909f2bf TM |
279 | #define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input) |
280 | #define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input) | |
d659072f | 281 | |
ccd979bd MF |
282 | /* |
283 | * Journal Flags (ocfs2_dinode.id1.journal1.i_flags) | |
284 | */ | |
285 | #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */ | |
286 | ||
287 | /* | |
288 | * superblock s_state flags | |
289 | */ | |
290 | #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */ | |
291 | ||
292 | /* Limit of space in ocfs2_dir_entry */ | |
293 | #define OCFS2_MAX_FILENAME_LEN 255 | |
294 | ||
295 | /* Maximum slots on an ocfs2 file system */ | |
296 | #define OCFS2_MAX_SLOTS 255 | |
297 | ||
298 | /* Slot map indicator for an empty slot */ | |
299 | #define OCFS2_INVALID_SLOT -1 | |
300 | ||
301 | #define OCFS2_VOL_UUID_LEN 16 | |
302 | #define OCFS2_MAX_VOL_LABEL_LEN 64 | |
303 | ||
b61817e1 JB |
304 | /* The alternate, userspace stack fields */ |
305 | #define OCFS2_STACK_LABEL_LEN 4 | |
306 | #define OCFS2_CLUSTER_NAME_LEN 16 | |
307 | ||
ccd979bd MF |
308 | /* Journal limits (in bytes) */ |
309 | #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024) | |
ccd979bd | 310 | |
2fbe8d1e SM |
311 | /* |
312 | * Default local alloc size (in megabytes) | |
313 | * | |
314 | * The value chosen should be such that most allocations, including new | |
315 | * block groups, use local alloc. | |
316 | */ | |
317 | #define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8 | |
318 | ||
fdd77704 TY |
319 | /* |
320 | * Inline extended attribute size (in bytes) | |
321 | * The value chosen should be aligned to 16 byte boundaries. | |
322 | */ | |
323 | #define OCFS2_MIN_XATTR_INLINE_SIZE 256 | |
324 | ||
ccd979bd MF |
325 | struct ocfs2_system_inode_info { |
326 | char *si_name; | |
327 | int si_iflags; | |
328 | int si_mode; | |
329 | }; | |
330 | ||
331 | /* System file index */ | |
332 | enum { | |
333 | BAD_BLOCK_SYSTEM_INODE = 0, | |
334 | GLOBAL_INODE_ALLOC_SYSTEM_INODE, | |
335 | SLOT_MAP_SYSTEM_INODE, | |
336 | #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE | |
337 | HEARTBEAT_SYSTEM_INODE, | |
338 | GLOBAL_BITMAP_SYSTEM_INODE, | |
1a224ad1 JK |
339 | USER_QUOTA_SYSTEM_INODE, |
340 | GROUP_QUOTA_SYSTEM_INODE, | |
341 | #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE | |
ccd979bd MF |
342 | ORPHAN_DIR_SYSTEM_INODE, |
343 | EXTENT_ALLOC_SYSTEM_INODE, | |
344 | INODE_ALLOC_SYSTEM_INODE, | |
345 | JOURNAL_SYSTEM_INODE, | |
346 | LOCAL_ALLOC_SYSTEM_INODE, | |
347 | TRUNCATE_LOG_SYSTEM_INODE, | |
1a224ad1 JK |
348 | LOCAL_USER_QUOTA_SYSTEM_INODE, |
349 | LOCAL_GROUP_QUOTA_SYSTEM_INODE, | |
ccd979bd MF |
350 | NUM_SYSTEM_INODES |
351 | }; | |
352 | ||
353 | static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { | |
354 | /* Global system inodes (single copy) */ | |
355 | /* The first two are only used from userspace mfks/tunefs */ | |
356 | [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 }, | |
357 | [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, | |
358 | ||
359 | /* These are used by the running filesystem */ | |
360 | [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 }, | |
361 | [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 }, | |
362 | [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 }, | |
1a224ad1 JK |
363 | [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
364 | [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 }, | |
ccd979bd MF |
365 | |
366 | /* Slot-specific system inodes (one copy per slot) */ | |
367 | [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 }, | |
368 | [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, | |
369 | [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, | |
370 | [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 }, | |
371 | [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 }, | |
1a224ad1 JK |
372 | [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }, |
373 | [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 }, | |
374 | [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 }, | |
ccd979bd MF |
375 | }; |
376 | ||
377 | /* Parameter passed from mount.ocfs2 to module */ | |
378 | #define OCFS2_HB_NONE "heartbeat=none" | |
379 | #define OCFS2_HB_LOCAL "heartbeat=local" | |
380 | ||
381 | /* | |
382 | * OCFS2 directory file types. Only the low 3 bits are used. The | |
383 | * other bits are reserved for now. | |
384 | */ | |
385 | #define OCFS2_FT_UNKNOWN 0 | |
386 | #define OCFS2_FT_REG_FILE 1 | |
387 | #define OCFS2_FT_DIR 2 | |
388 | #define OCFS2_FT_CHRDEV 3 | |
389 | #define OCFS2_FT_BLKDEV 4 | |
390 | #define OCFS2_FT_FIFO 5 | |
391 | #define OCFS2_FT_SOCK 6 | |
392 | #define OCFS2_FT_SYMLINK 7 | |
393 | ||
394 | #define OCFS2_FT_MAX 8 | |
395 | ||
396 | /* | |
397 | * OCFS2_DIR_PAD defines the directory entries boundaries | |
398 | * | |
399 | * NOTE: It must be a multiple of 4 | |
400 | */ | |
401 | #define OCFS2_DIR_PAD 4 | |
402 | #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1) | |
403 | #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name) | |
404 | #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \ | |
405 | OCFS2_DIR_ROUND) & \ | |
406 | ~OCFS2_DIR_ROUND) | |
407 | ||
408 | #define OCFS2_LINK_MAX 32000 | |
409 | ||
410 | #define S_SHIFT 12 | |
411 | static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = { | |
412 | [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE, | |
413 | [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR, | |
414 | [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV, | |
415 | [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV, | |
416 | [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO, | |
417 | [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK, | |
418 | [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK, | |
419 | }; | |
420 | ||
421 | ||
422 | /* | |
423 | * Convenience casts | |
424 | */ | |
425 | #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super)) | |
426 | ||
427 | /* | |
428 | * On disk extent record for OCFS2 | |
429 | * It describes a range of clusters on disk. | |
e48edee2 MF |
430 | * |
431 | * Length fields are divided into interior and leaf node versions. | |
432 | * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes. | |
ccd979bd MF |
433 | */ |
434 | struct ocfs2_extent_rec { | |
435 | /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */ | |
e48edee2 MF |
436 | union { |
437 | __le32 e_int_clusters; /* Clusters covered by all children */ | |
438 | struct { | |
439 | __le16 e_leaf_clusters; /* Clusters covered by this | |
440 | extent */ | |
441 | __u8 e_reserved1; | |
442 | __u8 e_flags; /* Extent flags */ | |
443 | }; | |
444 | }; | |
ccd979bd MF |
445 | __le64 e_blkno; /* Physical disk offset, in blocks */ |
446 | /*10*/ | |
447 | }; | |
448 | ||
449 | struct ocfs2_chain_rec { | |
450 | __le32 c_free; /* Number of free bits in this chain. */ | |
451 | __le32 c_total; /* Number of total bits in this chain */ | |
452 | __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */ | |
453 | }; | |
454 | ||
455 | struct ocfs2_truncate_rec { | |
456 | __le32 t_start; /* 1st cluster in this log */ | |
457 | __le32 t_clusters; /* Number of total clusters covered */ | |
458 | }; | |
459 | ||
460 | /* | |
461 | * On disk extent list for OCFS2 (node in the tree). Note that this | |
462 | * is contained inside ocfs2_dinode or ocfs2_extent_block, so the | |
463 | * offsets are relative to ocfs2_dinode.id2.i_list or | |
464 | * ocfs2_extent_block.h_list, respectively. | |
465 | */ | |
466 | struct ocfs2_extent_list { | |
467 | /*00*/ __le16 l_tree_depth; /* Extent tree depth from this | |
468 | point. 0 means data extents | |
469 | hang directly off this | |
dcd0538f MF |
470 | header (a leaf) |
471 | NOTE: The high 8 bits cannot be | |
472 | used - tree_depth is never that big. | |
473 | */ | |
ccd979bd MF |
474 | __le16 l_count; /* Number of extent records */ |
475 | __le16 l_next_free_rec; /* Next unused extent slot */ | |
476 | __le16 l_reserved1; | |
477 | __le64 l_reserved2; /* Pad to | |
478 | sizeof(ocfs2_extent_rec) */ | |
479 | /*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */ | |
480 | }; | |
481 | ||
482 | /* | |
483 | * On disk allocation chain list for OCFS2. Note that this is | |
484 | * contained inside ocfs2_dinode, so the offsets are relative to | |
485 | * ocfs2_dinode.id2.i_chain. | |
486 | */ | |
487 | struct ocfs2_chain_list { | |
488 | /*00*/ __le16 cl_cpg; /* Clusters per Block Group */ | |
489 | __le16 cl_bpc; /* Bits per cluster */ | |
490 | __le16 cl_count; /* Total chains in this list */ | |
491 | __le16 cl_next_free_rec; /* Next unused chain slot */ | |
492 | __le64 cl_reserved1; | |
493 | /*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */ | |
494 | }; | |
495 | ||
496 | /* | |
497 | * On disk deallocation log for OCFS2. Note that this is | |
498 | * contained inside ocfs2_dinode, so the offsets are relative to | |
499 | * ocfs2_dinode.id2.i_dealloc. | |
500 | */ | |
501 | struct ocfs2_truncate_log { | |
502 | /*00*/ __le16 tl_count; /* Total records in this log */ | |
503 | __le16 tl_used; /* Number of records in use */ | |
504 | __le32 tl_reserved1; | |
505 | /*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */ | |
506 | }; | |
507 | ||
508 | /* | |
509 | * On disk extent block (indirect block) for OCFS2 | |
510 | */ | |
511 | struct ocfs2_extent_block | |
512 | { | |
513 | /*00*/ __u8 h_signature[8]; /* Signature for verification */ | |
514 | __le64 h_reserved1; | |
515 | /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this | |
516 | extent_header belongs to */ | |
517 | __le16 h_suballoc_bit; /* Bit offset in suballocator | |
518 | block group */ | |
519 | __le32 h_fs_generation; /* Must match super block */ | |
520 | __le64 h_blkno; /* Offset on disk, in blocks */ | |
521 | /*20*/ __le64 h_reserved3; | |
522 | __le64 h_next_leaf_blk; /* Offset on disk, in blocks, | |
523 | of next leaf header pointing | |
524 | to data */ | |
525 | /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */ | |
526 | /* Actual on-disk size is one block */ | |
527 | }; | |
528 | ||
fb86b1f0 JB |
529 | /* |
530 | * On disk slot map for OCFS2. This defines the contents of the "slot_map" | |
386a2ef8 JB |
531 | * system file. A slot is valid if it contains a node number >= 0. The |
532 | * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty. | |
fb86b1f0 JB |
533 | */ |
534 | struct ocfs2_slot_map { | |
535 | /*00*/ __le16 sm_slots[0]; | |
536 | /* | |
537 | * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255, | |
538 | * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize. | |
539 | */ | |
540 | }; | |
541 | ||
386a2ef8 JB |
542 | struct ocfs2_extended_slot { |
543 | /*00*/ __u8 es_valid; | |
544 | __u8 es_reserved1[3]; | |
545 | __le32 es_node_num; | |
546 | /*10*/ | |
547 | }; | |
548 | ||
549 | /* | |
550 | * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP | |
551 | * is set. It separates out the valid marker from the node number, and | |
552 | * has room to grow. Unlike the old slot map, this format is defined by | |
553 | * i_size. | |
554 | */ | |
555 | struct ocfs2_slot_map_extended { | |
556 | /*00*/ struct ocfs2_extended_slot se_slots[0]; | |
557 | /* | |
558 | * Actual size is i_size of the slot_map system file. It should | |
559 | * match s_max_slots * sizeof(struct ocfs2_extended_slot) | |
560 | */ | |
561 | }; | |
562 | ||
b61817e1 JB |
563 | struct ocfs2_cluster_info { |
564 | /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN]; | |
565 | __le32 ci_reserved; | |
566 | /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN]; | |
567 | /*18*/ | |
568 | }; | |
569 | ||
ccd979bd MF |
570 | /* |
571 | * On disk superblock for OCFS2 | |
572 | * Note that it is contained inside an ocfs2_dinode, so all offsets | |
573 | * are relative to the start of ocfs2_dinode.id2. | |
574 | */ | |
575 | struct ocfs2_super_block { | |
576 | /*00*/ __le16 s_major_rev_level; | |
577 | __le16 s_minor_rev_level; | |
578 | __le16 s_mnt_count; | |
579 | __le16 s_max_mnt_count; | |
580 | __le16 s_state; /* File system state */ | |
581 | __le16 s_errors; /* Behaviour when detecting errors */ | |
582 | __le32 s_checkinterval; /* Max time between checks */ | |
583 | /*10*/ __le64 s_lastcheck; /* Time of last check */ | |
584 | __le32 s_creator_os; /* OS */ | |
585 | __le32 s_feature_compat; /* Compatible feature set */ | |
586 | /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */ | |
587 | __le32 s_feature_ro_compat; /* Readonly-compatible feature set */ | |
588 | __le64 s_root_blkno; /* Offset, in blocks, of root directory | |
589 | dinode */ | |
590 | /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system | |
591 | directory dinode */ | |
592 | __le32 s_blocksize_bits; /* Blocksize for this fs */ | |
593 | __le32 s_clustersize_bits; /* Clustersize for this fs */ | |
594 | /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts | |
595 | before tunefs required */ | |
92e91ce2 | 596 | __le16 s_tunefs_flag; |
cf1d6c76 | 597 | __le32 s_uuid_hash; /* hash value of uuid */ |
ccd979bd MF |
598 | __le64 s_first_cluster_group; /* Block offset of 1st cluster |
599 | * group header */ | |
600 | /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */ | |
601 | /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */ | |
b61817e1 JB |
602 | /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace |
603 | stack. Only valid | |
604 | with INCOMPAT flag. */ | |
8154da3d TY |
605 | /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size |
606 | for this fs*/ | |
607 | __le16 s_reserved0; | |
608 | __le32 s_reserved1; | |
609 | /*C0*/ __le64 s_reserved2[16]; /* Fill out superblock */ | |
b61817e1 JB |
610 | /*140*/ |
611 | ||
612 | /* | |
613 | * NOTE: As stated above, all offsets are relative to | |
614 | * ocfs2_dinode.id2, which is at 0xC0 in the inode. | |
615 | * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within | |
616 | * our smallest blocksize, which is 512 bytes. To ensure this, | |
617 | * we reserve the space in s_reserved2. Anything past s_reserved2 | |
618 | * will not be available on the smallest blocksize. | |
619 | */ | |
ccd979bd MF |
620 | }; |
621 | ||
622 | /* | |
623 | * Local allocation bitmap for OCFS2 slots | |
624 | * Note that it exists inside an ocfs2_dinode, so all offsets are | |
625 | * relative to the start of ocfs2_dinode.id2. | |
626 | */ | |
627 | struct ocfs2_local_alloc | |
628 | { | |
629 | /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */ | |
630 | __le16 la_size; /* Size of included bitmap, in bytes */ | |
631 | __le16 la_reserved1; | |
632 | __le64 la_reserved2; | |
633 | /*10*/ __u8 la_bitmap[0]; | |
634 | }; | |
635 | ||
15b1e36b MF |
636 | /* |
637 | * Data-in-inode header. This is only used if i_dyn_features has | |
638 | * OCFS2_INLINE_DATA_FL set. | |
639 | */ | |
640 | struct ocfs2_inline_data | |
641 | { | |
642 | /*00*/ __le16 id_count; /* Number of bytes that can be used | |
643 | * for data, starting at id_data */ | |
644 | __le16 id_reserved0; | |
645 | __le32 id_reserved1; | |
646 | __u8 id_data[0]; /* Start of user data */ | |
647 | }; | |
648 | ||
ccd979bd MF |
649 | /* |
650 | * On disk inode for OCFS2 | |
651 | */ | |
652 | struct ocfs2_dinode { | |
653 | /*00*/ __u8 i_signature[8]; /* Signature for validation */ | |
654 | __le32 i_generation; /* Generation number */ | |
655 | __le16 i_suballoc_slot; /* Slot suballocator this inode | |
656 | belongs to */ | |
657 | __le16 i_suballoc_bit; /* Bit offset in suballocator | |
658 | block group */ | |
fdd77704 TY |
659 | /*10*/ __le16 i_reserved0; |
660 | __le16 i_xattr_inline_size; | |
ccd979bd MF |
661 | __le32 i_clusters; /* Cluster count */ |
662 | __le32 i_uid; /* Owner UID */ | |
663 | __le32 i_gid; /* Owning GID */ | |
664 | /*20*/ __le64 i_size; /* Size in bytes */ | |
665 | __le16 i_mode; /* File mode */ | |
666 | __le16 i_links_count; /* Links count */ | |
667 | __le32 i_flags; /* File flags */ | |
668 | /*30*/ __le64 i_atime; /* Access time */ | |
669 | __le64 i_ctime; /* Creation time */ | |
670 | /*40*/ __le64 i_mtime; /* Modification time */ | |
671 | __le64 i_dtime; /* Deletion time */ | |
672 | /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */ | |
673 | __le64 i_last_eb_blk; /* Pointer to last extent | |
674 | block */ | |
675 | /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */ | |
676 | __le32 i_atime_nsec; | |
677 | __le32 i_ctime_nsec; | |
678 | __le32 i_mtime_nsec; | |
fdd77704 | 679 | /*70*/ __le32 i_attr; |
50008630 TY |
680 | __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL |
681 | was set in i_flags */ | |
15b1e36b | 682 | __le16 i_dyn_features; |
fdd77704 TY |
683 | __le64 i_xattr_loc; |
684 | /*80*/ __le64 i_reserved2[7]; | |
ccd979bd MF |
685 | /*B8*/ union { |
686 | __le64 i_pad1; /* Generic way to refer to this | |
687 | 64bit union */ | |
688 | struct { | |
689 | __le64 i_rdev; /* Device number */ | |
690 | } dev1; | |
691 | struct { /* Info for bitmap system | |
692 | inodes */ | |
693 | __le32 i_used; /* Bits (ie, clusters) used */ | |
694 | __le32 i_total; /* Total bits (clusters) | |
695 | available */ | |
696 | } bitmap1; | |
697 | struct { /* Info for journal system | |
698 | inodes */ | |
699 | __le32 ij_flags; /* Mounted, version, etc. */ | |
c69991aa SM |
700 | __le32 ij_recovery_generation; /* Incremented when the |
701 | journal is recovered | |
702 | after an unclean | |
703 | shutdown */ | |
ccd979bd MF |
704 | } journal1; |
705 | } id1; /* Inode type dependant 1 */ | |
706 | /*C0*/ union { | |
707 | struct ocfs2_super_block i_super; | |
708 | struct ocfs2_local_alloc i_lab; | |
709 | struct ocfs2_chain_list i_chain; | |
710 | struct ocfs2_extent_list i_list; | |
711 | struct ocfs2_truncate_log i_dealloc; | |
15b1e36b | 712 | struct ocfs2_inline_data i_data; |
ccd979bd MF |
713 | __u8 i_symlink[0]; |
714 | } id2; | |
715 | /* Actual on-disk size is one block */ | |
716 | }; | |
717 | ||
718 | /* | |
719 | * On-disk directory entry structure for OCFS2 | |
720 | * | |
721 | * Packed as this structure could be accessed unaligned on 64-bit platforms | |
722 | */ | |
723 | struct ocfs2_dir_entry { | |
724 | /*00*/ __le64 inode; /* Inode number */ | |
725 | __le16 rec_len; /* Directory entry length */ | |
726 | __u8 name_len; /* Name length */ | |
727 | __u8 file_type; | |
728 | /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */ | |
729 | /* Actual on-disk length specified by rec_len */ | |
730 | } __attribute__ ((packed)); | |
731 | ||
732 | /* | |
733 | * On disk allocator group structure for OCFS2 | |
734 | */ | |
735 | struct ocfs2_group_desc | |
736 | { | |
737 | /*00*/ __u8 bg_signature[8]; /* Signature for validation */ | |
738 | __le16 bg_size; /* Size of included bitmap in | |
739 | bytes. */ | |
740 | __le16 bg_bits; /* Bits represented by this | |
741 | group. */ | |
742 | __le16 bg_free_bits_count; /* Free bits count */ | |
743 | __le16 bg_chain; /* What chain I am in. */ | |
744 | /*10*/ __le32 bg_generation; | |
745 | __le32 bg_reserved1; | |
746 | __le64 bg_next_group; /* Next group in my list, in | |
747 | blocks */ | |
748 | /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in | |
749 | blocks */ | |
750 | __le64 bg_blkno; /* Offset on disk, in blocks */ | |
751 | /*30*/ __le64 bg_reserved2[2]; | |
752 | /*40*/ __u8 bg_bitmap[0]; | |
753 | }; | |
754 | ||
5a7bc8eb TM |
755 | /* |
756 | * On disk extended attribute structure for OCFS2. | |
757 | */ | |
758 | ||
759 | /* | |
760 | * ocfs2_xattr_entry indicates one extend attribute. | |
761 | * | |
762 | * Note that it can be stored in inode, one block or one xattr bucket. | |
763 | */ | |
764 | struct ocfs2_xattr_entry { | |
765 | __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */ | |
8573f79d | 766 | __le16 xe_name_offset; /* byte offset from the 1st entry in the |
5a7bc8eb TM |
767 | local xattr storage(inode, xattr block or |
768 | xattr bucket). */ | |
769 | __u8 xe_name_len; /* xattr name len, does't include prefix. */ | |
8573f79d TM |
770 | __u8 xe_type; /* the low 7 bits indicate the name prefix |
771 | * type and the highest bit indicates whether | |
5a7bc8eb TM |
772 | * the EA is stored in the local storage. */ |
773 | __le64 xe_value_size; /* real xattr value length. */ | |
774 | }; | |
775 | ||
776 | /* | |
777 | * On disk structure for xattr header. | |
778 | * | |
779 | * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in | |
780 | * the local xattr storage. | |
781 | */ | |
782 | struct ocfs2_xattr_header { | |
783 | __le16 xh_count; /* contains the count of how | |
784 | many records are in the | |
785 | local xattr storage. */ | |
0c044f0b TM |
786 | __le16 xh_free_start; /* current offset for storing |
787 | xattr. */ | |
788 | __le16 xh_name_value_len; /* total length of name/value | |
789 | length in this bucket. */ | |
8573f79d TM |
790 | __le16 xh_num_buckets; /* Number of xattr buckets |
791 | in this extent record, | |
792 | only valid in the first | |
793 | bucket. */ | |
5a7bc8eb TM |
794 | __le64 xh_csum; |
795 | struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */ | |
796 | }; | |
797 | ||
798 | /* | |
799 | * On disk structure for xattr value root. | |
800 | * | |
8573f79d TM |
801 | * When an xattr's value is large enough, it is stored in an external |
802 | * b-tree like file data. The xattr value root points to this structure. | |
5a7bc8eb TM |
803 | */ |
804 | struct ocfs2_xattr_value_root { | |
805 | /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */ | |
806 | __le32 xr_reserved0; | |
807 | __le64 xr_last_eb_blk; /* Pointer to last extent block */ | |
808 | /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */ | |
809 | }; | |
810 | ||
811 | /* | |
812 | * On disk structure for xattr tree root. | |
813 | * | |
814 | * It is used when there are too many extended attributes for one file. These | |
815 | * attributes will be organized and stored in an indexed-btree. | |
816 | */ | |
817 | struct ocfs2_xattr_tree_root { | |
818 | /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */ | |
819 | __le32 xt_reserved0; | |
820 | __le64 xt_last_eb_blk; /* Pointer to last extent block */ | |
821 | /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */ | |
822 | }; | |
823 | ||
cf1d6c76 TY |
824 | #define OCFS2_XATTR_INDEXED 0x1 |
825 | #define OCFS2_HASH_SHIFT 5 | |
826 | #define OCFS2_XATTR_ROUND 3 | |
827 | #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \ | |
828 | ~(OCFS2_XATTR_ROUND)) | |
5a7bc8eb | 829 | |
0c044f0b TM |
830 | #define OCFS2_XATTR_BUCKET_SIZE 4096 |
831 | #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \ | |
832 | / OCFS2_MIN_BLOCKSIZE) | |
833 | ||
5a7bc8eb TM |
834 | /* |
835 | * On disk structure for xattr block. | |
836 | */ | |
837 | struct ocfs2_xattr_block { | |
838 | /*00*/ __u8 xb_signature[8]; /* Signature for verification */ | |
839 | __le16 xb_suballoc_slot; /* Slot suballocator this | |
840 | block belongs to. */ | |
841 | __le16 xb_suballoc_bit; /* Bit offset in suballocator | |
842 | block group */ | |
843 | __le32 xb_fs_generation; /* Must match super block */ | |
844 | /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */ | |
845 | __le64 xb_csum; | |
846 | /*20*/ __le16 xb_flags; /* Indicates whether this block contains | |
847 | real xattr or a xattr tree. */ | |
848 | __le16 xb_reserved0; | |
849 | __le32 xb_reserved1; | |
850 | __le64 xb_reserved2; | |
851 | /*30*/ union { | |
852 | struct ocfs2_xattr_header xb_header; /* xattr header if this | |
853 | block contains xattr */ | |
854 | struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this | |
855 | block cotains xattr | |
856 | tree. */ | |
857 | } xb_attrs; | |
858 | }; | |
859 | ||
860 | #define OCFS2_XATTR_ENTRY_LOCAL 0x80 | |
861 | #define OCFS2_XATTR_TYPE_MASK 0x7F | |
862 | static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe, | |
863 | int local) | |
864 | { | |
865 | if (local) | |
866 | xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL; | |
867 | else | |
868 | xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL; | |
869 | } | |
870 | ||
871 | static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe) | |
872 | { | |
873 | return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL; | |
874 | } | |
875 | ||
876 | static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type) | |
877 | { | |
878 | xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK; | |
879 | } | |
880 | ||
881 | static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe) | |
882 | { | |
883 | return xe->xe_type & OCFS2_XATTR_TYPE_MASK; | |
884 | } | |
885 | ||
ccd979bd MF |
886 | #ifdef __KERNEL__ |
887 | static inline int ocfs2_fast_symlink_chars(struct super_block *sb) | |
888 | { | |
889 | return sb->s_blocksize - | |
890 | offsetof(struct ocfs2_dinode, id2.i_symlink); | |
891 | } | |
892 | ||
15b1e36b MF |
893 | static inline int ocfs2_max_inline_data(struct super_block *sb) |
894 | { | |
895 | return sb->s_blocksize - | |
896 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); | |
897 | } | |
898 | ||
fdd77704 TY |
899 | static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb, |
900 | struct ocfs2_dinode *di) | |
901 | { | |
902 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); | |
903 | ||
904 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) | |
905 | return sb->s_blocksize - | |
906 | offsetof(struct ocfs2_dinode, id2.i_data.id_data) - | |
907 | xattrsize; | |
908 | else | |
909 | return sb->s_blocksize - | |
910 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); | |
911 | } | |
912 | ||
ccd979bd MF |
913 | static inline int ocfs2_extent_recs_per_inode(struct super_block *sb) |
914 | { | |
915 | int size; | |
916 | ||
917 | size = sb->s_blocksize - | |
918 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); | |
919 | ||
920 | return size / sizeof(struct ocfs2_extent_rec); | |
921 | } | |
922 | ||
fdd77704 TY |
923 | static inline int ocfs2_extent_recs_per_inode_with_xattr( |
924 | struct super_block *sb, | |
925 | struct ocfs2_dinode *di) | |
926 | { | |
927 | int size; | |
928 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); | |
929 | ||
930 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) | |
931 | size = sb->s_blocksize - | |
932 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs) - | |
933 | xattrsize; | |
934 | else | |
935 | size = sb->s_blocksize - | |
936 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); | |
937 | ||
938 | return size / sizeof(struct ocfs2_extent_rec); | |
939 | } | |
940 | ||
ccd979bd MF |
941 | static inline int ocfs2_chain_recs_per_inode(struct super_block *sb) |
942 | { | |
943 | int size; | |
944 | ||
945 | size = sb->s_blocksize - | |
946 | offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); | |
947 | ||
948 | return size / sizeof(struct ocfs2_chain_rec); | |
949 | } | |
950 | ||
951 | static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb) | |
952 | { | |
953 | int size; | |
954 | ||
955 | size = sb->s_blocksize - | |
956 | offsetof(struct ocfs2_extent_block, h_list.l_recs); | |
957 | ||
958 | return size / sizeof(struct ocfs2_extent_rec); | |
959 | } | |
960 | ||
961 | static inline u16 ocfs2_local_alloc_size(struct super_block *sb) | |
962 | { | |
963 | u16 size; | |
964 | ||
965 | size = sb->s_blocksize - | |
966 | offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); | |
967 | ||
968 | return size; | |
969 | } | |
970 | ||
971 | static inline int ocfs2_group_bitmap_size(struct super_block *sb) | |
972 | { | |
973 | int size; | |
974 | ||
975 | size = sb->s_blocksize - | |
976 | offsetof(struct ocfs2_group_desc, bg_bitmap); | |
977 | ||
978 | return size; | |
979 | } | |
980 | ||
981 | static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb) | |
982 | { | |
983 | int size; | |
984 | ||
985 | size = sb->s_blocksize - | |
986 | offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); | |
987 | ||
988 | return size / sizeof(struct ocfs2_truncate_rec); | |
989 | } | |
50af94b1 MF |
990 | |
991 | static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index) | |
992 | { | |
993 | u64 offset = OCFS2_BACKUP_SB_START; | |
994 | ||
995 | if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { | |
996 | offset <<= (2 * index); | |
a8a75a20 | 997 | offset >>= sb->s_blocksize_bits; |
50af94b1 MF |
998 | return offset; |
999 | } | |
1000 | ||
1001 | return 0; | |
1002 | ||
1003 | } | |
0c044f0b TM |
1004 | |
1005 | static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb) | |
1006 | { | |
1007 | int size; | |
1008 | ||
1009 | size = sb->s_blocksize - | |
1010 | offsetof(struct ocfs2_xattr_block, | |
1011 | xb_attrs.xb_root.xt_list.l_recs); | |
1012 | ||
1013 | return size / sizeof(struct ocfs2_extent_rec); | |
1014 | } | |
ccd979bd MF |
1015 | #else |
1016 | static inline int ocfs2_fast_symlink_chars(int blocksize) | |
1017 | { | |
1018 | return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink); | |
1019 | } | |
1020 | ||
15b1e36b MF |
1021 | static inline int ocfs2_max_inline_data(int blocksize) |
1022 | { | |
1023 | return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data); | |
1024 | } | |
1025 | ||
ccd979bd MF |
1026 | static inline int ocfs2_extent_recs_per_inode(int blocksize) |
1027 | { | |
1028 | int size; | |
1029 | ||
1030 | size = blocksize - | |
1031 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); | |
1032 | ||
1033 | return size / sizeof(struct ocfs2_extent_rec); | |
1034 | } | |
1035 | ||
1036 | static inline int ocfs2_chain_recs_per_inode(int blocksize) | |
1037 | { | |
1038 | int size; | |
1039 | ||
1040 | size = blocksize - | |
1041 | offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); | |
1042 | ||
1043 | return size / sizeof(struct ocfs2_chain_rec); | |
1044 | } | |
1045 | ||
1046 | static inline int ocfs2_extent_recs_per_eb(int blocksize) | |
1047 | { | |
1048 | int size; | |
1049 | ||
1050 | size = blocksize - | |
1051 | offsetof(struct ocfs2_extent_block, h_list.l_recs); | |
1052 | ||
1053 | return size / sizeof(struct ocfs2_extent_rec); | |
1054 | } | |
1055 | ||
1056 | static inline int ocfs2_local_alloc_size(int blocksize) | |
1057 | { | |
1058 | int size; | |
1059 | ||
1060 | size = blocksize - | |
1061 | offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); | |
1062 | ||
1063 | return size; | |
1064 | } | |
1065 | ||
1066 | static inline int ocfs2_group_bitmap_size(int blocksize) | |
1067 | { | |
1068 | int size; | |
1069 | ||
1070 | size = blocksize - | |
1071 | offsetof(struct ocfs2_group_desc, bg_bitmap); | |
1072 | ||
1073 | return size; | |
1074 | } | |
1075 | ||
1076 | static inline int ocfs2_truncate_recs_per_inode(int blocksize) | |
1077 | { | |
1078 | int size; | |
1079 | ||
1080 | size = blocksize - | |
1081 | offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); | |
1082 | ||
1083 | return size / sizeof(struct ocfs2_truncate_rec); | |
1084 | } | |
50af94b1 MF |
1085 | |
1086 | static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index) | |
1087 | { | |
1088 | uint64_t offset = OCFS2_BACKUP_SB_START; | |
1089 | ||
1090 | if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { | |
1091 | offset <<= (2 * index); | |
1092 | offset /= blocksize; | |
1093 | return offset; | |
1094 | } | |
1095 | ||
1096 | return 0; | |
1097 | } | |
0c044f0b TM |
1098 | |
1099 | static inline int ocfs2_xattr_recs_per_xb(int blocksize) | |
1100 | { | |
1101 | int size; | |
1102 | ||
1103 | size = blocksize - | |
1104 | offsetof(struct ocfs2_xattr_block, | |
1105 | xb_attrs.xb_root.xt_list.l_recs); | |
1106 | ||
1107 | return size / sizeof(struct ocfs2_extent_rec); | |
1108 | } | |
ccd979bd MF |
1109 | #endif /* __KERNEL__ */ |
1110 | ||
1111 | ||
1112 | static inline int ocfs2_system_inode_is_global(int type) | |
1113 | { | |
1114 | return ((type >= 0) && | |
1115 | (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)); | |
1116 | } | |
1117 | ||
1118 | static inline int ocfs2_sprintf_system_inode_name(char *buf, int len, | |
1119 | int type, int slot) | |
1120 | { | |
1121 | int chars; | |
1122 | ||
1123 | /* | |
1124 | * Global system inodes can only have one copy. Everything | |
1125 | * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode | |
1126 | * list has a copy per slot. | |
1127 | */ | |
1128 | if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE) | |
fe9f3877 | 1129 | chars = snprintf(buf, len, "%s", |
ccd979bd MF |
1130 | ocfs2_system_inodes[type].si_name); |
1131 | else | |
1132 | chars = snprintf(buf, len, | |
1133 | ocfs2_system_inodes[type].si_name, | |
1134 | slot); | |
1135 | ||
1136 | return chars; | |
1137 | } | |
1138 | ||
1139 | static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de, | |
1140 | umode_t mode) | |
1141 | { | |
1142 | de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; | |
1143 | } | |
1144 | ||
1145 | #endif /* _OCFS2_FS_H */ | |
1146 |