Merge branch 'upstream-linus' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzik...
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / ocfs2 / ocfs2_fs.h
blob82f8a75b207e4b015a65bb3de1acbc0a4a41502e
1 /* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
4 * ocfs2_fs.h
6 * On-disk structures for OCFS2.
8 * Copyright (C) 2002, 2004 Oracle. All rights reserved.
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.
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.
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.
25 #ifndef _OCFS2_FS_H
26 #define _OCFS2_FS_H
28 /* Version */
29 #define OCFS2_MAJOR_REV_LEVEL 0
30 #define OCFS2_MINOR_REV_LEVEL 90
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.
38 * All other structures are found from the superblock information.
40 * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a
41 * blocksize of 2K, it is 4096 bytes into disk.
43 #define OCFS2_SUPER_BLOCK_BLKNO 2
46 * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could
47 * grow if needed.
49 #define OCFS2_MIN_CLUSTERSIZE 4096
50 #define OCFS2_MAX_CLUSTERSIZE 1048576
53 * Blocks cannot be bigger than clusters, so the maximum blocksize is the
54 * minimum cluster size.
56 #define OCFS2_MIN_BLOCKSIZE 512
57 #define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE
59 /* Filesystem magic number */
60 #define OCFS2_SUPER_MAGIC 0x7461636f
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"
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)
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
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*.
98 #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
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.
105 #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
107 /* Used to denote a non-clustered volume */
108 #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
110 /* Support for sparse allocation in b-trees */
111 #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
114 * backup superblock flag is used to indicate that this volume
115 * has backup superblocks.
117 #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
120 * Unwritten extents support.
122 #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
124 /* The byte offset of the first backup block will be 1G.
125 * The following will be 4G, 16G, 64G, 256G and 1T.
127 #define OCFS2_BACKUP_SB_START 1 << 30
129 /* the max backup superblock nums */
130 #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
133 * Flags on ocfs2_dinode.i_flags
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 */
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) */
160 #define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
161 #define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
164 * Extent record flags (e_node.leaf.flags)
166 #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
167 * unwritten */
170 * ioctl commands
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)
178 * Space reservation / allocation / free ioctls and argument structure
179 * are designed to be compatible with XFS.
181 * ALLOCSP* and FREESP* are not and will never be supported, but are
182 * included here for completeness.
184 struct ocfs2_space_resv {
185 __s16 l_type;
186 __s16 l_whence;
187 __s64 l_start;
188 __s64 l_len; /* len == 0 means until end of file */
189 __s32 l_sysid;
190 __u32 l_pid;
191 __s32 l_pad[4]; /* reserve area */
194 #define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
195 #define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
196 #define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
197 #define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
198 #define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
199 #define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
200 #define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
201 #define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
204 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
206 #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
209 * superblock s_state flags
211 #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
213 /* Limit of space in ocfs2_dir_entry */
214 #define OCFS2_MAX_FILENAME_LEN 255
216 /* Maximum slots on an ocfs2 file system */
217 #define OCFS2_MAX_SLOTS 255
219 /* Slot map indicator for an empty slot */
220 #define OCFS2_INVALID_SLOT -1
222 #define OCFS2_VOL_UUID_LEN 16
223 #define OCFS2_MAX_VOL_LABEL_LEN 64
225 /* Journal limits (in bytes) */
226 #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
228 struct ocfs2_system_inode_info {
229 char *si_name;
230 int si_iflags;
231 int si_mode;
234 /* System file index */
235 enum {
236 BAD_BLOCK_SYSTEM_INODE = 0,
237 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
238 SLOT_MAP_SYSTEM_INODE,
239 #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
240 HEARTBEAT_SYSTEM_INODE,
241 GLOBAL_BITMAP_SYSTEM_INODE,
242 #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
243 ORPHAN_DIR_SYSTEM_INODE,
244 EXTENT_ALLOC_SYSTEM_INODE,
245 INODE_ALLOC_SYSTEM_INODE,
246 JOURNAL_SYSTEM_INODE,
247 LOCAL_ALLOC_SYSTEM_INODE,
248 TRUNCATE_LOG_SYSTEM_INODE,
249 NUM_SYSTEM_INODES
252 static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
253 /* Global system inodes (single copy) */
254 /* The first two are only used from userspace mfks/tunefs */
255 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
256 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
258 /* These are used by the running filesystem */
259 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
260 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
261 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
263 /* Slot-specific system inodes (one copy per slot) */
264 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
265 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
266 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
267 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
268 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
269 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
272 /* Parameter passed from mount.ocfs2 to module */
273 #define OCFS2_HB_NONE "heartbeat=none"
274 #define OCFS2_HB_LOCAL "heartbeat=local"
277 * OCFS2 directory file types. Only the low 3 bits are used. The
278 * other bits are reserved for now.
280 #define OCFS2_FT_UNKNOWN 0
281 #define OCFS2_FT_REG_FILE 1
282 #define OCFS2_FT_DIR 2
283 #define OCFS2_FT_CHRDEV 3
284 #define OCFS2_FT_BLKDEV 4
285 #define OCFS2_FT_FIFO 5
286 #define OCFS2_FT_SOCK 6
287 #define OCFS2_FT_SYMLINK 7
289 #define OCFS2_FT_MAX 8
292 * OCFS2_DIR_PAD defines the directory entries boundaries
294 * NOTE: It must be a multiple of 4
296 #define OCFS2_DIR_PAD 4
297 #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
298 #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
299 #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
300 OCFS2_DIR_ROUND) & \
301 ~OCFS2_DIR_ROUND)
303 #define OCFS2_LINK_MAX 32000
305 #define S_SHIFT 12
306 static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
307 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
308 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
309 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
310 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
311 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
312 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
313 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
318 * Convenience casts
320 #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
323 * On disk extent record for OCFS2
324 * It describes a range of clusters on disk.
326 * Length fields are divided into interior and leaf node versions.
327 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
329 struct ocfs2_extent_rec {
330 /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
331 union {
332 __le32 e_int_clusters; /* Clusters covered by all children */
333 struct {
334 __le16 e_leaf_clusters; /* Clusters covered by this
335 extent */
336 __u8 e_reserved1;
337 __u8 e_flags; /* Extent flags */
340 __le64 e_blkno; /* Physical disk offset, in blocks */
341 /*10*/
344 struct ocfs2_chain_rec {
345 __le32 c_free; /* Number of free bits in this chain. */
346 __le32 c_total; /* Number of total bits in this chain */
347 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
350 struct ocfs2_truncate_rec {
351 __le32 t_start; /* 1st cluster in this log */
352 __le32 t_clusters; /* Number of total clusters covered */
356 * On disk extent list for OCFS2 (node in the tree). Note that this
357 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
358 * offsets are relative to ocfs2_dinode.id2.i_list or
359 * ocfs2_extent_block.h_list, respectively.
361 struct ocfs2_extent_list {
362 /*00*/ __le16 l_tree_depth; /* Extent tree depth from this
363 point. 0 means data extents
364 hang directly off this
365 header (a leaf)
366 NOTE: The high 8 bits cannot be
367 used - tree_depth is never that big.
369 __le16 l_count; /* Number of extent records */
370 __le16 l_next_free_rec; /* Next unused extent slot */
371 __le16 l_reserved1;
372 __le64 l_reserved2; /* Pad to
373 sizeof(ocfs2_extent_rec) */
374 /*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
378 * On disk allocation chain list for OCFS2. Note that this is
379 * contained inside ocfs2_dinode, so the offsets are relative to
380 * ocfs2_dinode.id2.i_chain.
382 struct ocfs2_chain_list {
383 /*00*/ __le16 cl_cpg; /* Clusters per Block Group */
384 __le16 cl_bpc; /* Bits per cluster */
385 __le16 cl_count; /* Total chains in this list */
386 __le16 cl_next_free_rec; /* Next unused chain slot */
387 __le64 cl_reserved1;
388 /*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
392 * On disk deallocation log for OCFS2. Note that this is
393 * contained inside ocfs2_dinode, so the offsets are relative to
394 * ocfs2_dinode.id2.i_dealloc.
396 struct ocfs2_truncate_log {
397 /*00*/ __le16 tl_count; /* Total records in this log */
398 __le16 tl_used; /* Number of records in use */
399 __le32 tl_reserved1;
400 /*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
404 * On disk extent block (indirect block) for OCFS2
406 struct ocfs2_extent_block
408 /*00*/ __u8 h_signature[8]; /* Signature for verification */
409 __le64 h_reserved1;
410 /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
411 extent_header belongs to */
412 __le16 h_suballoc_bit; /* Bit offset in suballocator
413 block group */
414 __le32 h_fs_generation; /* Must match super block */
415 __le64 h_blkno; /* Offset on disk, in blocks */
416 /*20*/ __le64 h_reserved3;
417 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
418 of next leaf header pointing
419 to data */
420 /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
421 /* Actual on-disk size is one block */
425 * On disk superblock for OCFS2
426 * Note that it is contained inside an ocfs2_dinode, so all offsets
427 * are relative to the start of ocfs2_dinode.id2.
429 struct ocfs2_super_block {
430 /*00*/ __le16 s_major_rev_level;
431 __le16 s_minor_rev_level;
432 __le16 s_mnt_count;
433 __le16 s_max_mnt_count;
434 __le16 s_state; /* File system state */
435 __le16 s_errors; /* Behaviour when detecting errors */
436 __le32 s_checkinterval; /* Max time between checks */
437 /*10*/ __le64 s_lastcheck; /* Time of last check */
438 __le32 s_creator_os; /* OS */
439 __le32 s_feature_compat; /* Compatible feature set */
440 /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
441 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
442 __le64 s_root_blkno; /* Offset, in blocks, of root directory
443 dinode */
444 /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
445 directory dinode */
446 __le32 s_blocksize_bits; /* Blocksize for this fs */
447 __le32 s_clustersize_bits; /* Clustersize for this fs */
448 /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
449 before tunefs required */
450 __le16 s_reserved1;
451 __le32 s_reserved2;
452 __le64 s_first_cluster_group; /* Block offset of 1st cluster
453 * group header */
454 /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
455 /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
456 /*A0*/
460 * Local allocation bitmap for OCFS2 slots
461 * Note that it exists inside an ocfs2_dinode, so all offsets are
462 * relative to the start of ocfs2_dinode.id2.
464 struct ocfs2_local_alloc
466 /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
467 __le16 la_size; /* Size of included bitmap, in bytes */
468 __le16 la_reserved1;
469 __le64 la_reserved2;
470 /*10*/ __u8 la_bitmap[0];
474 * On disk inode for OCFS2
476 struct ocfs2_dinode {
477 /*00*/ __u8 i_signature[8]; /* Signature for validation */
478 __le32 i_generation; /* Generation number */
479 __le16 i_suballoc_slot; /* Slot suballocator this inode
480 belongs to */
481 __le16 i_suballoc_bit; /* Bit offset in suballocator
482 block group */
483 /*10*/ __le32 i_reserved0;
484 __le32 i_clusters; /* Cluster count */
485 __le32 i_uid; /* Owner UID */
486 __le32 i_gid; /* Owning GID */
487 /*20*/ __le64 i_size; /* Size in bytes */
488 __le16 i_mode; /* File mode */
489 __le16 i_links_count; /* Links count */
490 __le32 i_flags; /* File flags */
491 /*30*/ __le64 i_atime; /* Access time */
492 __le64 i_ctime; /* Creation time */
493 /*40*/ __le64 i_mtime; /* Modification time */
494 __le64 i_dtime; /* Deletion time */
495 /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
496 __le64 i_last_eb_blk; /* Pointer to last extent
497 block */
498 /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
499 __le32 i_atime_nsec;
500 __le32 i_ctime_nsec;
501 __le32 i_mtime_nsec;
502 __le32 i_attr;
503 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
504 was set in i_flags */
505 __le16 i_reserved1;
506 /*70*/ __le64 i_reserved2[8];
507 /*B8*/ union {
508 __le64 i_pad1; /* Generic way to refer to this
509 64bit union */
510 struct {
511 __le64 i_rdev; /* Device number */
512 } dev1;
513 struct { /* Info for bitmap system
514 inodes */
515 __le32 i_used; /* Bits (ie, clusters) used */
516 __le32 i_total; /* Total bits (clusters)
517 available */
518 } bitmap1;
519 struct { /* Info for journal system
520 inodes */
521 __le32 ij_flags; /* Mounted, version, etc. */
522 __le32 ij_pad;
523 } journal1;
524 } id1; /* Inode type dependant 1 */
525 /*C0*/ union {
526 struct ocfs2_super_block i_super;
527 struct ocfs2_local_alloc i_lab;
528 struct ocfs2_chain_list i_chain;
529 struct ocfs2_extent_list i_list;
530 struct ocfs2_truncate_log i_dealloc;
531 __u8 i_symlink[0];
532 } id2;
533 /* Actual on-disk size is one block */
537 * On-disk directory entry structure for OCFS2
539 * Packed as this structure could be accessed unaligned on 64-bit platforms
541 struct ocfs2_dir_entry {
542 /*00*/ __le64 inode; /* Inode number */
543 __le16 rec_len; /* Directory entry length */
544 __u8 name_len; /* Name length */
545 __u8 file_type;
546 /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
547 /* Actual on-disk length specified by rec_len */
548 } __attribute__ ((packed));
551 * On disk allocator group structure for OCFS2
553 struct ocfs2_group_desc
555 /*00*/ __u8 bg_signature[8]; /* Signature for validation */
556 __le16 bg_size; /* Size of included bitmap in
557 bytes. */
558 __le16 bg_bits; /* Bits represented by this
559 group. */
560 __le16 bg_free_bits_count; /* Free bits count */
561 __le16 bg_chain; /* What chain I am in. */
562 /*10*/ __le32 bg_generation;
563 __le32 bg_reserved1;
564 __le64 bg_next_group; /* Next group in my list, in
565 blocks */
566 /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
567 blocks */
568 __le64 bg_blkno; /* Offset on disk, in blocks */
569 /*30*/ __le64 bg_reserved2[2];
570 /*40*/ __u8 bg_bitmap[0];
573 #ifdef __KERNEL__
574 static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
576 return sb->s_blocksize -
577 offsetof(struct ocfs2_dinode, id2.i_symlink);
580 static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
582 int size;
584 size = sb->s_blocksize -
585 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
587 return size / sizeof(struct ocfs2_extent_rec);
590 static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
592 int size;
594 size = sb->s_blocksize -
595 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
597 return size / sizeof(struct ocfs2_chain_rec);
600 static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
602 int size;
604 size = sb->s_blocksize -
605 offsetof(struct ocfs2_extent_block, h_list.l_recs);
607 return size / sizeof(struct ocfs2_extent_rec);
610 static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
612 u16 size;
614 size = sb->s_blocksize -
615 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
617 return size;
620 static inline int ocfs2_group_bitmap_size(struct super_block *sb)
622 int size;
624 size = sb->s_blocksize -
625 offsetof(struct ocfs2_group_desc, bg_bitmap);
627 return size;
630 static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
632 int size;
634 size = sb->s_blocksize -
635 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
637 return size / sizeof(struct ocfs2_truncate_rec);
640 static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
642 u64 offset = OCFS2_BACKUP_SB_START;
644 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
645 offset <<= (2 * index);
646 offset >>= sb->s_blocksize_bits;
647 return offset;
650 return 0;
653 #else
654 static inline int ocfs2_fast_symlink_chars(int blocksize)
656 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
659 static inline int ocfs2_extent_recs_per_inode(int blocksize)
661 int size;
663 size = blocksize -
664 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
666 return size / sizeof(struct ocfs2_extent_rec);
669 static inline int ocfs2_chain_recs_per_inode(int blocksize)
671 int size;
673 size = blocksize -
674 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
676 return size / sizeof(struct ocfs2_chain_rec);
679 static inline int ocfs2_extent_recs_per_eb(int blocksize)
681 int size;
683 size = blocksize -
684 offsetof(struct ocfs2_extent_block, h_list.l_recs);
686 return size / sizeof(struct ocfs2_extent_rec);
689 static inline int ocfs2_local_alloc_size(int blocksize)
691 int size;
693 size = blocksize -
694 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
696 return size;
699 static inline int ocfs2_group_bitmap_size(int blocksize)
701 int size;
703 size = blocksize -
704 offsetof(struct ocfs2_group_desc, bg_bitmap);
706 return size;
709 static inline int ocfs2_truncate_recs_per_inode(int blocksize)
711 int size;
713 size = blocksize -
714 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
716 return size / sizeof(struct ocfs2_truncate_rec);
719 static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
721 uint64_t offset = OCFS2_BACKUP_SB_START;
723 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
724 offset <<= (2 * index);
725 offset /= blocksize;
726 return offset;
729 return 0;
731 #endif /* __KERNEL__ */
734 static inline int ocfs2_system_inode_is_global(int type)
736 return ((type >= 0) &&
737 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
740 static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
741 int type, int slot)
743 int chars;
746 * Global system inodes can only have one copy. Everything
747 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
748 * list has a copy per slot.
750 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
751 chars = snprintf(buf, len,
752 ocfs2_system_inodes[type].si_name);
753 else
754 chars = snprintf(buf, len,
755 ocfs2_system_inodes[type].si_name,
756 slot);
758 return chars;
761 static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
762 umode_t mode)
764 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
767 #endif /* _OCFS2_FS_H */