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