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