]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - fs/ocfs2/ocfs2_fs.h
ocfs2: Create stack glue sysfs files.
[mirror_ubuntu-zesty-kernel.git] / fs / ocfs2 / ocfs2_fs.h
CommitLineData
ccd979bd
MF
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
50af94b1 88#define OCFS2_FEATURE_COMPAT_SUPP OCFS2_FEATURE_COMPAT_BACKUP_SB
dcd0538f 89#define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \
15b1e36b 90 | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \
386a2ef8
JB
91 | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \
92 | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP)
328d5752 93#define OCFS2_FEATURE_RO_COMPAT_SUPP OCFS2_FEATURE_RO_COMPAT_UNWRITTEN
ccd979bd
MF
94
95/*
96 * Heartbeat-only devices are missing journals and other files. The
97 * filesystem driver can't load them, but the library can. Never put
98 * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*.
99 */
100#define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002
101
8903901d
MF
102/*
103 * tunefs sets this incompat flag before starting the resize and clears it
104 * at the end. This flag protects users from inadvertently mounting the fs
105 * after an aborted run without fsck-ing.
106 */
107#define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004
ccd979bd 108
c271c5c2
SM
109/* Used to denote a non-clustered volume */
110#define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008
111
8903901d
MF
112/* Support for sparse allocation in b-trees */
113#define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010
114
92e91ce2
MF
115/*
116 * Tunefs sets this incompat flag before starting an operation which
117 * would require cleanup on abort. This is done to protect users from
118 * inadvertently mounting the fs after an aborted run without
119 * fsck-ing.
120 *
121 * s_tunefs_flags on the super block describes precisely which
122 * operations were in progress.
123 */
124#define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020
125
15b1e36b
MF
126/* Support for data packed into inode blocks */
127#define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040
128
386a2ef8
JB
129/* Support for the extended slot map */
130#define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100
131
132
50af94b1
MF
133/*
134 * backup superblock flag is used to indicate that this volume
135 * has backup superblocks.
136 */
137#define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001
138
328d5752
MF
139/*
140 * Unwritten extents support.
141 */
142#define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001
143
50af94b1
MF
144/* The byte offset of the first backup block will be 1G.
145 * The following will be 4G, 16G, 64G, 256G and 1T.
146 */
147#define OCFS2_BACKUP_SB_START 1 << 30
148
149/* the max backup superblock nums */
150#define OCFS2_MAX_BACKUP_SUPERBLOCKS 6
151
92e91ce2
MF
152/*
153 * Flags on ocfs2_super_block.s_tunefs_flags
154 */
155#define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */
156
ccd979bd
MF
157/*
158 * Flags on ocfs2_dinode.i_flags
159 */
160#define OCFS2_VALID_FL (0x00000001) /* Inode is valid */
161#define OCFS2_UNUSED2_FL (0x00000002)
162#define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */
163#define OCFS2_UNUSED3_FL (0x00000008)
164/* System inode flags */
165#define OCFS2_SYSTEM_FL (0x00000010) /* System inode */
166#define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */
167#define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */
168#define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */
169#define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */
170#define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */
171#define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */
172#define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */
173
15b1e36b
MF
174/*
175 * Flags on ocfs2_dinode.i_dyn_features
176 *
177 * These can change much more often than i_flags. When adding flags,
178 * keep in mind that i_dyn_features is only 16 bits wide.
179 */
180#define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */
181#define OCFS2_HAS_XATTR_FL (0x0002)
182#define OCFS2_INLINE_XATTR_FL (0x0004)
183#define OCFS2_INDEXED_DIR_FL (0x0008)
184
ca4d147e
HP
185/* Inode attributes, keep in sync with EXT2 */
186#define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */
187#define OCFS2_UNRM_FL (0x00000002) /* Undelete */
188#define OCFS2_COMPR_FL (0x00000004) /* Compress file */
189#define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */
190#define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */
191#define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */
192#define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */
193#define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */
194#define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */
195
196#define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */
197#define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */
198
e48edee2
MF
199/*
200 * Extent record flags (e_node.leaf.flags)
201 */
202#define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but
203 * unwritten */
204
ca4d147e
HP
205/*
206 * ioctl commands
207 */
208#define OCFS2_IOC_GETFLAGS _IOR('f', 1, long)
209#define OCFS2_IOC_SETFLAGS _IOW('f', 2, long)
586d232b
MF
210#define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int)
211#define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int)
ca4d147e 212
b2580103
MF
213/*
214 * Space reservation / allocation / free ioctls and argument structure
215 * are designed to be compatible with XFS.
216 *
217 * ALLOCSP* and FREESP* are not and will never be supported, but are
218 * included here for completeness.
219 */
220struct ocfs2_space_resv {
221 __s16 l_type;
222 __s16 l_whence;
223 __s64 l_start;
224 __s64 l_len; /* len == 0 means until end of file */
225 __s32 l_sysid;
226 __u32 l_pid;
227 __s32 l_pad[4]; /* reserve area */
228};
229
230#define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv)
231#define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv)
232#define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv)
233#define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv)
234#define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv)
235#define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv)
236#define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv)
237#define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv)
238
7909f2bf
TM
239/* Used to pass group descriptor data when online resize is done */
240struct ocfs2_new_group_input {
241 __u64 group; /* Group descriptor's blkno. */
242 __u32 clusters; /* Total number of clusters in this group */
243 __u32 frees; /* Total free clusters in this group */
244 __u16 chain; /* Chain for this group */
245 __u16 reserved1;
246 __u32 reserved2;
247};
248
d659072f 249#define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int)
7909f2bf
TM
250#define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input)
251#define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input)
d659072f 252
ccd979bd
MF
253/*
254 * Journal Flags (ocfs2_dinode.id1.journal1.i_flags)
255 */
256#define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */
257
258/*
259 * superblock s_state flags
260 */
261#define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */
262
263/* Limit of space in ocfs2_dir_entry */
264#define OCFS2_MAX_FILENAME_LEN 255
265
266/* Maximum slots on an ocfs2 file system */
267#define OCFS2_MAX_SLOTS 255
268
269/* Slot map indicator for an empty slot */
270#define OCFS2_INVALID_SLOT -1
271
272#define OCFS2_VOL_UUID_LEN 16
273#define OCFS2_MAX_VOL_LABEL_LEN 64
274
275/* Journal limits (in bytes) */
276#define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024)
ccd979bd 277
2fbe8d1e
SM
278/*
279 * Default local alloc size (in megabytes)
280 *
281 * The value chosen should be such that most allocations, including new
282 * block groups, use local alloc.
283 */
284#define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8
285
ccd979bd
MF
286struct ocfs2_system_inode_info {
287 char *si_name;
288 int si_iflags;
289 int si_mode;
290};
291
292/* System file index */
293enum {
294 BAD_BLOCK_SYSTEM_INODE = 0,
295 GLOBAL_INODE_ALLOC_SYSTEM_INODE,
296 SLOT_MAP_SYSTEM_INODE,
297#define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE
298 HEARTBEAT_SYSTEM_INODE,
299 GLOBAL_BITMAP_SYSTEM_INODE,
300#define OCFS2_LAST_GLOBAL_SYSTEM_INODE GLOBAL_BITMAP_SYSTEM_INODE
301 ORPHAN_DIR_SYSTEM_INODE,
302 EXTENT_ALLOC_SYSTEM_INODE,
303 INODE_ALLOC_SYSTEM_INODE,
304 JOURNAL_SYSTEM_INODE,
305 LOCAL_ALLOC_SYSTEM_INODE,
306 TRUNCATE_LOG_SYSTEM_INODE,
307 NUM_SYSTEM_INODES
308};
309
310static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = {
311 /* Global system inodes (single copy) */
312 /* The first two are only used from userspace mfks/tunefs */
313 [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 },
314 [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
315
316 /* These are used by the running filesystem */
317 [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 },
318 [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 },
319 [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 },
320
321 /* Slot-specific system inodes (one copy per slot) */
322 [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 },
323 [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
324 [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 },
325 [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 },
326 [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 },
327 [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }
328};
329
330/* Parameter passed from mount.ocfs2 to module */
331#define OCFS2_HB_NONE "heartbeat=none"
332#define OCFS2_HB_LOCAL "heartbeat=local"
333
334/*
335 * OCFS2 directory file types. Only the low 3 bits are used. The
336 * other bits are reserved for now.
337 */
338#define OCFS2_FT_UNKNOWN 0
339#define OCFS2_FT_REG_FILE 1
340#define OCFS2_FT_DIR 2
341#define OCFS2_FT_CHRDEV 3
342#define OCFS2_FT_BLKDEV 4
343#define OCFS2_FT_FIFO 5
344#define OCFS2_FT_SOCK 6
345#define OCFS2_FT_SYMLINK 7
346
347#define OCFS2_FT_MAX 8
348
349/*
350 * OCFS2_DIR_PAD defines the directory entries boundaries
351 *
352 * NOTE: It must be a multiple of 4
353 */
354#define OCFS2_DIR_PAD 4
355#define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1)
356#define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name)
357#define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \
358 OCFS2_DIR_ROUND) & \
359 ~OCFS2_DIR_ROUND)
360
361#define OCFS2_LINK_MAX 32000
362
363#define S_SHIFT 12
364static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = {
365 [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE,
366 [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR,
367 [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV,
368 [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV,
369 [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO,
370 [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK,
371 [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK,
372};
373
374
375/*
376 * Convenience casts
377 */
378#define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super))
379
380/*
381 * On disk extent record for OCFS2
382 * It describes a range of clusters on disk.
e48edee2
MF
383 *
384 * Length fields are divided into interior and leaf node versions.
385 * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes.
ccd979bd
MF
386 */
387struct ocfs2_extent_rec {
388/*00*/ __le32 e_cpos; /* Offset into the file, in clusters */
e48edee2
MF
389 union {
390 __le32 e_int_clusters; /* Clusters covered by all children */
391 struct {
392 __le16 e_leaf_clusters; /* Clusters covered by this
393 extent */
394 __u8 e_reserved1;
395 __u8 e_flags; /* Extent flags */
396 };
397 };
ccd979bd
MF
398 __le64 e_blkno; /* Physical disk offset, in blocks */
399/*10*/
400};
401
402struct ocfs2_chain_rec {
403 __le32 c_free; /* Number of free bits in this chain. */
404 __le32 c_total; /* Number of total bits in this chain */
405 __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */
406};
407
408struct ocfs2_truncate_rec {
409 __le32 t_start; /* 1st cluster in this log */
410 __le32 t_clusters; /* Number of total clusters covered */
411};
412
413/*
414 * On disk extent list for OCFS2 (node in the tree). Note that this
415 * is contained inside ocfs2_dinode or ocfs2_extent_block, so the
416 * offsets are relative to ocfs2_dinode.id2.i_list or
417 * ocfs2_extent_block.h_list, respectively.
418 */
419struct ocfs2_extent_list {
420/*00*/ __le16 l_tree_depth; /* Extent tree depth from this
421 point. 0 means data extents
422 hang directly off this
dcd0538f
MF
423 header (a leaf)
424 NOTE: The high 8 bits cannot be
425 used - tree_depth is never that big.
426 */
ccd979bd
MF
427 __le16 l_count; /* Number of extent records */
428 __le16 l_next_free_rec; /* Next unused extent slot */
429 __le16 l_reserved1;
430 __le64 l_reserved2; /* Pad to
431 sizeof(ocfs2_extent_rec) */
432/*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */
433};
434
435/*
436 * On disk allocation chain list for OCFS2. Note that this is
437 * contained inside ocfs2_dinode, so the offsets are relative to
438 * ocfs2_dinode.id2.i_chain.
439 */
440struct ocfs2_chain_list {
441/*00*/ __le16 cl_cpg; /* Clusters per Block Group */
442 __le16 cl_bpc; /* Bits per cluster */
443 __le16 cl_count; /* Total chains in this list */
444 __le16 cl_next_free_rec; /* Next unused chain slot */
445 __le64 cl_reserved1;
446/*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */
447};
448
449/*
450 * On disk deallocation log for OCFS2. Note that this is
451 * contained inside ocfs2_dinode, so the offsets are relative to
452 * ocfs2_dinode.id2.i_dealloc.
453 */
454struct ocfs2_truncate_log {
455/*00*/ __le16 tl_count; /* Total records in this log */
456 __le16 tl_used; /* Number of records in use */
457 __le32 tl_reserved1;
458/*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */
459};
460
461/*
462 * On disk extent block (indirect block) for OCFS2
463 */
464struct ocfs2_extent_block
465{
466/*00*/ __u8 h_signature[8]; /* Signature for verification */
467 __le64 h_reserved1;
468/*10*/ __le16 h_suballoc_slot; /* Slot suballocator this
469 extent_header belongs to */
470 __le16 h_suballoc_bit; /* Bit offset in suballocator
471 block group */
472 __le32 h_fs_generation; /* Must match super block */
473 __le64 h_blkno; /* Offset on disk, in blocks */
474/*20*/ __le64 h_reserved3;
475 __le64 h_next_leaf_blk; /* Offset on disk, in blocks,
476 of next leaf header pointing
477 to data */
478/*30*/ struct ocfs2_extent_list h_list; /* Extent record list */
479/* Actual on-disk size is one block */
480};
481
fb86b1f0
JB
482/*
483 * On disk slot map for OCFS2. This defines the contents of the "slot_map"
386a2ef8
JB
484 * system file. A slot is valid if it contains a node number >= 0. The
485 * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty.
fb86b1f0
JB
486 */
487struct ocfs2_slot_map {
488/*00*/ __le16 sm_slots[0];
489/*
490 * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255,
491 * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize.
492 */
493};
494
386a2ef8
JB
495struct ocfs2_extended_slot {
496/*00*/ __u8 es_valid;
497 __u8 es_reserved1[3];
498 __le32 es_node_num;
499/*10*/
500};
501
502/*
503 * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP
504 * is set. It separates out the valid marker from the node number, and
505 * has room to grow. Unlike the old slot map, this format is defined by
506 * i_size.
507 */
508struct ocfs2_slot_map_extended {
509/*00*/ struct ocfs2_extended_slot se_slots[0];
510/*
511 * Actual size is i_size of the slot_map system file. It should
512 * match s_max_slots * sizeof(struct ocfs2_extended_slot)
513 */
514};
515
ccd979bd
MF
516/*
517 * On disk superblock for OCFS2
518 * Note that it is contained inside an ocfs2_dinode, so all offsets
519 * are relative to the start of ocfs2_dinode.id2.
520 */
521struct ocfs2_super_block {
522/*00*/ __le16 s_major_rev_level;
523 __le16 s_minor_rev_level;
524 __le16 s_mnt_count;
525 __le16 s_max_mnt_count;
526 __le16 s_state; /* File system state */
527 __le16 s_errors; /* Behaviour when detecting errors */
528 __le32 s_checkinterval; /* Max time between checks */
529/*10*/ __le64 s_lastcheck; /* Time of last check */
530 __le32 s_creator_os; /* OS */
531 __le32 s_feature_compat; /* Compatible feature set */
532/*20*/ __le32 s_feature_incompat; /* Incompatible feature set */
533 __le32 s_feature_ro_compat; /* Readonly-compatible feature set */
534 __le64 s_root_blkno; /* Offset, in blocks, of root directory
535 dinode */
536/*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system
537 directory dinode */
538 __le32 s_blocksize_bits; /* Blocksize for this fs */
539 __le32 s_clustersize_bits; /* Clustersize for this fs */
540/*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts
541 before tunefs required */
92e91ce2
MF
542 __le16 s_tunefs_flag;
543 __le32 s_reserved1;
ccd979bd
MF
544 __le64 s_first_cluster_group; /* Block offset of 1st cluster
545 * group header */
546/*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */
547/*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */
548/*A0*/
549};
550
551/*
552 * Local allocation bitmap for OCFS2 slots
553 * Note that it exists inside an ocfs2_dinode, so all offsets are
554 * relative to the start of ocfs2_dinode.id2.
555 */
556struct ocfs2_local_alloc
557{
558/*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */
559 __le16 la_size; /* Size of included bitmap, in bytes */
560 __le16 la_reserved1;
561 __le64 la_reserved2;
562/*10*/ __u8 la_bitmap[0];
563};
564
15b1e36b
MF
565/*
566 * Data-in-inode header. This is only used if i_dyn_features has
567 * OCFS2_INLINE_DATA_FL set.
568 */
569struct ocfs2_inline_data
570{
571/*00*/ __le16 id_count; /* Number of bytes that can be used
572 * for data, starting at id_data */
573 __le16 id_reserved0;
574 __le32 id_reserved1;
575 __u8 id_data[0]; /* Start of user data */
576};
577
ccd979bd
MF
578/*
579 * On disk inode for OCFS2
580 */
581struct ocfs2_dinode {
582/*00*/ __u8 i_signature[8]; /* Signature for validation */
583 __le32 i_generation; /* Generation number */
584 __le16 i_suballoc_slot; /* Slot suballocator this inode
585 belongs to */
586 __le16 i_suballoc_bit; /* Bit offset in suballocator
587 block group */
588/*10*/ __le32 i_reserved0;
589 __le32 i_clusters; /* Cluster count */
590 __le32 i_uid; /* Owner UID */
591 __le32 i_gid; /* Owning GID */
592/*20*/ __le64 i_size; /* Size in bytes */
593 __le16 i_mode; /* File mode */
594 __le16 i_links_count; /* Links count */
595 __le32 i_flags; /* File flags */
596/*30*/ __le64 i_atime; /* Access time */
597 __le64 i_ctime; /* Creation time */
598/*40*/ __le64 i_mtime; /* Modification time */
599 __le64 i_dtime; /* Deletion time */
600/*50*/ __le64 i_blkno; /* Offset on disk, in blocks */
601 __le64 i_last_eb_blk; /* Pointer to last extent
602 block */
603/*60*/ __le32 i_fs_generation; /* Generation per fs-instance */
604 __le32 i_atime_nsec;
605 __le32 i_ctime_nsec;
606 __le32 i_mtime_nsec;
ca4d147e 607 __le32 i_attr;
50008630
TY
608 __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL
609 was set in i_flags */
15b1e36b 610 __le16 i_dyn_features;
ca4d147e 611/*70*/ __le64 i_reserved2[8];
ccd979bd
MF
612/*B8*/ union {
613 __le64 i_pad1; /* Generic way to refer to this
614 64bit union */
615 struct {
616 __le64 i_rdev; /* Device number */
617 } dev1;
618 struct { /* Info for bitmap system
619 inodes */
620 __le32 i_used; /* Bits (ie, clusters) used */
621 __le32 i_total; /* Total bits (clusters)
622 available */
623 } bitmap1;
624 struct { /* Info for journal system
625 inodes */
626 __le32 ij_flags; /* Mounted, version, etc. */
627 __le32 ij_pad;
628 } journal1;
629 } id1; /* Inode type dependant 1 */
630/*C0*/ union {
631 struct ocfs2_super_block i_super;
632 struct ocfs2_local_alloc i_lab;
633 struct ocfs2_chain_list i_chain;
634 struct ocfs2_extent_list i_list;
635 struct ocfs2_truncate_log i_dealloc;
15b1e36b 636 struct ocfs2_inline_data i_data;
ccd979bd
MF
637 __u8 i_symlink[0];
638 } id2;
639/* Actual on-disk size is one block */
640};
641
642/*
643 * On-disk directory entry structure for OCFS2
644 *
645 * Packed as this structure could be accessed unaligned on 64-bit platforms
646 */
647struct ocfs2_dir_entry {
648/*00*/ __le64 inode; /* Inode number */
649 __le16 rec_len; /* Directory entry length */
650 __u8 name_len; /* Name length */
651 __u8 file_type;
652/*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */
653/* Actual on-disk length specified by rec_len */
654} __attribute__ ((packed));
655
656/*
657 * On disk allocator group structure for OCFS2
658 */
659struct ocfs2_group_desc
660{
661/*00*/ __u8 bg_signature[8]; /* Signature for validation */
662 __le16 bg_size; /* Size of included bitmap in
663 bytes. */
664 __le16 bg_bits; /* Bits represented by this
665 group. */
666 __le16 bg_free_bits_count; /* Free bits count */
667 __le16 bg_chain; /* What chain I am in. */
668/*10*/ __le32 bg_generation;
669 __le32 bg_reserved1;
670 __le64 bg_next_group; /* Next group in my list, in
671 blocks */
672/*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in
673 blocks */
674 __le64 bg_blkno; /* Offset on disk, in blocks */
675/*30*/ __le64 bg_reserved2[2];
676/*40*/ __u8 bg_bitmap[0];
677};
678
679#ifdef __KERNEL__
680static inline int ocfs2_fast_symlink_chars(struct super_block *sb)
681{
682 return sb->s_blocksize -
683 offsetof(struct ocfs2_dinode, id2.i_symlink);
684}
685
15b1e36b
MF
686static inline int ocfs2_max_inline_data(struct super_block *sb)
687{
688 return sb->s_blocksize -
689 offsetof(struct ocfs2_dinode, id2.i_data.id_data);
690}
691
ccd979bd
MF
692static inline int ocfs2_extent_recs_per_inode(struct super_block *sb)
693{
694 int size;
695
696 size = sb->s_blocksize -
697 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
698
699 return size / sizeof(struct ocfs2_extent_rec);
700}
701
702static inline int ocfs2_chain_recs_per_inode(struct super_block *sb)
703{
704 int size;
705
706 size = sb->s_blocksize -
707 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
708
709 return size / sizeof(struct ocfs2_chain_rec);
710}
711
712static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb)
713{
714 int size;
715
716 size = sb->s_blocksize -
717 offsetof(struct ocfs2_extent_block, h_list.l_recs);
718
719 return size / sizeof(struct ocfs2_extent_rec);
720}
721
722static inline u16 ocfs2_local_alloc_size(struct super_block *sb)
723{
724 u16 size;
725
726 size = sb->s_blocksize -
727 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
728
729 return size;
730}
731
732static inline int ocfs2_group_bitmap_size(struct super_block *sb)
733{
734 int size;
735
736 size = sb->s_blocksize -
737 offsetof(struct ocfs2_group_desc, bg_bitmap);
738
739 return size;
740}
741
742static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb)
743{
744 int size;
745
746 size = sb->s_blocksize -
747 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
748
749 return size / sizeof(struct ocfs2_truncate_rec);
750}
50af94b1
MF
751
752static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index)
753{
754 u64 offset = OCFS2_BACKUP_SB_START;
755
756 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
757 offset <<= (2 * index);
a8a75a20 758 offset >>= sb->s_blocksize_bits;
50af94b1
MF
759 return offset;
760 }
761
762 return 0;
763
764}
ccd979bd
MF
765#else
766static inline int ocfs2_fast_symlink_chars(int blocksize)
767{
768 return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink);
769}
770
15b1e36b
MF
771static inline int ocfs2_max_inline_data(int blocksize)
772{
773 return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data);
774}
775
ccd979bd
MF
776static inline int ocfs2_extent_recs_per_inode(int blocksize)
777{
778 int size;
779
780 size = blocksize -
781 offsetof(struct ocfs2_dinode, id2.i_list.l_recs);
782
783 return size / sizeof(struct ocfs2_extent_rec);
784}
785
786static inline int ocfs2_chain_recs_per_inode(int blocksize)
787{
788 int size;
789
790 size = blocksize -
791 offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs);
792
793 return size / sizeof(struct ocfs2_chain_rec);
794}
795
796static inline int ocfs2_extent_recs_per_eb(int blocksize)
797{
798 int size;
799
800 size = blocksize -
801 offsetof(struct ocfs2_extent_block, h_list.l_recs);
802
803 return size / sizeof(struct ocfs2_extent_rec);
804}
805
806static inline int ocfs2_local_alloc_size(int blocksize)
807{
808 int size;
809
810 size = blocksize -
811 offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap);
812
813 return size;
814}
815
816static inline int ocfs2_group_bitmap_size(int blocksize)
817{
818 int size;
819
820 size = blocksize -
821 offsetof(struct ocfs2_group_desc, bg_bitmap);
822
823 return size;
824}
825
826static inline int ocfs2_truncate_recs_per_inode(int blocksize)
827{
828 int size;
829
830 size = blocksize -
831 offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs);
832
833 return size / sizeof(struct ocfs2_truncate_rec);
834}
50af94b1
MF
835
836static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index)
837{
838 uint64_t offset = OCFS2_BACKUP_SB_START;
839
840 if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) {
841 offset <<= (2 * index);
842 offset /= blocksize;
843 return offset;
844 }
845
846 return 0;
847}
ccd979bd
MF
848#endif /* __KERNEL__ */
849
850
851static inline int ocfs2_system_inode_is_global(int type)
852{
853 return ((type >= 0) &&
854 (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE));
855}
856
857static inline int ocfs2_sprintf_system_inode_name(char *buf, int len,
858 int type, int slot)
859{
860 int chars;
861
862 /*
863 * Global system inodes can only have one copy. Everything
864 * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode
865 * list has a copy per slot.
866 */
867 if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)
868 chars = snprintf(buf, len,
869 ocfs2_system_inodes[type].si_name);
870 else
871 chars = snprintf(buf, len,
872 ocfs2_system_inodes[type].si_name,
873 slot);
874
875 return chars;
876}
877
878static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de,
879 umode_t mode)
880{
881 de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT];
882}
883
884#endif /* _OCFS2_FS_H */
885