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