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