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