Dave Chinner | 6ca1c90 | 2013-08-12 20:49:26 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write the Free Software Foundation, |
| 16 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 17 | */ |
| 18 | #ifndef __XFS_FORMAT_H__ |
| 19 | #define __XFS_FORMAT_H__ |
| 20 | |
| 21 | /* |
| 22 | * XFS On Disk Format Definitions |
| 23 | * |
| 24 | * This header file defines all the on-disk format definitions for |
| 25 | * general XFS objects. Directory and attribute related objects are defined in |
| 26 | * xfs_da_format.h, which log and log item formats are defined in |
| 27 | * xfs_log_format.h. Everything else goes here. |
| 28 | */ |
| 29 | |
Dave Chinner | 1fb7e48d | 2013-08-12 20:49:40 +1000 | [diff] [blame] | 30 | struct xfs_mount; |
| 31 | struct xfs_trans; |
| 32 | struct xfs_inode; |
| 33 | struct xfs_buf; |
| 34 | struct xfs_ifork; |
| 35 | |
Christoph Hellwig | 6d3ebaa | 2014-11-28 14:24:06 +1100 | [diff] [blame^] | 36 | typedef struct xfs_timestamp { |
| 37 | __be32 t_sec; /* timestamp seconds */ |
| 38 | __be32 t_nsec; /* timestamp nanoseconds */ |
| 39 | } xfs_timestamp_t; |
| 40 | |
| 41 | /* |
| 42 | * On-disk inode structure. |
| 43 | * |
| 44 | * This is just the header or "dinode core", the inode is expanded to fill a |
| 45 | * variable size the leftover area split into a data and an attribute fork. |
| 46 | * The format of the data and attribute fork depends on the format of the |
| 47 | * inode as indicated by di_format and di_aformat. To access the data and |
| 48 | * attribute use the XFS_DFORK_DPTR, XFS_DFORK_APTR, and XFS_DFORK_PTR macros |
| 49 | * below. |
| 50 | * |
| 51 | * There is a very similar struct icdinode in xfs_inode which matches the |
| 52 | * layout of the first 96 bytes of this structure, but is kept in native |
| 53 | * format instead of big endian. |
| 54 | * |
| 55 | * Note: di_flushiter is only used by v1/2 inodes - it's effectively a zeroed |
| 56 | * padding field for v3 inodes. |
| 57 | */ |
| 58 | #define XFS_DINODE_MAGIC 0x494e /* 'IN' */ |
| 59 | #define XFS_DINODE_GOOD_VERSION(v) ((v) >= 1 && (v) <= 3) |
| 60 | typedef struct xfs_dinode { |
| 61 | __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */ |
| 62 | __be16 di_mode; /* mode and type of file */ |
| 63 | __u8 di_version; /* inode version */ |
| 64 | __u8 di_format; /* format of di_c data */ |
| 65 | __be16 di_onlink; /* old number of links to file */ |
| 66 | __be32 di_uid; /* owner's user id */ |
| 67 | __be32 di_gid; /* owner's group id */ |
| 68 | __be32 di_nlink; /* number of links to file */ |
| 69 | __be16 di_projid_lo; /* lower part of owner's project id */ |
| 70 | __be16 di_projid_hi; /* higher part owner's project id */ |
| 71 | __u8 di_pad[6]; /* unused, zeroed space */ |
| 72 | __be16 di_flushiter; /* incremented on flush */ |
| 73 | xfs_timestamp_t di_atime; /* time last accessed */ |
| 74 | xfs_timestamp_t di_mtime; /* time last modified */ |
| 75 | xfs_timestamp_t di_ctime; /* time created/inode modified */ |
| 76 | __be64 di_size; /* number of bytes in file */ |
| 77 | __be64 di_nblocks; /* # of direct & btree blocks used */ |
| 78 | __be32 di_extsize; /* basic/minimum extent size for file */ |
| 79 | __be32 di_nextents; /* number of extents in data fork */ |
| 80 | __be16 di_anextents; /* number of extents in attribute fork*/ |
| 81 | __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */ |
| 82 | __s8 di_aformat; /* format of attr fork's data */ |
| 83 | __be32 di_dmevmask; /* DMIG event mask */ |
| 84 | __be16 di_dmstate; /* DMIG state info */ |
| 85 | __be16 di_flags; /* random flags, XFS_DIFLAG_... */ |
| 86 | __be32 di_gen; /* generation number */ |
| 87 | |
| 88 | /* di_next_unlinked is the only non-core field in the old dinode */ |
| 89 | __be32 di_next_unlinked;/* agi unlinked list ptr */ |
| 90 | |
| 91 | /* start of the extended dinode, writable fields */ |
| 92 | __le32 di_crc; /* CRC of the inode */ |
| 93 | __be64 di_changecount; /* number of attribute changes */ |
| 94 | __be64 di_lsn; /* flush sequence */ |
| 95 | __be64 di_flags2; /* more random flags */ |
| 96 | __u8 di_pad2[16]; /* more padding for future expansion */ |
| 97 | |
| 98 | /* fields only written to during inode creation */ |
| 99 | xfs_timestamp_t di_crtime; /* time created */ |
| 100 | __be64 di_ino; /* inode number */ |
| 101 | uuid_t di_uuid; /* UUID of the filesystem */ |
| 102 | |
| 103 | /* structure must be padded to 64 bit alignment */ |
| 104 | } xfs_dinode_t; |
| 105 | |
| 106 | #define XFS_DINODE_CRC_OFF offsetof(struct xfs_dinode, di_crc) |
| 107 | |
| 108 | #define DI_MAX_FLUSH 0xffff |
| 109 | |
| 110 | /* |
| 111 | * Size of the core inode on disk. Version 1 and 2 inodes have |
| 112 | * the same size, but version 3 has grown a few additional fields. |
| 113 | */ |
| 114 | static inline uint xfs_dinode_size(int version) |
| 115 | { |
| 116 | if (version == 3) |
| 117 | return sizeof(struct xfs_dinode); |
| 118 | return offsetof(struct xfs_dinode, di_crc); |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * The 32 bit link count in the inode theoretically maxes out at UINT_MAX. |
| 123 | * Since the pathconf interface is signed, we use 2^31 - 1 instead. |
| 124 | * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX. |
| 125 | */ |
| 126 | #define XFS_MAXLINK ((1U << 31) - 1U) |
| 127 | #define XFS_MAXLINK_1 65535U |
| 128 | |
| 129 | /* |
| 130 | * Values for di_format |
| 131 | */ |
| 132 | typedef enum xfs_dinode_fmt { |
| 133 | XFS_DINODE_FMT_DEV, /* xfs_dev_t */ |
| 134 | XFS_DINODE_FMT_LOCAL, /* bulk data */ |
| 135 | XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */ |
| 136 | XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */ |
| 137 | XFS_DINODE_FMT_UUID /* uuid_t */ |
| 138 | } xfs_dinode_fmt_t; |
| 139 | |
| 140 | /* |
| 141 | * Inode minimum and maximum sizes. |
| 142 | */ |
| 143 | #define XFS_DINODE_MIN_LOG 8 |
| 144 | #define XFS_DINODE_MAX_LOG 11 |
| 145 | #define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG) |
| 146 | #define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG) |
| 147 | |
| 148 | /* |
| 149 | * Inode size for given fs. |
| 150 | */ |
| 151 | #define XFS_LITINO(mp, version) \ |
| 152 | ((int)(((mp)->m_sb.sb_inodesize) - xfs_dinode_size(version))) |
| 153 | |
| 154 | /* |
| 155 | * Inode data & attribute fork sizes, per inode. |
| 156 | */ |
| 157 | #define XFS_DFORK_Q(dip) ((dip)->di_forkoff != 0) |
| 158 | #define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3)) |
| 159 | |
| 160 | #define XFS_DFORK_DSIZE(dip,mp) \ |
| 161 | (XFS_DFORK_Q(dip) ? \ |
| 162 | XFS_DFORK_BOFF(dip) : \ |
| 163 | XFS_LITINO(mp, (dip)->di_version)) |
| 164 | #define XFS_DFORK_ASIZE(dip,mp) \ |
| 165 | (XFS_DFORK_Q(dip) ? \ |
| 166 | XFS_LITINO(mp, (dip)->di_version) - XFS_DFORK_BOFF(dip) : \ |
| 167 | 0) |
| 168 | #define XFS_DFORK_SIZE(dip,mp,w) \ |
| 169 | ((w) == XFS_DATA_FORK ? \ |
| 170 | XFS_DFORK_DSIZE(dip, mp) : \ |
| 171 | XFS_DFORK_ASIZE(dip, mp)) |
| 172 | |
| 173 | /* |
| 174 | * Return pointers to the data or attribute forks. |
| 175 | */ |
| 176 | #define XFS_DFORK_DPTR(dip) \ |
| 177 | ((char *)dip + xfs_dinode_size(dip->di_version)) |
| 178 | #define XFS_DFORK_APTR(dip) \ |
| 179 | (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip)) |
| 180 | #define XFS_DFORK_PTR(dip,w) \ |
| 181 | ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip)) |
| 182 | |
| 183 | #define XFS_DFORK_FORMAT(dip,w) \ |
| 184 | ((w) == XFS_DATA_FORK ? \ |
| 185 | (dip)->di_format : \ |
| 186 | (dip)->di_aformat) |
| 187 | #define XFS_DFORK_NEXTENTS(dip,w) \ |
| 188 | ((w) == XFS_DATA_FORK ? \ |
| 189 | be32_to_cpu((dip)->di_nextents) : \ |
| 190 | be16_to_cpu((dip)->di_anextents)) |
| 191 | |
| 192 | /* |
| 193 | * For block and character special files the 32bit dev_t is stored at the |
| 194 | * beginning of the data fork. |
| 195 | */ |
| 196 | static inline xfs_dev_t xfs_dinode_get_rdev(struct xfs_dinode *dip) |
| 197 | { |
| 198 | return be32_to_cpu(*(__be32 *)XFS_DFORK_DPTR(dip)); |
| 199 | } |
| 200 | |
| 201 | static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) |
| 202 | { |
| 203 | *(__be32 *)XFS_DFORK_DPTR(dip) = cpu_to_be32(rdev); |
| 204 | } |
| 205 | |
| 206 | /* |
| 207 | * Values for di_flags |
| 208 | * There should be a one-to-one correspondence between these flags and the |
| 209 | * XFS_XFLAG_s. |
| 210 | */ |
| 211 | #define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */ |
| 212 | #define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */ |
| 213 | #define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */ |
| 214 | #define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */ |
| 215 | #define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */ |
| 216 | #define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */ |
| 217 | #define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */ |
| 218 | #define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */ |
| 219 | #define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */ |
| 220 | #define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */ |
| 221 | #define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */ |
| 222 | #define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */ |
| 223 | #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */ |
| 224 | #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */ |
| 225 | #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */ |
| 226 | #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT) |
| 227 | #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT) |
| 228 | #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT) |
| 229 | #define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT) |
| 230 | #define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT) |
| 231 | #define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT) |
| 232 | #define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT) |
| 233 | #define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT) |
| 234 | #define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT) |
| 235 | #define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT) |
| 236 | #define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT) |
| 237 | #define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT) |
| 238 | #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT) |
| 239 | #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT) |
| 240 | #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT) |
| 241 | |
| 242 | #define XFS_DIFLAG_ANY \ |
| 243 | (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \ |
| 244 | XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \ |
| 245 | XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \ |
| 246 | XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \ |
| 247 | XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM) |
| 248 | |
| 249 | |
Dave Chinner | 6ca1c90 | 2013-08-12 20:49:26 +1000 | [diff] [blame] | 250 | /* |
Dave Chinner | c729820 | 2013-08-12 20:49:29 +1000 | [diff] [blame] | 251 | * RealTime Device format definitions |
| 252 | */ |
| 253 | |
| 254 | /* Min and max rt extent sizes, specified in bytes */ |
| 255 | #define XFS_MAX_RTEXTSIZE (1024 * 1024 * 1024) /* 1GB */ |
| 256 | #define XFS_DFL_RTEXTSIZE (64 * 1024) /* 64kB */ |
| 257 | #define XFS_MIN_RTEXTSIZE (4 * 1024) /* 4kB */ |
| 258 | |
| 259 | #define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize) |
| 260 | #define XFS_BLOCKMASK(mp) ((mp)->m_blockmask) |
| 261 | #define XFS_BLOCKWSIZE(mp) ((mp)->m_blockwsize) |
| 262 | #define XFS_BLOCKWMASK(mp) ((mp)->m_blockwmask) |
| 263 | |
| 264 | /* |
| 265 | * RT Summary and bit manipulation macros. |
| 266 | */ |
| 267 | #define XFS_SUMOFFS(mp,ls,bb) ((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb))) |
| 268 | #define XFS_SUMOFFSTOBLOCK(mp,s) \ |
| 269 | (((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog) |
| 270 | #define XFS_SUMPTR(mp,bp,so) \ |
| 271 | ((xfs_suminfo_t *)((bp)->b_addr + \ |
| 272 | (((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp)))) |
| 273 | |
| 274 | #define XFS_BITTOBLOCK(mp,bi) ((bi) >> (mp)->m_blkbit_log) |
| 275 | #define XFS_BLOCKTOBIT(mp,bb) ((bb) << (mp)->m_blkbit_log) |
| 276 | #define XFS_BITTOWORD(mp,bi) \ |
| 277 | ((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp))) |
| 278 | |
| 279 | #define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b)) |
| 280 | #define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b)) |
| 281 | |
| 282 | #define XFS_RTLOBIT(w) xfs_lowbit32(w) |
| 283 | #define XFS_RTHIBIT(w) xfs_highbit32(w) |
| 284 | |
Dave Chinner | c729820 | 2013-08-12 20:49:29 +1000 | [diff] [blame] | 285 | #define XFS_RTBLOCKLOG(b) xfs_highbit64(b) |
Dave Chinner | c729820 | 2013-08-12 20:49:29 +1000 | [diff] [blame] | 286 | |
| 287 | /* |
Dave Chinner | 6ca1c90 | 2013-08-12 20:49:26 +1000 | [diff] [blame] | 288 | * Dquot and dquot block format definitions |
| 289 | */ |
| 290 | #define XFS_DQUOT_MAGIC 0x4451 /* 'DQ' */ |
| 291 | #define XFS_DQUOT_VERSION (u_int8_t)0x01 /* latest version number */ |
| 292 | |
| 293 | /* |
| 294 | * This is the main portion of the on-disk representation of quota |
| 295 | * information for a user. This is the q_core of the xfs_dquot_t that |
| 296 | * is kept in kernel memory. We pad this with some more expansion room |
| 297 | * to construct the on disk structure. |
| 298 | */ |
| 299 | typedef struct xfs_disk_dquot { |
| 300 | __be16 d_magic; /* dquot magic = XFS_DQUOT_MAGIC */ |
| 301 | __u8 d_version; /* dquot version */ |
| 302 | __u8 d_flags; /* XFS_DQ_USER/PROJ/GROUP */ |
| 303 | __be32 d_id; /* user,project,group id */ |
| 304 | __be64 d_blk_hardlimit;/* absolute limit on disk blks */ |
| 305 | __be64 d_blk_softlimit;/* preferred limit on disk blks */ |
| 306 | __be64 d_ino_hardlimit;/* maximum # allocated inodes */ |
| 307 | __be64 d_ino_softlimit;/* preferred inode limit */ |
| 308 | __be64 d_bcount; /* disk blocks owned by the user */ |
| 309 | __be64 d_icount; /* inodes owned by the user */ |
| 310 | __be32 d_itimer; /* zero if within inode limits if not, |
| 311 | this is when we refuse service */ |
| 312 | __be32 d_btimer; /* similar to above; for disk blocks */ |
| 313 | __be16 d_iwarns; /* warnings issued wrt num inodes */ |
| 314 | __be16 d_bwarns; /* warnings issued wrt disk blocks */ |
| 315 | __be32 d_pad0; /* 64 bit align */ |
| 316 | __be64 d_rtb_hardlimit;/* absolute limit on realtime blks */ |
| 317 | __be64 d_rtb_softlimit;/* preferred limit on RT disk blks */ |
| 318 | __be64 d_rtbcount; /* realtime blocks owned */ |
| 319 | __be32 d_rtbtimer; /* similar to above; for RT disk blocks */ |
| 320 | __be16 d_rtbwarns; /* warnings issued wrt RT disk blocks */ |
| 321 | __be16 d_pad; |
| 322 | } xfs_disk_dquot_t; |
| 323 | |
| 324 | /* |
| 325 | * This is what goes on disk. This is separated from the xfs_disk_dquot because |
| 326 | * carrying the unnecessary padding would be a waste of memory. |
| 327 | */ |
| 328 | typedef struct xfs_dqblk { |
| 329 | xfs_disk_dquot_t dd_diskdq; /* portion that lives incore as well */ |
| 330 | char dd_fill[4]; /* filling for posterity */ |
| 331 | |
| 332 | /* |
| 333 | * These two are only present on filesystems with the CRC bits set. |
| 334 | */ |
| 335 | __be32 dd_crc; /* checksum */ |
| 336 | __be64 dd_lsn; /* last modification in log */ |
| 337 | uuid_t dd_uuid; /* location information */ |
| 338 | } xfs_dqblk_t; |
| 339 | |
| 340 | #define XFS_DQUOT_CRC_OFF offsetof(struct xfs_dqblk, dd_crc) |
| 341 | |
Dave Chinner | 1fb7e48d | 2013-08-12 20:49:40 +1000 | [diff] [blame] | 342 | /* |
| 343 | * Remote symlink format and access functions. |
| 344 | */ |
| 345 | #define XFS_SYMLINK_MAGIC 0x58534c4d /* XSLM */ |
| 346 | |
| 347 | struct xfs_dsymlink_hdr { |
| 348 | __be32 sl_magic; |
| 349 | __be32 sl_offset; |
| 350 | __be32 sl_bytes; |
| 351 | __be32 sl_crc; |
| 352 | uuid_t sl_uuid; |
| 353 | __be64 sl_owner; |
| 354 | __be64 sl_blkno; |
| 355 | __be64 sl_lsn; |
| 356 | }; |
| 357 | |
Eric Sandeen | 533b81c | 2014-02-27 15:15:27 +1100 | [diff] [blame] | 358 | #define XFS_SYMLINK_CRC_OFF offsetof(struct xfs_dsymlink_hdr, sl_crc) |
| 359 | |
Dave Chinner | 1fb7e48d | 2013-08-12 20:49:40 +1000 | [diff] [blame] | 360 | /* |
| 361 | * The maximum pathlen is 1024 bytes. Since the minimum file system |
| 362 | * blocksize is 512 bytes, we can get a max of 3 extents back from |
| 363 | * bmapi when crc headers are taken into account. |
| 364 | */ |
| 365 | #define XFS_SYMLINK_MAPS 3 |
| 366 | |
| 367 | #define XFS_SYMLINK_BUF_SPACE(mp, bufsize) \ |
| 368 | ((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \ |
| 369 | sizeof(struct xfs_dsymlink_hdr) : 0)) |
| 370 | |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 371 | |
| 372 | /* |
| 373 | * Allocation Btree format definitions |
| 374 | * |
| 375 | * There are two on-disk btrees, one sorted by blockno and one sorted |
| 376 | * by blockcount and blockno. All blocks look the same to make the code |
| 377 | * simpler; if we have time later, we'll make the optimizations. |
| 378 | */ |
| 379 | #define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */ |
| 380 | #define XFS_ABTB_CRC_MAGIC 0x41423342 /* 'AB3B' */ |
| 381 | #define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */ |
| 382 | #define XFS_ABTC_CRC_MAGIC 0x41423343 /* 'AB3C' */ |
| 383 | |
| 384 | /* |
| 385 | * Data record/key structure |
| 386 | */ |
| 387 | typedef struct xfs_alloc_rec { |
| 388 | __be32 ar_startblock; /* starting block number */ |
| 389 | __be32 ar_blockcount; /* count of free blocks */ |
| 390 | } xfs_alloc_rec_t, xfs_alloc_key_t; |
| 391 | |
| 392 | typedef struct xfs_alloc_rec_incore { |
| 393 | xfs_agblock_t ar_startblock; /* starting block number */ |
| 394 | xfs_extlen_t ar_blockcount; /* count of free blocks */ |
| 395 | } xfs_alloc_rec_incore_t; |
| 396 | |
| 397 | /* btree pointer type */ |
| 398 | typedef __be32 xfs_alloc_ptr_t; |
| 399 | |
| 400 | /* |
| 401 | * Block numbers in the AG: |
| 402 | * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3. |
| 403 | */ |
| 404 | #define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1)) |
| 405 | #define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1)) |
| 406 | |
| 407 | |
| 408 | /* |
| 409 | * Inode Allocation Btree format definitions |
| 410 | * |
| 411 | * There is a btree for the inode map per allocation group. |
| 412 | */ |
| 413 | #define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */ |
| 414 | #define XFS_IBT_CRC_MAGIC 0x49414233 /* 'IAB3' */ |
Brian Foster | aafc3c2 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 415 | #define XFS_FIBT_MAGIC 0x46494254 /* 'FIBT' */ |
| 416 | #define XFS_FIBT_CRC_MAGIC 0x46494233 /* 'FIB3' */ |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 417 | |
| 418 | typedef __uint64_t xfs_inofree_t; |
| 419 | #define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t)) |
| 420 | #define XFS_INODES_PER_CHUNK_LOG (XFS_NBBYLOG + 3) |
| 421 | #define XFS_INOBT_ALL_FREE ((xfs_inofree_t)-1) |
| 422 | #define XFS_INOBT_MASK(i) ((xfs_inofree_t)1 << (i)) |
| 423 | |
| 424 | static inline xfs_inofree_t xfs_inobt_maskn(int i, int n) |
| 425 | { |
| 426 | return ((n >= XFS_INODES_PER_CHUNK ? 0 : XFS_INOBT_MASK(n)) - 1) << i; |
| 427 | } |
| 428 | |
| 429 | /* |
| 430 | * Data record structure |
| 431 | */ |
| 432 | typedef struct xfs_inobt_rec { |
| 433 | __be32 ir_startino; /* starting inode number */ |
| 434 | __be32 ir_freecount; /* count of free inodes (set bits) */ |
| 435 | __be64 ir_free; /* free inode mask */ |
| 436 | } xfs_inobt_rec_t; |
| 437 | |
| 438 | typedef struct xfs_inobt_rec_incore { |
| 439 | xfs_agino_t ir_startino; /* starting inode number */ |
| 440 | __int32_t ir_freecount; /* count of free inodes (set bits) */ |
| 441 | xfs_inofree_t ir_free; /* free inode mask */ |
| 442 | } xfs_inobt_rec_incore_t; |
| 443 | |
| 444 | |
| 445 | /* |
| 446 | * Key structure |
| 447 | */ |
| 448 | typedef struct xfs_inobt_key { |
| 449 | __be32 ir_startino; /* starting inode number */ |
| 450 | } xfs_inobt_key_t; |
| 451 | |
| 452 | /* btree pointer type */ |
| 453 | typedef __be32 xfs_inobt_ptr_t; |
| 454 | |
| 455 | /* |
| 456 | * block numbers in the AG. |
| 457 | */ |
| 458 | #define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1)) |
Brian Foster | aafc3c2 | 2014-04-24 16:00:52 +1000 | [diff] [blame] | 459 | #define XFS_FIBT_BLOCK(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1)) |
| 460 | |
| 461 | /* |
| 462 | * The first data block of an AG depends on whether the filesystem was formatted |
| 463 | * with the finobt feature. If so, account for the finobt reserved root btree |
| 464 | * block. |
| 465 | */ |
| 466 | #define XFS_PREALLOC_BLOCKS(mp) \ |
| 467 | (xfs_sb_version_hasfinobt(&((mp)->m_sb)) ? \ |
| 468 | XFS_FIBT_BLOCK(mp) + 1 : \ |
| 469 | XFS_IBT_BLOCK(mp) + 1) |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 470 | |
| 471 | |
| 472 | |
| 473 | /* |
| 474 | * BMAP Btree format definitions |
| 475 | * |
| 476 | * This includes both the root block definition that sits inside an inode fork |
| 477 | * and the record/pointer formats for the leaf/node in the blocks. |
| 478 | */ |
| 479 | #define XFS_BMAP_MAGIC 0x424d4150 /* 'BMAP' */ |
| 480 | #define XFS_BMAP_CRC_MAGIC 0x424d4133 /* 'BMA3' */ |
| 481 | |
| 482 | /* |
| 483 | * Bmap root header, on-disk form only. |
| 484 | */ |
| 485 | typedef struct xfs_bmdr_block { |
| 486 | __be16 bb_level; /* 0 is a leaf */ |
| 487 | __be16 bb_numrecs; /* current # of data records */ |
| 488 | } xfs_bmdr_block_t; |
| 489 | |
| 490 | /* |
| 491 | * Bmap btree record and extent descriptor. |
| 492 | * l0:63 is an extent flag (value 1 indicates non-normal). |
| 493 | * l0:9-62 are startoff. |
| 494 | * l0:0-8 and l1:21-63 are startblock. |
| 495 | * l1:0-20 are blockcount. |
| 496 | */ |
| 497 | #define BMBT_EXNTFLAG_BITLEN 1 |
| 498 | #define BMBT_STARTOFF_BITLEN 54 |
| 499 | #define BMBT_STARTBLOCK_BITLEN 52 |
| 500 | #define BMBT_BLOCKCOUNT_BITLEN 21 |
| 501 | |
| 502 | typedef struct xfs_bmbt_rec { |
| 503 | __be64 l0, l1; |
| 504 | } xfs_bmbt_rec_t; |
| 505 | |
| 506 | typedef __uint64_t xfs_bmbt_rec_base_t; /* use this for casts */ |
| 507 | typedef xfs_bmbt_rec_t xfs_bmdr_rec_t; |
| 508 | |
| 509 | typedef struct xfs_bmbt_rec_host { |
| 510 | __uint64_t l0, l1; |
| 511 | } xfs_bmbt_rec_host_t; |
| 512 | |
| 513 | /* |
| 514 | * Values and macros for delayed-allocation startblock fields. |
| 515 | */ |
| 516 | #define STARTBLOCKVALBITS 17 |
Christoph Hellwig | d5cf09b | 2014-07-30 09:12:05 +1000 | [diff] [blame] | 517 | #define STARTBLOCKMASKBITS (15 + 20) |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 518 | #define STARTBLOCKMASK \ |
| 519 | (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS) |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 520 | |
| 521 | static inline int isnullstartblock(xfs_fsblock_t x) |
| 522 | { |
| 523 | return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK; |
| 524 | } |
| 525 | |
Dave Chinner | a4fbe6a | 2013-10-23 10:51:50 +1100 | [diff] [blame] | 526 | static inline xfs_fsblock_t nullstartblock(int k) |
| 527 | { |
| 528 | ASSERT(k < (1 << STARTBLOCKVALBITS)); |
| 529 | return STARTBLOCKMASK | (k); |
| 530 | } |
| 531 | |
| 532 | static inline xfs_filblks_t startblockval(xfs_fsblock_t x) |
| 533 | { |
| 534 | return (xfs_filblks_t)((x) & ~STARTBLOCKMASK); |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * Possible extent formats. |
| 539 | */ |
| 540 | typedef enum { |
| 541 | XFS_EXTFMT_NOSTATE = 0, |
| 542 | XFS_EXTFMT_HASSTATE |
| 543 | } xfs_exntfmt_t; |
| 544 | |
| 545 | /* |
| 546 | * Possible extent states. |
| 547 | */ |
| 548 | typedef enum { |
| 549 | XFS_EXT_NORM, XFS_EXT_UNWRITTEN, |
| 550 | XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID |
| 551 | } xfs_exntst_t; |
| 552 | |
| 553 | /* |
| 554 | * Incore version of above. |
| 555 | */ |
| 556 | typedef struct xfs_bmbt_irec |
| 557 | { |
| 558 | xfs_fileoff_t br_startoff; /* starting file offset */ |
| 559 | xfs_fsblock_t br_startblock; /* starting block number */ |
| 560 | xfs_filblks_t br_blockcount; /* number of blocks */ |
| 561 | xfs_exntst_t br_state; /* extent state */ |
| 562 | } xfs_bmbt_irec_t; |
| 563 | |
| 564 | /* |
| 565 | * Key structure for non-leaf levels of the tree. |
| 566 | */ |
| 567 | typedef struct xfs_bmbt_key { |
| 568 | __be64 br_startoff; /* starting file offset */ |
| 569 | } xfs_bmbt_key_t, xfs_bmdr_key_t; |
| 570 | |
| 571 | /* btree pointer type */ |
| 572 | typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t; |
| 573 | |
| 574 | |
| 575 | /* |
| 576 | * Generic Btree block format definitions |
| 577 | * |
| 578 | * This is a combination of the actual format used on disk for short and long |
| 579 | * format btrees. The first three fields are shared by both format, but the |
| 580 | * pointers are different and should be used with care. |
| 581 | * |
| 582 | * To get the size of the actual short or long form headers please use the size |
| 583 | * macros below. Never use sizeof(xfs_btree_block). |
| 584 | * |
| 585 | * The blkno, crc, lsn, owner and uuid fields are only available in filesystems |
| 586 | * with the crc feature bit, and all accesses to them must be conditional on |
| 587 | * that flag. |
| 588 | */ |
| 589 | struct xfs_btree_block { |
| 590 | __be32 bb_magic; /* magic number for block type */ |
| 591 | __be16 bb_level; /* 0 is a leaf */ |
| 592 | __be16 bb_numrecs; /* current # of data records */ |
| 593 | union { |
| 594 | struct { |
| 595 | __be32 bb_leftsib; |
| 596 | __be32 bb_rightsib; |
| 597 | |
| 598 | __be64 bb_blkno; |
| 599 | __be64 bb_lsn; |
| 600 | uuid_t bb_uuid; |
| 601 | __be32 bb_owner; |
| 602 | __le32 bb_crc; |
| 603 | } s; /* short form pointers */ |
| 604 | struct { |
| 605 | __be64 bb_leftsib; |
| 606 | __be64 bb_rightsib; |
| 607 | |
| 608 | __be64 bb_blkno; |
| 609 | __be64 bb_lsn; |
| 610 | uuid_t bb_uuid; |
| 611 | __be64 bb_owner; |
| 612 | __le32 bb_crc; |
| 613 | __be32 bb_pad; /* padding for alignment */ |
| 614 | } l; /* long form pointers */ |
| 615 | } bb_u; /* rest */ |
| 616 | }; |
| 617 | |
| 618 | #define XFS_BTREE_SBLOCK_LEN 16 /* size of a short form block */ |
| 619 | #define XFS_BTREE_LBLOCK_LEN 24 /* size of a long form block */ |
| 620 | |
| 621 | /* sizes of CRC enabled btree blocks */ |
| 622 | #define XFS_BTREE_SBLOCK_CRC_LEN (XFS_BTREE_SBLOCK_LEN + 40) |
| 623 | #define XFS_BTREE_LBLOCK_CRC_LEN (XFS_BTREE_LBLOCK_LEN + 48) |
| 624 | |
| 625 | #define XFS_BTREE_SBLOCK_CRC_OFF \ |
| 626 | offsetof(struct xfs_btree_block, bb_u.s.bb_crc) |
| 627 | #define XFS_BTREE_LBLOCK_CRC_OFF \ |
| 628 | offsetof(struct xfs_btree_block, bb_u.l.bb_crc) |
| 629 | |
Dave Chinner | 6ca1c90 | 2013-08-12 20:49:26 +1000 | [diff] [blame] | 630 | #endif /* __XFS_FORMAT_H__ */ |