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