Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 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 | |
Fabian Frederick | 62aa81d | 2017-07-06 15:36:10 -0700 | [diff] [blame] | 28 | #include <linux/magic.h> |
| 29 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 30 | /* Version */ |
| 31 | #define OCFS2_MAJOR_REV_LEVEL 0 |
| 32 | #define OCFS2_MINOR_REV_LEVEL 90 |
| 33 | |
| 34 | /* |
| 35 | * An OCFS2 volume starts this way: |
| 36 | * Sector 0: Valid ocfs1_vol_disk_hdr that cleanly fails to mount OCFS. |
| 37 | * Sector 1: Valid ocfs1_vol_label that cleanly fails to mount OCFS. |
| 38 | * Block OCFS2_SUPER_BLOCK_BLKNO: OCFS2 superblock. |
| 39 | * |
| 40 | * All other structures are found from the superblock information. |
| 41 | * |
| 42 | * OCFS2_SUPER_BLOCK_BLKNO is in blocks, not sectors. eg, for a |
| 43 | * blocksize of 2K, it is 4096 bytes into disk. |
| 44 | */ |
| 45 | #define OCFS2_SUPER_BLOCK_BLKNO 2 |
| 46 | |
| 47 | /* |
| 48 | * Cluster size limits. The maximum is kept arbitrarily at 1 MB, and could |
| 49 | * grow if needed. |
| 50 | */ |
| 51 | #define OCFS2_MIN_CLUSTERSIZE 4096 |
| 52 | #define OCFS2_MAX_CLUSTERSIZE 1048576 |
| 53 | |
| 54 | /* |
| 55 | * Blocks cannot be bigger than clusters, so the maximum blocksize is the |
| 56 | * minimum cluster size. |
| 57 | */ |
| 58 | #define OCFS2_MIN_BLOCKSIZE 512 |
| 59 | #define OCFS2_MAX_BLOCKSIZE OCFS2_MIN_CLUSTERSIZE |
| 60 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 61 | /* Object signatures */ |
| 62 | #define OCFS2_SUPER_BLOCK_SIGNATURE "OCFSV2" |
| 63 | #define OCFS2_INODE_SIGNATURE "INODE01" |
| 64 | #define OCFS2_EXTENT_BLOCK_SIGNATURE "EXBLK01" |
| 65 | #define OCFS2_GROUP_DESC_SIGNATURE "GROUP01" |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 66 | #define OCFS2_XATTR_BLOCK_SIGNATURE "XATTR01" |
Mark Fasheh | 87d35a7 | 2008-12-10 17:36:25 -0800 | [diff] [blame] | 67 | #define OCFS2_DIR_TRAILER_SIGNATURE "DIRTRL1" |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 68 | #define OCFS2_DX_ROOT_SIGNATURE "DXDIR01" |
| 69 | #define OCFS2_DX_LEAF_SIGNATURE "DXLEAF1" |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 70 | #define OCFS2_REFCOUNT_BLOCK_SIGNATURE "REFCNT1" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 71 | |
| 72 | /* Compatibility flags */ |
| 73 | #define OCFS2_HAS_COMPAT_FEATURE(sb,mask) \ |
| 74 | ( OCFS2_SB(sb)->s_feature_compat & (mask) ) |
| 75 | #define OCFS2_HAS_RO_COMPAT_FEATURE(sb,mask) \ |
| 76 | ( OCFS2_SB(sb)->s_feature_ro_compat & (mask) ) |
| 77 | #define OCFS2_HAS_INCOMPAT_FEATURE(sb,mask) \ |
| 78 | ( OCFS2_SB(sb)->s_feature_incompat & (mask) ) |
| 79 | #define OCFS2_SET_COMPAT_FEATURE(sb,mask) \ |
| 80 | OCFS2_SB(sb)->s_feature_compat |= (mask) |
| 81 | #define OCFS2_SET_RO_COMPAT_FEATURE(sb,mask) \ |
| 82 | OCFS2_SB(sb)->s_feature_ro_compat |= (mask) |
| 83 | #define OCFS2_SET_INCOMPAT_FEATURE(sb,mask) \ |
| 84 | OCFS2_SB(sb)->s_feature_incompat |= (mask) |
| 85 | #define OCFS2_CLEAR_COMPAT_FEATURE(sb,mask) \ |
| 86 | OCFS2_SB(sb)->s_feature_compat &= ~(mask) |
| 87 | #define OCFS2_CLEAR_RO_COMPAT_FEATURE(sb,mask) \ |
| 88 | OCFS2_SB(sb)->s_feature_ro_compat &= ~(mask) |
| 89 | #define OCFS2_CLEAR_INCOMPAT_FEATURE(sb,mask) \ |
| 90 | OCFS2_SB(sb)->s_feature_incompat &= ~(mask) |
| 91 | |
Joel Becker | a977218 | 2008-12-16 18:10:18 -0800 | [diff] [blame] | 92 | #define OCFS2_FEATURE_COMPAT_SUPP (OCFS2_FEATURE_COMPAT_BACKUP_SB \ |
| 93 | | OCFS2_FEATURE_COMPAT_JBD2_SB) |
Mark Fasheh | dcd0538 | 2007-01-16 11:32:23 -0800 | [diff] [blame] | 94 | #define OCFS2_FEATURE_INCOMPAT_SUPP (OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT \ |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 95 | | OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC \ |
Joel Becker | 386a2ef | 2008-02-01 12:06:54 -0800 | [diff] [blame] | 96 | | OCFS2_FEATURE_INCOMPAT_INLINE_DATA \ |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 97 | | OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP \ |
Tiger Yang | 8154da3 | 2008-08-18 17:11:46 +0800 | [diff] [blame] | 98 | | OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK \ |
Joel Becker | 9d28cfb | 2008-10-16 17:53:29 -0700 | [diff] [blame] | 99 | | OCFS2_FEATURE_INCOMPAT_XATTR \ |
Mark Fasheh | 3a8df2b | 2008-11-24 17:14:09 -0800 | [diff] [blame] | 100 | | OCFS2_FEATURE_INCOMPAT_META_ECC \ |
Tao Ma | 64871b8 | 2009-08-18 11:48:02 +0800 | [diff] [blame] | 101 | | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS \ |
Tao Ma | 1a934c3 | 2010-03-18 15:54:22 +0800 | [diff] [blame] | 102 | | OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE \ |
Sunil Mushran | 98f486f2 | 2010-10-09 10:24:46 -0700 | [diff] [blame] | 103 | | OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG \ |
Mark Fasheh | 18d585f | 2015-03-12 16:25:46 -0700 | [diff] [blame] | 104 | | OCFS2_FEATURE_INCOMPAT_CLUSTERINFO \ |
| 105 | | OCFS2_FEATURE_INCOMPAT_APPEND_DIO) |
Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 106 | #define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \ |
| 107 | | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \ |
Mark Fasheh | 18d585f | 2015-03-12 16:25:46 -0700 | [diff] [blame] | 108 | | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 109 | |
| 110 | /* |
| 111 | * Heartbeat-only devices are missing journals and other files. The |
| 112 | * filesystem driver can't load them, but the library can. Never put |
| 113 | * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*. |
| 114 | */ |
| 115 | #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002 |
| 116 | |
Mark Fasheh | 8903901 | 2006-12-07 18:05:37 -0800 | [diff] [blame] | 117 | /* |
| 118 | * tunefs sets this incompat flag before starting the resize and clears it |
| 119 | * at the end. This flag protects users from inadvertently mounting the fs |
| 120 | * after an aborted run without fsck-ing. |
| 121 | */ |
| 122 | #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004 |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 123 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 124 | /* Used to denote a non-clustered volume */ |
| 125 | #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008 |
| 126 | |
Mark Fasheh | 8903901 | 2006-12-07 18:05:37 -0800 | [diff] [blame] | 127 | /* Support for sparse allocation in b-trees */ |
| 128 | #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010 |
| 129 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 130 | /* |
Mark Fasheh | 92e91ce | 2007-09-20 11:19:20 -0700 | [diff] [blame] | 131 | * Tunefs sets this incompat flag before starting an operation which |
| 132 | * would require cleanup on abort. This is done to protect users from |
| 133 | * inadvertently mounting the fs after an aborted run without |
| 134 | * fsck-ing. |
| 135 | * |
| 136 | * s_tunefs_flags on the super block describes precisely which |
| 137 | * operations were in progress. |
| 138 | */ |
| 139 | #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020 |
| 140 | |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 141 | /* Support for data packed into inode blocks */ |
| 142 | #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040 |
| 143 | |
Mark Fasheh | 92e91ce | 2007-09-20 11:19:20 -0700 | [diff] [blame] | 144 | /* |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 145 | * Support for alternate, userspace cluster stacks. If set, the superblock |
| 146 | * field s_cluster_info contains a tag for the alternate stack in use as |
| 147 | * well as the name of the cluster being joined. |
| 148 | * mount.ocfs2 must pass in a matching stack name. |
| 149 | * |
| 150 | * If not set, the classic stack will be used. This is compatbile with |
| 151 | * all older versions. |
| 152 | */ |
| 153 | #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080 |
| 154 | |
Tiger Yang | 8154da3 | 2008-08-18 17:11:46 +0800 | [diff] [blame] | 155 | /* Support for the extended slot map */ |
| 156 | #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100 |
| 157 | |
| 158 | /* Support for extended attributes */ |
| 159 | #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200 |
| 160 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 161 | /* Support for indexed directores */ |
| 162 | #define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400 |
| 163 | |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 164 | /* Metadata checksum and error correction */ |
| 165 | #define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800 |
| 166 | |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 167 | /* Refcount tree support */ |
| 168 | #define OCFS2_FEATURE_INCOMPAT_REFCOUNT_TREE 0x1000 |
| 169 | |
Masahiro Yamada | e1c0506 | 2015-07-07 10:14:59 +0900 | [diff] [blame] | 170 | /* Discontiguous block groups */ |
Joel Becker | 4cbe424 | 2010-04-13 14:26:12 +0800 | [diff] [blame] | 171 | #define OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG 0x2000 |
| 172 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 173 | /* |
Sunil Mushran | 98f486f2 | 2010-10-09 10:24:46 -0700 | [diff] [blame] | 174 | * Incompat bit to indicate useable clusterinfo with stackflags for all |
| 175 | * cluster stacks (userspace adnd o2cb). If this bit is set, |
| 176 | * INCOMPAT_USERSPACE_STACK becomes superfluous and thus should not be set. |
| 177 | */ |
| 178 | #define OCFS2_FEATURE_INCOMPAT_CLUSTERINFO 0x4000 |
| 179 | |
| 180 | /* |
Mark Fasheh | 18d585f | 2015-03-12 16:25:46 -0700 | [diff] [blame] | 181 | * Append Direct IO support |
| 182 | */ |
| 183 | #define OCFS2_FEATURE_INCOMPAT_APPEND_DIO 0x8000 |
| 184 | |
| 185 | /* |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 186 | * backup superblock flag is used to indicate that this volume |
| 187 | * has backup superblocks. |
| 188 | */ |
| 189 | #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001 |
| 190 | |
Mark Fasheh | 328d575 | 2007-06-18 10:48:04 -0700 | [diff] [blame] | 191 | /* |
Joel Becker | a977218 | 2008-12-16 18:10:18 -0800 | [diff] [blame] | 192 | * The filesystem will correctly handle journal feature bits. |
| 193 | */ |
| 194 | #define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002 |
| 195 | |
| 196 | /* |
Mark Fasheh | 328d575 | 2007-06-18 10:48:04 -0700 | [diff] [blame] | 197 | * Unwritten extents support. |
| 198 | */ |
| 199 | #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001 |
| 200 | |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 201 | /* |
| 202 | * Maintain quota information for this filesystem |
| 203 | */ |
| 204 | #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002 |
| 205 | #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004 |
| 206 | |
Joseph Qi | 160cc26 | 2015-02-16 16:00:15 -0800 | [diff] [blame] | 207 | |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 208 | /* The byte offset of the first backup block will be 1G. |
| 209 | * The following will be 4G, 16G, 64G, 256G and 1T. |
| 210 | */ |
| 211 | #define OCFS2_BACKUP_SB_START 1 << 30 |
| 212 | |
| 213 | /* the max backup superblock nums */ |
| 214 | #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6 |
| 215 | |
| 216 | /* |
Mark Fasheh | 92e91ce | 2007-09-20 11:19:20 -0700 | [diff] [blame] | 217 | * Flags on ocfs2_super_block.s_tunefs_flags |
| 218 | */ |
| 219 | #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */ |
| 220 | |
| 221 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 222 | * Flags on ocfs2_dinode.i_flags |
| 223 | */ |
| 224 | #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */ |
| 225 | #define OCFS2_UNUSED2_FL (0x00000002) |
| 226 | #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */ |
| 227 | #define OCFS2_UNUSED3_FL (0x00000008) |
| 228 | /* System inode flags */ |
| 229 | #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */ |
| 230 | #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */ |
| 231 | #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */ |
| 232 | #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */ |
| 233 | #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */ |
| 234 | #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */ |
| 235 | #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */ |
| 236 | #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */ |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 237 | #define OCFS2_QUOTA_FL (0x00001000) /* Quota file */ |
Joseph Qi | 06ee5c7 | 2015-02-16 15:59:54 -0800 | [diff] [blame] | 238 | #define OCFS2_DIO_ORPHANED_FL (0X00002000) /* On the orphan list especially |
| 239 | * for dio */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 240 | |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 241 | /* |
| 242 | * Flags on ocfs2_dinode.i_dyn_features |
| 243 | * |
| 244 | * These can change much more often than i_flags. When adding flags, |
| 245 | * keep in mind that i_dyn_features is only 16 bits wide. |
| 246 | */ |
| 247 | #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */ |
| 248 | #define OCFS2_HAS_XATTR_FL (0x0002) |
| 249 | #define OCFS2_INLINE_XATTR_FL (0x0004) |
| 250 | #define OCFS2_INDEXED_DIR_FL (0x0008) |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 251 | #define OCFS2_HAS_REFCOUNT_FL (0x0010) |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 252 | |
Herbert Poetzl | ca4d147 | 2006-07-03 17:27:12 -0700 | [diff] [blame] | 253 | /* Inode attributes, keep in sync with EXT2 */ |
Tao Ma | 0000b86 | 2010-09-19 13:42:29 +0800 | [diff] [blame] | 254 | #define OCFS2_SECRM_FL FS_SECRM_FL /* Secure deletion */ |
| 255 | #define OCFS2_UNRM_FL FS_UNRM_FL /* Undelete */ |
| 256 | #define OCFS2_COMPR_FL FS_COMPR_FL /* Compress file */ |
| 257 | #define OCFS2_SYNC_FL FS_SYNC_FL /* Synchronous updates */ |
| 258 | #define OCFS2_IMMUTABLE_FL FS_IMMUTABLE_FL /* Immutable file */ |
| 259 | #define OCFS2_APPEND_FL FS_APPEND_FL /* writes to file may only append */ |
| 260 | #define OCFS2_NODUMP_FL FS_NODUMP_FL /* do not dump file */ |
| 261 | #define OCFS2_NOATIME_FL FS_NOATIME_FL /* do not update atime */ |
| 262 | /* Reserved for compression usage... */ |
| 263 | #define OCFS2_DIRTY_FL FS_DIRTY_FL |
| 264 | #define OCFS2_COMPRBLK_FL FS_COMPRBLK_FL /* One or more compressed clusters */ |
| 265 | #define OCFS2_NOCOMP_FL FS_NOCOMP_FL /* Don't compress */ |
| 266 | #define OCFS2_ECOMPR_FL FS_ECOMPR_FL /* Compression error */ |
| 267 | /* End compression flags --- maybe not all used */ |
| 268 | #define OCFS2_BTREE_FL FS_BTREE_FL /* btree format dir */ |
| 269 | #define OCFS2_INDEX_FL FS_INDEX_FL /* hash-indexed directory */ |
| 270 | #define OCFS2_IMAGIC_FL FS_IMAGIC_FL /* AFS directory */ |
| 271 | #define OCFS2_JOURNAL_DATA_FL FS_JOURNAL_DATA_FL /* Reserved for ext3 */ |
| 272 | #define OCFS2_NOTAIL_FL FS_NOTAIL_FL /* file tail should not be merged */ |
| 273 | #define OCFS2_DIRSYNC_FL FS_DIRSYNC_FL /* dirsync behaviour (directories only) */ |
| 274 | #define OCFS2_TOPDIR_FL FS_TOPDIR_FL /* Top of directory hierarchies*/ |
| 275 | #define OCFS2_RESERVED_FL FS_RESERVED_FL /* reserved for ext2 lib */ |
Herbert Poetzl | ca4d147 | 2006-07-03 17:27:12 -0700 | [diff] [blame] | 276 | |
Tao Ma | 0000b86 | 2010-09-19 13:42:29 +0800 | [diff] [blame] | 277 | #define OCFS2_FL_VISIBLE FS_FL_USER_VISIBLE /* User visible flags */ |
| 278 | #define OCFS2_FL_MODIFIABLE FS_FL_USER_MODIFIABLE /* User modifiable flags */ |
Herbert Poetzl | ca4d147 | 2006-07-03 17:27:12 -0700 | [diff] [blame] | 279 | |
| 280 | /* |
Mark Fasheh | e48edee | 2007-03-07 16:46:57 -0800 | [diff] [blame] | 281 | * Extent record flags (e_node.leaf.flags) |
| 282 | */ |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 283 | #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but |
| 284 | * unwritten */ |
| 285 | #define OCFS2_EXT_REFCOUNTED (0x02) /* Extent is reference |
| 286 | * counted in an associated |
| 287 | * refcount tree */ |
Mark Fasheh | e48edee | 2007-03-07 16:46:57 -0800 | [diff] [blame] | 288 | |
| 289 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 290 | * Journal Flags (ocfs2_dinode.id1.journal1.i_flags) |
| 291 | */ |
| 292 | #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */ |
| 293 | |
| 294 | /* |
| 295 | * superblock s_state flags |
| 296 | */ |
| 297 | #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */ |
| 298 | |
| 299 | /* Limit of space in ocfs2_dir_entry */ |
| 300 | #define OCFS2_MAX_FILENAME_LEN 255 |
| 301 | |
| 302 | /* Maximum slots on an ocfs2 file system */ |
| 303 | #define OCFS2_MAX_SLOTS 255 |
| 304 | |
| 305 | /* Slot map indicator for an empty slot */ |
| 306 | #define OCFS2_INVALID_SLOT -1 |
| 307 | |
| 308 | #define OCFS2_VOL_UUID_LEN 16 |
| 309 | #define OCFS2_MAX_VOL_LABEL_LEN 64 |
| 310 | |
Sunil Mushran | 98f486f2 | 2010-10-09 10:24:46 -0700 | [diff] [blame] | 311 | /* The cluster stack fields */ |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 312 | #define OCFS2_STACK_LABEL_LEN 4 |
| 313 | #define OCFS2_CLUSTER_NAME_LEN 16 |
| 314 | |
Sunil Mushran | 98f486f2 | 2010-10-09 10:24:46 -0700 | [diff] [blame] | 315 | /* Classic (historically speaking) cluster stack */ |
| 316 | #define OCFS2_CLASSIC_CLUSTER_STACK "o2cb" |
| 317 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 318 | /* Journal limits (in bytes) */ |
| 319 | #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 320 | |
Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 321 | /* |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 322 | * Inline extended attribute size (in bytes) |
| 323 | * The value chosen should be aligned to 16 byte boundaries. |
| 324 | */ |
| 325 | #define OCFS2_MIN_XATTR_INLINE_SIZE 256 |
| 326 | |
Sunil Mushran | 98f486f2 | 2010-10-09 10:24:46 -0700 | [diff] [blame] | 327 | /* |
| 328 | * Cluster info flags (ocfs2_cluster_info.ci_stackflags) |
| 329 | */ |
| 330 | #define OCFS2_CLUSTER_O2CB_GLOBAL_HEARTBEAT (0x01) |
| 331 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 332 | struct ocfs2_system_inode_info { |
| 333 | char *si_name; |
| 334 | int si_iflags; |
| 335 | int si_mode; |
| 336 | }; |
| 337 | |
| 338 | /* System file index */ |
| 339 | enum { |
| 340 | BAD_BLOCK_SYSTEM_INODE = 0, |
| 341 | GLOBAL_INODE_ALLOC_SYSTEM_INODE, |
| 342 | SLOT_MAP_SYSTEM_INODE, |
| 343 | #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE |
| 344 | HEARTBEAT_SYSTEM_INODE, |
| 345 | GLOBAL_BITMAP_SYSTEM_INODE, |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 346 | USER_QUOTA_SYSTEM_INODE, |
| 347 | GROUP_QUOTA_SYSTEM_INODE, |
| 348 | #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE |
Tao Ma | b4d693f | 2010-08-16 16:58:21 +0800 | [diff] [blame] | 349 | #define OCFS2_FIRST_LOCAL_SYSTEM_INODE ORPHAN_DIR_SYSTEM_INODE |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 350 | ORPHAN_DIR_SYSTEM_INODE, |
| 351 | EXTENT_ALLOC_SYSTEM_INODE, |
| 352 | INODE_ALLOC_SYSTEM_INODE, |
| 353 | JOURNAL_SYSTEM_INODE, |
| 354 | LOCAL_ALLOC_SYSTEM_INODE, |
| 355 | TRUNCATE_LOG_SYSTEM_INODE, |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 356 | LOCAL_USER_QUOTA_SYSTEM_INODE, |
| 357 | LOCAL_GROUP_QUOTA_SYSTEM_INODE, |
Tao Ma | b4d693f | 2010-08-16 16:58:21 +0800 | [diff] [blame] | 358 | #define OCFS2_LAST_LOCAL_SYSTEM_INODE LOCAL_GROUP_QUOTA_SYSTEM_INODE |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 359 | NUM_SYSTEM_INODES |
| 360 | }; |
Tao Ma | 7d8f987 | 2010-12-22 17:50:30 +0800 | [diff] [blame] | 361 | #define NUM_GLOBAL_SYSTEM_INODES OCFS2_FIRST_LOCAL_SYSTEM_INODE |
Tao Ma | b4d693f | 2010-08-16 16:58:21 +0800 | [diff] [blame] | 362 | #define NUM_LOCAL_SYSTEM_INODES \ |
| 363 | (NUM_SYSTEM_INODES - OCFS2_FIRST_LOCAL_SYSTEM_INODE) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 364 | |
| 365 | static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { |
| 366 | /* Global system inodes (single copy) */ |
| 367 | /* The first two are only used from userspace mfks/tunefs */ |
| 368 | [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 }, |
| 369 | [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, |
| 370 | |
| 371 | /* These are used by the running filesystem */ |
| 372 | [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 }, |
| 373 | [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 }, |
| 374 | [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 }, |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 375 | [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
| 376 | [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 377 | |
| 378 | /* Slot-specific system inodes (one copy per slot) */ |
| 379 | [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 }, |
| 380 | [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, |
| 381 | [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, |
| 382 | [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 }, |
| 383 | [LOCAL_ALLOC_SYSTEM_INODE] = { "local_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_LOCAL_ALLOC_FL, S_IFREG | 0644 }, |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 384 | [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }, |
| 385 | [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
| 386 | [LOCAL_GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 387 | }; |
| 388 | |
| 389 | /* Parameter passed from mount.ocfs2 to module */ |
| 390 | #define OCFS2_HB_NONE "heartbeat=none" |
| 391 | #define OCFS2_HB_LOCAL "heartbeat=local" |
Sunil Mushran | 2c44271 | 2010-10-07 15:23:50 -0700 | [diff] [blame] | 392 | #define OCFS2_HB_GLOBAL "heartbeat=global" |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 393 | |
| 394 | /* |
| 395 | * OCFS2 directory file types. Only the low 3 bits are used. The |
| 396 | * other bits are reserved for now. |
| 397 | */ |
| 398 | #define OCFS2_FT_UNKNOWN 0 |
| 399 | #define OCFS2_FT_REG_FILE 1 |
| 400 | #define OCFS2_FT_DIR 2 |
| 401 | #define OCFS2_FT_CHRDEV 3 |
| 402 | #define OCFS2_FT_BLKDEV 4 |
| 403 | #define OCFS2_FT_FIFO 5 |
| 404 | #define OCFS2_FT_SOCK 6 |
| 405 | #define OCFS2_FT_SYMLINK 7 |
| 406 | |
| 407 | #define OCFS2_FT_MAX 8 |
| 408 | |
| 409 | /* |
| 410 | * OCFS2_DIR_PAD defines the directory entries boundaries |
| 411 | * |
| 412 | * NOTE: It must be a multiple of 4 |
| 413 | */ |
| 414 | #define OCFS2_DIR_PAD 4 |
| 415 | #define OCFS2_DIR_ROUND (OCFS2_DIR_PAD - 1) |
| 416 | #define OCFS2_DIR_MEMBER_LEN offsetof(struct ocfs2_dir_entry, name) |
| 417 | #define OCFS2_DIR_REC_LEN(name_len) (((name_len) + OCFS2_DIR_MEMBER_LEN + \ |
| 418 | OCFS2_DIR_ROUND) & \ |
| 419 | ~OCFS2_DIR_ROUND) |
Mark Fasheh | e7c17e4 | 2009-01-29 18:17:46 -0800 | [diff] [blame] | 420 | #define OCFS2_DIR_MIN_REC_LEN OCFS2_DIR_REC_LEN(1) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 421 | |
| 422 | #define OCFS2_LINK_MAX 32000 |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 423 | #define OCFS2_DX_LINK_MAX ((1U << 31) - 1U) |
| 424 | #define OCFS2_LINKS_HI_SHIFT 16 |
Mark Fasheh | e3a93c2 | 2009-02-17 15:29:35 -0800 | [diff] [blame] | 425 | #define OCFS2_DX_ENTRIES_MAX (0xffffffffU) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 426 | |
| 427 | #define S_SHIFT 12 |
| 428 | static unsigned char ocfs2_type_by_mode[S_IFMT >> S_SHIFT] = { |
| 429 | [S_IFREG >> S_SHIFT] = OCFS2_FT_REG_FILE, |
| 430 | [S_IFDIR >> S_SHIFT] = OCFS2_FT_DIR, |
| 431 | [S_IFCHR >> S_SHIFT] = OCFS2_FT_CHRDEV, |
| 432 | [S_IFBLK >> S_SHIFT] = OCFS2_FT_BLKDEV, |
| 433 | [S_IFIFO >> S_SHIFT] = OCFS2_FT_FIFO, |
| 434 | [S_IFSOCK >> S_SHIFT] = OCFS2_FT_SOCK, |
| 435 | [S_IFLNK >> S_SHIFT] = OCFS2_FT_SYMLINK, |
| 436 | }; |
| 437 | |
| 438 | |
| 439 | /* |
| 440 | * Convenience casts |
| 441 | */ |
| 442 | #define OCFS2_RAW_SB(dinode) (&((dinode)->id2.i_super)) |
| 443 | |
| 444 | /* |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 445 | * Block checking structure. This is used in metadata to validate the |
| 446 | * contents. If OCFS2_FEATURE_INCOMPAT_META_ECC is not set, it is all |
| 447 | * zeros. |
| 448 | */ |
| 449 | struct ocfs2_block_check { |
| 450 | /*00*/ __le32 bc_crc32e; /* 802.3 Ethernet II CRC32 */ |
| 451 | __le16 bc_ecc; /* Single-error-correction parity vector. |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 452 | This is a simple Hamming code dependent |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 453 | on the blocksize. OCFS2's maximum |
| 454 | blocksize, 4K, requires 16 parity bits, |
| 455 | so we fit in __le16. */ |
| 456 | __le16 bc_reserved1; |
| 457 | /*08*/ |
| 458 | }; |
| 459 | |
| 460 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 461 | * On disk extent record for OCFS2 |
| 462 | * It describes a range of clusters on disk. |
Mark Fasheh | e48edee | 2007-03-07 16:46:57 -0800 | [diff] [blame] | 463 | * |
| 464 | * Length fields are divided into interior and leaf node versions. |
| 465 | * This leaves room for a flags field (OCFS2_EXT_*) in the leaf nodes. |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 466 | */ |
| 467 | struct ocfs2_extent_rec { |
| 468 | /*00*/ __le32 e_cpos; /* Offset into the file, in clusters */ |
Mark Fasheh | e48edee | 2007-03-07 16:46:57 -0800 | [diff] [blame] | 469 | union { |
| 470 | __le32 e_int_clusters; /* Clusters covered by all children */ |
| 471 | struct { |
| 472 | __le16 e_leaf_clusters; /* Clusters covered by this |
| 473 | extent */ |
| 474 | __u8 e_reserved1; |
| 475 | __u8 e_flags; /* Extent flags */ |
| 476 | }; |
| 477 | }; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 478 | __le64 e_blkno; /* Physical disk offset, in blocks */ |
| 479 | /*10*/ |
| 480 | }; |
| 481 | |
| 482 | struct ocfs2_chain_rec { |
| 483 | __le32 c_free; /* Number of free bits in this chain. */ |
| 484 | __le32 c_total; /* Number of total bits in this chain */ |
| 485 | __le64 c_blkno; /* Physical disk offset (blocks) of 1st group */ |
| 486 | }; |
| 487 | |
| 488 | struct ocfs2_truncate_rec { |
| 489 | __le32 t_start; /* 1st cluster in this log */ |
| 490 | __le32 t_clusters; /* Number of total clusters covered */ |
| 491 | }; |
| 492 | |
| 493 | /* |
| 494 | * On disk extent list for OCFS2 (node in the tree). Note that this |
| 495 | * is contained inside ocfs2_dinode or ocfs2_extent_block, so the |
| 496 | * offsets are relative to ocfs2_dinode.id2.i_list or |
| 497 | * ocfs2_extent_block.h_list, respectively. |
| 498 | */ |
| 499 | struct ocfs2_extent_list { |
| 500 | /*00*/ __le16 l_tree_depth; /* Extent tree depth from this |
| 501 | point. 0 means data extents |
| 502 | hang directly off this |
Mark Fasheh | dcd0538 | 2007-01-16 11:32:23 -0800 | [diff] [blame] | 503 | header (a leaf) |
| 504 | NOTE: The high 8 bits cannot be |
| 505 | used - tree_depth is never that big. |
| 506 | */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 507 | __le16 l_count; /* Number of extent records */ |
| 508 | __le16 l_next_free_rec; /* Next unused extent slot */ |
| 509 | __le16 l_reserved1; |
| 510 | __le64 l_reserved2; /* Pad to |
| 511 | sizeof(ocfs2_extent_rec) */ |
| 512 | /*10*/ struct ocfs2_extent_rec l_recs[0]; /* Extent records */ |
| 513 | }; |
| 514 | |
| 515 | /* |
| 516 | * On disk allocation chain list for OCFS2. Note that this is |
| 517 | * contained inside ocfs2_dinode, so the offsets are relative to |
| 518 | * ocfs2_dinode.id2.i_chain. |
| 519 | */ |
| 520 | struct ocfs2_chain_list { |
| 521 | /*00*/ __le16 cl_cpg; /* Clusters per Block Group */ |
| 522 | __le16 cl_bpc; /* Bits per cluster */ |
| 523 | __le16 cl_count; /* Total chains in this list */ |
| 524 | __le16 cl_next_free_rec; /* Next unused chain slot */ |
| 525 | __le64 cl_reserved1; |
| 526 | /*10*/ struct ocfs2_chain_rec cl_recs[0]; /* Chain records */ |
| 527 | }; |
| 528 | |
| 529 | /* |
| 530 | * On disk deallocation log for OCFS2. Note that this is |
| 531 | * contained inside ocfs2_dinode, so the offsets are relative to |
| 532 | * ocfs2_dinode.id2.i_dealloc. |
| 533 | */ |
| 534 | struct ocfs2_truncate_log { |
| 535 | /*00*/ __le16 tl_count; /* Total records in this log */ |
| 536 | __le16 tl_used; /* Number of records in use */ |
| 537 | __le32 tl_reserved1; |
| 538 | /*08*/ struct ocfs2_truncate_rec tl_recs[0]; /* Truncate records */ |
| 539 | }; |
| 540 | |
| 541 | /* |
| 542 | * On disk extent block (indirect block) for OCFS2 |
| 543 | */ |
| 544 | struct ocfs2_extent_block |
| 545 | { |
| 546 | /*00*/ __u8 h_signature[8]; /* Signature for verification */ |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 547 | struct ocfs2_block_check h_check; /* Error checking */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 548 | /*10*/ __le16 h_suballoc_slot; /* Slot suballocator this |
| 549 | extent_header belongs to */ |
| 550 | __le16 h_suballoc_bit; /* Bit offset in suballocator |
| 551 | block group */ |
| 552 | __le32 h_fs_generation; /* Must match super block */ |
| 553 | __le64 h_blkno; /* Offset on disk, in blocks */ |
Joel Becker | 9cbc012 | 2010-03-26 10:07:42 +0800 | [diff] [blame] | 554 | /*20*/ __le64 h_suballoc_loc; /* Suballocator block group this |
| 555 | eb belongs to. Only valid |
| 556 | if allocated from a |
| 557 | discontiguous block group */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 558 | __le64 h_next_leaf_blk; /* Offset on disk, in blocks, |
| 559 | of next leaf header pointing |
| 560 | to data */ |
| 561 | /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */ |
| 562 | /* Actual on-disk size is one block */ |
| 563 | }; |
| 564 | |
| 565 | /* |
Joel Becker | fb86b1f | 2008-02-01 11:59:05 -0800 | [diff] [blame] | 566 | * On disk slot map for OCFS2. This defines the contents of the "slot_map" |
Joel Becker | 386a2ef | 2008-02-01 12:06:54 -0800 | [diff] [blame] | 567 | * system file. A slot is valid if it contains a node number >= 0. The |
| 568 | * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty. |
Joel Becker | fb86b1f | 2008-02-01 11:59:05 -0800 | [diff] [blame] | 569 | */ |
| 570 | struct ocfs2_slot_map { |
| 571 | /*00*/ __le16 sm_slots[0]; |
| 572 | /* |
| 573 | * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255, |
| 574 | * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize. |
| 575 | */ |
| 576 | }; |
| 577 | |
Joel Becker | 386a2ef | 2008-02-01 12:06:54 -0800 | [diff] [blame] | 578 | struct ocfs2_extended_slot { |
| 579 | /*00*/ __u8 es_valid; |
| 580 | __u8 es_reserved1[3]; |
| 581 | __le32 es_node_num; |
Guozhonghua | 8ba4422 | 2016-05-19 17:09:44 -0700 | [diff] [blame] | 582 | /*08*/ |
Joel Becker | 386a2ef | 2008-02-01 12:06:54 -0800 | [diff] [blame] | 583 | }; |
| 584 | |
| 585 | /* |
| 586 | * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP |
| 587 | * is set. It separates out the valid marker from the node number, and |
| 588 | * has room to grow. Unlike the old slot map, this format is defined by |
| 589 | * i_size. |
| 590 | */ |
| 591 | struct ocfs2_slot_map_extended { |
| 592 | /*00*/ struct ocfs2_extended_slot se_slots[0]; |
| 593 | /* |
| 594 | * Actual size is i_size of the slot_map system file. It should |
| 595 | * match s_max_slots * sizeof(struct ocfs2_extended_slot) |
| 596 | */ |
| 597 | }; |
| 598 | |
Sunil Mushran | 98f486f2 | 2010-10-09 10:24:46 -0700 | [diff] [blame] | 599 | /* |
| 600 | * ci_stackflags is only valid if the incompat bit |
| 601 | * OCFS2_FEATURE_INCOMPAT_CLUSTERINFO is set. |
| 602 | */ |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 603 | struct ocfs2_cluster_info { |
| 604 | /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN]; |
Sunil Mushran | 98f486f2 | 2010-10-09 10:24:46 -0700 | [diff] [blame] | 605 | union { |
| 606 | __le32 ci_reserved; |
| 607 | struct { |
| 608 | __u8 ci_stackflags; |
| 609 | __u8 ci_reserved1; |
| 610 | __u8 ci_reserved2; |
| 611 | __u8 ci_reserved3; |
| 612 | }; |
| 613 | }; |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 614 | /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN]; |
| 615 | /*18*/ |
| 616 | }; |
| 617 | |
Joel Becker | fb86b1f | 2008-02-01 11:59:05 -0800 | [diff] [blame] | 618 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 619 | * On disk superblock for OCFS2 |
| 620 | * Note that it is contained inside an ocfs2_dinode, so all offsets |
| 621 | * are relative to the start of ocfs2_dinode.id2. |
| 622 | */ |
| 623 | struct ocfs2_super_block { |
| 624 | /*00*/ __le16 s_major_rev_level; |
| 625 | __le16 s_minor_rev_level; |
| 626 | __le16 s_mnt_count; |
| 627 | __le16 s_max_mnt_count; |
| 628 | __le16 s_state; /* File system state */ |
| 629 | __le16 s_errors; /* Behaviour when detecting errors */ |
| 630 | __le32 s_checkinterval; /* Max time between checks */ |
| 631 | /*10*/ __le64 s_lastcheck; /* Time of last check */ |
| 632 | __le32 s_creator_os; /* OS */ |
| 633 | __le32 s_feature_compat; /* Compatible feature set */ |
| 634 | /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */ |
| 635 | __le32 s_feature_ro_compat; /* Readonly-compatible feature set */ |
| 636 | __le64 s_root_blkno; /* Offset, in blocks, of root directory |
| 637 | dinode */ |
| 638 | /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system |
| 639 | directory dinode */ |
| 640 | __le32 s_blocksize_bits; /* Blocksize for this fs */ |
| 641 | __le32 s_clustersize_bits; /* Clustersize for this fs */ |
| 642 | /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts |
| 643 | before tunefs required */ |
Mark Fasheh | 92e91ce | 2007-09-20 11:19:20 -0700 | [diff] [blame] | 644 | __le16 s_tunefs_flag; |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 645 | __le32 s_uuid_hash; /* hash value of uuid */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 646 | __le64 s_first_cluster_group; /* Block offset of 1st cluster |
| 647 | * group header */ |
| 648 | /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */ |
| 649 | /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */ |
Sunil Mushran | 98f486f2 | 2010-10-09 10:24:46 -0700 | [diff] [blame] | 650 | /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Only valid if either |
| 651 | userspace or clusterinfo |
| 652 | INCOMPAT flag set. */ |
Tiger Yang | 8154da3 | 2008-08-18 17:11:46 +0800 | [diff] [blame] | 653 | /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size |
| 654 | for this fs*/ |
| 655 | __le16 s_reserved0; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 656 | __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash. |
| 657 | * s_uuid_hash serves as seed[3]. */ |
| 658 | /*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */ |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 659 | /*140*/ |
| 660 | |
| 661 | /* |
| 662 | * NOTE: As stated above, all offsets are relative to |
| 663 | * ocfs2_dinode.id2, which is at 0xC0 in the inode. |
| 664 | * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within |
| 665 | * our smallest blocksize, which is 512 bytes. To ensure this, |
| 666 | * we reserve the space in s_reserved2. Anything past s_reserved2 |
| 667 | * will not be available on the smallest blocksize. |
| 668 | */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 669 | }; |
| 670 | |
| 671 | /* |
| 672 | * Local allocation bitmap for OCFS2 slots |
| 673 | * Note that it exists inside an ocfs2_dinode, so all offsets are |
| 674 | * relative to the start of ocfs2_dinode.id2. |
| 675 | */ |
| 676 | struct ocfs2_local_alloc |
| 677 | { |
| 678 | /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */ |
| 679 | __le16 la_size; /* Size of included bitmap, in bytes */ |
| 680 | __le16 la_reserved1; |
| 681 | __le64 la_reserved2; |
| 682 | /*10*/ __u8 la_bitmap[0]; |
| 683 | }; |
| 684 | |
| 685 | /* |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 686 | * Data-in-inode header. This is only used if i_dyn_features has |
| 687 | * OCFS2_INLINE_DATA_FL set. |
| 688 | */ |
| 689 | struct ocfs2_inline_data |
| 690 | { |
| 691 | /*00*/ __le16 id_count; /* Number of bytes that can be used |
| 692 | * for data, starting at id_data */ |
| 693 | __le16 id_reserved0; |
| 694 | __le32 id_reserved1; |
| 695 | __u8 id_data[0]; /* Start of user data */ |
| 696 | }; |
| 697 | |
| 698 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 699 | * On disk inode for OCFS2 |
| 700 | */ |
| 701 | struct ocfs2_dinode { |
| 702 | /*00*/ __u8 i_signature[8]; /* Signature for validation */ |
| 703 | __le32 i_generation; /* Generation number */ |
| 704 | __le16 i_suballoc_slot; /* Slot suballocator this inode |
| 705 | belongs to */ |
| 706 | __le16 i_suballoc_bit; /* Bit offset in suballocator |
| 707 | block group */ |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 708 | /*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */ |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 709 | __le16 i_xattr_inline_size; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 710 | __le32 i_clusters; /* Cluster count */ |
| 711 | __le32 i_uid; /* Owner UID */ |
| 712 | __le32 i_gid; /* Owning GID */ |
| 713 | /*20*/ __le64 i_size; /* Size in bytes */ |
| 714 | __le16 i_mode; /* File mode */ |
| 715 | __le16 i_links_count; /* Links count */ |
| 716 | __le32 i_flags; /* File flags */ |
| 717 | /*30*/ __le64 i_atime; /* Access time */ |
| 718 | __le64 i_ctime; /* Creation time */ |
| 719 | /*40*/ __le64 i_mtime; /* Modification time */ |
| 720 | __le64 i_dtime; /* Deletion time */ |
| 721 | /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */ |
| 722 | __le64 i_last_eb_blk; /* Pointer to last extent |
| 723 | block */ |
| 724 | /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */ |
| 725 | __le32 i_atime_nsec; |
| 726 | __le32 i_ctime_nsec; |
| 727 | __le32 i_mtime_nsec; |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 728 | /*70*/ __le32 i_attr; |
Tiger Yang | 5000863 | 2007-03-20 16:01:38 -0700 | [diff] [blame] | 729 | __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL |
| 730 | was set in i_flags */ |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 731 | __le16 i_dyn_features; |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 732 | __le64 i_xattr_loc; |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 733 | /*80*/ struct ocfs2_block_check i_check; /* Error checking */ |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 734 | /*88*/ __le64 i_dx_root; /* Pointer to dir index root block */ |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 735 | /*90*/ __le64 i_refcount_loc; |
Joel Becker | 9cbc012 | 2010-03-26 10:07:42 +0800 | [diff] [blame] | 736 | __le64 i_suballoc_loc; /* Suballocator block group this |
| 737 | inode belongs to. Only valid |
| 738 | if allocated from a |
| 739 | discontiguous block group */ |
Joseph Qi | 06ee5c7 | 2015-02-16 15:59:54 -0800 | [diff] [blame] | 740 | /*A0*/ __le16 i_dio_orphaned_slot; /* only used for append dio write */ |
| 741 | __le16 i_reserved1[3]; |
| 742 | __le64 i_reserved2[2]; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 743 | /*B8*/ union { |
| 744 | __le64 i_pad1; /* Generic way to refer to this |
| 745 | 64bit union */ |
| 746 | struct { |
| 747 | __le64 i_rdev; /* Device number */ |
| 748 | } dev1; |
| 749 | struct { /* Info for bitmap system |
| 750 | inodes */ |
| 751 | __le32 i_used; /* Bits (ie, clusters) used */ |
| 752 | __le32 i_total; /* Total bits (clusters) |
| 753 | available */ |
| 754 | } bitmap1; |
| 755 | struct { /* Info for journal system |
| 756 | inodes */ |
| 757 | __le32 ij_flags; /* Mounted, version, etc. */ |
Sunil Mushran | c69991a | 2008-07-14 17:31:09 -0700 | [diff] [blame] | 758 | __le32 ij_recovery_generation; /* Incremented when the |
| 759 | journal is recovered |
| 760 | after an unclean |
| 761 | shutdown */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 762 | } journal1; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 763 | } id1; /* Inode type dependent 1 */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 764 | /*C0*/ union { |
| 765 | struct ocfs2_super_block i_super; |
| 766 | struct ocfs2_local_alloc i_lab; |
| 767 | struct ocfs2_chain_list i_chain; |
| 768 | struct ocfs2_extent_list i_list; |
| 769 | struct ocfs2_truncate_log i_dealloc; |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 770 | struct ocfs2_inline_data i_data; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 771 | __u8 i_symlink[0]; |
| 772 | } id2; |
| 773 | /* Actual on-disk size is one block */ |
| 774 | }; |
| 775 | |
| 776 | /* |
| 777 | * On-disk directory entry structure for OCFS2 |
| 778 | * |
| 779 | * Packed as this structure could be accessed unaligned on 64-bit platforms |
| 780 | */ |
| 781 | struct ocfs2_dir_entry { |
| 782 | /*00*/ __le64 inode; /* Inode number */ |
| 783 | __le16 rec_len; /* Directory entry length */ |
| 784 | __u8 name_len; /* Name length */ |
| 785 | __u8 file_type; |
| 786 | /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */ |
| 787 | /* Actual on-disk length specified by rec_len */ |
| 788 | } __attribute__ ((packed)); |
| 789 | |
| 790 | /* |
Mark Fasheh | 87d35a7 | 2008-12-10 17:36:25 -0800 | [diff] [blame] | 791 | * Per-block record for the unindexed directory btree. This is carefully |
| 792 | * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are |
| 793 | * mirrored. That way, the directory manipulation code needs a minimal amount |
| 794 | * of update. |
| 795 | * |
| 796 | * NOTE: Keep this structure aligned to a multiple of 4 bytes. |
| 797 | */ |
| 798 | struct ocfs2_dir_block_trailer { |
| 799 | /*00*/ __le64 db_compat_inode; /* Always zero. Was inode */ |
| 800 | |
| 801 | __le16 db_compat_rec_len; /* Backwards compatible with |
| 802 | * ocfs2_dir_entry. */ |
| 803 | __u8 db_compat_name_len; /* Always zero. Was name_len */ |
| 804 | __u8 db_reserved0; |
| 805 | __le16 db_reserved1; |
| 806 | __le16 db_free_rec_len; /* Size of largest empty hole |
| 807 | * in this block. (unused) */ |
| 808 | /*10*/ __u8 db_signature[8]; /* Signature for verification */ |
| 809 | __le64 db_reserved2; |
| 810 | __le64 db_free_next; /* Next block in list (unused) */ |
| 811 | /*20*/ __le64 db_blkno; /* Offset on disk, in blocks */ |
| 812 | __le64 db_parent_dinode; /* dinode which owns me, in |
| 813 | blocks */ |
Joel Becker | c175a51 | 2008-12-10 17:58:22 -0800 | [diff] [blame] | 814 | /*30*/ struct ocfs2_block_check db_check; /* Error checking */ |
Mark Fasheh | 87d35a7 | 2008-12-10 17:36:25 -0800 | [diff] [blame] | 815 | /*40*/ |
| 816 | }; |
| 817 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 818 | /* |
| 819 | * A directory entry in the indexed tree. We don't store the full name here, |
| 820 | * but instead provide a pointer to the full dirent in the unindexed tree. |
| 821 | * |
| 822 | * We also store name_len here so as to reduce the number of leaf blocks we |
| 823 | * need to search in case of collisions. |
| 824 | */ |
| 825 | struct ocfs2_dx_entry { |
| 826 | __le32 dx_major_hash; /* Used to find logical |
| 827 | * cluster in index */ |
| 828 | __le32 dx_minor_hash; /* Lower bits used to find |
| 829 | * block in cluster */ |
| 830 | __le64 dx_dirent_blk; /* Physical block in unindexed |
| 831 | * tree holding this dirent. */ |
| 832 | }; |
| 833 | |
| 834 | struct ocfs2_dx_entry_list { |
| 835 | __le32 de_reserved; |
| 836 | __le16 de_count; /* Maximum number of entries |
| 837 | * possible in de_entries */ |
| 838 | __le16 de_num_used; /* Current number of |
| 839 | * de_entries entries */ |
| 840 | struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries |
| 841 | * in a packed array of |
| 842 | * length de_num_used */ |
| 843 | }; |
| 844 | |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 845 | #define OCFS2_DX_FLAG_INLINE 0x01 |
| 846 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 847 | /* |
| 848 | * A directory indexing block. Each indexed directory has one of these, |
| 849 | * pointed to by ocfs2_dinode. |
| 850 | * |
| 851 | * This block stores an indexed btree root, and a set of free space |
| 852 | * start-of-list pointers. |
| 853 | */ |
| 854 | struct ocfs2_dx_root_block { |
| 855 | __u8 dr_signature[8]; /* Signature for verification */ |
| 856 | struct ocfs2_block_check dr_check; /* Error checking */ |
| 857 | __le16 dr_suballoc_slot; /* Slot suballocator this |
| 858 | * block belongs to. */ |
| 859 | __le16 dr_suballoc_bit; /* Bit offset in suballocator |
| 860 | * block group */ |
| 861 | __le32 dr_fs_generation; /* Must match super block */ |
| 862 | __le64 dr_blkno; /* Offset on disk, in blocks */ |
| 863 | __le64 dr_last_eb_blk; /* Pointer to last |
| 864 | * extent block */ |
| 865 | __le32 dr_clusters; /* Clusters allocated |
| 866 | * to the indexed tree. */ |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 867 | __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */ |
| 868 | __u8 dr_reserved0; |
| 869 | __le16 dr_reserved1; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 870 | __le64 dr_dir_blkno; /* Pointer to parent inode */ |
Mark Fasheh | e3a93c2 | 2009-02-17 15:29:35 -0800 | [diff] [blame] | 871 | __le32 dr_num_entries; /* Total number of |
| 872 | * names stored in |
| 873 | * this directory.*/ |
| 874 | __le32 dr_reserved2; |
Mark Fasheh | e7c17e4 | 2009-01-29 18:17:46 -0800 | [diff] [blame] | 875 | __le64 dr_free_blk; /* Pointer to head of free |
| 876 | * unindexed block list. */ |
Joel Becker | 9cbc012 | 2010-03-26 10:07:42 +0800 | [diff] [blame] | 877 | __le64 dr_suballoc_loc; /* Suballocator block group |
| 878 | this root belongs to. |
| 879 | Only valid if allocated |
| 880 | from a discontiguous |
| 881 | block group */ |
| 882 | __le64 dr_reserved3[14]; |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 883 | union { |
| 884 | struct ocfs2_extent_list dr_list; /* Keep this aligned to 128 |
| 885 | * bits for maximum space |
| 886 | * efficiency. */ |
| 887 | struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of |
| 888 | * entries. We grow out |
| 889 | * to extents if this |
| 890 | * gets too big. */ |
| 891 | }; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 892 | }; |
| 893 | |
| 894 | /* |
| 895 | * The header of a leaf block in the indexed tree. |
| 896 | */ |
| 897 | struct ocfs2_dx_leaf { |
| 898 | __u8 dl_signature[8];/* Signature for verification */ |
| 899 | struct ocfs2_block_check dl_check; /* Error checking */ |
| 900 | __le64 dl_blkno; /* Offset on disk, in blocks */ |
| 901 | __le32 dl_fs_generation;/* Must match super block */ |
| 902 | __le32 dl_reserved0; |
| 903 | __le64 dl_reserved1; |
| 904 | struct ocfs2_dx_entry_list dl_list; |
| 905 | }; |
| 906 | |
Mark Fasheh | 87d35a7 | 2008-12-10 17:36:25 -0800 | [diff] [blame] | 907 | /* |
Joel Becker | 4cbe424 | 2010-04-13 14:26:12 +0800 | [diff] [blame] | 908 | * Largest bitmap for a block (suballocator) group in bytes. This limit |
| 909 | * does not affect cluster groups (global allocator). Cluster group |
| 910 | * bitmaps run to the end of the block. |
| 911 | */ |
| 912 | #define OCFS2_MAX_BG_BITMAP_SIZE 256 |
| 913 | |
| 914 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 915 | * On disk allocator group structure for OCFS2 |
| 916 | */ |
| 917 | struct ocfs2_group_desc |
| 918 | { |
| 919 | /*00*/ __u8 bg_signature[8]; /* Signature for validation */ |
| 920 | __le16 bg_size; /* Size of included bitmap in |
| 921 | bytes. */ |
| 922 | __le16 bg_bits; /* Bits represented by this |
| 923 | group. */ |
| 924 | __le16 bg_free_bits_count; /* Free bits count */ |
| 925 | __le16 bg_chain; /* What chain I am in. */ |
| 926 | /*10*/ __le32 bg_generation; |
| 927 | __le32 bg_reserved1; |
| 928 | __le64 bg_next_group; /* Next group in my list, in |
| 929 | blocks */ |
| 930 | /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in |
| 931 | blocks */ |
| 932 | __le64 bg_blkno; /* Offset on disk, in blocks */ |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 933 | /*30*/ struct ocfs2_block_check bg_check; /* Error checking */ |
| 934 | __le64 bg_reserved2; |
Joel Becker | 4cbe424 | 2010-04-13 14:26:12 +0800 | [diff] [blame] | 935 | /*40*/ union { |
| 936 | __u8 bg_bitmap[0]; |
| 937 | struct { |
| 938 | /* |
| 939 | * Block groups may be discontiguous when |
| 940 | * OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG is set. |
Masahiro Yamada | e1c0506 | 2015-07-07 10:14:59 +0900 | [diff] [blame] | 941 | * The extents of a discontiguous block group are |
Joel Becker | 4cbe424 | 2010-04-13 14:26:12 +0800 | [diff] [blame] | 942 | * stored in bg_list. It is a flat list. |
| 943 | * l_tree_depth must always be zero. A |
| 944 | * discontiguous group is signified by a non-zero |
| 945 | * bg_list->l_next_free_rec. Only block groups |
| 946 | * can be discontiguous; Cluster groups cannot. |
| 947 | * We've never made a block group with more than |
| 948 | * 2048 blocks (256 bytes of bg_bitmap). This |
| 949 | * codifies that limit so that we can fit bg_list. |
| 950 | * bg_size of a discontiguous block group will |
| 951 | * be 256 to match bg_bitmap_filler. |
| 952 | */ |
| 953 | __u8 bg_bitmap_filler[OCFS2_MAX_BG_BITMAP_SIZE]; |
| 954 | /*140*/ struct ocfs2_extent_list bg_list; |
| 955 | }; |
| 956 | }; |
| 957 | /* Actual on-disk size is one block */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 958 | }; |
| 959 | |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 960 | struct ocfs2_refcount_rec { |
| 961 | /*00*/ __le64 r_cpos; /* Physical offset, in clusters */ |
| 962 | __le32 r_clusters; /* Clusters covered by this extent */ |
| 963 | __le32 r_refcount; /* Reference count of this extent */ |
| 964 | /*10*/ |
| 965 | }; |
Tao Ma | e73a819 | 2009-08-11 14:33:14 +0800 | [diff] [blame] | 966 | #define OCFS2_32BIT_POS_MASK (0xffffffffULL) |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 967 | |
| 968 | #define OCFS2_REFCOUNT_LEAF_FL (0x00000001) |
| 969 | #define OCFS2_REFCOUNT_TREE_FL (0x00000002) |
| 970 | |
| 971 | struct ocfs2_refcount_list { |
| 972 | /*00*/ __le16 rl_count; /* Maximum number of entries possible |
| 973 | in rl_records */ |
| 974 | __le16 rl_used; /* Current number of used records */ |
| 975 | __le32 rl_reserved2; |
| 976 | __le64 rl_reserved1; /* Pad to sizeof(ocfs2_refcount_record) */ |
| 977 | /*10*/ struct ocfs2_refcount_rec rl_recs[0]; /* Refcount records */ |
| 978 | }; |
| 979 | |
| 980 | |
| 981 | struct ocfs2_refcount_block { |
| 982 | /*00*/ __u8 rf_signature[8]; /* Signature for verification */ |
| 983 | __le16 rf_suballoc_slot; /* Slot suballocator this block |
| 984 | belongs to */ |
| 985 | __le16 rf_suballoc_bit; /* Bit offset in suballocator |
| 986 | block group */ |
| 987 | __le32 rf_fs_generation; /* Must match superblock */ |
| 988 | /*10*/ __le64 rf_blkno; /* Offset on disk, in blocks */ |
| 989 | __le64 rf_parent; /* Parent block, only valid if |
| 990 | OCFS2_REFCOUNT_LEAF_FL is set in |
| 991 | rf_flags */ |
| 992 | /*20*/ struct ocfs2_block_check rf_check; /* Error checking */ |
| 993 | __le64 rf_last_eb_blk; /* Pointer to last extent block */ |
| 994 | /*30*/ __le32 rf_count; /* Number of inodes sharing this |
| 995 | refcount tree */ |
| 996 | __le32 rf_flags; /* See the flags above */ |
| 997 | __le32 rf_clusters; /* clusters covered by refcount tree. */ |
| 998 | __le32 rf_cpos; /* cluster offset in refcount tree.*/ |
| 999 | /*40*/ __le32 rf_generation; /* generation number. all be the same |
| 1000 | * for the same refcount tree. */ |
| 1001 | __le32 rf_reserved0; |
Joel Becker | 9cbc012 | 2010-03-26 10:07:42 +0800 | [diff] [blame] | 1002 | __le64 rf_suballoc_loc; /* Suballocator block group this |
| 1003 | refcount block belongs to. Only |
| 1004 | valid if allocated from a |
| 1005 | discontiguous block group */ |
| 1006 | /*50*/ __le64 rf_reserved1[6]; |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 1007 | /*80*/ union { |
| 1008 | struct ocfs2_refcount_list rf_records; /* List of refcount |
| 1009 | records */ |
| 1010 | struct ocfs2_extent_list rf_list; /* Extent record list, |
| 1011 | only valid if |
| 1012 | OCFS2_REFCOUNT_TREE_FL |
| 1013 | is set in rf_flags */ |
| 1014 | }; |
| 1015 | /* Actual on-disk size is one block */ |
| 1016 | }; |
| 1017 | |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1018 | /* |
| 1019 | * On disk extended attribute structure for OCFS2. |
| 1020 | */ |
| 1021 | |
| 1022 | /* |
| 1023 | * ocfs2_xattr_entry indicates one extend attribute. |
| 1024 | * |
| 1025 | * Note that it can be stored in inode, one block or one xattr bucket. |
| 1026 | */ |
| 1027 | struct ocfs2_xattr_entry { |
| 1028 | __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */ |
Tao Ma | 8573f79 | 2008-10-24 22:24:17 +0800 | [diff] [blame] | 1029 | __le16 xe_name_offset; /* byte offset from the 1st entry in the |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1030 | local xattr storage(inode, xattr block or |
| 1031 | xattr bucket). */ |
Lucas De Marchi | e9c5499 | 2011-04-26 23:28:26 -0700 | [diff] [blame] | 1032 | __u8 xe_name_len; /* xattr name len, doesn't include prefix. */ |
Tao Ma | 8573f79 | 2008-10-24 22:24:17 +0800 | [diff] [blame] | 1033 | __u8 xe_type; /* the low 7 bits indicate the name prefix |
| 1034 | * type and the highest bit indicates whether |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1035 | * the EA is stored in the local storage. */ |
| 1036 | __le64 xe_value_size; /* real xattr value length. */ |
| 1037 | }; |
| 1038 | |
| 1039 | /* |
| 1040 | * On disk structure for xattr header. |
| 1041 | * |
| 1042 | * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in |
| 1043 | * the local xattr storage. |
| 1044 | */ |
| 1045 | struct ocfs2_xattr_header { |
| 1046 | __le16 xh_count; /* contains the count of how |
| 1047 | many records are in the |
| 1048 | local xattr storage. */ |
Tao Ma | 0c044f0 | 2008-08-18 17:38:50 +0800 | [diff] [blame] | 1049 | __le16 xh_free_start; /* current offset for storing |
| 1050 | xattr. */ |
| 1051 | __le16 xh_name_value_len; /* total length of name/value |
| 1052 | length in this bucket. */ |
Tao Ma | 8573f79 | 2008-10-24 22:24:17 +0800 | [diff] [blame] | 1053 | __le16 xh_num_buckets; /* Number of xattr buckets |
| 1054 | in this extent record, |
| 1055 | only valid in the first |
| 1056 | bucket. */ |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 1057 | struct ocfs2_block_check xh_check; /* Error checking |
| 1058 | (Note, this is only |
| 1059 | used for xattr |
| 1060 | buckets. A block uses |
| 1061 | xb_check and sets |
| 1062 | this field to zero.) */ |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1063 | struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */ |
| 1064 | }; |
| 1065 | |
| 1066 | /* |
| 1067 | * On disk structure for xattr value root. |
| 1068 | * |
Tao Ma | 8573f79 | 2008-10-24 22:24:17 +0800 | [diff] [blame] | 1069 | * When an xattr's value is large enough, it is stored in an external |
| 1070 | * b-tree like file data. The xattr value root points to this structure. |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1071 | */ |
| 1072 | struct ocfs2_xattr_value_root { |
| 1073 | /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */ |
| 1074 | __le32 xr_reserved0; |
| 1075 | __le64 xr_last_eb_blk; /* Pointer to last extent block */ |
| 1076 | /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */ |
| 1077 | }; |
| 1078 | |
| 1079 | /* |
| 1080 | * On disk structure for xattr tree root. |
| 1081 | * |
| 1082 | * It is used when there are too many extended attributes for one file. These |
| 1083 | * attributes will be organized and stored in an indexed-btree. |
| 1084 | */ |
| 1085 | struct ocfs2_xattr_tree_root { |
| 1086 | /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */ |
| 1087 | __le32 xt_reserved0; |
| 1088 | __le64 xt_last_eb_blk; /* Pointer to last extent block */ |
| 1089 | /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */ |
| 1090 | }; |
| 1091 | |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 1092 | #define OCFS2_XATTR_INDEXED 0x1 |
| 1093 | #define OCFS2_HASH_SHIFT 5 |
| 1094 | #define OCFS2_XATTR_ROUND 3 |
| 1095 | #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \ |
| 1096 | ~(OCFS2_XATTR_ROUND)) |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1097 | |
Tao Ma | 0c044f0 | 2008-08-18 17:38:50 +0800 | [diff] [blame] | 1098 | #define OCFS2_XATTR_BUCKET_SIZE 4096 |
| 1099 | #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \ |
| 1100 | / OCFS2_MIN_BLOCKSIZE) |
| 1101 | |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1102 | /* |
| 1103 | * On disk structure for xattr block. |
| 1104 | */ |
| 1105 | struct ocfs2_xattr_block { |
| 1106 | /*00*/ __u8 xb_signature[8]; /* Signature for verification */ |
| 1107 | __le16 xb_suballoc_slot; /* Slot suballocator this |
| 1108 | block belongs to. */ |
| 1109 | __le16 xb_suballoc_bit; /* Bit offset in suballocator |
| 1110 | block group */ |
| 1111 | __le32 xb_fs_generation; /* Must match super block */ |
| 1112 | /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */ |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 1113 | struct ocfs2_block_check xb_check; /* Error checking */ |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1114 | /*20*/ __le16 xb_flags; /* Indicates whether this block contains |
| 1115 | real xattr or a xattr tree. */ |
| 1116 | __le16 xb_reserved0; |
| 1117 | __le32 xb_reserved1; |
Joel Becker | 9cbc012 | 2010-03-26 10:07:42 +0800 | [diff] [blame] | 1118 | __le64 xb_suballoc_loc; /* Suballocator block group this |
| 1119 | xattr block belongs to. Only |
| 1120 | valid if allocated from a |
| 1121 | discontiguous block group */ |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1122 | /*30*/ union { |
| 1123 | struct ocfs2_xattr_header xb_header; /* xattr header if this |
| 1124 | block contains xattr */ |
| 1125 | struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this |
| 1126 | block cotains xattr |
| 1127 | tree. */ |
| 1128 | } xb_attrs; |
| 1129 | }; |
| 1130 | |
| 1131 | #define OCFS2_XATTR_ENTRY_LOCAL 0x80 |
| 1132 | #define OCFS2_XATTR_TYPE_MASK 0x7F |
| 1133 | static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe, |
| 1134 | int local) |
| 1135 | { |
| 1136 | if (local) |
| 1137 | xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL; |
| 1138 | else |
| 1139 | xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL; |
| 1140 | } |
| 1141 | |
| 1142 | static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe) |
| 1143 | { |
| 1144 | return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL; |
| 1145 | } |
| 1146 | |
| 1147 | static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type) |
| 1148 | { |
| 1149 | xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK; |
| 1150 | } |
| 1151 | |
| 1152 | static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe) |
| 1153 | { |
| 1154 | return xe->xe_type & OCFS2_XATTR_TYPE_MASK; |
| 1155 | } |
| 1156 | |
Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 1157 | /* |
| 1158 | * On disk structures for global quota file |
| 1159 | */ |
| 1160 | |
| 1161 | /* Magic numbers and known versions for global quota files */ |
| 1162 | #define OCFS2_GLOBAL_QMAGICS {\ |
| 1163 | 0x0cf52470, /* USRQUOTA */ \ |
| 1164 | 0x0cf52471 /* GRPQUOTA */ \ |
| 1165 | } |
| 1166 | |
| 1167 | #define OCFS2_GLOBAL_QVERSIONS {\ |
| 1168 | 0, \ |
| 1169 | 0, \ |
| 1170 | } |
| 1171 | |
| 1172 | |
| 1173 | /* Each block of each quota file has a certain fixed number of bytes reserved |
| 1174 | * for OCFS2 internal use at its end. OCFS2 can use it for things like |
| 1175 | * checksums, etc. */ |
| 1176 | #define OCFS2_QBLK_RESERVED_SPACE 8 |
| 1177 | |
| 1178 | /* Generic header of all quota files */ |
| 1179 | struct ocfs2_disk_dqheader { |
| 1180 | __le32 dqh_magic; /* Magic number identifying file */ |
| 1181 | __le32 dqh_version; /* Quota format version */ |
| 1182 | }; |
| 1183 | |
| 1184 | #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader)) |
| 1185 | |
| 1186 | /* Information header of global quota file (immediately follows the generic |
| 1187 | * header) */ |
| 1188 | struct ocfs2_global_disk_dqinfo { |
| 1189 | /*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */ |
| 1190 | __le32 dqi_igrace; /* Grace time for inode softlimit excess */ |
| 1191 | __le32 dqi_syncms; /* Time after which we sync local changes to |
| 1192 | * global quota file */ |
| 1193 | __le32 dqi_blocks; /* Number of blocks in quota file */ |
| 1194 | /*10*/ __le32 dqi_free_blk; /* First free block in quota file */ |
| 1195 | __le32 dqi_free_entry; /* First block with free dquot entry in quota |
| 1196 | * file */ |
| 1197 | }; |
| 1198 | |
| 1199 | /* Structure with global user / group information. We reserve some space |
| 1200 | * for future use. */ |
| 1201 | struct ocfs2_global_disk_dqblk { |
| 1202 | /*00*/ __le32 dqb_id; /* ID the structure belongs to */ |
| 1203 | __le32 dqb_use_count; /* Number of nodes having reference to this structure */ |
| 1204 | __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */ |
| 1205 | /*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */ |
| 1206 | __le64 dqb_curinodes; /* current # allocated inodes */ |
| 1207 | /*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */ |
| 1208 | __le64 dqb_bsoftlimit; /* preferred limit on disk space */ |
| 1209 | /*30*/ __le64 dqb_curspace; /* current space occupied */ |
| 1210 | __le64 dqb_btime; /* time limit for excessive disk use */ |
| 1211 | /*40*/ __le64 dqb_itime; /* time limit for excessive inode use */ |
| 1212 | __le64 dqb_pad1; |
| 1213 | /*50*/ __le64 dqb_pad2; |
| 1214 | }; |
| 1215 | |
| 1216 | /* |
| 1217 | * On-disk structures for local quota file |
| 1218 | */ |
| 1219 | |
| 1220 | /* Magic numbers and known versions for local quota files */ |
| 1221 | #define OCFS2_LOCAL_QMAGICS {\ |
| 1222 | 0x0cf524c0, /* USRQUOTA */ \ |
| 1223 | 0x0cf524c1 /* GRPQUOTA */ \ |
| 1224 | } |
| 1225 | |
| 1226 | #define OCFS2_LOCAL_QVERSIONS {\ |
| 1227 | 0, \ |
| 1228 | 0, \ |
| 1229 | } |
| 1230 | |
| 1231 | /* Quota flags in dqinfo header */ |
| 1232 | #define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\ |
| 1233 | * quota has been cleanly turned off) */ |
| 1234 | |
| 1235 | #define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader)) |
| 1236 | |
| 1237 | /* Information header of local quota file (immediately follows the generic |
| 1238 | * header) */ |
| 1239 | struct ocfs2_local_disk_dqinfo { |
| 1240 | __le32 dqi_flags; /* Flags for quota file */ |
| 1241 | __le32 dqi_chunks; /* Number of chunks of quota structures |
| 1242 | * with a bitmap */ |
| 1243 | __le32 dqi_blocks; /* Number of blocks allocated for quota file */ |
| 1244 | }; |
| 1245 | |
| 1246 | /* Header of one chunk of a quota file */ |
| 1247 | struct ocfs2_local_disk_chunk { |
| 1248 | __le32 dqc_free; /* Number of free entries in the bitmap */ |
Coly Li | 9365454 | 2009-12-06 22:38:53 +0800 | [diff] [blame] | 1249 | __u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding |
Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 1250 | * chunk of quota file */ |
| 1251 | }; |
| 1252 | |
| 1253 | /* One entry in local quota file */ |
| 1254 | struct ocfs2_local_disk_dqblk { |
| 1255 | /*00*/ __le64 dqb_id; /* id this quota applies to */ |
| 1256 | __le64 dqb_spacemod; /* Change in the amount of used space */ |
| 1257 | /*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */ |
| 1258 | }; |
| 1259 | |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 1260 | |
| 1261 | /* |
| 1262 | * The quota trailer lives at the end of each quota block. |
| 1263 | */ |
| 1264 | |
| 1265 | struct ocfs2_disk_dqtrailer { |
| 1266 | /*00*/ struct ocfs2_block_check dq_check; /* Error checking */ |
| 1267 | /*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */ |
| 1268 | }; |
| 1269 | |
| 1270 | static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize, |
| 1271 | void *buf) |
| 1272 | { |
| 1273 | char *ptr = buf; |
| 1274 | ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE; |
| 1275 | |
| 1276 | return (struct ocfs2_disk_dqtrailer *)ptr; |
| 1277 | } |
| 1278 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1279 | #ifdef __KERNEL__ |
| 1280 | static inline int ocfs2_fast_symlink_chars(struct super_block *sb) |
| 1281 | { |
| 1282 | return sb->s_blocksize - |
| 1283 | offsetof(struct ocfs2_dinode, id2.i_symlink); |
| 1284 | } |
| 1285 | |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 1286 | static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb, |
| 1287 | struct ocfs2_dinode *di) |
| 1288 | { |
| 1289 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); |
| 1290 | |
| 1291 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) |
| 1292 | return sb->s_blocksize - |
| 1293 | offsetof(struct ocfs2_dinode, id2.i_data.id_data) - |
| 1294 | xattrsize; |
| 1295 | else |
| 1296 | return sb->s_blocksize - |
| 1297 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); |
| 1298 | } |
| 1299 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1300 | static inline int ocfs2_extent_recs_per_inode(struct super_block *sb) |
| 1301 | { |
| 1302 | int size; |
| 1303 | |
| 1304 | size = sb->s_blocksize - |
| 1305 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); |
| 1306 | |
| 1307 | return size / sizeof(struct ocfs2_extent_rec); |
| 1308 | } |
| 1309 | |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 1310 | static inline int ocfs2_extent_recs_per_inode_with_xattr( |
| 1311 | struct super_block *sb, |
| 1312 | struct ocfs2_dinode *di) |
| 1313 | { |
| 1314 | int size; |
| 1315 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); |
| 1316 | |
| 1317 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) |
| 1318 | size = sb->s_blocksize - |
| 1319 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs) - |
| 1320 | xattrsize; |
| 1321 | else |
| 1322 | size = sb->s_blocksize - |
| 1323 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); |
| 1324 | |
| 1325 | return size / sizeof(struct ocfs2_extent_rec); |
| 1326 | } |
| 1327 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 1328 | static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb) |
| 1329 | { |
| 1330 | int size; |
| 1331 | |
| 1332 | size = sb->s_blocksize - |
| 1333 | offsetof(struct ocfs2_dx_root_block, dr_list.l_recs); |
| 1334 | |
| 1335 | return size / sizeof(struct ocfs2_extent_rec); |
| 1336 | } |
| 1337 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1338 | static inline int ocfs2_chain_recs_per_inode(struct super_block *sb) |
| 1339 | { |
| 1340 | int size; |
| 1341 | |
| 1342 | size = sb->s_blocksize - |
| 1343 | offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); |
| 1344 | |
| 1345 | return size / sizeof(struct ocfs2_chain_rec); |
| 1346 | } |
| 1347 | |
| 1348 | static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb) |
| 1349 | { |
| 1350 | int size; |
| 1351 | |
| 1352 | size = sb->s_blocksize - |
| 1353 | offsetof(struct ocfs2_extent_block, h_list.l_recs); |
| 1354 | |
| 1355 | return size / sizeof(struct ocfs2_extent_rec); |
| 1356 | } |
| 1357 | |
Joel Becker | 798db35 | 2010-04-13 14:26:32 +0800 | [diff] [blame] | 1358 | static inline u16 ocfs2_extent_recs_per_gd(struct super_block *sb) |
| 1359 | { |
| 1360 | int size; |
| 1361 | |
| 1362 | size = sb->s_blocksize - |
| 1363 | offsetof(struct ocfs2_group_desc, bg_list.l_recs); |
| 1364 | |
| 1365 | return size / sizeof(struct ocfs2_extent_rec); |
| 1366 | } |
| 1367 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 1368 | static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb) |
| 1369 | { |
| 1370 | int size; |
| 1371 | |
| 1372 | size = sb->s_blocksize - |
| 1373 | offsetof(struct ocfs2_dx_leaf, dl_list.de_entries); |
| 1374 | |
| 1375 | return size / sizeof(struct ocfs2_dx_entry); |
| 1376 | } |
| 1377 | |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 1378 | static inline int ocfs2_dx_entries_per_root(struct super_block *sb) |
| 1379 | { |
| 1380 | int size; |
| 1381 | |
| 1382 | size = sb->s_blocksize - |
| 1383 | offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries); |
| 1384 | |
| 1385 | return size / sizeof(struct ocfs2_dx_entry); |
| 1386 | } |
| 1387 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1388 | static inline u16 ocfs2_local_alloc_size(struct super_block *sb) |
| 1389 | { |
| 1390 | u16 size; |
| 1391 | |
| 1392 | size = sb->s_blocksize - |
| 1393 | offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); |
| 1394 | |
| 1395 | return size; |
| 1396 | } |
| 1397 | |
Joel Becker | 4cbe424 | 2010-04-13 14:26:12 +0800 | [diff] [blame] | 1398 | static inline int ocfs2_group_bitmap_size(struct super_block *sb, |
Tao Ma | 8571882 | 2010-04-13 14:38:06 +0800 | [diff] [blame] | 1399 | int suballocator, |
| 1400 | u32 feature_incompat) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1401 | { |
Tao Ma | 8571882 | 2010-04-13 14:38:06 +0800 | [diff] [blame] | 1402 | int size = sb->s_blocksize - |
| 1403 | offsetof(struct ocfs2_group_desc, bg_bitmap); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1404 | |
Tao Ma | 8571882 | 2010-04-13 14:38:06 +0800 | [diff] [blame] | 1405 | /* |
| 1406 | * The cluster allocator uses the entire block. Suballocators have |
| 1407 | * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older |
| 1408 | * code expects bg_size set to the maximum. Thus we must keep |
| 1409 | * bg_size as-is unless discontig_bg is enabled. |
| 1410 | */ |
| 1411 | if (suballocator && |
| 1412 | (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG)) |
Joel Becker | 4cbe424 | 2010-04-13 14:26:12 +0800 | [diff] [blame] | 1413 | size = OCFS2_MAX_BG_BITMAP_SIZE; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1414 | |
| 1415 | return size; |
| 1416 | } |
| 1417 | |
| 1418 | static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb) |
| 1419 | { |
| 1420 | int size; |
| 1421 | |
| 1422 | size = sb->s_blocksize - |
| 1423 | offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); |
| 1424 | |
| 1425 | return size / sizeof(struct ocfs2_truncate_rec); |
| 1426 | } |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 1427 | |
| 1428 | static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index) |
| 1429 | { |
| 1430 | u64 offset = OCFS2_BACKUP_SB_START; |
| 1431 | |
| 1432 | if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { |
| 1433 | offset <<= (2 * index); |
Mark Fasheh | a8a75a2 | 2007-01-26 10:46:59 -0800 | [diff] [blame] | 1434 | offset >>= sb->s_blocksize_bits; |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 1435 | return offset; |
| 1436 | } |
| 1437 | |
| 1438 | return 0; |
| 1439 | |
| 1440 | } |
Tao Ma | 0c044f0 | 2008-08-18 17:38:50 +0800 | [diff] [blame] | 1441 | |
| 1442 | static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb) |
| 1443 | { |
| 1444 | int size; |
| 1445 | |
| 1446 | size = sb->s_blocksize - |
| 1447 | offsetof(struct ocfs2_xattr_block, |
| 1448 | xb_attrs.xb_root.xt_list.l_recs); |
| 1449 | |
| 1450 | return size / sizeof(struct ocfs2_extent_rec); |
| 1451 | } |
Tao Ma | 721f69c | 2009-08-18 11:17:49 +0800 | [diff] [blame] | 1452 | |
| 1453 | static inline u16 ocfs2_extent_recs_per_rb(struct super_block *sb) |
| 1454 | { |
| 1455 | int size; |
| 1456 | |
| 1457 | size = sb->s_blocksize - |
| 1458 | offsetof(struct ocfs2_refcount_block, rf_list.l_recs); |
| 1459 | |
| 1460 | return size / sizeof(struct ocfs2_extent_rec); |
| 1461 | } |
| 1462 | |
| 1463 | static inline u16 ocfs2_refcount_recs_per_rb(struct super_block *sb) |
| 1464 | { |
| 1465 | int size; |
| 1466 | |
| 1467 | size = sb->s_blocksize - |
| 1468 | offsetof(struct ocfs2_refcount_block, rf_records.rl_recs); |
| 1469 | |
| 1470 | return size / sizeof(struct ocfs2_refcount_rec); |
| 1471 | } |
Tao Ma | e73a819 | 2009-08-11 14:33:14 +0800 | [diff] [blame] | 1472 | |
| 1473 | static inline u32 |
| 1474 | ocfs2_get_ref_rec_low_cpos(const struct ocfs2_refcount_rec *rec) |
| 1475 | { |
| 1476 | return le64_to_cpu(rec->r_cpos) & OCFS2_32BIT_POS_MASK; |
| 1477 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1478 | #else |
| 1479 | static inline int ocfs2_fast_symlink_chars(int blocksize) |
| 1480 | { |
| 1481 | return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink); |
| 1482 | } |
| 1483 | |
Tao Ma | 1097df3 | 2010-01-20 11:31:11 +0800 | [diff] [blame] | 1484 | static inline int ocfs2_max_inline_data_with_xattr(int blocksize, |
| 1485 | struct ocfs2_dinode *di) |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 1486 | { |
Tao Ma | 1097df3 | 2010-01-20 11:31:11 +0800 | [diff] [blame] | 1487 | if (di && (di->i_dyn_features & OCFS2_INLINE_XATTR_FL)) |
| 1488 | return blocksize - |
| 1489 | offsetof(struct ocfs2_dinode, id2.i_data.id_data) - |
| 1490 | di->i_xattr_inline_size; |
| 1491 | else |
| 1492 | return blocksize - |
| 1493 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1496 | static inline int ocfs2_extent_recs_per_inode(int blocksize) |
| 1497 | { |
| 1498 | int size; |
| 1499 | |
| 1500 | size = blocksize - |
| 1501 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); |
| 1502 | |
| 1503 | return size / sizeof(struct ocfs2_extent_rec); |
| 1504 | } |
| 1505 | |
| 1506 | static inline int ocfs2_chain_recs_per_inode(int blocksize) |
| 1507 | { |
| 1508 | int size; |
| 1509 | |
| 1510 | size = blocksize - |
| 1511 | offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); |
| 1512 | |
| 1513 | return size / sizeof(struct ocfs2_chain_rec); |
| 1514 | } |
| 1515 | |
| 1516 | static inline int ocfs2_extent_recs_per_eb(int blocksize) |
| 1517 | { |
| 1518 | int size; |
| 1519 | |
| 1520 | size = blocksize - |
| 1521 | offsetof(struct ocfs2_extent_block, h_list.l_recs); |
| 1522 | |
| 1523 | return size / sizeof(struct ocfs2_extent_rec); |
| 1524 | } |
| 1525 | |
Joel Becker | 798db35 | 2010-04-13 14:26:32 +0800 | [diff] [blame] | 1526 | static inline int ocfs2_extent_recs_per_gd(int blocksize) |
| 1527 | { |
| 1528 | int size; |
| 1529 | |
| 1530 | size = blocksize - |
| 1531 | offsetof(struct ocfs2_group_desc, bg_list.l_recs); |
| 1532 | |
| 1533 | return size / sizeof(struct ocfs2_extent_rec); |
| 1534 | } |
| 1535 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1536 | static inline int ocfs2_local_alloc_size(int blocksize) |
| 1537 | { |
| 1538 | int size; |
| 1539 | |
| 1540 | size = blocksize - |
| 1541 | offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); |
| 1542 | |
| 1543 | return size; |
| 1544 | } |
| 1545 | |
Tao Ma | 8571882 | 2010-04-13 14:38:06 +0800 | [diff] [blame] | 1546 | static inline int ocfs2_group_bitmap_size(int blocksize, |
| 1547 | int suballocator, |
| 1548 | uint32_t feature_incompat) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1549 | { |
Tao Ma | 8571882 | 2010-04-13 14:38:06 +0800 | [diff] [blame] | 1550 | int size = sb->s_blocksize - |
| 1551 | offsetof(struct ocfs2_group_desc, bg_bitmap); |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1552 | |
Tao Ma | 8571882 | 2010-04-13 14:38:06 +0800 | [diff] [blame] | 1553 | /* |
| 1554 | * The cluster allocator uses the entire block. Suballocators have |
| 1555 | * never used more than OCFS2_MAX_BG_BITMAP_SIZE. Unfortunately, older |
| 1556 | * code expects bg_size set to the maximum. Thus we must keep |
| 1557 | * bg_size as-is unless discontig_bg is enabled. |
| 1558 | */ |
| 1559 | if (suballocator && |
| 1560 | (feature_incompat & OCFS2_FEATURE_INCOMPAT_DISCONTIG_BG)) |
Joel Becker | 4cbe424 | 2010-04-13 14:26:12 +0800 | [diff] [blame] | 1561 | size = OCFS2_MAX_BG_BITMAP_SIZE; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1562 | |
| 1563 | return size; |
| 1564 | } |
| 1565 | |
| 1566 | static inline int ocfs2_truncate_recs_per_inode(int blocksize) |
| 1567 | { |
| 1568 | int size; |
| 1569 | |
| 1570 | size = blocksize - |
| 1571 | offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); |
| 1572 | |
| 1573 | return size / sizeof(struct ocfs2_truncate_rec); |
| 1574 | } |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 1575 | |
| 1576 | static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index) |
| 1577 | { |
| 1578 | uint64_t offset = OCFS2_BACKUP_SB_START; |
| 1579 | |
| 1580 | if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { |
| 1581 | offset <<= (2 * index); |
| 1582 | offset /= blocksize; |
| 1583 | return offset; |
| 1584 | } |
| 1585 | |
| 1586 | return 0; |
| 1587 | } |
Tao Ma | 0c044f0 | 2008-08-18 17:38:50 +0800 | [diff] [blame] | 1588 | |
| 1589 | static inline int ocfs2_xattr_recs_per_xb(int blocksize) |
| 1590 | { |
| 1591 | int size; |
| 1592 | |
| 1593 | size = blocksize - |
| 1594 | offsetof(struct ocfs2_xattr_block, |
| 1595 | xb_attrs.xb_root.xt_list.l_recs); |
| 1596 | |
| 1597 | return size / sizeof(struct ocfs2_extent_rec); |
| 1598 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1599 | #endif /* __KERNEL__ */ |
| 1600 | |
| 1601 | |
| 1602 | static inline int ocfs2_system_inode_is_global(int type) |
| 1603 | { |
| 1604 | return ((type >= 0) && |
| 1605 | (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)); |
| 1606 | } |
| 1607 | |
| 1608 | static inline int ocfs2_sprintf_system_inode_name(char *buf, int len, |
| 1609 | int type, int slot) |
| 1610 | { |
| 1611 | int chars; |
| 1612 | |
| 1613 | /* |
| 1614 | * Global system inodes can only have one copy. Everything |
| 1615 | * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode |
| 1616 | * list has a copy per slot. |
| 1617 | */ |
| 1618 | if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE) |
Joel Becker | fe9f387 | 2008-06-12 22:39:18 -0700 | [diff] [blame] | 1619 | chars = snprintf(buf, len, "%s", |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1620 | ocfs2_system_inodes[type].si_name); |
| 1621 | else |
| 1622 | chars = snprintf(buf, len, |
| 1623 | ocfs2_system_inodes[type].si_name, |
| 1624 | slot); |
| 1625 | |
| 1626 | return chars; |
| 1627 | } |
| 1628 | |
| 1629 | static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de, |
| 1630 | umode_t mode) |
| 1631 | { |
| 1632 | de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; |
| 1633 | } |
| 1634 | |
Tao Ma | af2bf0d | 2010-05-17 15:14:17 +0800 | [diff] [blame] | 1635 | static inline int ocfs2_gd_is_discontig(struct ocfs2_group_desc *gd) |
| 1636 | { |
| 1637 | if ((offsetof(struct ocfs2_group_desc, bg_bitmap) + |
| 1638 | le16_to_cpu(gd->bg_size)) != |
| 1639 | offsetof(struct ocfs2_group_desc, bg_list)) |
| 1640 | return 0; |
| 1641 | /* |
| 1642 | * Only valid to check l_next_free_rec if |
| 1643 | * bg_bitmap + bg_size == bg_list. |
| 1644 | */ |
| 1645 | if (!gd->bg_list.l_next_free_rec) |
| 1646 | return 0; |
| 1647 | return 1; |
| 1648 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1649 | #endif /* _OCFS2_FS_H */ |
| 1650 | |