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" |
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 \ |
| 101 | | OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS) |
Jan Kara | 19ece54 | 2008-08-21 20:13:17 +0200 | [diff] [blame] | 102 | #define OCFS2_FEATURE_RO_COMPAT_SUPP (OCFS2_FEATURE_RO_COMPAT_UNWRITTEN \ |
| 103 | | OCFS2_FEATURE_RO_COMPAT_USRQUOTA \ |
| 104 | | OCFS2_FEATURE_RO_COMPAT_GRPQUOTA) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 105 | |
| 106 | /* |
| 107 | * Heartbeat-only devices are missing journals and other files. The |
| 108 | * filesystem driver can't load them, but the library can. Never put |
| 109 | * this in OCFS2_FEATURE_INCOMPAT_SUPP, *ever*. |
| 110 | */ |
| 111 | #define OCFS2_FEATURE_INCOMPAT_HEARTBEAT_DEV 0x0002 |
| 112 | |
Mark Fasheh | 8903901 | 2006-12-07 18:05:37 -0800 | [diff] [blame] | 113 | /* |
| 114 | * tunefs sets this incompat flag before starting the resize and clears it |
| 115 | * at the end. This flag protects users from inadvertently mounting the fs |
| 116 | * after an aborted run without fsck-ing. |
| 117 | */ |
| 118 | #define OCFS2_FEATURE_INCOMPAT_RESIZE_INPROG 0x0004 |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 119 | |
Sunil Mushran | c271c5c | 2006-12-05 17:56:35 -0800 | [diff] [blame] | 120 | /* Used to denote a non-clustered volume */ |
| 121 | #define OCFS2_FEATURE_INCOMPAT_LOCAL_MOUNT 0x0008 |
| 122 | |
Mark Fasheh | 8903901 | 2006-12-07 18:05:37 -0800 | [diff] [blame] | 123 | /* Support for sparse allocation in b-trees */ |
| 124 | #define OCFS2_FEATURE_INCOMPAT_SPARSE_ALLOC 0x0010 |
| 125 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 126 | /* |
Mark Fasheh | 92e91ce | 2007-09-20 11:19:20 -0700 | [diff] [blame] | 127 | * Tunefs sets this incompat flag before starting an operation which |
| 128 | * would require cleanup on abort. This is done to protect users from |
| 129 | * inadvertently mounting the fs after an aborted run without |
| 130 | * fsck-ing. |
| 131 | * |
| 132 | * s_tunefs_flags on the super block describes precisely which |
| 133 | * operations were in progress. |
| 134 | */ |
| 135 | #define OCFS2_FEATURE_INCOMPAT_TUNEFS_INPROG 0x0020 |
| 136 | |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 137 | /* Support for data packed into inode blocks */ |
| 138 | #define OCFS2_FEATURE_INCOMPAT_INLINE_DATA 0x0040 |
| 139 | |
Mark Fasheh | 92e91ce | 2007-09-20 11:19:20 -0700 | [diff] [blame] | 140 | /* |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 141 | * Support for alternate, userspace cluster stacks. If set, the superblock |
| 142 | * field s_cluster_info contains a tag for the alternate stack in use as |
| 143 | * well as the name of the cluster being joined. |
| 144 | * mount.ocfs2 must pass in a matching stack name. |
| 145 | * |
| 146 | * If not set, the classic stack will be used. This is compatbile with |
| 147 | * all older versions. |
| 148 | */ |
| 149 | #define OCFS2_FEATURE_INCOMPAT_USERSPACE_STACK 0x0080 |
| 150 | |
Tiger Yang | 8154da3 | 2008-08-18 17:11:46 +0800 | [diff] [blame] | 151 | /* Support for the extended slot map */ |
| 152 | #define OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP 0x100 |
| 153 | |
| 154 | /* Support for extended attributes */ |
| 155 | #define OCFS2_FEATURE_INCOMPAT_XATTR 0x0200 |
| 156 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 157 | /* Support for indexed directores */ |
| 158 | #define OCFS2_FEATURE_INCOMPAT_INDEXED_DIRS 0x0400 |
| 159 | |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 160 | /* Metadata checksum and error correction */ |
| 161 | #define OCFS2_FEATURE_INCOMPAT_META_ECC 0x0800 |
| 162 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 163 | /* |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 164 | * backup superblock flag is used to indicate that this volume |
| 165 | * has backup superblocks. |
| 166 | */ |
| 167 | #define OCFS2_FEATURE_COMPAT_BACKUP_SB 0x0001 |
| 168 | |
Mark Fasheh | 328d575 | 2007-06-18 10:48:04 -0700 | [diff] [blame] | 169 | /* |
Joel Becker | a977218 | 2008-12-16 18:10:18 -0800 | [diff] [blame] | 170 | * The filesystem will correctly handle journal feature bits. |
| 171 | */ |
| 172 | #define OCFS2_FEATURE_COMPAT_JBD2_SB 0x0002 |
| 173 | |
| 174 | /* |
Mark Fasheh | 328d575 | 2007-06-18 10:48:04 -0700 | [diff] [blame] | 175 | * Unwritten extents support. |
| 176 | */ |
| 177 | #define OCFS2_FEATURE_RO_COMPAT_UNWRITTEN 0x0001 |
| 178 | |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 179 | /* |
| 180 | * Maintain quota information for this filesystem |
| 181 | */ |
| 182 | #define OCFS2_FEATURE_RO_COMPAT_USRQUOTA 0x0002 |
| 183 | #define OCFS2_FEATURE_RO_COMPAT_GRPQUOTA 0x0004 |
| 184 | |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 185 | /* The byte offset of the first backup block will be 1G. |
| 186 | * The following will be 4G, 16G, 64G, 256G and 1T. |
| 187 | */ |
| 188 | #define OCFS2_BACKUP_SB_START 1 << 30 |
| 189 | |
| 190 | /* the max backup superblock nums */ |
| 191 | #define OCFS2_MAX_BACKUP_SUPERBLOCKS 6 |
| 192 | |
| 193 | /* |
Mark Fasheh | 92e91ce | 2007-09-20 11:19:20 -0700 | [diff] [blame] | 194 | * Flags on ocfs2_super_block.s_tunefs_flags |
| 195 | */ |
| 196 | #define OCFS2_TUNEFS_INPROG_REMOVE_SLOT 0x0001 /* Removing slots */ |
| 197 | |
| 198 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 199 | * Flags on ocfs2_dinode.i_flags |
| 200 | */ |
| 201 | #define OCFS2_VALID_FL (0x00000001) /* Inode is valid */ |
| 202 | #define OCFS2_UNUSED2_FL (0x00000002) |
| 203 | #define OCFS2_ORPHANED_FL (0x00000004) /* On the orphan list */ |
| 204 | #define OCFS2_UNUSED3_FL (0x00000008) |
| 205 | /* System inode flags */ |
| 206 | #define OCFS2_SYSTEM_FL (0x00000010) /* System inode */ |
| 207 | #define OCFS2_SUPER_BLOCK_FL (0x00000020) /* Super block */ |
| 208 | #define OCFS2_LOCAL_ALLOC_FL (0x00000040) /* Slot local alloc bitmap */ |
| 209 | #define OCFS2_BITMAP_FL (0x00000080) /* Allocation bitmap */ |
| 210 | #define OCFS2_JOURNAL_FL (0x00000100) /* Slot local journal */ |
| 211 | #define OCFS2_HEARTBEAT_FL (0x00000200) /* Heartbeat area */ |
| 212 | #define OCFS2_CHAIN_FL (0x00000400) /* Chain allocator */ |
| 213 | #define OCFS2_DEALLOC_FL (0x00000800) /* Truncate log */ |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 214 | #define OCFS2_QUOTA_FL (0x00001000) /* Quota file */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 215 | |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 216 | /* |
| 217 | * Flags on ocfs2_dinode.i_dyn_features |
| 218 | * |
| 219 | * These can change much more often than i_flags. When adding flags, |
| 220 | * keep in mind that i_dyn_features is only 16 bits wide. |
| 221 | */ |
| 222 | #define OCFS2_INLINE_DATA_FL (0x0001) /* Data stored in inode block */ |
| 223 | #define OCFS2_HAS_XATTR_FL (0x0002) |
| 224 | #define OCFS2_INLINE_XATTR_FL (0x0004) |
| 225 | #define OCFS2_INDEXED_DIR_FL (0x0008) |
| 226 | |
Herbert Poetzl | ca4d147 | 2006-07-03 17:27:12 -0700 | [diff] [blame] | 227 | /* Inode attributes, keep in sync with EXT2 */ |
| 228 | #define OCFS2_SECRM_FL (0x00000001) /* Secure deletion */ |
| 229 | #define OCFS2_UNRM_FL (0x00000002) /* Undelete */ |
| 230 | #define OCFS2_COMPR_FL (0x00000004) /* Compress file */ |
| 231 | #define OCFS2_SYNC_FL (0x00000008) /* Synchronous updates */ |
| 232 | #define OCFS2_IMMUTABLE_FL (0x00000010) /* Immutable file */ |
| 233 | #define OCFS2_APPEND_FL (0x00000020) /* writes to file may only append */ |
| 234 | #define OCFS2_NODUMP_FL (0x00000040) /* do not dump file */ |
| 235 | #define OCFS2_NOATIME_FL (0x00000080) /* do not update atime */ |
| 236 | #define OCFS2_DIRSYNC_FL (0x00010000) /* dirsync behaviour (directories only) */ |
| 237 | |
| 238 | #define OCFS2_FL_VISIBLE (0x000100FF) /* User visible flags */ |
| 239 | #define OCFS2_FL_MODIFIABLE (0x000100FF) /* User modifiable flags */ |
| 240 | |
| 241 | /* |
Mark Fasheh | e48edee | 2007-03-07 16:46:57 -0800 | [diff] [blame] | 242 | * Extent record flags (e_node.leaf.flags) |
| 243 | */ |
| 244 | #define OCFS2_EXT_UNWRITTEN (0x01) /* Extent is allocated but |
| 245 | * unwritten */ |
| 246 | |
| 247 | /* |
Herbert Poetzl | ca4d147 | 2006-07-03 17:27:12 -0700 | [diff] [blame] | 248 | * ioctl commands |
| 249 | */ |
| 250 | #define OCFS2_IOC_GETFLAGS _IOR('f', 1, long) |
| 251 | #define OCFS2_IOC_SETFLAGS _IOW('f', 2, long) |
Mark Fasheh | 586d232 | 2007-03-09 15:56:28 -0800 | [diff] [blame] | 252 | #define OCFS2_IOC32_GETFLAGS _IOR('f', 1, int) |
| 253 | #define OCFS2_IOC32_SETFLAGS _IOW('f', 2, int) |
Herbert Poetzl | ca4d147 | 2006-07-03 17:27:12 -0700 | [diff] [blame] | 254 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 255 | /* |
Mark Fasheh | b258010 | 2007-03-09 16:53:21 -0800 | [diff] [blame] | 256 | * Space reservation / allocation / free ioctls and argument structure |
| 257 | * are designed to be compatible with XFS. |
| 258 | * |
| 259 | * ALLOCSP* and FREESP* are not and will never be supported, but are |
| 260 | * included here for completeness. |
| 261 | */ |
| 262 | struct ocfs2_space_resv { |
| 263 | __s16 l_type; |
| 264 | __s16 l_whence; |
| 265 | __s64 l_start; |
| 266 | __s64 l_len; /* len == 0 means until end of file */ |
| 267 | __s32 l_sysid; |
| 268 | __u32 l_pid; |
| 269 | __s32 l_pad[4]; /* reserve area */ |
| 270 | }; |
| 271 | |
| 272 | #define OCFS2_IOC_ALLOCSP _IOW ('X', 10, struct ocfs2_space_resv) |
| 273 | #define OCFS2_IOC_FREESP _IOW ('X', 11, struct ocfs2_space_resv) |
| 274 | #define OCFS2_IOC_RESVSP _IOW ('X', 40, struct ocfs2_space_resv) |
| 275 | #define OCFS2_IOC_UNRESVSP _IOW ('X', 41, struct ocfs2_space_resv) |
| 276 | #define OCFS2_IOC_ALLOCSP64 _IOW ('X', 36, struct ocfs2_space_resv) |
| 277 | #define OCFS2_IOC_FREESP64 _IOW ('X', 37, struct ocfs2_space_resv) |
| 278 | #define OCFS2_IOC_RESVSP64 _IOW ('X', 42, struct ocfs2_space_resv) |
| 279 | #define OCFS2_IOC_UNRESVSP64 _IOW ('X', 43, struct ocfs2_space_resv) |
| 280 | |
Tao Ma | 7909f2b | 2007-12-18 15:47:25 +0800 | [diff] [blame] | 281 | /* Used to pass group descriptor data when online resize is done */ |
| 282 | struct ocfs2_new_group_input { |
| 283 | __u64 group; /* Group descriptor's blkno. */ |
| 284 | __u32 clusters; /* Total number of clusters in this group */ |
| 285 | __u32 frees; /* Total free clusters in this group */ |
| 286 | __u16 chain; /* Chain for this group */ |
| 287 | __u16 reserved1; |
| 288 | __u32 reserved2; |
| 289 | }; |
| 290 | |
Tao Ma | d659072 | 2007-12-18 15:47:03 +0800 | [diff] [blame] | 291 | #define OCFS2_IOC_GROUP_EXTEND _IOW('o', 1, int) |
Tao Ma | 7909f2b | 2007-12-18 15:47:25 +0800 | [diff] [blame] | 292 | #define OCFS2_IOC_GROUP_ADD _IOW('o', 2,struct ocfs2_new_group_input) |
| 293 | #define OCFS2_IOC_GROUP_ADD64 _IOW('o', 3,struct ocfs2_new_group_input) |
Tao Ma | d659072 | 2007-12-18 15:47:03 +0800 | [diff] [blame] | 294 | |
Mark Fasheh | b258010 | 2007-03-09 16:53:21 -0800 | [diff] [blame] | 295 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 296 | * Journal Flags (ocfs2_dinode.id1.journal1.i_flags) |
| 297 | */ |
| 298 | #define OCFS2_JOURNAL_DIRTY_FL (0x00000001) /* Journal needs recovery */ |
| 299 | |
| 300 | /* |
| 301 | * superblock s_state flags |
| 302 | */ |
| 303 | #define OCFS2_ERROR_FS (0x00000001) /* FS saw errors */ |
| 304 | |
| 305 | /* Limit of space in ocfs2_dir_entry */ |
| 306 | #define OCFS2_MAX_FILENAME_LEN 255 |
| 307 | |
| 308 | /* Maximum slots on an ocfs2 file system */ |
| 309 | #define OCFS2_MAX_SLOTS 255 |
| 310 | |
| 311 | /* Slot map indicator for an empty slot */ |
| 312 | #define OCFS2_INVALID_SLOT -1 |
| 313 | |
| 314 | #define OCFS2_VOL_UUID_LEN 16 |
| 315 | #define OCFS2_MAX_VOL_LABEL_LEN 64 |
| 316 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 317 | /* The alternate, userspace stack fields */ |
| 318 | #define OCFS2_STACK_LABEL_LEN 4 |
| 319 | #define OCFS2_CLUSTER_NAME_LEN 16 |
| 320 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 321 | /* Journal limits (in bytes) */ |
| 322 | #define OCFS2_MIN_JOURNAL_SIZE (4 * 1024 * 1024) |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 323 | |
Sunil Mushran | 2fbe8d1 | 2007-12-20 14:58:11 -0800 | [diff] [blame] | 324 | /* |
| 325 | * Default local alloc size (in megabytes) |
| 326 | * |
| 327 | * The value chosen should be such that most allocations, including new |
| 328 | * block groups, use local alloc. |
| 329 | */ |
| 330 | #define OCFS2_DEFAULT_LOCAL_ALLOC_SIZE 8 |
| 331 | |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 332 | /* |
| 333 | * Inline extended attribute size (in bytes) |
| 334 | * The value chosen should be aligned to 16 byte boundaries. |
| 335 | */ |
| 336 | #define OCFS2_MIN_XATTR_INLINE_SIZE 256 |
| 337 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 338 | struct ocfs2_system_inode_info { |
| 339 | char *si_name; |
| 340 | int si_iflags; |
| 341 | int si_mode; |
| 342 | }; |
| 343 | |
| 344 | /* System file index */ |
| 345 | enum { |
| 346 | BAD_BLOCK_SYSTEM_INODE = 0, |
| 347 | GLOBAL_INODE_ALLOC_SYSTEM_INODE, |
| 348 | SLOT_MAP_SYSTEM_INODE, |
| 349 | #define OCFS2_FIRST_ONLINE_SYSTEM_INODE SLOT_MAP_SYSTEM_INODE |
| 350 | HEARTBEAT_SYSTEM_INODE, |
| 351 | GLOBAL_BITMAP_SYSTEM_INODE, |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 352 | USER_QUOTA_SYSTEM_INODE, |
| 353 | GROUP_QUOTA_SYSTEM_INODE, |
| 354 | #define OCFS2_LAST_GLOBAL_SYSTEM_INODE GROUP_QUOTA_SYSTEM_INODE |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 355 | ORPHAN_DIR_SYSTEM_INODE, |
| 356 | EXTENT_ALLOC_SYSTEM_INODE, |
| 357 | INODE_ALLOC_SYSTEM_INODE, |
| 358 | JOURNAL_SYSTEM_INODE, |
| 359 | LOCAL_ALLOC_SYSTEM_INODE, |
| 360 | TRUNCATE_LOG_SYSTEM_INODE, |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 361 | LOCAL_USER_QUOTA_SYSTEM_INODE, |
| 362 | LOCAL_GROUP_QUOTA_SYSTEM_INODE, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 363 | NUM_SYSTEM_INODES |
| 364 | }; |
| 365 | |
| 366 | static struct ocfs2_system_inode_info ocfs2_system_inodes[NUM_SYSTEM_INODES] = { |
| 367 | /* Global system inodes (single copy) */ |
| 368 | /* The first two are only used from userspace mfks/tunefs */ |
| 369 | [BAD_BLOCK_SYSTEM_INODE] = { "bad_blocks", 0, S_IFREG | 0644 }, |
| 370 | [GLOBAL_INODE_ALLOC_SYSTEM_INODE] = { "global_inode_alloc", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, |
| 371 | |
| 372 | /* These are used by the running filesystem */ |
| 373 | [SLOT_MAP_SYSTEM_INODE] = { "slot_map", 0, S_IFREG | 0644 }, |
| 374 | [HEARTBEAT_SYSTEM_INODE] = { "heartbeat", OCFS2_HEARTBEAT_FL, S_IFREG | 0644 }, |
| 375 | [GLOBAL_BITMAP_SYSTEM_INODE] = { "global_bitmap", 0, S_IFREG | 0644 }, |
Jan Kara | 1a224ad | 2008-08-20 15:43:36 +0200 | [diff] [blame] | 376 | [USER_QUOTA_SYSTEM_INODE] = { "aquota.user", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
| 377 | [GROUP_QUOTA_SYSTEM_INODE] = { "aquota.group", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 378 | |
| 379 | /* Slot-specific system inodes (one copy per slot) */ |
| 380 | [ORPHAN_DIR_SYSTEM_INODE] = { "orphan_dir:%04d", 0, S_IFDIR | 0755 }, |
| 381 | [EXTENT_ALLOC_SYSTEM_INODE] = { "extent_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, |
| 382 | [INODE_ALLOC_SYSTEM_INODE] = { "inode_alloc:%04d", OCFS2_BITMAP_FL | OCFS2_CHAIN_FL, S_IFREG | 0644 }, |
| 383 | [JOURNAL_SYSTEM_INODE] = { "journal:%04d", OCFS2_JOURNAL_FL, S_IFREG | 0644 }, |
| 384 | [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] | 385 | [TRUNCATE_LOG_SYSTEM_INODE] = { "truncate_log:%04d", OCFS2_DEALLOC_FL, S_IFREG | 0644 }, |
| 386 | [LOCAL_USER_QUOTA_SYSTEM_INODE] = { "aquota.user:%04d", OCFS2_QUOTA_FL, S_IFREG | 0644 }, |
| 387 | [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] | 388 | }; |
| 389 | |
| 390 | /* Parameter passed from mount.ocfs2 to module */ |
| 391 | #define OCFS2_HB_NONE "heartbeat=none" |
| 392 | #define OCFS2_HB_LOCAL "heartbeat=local" |
| 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. |
| 452 | This is a simple Hamming code dependant |
| 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 */ |
| 554 | /*20*/ __le64 h_reserved3; |
| 555 | __le64 h_next_leaf_blk; /* Offset on disk, in blocks, |
| 556 | of next leaf header pointing |
| 557 | to data */ |
| 558 | /*30*/ struct ocfs2_extent_list h_list; /* Extent record list */ |
| 559 | /* Actual on-disk size is one block */ |
| 560 | }; |
| 561 | |
| 562 | /* |
Joel Becker | fb86b1f | 2008-02-01 11:59:05 -0800 | [diff] [blame] | 563 | * 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] | 564 | * system file. A slot is valid if it contains a node number >= 0. The |
| 565 | * value -1 (0xFFFF) is OCFS2_INVALID_SLOT. This marks a slot empty. |
Joel Becker | fb86b1f | 2008-02-01 11:59:05 -0800 | [diff] [blame] | 566 | */ |
| 567 | struct ocfs2_slot_map { |
| 568 | /*00*/ __le16 sm_slots[0]; |
| 569 | /* |
| 570 | * Actual on-disk size is one block. OCFS2_MAX_SLOTS is 255, |
| 571 | * 255 * sizeof(__le16) == 512B, within the 512B block minimum blocksize. |
| 572 | */ |
| 573 | }; |
| 574 | |
Joel Becker | 386a2ef | 2008-02-01 12:06:54 -0800 | [diff] [blame] | 575 | struct ocfs2_extended_slot { |
| 576 | /*00*/ __u8 es_valid; |
| 577 | __u8 es_reserved1[3]; |
| 578 | __le32 es_node_num; |
| 579 | /*10*/ |
| 580 | }; |
| 581 | |
| 582 | /* |
| 583 | * The extended slot map, used when OCFS2_FEATURE_INCOMPAT_EXTENDED_SLOT_MAP |
| 584 | * is set. It separates out the valid marker from the node number, and |
| 585 | * has room to grow. Unlike the old slot map, this format is defined by |
| 586 | * i_size. |
| 587 | */ |
| 588 | struct ocfs2_slot_map_extended { |
| 589 | /*00*/ struct ocfs2_extended_slot se_slots[0]; |
| 590 | /* |
| 591 | * Actual size is i_size of the slot_map system file. It should |
| 592 | * match s_max_slots * sizeof(struct ocfs2_extended_slot) |
| 593 | */ |
| 594 | }; |
| 595 | |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 596 | struct ocfs2_cluster_info { |
| 597 | /*00*/ __u8 ci_stack[OCFS2_STACK_LABEL_LEN]; |
| 598 | __le32 ci_reserved; |
| 599 | /*08*/ __u8 ci_cluster[OCFS2_CLUSTER_NAME_LEN]; |
| 600 | /*18*/ |
| 601 | }; |
| 602 | |
Joel Becker | fb86b1f | 2008-02-01 11:59:05 -0800 | [diff] [blame] | 603 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 604 | * On disk superblock for OCFS2 |
| 605 | * Note that it is contained inside an ocfs2_dinode, so all offsets |
| 606 | * are relative to the start of ocfs2_dinode.id2. |
| 607 | */ |
| 608 | struct ocfs2_super_block { |
| 609 | /*00*/ __le16 s_major_rev_level; |
| 610 | __le16 s_minor_rev_level; |
| 611 | __le16 s_mnt_count; |
| 612 | __le16 s_max_mnt_count; |
| 613 | __le16 s_state; /* File system state */ |
| 614 | __le16 s_errors; /* Behaviour when detecting errors */ |
| 615 | __le32 s_checkinterval; /* Max time between checks */ |
| 616 | /*10*/ __le64 s_lastcheck; /* Time of last check */ |
| 617 | __le32 s_creator_os; /* OS */ |
| 618 | __le32 s_feature_compat; /* Compatible feature set */ |
| 619 | /*20*/ __le32 s_feature_incompat; /* Incompatible feature set */ |
| 620 | __le32 s_feature_ro_compat; /* Readonly-compatible feature set */ |
| 621 | __le64 s_root_blkno; /* Offset, in blocks, of root directory |
| 622 | dinode */ |
| 623 | /*30*/ __le64 s_system_dir_blkno; /* Offset, in blocks, of system |
| 624 | directory dinode */ |
| 625 | __le32 s_blocksize_bits; /* Blocksize for this fs */ |
| 626 | __le32 s_clustersize_bits; /* Clustersize for this fs */ |
| 627 | /*40*/ __le16 s_max_slots; /* Max number of simultaneous mounts |
| 628 | before tunefs required */ |
Mark Fasheh | 92e91ce | 2007-09-20 11:19:20 -0700 | [diff] [blame] | 629 | __le16 s_tunefs_flag; |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 630 | __le32 s_uuid_hash; /* hash value of uuid */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 631 | __le64 s_first_cluster_group; /* Block offset of 1st cluster |
| 632 | * group header */ |
| 633 | /*50*/ __u8 s_label[OCFS2_MAX_VOL_LABEL_LEN]; /* Label for mounting, etc. */ |
| 634 | /*90*/ __u8 s_uuid[OCFS2_VOL_UUID_LEN]; /* 128-bit uuid */ |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 635 | /*A0*/ struct ocfs2_cluster_info s_cluster_info; /* Selected userspace |
| 636 | stack. Only valid |
| 637 | with INCOMPAT flag. */ |
Tiger Yang | 8154da3 | 2008-08-18 17:11:46 +0800 | [diff] [blame] | 638 | /*B8*/ __le16 s_xattr_inline_size; /* extended attribute inline size |
| 639 | for this fs*/ |
| 640 | __le16 s_reserved0; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 641 | __le32 s_dx_seed[3]; /* seed[0-2] for dx dir hash. |
| 642 | * s_uuid_hash serves as seed[3]. */ |
| 643 | /*C0*/ __le64 s_reserved2[15]; /* Fill out superblock */ |
Joel Becker | b61817e | 2008-02-01 15:08:23 -0800 | [diff] [blame] | 644 | /*140*/ |
| 645 | |
| 646 | /* |
| 647 | * NOTE: As stated above, all offsets are relative to |
| 648 | * ocfs2_dinode.id2, which is at 0xC0 in the inode. |
| 649 | * 0xC0 + 0x140 = 0x200 or 512 bytes. A superblock must fit within |
| 650 | * our smallest blocksize, which is 512 bytes. To ensure this, |
| 651 | * we reserve the space in s_reserved2. Anything past s_reserved2 |
| 652 | * will not be available on the smallest blocksize. |
| 653 | */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 654 | }; |
| 655 | |
| 656 | /* |
| 657 | * Local allocation bitmap for OCFS2 slots |
| 658 | * Note that it exists inside an ocfs2_dinode, so all offsets are |
| 659 | * relative to the start of ocfs2_dinode.id2. |
| 660 | */ |
| 661 | struct ocfs2_local_alloc |
| 662 | { |
| 663 | /*00*/ __le32 la_bm_off; /* Starting bit offset in main bitmap */ |
| 664 | __le16 la_size; /* Size of included bitmap, in bytes */ |
| 665 | __le16 la_reserved1; |
| 666 | __le64 la_reserved2; |
| 667 | /*10*/ __u8 la_bitmap[0]; |
| 668 | }; |
| 669 | |
| 670 | /* |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 671 | * Data-in-inode header. This is only used if i_dyn_features has |
| 672 | * OCFS2_INLINE_DATA_FL set. |
| 673 | */ |
| 674 | struct ocfs2_inline_data |
| 675 | { |
| 676 | /*00*/ __le16 id_count; /* Number of bytes that can be used |
| 677 | * for data, starting at id_data */ |
| 678 | __le16 id_reserved0; |
| 679 | __le32 id_reserved1; |
| 680 | __u8 id_data[0]; /* Start of user data */ |
| 681 | }; |
| 682 | |
| 683 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 684 | * On disk inode for OCFS2 |
| 685 | */ |
| 686 | struct ocfs2_dinode { |
| 687 | /*00*/ __u8 i_signature[8]; /* Signature for validation */ |
| 688 | __le32 i_generation; /* Generation number */ |
| 689 | __le16 i_suballoc_slot; /* Slot suballocator this inode |
| 690 | belongs to */ |
| 691 | __le16 i_suballoc_bit; /* Bit offset in suballocator |
| 692 | block group */ |
Mark Fasheh | 198a1ca | 2008-11-20 17:54:57 -0800 | [diff] [blame] | 693 | /*10*/ __le16 i_links_count_hi; /* High 16 bits of links count */ |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 694 | __le16 i_xattr_inline_size; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 695 | __le32 i_clusters; /* Cluster count */ |
| 696 | __le32 i_uid; /* Owner UID */ |
| 697 | __le32 i_gid; /* Owning GID */ |
| 698 | /*20*/ __le64 i_size; /* Size in bytes */ |
| 699 | __le16 i_mode; /* File mode */ |
| 700 | __le16 i_links_count; /* Links count */ |
| 701 | __le32 i_flags; /* File flags */ |
| 702 | /*30*/ __le64 i_atime; /* Access time */ |
| 703 | __le64 i_ctime; /* Creation time */ |
| 704 | /*40*/ __le64 i_mtime; /* Modification time */ |
| 705 | __le64 i_dtime; /* Deletion time */ |
| 706 | /*50*/ __le64 i_blkno; /* Offset on disk, in blocks */ |
| 707 | __le64 i_last_eb_blk; /* Pointer to last extent |
| 708 | block */ |
| 709 | /*60*/ __le32 i_fs_generation; /* Generation per fs-instance */ |
| 710 | __le32 i_atime_nsec; |
| 711 | __le32 i_ctime_nsec; |
| 712 | __le32 i_mtime_nsec; |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 713 | /*70*/ __le32 i_attr; |
Tiger Yang | 5000863 | 2007-03-20 16:01:38 -0700 | [diff] [blame] | 714 | __le16 i_orphaned_slot; /* Only valid when OCFS2_ORPHANED_FL |
| 715 | was set in i_flags */ |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 716 | __le16 i_dyn_features; |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 717 | __le64 i_xattr_loc; |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 718 | /*80*/ struct ocfs2_block_check i_check; /* Error checking */ |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 719 | /*88*/ __le64 i_dx_root; /* Pointer to dir index root block */ |
| 720 | __le64 i_reserved2[5]; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 721 | /*B8*/ union { |
| 722 | __le64 i_pad1; /* Generic way to refer to this |
| 723 | 64bit union */ |
| 724 | struct { |
| 725 | __le64 i_rdev; /* Device number */ |
| 726 | } dev1; |
| 727 | struct { /* Info for bitmap system |
| 728 | inodes */ |
| 729 | __le32 i_used; /* Bits (ie, clusters) used */ |
| 730 | __le32 i_total; /* Total bits (clusters) |
| 731 | available */ |
| 732 | } bitmap1; |
| 733 | struct { /* Info for journal system |
| 734 | inodes */ |
| 735 | __le32 ij_flags; /* Mounted, version, etc. */ |
Sunil Mushran | c69991a | 2008-07-14 17:31:09 -0700 | [diff] [blame] | 736 | __le32 ij_recovery_generation; /* Incremented when the |
| 737 | journal is recovered |
| 738 | after an unclean |
| 739 | shutdown */ |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 740 | } journal1; |
| 741 | } id1; /* Inode type dependant 1 */ |
| 742 | /*C0*/ union { |
| 743 | struct ocfs2_super_block i_super; |
| 744 | struct ocfs2_local_alloc i_lab; |
| 745 | struct ocfs2_chain_list i_chain; |
| 746 | struct ocfs2_extent_list i_list; |
| 747 | struct ocfs2_truncate_log i_dealloc; |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 748 | struct ocfs2_inline_data i_data; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 749 | __u8 i_symlink[0]; |
| 750 | } id2; |
| 751 | /* Actual on-disk size is one block */ |
| 752 | }; |
| 753 | |
| 754 | /* |
| 755 | * On-disk directory entry structure for OCFS2 |
| 756 | * |
| 757 | * Packed as this structure could be accessed unaligned on 64-bit platforms |
| 758 | */ |
| 759 | struct ocfs2_dir_entry { |
| 760 | /*00*/ __le64 inode; /* Inode number */ |
| 761 | __le16 rec_len; /* Directory entry length */ |
| 762 | __u8 name_len; /* Name length */ |
| 763 | __u8 file_type; |
| 764 | /*0C*/ char name[OCFS2_MAX_FILENAME_LEN]; /* File name */ |
| 765 | /* Actual on-disk length specified by rec_len */ |
| 766 | } __attribute__ ((packed)); |
| 767 | |
| 768 | /* |
Mark Fasheh | 87d35a7 | 2008-12-10 17:36:25 -0800 | [diff] [blame] | 769 | * Per-block record for the unindexed directory btree. This is carefully |
| 770 | * crafted so that the rec_len and name_len records of an ocfs2_dir_entry are |
| 771 | * mirrored. That way, the directory manipulation code needs a minimal amount |
| 772 | * of update. |
| 773 | * |
| 774 | * NOTE: Keep this structure aligned to a multiple of 4 bytes. |
| 775 | */ |
| 776 | struct ocfs2_dir_block_trailer { |
| 777 | /*00*/ __le64 db_compat_inode; /* Always zero. Was inode */ |
| 778 | |
| 779 | __le16 db_compat_rec_len; /* Backwards compatible with |
| 780 | * ocfs2_dir_entry. */ |
| 781 | __u8 db_compat_name_len; /* Always zero. Was name_len */ |
| 782 | __u8 db_reserved0; |
| 783 | __le16 db_reserved1; |
| 784 | __le16 db_free_rec_len; /* Size of largest empty hole |
| 785 | * in this block. (unused) */ |
| 786 | /*10*/ __u8 db_signature[8]; /* Signature for verification */ |
| 787 | __le64 db_reserved2; |
| 788 | __le64 db_free_next; /* Next block in list (unused) */ |
| 789 | /*20*/ __le64 db_blkno; /* Offset on disk, in blocks */ |
| 790 | __le64 db_parent_dinode; /* dinode which owns me, in |
| 791 | blocks */ |
Joel Becker | c175a51 | 2008-12-10 17:58:22 -0800 | [diff] [blame] | 792 | /*30*/ struct ocfs2_block_check db_check; /* Error checking */ |
Mark Fasheh | 87d35a7 | 2008-12-10 17:36:25 -0800 | [diff] [blame] | 793 | /*40*/ |
| 794 | }; |
| 795 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 796 | /* |
| 797 | * A directory entry in the indexed tree. We don't store the full name here, |
| 798 | * but instead provide a pointer to the full dirent in the unindexed tree. |
| 799 | * |
| 800 | * We also store name_len here so as to reduce the number of leaf blocks we |
| 801 | * need to search in case of collisions. |
| 802 | */ |
| 803 | struct ocfs2_dx_entry { |
| 804 | __le32 dx_major_hash; /* Used to find logical |
| 805 | * cluster in index */ |
| 806 | __le32 dx_minor_hash; /* Lower bits used to find |
| 807 | * block in cluster */ |
| 808 | __le64 dx_dirent_blk; /* Physical block in unindexed |
| 809 | * tree holding this dirent. */ |
| 810 | }; |
| 811 | |
| 812 | struct ocfs2_dx_entry_list { |
| 813 | __le32 de_reserved; |
| 814 | __le16 de_count; /* Maximum number of entries |
| 815 | * possible in de_entries */ |
| 816 | __le16 de_num_used; /* Current number of |
| 817 | * de_entries entries */ |
| 818 | struct ocfs2_dx_entry de_entries[0]; /* Indexed dir entries |
| 819 | * in a packed array of |
| 820 | * length de_num_used */ |
| 821 | }; |
| 822 | |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 823 | #define OCFS2_DX_FLAG_INLINE 0x01 |
| 824 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 825 | /* |
| 826 | * A directory indexing block. Each indexed directory has one of these, |
| 827 | * pointed to by ocfs2_dinode. |
| 828 | * |
| 829 | * This block stores an indexed btree root, and a set of free space |
| 830 | * start-of-list pointers. |
| 831 | */ |
| 832 | struct ocfs2_dx_root_block { |
| 833 | __u8 dr_signature[8]; /* Signature for verification */ |
| 834 | struct ocfs2_block_check dr_check; /* Error checking */ |
| 835 | __le16 dr_suballoc_slot; /* Slot suballocator this |
| 836 | * block belongs to. */ |
| 837 | __le16 dr_suballoc_bit; /* Bit offset in suballocator |
| 838 | * block group */ |
| 839 | __le32 dr_fs_generation; /* Must match super block */ |
| 840 | __le64 dr_blkno; /* Offset on disk, in blocks */ |
| 841 | __le64 dr_last_eb_blk; /* Pointer to last |
| 842 | * extent block */ |
| 843 | __le32 dr_clusters; /* Clusters allocated |
| 844 | * to the indexed tree. */ |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 845 | __u8 dr_flags; /* OCFS2_DX_FLAG_* flags */ |
| 846 | __u8 dr_reserved0; |
| 847 | __le16 dr_reserved1; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 848 | __le64 dr_dir_blkno; /* Pointer to parent inode */ |
Mark Fasheh | e3a93c2 | 2009-02-17 15:29:35 -0800 | [diff] [blame] | 849 | __le32 dr_num_entries; /* Total number of |
| 850 | * names stored in |
| 851 | * this directory.*/ |
| 852 | __le32 dr_reserved2; |
Mark Fasheh | e7c17e4 | 2009-01-29 18:17:46 -0800 | [diff] [blame] | 853 | __le64 dr_free_blk; /* Pointer to head of free |
| 854 | * unindexed block list. */ |
| 855 | __le64 dr_reserved3[15]; |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 856 | union { |
| 857 | struct ocfs2_extent_list dr_list; /* Keep this aligned to 128 |
| 858 | * bits for maximum space |
| 859 | * efficiency. */ |
| 860 | struct ocfs2_dx_entry_list dr_entries; /* In-root-block list of |
| 861 | * entries. We grow out |
| 862 | * to extents if this |
| 863 | * gets too big. */ |
| 864 | }; |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 865 | }; |
| 866 | |
| 867 | /* |
| 868 | * The header of a leaf block in the indexed tree. |
| 869 | */ |
| 870 | struct ocfs2_dx_leaf { |
| 871 | __u8 dl_signature[8];/* Signature for verification */ |
| 872 | struct ocfs2_block_check dl_check; /* Error checking */ |
| 873 | __le64 dl_blkno; /* Offset on disk, in blocks */ |
| 874 | __le32 dl_fs_generation;/* Must match super block */ |
| 875 | __le32 dl_reserved0; |
| 876 | __le64 dl_reserved1; |
| 877 | struct ocfs2_dx_entry_list dl_list; |
| 878 | }; |
| 879 | |
Mark Fasheh | 87d35a7 | 2008-12-10 17:36:25 -0800 | [diff] [blame] | 880 | /* |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 881 | * On disk allocator group structure for OCFS2 |
| 882 | */ |
| 883 | struct ocfs2_group_desc |
| 884 | { |
| 885 | /*00*/ __u8 bg_signature[8]; /* Signature for validation */ |
| 886 | __le16 bg_size; /* Size of included bitmap in |
| 887 | bytes. */ |
| 888 | __le16 bg_bits; /* Bits represented by this |
| 889 | group. */ |
| 890 | __le16 bg_free_bits_count; /* Free bits count */ |
| 891 | __le16 bg_chain; /* What chain I am in. */ |
| 892 | /*10*/ __le32 bg_generation; |
| 893 | __le32 bg_reserved1; |
| 894 | __le64 bg_next_group; /* Next group in my list, in |
| 895 | blocks */ |
| 896 | /*20*/ __le64 bg_parent_dinode; /* dinode which owns me, in |
| 897 | blocks */ |
| 898 | __le64 bg_blkno; /* Offset on disk, in blocks */ |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 899 | /*30*/ struct ocfs2_block_check bg_check; /* Error checking */ |
| 900 | __le64 bg_reserved2; |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 901 | /*40*/ __u8 bg_bitmap[0]; |
| 902 | }; |
| 903 | |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 904 | /* |
| 905 | * On disk extended attribute structure for OCFS2. |
| 906 | */ |
| 907 | |
| 908 | /* |
| 909 | * ocfs2_xattr_entry indicates one extend attribute. |
| 910 | * |
| 911 | * Note that it can be stored in inode, one block or one xattr bucket. |
| 912 | */ |
| 913 | struct ocfs2_xattr_entry { |
| 914 | __le32 xe_name_hash; /* hash value of xattr prefix+suffix. */ |
Tao Ma | 8573f79 | 2008-10-24 22:24:17 +0800 | [diff] [blame] | 915 | __le16 xe_name_offset; /* byte offset from the 1st entry in the |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 916 | local xattr storage(inode, xattr block or |
| 917 | xattr bucket). */ |
| 918 | __u8 xe_name_len; /* xattr name len, does't include prefix. */ |
Tao Ma | 8573f79 | 2008-10-24 22:24:17 +0800 | [diff] [blame] | 919 | __u8 xe_type; /* the low 7 bits indicate the name prefix |
| 920 | * type and the highest bit indicates whether |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 921 | * the EA is stored in the local storage. */ |
| 922 | __le64 xe_value_size; /* real xattr value length. */ |
| 923 | }; |
| 924 | |
| 925 | /* |
| 926 | * On disk structure for xattr header. |
| 927 | * |
| 928 | * One ocfs2_xattr_header describes how many ocfs2_xattr_entry records in |
| 929 | * the local xattr storage. |
| 930 | */ |
| 931 | struct ocfs2_xattr_header { |
| 932 | __le16 xh_count; /* contains the count of how |
| 933 | many records are in the |
| 934 | local xattr storage. */ |
Tao Ma | 0c044f0 | 2008-08-18 17:38:50 +0800 | [diff] [blame] | 935 | __le16 xh_free_start; /* current offset for storing |
| 936 | xattr. */ |
| 937 | __le16 xh_name_value_len; /* total length of name/value |
| 938 | length in this bucket. */ |
Tao Ma | 8573f79 | 2008-10-24 22:24:17 +0800 | [diff] [blame] | 939 | __le16 xh_num_buckets; /* Number of xattr buckets |
| 940 | in this extent record, |
| 941 | only valid in the first |
| 942 | bucket. */ |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 943 | struct ocfs2_block_check xh_check; /* Error checking |
| 944 | (Note, this is only |
| 945 | used for xattr |
| 946 | buckets. A block uses |
| 947 | xb_check and sets |
| 948 | this field to zero.) */ |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 949 | struct ocfs2_xattr_entry xh_entries[0]; /* xattr entry list. */ |
| 950 | }; |
| 951 | |
| 952 | /* |
| 953 | * On disk structure for xattr value root. |
| 954 | * |
Tao Ma | 8573f79 | 2008-10-24 22:24:17 +0800 | [diff] [blame] | 955 | * When an xattr's value is large enough, it is stored in an external |
| 956 | * 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] | 957 | */ |
| 958 | struct ocfs2_xattr_value_root { |
| 959 | /*00*/ __le32 xr_clusters; /* clusters covered by xattr value. */ |
| 960 | __le32 xr_reserved0; |
| 961 | __le64 xr_last_eb_blk; /* Pointer to last extent block */ |
| 962 | /*10*/ struct ocfs2_extent_list xr_list; /* Extent record list */ |
| 963 | }; |
| 964 | |
| 965 | /* |
| 966 | * On disk structure for xattr tree root. |
| 967 | * |
| 968 | * It is used when there are too many extended attributes for one file. These |
| 969 | * attributes will be organized and stored in an indexed-btree. |
| 970 | */ |
| 971 | struct ocfs2_xattr_tree_root { |
| 972 | /*00*/ __le32 xt_clusters; /* clusters covered by xattr. */ |
| 973 | __le32 xt_reserved0; |
| 974 | __le64 xt_last_eb_blk; /* Pointer to last extent block */ |
| 975 | /*10*/ struct ocfs2_extent_list xt_list; /* Extent record list */ |
| 976 | }; |
| 977 | |
Tiger Yang | cf1d6c7 | 2008-08-18 17:11:00 +0800 | [diff] [blame] | 978 | #define OCFS2_XATTR_INDEXED 0x1 |
| 979 | #define OCFS2_HASH_SHIFT 5 |
| 980 | #define OCFS2_XATTR_ROUND 3 |
| 981 | #define OCFS2_XATTR_SIZE(size) (((size) + OCFS2_XATTR_ROUND) & \ |
| 982 | ~(OCFS2_XATTR_ROUND)) |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 983 | |
Tao Ma | 0c044f0 | 2008-08-18 17:38:50 +0800 | [diff] [blame] | 984 | #define OCFS2_XATTR_BUCKET_SIZE 4096 |
| 985 | #define OCFS2_XATTR_MAX_BLOCKS_PER_BUCKET (OCFS2_XATTR_BUCKET_SIZE \ |
| 986 | / OCFS2_MIN_BLOCKSIZE) |
| 987 | |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 988 | /* |
| 989 | * On disk structure for xattr block. |
| 990 | */ |
| 991 | struct ocfs2_xattr_block { |
| 992 | /*00*/ __u8 xb_signature[8]; /* Signature for verification */ |
| 993 | __le16 xb_suballoc_slot; /* Slot suballocator this |
| 994 | block belongs to. */ |
| 995 | __le16 xb_suballoc_bit; /* Bit offset in suballocator |
| 996 | block group */ |
| 997 | __le32 xb_fs_generation; /* Must match super block */ |
| 998 | /*10*/ __le64 xb_blkno; /* Offset on disk, in blocks */ |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 999 | struct ocfs2_block_check xb_check; /* Error checking */ |
Tao Ma | 5a7bc8e | 2008-08-18 17:38:46 +0800 | [diff] [blame] | 1000 | /*20*/ __le16 xb_flags; /* Indicates whether this block contains |
| 1001 | real xattr or a xattr tree. */ |
| 1002 | __le16 xb_reserved0; |
| 1003 | __le32 xb_reserved1; |
| 1004 | __le64 xb_reserved2; |
| 1005 | /*30*/ union { |
| 1006 | struct ocfs2_xattr_header xb_header; /* xattr header if this |
| 1007 | block contains xattr */ |
| 1008 | struct ocfs2_xattr_tree_root xb_root;/* xattr tree root if this |
| 1009 | block cotains xattr |
| 1010 | tree. */ |
| 1011 | } xb_attrs; |
| 1012 | }; |
| 1013 | |
| 1014 | #define OCFS2_XATTR_ENTRY_LOCAL 0x80 |
| 1015 | #define OCFS2_XATTR_TYPE_MASK 0x7F |
| 1016 | static inline void ocfs2_xattr_set_local(struct ocfs2_xattr_entry *xe, |
| 1017 | int local) |
| 1018 | { |
| 1019 | if (local) |
| 1020 | xe->xe_type |= OCFS2_XATTR_ENTRY_LOCAL; |
| 1021 | else |
| 1022 | xe->xe_type &= ~OCFS2_XATTR_ENTRY_LOCAL; |
| 1023 | } |
| 1024 | |
| 1025 | static inline int ocfs2_xattr_is_local(struct ocfs2_xattr_entry *xe) |
| 1026 | { |
| 1027 | return xe->xe_type & OCFS2_XATTR_ENTRY_LOCAL; |
| 1028 | } |
| 1029 | |
| 1030 | static inline void ocfs2_xattr_set_type(struct ocfs2_xattr_entry *xe, int type) |
| 1031 | { |
| 1032 | xe->xe_type |= type & OCFS2_XATTR_TYPE_MASK; |
| 1033 | } |
| 1034 | |
| 1035 | static inline int ocfs2_xattr_get_type(struct ocfs2_xattr_entry *xe) |
| 1036 | { |
| 1037 | return xe->xe_type & OCFS2_XATTR_TYPE_MASK; |
| 1038 | } |
| 1039 | |
Jan Kara | 9e33d69 | 2008-08-25 19:56:50 +0200 | [diff] [blame] | 1040 | /* |
| 1041 | * On disk structures for global quota file |
| 1042 | */ |
| 1043 | |
| 1044 | /* Magic numbers and known versions for global quota files */ |
| 1045 | #define OCFS2_GLOBAL_QMAGICS {\ |
| 1046 | 0x0cf52470, /* USRQUOTA */ \ |
| 1047 | 0x0cf52471 /* GRPQUOTA */ \ |
| 1048 | } |
| 1049 | |
| 1050 | #define OCFS2_GLOBAL_QVERSIONS {\ |
| 1051 | 0, \ |
| 1052 | 0, \ |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | /* Each block of each quota file has a certain fixed number of bytes reserved |
| 1057 | * for OCFS2 internal use at its end. OCFS2 can use it for things like |
| 1058 | * checksums, etc. */ |
| 1059 | #define OCFS2_QBLK_RESERVED_SPACE 8 |
| 1060 | |
| 1061 | /* Generic header of all quota files */ |
| 1062 | struct ocfs2_disk_dqheader { |
| 1063 | __le32 dqh_magic; /* Magic number identifying file */ |
| 1064 | __le32 dqh_version; /* Quota format version */ |
| 1065 | }; |
| 1066 | |
| 1067 | #define OCFS2_GLOBAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader)) |
| 1068 | |
| 1069 | /* Information header of global quota file (immediately follows the generic |
| 1070 | * header) */ |
| 1071 | struct ocfs2_global_disk_dqinfo { |
| 1072 | /*00*/ __le32 dqi_bgrace; /* Grace time for space softlimit excess */ |
| 1073 | __le32 dqi_igrace; /* Grace time for inode softlimit excess */ |
| 1074 | __le32 dqi_syncms; /* Time after which we sync local changes to |
| 1075 | * global quota file */ |
| 1076 | __le32 dqi_blocks; /* Number of blocks in quota file */ |
| 1077 | /*10*/ __le32 dqi_free_blk; /* First free block in quota file */ |
| 1078 | __le32 dqi_free_entry; /* First block with free dquot entry in quota |
| 1079 | * file */ |
| 1080 | }; |
| 1081 | |
| 1082 | /* Structure with global user / group information. We reserve some space |
| 1083 | * for future use. */ |
| 1084 | struct ocfs2_global_disk_dqblk { |
| 1085 | /*00*/ __le32 dqb_id; /* ID the structure belongs to */ |
| 1086 | __le32 dqb_use_count; /* Number of nodes having reference to this structure */ |
| 1087 | __le64 dqb_ihardlimit; /* absolute limit on allocated inodes */ |
| 1088 | /*10*/ __le64 dqb_isoftlimit; /* preferred inode limit */ |
| 1089 | __le64 dqb_curinodes; /* current # allocated inodes */ |
| 1090 | /*20*/ __le64 dqb_bhardlimit; /* absolute limit on disk space */ |
| 1091 | __le64 dqb_bsoftlimit; /* preferred limit on disk space */ |
| 1092 | /*30*/ __le64 dqb_curspace; /* current space occupied */ |
| 1093 | __le64 dqb_btime; /* time limit for excessive disk use */ |
| 1094 | /*40*/ __le64 dqb_itime; /* time limit for excessive inode use */ |
| 1095 | __le64 dqb_pad1; |
| 1096 | /*50*/ __le64 dqb_pad2; |
| 1097 | }; |
| 1098 | |
| 1099 | /* |
| 1100 | * On-disk structures for local quota file |
| 1101 | */ |
| 1102 | |
| 1103 | /* Magic numbers and known versions for local quota files */ |
| 1104 | #define OCFS2_LOCAL_QMAGICS {\ |
| 1105 | 0x0cf524c0, /* USRQUOTA */ \ |
| 1106 | 0x0cf524c1 /* GRPQUOTA */ \ |
| 1107 | } |
| 1108 | |
| 1109 | #define OCFS2_LOCAL_QVERSIONS {\ |
| 1110 | 0, \ |
| 1111 | 0, \ |
| 1112 | } |
| 1113 | |
| 1114 | /* Quota flags in dqinfo header */ |
| 1115 | #define OLQF_CLEAN 0x0001 /* Quota file is empty (this should be after\ |
| 1116 | * quota has been cleanly turned off) */ |
| 1117 | |
| 1118 | #define OCFS2_LOCAL_INFO_OFF (sizeof(struct ocfs2_disk_dqheader)) |
| 1119 | |
| 1120 | /* Information header of local quota file (immediately follows the generic |
| 1121 | * header) */ |
| 1122 | struct ocfs2_local_disk_dqinfo { |
| 1123 | __le32 dqi_flags; /* Flags for quota file */ |
| 1124 | __le32 dqi_chunks; /* Number of chunks of quota structures |
| 1125 | * with a bitmap */ |
| 1126 | __le32 dqi_blocks; /* Number of blocks allocated for quota file */ |
| 1127 | }; |
| 1128 | |
| 1129 | /* Header of one chunk of a quota file */ |
| 1130 | struct ocfs2_local_disk_chunk { |
| 1131 | __le32 dqc_free; /* Number of free entries in the bitmap */ |
| 1132 | u8 dqc_bitmap[0]; /* Bitmap of entries in the corresponding |
| 1133 | * chunk of quota file */ |
| 1134 | }; |
| 1135 | |
| 1136 | /* One entry in local quota file */ |
| 1137 | struct ocfs2_local_disk_dqblk { |
| 1138 | /*00*/ __le64 dqb_id; /* id this quota applies to */ |
| 1139 | __le64 dqb_spacemod; /* Change in the amount of used space */ |
| 1140 | /*10*/ __le64 dqb_inodemod; /* Change in the amount of used inodes */ |
| 1141 | }; |
| 1142 | |
Joel Becker | ab552d5 | 2008-10-16 17:50:30 -0700 | [diff] [blame] | 1143 | |
| 1144 | /* |
| 1145 | * The quota trailer lives at the end of each quota block. |
| 1146 | */ |
| 1147 | |
| 1148 | struct ocfs2_disk_dqtrailer { |
| 1149 | /*00*/ struct ocfs2_block_check dq_check; /* Error checking */ |
| 1150 | /*08*/ /* Cannot be larger than OCFS2_QBLK_RESERVED_SPACE */ |
| 1151 | }; |
| 1152 | |
| 1153 | static inline struct ocfs2_disk_dqtrailer *ocfs2_block_dqtrailer(int blocksize, |
| 1154 | void *buf) |
| 1155 | { |
| 1156 | char *ptr = buf; |
| 1157 | ptr += blocksize - OCFS2_QBLK_RESERVED_SPACE; |
| 1158 | |
| 1159 | return (struct ocfs2_disk_dqtrailer *)ptr; |
| 1160 | } |
| 1161 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1162 | #ifdef __KERNEL__ |
| 1163 | static inline int ocfs2_fast_symlink_chars(struct super_block *sb) |
| 1164 | { |
| 1165 | return sb->s_blocksize - |
| 1166 | offsetof(struct ocfs2_dinode, id2.i_symlink); |
| 1167 | } |
| 1168 | |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 1169 | static inline int ocfs2_max_inline_data_with_xattr(struct super_block *sb, |
| 1170 | struct ocfs2_dinode *di) |
| 1171 | { |
| 1172 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); |
| 1173 | |
| 1174 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) |
| 1175 | return sb->s_blocksize - |
| 1176 | offsetof(struct ocfs2_dinode, id2.i_data.id_data) - |
| 1177 | xattrsize; |
| 1178 | else |
| 1179 | return sb->s_blocksize - |
| 1180 | offsetof(struct ocfs2_dinode, id2.i_data.id_data); |
| 1181 | } |
| 1182 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1183 | static inline int ocfs2_extent_recs_per_inode(struct super_block *sb) |
| 1184 | { |
| 1185 | int size; |
| 1186 | |
| 1187 | size = sb->s_blocksize - |
| 1188 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); |
| 1189 | |
| 1190 | return size / sizeof(struct ocfs2_extent_rec); |
| 1191 | } |
| 1192 | |
Tiger Yang | fdd7770 | 2008-08-18 17:08:55 +0800 | [diff] [blame] | 1193 | static inline int ocfs2_extent_recs_per_inode_with_xattr( |
| 1194 | struct super_block *sb, |
| 1195 | struct ocfs2_dinode *di) |
| 1196 | { |
| 1197 | int size; |
| 1198 | unsigned int xattrsize = le16_to_cpu(di->i_xattr_inline_size); |
| 1199 | |
| 1200 | if (le16_to_cpu(di->i_dyn_features) & OCFS2_INLINE_XATTR_FL) |
| 1201 | size = sb->s_blocksize - |
| 1202 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs) - |
| 1203 | xattrsize; |
| 1204 | else |
| 1205 | size = sb->s_blocksize - |
| 1206 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); |
| 1207 | |
| 1208 | return size / sizeof(struct ocfs2_extent_rec); |
| 1209 | } |
| 1210 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 1211 | static inline int ocfs2_extent_recs_per_dx_root(struct super_block *sb) |
| 1212 | { |
| 1213 | int size; |
| 1214 | |
| 1215 | size = sb->s_blocksize - |
| 1216 | offsetof(struct ocfs2_dx_root_block, dr_list.l_recs); |
| 1217 | |
| 1218 | return size / sizeof(struct ocfs2_extent_rec); |
| 1219 | } |
| 1220 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1221 | static inline int ocfs2_chain_recs_per_inode(struct super_block *sb) |
| 1222 | { |
| 1223 | int size; |
| 1224 | |
| 1225 | size = sb->s_blocksize - |
| 1226 | offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); |
| 1227 | |
| 1228 | return size / sizeof(struct ocfs2_chain_rec); |
| 1229 | } |
| 1230 | |
| 1231 | static inline u16 ocfs2_extent_recs_per_eb(struct super_block *sb) |
| 1232 | { |
| 1233 | int size; |
| 1234 | |
| 1235 | size = sb->s_blocksize - |
| 1236 | offsetof(struct ocfs2_extent_block, h_list.l_recs); |
| 1237 | |
| 1238 | return size / sizeof(struct ocfs2_extent_rec); |
| 1239 | } |
| 1240 | |
Mark Fasheh | 9b7895e | 2008-11-12 16:27:44 -0800 | [diff] [blame] | 1241 | static inline int ocfs2_dx_entries_per_leaf(struct super_block *sb) |
| 1242 | { |
| 1243 | int size; |
| 1244 | |
| 1245 | size = sb->s_blocksize - |
| 1246 | offsetof(struct ocfs2_dx_leaf, dl_list.de_entries); |
| 1247 | |
| 1248 | return size / sizeof(struct ocfs2_dx_entry); |
| 1249 | } |
| 1250 | |
Mark Fasheh | 4ed8a6b | 2008-11-24 17:02:08 -0800 | [diff] [blame] | 1251 | static inline int ocfs2_dx_entries_per_root(struct super_block *sb) |
| 1252 | { |
| 1253 | int size; |
| 1254 | |
| 1255 | size = sb->s_blocksize - |
| 1256 | offsetof(struct ocfs2_dx_root_block, dr_entries.de_entries); |
| 1257 | |
| 1258 | return size / sizeof(struct ocfs2_dx_entry); |
| 1259 | } |
| 1260 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1261 | static inline u16 ocfs2_local_alloc_size(struct super_block *sb) |
| 1262 | { |
| 1263 | u16 size; |
| 1264 | |
| 1265 | size = sb->s_blocksize - |
| 1266 | offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); |
| 1267 | |
| 1268 | return size; |
| 1269 | } |
| 1270 | |
| 1271 | static inline int ocfs2_group_bitmap_size(struct super_block *sb) |
| 1272 | { |
| 1273 | int size; |
| 1274 | |
| 1275 | size = sb->s_blocksize - |
| 1276 | offsetof(struct ocfs2_group_desc, bg_bitmap); |
| 1277 | |
| 1278 | return size; |
| 1279 | } |
| 1280 | |
| 1281 | static inline int ocfs2_truncate_recs_per_inode(struct super_block *sb) |
| 1282 | { |
| 1283 | int size; |
| 1284 | |
| 1285 | size = sb->s_blocksize - |
| 1286 | offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); |
| 1287 | |
| 1288 | return size / sizeof(struct ocfs2_truncate_rec); |
| 1289 | } |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 1290 | |
| 1291 | static inline u64 ocfs2_backup_super_blkno(struct super_block *sb, int index) |
| 1292 | { |
| 1293 | u64 offset = OCFS2_BACKUP_SB_START; |
| 1294 | |
| 1295 | if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { |
| 1296 | offset <<= (2 * index); |
Mark Fasheh | a8a75a2 | 2007-01-26 10:46:59 -0800 | [diff] [blame] | 1297 | offset >>= sb->s_blocksize_bits; |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 1298 | return offset; |
| 1299 | } |
| 1300 | |
| 1301 | return 0; |
| 1302 | |
| 1303 | } |
Tao Ma | 0c044f0 | 2008-08-18 17:38:50 +0800 | [diff] [blame] | 1304 | |
| 1305 | static inline u16 ocfs2_xattr_recs_per_xb(struct super_block *sb) |
| 1306 | { |
| 1307 | int size; |
| 1308 | |
| 1309 | size = sb->s_blocksize - |
| 1310 | offsetof(struct ocfs2_xattr_block, |
| 1311 | xb_attrs.xb_root.xt_list.l_recs); |
| 1312 | |
| 1313 | return size / sizeof(struct ocfs2_extent_rec); |
| 1314 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1315 | #else |
| 1316 | static inline int ocfs2_fast_symlink_chars(int blocksize) |
| 1317 | { |
| 1318 | return blocksize - offsetof(struct ocfs2_dinode, id2.i_symlink); |
| 1319 | } |
| 1320 | |
Mark Fasheh | 15b1e36 | 2007-09-07 13:58:15 -0700 | [diff] [blame] | 1321 | static inline int ocfs2_max_inline_data(int blocksize) |
| 1322 | { |
| 1323 | return blocksize - offsetof(struct ocfs2_dinode, id2.i_data.id_data); |
| 1324 | } |
| 1325 | |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1326 | static inline int ocfs2_extent_recs_per_inode(int blocksize) |
| 1327 | { |
| 1328 | int size; |
| 1329 | |
| 1330 | size = blocksize - |
| 1331 | offsetof(struct ocfs2_dinode, id2.i_list.l_recs); |
| 1332 | |
| 1333 | return size / sizeof(struct ocfs2_extent_rec); |
| 1334 | } |
| 1335 | |
| 1336 | static inline int ocfs2_chain_recs_per_inode(int blocksize) |
| 1337 | { |
| 1338 | int size; |
| 1339 | |
| 1340 | size = blocksize - |
| 1341 | offsetof(struct ocfs2_dinode, id2.i_chain.cl_recs); |
| 1342 | |
| 1343 | return size / sizeof(struct ocfs2_chain_rec); |
| 1344 | } |
| 1345 | |
| 1346 | static inline int ocfs2_extent_recs_per_eb(int blocksize) |
| 1347 | { |
| 1348 | int size; |
| 1349 | |
| 1350 | size = blocksize - |
| 1351 | offsetof(struct ocfs2_extent_block, h_list.l_recs); |
| 1352 | |
| 1353 | return size / sizeof(struct ocfs2_extent_rec); |
| 1354 | } |
| 1355 | |
| 1356 | static inline int ocfs2_local_alloc_size(int blocksize) |
| 1357 | { |
| 1358 | int size; |
| 1359 | |
| 1360 | size = blocksize - |
| 1361 | offsetof(struct ocfs2_dinode, id2.i_lab.la_bitmap); |
| 1362 | |
| 1363 | return size; |
| 1364 | } |
| 1365 | |
| 1366 | static inline int ocfs2_group_bitmap_size(int blocksize) |
| 1367 | { |
| 1368 | int size; |
| 1369 | |
| 1370 | size = blocksize - |
| 1371 | offsetof(struct ocfs2_group_desc, bg_bitmap); |
| 1372 | |
| 1373 | return size; |
| 1374 | } |
| 1375 | |
| 1376 | static inline int ocfs2_truncate_recs_per_inode(int blocksize) |
| 1377 | { |
| 1378 | int size; |
| 1379 | |
| 1380 | size = blocksize - |
| 1381 | offsetof(struct ocfs2_dinode, id2.i_dealloc.tl_recs); |
| 1382 | |
| 1383 | return size / sizeof(struct ocfs2_truncate_rec); |
| 1384 | } |
Mark Fasheh | 50af94b | 2007-01-21 14:44:59 -0800 | [diff] [blame] | 1385 | |
| 1386 | static inline uint64_t ocfs2_backup_super_blkno(int blocksize, int index) |
| 1387 | { |
| 1388 | uint64_t offset = OCFS2_BACKUP_SB_START; |
| 1389 | |
| 1390 | if (index >= 0 && index < OCFS2_MAX_BACKUP_SUPERBLOCKS) { |
| 1391 | offset <<= (2 * index); |
| 1392 | offset /= blocksize; |
| 1393 | return offset; |
| 1394 | } |
| 1395 | |
| 1396 | return 0; |
| 1397 | } |
Tao Ma | 0c044f0 | 2008-08-18 17:38:50 +0800 | [diff] [blame] | 1398 | |
| 1399 | static inline int ocfs2_xattr_recs_per_xb(int blocksize) |
| 1400 | { |
| 1401 | int size; |
| 1402 | |
| 1403 | size = blocksize - |
| 1404 | offsetof(struct ocfs2_xattr_block, |
| 1405 | xb_attrs.xb_root.xt_list.l_recs); |
| 1406 | |
| 1407 | return size / sizeof(struct ocfs2_extent_rec); |
| 1408 | } |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1409 | #endif /* __KERNEL__ */ |
| 1410 | |
| 1411 | |
| 1412 | static inline int ocfs2_system_inode_is_global(int type) |
| 1413 | { |
| 1414 | return ((type >= 0) && |
| 1415 | (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE)); |
| 1416 | } |
| 1417 | |
| 1418 | static inline int ocfs2_sprintf_system_inode_name(char *buf, int len, |
| 1419 | int type, int slot) |
| 1420 | { |
| 1421 | int chars; |
| 1422 | |
| 1423 | /* |
| 1424 | * Global system inodes can only have one copy. Everything |
| 1425 | * after OCFS2_LAST_GLOBAL_SYSTEM_INODE in the system inode |
| 1426 | * list has a copy per slot. |
| 1427 | */ |
| 1428 | if (type <= OCFS2_LAST_GLOBAL_SYSTEM_INODE) |
Joel Becker | fe9f387 | 2008-06-12 22:39:18 -0700 | [diff] [blame] | 1429 | chars = snprintf(buf, len, "%s", |
Mark Fasheh | ccd979b | 2005-12-15 14:31:24 -0800 | [diff] [blame] | 1430 | ocfs2_system_inodes[type].si_name); |
| 1431 | else |
| 1432 | chars = snprintf(buf, len, |
| 1433 | ocfs2_system_inodes[type].si_name, |
| 1434 | slot); |
| 1435 | |
| 1436 | return chars; |
| 1437 | } |
| 1438 | |
| 1439 | static inline void ocfs2_set_de_type(struct ocfs2_dir_entry *de, |
| 1440 | umode_t mode) |
| 1441 | { |
| 1442 | de->file_type = ocfs2_type_by_mode[(mode & S_IFMT)>>S_SHIFT]; |
| 1443 | } |
| 1444 | |
| 1445 | #endif /* _OCFS2_FS_H */ |
| 1446 | |