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