]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/ocfs2/ocfs2_fs.h
c20a74b99d87da366cbd3f267a5d5ff3b3878aa8
[linux-2.6-omap-h63xx.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
68 /* Compatibility flags */
69 #define OCFS2_HAS_COMPAT_FEATURE(sb,mask)                       \
70         ( OCFS2_SB(sb)->s_feature_compat & (mask) )
71 #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask)                    \
72         ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) )
73 #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask)                     \
74         ( OCFS2_SB(sb)->s_feature_incompat & (mask) )
75 #define OCFS2_SET_COMPAT_FEATURE(sb,mask)                       \
76         OCFS2_SB(sb)->s_feature_compat |= (mask)
77 #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask)                    \
78         OCFS2_SB(sb)->s_feature_ro_compat |= (mask)
79 #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask)                     \
80         OCFS2_SB(sb)->s_feature_incompat |= (mask)
81 #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask)                     \
82         OCFS2_SB(sb)->s_feature_compat &= ~(mask)
83 #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask)                  \
84         OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask)
85 #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask)                   \
86         OCFS2_SB(sb)->s_feature_incompat &= ~(mask)
87
88 #define OCFS2_FEATURE_COMPAT_SUPP       OCFS2_FEATURE_COMPAT_BACKUP_SB
89 #define OCFS2_FEATURE_INCOMPAT_SUPP     (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
90                                          | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC)
91 #define OCFS2_FEATURE_RO_COMPAT_SUPP    OCFS2_FEATURE_RO_COMPAT_UNWRITTEN
92
93 /*
94  * Heartbeat-only devices are missing journals and other files.  The
95  * filesystem driver can't load them, but the library can.  Never put
96  * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
97  */
98 #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV    0x0002
99
100 /*
101  * tunefs sets this incompat flag before starting the resize and clears it
102  * at the end. This flag protects users from inadvertently mounting the fs
103  * after an aborted run without fsck-ing.
104  */
105 #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG    0x0004
106
107 /* Used to denote a non-clustered volume */
108 #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT      0x0008
109
110 /* Support for sparse allocation in b-trees */
111 #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC     0x0010
112
113 /*
114  * backup superblock flag is used to indicate that this volume
115  * has backup superblocks.
116  */
117 #define OCFS2_FEATURE_COMPAT_BACKUP_SB          0x0001
118
119 /*
120  * Unwritten extents support.
121  */
122 #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN       0x0001
123
124 /* The byte offset of the first backup block will be 1G.
125  * The following will be 4G, 16G, 64G, 256G and 1T.
126  */
127 #define OCFS2_BACKUP_SB_START                   1 << 30
128
129 /* the max backup superblock nums */
130 #define OCFS2_MAX_BACKUP_SUPERBLOCKS    6
131
132 /*
133  * Flags on ocfs2_dinode.i_flags
134  */
135 #define OCFS2_VALID_FL          (0x00000001)    /* Inode is valid */
136 #define OCFS2_UNUSED2_FL        (0x00000002)
137 #define OCFS2_ORPHANED_FL       (0x00000004)    /* On the orphan list */
138 #define OCFS2_UNUSED3_FL        (0x00000008)
139 /* System inode flags */
140 #define OCFS2_SYSTEM_FL         (0x00000010)    /* System inode */
141 #define OCFS2_SUPER_BLOCK_FL    (0x00000020)    /* Super block */
142 #define OCFS2_LOCAL_ALLOC_FL    (0x00000040)    /* Slot local alloc bitmap */
143 #define OCFS2_BITMAP_FL         (0x00000080)    /* Allocation bitmap */
144 #define OCFS2_JOURNAL_FL        (0x00000100)    /* Slot local journal */
145 #define OCFS2_HEARTBEAT_FL      (0x00000200)    /* Heartbeat area */
146 #define OCFS2_CHAIN_FL          (0x00000400)    /* Chain allocator */
147 #define OCFS2_DEALLOC_FL        (0x00000800)    /* Truncate log */
148
149 /* Inode attributes, keep in sync with EXT2 */
150 #define OCFS2_SECRM_FL          (0x00000001)    /* Secure deletion */
151 #define OCFS2_UNRM_FL           (0x00000002)    /* Undelete */
152 #define OCFS2_COMPR_FL          (0x00000004)    /* Compress file */
153 #define OCFS2_SYNC_FL           (0x00000008)    /* Synchronous updates */
154 #define OCFS2_IMMUTABLE_FL      (0x00000010)    /* Immutable file */
155 #define OCFS2_APPEND_FL         (0x00000020)    /* writes to file may only append */
156 #define OCFS2_NODUMP_FL         (0x00000040)    /* do not dump file */
157 #define OCFS2_NOATIME_FL        (0x00000080)    /* do not update atime */
158 #define OCFS2_DIRSYNC_FL        (0x00010000)    /* dirsync behaviour (directories only) */
159
160 #define OCFS2_FL_VISIBLE        (0x000100FF)    /* User visible flags */
161 #define OCFS2_FL_MODIFIABLE     (0x000100FF)    /* User modifiable flags */
162
163 /*
164  * Extent record flags (e_node.leaf.flags)
165  */
166 #define OCFS2_EXT_UNWRITTEN     (0x01)  /* Extent is allocated but
167                                          * unwritten */
168
169 /*
170  * ioctl commands
171  */
172 #define OCFS2_IOC_GETFLAGS      _IOR('f', 1, long)
173 #define OCFS2_IOC_SETFLAGS      _IOW('f', 2, long)
174 #define OCFS2_IOC32_GETFLAGS    _IOR('f', 1, int)
175 #define OCFS2_IOC32_SETFLAGS    _IOW('f', 2, int)
176
177 /*
178  * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
179  */
180 #define OCFS2_JOURNAL_DIRTY_FL  (0x00000001)    /* Journal needs recovery */
181
182 /*
183  * superblock s_state flags
184  */
185 #define OCFS2_ERROR_FS          (0x00000001)    /* FS saw errors */
186
187 /* Limit of space in ocfs2_dir_entry */
188 #define OCFS2_MAX_FILENAME_LEN          255
189
190 /* Maximum slots on an ocfs2 file system */
191 #define OCFS2_MAX_SLOTS                 255
192
193 /* Slot map indicator for an empty slot */
194 #define OCFS2_INVALID_SLOT              -1
195
196 #define OCFS2_VOL_UUID_LEN              16
197 #define OCFS2_MAX_VOL_LABEL_LEN         64
198
199 /* Journal limits (in bytes) */
200 #define OCFS2_MIN_JOURNAL_SIZE          (4 * 1024 * 1024)
201
202 struct ocfs2_system_inode_info {
203         char    *si_name;
204         int     si_iflags;
205         int     si_mode;
206 };
207
208 /* System file index */
209 enum {
210         BAD_BLOCK_SYSTEM_INODE = 0,
211         GLOBAL_INODE_ALLOC_SYSTEM_INODE,
212         SLOT_MAP_SYSTEM_INODE,
213 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
214         HEARTBEAT_SYSTEM_INODE,
215         GLOBAL_BITMAP_SYSTEM_INODE,
216 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
217         ORPHAN_DIR_SYSTEM_INODE,
218         EXTENT_ALLOC_SYSTEM_INODE,
219         INODE_ALLOC_SYSTEM_INODE,
220         JOURNAL_SYSTEM_INODE,
221         LOCAL_ALLOC_SYSTEM_INODE,
222         TRUNCATE_LOG_SYSTEM_INODE,
223         NUM_SYSTEM_INODES
224 };
225
226 static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
227         /* Global system inodes (single copy) */
228         /* The first two are only used from userspace mfks/tunefs */
229         [BAD_BLOCK_SYSTEM_INODE]                = { "bad_blocks", 0, S_IFREG | 0644 },
230         [GLOBAL_INODE_ALLOC_SYSTEM_INODE]       = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
231
232         /* These are used by the running filesystem */
233         [SLOT_MAP_SYSTEM_INODE]                 = { "slot_map", 0, S_IFREG | 0644 },
234         [HEARTBEAT_SYSTEM_INODE]                = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
235         [GLOBAL_BITMAP_SYSTEM_INODE]            = { "global_bitmap", 0, S_IFREG | 0644 },
236
237         /* Slot-specific system inodes (one copy per slot) */
238         [ORPHAN_DIR_SYSTEM_INODE]               = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
239         [EXTENT_ALLOC_SYSTEM_INODE]             = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
240         [INODE_ALLOC_SYSTEM_INODE]              = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
241         [JOURNAL_SYSTEM_INODE]                  = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
242         [LOCAL_ALLOC_SYSTEM_INODE]              = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
243         [TRUNCATE_LOG_SYSTEM_INODE]             = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
244 };
245
246 /* Parameter passed from mount.ocfs2 to module */
247 #define OCFS2_HB_NONE                   "heartbeat=none"
248 #define OCFS2_HB_LOCAL                  "heartbeat=local"
249
250 /*
251  * OCFS2 directory file types.  Only the low 3 bits are used.  The
252  * other bits are reserved for now.
253  */
254 #define OCFS2_FT_UNKNOWN        0
255 #define OCFS2_FT_REG_FILE       1
256 #define OCFS2_FT_DIR            2
257 #define OCFS2_FT_CHRDEV         3
258 #define OCFS2_FT_BLKDEV         4
259 #define OCFS2_FT_FIFO           5
260 #define OCFS2_FT_SOCK           6
261 #define OCFS2_FT_SYMLINK        7
262
263 #define OCFS2_FT_MAX            8
264
265 /*
266  * OCFS2_DIR_PAD defines the directory entries boundaries
267  *
268  * NOTE: It must be a multiple of 4
269  */
270 #define OCFS2_DIR_PAD                   4
271 #define OCFS2_DIR_ROUND                 (OCFS2_DIR_PAD - 1)
272 #define OCFS2_DIR_MEMBER_LEN            offsetof(struct ocfs2_dir_entry, name)
273 #define OCFS2_DIR_REC_LEN(name_len)     (((name_len) + OCFS2_DIR_MEMBER_LEN + \
274                                           OCFS2_DIR_ROUND) & \
275                                          ~OCFS2_DIR_ROUND)
276
277 #define OCFS2_LINK_MAX          32000
278
279 #define S_SHIFT                 12
280 static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
281         [S_IFREG >> S_SHIFT]  = OCFS2_FT_REG_FILE,
282         [S_IFDIR >> S_SHIFT]  = OCFS2_FT_DIR,
283         [S_IFCHR >> S_SHIFT]  = OCFS2_FT_CHRDEV,
284         [S_IFBLK >> S_SHIFT]  = OCFS2_FT_BLKDEV,
285         [S_IFIFO >> S_SHIFT]  = OCFS2_FT_FIFO,
286         [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
287         [S_IFLNK >> S_SHIFT]  = OCFS2_FT_SYMLINK,
288 };
289
290
291 /*
292  * Convenience casts
293  */
294 #define OCFS2_RAW_SB(dinode)            (&((dinode)->id2.i_super))
295
296 /*
297  * On disk extent record for OCFS2
298  * It describes a range of clusters on disk.
299  *
300  * Length fields are divided into interior and leaf node versions.
301  * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
302  */
303 struct ocfs2_extent_rec {
304 /*00*/  __le32 e_cpos;          /* Offset into the file, in clusters */
305         union {
306                 __le32 e_int_clusters; /* Clusters covered by all children */
307                 struct {
308                         __le16 e_leaf_clusters; /* Clusters covered by this
309                                                    extent */
310                         __u8 e_reserved1;
311                         __u8 e_flags; /* Extent flags */
312                 };
313         };
314         __le64 e_blkno;         /* Physical disk offset, in blocks */
315 /*10*/
316 };
317
318 struct ocfs2_chain_rec {
319         __le32 c_free;  /* Number of free bits in this chain. */
320         __le32 c_total; /* Number of total bits in this chain */
321         __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
322 };
323
324 struct ocfs2_truncate_rec {
325         __le32 t_start;         /* 1st cluster in this log */
326         __le32 t_clusters;      /* Number of total clusters covered */
327 };
328
329 /*
330  * On disk extent list for OCFS2 (node in the tree).  Note that this
331  * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
332  * offsets are relative to ocfs2_dinode.id2.i_list or
333  * ocfs2_extent_block.h_list, respectively.
334  */
335 struct ocfs2_extent_list {
336 /*00*/  __le16 l_tree_depth;            /* Extent tree depth from this
337                                            point.  0 means data extents
338                                            hang directly off this
339                                            header (a leaf)
340                                            NOTE: The high 8 bits cannot be
341                                            used - tree_depth is never that big.
342                                         */
343         __le16 l_count;                 /* Number of extent records */
344         __le16 l_next_free_rec;         /* Next unused extent slot */
345         __le16 l_reserved1;
346         __le64 l_reserved2;             /* Pad to
347                                            sizeof(ocfs2_extent_rec) */
348 /*10*/  struct ocfs2_extent_rec l_recs[0];      /* Extent records */
349 };
350
351 /*
352  * On disk allocation chain list for OCFS2.  Note that this is
353  * contained inside ocfs2_dinode, so the offsets are relative to
354  * ocfs2_dinode.id2.i_chain.
355  */
356 struct ocfs2_chain_list {
357 /*00*/  __le16 cl_cpg;                  /* Clusters per Block Group */
358         __le16 cl_bpc;                  /* Bits per cluster */
359         __le16 cl_count;                /* Total chains in this list */
360         __le16 cl_next_free_rec;        /* Next unused chain slot */
361         __le64 cl_reserved1;
362 /*10*/  struct ocfs2_chain_rec cl_recs[0];      /* Chain records */
363 };
364
365 /*
366  * On disk deallocation log for OCFS2.  Note that this is
367  * contained inside ocfs2_dinode, so the offsets are relative to
368  * ocfs2_dinode.id2.i_dealloc.
369  */
370 struct ocfs2_truncate_log {
371 /*00*/  __le16 tl_count;                /* Total records in this log */
372         __le16 tl_used;                 /* Number of records in use */
373         __le32 tl_reserved1;
374 /*08*/  struct ocfs2_truncate_rec tl_recs[0];   /* Truncate records */
375 };
376
377 /*
378  * On disk extent block (indirect block) for OCFS2
379  */
380 struct ocfs2_extent_block
381 {
382 /*00*/  __u8 h_signature[8];            /* Signature for verification */
383         __le64 h_reserved1;
384 /*10*/  __le16 h_suballoc_slot;         /* Slot suballocator this
385                                            extent_header belongs to */
386         __le16 h_suballoc_bit;          /* Bit offset in suballocator
387                                            block group */
388         __le32 h_fs_generation;         /* Must match super block */
389         __le64 h_blkno;                 /* Offset on disk, in blocks */
390 /*20*/  __le64 h_reserved3;
391         __le64 h_next_leaf_blk;         /* Offset on disk, in blocks,
392                                            of next leaf header pointing
393                                            to data */
394 /*30*/  struct ocfs2_extent_list h_list;        /* Extent record list */
395 /* Actual on-disk size is one block */
396 };
397
398 /*
399  * On disk superblock for OCFS2
400  * Note that it is contained inside an ocfs2_dinode, so all offsets
401  * are relative to the start of ocfs2_dinode.id2.
402  */
403 struct ocfs2_super_block {
404 /*00*/  __le16 s_major_rev_level;
405         __le16 s_minor_rev_level;
406         __le16 s_mnt_count;
407         __le16 s_max_mnt_count;
408         __le16 s_state;                 /* File system state */
409         __le16 s_errors;                        /* Behaviour when detecting errors */
410         __le32 s_checkinterval;         /* Max time between checks */
411 /*10*/  __le64 s_lastcheck;             /* Time of last check */
412         __le32 s_creator_os;            /* OS */
413         __le32 s_feature_compat;                /* Compatible feature set */
414 /*20*/  __le32 s_feature_incompat;      /* Incompatible feature set */
415         __le32 s_feature_ro_compat;     /* Readonly-compatible feature set */
416         __le64 s_root_blkno;            /* Offset, in blocks, of root directory
417                                            dinode */
418 /*30*/  __le64 s_system_dir_blkno;      /* Offset, in blocks, of system
419                                            directory dinode */
420         __le32 s_blocksize_bits;                /* Blocksize for this fs */
421         __le32 s_clustersize_bits;      /* Clustersize for this fs */
422 /*40*/  __le16 s_max_slots;             /* Max number of simultaneous mounts
423                                            before tunefs required */
424         __le16 s_reserved1;
425         __le32 s_reserved2;
426         __le64 s_first_cluster_group;   /* Block offset of 1st cluster
427                                          * group header */
428 /*50*/  __u8  s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
429 /*90*/  __u8  s_uuid[OCFS2_VOL_UUID_LEN];       /* 128-bit uuid */
430 /*A0*/
431 };
432
433 /*
434  * Local allocation bitmap for OCFS2 slots
435  * Note that it exists inside an ocfs2_dinode, so all offsets are
436  * relative to the start of ocfs2_dinode.id2.
437  */
438 struct ocfs2_local_alloc
439 {
440 /*00*/  __le32 la_bm_off;       /* Starting bit offset in main bitmap */
441         __le16 la_size;         /* Size of included bitmap, in bytes */
442         __le16 la_reserved1;
443         __le64 la_reserved2;
444 /*10*/  __u8   la_bitmap[0];
445 };
446
447 /*
448  * On disk inode for OCFS2
449  */
450 struct ocfs2_dinode {
451 /*00*/  __u8 i_signature[8];            /* Signature for validation */
452         __le32 i_generation;            /* Generation number */
453         __le16 i_suballoc_slot;         /* Slot suballocator this inode
454                                            belongs to */
455         __le16 i_suballoc_bit;          /* Bit offset in suballocator
456                                            block group */
457 /*10*/  __le32 i_reserved0;
458         __le32 i_clusters;              /* Cluster count */
459         __le32 i_uid;                   /* Owner UID */
460         __le32 i_gid;                   /* Owning GID */
461 /*20*/  __le64 i_size;                  /* Size in bytes */
462         __le16 i_mode;                  /* File mode */
463         __le16 i_links_count;           /* Links count */
464         __le32 i_flags;                 /* File flags */
465 /*30*/  __le64 i_atime;                 /* Access time */
466         __le64 i_ctime;                 /* Creation time */
467 /*40*/  __le64 i_mtime;                 /* Modification time */
468         __le64 i_dtime;                 /* Deletion time */
469 /*50*/  __le64 i_blkno;                 /* Offset on disk, in blocks */
470         __le64 i_last_eb_blk;           /* Pointer to last extent
471                                            block */
472 /*60*/  __le32 i_fs_generation;         /* Generation per fs-instance */
473         __le32 i_atime_nsec;
474         __le32 i_ctime_nsec;
475         __le32 i_mtime_nsec;
476         __le32 i_attr;
477         __le16 i_orphaned_slot;         /* Only valid when OCFS2_ORPHANED_FL
478                                            was set in i_flags */
479         __le16 i_reserved1;
480 /*70*/  __le64 i_reserved2[8];
481 /*B8*/  union {
482                 __le64 i_pad1;          /* Generic way to refer to this
483                                            64bit union */
484                 struct {
485                         __le64 i_rdev;  /* Device number */
486                 } dev1;
487                 struct {                /* Info for bitmap system
488                                            inodes */
489                         __le32 i_used;  /* Bits (ie, clusters) used  */
490                         __le32 i_total; /* Total bits (clusters)
491                                            available */
492                 } bitmap1;
493                 struct {                /* Info for journal system
494                                            inodes */
495                         __le32 ij_flags;        /* Mounted, version, etc. */
496                         __le32 ij_pad;
497                 } journal1;
498         } id1;                          /* Inode type dependant 1 */
499 /*C0*/  union {
500                 struct ocfs2_super_block        i_super;
501                 struct ocfs2_local_alloc        i_lab;
502                 struct ocfs2_chain_list         i_chain;
503                 struct ocfs2_extent_list        i_list;
504                 struct ocfs2_truncate_log       i_dealloc;
505                 __u8                            i_symlink[0];
506         } id2;
507 /* Actual on-disk size is one block */
508 };
509
510 /*
511  * On-disk directory entry structure for OCFS2
512  *
513  * Packed as this structure could be accessed unaligned on 64-bit platforms
514  */
515 struct ocfs2_dir_entry {
516 /*00*/  __le64   inode;                  /* Inode number */
517         __le16   rec_len;                /* Directory entry length */
518         __u8    name_len;               /* Name length */
519         __u8    file_type;
520 /*0C*/  char    name[OCFS2_MAX_FILENAME_LEN];   /* File name */
521 /* Actual on-disk length specified by rec_len */
522 } __attribute__ ((packed));
523
524 /*
525  * On disk allocator group structure for OCFS2
526  */
527 struct ocfs2_group_desc
528 {
529 /*00*/  __u8    bg_signature[8];        /* Signature for validation */
530         __le16   bg_size;                /* Size of included bitmap in
531                                            bytes. */
532         __le16   bg_bits;                /* Bits represented by this
533                                            group. */
534         __le16  bg_free_bits_count;     /* Free bits count */
535         __le16   bg_chain;               /* What chain I am in. */
536 /*10*/  __le32   bg_generation;
537         __le32  bg_reserved1;
538         __le64   bg_next_group;          /* Next group in my list, in
539                                            blocks */
540 /*20*/  __le64   bg_parent_dinode;       /* dinode which owns me, in
541                                            blocks */
542         __le64   bg_blkno;               /* Offset on disk, in blocks */
543 /*30*/  __le64   bg_reserved2[2];
544 /*40*/  __u8    bg_bitmap[0];
545 };
546
547 #ifdef __KERNEL__
548 static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
549 {
550         return  sb->s_blocksize -
551                  offsetof(struct ocfs2_dinode, id2.i_symlink);
552 }
553
554 static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
555 {
556         int size;
557
558         size = sb->s_blocksize -
559                 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
560
561         return size / sizeof(struct ocfs2_extent_rec);
562 }
563
564 static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
565 {
566         int size;
567
568         size = sb->s_blocksize -
569                 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
570
571         return size / sizeof(struct ocfs2_chain_rec);
572 }
573
574 static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
575 {
576         int size;
577
578         size = sb->s_blocksize -
579                 offsetof(struct ocfs2_extent_block, h_list.l_recs);
580
581         return size / sizeof(struct ocfs2_extent_rec);
582 }
583
584 static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
585 {
586         u16 size;
587
588         size = sb->s_blocksize -
589                 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
590
591         return size;
592 }
593
594 static inline int ocfs2_group_bitmap_size(struct super_block *sb)
595 {
596         int size;
597
598         size = sb->s_blocksize -
599                 offsetof(struct ocfs2_group_desc, bg_bitmap);
600
601         return size;
602 }
603
604 static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
605 {
606         int size;
607
608         size = sb->s_blocksize -
609                 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
610
611         return size / sizeof(struct ocfs2_truncate_rec);
612 }
613
614 static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
615 {
616         u64 offset = OCFS2_BACKUP_SB_START;
617
618         if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
619                 offset <<= (2 * index);
620                 offset >>= sb->s_blocksize_bits;
621                 return offset;
622         }
623
624         return 0;
625
626 }
627 #else
628 static inline int ocfs2_fast_symlink_chars(int blocksize)
629 {
630         return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
631 }
632
633 static inline int ocfs2_extent_recs_per_inode(int blocksize)
634 {
635         int size;
636
637         size = blocksize -
638                 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
639
640         return size / sizeof(struct ocfs2_extent_rec);
641 }
642
643 static inline int ocfs2_chain_recs_per_inode(int blocksize)
644 {
645         int size;
646
647         size = blocksize -
648                 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
649
650         return size / sizeof(struct ocfs2_chain_rec);
651 }
652
653 static inline int ocfs2_extent_recs_per_eb(int blocksize)
654 {
655         int size;
656
657         size = blocksize -
658                 offsetof(struct ocfs2_extent_block, h_list.l_recs);
659
660         return size / sizeof(struct ocfs2_extent_rec);
661 }
662
663 static inline int ocfs2_local_alloc_size(int blocksize)
664 {
665         int size;
666
667         size = blocksize -
668                 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
669
670         return size;
671 }
672
673 static inline int ocfs2_group_bitmap_size(int blocksize)
674 {
675         int size;
676
677         size = blocksize -
678                 offsetof(struct ocfs2_group_desc, bg_bitmap);
679
680         return size;
681 }
682
683 static inline int ocfs2_truncate_recs_per_inode(int blocksize)
684 {
685         int size;
686
687         size = blocksize -
688                 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
689
690         return size / sizeof(struct ocfs2_truncate_rec);
691 }
692
693 static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
694 {
695         uint64_t offset = OCFS2_BACKUP_SB_START;
696
697         if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
698                 offset <<= (2 * index);
699                 offset /= blocksize;
700                 return offset;
701         }
702
703         return 0;
704 }
705 #endif  /* __KERNEL__ */
706
707
708 static inline int ocfs2_system_inode_is_global(int type)
709 {
710         return ((type >= 0) &&
711                 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
712 }
713
714 static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
715                                                   int type, int slot)
716 {
717         int chars;
718
719         /*
720          * Global system inodes can only have one copy.  Everything
721          * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
722          * list has a copy per slot.
723          */
724         if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
725                 chars = snprintf(buf, len,
726                                  ocfs2_system_inodes[type].si_name);
727         else
728                 chars = snprintf(buf, len,
729                                  ocfs2_system_inodes[type].si_name,
730                                  slot);
731
732         return chars;
733 }
734
735 static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
736                                     umode_t mode)
737 {
738         de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
739 }
740
741 #endif  /* _OCFS2_FS_H */
742