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