Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | #ifndef __XFS_DINODE_H__ |
| 19 | #define __XFS_DINODE_H__ |
| 20 | |
Christoph Hellwig | 51ce16d | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 21 | #define XFS_DINODE_MAGIC 0x494e /* 'IN' */ |
Christoph Hellwig | 93848a9 | 2013-04-03 16:11:17 +1100 | [diff] [blame] | 22 | #define XFS_DINODE_GOOD_VERSION(v) ((v) >= 1 && (v) <= 3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | typedef struct xfs_timestamp { |
Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 25 | __be32 t_sec; /* timestamp seconds */ |
| 26 | __be32 t_nsec; /* timestamp nanoseconds */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | } xfs_timestamp_t; |
| 28 | |
| 29 | /* |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 30 | * On-disk inode structure. |
| 31 | * |
| 32 | * This is just the header or "dinode core", the inode is expanded to fill a |
| 33 | * variable size the leftover area split into a data and an attribute fork. |
| 34 | * The format of the data and attribute fork depends on the format of the |
| 35 | * inode as indicated by di_format and di_aformat. To access the data and |
Chen Baozi | 51c8422 | 2012-05-26 00:48:47 +0800 | [diff] [blame] | 36 | * attribute use the XFS_DFORK_DPTR, XFS_DFORK_APTR, and XFS_DFORK_PTR macros |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 37 | * below. |
| 38 | * |
| 39 | * There is a very similar struct icdinode in xfs_inode which matches the |
| 40 | * layout of the first 96 bytes of this structure, but is kept in native |
| 41 | * format instead of big endian. |
Dave Chinner | e1b4271 | 2013-07-24 15:47:30 +1000 | [diff] [blame] | 42 | * |
| 43 | * Note: di_flushiter is only used by v1/2 inodes - it's effectively a zeroed |
| 44 | * padding field for v3 inodes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | */ |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 46 | typedef struct xfs_dinode { |
Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 47 | __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */ |
| 48 | __be16 di_mode; /* mode and type of file */ |
| 49 | __u8 di_version; /* inode version */ |
| 50 | __u8 di_format; /* format of di_c data */ |
| 51 | __be16 di_onlink; /* old number of links to file */ |
| 52 | __be32 di_uid; /* owner's user id */ |
| 53 | __be32 di_gid; /* owner's group id */ |
| 54 | __be32 di_nlink; /* number of links to file */ |
Arkadiusz Mi?kiewicz | 6743099 | 2010-09-26 06:10:18 +0000 | [diff] [blame] | 55 | __be16 di_projid_lo; /* lower part of owner's project id */ |
| 56 | __be16 di_projid_hi; /* higher part owner's project id */ |
| 57 | __u8 di_pad[6]; /* unused, zeroed space */ |
Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 58 | __be16 di_flushiter; /* incremented on flush */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | xfs_timestamp_t di_atime; /* time last accessed */ |
| 60 | xfs_timestamp_t di_mtime; /* time last modified */ |
| 61 | xfs_timestamp_t di_ctime; /* time created/inode modified */ |
Christoph Hellwig | 347d1c0 | 2007-08-28 13:57:51 +1000 | [diff] [blame] | 62 | __be64 di_size; /* number of bytes in file */ |
| 63 | __be64 di_nblocks; /* # of direct & btree blocks used */ |
| 64 | __be32 di_extsize; /* basic/minimum extent size for file */ |
| 65 | __be32 di_nextents; /* number of extents in data fork */ |
| 66 | __be16 di_anextents; /* number of extents in attribute fork*/ |
| 67 | __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */ |
| 68 | __s8 di_aformat; /* format of attr fork's data */ |
| 69 | __be32 di_dmevmask; /* DMIG event mask */ |
| 70 | __be16 di_dmstate; /* DMIG state info */ |
| 71 | __be16 di_flags; /* random flags, XFS_DIFLAG_... */ |
| 72 | __be32 di_gen; /* generation number */ |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 73 | |
| 74 | /* di_next_unlinked is the only non-core field in the old dinode */ |
| 75 | __be32 di_next_unlinked;/* agi unlinked list ptr */ |
Christoph Hellwig | 93848a9 | 2013-04-03 16:11:17 +1100 | [diff] [blame] | 76 | |
| 77 | /* start of the extended dinode, writable fields */ |
| 78 | __le32 di_crc; /* CRC of the inode */ |
| 79 | __be64 di_changecount; /* number of attribute changes */ |
| 80 | __be64 di_lsn; /* flush sequence */ |
| 81 | __be64 di_flags2; /* more random flags */ |
| 82 | __u8 di_pad2[16]; /* more padding for future expansion */ |
| 83 | |
| 84 | /* fields only written to during inode creation */ |
| 85 | xfs_timestamp_t di_crtime; /* time created */ |
| 86 | __be64 di_ino; /* inode number */ |
| 87 | uuid_t di_uuid; /* UUID of the filesystem */ |
| 88 | |
| 89 | /* structure must be padded to 64 bit alignment */ |
| 90 | } xfs_dinode_t; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Eric Sandeen | 533b81c | 2014-02-27 15:15:27 +1100 | [diff] [blame] | 92 | #define XFS_DINODE_CRC_OFF offsetof(struct xfs_dinode, di_crc) |
| 93 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | #define DI_MAX_FLUSH 0xffff |
| 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | /* |
Christoph Hellwig | 93848a9 | 2013-04-03 16:11:17 +1100 | [diff] [blame] | 97 | * Size of the core inode on disk. Version 1 and 2 inodes have |
| 98 | * the same size, but version 3 has grown a few additional fields. |
| 99 | */ |
| 100 | static inline uint xfs_dinode_size(int version) |
| 101 | { |
| 102 | if (version == 3) |
| 103 | return sizeof(struct xfs_dinode); |
| 104 | return offsetof(struct xfs_dinode, di_crc); |
| 105 | } |
| 106 | |
| 107 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | * The 32 bit link count in the inode theoretically maxes out at UINT_MAX. |
| 109 | * Since the pathconf interface is signed, we use 2^31 - 1 instead. |
| 110 | * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX. |
| 111 | */ |
| 112 | #define XFS_MAXLINK ((1U << 31) - 1U) |
| 113 | #define XFS_MAXLINK_1 65535U |
| 114 | |
| 115 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | * Values for di_format |
| 117 | */ |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 118 | typedef enum xfs_dinode_fmt { |
| 119 | XFS_DINODE_FMT_DEV, /* xfs_dev_t */ |
| 120 | XFS_DINODE_FMT_LOCAL, /* bulk data */ |
| 121 | XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */ |
| 122 | XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */ |
| 123 | XFS_DINODE_FMT_UUID /* uuid_t */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } xfs_dinode_fmt_t; |
| 125 | |
| 126 | /* |
| 127 | * Inode minimum and maximum sizes. |
| 128 | */ |
| 129 | #define XFS_DINODE_MIN_LOG 8 |
| 130 | #define XFS_DINODE_MAX_LOG 11 |
| 131 | #define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG) |
| 132 | #define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG) |
| 133 | |
| 134 | /* |
| 135 | * Inode size for given fs. |
| 136 | */ |
Christoph Hellwig | 56cea2d | 2013-03-12 23:30:36 +1100 | [diff] [blame] | 137 | #define XFS_LITINO(mp, version) \ |
Christoph Hellwig | 93848a9 | 2013-04-03 16:11:17 +1100 | [diff] [blame] | 138 | ((int)(((mp)->m_sb.sb_inodesize) - xfs_dinode_size(version))) |
Christoph Hellwig | 6447c36 | 2009-03-29 09:51:14 +0200 | [diff] [blame] | 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | * Inode data & attribute fork sizes, per inode. |
| 142 | */ |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 143 | #define XFS_DFORK_Q(dip) ((dip)->di_forkoff != 0) |
| 144 | #define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 146 | #define XFS_DFORK_DSIZE(dip,mp) \ |
Christoph Hellwig | 45ba598 | 2007-12-07 14:07:20 +1100 | [diff] [blame] | 147 | (XFS_DFORK_Q(dip) ? \ |
| 148 | XFS_DFORK_BOFF(dip) : \ |
Christoph Hellwig | 56cea2d | 2013-03-12 23:30:36 +1100 | [diff] [blame] | 149 | XFS_LITINO(mp, (dip)->di_version)) |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 150 | #define XFS_DFORK_ASIZE(dip,mp) \ |
Christoph Hellwig | 45ba598 | 2007-12-07 14:07:20 +1100 | [diff] [blame] | 151 | (XFS_DFORK_Q(dip) ? \ |
Christoph Hellwig | 56cea2d | 2013-03-12 23:30:36 +1100 | [diff] [blame] | 152 | XFS_LITINO(mp, (dip)->di_version) - XFS_DFORK_BOFF(dip) : \ |
Christoph Hellwig | 45ba598 | 2007-12-07 14:07:20 +1100 | [diff] [blame] | 153 | 0) |
| 154 | #define XFS_DFORK_SIZE(dip,mp,w) \ |
| 155 | ((w) == XFS_DATA_FORK ? \ |
| 156 | XFS_DFORK_DSIZE(dip, mp) : \ |
| 157 | XFS_DFORK_ASIZE(dip, mp)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 159 | /* |
| 160 | * Return pointers to the data or attribute forks. |
| 161 | */ |
| 162 | #define XFS_DFORK_DPTR(dip) \ |
Christoph Hellwig | 93848a9 | 2013-04-03 16:11:17 +1100 | [diff] [blame] | 163 | ((char *)dip + xfs_dinode_size(dip->di_version)) |
Christoph Hellwig | 45ba598 | 2007-12-07 14:07:20 +1100 | [diff] [blame] | 164 | #define XFS_DFORK_APTR(dip) \ |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 165 | (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip)) |
Christoph Hellwig | 45ba598 | 2007-12-07 14:07:20 +1100 | [diff] [blame] | 166 | #define XFS_DFORK_PTR(dip,w) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip)) |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 168 | |
Christoph Hellwig | 45ba598 | 2007-12-07 14:07:20 +1100 | [diff] [blame] | 169 | #define XFS_DFORK_FORMAT(dip,w) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | ((w) == XFS_DATA_FORK ? \ |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 171 | (dip)->di_format : \ |
| 172 | (dip)->di_aformat) |
Christoph Hellwig | 45ba598 | 2007-12-07 14:07:20 +1100 | [diff] [blame] | 173 | #define XFS_DFORK_NEXTENTS(dip,w) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | ((w) == XFS_DATA_FORK ? \ |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 175 | be32_to_cpu((dip)->di_nextents) : \ |
| 176 | be16_to_cpu((dip)->di_anextents)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
Chandra Seetharaman | 6292604 | 2011-07-22 23:40:15 +0000 | [diff] [blame] | 178 | #define XFS_BUF_TO_DINODE(bp) ((xfs_dinode_t *)((bp)->b_addr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | /* |
Christoph Hellwig | 81591fe | 2008-11-28 14:23:39 +1100 | [diff] [blame] | 181 | * For block and character special files the 32bit dev_t is stored at the |
| 182 | * beginning of the data fork. |
| 183 | */ |
| 184 | static inline xfs_dev_t xfs_dinode_get_rdev(struct xfs_dinode *dip) |
| 185 | { |
| 186 | return be32_to_cpu(*(__be32 *)XFS_DFORK_DPTR(dip)); |
| 187 | } |
| 188 | |
| 189 | static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev) |
| 190 | { |
| 191 | *(__be32 *)XFS_DFORK_DPTR(dip) = cpu_to_be32(rdev); |
| 192 | } |
| 193 | |
| 194 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | * Values for di_flags |
| 196 | * There should be a one-to-one correspondence between these flags and the |
| 197 | * XFS_XFLAG_s. |
| 198 | */ |
| 199 | #define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */ |
| 200 | #define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */ |
| 201 | #define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */ |
| 202 | #define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */ |
| 203 | #define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */ |
| 204 | #define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */ |
| 205 | #define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */ |
| 206 | #define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */ |
| 207 | #define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */ |
Nathan Scott | dd9f438 | 2006-01-11 15:28:28 +1100 | [diff] [blame] | 208 | #define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */ |
| 209 | #define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */ |
| 210 | #define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */ |
| 211 | #define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */ |
Barry Naujok | d3446ea | 2006-06-09 14:54:19 +1000 | [diff] [blame] | 212 | #define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */ |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 213 | #define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | #define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT) |
| 215 | #define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT) |
| 216 | #define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT) |
| 217 | #define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT) |
| 218 | #define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT) |
| 219 | #define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT) |
| 220 | #define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT) |
| 221 | #define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT) |
| 222 | #define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT) |
| 223 | #define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT) |
| 224 | #define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT) |
Nathan Scott | dd9f438 | 2006-01-11 15:28:28 +1100 | [diff] [blame] | 225 | #define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT) |
| 226 | #define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT) |
Barry Naujok | d3446ea | 2006-06-09 14:54:19 +1000 | [diff] [blame] | 227 | #define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT) |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 228 | #define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Eric Sandeen | 71ddabb | 2007-11-23 16:29:42 +1100 | [diff] [blame] | 230 | #ifdef CONFIG_XFS_RT |
| 231 | #define XFS_IS_REALTIME_INODE(ip) ((ip)->i_d.di_flags & XFS_DIFLAG_REALTIME) |
| 232 | #else |
| 233 | #define XFS_IS_REALTIME_INODE(ip) (0) |
| 234 | #endif |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | #define XFS_DIFLAG_ANY \ |
| 237 | (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \ |
| 238 | XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \ |
| 239 | XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \ |
Nathan Scott | dd9f438 | 2006-01-11 15:28:28 +1100 | [diff] [blame] | 240 | XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \ |
David Chinner | 2a82b8b | 2007-07-11 11:09:12 +1000 | [diff] [blame] | 241 | XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
| 243 | #endif /* __XFS_DINODE_H__ */ |