blob: 749c861027944df49ee061667e1da231f6849764 [file] [log] [blame]
Dave Chinner6ca1c902013-08-12 20:49:26 +10001/*
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 Chinner1fb7e48d2013-08-12 20:49:40 +100030struct xfs_mount;
31struct xfs_trans;
32struct xfs_inode;
33struct xfs_buf;
34struct xfs_ifork;
35
Christoph Hellwig4fb6e8a2014-11-28 14:25:04 +110036/*
Christoph Hellwigbb58e612014-11-28 14:27:09 +110037 * Super block
38 * Fits into a sector-sized buffer at address 0 of each allocation group.
39 * Only the first of these is ever updated except during growfs.
40 */
41#define XFS_SB_MAGIC 0x58465342 /* 'XFSB' */
42#define XFS_SB_VERSION_1 1 /* 5.3, 6.0.1, 6.1 */
43#define XFS_SB_VERSION_2 2 /* 6.2 - attributes */
44#define XFS_SB_VERSION_3 3 /* 6.2 - new inode version */
45#define XFS_SB_VERSION_4 4 /* 6.2+ - bitmask version */
46#define XFS_SB_VERSION_5 5 /* CRC enabled filesystem */
47#define XFS_SB_VERSION_NUMBITS 0x000f
48#define XFS_SB_VERSION_ALLFBITS 0xfff0
49#define XFS_SB_VERSION_ATTRBIT 0x0010
50#define XFS_SB_VERSION_NLINKBIT 0x0020
51#define XFS_SB_VERSION_QUOTABIT 0x0040
52#define XFS_SB_VERSION_ALIGNBIT 0x0080
53#define XFS_SB_VERSION_DALIGNBIT 0x0100
54#define XFS_SB_VERSION_SHAREDBIT 0x0200
55#define XFS_SB_VERSION_LOGV2BIT 0x0400
56#define XFS_SB_VERSION_SECTORBIT 0x0800
57#define XFS_SB_VERSION_EXTFLGBIT 0x1000
58#define XFS_SB_VERSION_DIRV2BIT 0x2000
59#define XFS_SB_VERSION_BORGBIT 0x4000 /* ASCII only case-insens. */
60#define XFS_SB_VERSION_MOREBITSBIT 0x8000
61
62/*
63 * Supported feature bit list is just all bits in the versionnum field because
64 * we've used them all up and understand them all. Except, of course, for the
65 * shared superblock bit, which nobody knows what it does and so is unsupported.
66 */
67#define XFS_SB_VERSION_OKBITS \
68 ((XFS_SB_VERSION_NUMBITS | XFS_SB_VERSION_ALLFBITS) & \
69 ~XFS_SB_VERSION_SHAREDBIT)
70
71/*
72 * There are two words to hold XFS "feature" bits: the original
73 * word, sb_versionnum, and sb_features2. Whenever a bit is set in
74 * sb_features2, the feature bit XFS_SB_VERSION_MOREBITSBIT must be set.
75 *
76 * These defines represent bits in sb_features2.
77 */
78#define XFS_SB_VERSION2_RESERVED1BIT 0x00000001
79#define XFS_SB_VERSION2_LAZYSBCOUNTBIT 0x00000002 /* Superblk counters */
80#define XFS_SB_VERSION2_RESERVED4BIT 0x00000004
81#define XFS_SB_VERSION2_ATTR2BIT 0x00000008 /* Inline attr rework */
82#define XFS_SB_VERSION2_PARENTBIT 0x00000010 /* parent pointers */
83#define XFS_SB_VERSION2_PROJID32BIT 0x00000080 /* 32 bit project id */
84#define XFS_SB_VERSION2_CRCBIT 0x00000100 /* metadata CRCs */
85#define XFS_SB_VERSION2_FTYPE 0x00000200 /* inode type in dir */
86
87#define XFS_SB_VERSION2_OKBITS \
88 (XFS_SB_VERSION2_LAZYSBCOUNTBIT | \
89 XFS_SB_VERSION2_ATTR2BIT | \
90 XFS_SB_VERSION2_PROJID32BIT | \
91 XFS_SB_VERSION2_FTYPE)
92
93/*
94 * Superblock - in core version. Must match the ondisk version below.
95 * Must be padded to 64 bit alignment.
96 */
97typedef struct xfs_sb {
98 __uint32_t sb_magicnum; /* magic number == XFS_SB_MAGIC */
99 __uint32_t sb_blocksize; /* logical block size, bytes */
100 xfs_rfsblock_t sb_dblocks; /* number of data blocks */
101 xfs_rfsblock_t sb_rblocks; /* number of realtime blocks */
102 xfs_rtblock_t sb_rextents; /* number of realtime extents */
103 uuid_t sb_uuid; /* file system unique id */
104 xfs_fsblock_t sb_logstart; /* starting block of log if internal */
105 xfs_ino_t sb_rootino; /* root inode number */
106 xfs_ino_t sb_rbmino; /* bitmap inode for realtime extents */
107 xfs_ino_t sb_rsumino; /* summary inode for rt bitmap */
108 xfs_agblock_t sb_rextsize; /* realtime extent size, blocks */
109 xfs_agblock_t sb_agblocks; /* size of an allocation group */
110 xfs_agnumber_t sb_agcount; /* number of allocation groups */
111 xfs_extlen_t sb_rbmblocks; /* number of rt bitmap blocks */
112 xfs_extlen_t sb_logblocks; /* number of log blocks */
113 __uint16_t sb_versionnum; /* header version == XFS_SB_VERSION */
114 __uint16_t sb_sectsize; /* volume sector size, bytes */
115 __uint16_t sb_inodesize; /* inode size, bytes */
116 __uint16_t sb_inopblock; /* inodes per block */
117 char sb_fname[12]; /* file system name */
118 __uint8_t sb_blocklog; /* log2 of sb_blocksize */
119 __uint8_t sb_sectlog; /* log2 of sb_sectsize */
120 __uint8_t sb_inodelog; /* log2 of sb_inodesize */
121 __uint8_t sb_inopblog; /* log2 of sb_inopblock */
122 __uint8_t sb_agblklog; /* log2 of sb_agblocks (rounded up) */
123 __uint8_t sb_rextslog; /* log2 of sb_rextents */
124 __uint8_t sb_inprogress; /* mkfs is in progress, don't mount */
125 __uint8_t sb_imax_pct; /* max % of fs for inode space */
126 /* statistics */
127 /*
128 * These fields must remain contiguous. If you really
129 * want to change their layout, make sure you fix the
130 * code in xfs_trans_apply_sb_deltas().
131 */
132 __uint64_t sb_icount; /* allocated inodes */
133 __uint64_t sb_ifree; /* free inodes */
134 __uint64_t sb_fdblocks; /* free data blocks */
135 __uint64_t sb_frextents; /* free realtime extents */
136 /*
137 * End contiguous fields.
138 */
139 xfs_ino_t sb_uquotino; /* user quota inode */
140 xfs_ino_t sb_gquotino; /* group quota inode */
141 __uint16_t sb_qflags; /* quota flags */
142 __uint8_t sb_flags; /* misc. flags */
143 __uint8_t sb_shared_vn; /* shared version number */
144 xfs_extlen_t sb_inoalignmt; /* inode chunk alignment, fsblocks */
145 __uint32_t sb_unit; /* stripe or raid unit */
146 __uint32_t sb_width; /* stripe or raid width */
147 __uint8_t sb_dirblklog; /* log2 of dir block size (fsbs) */
148 __uint8_t sb_logsectlog; /* log2 of the log sector size */
149 __uint16_t sb_logsectsize; /* sector size for the log, bytes */
150 __uint32_t sb_logsunit; /* stripe unit size for the log */
151 __uint32_t sb_features2; /* additional feature bits */
152
153 /*
Dave Chinner074e4272015-01-22 09:10:33 +1100154 * bad features2 field as a result of failing to pad the sb structure to
155 * 64 bits. Some machines will be using this field for features2 bits.
156 * Easiest just to mark it bad and not use it for anything else.
157 *
158 * This is not kept up to date in memory; it is always overwritten by
159 * the value in sb_features2 when formatting the incore superblock to
160 * the disk buffer.
Christoph Hellwigbb58e612014-11-28 14:27:09 +1100161 */
162 __uint32_t sb_bad_features2;
163
164 /* version 5 superblock fields start here */
165
166 /* feature masks */
167 __uint32_t sb_features_compat;
168 __uint32_t sb_features_ro_compat;
169 __uint32_t sb_features_incompat;
170 __uint32_t sb_features_log_incompat;
171
172 __uint32_t sb_crc; /* superblock crc */
173 __uint32_t sb_pad;
174
175 xfs_ino_t sb_pquotino; /* project quota inode */
176 xfs_lsn_t sb_lsn; /* last write sequence */
177
178 /* must be padded to 64 bit alignment */
179} xfs_sb_t;
180
181#define XFS_SB_CRC_OFF offsetof(struct xfs_sb, sb_crc)
182
183/*
184 * Superblock - on disk version. Must match the in core version above.
185 * Must be padded to 64 bit alignment.
186 */
187typedef struct xfs_dsb {
188 __be32 sb_magicnum; /* magic number == XFS_SB_MAGIC */
189 __be32 sb_blocksize; /* logical block size, bytes */
190 __be64 sb_dblocks; /* number of data blocks */
191 __be64 sb_rblocks; /* number of realtime blocks */
192 __be64 sb_rextents; /* number of realtime extents */
193 uuid_t sb_uuid; /* file system unique id */
194 __be64 sb_logstart; /* starting block of log if internal */
195 __be64 sb_rootino; /* root inode number */
196 __be64 sb_rbmino; /* bitmap inode for realtime extents */
197 __be64 sb_rsumino; /* summary inode for rt bitmap */
198 __be32 sb_rextsize; /* realtime extent size, blocks */
199 __be32 sb_agblocks; /* size of an allocation group */
200 __be32 sb_agcount; /* number of allocation groups */
201 __be32 sb_rbmblocks; /* number of rt bitmap blocks */
202 __be32 sb_logblocks; /* number of log blocks */
203 __be16 sb_versionnum; /* header version == XFS_SB_VERSION */
204 __be16 sb_sectsize; /* volume sector size, bytes */
205 __be16 sb_inodesize; /* inode size, bytes */
206 __be16 sb_inopblock; /* inodes per block */
207 char sb_fname[12]; /* file system name */
208 __u8 sb_blocklog; /* log2 of sb_blocksize */
209 __u8 sb_sectlog; /* log2 of sb_sectsize */
210 __u8 sb_inodelog; /* log2 of sb_inodesize */
211 __u8 sb_inopblog; /* log2 of sb_inopblock */
212 __u8 sb_agblklog; /* log2 of sb_agblocks (rounded up) */
213 __u8 sb_rextslog; /* log2 of sb_rextents */
214 __u8 sb_inprogress; /* mkfs is in progress, don't mount */
215 __u8 sb_imax_pct; /* max % of fs for inode space */
216 /* statistics */
217 /*
218 * These fields must remain contiguous. If you really
219 * want to change their layout, make sure you fix the
220 * code in xfs_trans_apply_sb_deltas().
221 */
222 __be64 sb_icount; /* allocated inodes */
223 __be64 sb_ifree; /* free inodes */
224 __be64 sb_fdblocks; /* free data blocks */
225 __be64 sb_frextents; /* free realtime extents */
226 /*
227 * End contiguous fields.
228 */
229 __be64 sb_uquotino; /* user quota inode */
230 __be64 sb_gquotino; /* group quota inode */
231 __be16 sb_qflags; /* quota flags */
232 __u8 sb_flags; /* misc. flags */
233 __u8 sb_shared_vn; /* shared version number */
234 __be32 sb_inoalignmt; /* inode chunk alignment, fsblocks */
235 __be32 sb_unit; /* stripe or raid unit */
236 __be32 sb_width; /* stripe or raid width */
237 __u8 sb_dirblklog; /* log2 of dir block size (fsbs) */
238 __u8 sb_logsectlog; /* log2 of the log sector size */
239 __be16 sb_logsectsize; /* sector size for the log, bytes */
240 __be32 sb_logsunit; /* stripe unit size for the log */
241 __be32 sb_features2; /* additional feature bits */
242 /*
243 * bad features2 field as a result of failing to pad the sb
244 * structure to 64 bits. Some machines will be using this field
245 * for features2 bits. Easiest just to mark it bad and not use
246 * it for anything else.
247 */
248 __be32 sb_bad_features2;
249
250 /* version 5 superblock fields start here */
251
252 /* feature masks */
253 __be32 sb_features_compat;
254 __be32 sb_features_ro_compat;
255 __be32 sb_features_incompat;
256 __be32 sb_features_log_incompat;
257
258 __le32 sb_crc; /* superblock crc */
259 __be32 sb_pad;
260
261 __be64 sb_pquotino; /* project quota inode */
262 __be64 sb_lsn; /* last write sequence */
263
264 /* must be padded to 64 bit alignment */
265} xfs_dsb_t;
266
267/*
268 * Sequence number values for the fields.
269 */
270typedef enum {
271 XFS_SBS_MAGICNUM, XFS_SBS_BLOCKSIZE, XFS_SBS_DBLOCKS, XFS_SBS_RBLOCKS,
272 XFS_SBS_REXTENTS, XFS_SBS_UUID, XFS_SBS_LOGSTART, XFS_SBS_ROOTINO,
273 XFS_SBS_RBMINO, XFS_SBS_RSUMINO, XFS_SBS_REXTSIZE, XFS_SBS_AGBLOCKS,
274 XFS_SBS_AGCOUNT, XFS_SBS_RBMBLOCKS, XFS_SBS_LOGBLOCKS,
275 XFS_SBS_VERSIONNUM, XFS_SBS_SECTSIZE, XFS_SBS_INODESIZE,
276 XFS_SBS_INOPBLOCK, XFS_SBS_FNAME, XFS_SBS_BLOCKLOG,
277 XFS_SBS_SECTLOG, XFS_SBS_INODELOG, XFS_SBS_INOPBLOG, XFS_SBS_AGBLKLOG,
278 XFS_SBS_REXTSLOG, XFS_SBS_INPROGRESS, XFS_SBS_IMAX_PCT, XFS_SBS_ICOUNT,
279 XFS_SBS_IFREE, XFS_SBS_FDBLOCKS, XFS_SBS_FREXTENTS, XFS_SBS_UQUOTINO,
280 XFS_SBS_GQUOTINO, XFS_SBS_QFLAGS, XFS_SBS_FLAGS, XFS_SBS_SHARED_VN,
281 XFS_SBS_INOALIGNMT, XFS_SBS_UNIT, XFS_SBS_WIDTH, XFS_SBS_DIRBLKLOG,
282 XFS_SBS_LOGSECTLOG, XFS_SBS_LOGSECTSIZE, XFS_SBS_LOGSUNIT,
283 XFS_SBS_FEATURES2, XFS_SBS_BAD_FEATURES2, XFS_SBS_FEATURES_COMPAT,
284 XFS_SBS_FEATURES_RO_COMPAT, XFS_SBS_FEATURES_INCOMPAT,
285 XFS_SBS_FEATURES_LOG_INCOMPAT, XFS_SBS_CRC, XFS_SBS_PAD,
286 XFS_SBS_PQUOTINO, XFS_SBS_LSN,
287 XFS_SBS_FIELDCOUNT
288} xfs_sb_field_t;
289
290/*
291 * Mask values, defined based on the xfs_sb_field_t values.
292 * Only define the ones we're using.
293 */
294#define XFS_SB_MVAL(x) (1LL << XFS_SBS_ ## x)
295#define XFS_SB_UUID XFS_SB_MVAL(UUID)
296#define XFS_SB_FNAME XFS_SB_MVAL(FNAME)
297#define XFS_SB_ROOTINO XFS_SB_MVAL(ROOTINO)
298#define XFS_SB_RBMINO XFS_SB_MVAL(RBMINO)
299#define XFS_SB_RSUMINO XFS_SB_MVAL(RSUMINO)
300#define XFS_SB_VERSIONNUM XFS_SB_MVAL(VERSIONNUM)
301#define XFS_SB_UQUOTINO XFS_SB_MVAL(UQUOTINO)
302#define XFS_SB_GQUOTINO XFS_SB_MVAL(GQUOTINO)
303#define XFS_SB_QFLAGS XFS_SB_MVAL(QFLAGS)
304#define XFS_SB_SHARED_VN XFS_SB_MVAL(SHARED_VN)
305#define XFS_SB_UNIT XFS_SB_MVAL(UNIT)
306#define XFS_SB_WIDTH XFS_SB_MVAL(WIDTH)
307#define XFS_SB_ICOUNT XFS_SB_MVAL(ICOUNT)
308#define XFS_SB_IFREE XFS_SB_MVAL(IFREE)
309#define XFS_SB_FDBLOCKS XFS_SB_MVAL(FDBLOCKS)
310#define XFS_SB_FEATURES2 XFS_SB_MVAL(FEATURES2)
311#define XFS_SB_BAD_FEATURES2 XFS_SB_MVAL(BAD_FEATURES2)
312#define XFS_SB_FEATURES_COMPAT XFS_SB_MVAL(FEATURES_COMPAT)
313#define XFS_SB_FEATURES_RO_COMPAT XFS_SB_MVAL(FEATURES_RO_COMPAT)
314#define XFS_SB_FEATURES_INCOMPAT XFS_SB_MVAL(FEATURES_INCOMPAT)
315#define XFS_SB_FEATURES_LOG_INCOMPAT XFS_SB_MVAL(FEATURES_LOG_INCOMPAT)
316#define XFS_SB_CRC XFS_SB_MVAL(CRC)
317#define XFS_SB_PQUOTINO XFS_SB_MVAL(PQUOTINO)
318#define XFS_SB_NUM_BITS ((int)XFS_SBS_FIELDCOUNT)
319#define XFS_SB_ALL_BITS ((1LL << XFS_SB_NUM_BITS) - 1)
320#define XFS_SB_MOD_BITS \
321 (XFS_SB_UUID | XFS_SB_ROOTINO | XFS_SB_RBMINO | XFS_SB_RSUMINO | \
322 XFS_SB_VERSIONNUM | XFS_SB_UQUOTINO | XFS_SB_GQUOTINO | \
323 XFS_SB_QFLAGS | XFS_SB_SHARED_VN | XFS_SB_UNIT | XFS_SB_WIDTH | \
324 XFS_SB_ICOUNT | XFS_SB_IFREE | XFS_SB_FDBLOCKS | XFS_SB_FEATURES2 | \
325 XFS_SB_BAD_FEATURES2 | XFS_SB_FEATURES_COMPAT | \
326 XFS_SB_FEATURES_RO_COMPAT | XFS_SB_FEATURES_INCOMPAT | \
327 XFS_SB_FEATURES_LOG_INCOMPAT | XFS_SB_PQUOTINO)
328
329
330/*
331 * Misc. Flags - warning - these will be cleared by xfs_repair unless
332 * a feature bit is set when the flag is used.
333 */
334#define XFS_SBF_NOFLAGS 0x00 /* no flags set */
335#define XFS_SBF_READONLY 0x01 /* only read-only mounts allowed */
336
337/*
338 * define max. shared version we can interoperate with
339 */
340#define XFS_SB_MAX_SHARED_VN 0
341
342#define XFS_SB_VERSION_NUM(sbp) ((sbp)->sb_versionnum & XFS_SB_VERSION_NUMBITS)
343
344/*
345 * The first XFS version we support is a v4 superblock with V2 directories.
346 */
347static inline bool xfs_sb_good_v4_features(struct xfs_sb *sbp)
348{
349 if (!(sbp->sb_versionnum & XFS_SB_VERSION_DIRV2BIT))
350 return false;
351
352 /* check for unknown features in the fs */
353 if ((sbp->sb_versionnum & ~XFS_SB_VERSION_OKBITS) ||
354 ((sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT) &&
355 (sbp->sb_features2 & ~XFS_SB_VERSION2_OKBITS)))
356 return false;
357
358 return true;
359}
360
361static inline bool xfs_sb_good_version(struct xfs_sb *sbp)
362{
363 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5)
364 return true;
365 if (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_4)
366 return xfs_sb_good_v4_features(sbp);
367 return false;
368}
369
370/*
371 * Detect a mismatched features2 field. Older kernels read/wrote
372 * this into the wrong slot, so to be safe we keep them in sync.
373 */
374static inline bool xfs_sb_has_mismatched_features2(struct xfs_sb *sbp)
375{
376 return sbp->sb_bad_features2 != sbp->sb_features2;
377}
378
379static inline bool xfs_sb_version_hasattr(struct xfs_sb *sbp)
380{
381 return (sbp->sb_versionnum & XFS_SB_VERSION_ATTRBIT);
382}
383
384static inline void xfs_sb_version_addattr(struct xfs_sb *sbp)
385{
386 sbp->sb_versionnum |= XFS_SB_VERSION_ATTRBIT;
387}
388
389static inline bool xfs_sb_version_hasquota(struct xfs_sb *sbp)
390{
391 return (sbp->sb_versionnum & XFS_SB_VERSION_QUOTABIT);
392}
393
394static inline void xfs_sb_version_addquota(struct xfs_sb *sbp)
395{
396 sbp->sb_versionnum |= XFS_SB_VERSION_QUOTABIT;
397}
398
399static inline bool xfs_sb_version_hasalign(struct xfs_sb *sbp)
400{
401 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
402 (sbp->sb_versionnum & XFS_SB_VERSION_ALIGNBIT));
403}
404
405static inline bool xfs_sb_version_hasdalign(struct xfs_sb *sbp)
406{
407 return (sbp->sb_versionnum & XFS_SB_VERSION_DALIGNBIT);
408}
409
410static inline bool xfs_sb_version_haslogv2(struct xfs_sb *sbp)
411{
412 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
413 (sbp->sb_versionnum & XFS_SB_VERSION_LOGV2BIT);
414}
415
416static inline bool xfs_sb_version_hasextflgbit(struct xfs_sb *sbp)
417{
418 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
419 (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT);
420}
421
422static inline bool xfs_sb_version_hassector(struct xfs_sb *sbp)
423{
424 return (sbp->sb_versionnum & XFS_SB_VERSION_SECTORBIT);
425}
426
427static inline bool xfs_sb_version_hasasciici(struct xfs_sb *sbp)
428{
429 return (sbp->sb_versionnum & XFS_SB_VERSION_BORGBIT);
430}
431
432static inline bool xfs_sb_version_hasmorebits(struct xfs_sb *sbp)
433{
434 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 ||
435 (sbp->sb_versionnum & XFS_SB_VERSION_MOREBITSBIT);
436}
437
438/*
439 * sb_features2 bit version macros.
440 */
441static inline bool xfs_sb_version_haslazysbcount(struct xfs_sb *sbp)
442{
443 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
444 (xfs_sb_version_hasmorebits(sbp) &&
445 (sbp->sb_features2 & XFS_SB_VERSION2_LAZYSBCOUNTBIT));
446}
447
448static inline bool xfs_sb_version_hasattr2(struct xfs_sb *sbp)
449{
450 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
451 (xfs_sb_version_hasmorebits(sbp) &&
452 (sbp->sb_features2 & XFS_SB_VERSION2_ATTR2BIT));
453}
454
455static inline void xfs_sb_version_addattr2(struct xfs_sb *sbp)
456{
457 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
458 sbp->sb_features2 |= XFS_SB_VERSION2_ATTR2BIT;
Christoph Hellwigbb58e612014-11-28 14:27:09 +1100459}
460
461static inline void xfs_sb_version_removeattr2(struct xfs_sb *sbp)
462{
463 sbp->sb_features2 &= ~XFS_SB_VERSION2_ATTR2BIT;
Christoph Hellwigbb58e612014-11-28 14:27:09 +1100464 if (!sbp->sb_features2)
465 sbp->sb_versionnum &= ~XFS_SB_VERSION_MOREBITSBIT;
466}
467
468static inline bool xfs_sb_version_hasprojid32bit(struct xfs_sb *sbp)
469{
470 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) ||
471 (xfs_sb_version_hasmorebits(sbp) &&
472 (sbp->sb_features2 & XFS_SB_VERSION2_PROJID32BIT));
473}
474
475static inline void xfs_sb_version_addprojid32bit(struct xfs_sb *sbp)
476{
477 sbp->sb_versionnum |= XFS_SB_VERSION_MOREBITSBIT;
478 sbp->sb_features2 |= XFS_SB_VERSION2_PROJID32BIT;
Christoph Hellwigbb58e612014-11-28 14:27:09 +1100479}
480
481/*
482 * Extended v5 superblock feature masks. These are to be used for new v5
483 * superblock features only.
484 *
485 * Compat features are new features that old kernels will not notice or affect
486 * and so can mount read-write without issues.
487 *
488 * RO-Compat (read only) are features that old kernels can read but will break
489 * if they write. Hence only read-only mounts of such filesystems are allowed on
490 * kernels that don't support the feature bit.
491 *
492 * InCompat features are features which old kernels will not understand and so
493 * must not mount.
494 *
495 * Log-InCompat features are for changes to log formats or new transactions that
496 * can't be replayed on older kernels. The fields are set when the filesystem is
497 * mounted, and a clean unmount clears the fields.
498 */
499#define XFS_SB_FEAT_COMPAT_ALL 0
500#define XFS_SB_FEAT_COMPAT_UNKNOWN ~XFS_SB_FEAT_COMPAT_ALL
501static inline bool
502xfs_sb_has_compat_feature(
503 struct xfs_sb *sbp,
504 __uint32_t feature)
505{
506 return (sbp->sb_features_compat & feature) != 0;
507}
508
509#define XFS_SB_FEAT_RO_COMPAT_FINOBT (1 << 0) /* free inode btree */
510#define XFS_SB_FEAT_RO_COMPAT_ALL \
511 (XFS_SB_FEAT_RO_COMPAT_FINOBT)
512#define XFS_SB_FEAT_RO_COMPAT_UNKNOWN ~XFS_SB_FEAT_RO_COMPAT_ALL
513static inline bool
514xfs_sb_has_ro_compat_feature(
515 struct xfs_sb *sbp,
516 __uint32_t feature)
517{
518 return (sbp->sb_features_ro_compat & feature) != 0;
519}
520
521#define XFS_SB_FEAT_INCOMPAT_FTYPE (1 << 0) /* filetype in dirent */
522#define XFS_SB_FEAT_INCOMPAT_ALL \
523 (XFS_SB_FEAT_INCOMPAT_FTYPE)
524
525#define XFS_SB_FEAT_INCOMPAT_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_ALL
526static inline bool
527xfs_sb_has_incompat_feature(
528 struct xfs_sb *sbp,
529 __uint32_t feature)
530{
531 return (sbp->sb_features_incompat & feature) != 0;
532}
533
534#define XFS_SB_FEAT_INCOMPAT_LOG_ALL 0
535#define XFS_SB_FEAT_INCOMPAT_LOG_UNKNOWN ~XFS_SB_FEAT_INCOMPAT_LOG_ALL
536static inline bool
537xfs_sb_has_incompat_log_feature(
538 struct xfs_sb *sbp,
539 __uint32_t feature)
540{
541 return (sbp->sb_features_log_incompat & feature) != 0;
542}
543
544/*
545 * V5 superblock specific feature checks
546 */
547static inline int xfs_sb_version_hascrc(struct xfs_sb *sbp)
548{
549 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
550}
551
552static inline int xfs_sb_version_has_pquotino(struct xfs_sb *sbp)
553{
554 return XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5;
555}
556
557static inline int xfs_sb_version_hasftype(struct xfs_sb *sbp)
558{
559 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5 &&
560 xfs_sb_has_incompat_feature(sbp, XFS_SB_FEAT_INCOMPAT_FTYPE)) ||
561 (xfs_sb_version_hasmorebits(sbp) &&
562 (sbp->sb_features2 & XFS_SB_VERSION2_FTYPE));
563}
564
565static inline int xfs_sb_version_hasfinobt(xfs_sb_t *sbp)
566{
567 return (XFS_SB_VERSION_NUM(sbp) == XFS_SB_VERSION_5) &&
568 (sbp->sb_features_ro_compat & XFS_SB_FEAT_RO_COMPAT_FINOBT);
569}
570
571/*
572 * end of superblock version macros
573 */
574
575static inline bool
576xfs_is_quota_inode(struct xfs_sb *sbp, xfs_ino_t ino)
577{
578 return (ino == sbp->sb_uquotino ||
579 ino == sbp->sb_gquotino ||
580 ino == sbp->sb_pquotino);
581}
582
583#define XFS_SB_DADDR ((xfs_daddr_t)0) /* daddr in filesystem/ag */
584#define XFS_SB_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_SB_DADDR)
585#define XFS_BUF_TO_SBP(bp) ((xfs_dsb_t *)((bp)->b_addr))
586
587#define XFS_HDR_BLOCK(mp,d) ((xfs_agblock_t)XFS_BB_TO_FSBT(mp,d))
588#define XFS_DADDR_TO_FSB(mp,d) XFS_AGB_TO_FSB(mp, \
589 xfs_daddr_to_agno(mp,d), xfs_daddr_to_agbno(mp,d))
590#define XFS_FSB_TO_DADDR(mp,fsbno) XFS_AGB_TO_DADDR(mp, \
591 XFS_FSB_TO_AGNO(mp,fsbno), XFS_FSB_TO_AGBNO(mp,fsbno))
592
593/*
594 * File system sector to basic block conversions.
595 */
596#define XFS_FSS_TO_BB(mp,sec) ((sec) << (mp)->m_sectbb_log)
597
598/*
599 * File system block to basic block conversions.
600 */
601#define XFS_FSB_TO_BB(mp,fsbno) ((fsbno) << (mp)->m_blkbb_log)
602#define XFS_BB_TO_FSB(mp,bb) \
603 (((bb) + (XFS_FSB_TO_BB(mp,1) - 1)) >> (mp)->m_blkbb_log)
604#define XFS_BB_TO_FSBT(mp,bb) ((bb) >> (mp)->m_blkbb_log)
605
606/*
607 * File system block to byte conversions.
608 */
609#define XFS_FSB_TO_B(mp,fsbno) ((xfs_fsize_t)(fsbno) << (mp)->m_sb.sb_blocklog)
610#define XFS_B_TO_FSB(mp,b) \
611 ((((__uint64_t)(b)) + (mp)->m_blockmask) >> (mp)->m_sb.sb_blocklog)
612#define XFS_B_TO_FSBT(mp,b) (((__uint64_t)(b)) >> (mp)->m_sb.sb_blocklog)
613#define XFS_B_FSB_OFFSET(mp,b) ((b) & (mp)->m_blockmask)
614
615/*
Christoph Hellwig4fb6e8a2014-11-28 14:25:04 +1100616 * Allocation group header
617 *
618 * This is divided into three structures, placed in sequential 512-byte
619 * buffers after a copy of the superblock (also in a 512-byte buffer).
620 */
621#define XFS_AGF_MAGIC 0x58414746 /* 'XAGF' */
622#define XFS_AGI_MAGIC 0x58414749 /* 'XAGI' */
623#define XFS_AGFL_MAGIC 0x5841464c /* 'XAFL' */
624#define XFS_AGF_VERSION 1
625#define XFS_AGI_VERSION 1
626
627#define XFS_AGF_GOOD_VERSION(v) ((v) == XFS_AGF_VERSION)
628#define XFS_AGI_GOOD_VERSION(v) ((v) == XFS_AGI_VERSION)
629
630/*
631 * Btree number 0 is bno, 1 is cnt. This value gives the size of the
632 * arrays below.
633 */
634#define XFS_BTNUM_AGF ((int)XFS_BTNUM_CNTi + 1)
635
636/*
637 * The second word of agf_levels in the first a.g. overlaps the EFS
638 * superblock's magic number. Since the magic numbers valid for EFS
639 * are > 64k, our value cannot be confused for an EFS superblock's.
640 */
641
642typedef struct xfs_agf {
643 /*
644 * Common allocation group header information
645 */
646 __be32 agf_magicnum; /* magic number == XFS_AGF_MAGIC */
647 __be32 agf_versionnum; /* header version == XFS_AGF_VERSION */
648 __be32 agf_seqno; /* sequence # starting from 0 */
649 __be32 agf_length; /* size in blocks of a.g. */
650 /*
651 * Freespace information
652 */
653 __be32 agf_roots[XFS_BTNUM_AGF]; /* root blocks */
654 __be32 agf_spare0; /* spare field */
655 __be32 agf_levels[XFS_BTNUM_AGF]; /* btree levels */
656 __be32 agf_spare1; /* spare field */
657
658 __be32 agf_flfirst; /* first freelist block's index */
659 __be32 agf_fllast; /* last freelist block's index */
660 __be32 agf_flcount; /* count of blocks in freelist */
661 __be32 agf_freeblks; /* total free blocks */
662
663 __be32 agf_longest; /* longest free space */
664 __be32 agf_btreeblks; /* # of blocks held in AGF btrees */
665 uuid_t agf_uuid; /* uuid of filesystem */
666
667 /*
668 * reserve some contiguous space for future logged fields before we add
669 * the unlogged fields. This makes the range logging via flags and
670 * structure offsets much simpler.
671 */
672 __be64 agf_spare64[16];
673
674 /* unlogged fields, written during buffer writeback. */
675 __be64 agf_lsn; /* last write sequence */
676 __be32 agf_crc; /* crc of agf sector */
677 __be32 agf_spare2;
678
679 /* structure must be padded to 64 bit alignment */
680} xfs_agf_t;
681
682#define XFS_AGF_CRC_OFF offsetof(struct xfs_agf, agf_crc)
683
684#define XFS_AGF_MAGICNUM 0x00000001
685#define XFS_AGF_VERSIONNUM 0x00000002
686#define XFS_AGF_SEQNO 0x00000004
687#define XFS_AGF_LENGTH 0x00000008
688#define XFS_AGF_ROOTS 0x00000010
689#define XFS_AGF_LEVELS 0x00000020
690#define XFS_AGF_FLFIRST 0x00000040
691#define XFS_AGF_FLLAST 0x00000080
692#define XFS_AGF_FLCOUNT 0x00000100
693#define XFS_AGF_FREEBLKS 0x00000200
694#define XFS_AGF_LONGEST 0x00000400
695#define XFS_AGF_BTREEBLKS 0x00000800
696#define XFS_AGF_UUID 0x00001000
697#define XFS_AGF_NUM_BITS 13
698#define XFS_AGF_ALL_BITS ((1 << XFS_AGF_NUM_BITS) - 1)
699
700#define XFS_AGF_FLAGS \
701 { XFS_AGF_MAGICNUM, "MAGICNUM" }, \
702 { XFS_AGF_VERSIONNUM, "VERSIONNUM" }, \
703 { XFS_AGF_SEQNO, "SEQNO" }, \
704 { XFS_AGF_LENGTH, "LENGTH" }, \
705 { XFS_AGF_ROOTS, "ROOTS" }, \
706 { XFS_AGF_LEVELS, "LEVELS" }, \
707 { XFS_AGF_FLFIRST, "FLFIRST" }, \
708 { XFS_AGF_FLLAST, "FLLAST" }, \
709 { XFS_AGF_FLCOUNT, "FLCOUNT" }, \
710 { XFS_AGF_FREEBLKS, "FREEBLKS" }, \
711 { XFS_AGF_LONGEST, "LONGEST" }, \
712 { XFS_AGF_BTREEBLKS, "BTREEBLKS" }, \
713 { XFS_AGF_UUID, "UUID" }
714
715/* disk block (xfs_daddr_t) in the AG */
716#define XFS_AGF_DADDR(mp) ((xfs_daddr_t)(1 << (mp)->m_sectbb_log))
717#define XFS_AGF_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGF_DADDR(mp))
718#define XFS_BUF_TO_AGF(bp) ((xfs_agf_t *)((bp)->b_addr))
719
720/*
721 * Size of the unlinked inode hash table in the agi.
722 */
723#define XFS_AGI_UNLINKED_BUCKETS 64
724
725typedef struct xfs_agi {
726 /*
727 * Common allocation group header information
728 */
729 __be32 agi_magicnum; /* magic number == XFS_AGI_MAGIC */
730 __be32 agi_versionnum; /* header version == XFS_AGI_VERSION */
731 __be32 agi_seqno; /* sequence # starting from 0 */
732 __be32 agi_length; /* size in blocks of a.g. */
733 /*
734 * Inode information
735 * Inodes are mapped by interpreting the inode number, so no
736 * mapping data is needed here.
737 */
738 __be32 agi_count; /* count of allocated inodes */
739 __be32 agi_root; /* root of inode btree */
740 __be32 agi_level; /* levels in inode btree */
741 __be32 agi_freecount; /* number of free inodes */
742
743 __be32 agi_newino; /* new inode just allocated */
744 __be32 agi_dirino; /* last directory inode chunk */
745 /*
746 * Hash table of inodes which have been unlinked but are
747 * still being referenced.
748 */
749 __be32 agi_unlinked[XFS_AGI_UNLINKED_BUCKETS];
750 /*
751 * This marks the end of logging region 1 and start of logging region 2.
752 */
753 uuid_t agi_uuid; /* uuid of filesystem */
754 __be32 agi_crc; /* crc of agi sector */
755 __be32 agi_pad32;
756 __be64 agi_lsn; /* last write sequence */
757
758 __be32 agi_free_root; /* root of the free inode btree */
759 __be32 agi_free_level;/* levels in free inode btree */
760
761 /* structure must be padded to 64 bit alignment */
762} xfs_agi_t;
763
764#define XFS_AGI_CRC_OFF offsetof(struct xfs_agi, agi_crc)
765
766#define XFS_AGI_MAGICNUM (1 << 0)
767#define XFS_AGI_VERSIONNUM (1 << 1)
768#define XFS_AGI_SEQNO (1 << 2)
769#define XFS_AGI_LENGTH (1 << 3)
770#define XFS_AGI_COUNT (1 << 4)
771#define XFS_AGI_ROOT (1 << 5)
772#define XFS_AGI_LEVEL (1 << 6)
773#define XFS_AGI_FREECOUNT (1 << 7)
774#define XFS_AGI_NEWINO (1 << 8)
775#define XFS_AGI_DIRINO (1 << 9)
776#define XFS_AGI_UNLINKED (1 << 10)
777#define XFS_AGI_NUM_BITS_R1 11 /* end of the 1st agi logging region */
778#define XFS_AGI_ALL_BITS_R1 ((1 << XFS_AGI_NUM_BITS_R1) - 1)
779#define XFS_AGI_FREE_ROOT (1 << 11)
780#define XFS_AGI_FREE_LEVEL (1 << 12)
781#define XFS_AGI_NUM_BITS_R2 13
782
783/* disk block (xfs_daddr_t) in the AG */
784#define XFS_AGI_DADDR(mp) ((xfs_daddr_t)(2 << (mp)->m_sectbb_log))
785#define XFS_AGI_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGI_DADDR(mp))
786#define XFS_BUF_TO_AGI(bp) ((xfs_agi_t *)((bp)->b_addr))
787
788/*
789 * The third a.g. block contains the a.g. freelist, an array
790 * of block pointers to blocks owned by the allocation btree code.
791 */
792#define XFS_AGFL_DADDR(mp) ((xfs_daddr_t)(3 << (mp)->m_sectbb_log))
793#define XFS_AGFL_BLOCK(mp) XFS_HDR_BLOCK(mp, XFS_AGFL_DADDR(mp))
794#define XFS_BUF_TO_AGFL(bp) ((xfs_agfl_t *)((bp)->b_addr))
795
796#define XFS_BUF_TO_AGFL_BNO(mp, bp) \
797 (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
798 &(XFS_BUF_TO_AGFL(bp)->agfl_bno[0]) : \
799 (__be32 *)(bp)->b_addr)
800
801/*
802 * Size of the AGFL. For CRC-enabled filesystes we steal a couple of
803 * slots in the beginning of the block for a proper header with the
804 * location information and CRC.
805 */
806#define XFS_AGFL_SIZE(mp) \
807 (((mp)->m_sb.sb_sectsize - \
808 (xfs_sb_version_hascrc(&((mp)->m_sb)) ? \
809 sizeof(struct xfs_agfl) : 0)) / \
810 sizeof(xfs_agblock_t))
811
812typedef struct xfs_agfl {
813 __be32 agfl_magicnum;
814 __be32 agfl_seqno;
815 uuid_t agfl_uuid;
816 __be64 agfl_lsn;
817 __be32 agfl_crc;
818 __be32 agfl_bno[]; /* actually XFS_AGFL_SIZE(mp) */
819} xfs_agfl_t;
820
821#define XFS_AGFL_CRC_OFF offsetof(struct xfs_agfl, agfl_crc)
822
823
824#define XFS_AG_MAXLEVELS(mp) ((mp)->m_ag_maxlevels)
825#define XFS_MIN_FREELIST_RAW(bl,cl,mp) \
826 (MIN(bl + 1, XFS_AG_MAXLEVELS(mp)) + MIN(cl + 1, XFS_AG_MAXLEVELS(mp)))
827#define XFS_MIN_FREELIST(a,mp) \
828 (XFS_MIN_FREELIST_RAW( \
829 be32_to_cpu((a)->agf_levels[XFS_BTNUM_BNOi]), \
830 be32_to_cpu((a)->agf_levels[XFS_BTNUM_CNTi]), mp))
831#define XFS_MIN_FREELIST_PAG(pag,mp) \
832 (XFS_MIN_FREELIST_RAW( \
833 (unsigned int)(pag)->pagf_levels[XFS_BTNUM_BNOi], \
834 (unsigned int)(pag)->pagf_levels[XFS_BTNUM_CNTi], mp))
835
836#define XFS_AGB_TO_FSB(mp,agno,agbno) \
837 (((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))
838#define XFS_FSB_TO_AGNO(mp,fsbno) \
839 ((xfs_agnumber_t)((fsbno) >> (mp)->m_sb.sb_agblklog))
840#define XFS_FSB_TO_AGBNO(mp,fsbno) \
841 ((xfs_agblock_t)((fsbno) & xfs_mask32lo((mp)->m_sb.sb_agblklog)))
842#define XFS_AGB_TO_DADDR(mp,agno,agbno) \
843 ((xfs_daddr_t)XFS_FSB_TO_BB(mp, \
844 (xfs_fsblock_t)(agno) * (mp)->m_sb.sb_agblocks + (agbno)))
845#define XFS_AG_DADDR(mp,agno,d) (XFS_AGB_TO_DADDR(mp, agno, 0) + (d))
846
847/*
848 * For checking for bad ranges of xfs_daddr_t's, covering multiple
849 * allocation groups or a single xfs_daddr_t that's a superblock copy.
850 */
851#define XFS_AG_CHECK_DADDR(mp,d,len) \
852 ((len) == 1 ? \
853 ASSERT((d) == XFS_SB_DADDR || \
854 xfs_daddr_to_agbno(mp, d) != XFS_SB_DADDR) : \
855 ASSERT(xfs_daddr_to_agno(mp, d) == \
856 xfs_daddr_to_agno(mp, (d) + (len) - 1)))
857
Christoph Hellwig6d3ebaa2014-11-28 14:24:06 +1100858typedef struct xfs_timestamp {
859 __be32 t_sec; /* timestamp seconds */
860 __be32 t_nsec; /* timestamp nanoseconds */
861} xfs_timestamp_t;
862
863/*
864 * On-disk inode structure.
865 *
866 * This is just the header or "dinode core", the inode is expanded to fill a
867 * variable size the leftover area split into a data and an attribute fork.
868 * The format of the data and attribute fork depends on the format of the
869 * inode as indicated by di_format and di_aformat. To access the data and
870 * attribute use the XFS_DFORK_DPTR, XFS_DFORK_APTR, and XFS_DFORK_PTR macros
871 * below.
872 *
873 * There is a very similar struct icdinode in xfs_inode which matches the
874 * layout of the first 96 bytes of this structure, but is kept in native
875 * format instead of big endian.
876 *
877 * Note: di_flushiter is only used by v1/2 inodes - it's effectively a zeroed
878 * padding field for v3 inodes.
879 */
880#define XFS_DINODE_MAGIC 0x494e /* 'IN' */
881#define XFS_DINODE_GOOD_VERSION(v) ((v) >= 1 && (v) <= 3)
882typedef struct xfs_dinode {
883 __be16 di_magic; /* inode magic # = XFS_DINODE_MAGIC */
884 __be16 di_mode; /* mode and type of file */
885 __u8 di_version; /* inode version */
886 __u8 di_format; /* format of di_c data */
887 __be16 di_onlink; /* old number of links to file */
888 __be32 di_uid; /* owner's user id */
889 __be32 di_gid; /* owner's group id */
890 __be32 di_nlink; /* number of links to file */
891 __be16 di_projid_lo; /* lower part of owner's project id */
892 __be16 di_projid_hi; /* higher part owner's project id */
893 __u8 di_pad[6]; /* unused, zeroed space */
894 __be16 di_flushiter; /* incremented on flush */
895 xfs_timestamp_t di_atime; /* time last accessed */
896 xfs_timestamp_t di_mtime; /* time last modified */
897 xfs_timestamp_t di_ctime; /* time created/inode modified */
898 __be64 di_size; /* number of bytes in file */
899 __be64 di_nblocks; /* # of direct & btree blocks used */
900 __be32 di_extsize; /* basic/minimum extent size for file */
901 __be32 di_nextents; /* number of extents in data fork */
902 __be16 di_anextents; /* number of extents in attribute fork*/
903 __u8 di_forkoff; /* attr fork offs, <<3 for 64b align */
904 __s8 di_aformat; /* format of attr fork's data */
905 __be32 di_dmevmask; /* DMIG event mask */
906 __be16 di_dmstate; /* DMIG state info */
907 __be16 di_flags; /* random flags, XFS_DIFLAG_... */
908 __be32 di_gen; /* generation number */
909
910 /* di_next_unlinked is the only non-core field in the old dinode */
911 __be32 di_next_unlinked;/* agi unlinked list ptr */
912
913 /* start of the extended dinode, writable fields */
914 __le32 di_crc; /* CRC of the inode */
915 __be64 di_changecount; /* number of attribute changes */
916 __be64 di_lsn; /* flush sequence */
917 __be64 di_flags2; /* more random flags */
918 __u8 di_pad2[16]; /* more padding for future expansion */
919
920 /* fields only written to during inode creation */
921 xfs_timestamp_t di_crtime; /* time created */
922 __be64 di_ino; /* inode number */
923 uuid_t di_uuid; /* UUID of the filesystem */
924
925 /* structure must be padded to 64 bit alignment */
926} xfs_dinode_t;
927
928#define XFS_DINODE_CRC_OFF offsetof(struct xfs_dinode, di_crc)
929
930#define DI_MAX_FLUSH 0xffff
931
932/*
933 * Size of the core inode on disk. Version 1 and 2 inodes have
934 * the same size, but version 3 has grown a few additional fields.
935 */
936static inline uint xfs_dinode_size(int version)
937{
938 if (version == 3)
939 return sizeof(struct xfs_dinode);
940 return offsetof(struct xfs_dinode, di_crc);
941}
942
943/*
944 * The 32 bit link count in the inode theoretically maxes out at UINT_MAX.
945 * Since the pathconf interface is signed, we use 2^31 - 1 instead.
946 * The old inode format had a 16 bit link count, so its maximum is USHRT_MAX.
947 */
948#define XFS_MAXLINK ((1U << 31) - 1U)
949#define XFS_MAXLINK_1 65535U
950
951/*
952 * Values for di_format
953 */
954typedef enum xfs_dinode_fmt {
955 XFS_DINODE_FMT_DEV, /* xfs_dev_t */
956 XFS_DINODE_FMT_LOCAL, /* bulk data */
957 XFS_DINODE_FMT_EXTENTS, /* struct xfs_bmbt_rec */
958 XFS_DINODE_FMT_BTREE, /* struct xfs_bmdr_block */
959 XFS_DINODE_FMT_UUID /* uuid_t */
960} xfs_dinode_fmt_t;
961
962/*
963 * Inode minimum and maximum sizes.
964 */
965#define XFS_DINODE_MIN_LOG 8
966#define XFS_DINODE_MAX_LOG 11
967#define XFS_DINODE_MIN_SIZE (1 << XFS_DINODE_MIN_LOG)
968#define XFS_DINODE_MAX_SIZE (1 << XFS_DINODE_MAX_LOG)
969
970/*
971 * Inode size for given fs.
972 */
973#define XFS_LITINO(mp, version) \
974 ((int)(((mp)->m_sb.sb_inodesize) - xfs_dinode_size(version)))
975
976/*
977 * Inode data & attribute fork sizes, per inode.
978 */
979#define XFS_DFORK_Q(dip) ((dip)->di_forkoff != 0)
980#define XFS_DFORK_BOFF(dip) ((int)((dip)->di_forkoff << 3))
981
982#define XFS_DFORK_DSIZE(dip,mp) \
983 (XFS_DFORK_Q(dip) ? \
984 XFS_DFORK_BOFF(dip) : \
985 XFS_LITINO(mp, (dip)->di_version))
986#define XFS_DFORK_ASIZE(dip,mp) \
987 (XFS_DFORK_Q(dip) ? \
988 XFS_LITINO(mp, (dip)->di_version) - XFS_DFORK_BOFF(dip) : \
989 0)
990#define XFS_DFORK_SIZE(dip,mp,w) \
991 ((w) == XFS_DATA_FORK ? \
992 XFS_DFORK_DSIZE(dip, mp) : \
993 XFS_DFORK_ASIZE(dip, mp))
994
995/*
996 * Return pointers to the data or attribute forks.
997 */
998#define XFS_DFORK_DPTR(dip) \
999 ((char *)dip + xfs_dinode_size(dip->di_version))
1000#define XFS_DFORK_APTR(dip) \
1001 (XFS_DFORK_DPTR(dip) + XFS_DFORK_BOFF(dip))
1002#define XFS_DFORK_PTR(dip,w) \
1003 ((w) == XFS_DATA_FORK ? XFS_DFORK_DPTR(dip) : XFS_DFORK_APTR(dip))
1004
1005#define XFS_DFORK_FORMAT(dip,w) \
1006 ((w) == XFS_DATA_FORK ? \
1007 (dip)->di_format : \
1008 (dip)->di_aformat)
1009#define XFS_DFORK_NEXTENTS(dip,w) \
1010 ((w) == XFS_DATA_FORK ? \
1011 be32_to_cpu((dip)->di_nextents) : \
1012 be16_to_cpu((dip)->di_anextents))
1013
1014/*
1015 * For block and character special files the 32bit dev_t is stored at the
1016 * beginning of the data fork.
1017 */
1018static inline xfs_dev_t xfs_dinode_get_rdev(struct xfs_dinode *dip)
1019{
1020 return be32_to_cpu(*(__be32 *)XFS_DFORK_DPTR(dip));
1021}
1022
1023static inline void xfs_dinode_put_rdev(struct xfs_dinode *dip, xfs_dev_t rdev)
1024{
1025 *(__be32 *)XFS_DFORK_DPTR(dip) = cpu_to_be32(rdev);
1026}
1027
1028/*
1029 * Values for di_flags
1030 * There should be a one-to-one correspondence between these flags and the
1031 * XFS_XFLAG_s.
1032 */
1033#define XFS_DIFLAG_REALTIME_BIT 0 /* file's blocks come from rt area */
1034#define XFS_DIFLAG_PREALLOC_BIT 1 /* file space has been preallocated */
1035#define XFS_DIFLAG_NEWRTBM_BIT 2 /* for rtbitmap inode, new format */
1036#define XFS_DIFLAG_IMMUTABLE_BIT 3 /* inode is immutable */
1037#define XFS_DIFLAG_APPEND_BIT 4 /* inode is append-only */
1038#define XFS_DIFLAG_SYNC_BIT 5 /* inode is written synchronously */
1039#define XFS_DIFLAG_NOATIME_BIT 6 /* do not update atime */
1040#define XFS_DIFLAG_NODUMP_BIT 7 /* do not dump */
1041#define XFS_DIFLAG_RTINHERIT_BIT 8 /* create with realtime bit set */
1042#define XFS_DIFLAG_PROJINHERIT_BIT 9 /* create with parents projid */
1043#define XFS_DIFLAG_NOSYMLINKS_BIT 10 /* disallow symlink creation */
1044#define XFS_DIFLAG_EXTSIZE_BIT 11 /* inode extent size allocator hint */
1045#define XFS_DIFLAG_EXTSZINHERIT_BIT 12 /* inherit inode extent size */
1046#define XFS_DIFLAG_NODEFRAG_BIT 13 /* do not reorganize/defragment */
1047#define XFS_DIFLAG_FILESTREAM_BIT 14 /* use filestream allocator */
1048#define XFS_DIFLAG_REALTIME (1 << XFS_DIFLAG_REALTIME_BIT)
1049#define XFS_DIFLAG_PREALLOC (1 << XFS_DIFLAG_PREALLOC_BIT)
1050#define XFS_DIFLAG_NEWRTBM (1 << XFS_DIFLAG_NEWRTBM_BIT)
1051#define XFS_DIFLAG_IMMUTABLE (1 << XFS_DIFLAG_IMMUTABLE_BIT)
1052#define XFS_DIFLAG_APPEND (1 << XFS_DIFLAG_APPEND_BIT)
1053#define XFS_DIFLAG_SYNC (1 << XFS_DIFLAG_SYNC_BIT)
1054#define XFS_DIFLAG_NOATIME (1 << XFS_DIFLAG_NOATIME_BIT)
1055#define XFS_DIFLAG_NODUMP (1 << XFS_DIFLAG_NODUMP_BIT)
1056#define XFS_DIFLAG_RTINHERIT (1 << XFS_DIFLAG_RTINHERIT_BIT)
1057#define XFS_DIFLAG_PROJINHERIT (1 << XFS_DIFLAG_PROJINHERIT_BIT)
1058#define XFS_DIFLAG_NOSYMLINKS (1 << XFS_DIFLAG_NOSYMLINKS_BIT)
1059#define XFS_DIFLAG_EXTSIZE (1 << XFS_DIFLAG_EXTSIZE_BIT)
1060#define XFS_DIFLAG_EXTSZINHERIT (1 << XFS_DIFLAG_EXTSZINHERIT_BIT)
1061#define XFS_DIFLAG_NODEFRAG (1 << XFS_DIFLAG_NODEFRAG_BIT)
1062#define XFS_DIFLAG_FILESTREAM (1 << XFS_DIFLAG_FILESTREAM_BIT)
1063
1064#define XFS_DIFLAG_ANY \
1065 (XFS_DIFLAG_REALTIME | XFS_DIFLAG_PREALLOC | XFS_DIFLAG_NEWRTBM | \
1066 XFS_DIFLAG_IMMUTABLE | XFS_DIFLAG_APPEND | XFS_DIFLAG_SYNC | \
1067 XFS_DIFLAG_NOATIME | XFS_DIFLAG_NODUMP | XFS_DIFLAG_RTINHERIT | \
1068 XFS_DIFLAG_PROJINHERIT | XFS_DIFLAG_NOSYMLINKS | XFS_DIFLAG_EXTSIZE | \
1069 XFS_DIFLAG_EXTSZINHERIT | XFS_DIFLAG_NODEFRAG | XFS_DIFLAG_FILESTREAM)
1070
Christoph Hellwig508b6b32014-11-28 14:27:10 +11001071/*
1072 * Inode number format:
1073 * low inopblog bits - offset in block
1074 * next agblklog bits - block number in ag
1075 * next agno_log bits - ag number
1076 * high agno_log-agblklog-inopblog bits - 0
1077 */
1078#define XFS_INO_MASK(k) (__uint32_t)((1ULL << (k)) - 1)
1079#define XFS_INO_OFFSET_BITS(mp) (mp)->m_sb.sb_inopblog
1080#define XFS_INO_AGBNO_BITS(mp) (mp)->m_sb.sb_agblklog
1081#define XFS_INO_AGINO_BITS(mp) (mp)->m_agino_log
1082#define XFS_INO_AGNO_BITS(mp) (mp)->m_agno_log
1083#define XFS_INO_BITS(mp) \
1084 XFS_INO_AGNO_BITS(mp) + XFS_INO_AGINO_BITS(mp)
1085#define XFS_INO_TO_AGNO(mp,i) \
1086 ((xfs_agnumber_t)((i) >> XFS_INO_AGINO_BITS(mp)))
1087#define XFS_INO_TO_AGINO(mp,i) \
1088 ((xfs_agino_t)(i) & XFS_INO_MASK(XFS_INO_AGINO_BITS(mp)))
1089#define XFS_INO_TO_AGBNO(mp,i) \
1090 (((xfs_agblock_t)(i) >> XFS_INO_OFFSET_BITS(mp)) & \
1091 XFS_INO_MASK(XFS_INO_AGBNO_BITS(mp)))
1092#define XFS_INO_TO_OFFSET(mp,i) \
1093 ((int)(i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
1094#define XFS_INO_TO_FSB(mp,i) \
1095 XFS_AGB_TO_FSB(mp, XFS_INO_TO_AGNO(mp,i), XFS_INO_TO_AGBNO(mp,i))
1096#define XFS_AGINO_TO_INO(mp,a,i) \
1097 (((xfs_ino_t)(a) << XFS_INO_AGINO_BITS(mp)) | (i))
1098#define XFS_AGINO_TO_AGBNO(mp,i) ((i) >> XFS_INO_OFFSET_BITS(mp))
1099#define XFS_AGINO_TO_OFFSET(mp,i) \
1100 ((i) & XFS_INO_MASK(XFS_INO_OFFSET_BITS(mp)))
1101#define XFS_OFFBNO_TO_AGINO(mp,b,o) \
1102 ((xfs_agino_t)(((b) << XFS_INO_OFFSET_BITS(mp)) | (o)))
1103
1104#define XFS_MAXINUMBER ((xfs_ino_t)((1ULL << 56) - 1ULL))
1105#define XFS_MAXINUMBER_32 ((xfs_ino_t)((1ULL << 32) - 1ULL))
Christoph Hellwig6d3ebaa2014-11-28 14:24:06 +11001106
Dave Chinner6ca1c902013-08-12 20:49:26 +10001107/*
Dave Chinnerc7298202013-08-12 20:49:29 +10001108 * RealTime Device format definitions
1109 */
1110
1111/* Min and max rt extent sizes, specified in bytes */
1112#define XFS_MAX_RTEXTSIZE (1024 * 1024 * 1024) /* 1GB */
1113#define XFS_DFL_RTEXTSIZE (64 * 1024) /* 64kB */
1114#define XFS_MIN_RTEXTSIZE (4 * 1024) /* 4kB */
1115
1116#define XFS_BLOCKSIZE(mp) ((mp)->m_sb.sb_blocksize)
1117#define XFS_BLOCKMASK(mp) ((mp)->m_blockmask)
1118#define XFS_BLOCKWSIZE(mp) ((mp)->m_blockwsize)
1119#define XFS_BLOCKWMASK(mp) ((mp)->m_blockwmask)
1120
1121/*
1122 * RT Summary and bit manipulation macros.
1123 */
1124#define XFS_SUMOFFS(mp,ls,bb) ((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
1125#define XFS_SUMOFFSTOBLOCK(mp,s) \
1126 (((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
1127#define XFS_SUMPTR(mp,bp,so) \
1128 ((xfs_suminfo_t *)((bp)->b_addr + \
1129 (((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
1130
1131#define XFS_BITTOBLOCK(mp,bi) ((bi) >> (mp)->m_blkbit_log)
1132#define XFS_BLOCKTOBIT(mp,bb) ((bb) << (mp)->m_blkbit_log)
1133#define XFS_BITTOWORD(mp,bi) \
1134 ((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp)))
1135
1136#define XFS_RTMIN(a,b) ((a) < (b) ? (a) : (b))
1137#define XFS_RTMAX(a,b) ((a) > (b) ? (a) : (b))
1138
1139#define XFS_RTLOBIT(w) xfs_lowbit32(w)
1140#define XFS_RTHIBIT(w) xfs_highbit32(w)
1141
Dave Chinnerc7298202013-08-12 20:49:29 +10001142#define XFS_RTBLOCKLOG(b) xfs_highbit64(b)
Dave Chinnerc7298202013-08-12 20:49:29 +10001143
1144/*
Dave Chinner6ca1c902013-08-12 20:49:26 +10001145 * Dquot and dquot block format definitions
1146 */
1147#define XFS_DQUOT_MAGIC 0x4451 /* 'DQ' */
1148#define XFS_DQUOT_VERSION (u_int8_t)0x01 /* latest version number */
1149
1150/*
1151 * This is the main portion of the on-disk representation of quota
1152 * information for a user. This is the q_core of the xfs_dquot_t that
1153 * is kept in kernel memory. We pad this with some more expansion room
1154 * to construct the on disk structure.
1155 */
1156typedef struct xfs_disk_dquot {
1157 __be16 d_magic; /* dquot magic = XFS_DQUOT_MAGIC */
1158 __u8 d_version; /* dquot version */
1159 __u8 d_flags; /* XFS_DQ_USER/PROJ/GROUP */
1160 __be32 d_id; /* user,project,group id */
1161 __be64 d_blk_hardlimit;/* absolute limit on disk blks */
1162 __be64 d_blk_softlimit;/* preferred limit on disk blks */
1163 __be64 d_ino_hardlimit;/* maximum # allocated inodes */
1164 __be64 d_ino_softlimit;/* preferred inode limit */
1165 __be64 d_bcount; /* disk blocks owned by the user */
1166 __be64 d_icount; /* inodes owned by the user */
1167 __be32 d_itimer; /* zero if within inode limits if not,
1168 this is when we refuse service */
1169 __be32 d_btimer; /* similar to above; for disk blocks */
1170 __be16 d_iwarns; /* warnings issued wrt num inodes */
1171 __be16 d_bwarns; /* warnings issued wrt disk blocks */
1172 __be32 d_pad0; /* 64 bit align */
1173 __be64 d_rtb_hardlimit;/* absolute limit on realtime blks */
1174 __be64 d_rtb_softlimit;/* preferred limit on RT disk blks */
1175 __be64 d_rtbcount; /* realtime blocks owned */
1176 __be32 d_rtbtimer; /* similar to above; for RT disk blocks */
1177 __be16 d_rtbwarns; /* warnings issued wrt RT disk blocks */
1178 __be16 d_pad;
1179} xfs_disk_dquot_t;
1180
1181/*
1182 * This is what goes on disk. This is separated from the xfs_disk_dquot because
1183 * carrying the unnecessary padding would be a waste of memory.
1184 */
1185typedef struct xfs_dqblk {
1186 xfs_disk_dquot_t dd_diskdq; /* portion that lives incore as well */
1187 char dd_fill[4]; /* filling for posterity */
1188
1189 /*
1190 * These two are only present on filesystems with the CRC bits set.
1191 */
1192 __be32 dd_crc; /* checksum */
1193 __be64 dd_lsn; /* last modification in log */
1194 uuid_t dd_uuid; /* location information */
1195} xfs_dqblk_t;
1196
1197#define XFS_DQUOT_CRC_OFF offsetof(struct xfs_dqblk, dd_crc)
1198
Dave Chinner1fb7e48d2013-08-12 20:49:40 +10001199/*
1200 * Remote symlink format and access functions.
1201 */
1202#define XFS_SYMLINK_MAGIC 0x58534c4d /* XSLM */
1203
1204struct xfs_dsymlink_hdr {
1205 __be32 sl_magic;
1206 __be32 sl_offset;
1207 __be32 sl_bytes;
1208 __be32 sl_crc;
1209 uuid_t sl_uuid;
1210 __be64 sl_owner;
1211 __be64 sl_blkno;
1212 __be64 sl_lsn;
1213};
1214
Eric Sandeen533b81c2014-02-27 15:15:27 +11001215#define XFS_SYMLINK_CRC_OFF offsetof(struct xfs_dsymlink_hdr, sl_crc)
1216
Dave Chinner1fb7e48d2013-08-12 20:49:40 +10001217/*
1218 * The maximum pathlen is 1024 bytes. Since the minimum file system
1219 * blocksize is 512 bytes, we can get a max of 3 extents back from
1220 * bmapi when crc headers are taken into account.
1221 */
1222#define XFS_SYMLINK_MAPS 3
1223
1224#define XFS_SYMLINK_BUF_SPACE(mp, bufsize) \
1225 ((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
1226 sizeof(struct xfs_dsymlink_hdr) : 0))
1227
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11001228
1229/*
1230 * Allocation Btree format definitions
1231 *
1232 * There are two on-disk btrees, one sorted by blockno and one sorted
1233 * by blockcount and blockno. All blocks look the same to make the code
1234 * simpler; if we have time later, we'll make the optimizations.
1235 */
1236#define XFS_ABTB_MAGIC 0x41425442 /* 'ABTB' for bno tree */
1237#define XFS_ABTB_CRC_MAGIC 0x41423342 /* 'AB3B' */
1238#define XFS_ABTC_MAGIC 0x41425443 /* 'ABTC' for cnt tree */
1239#define XFS_ABTC_CRC_MAGIC 0x41423343 /* 'AB3C' */
1240
1241/*
1242 * Data record/key structure
1243 */
1244typedef struct xfs_alloc_rec {
1245 __be32 ar_startblock; /* starting block number */
1246 __be32 ar_blockcount; /* count of free blocks */
1247} xfs_alloc_rec_t, xfs_alloc_key_t;
1248
1249typedef struct xfs_alloc_rec_incore {
1250 xfs_agblock_t ar_startblock; /* starting block number */
1251 xfs_extlen_t ar_blockcount; /* count of free blocks */
1252} xfs_alloc_rec_incore_t;
1253
1254/* btree pointer type */
1255typedef __be32 xfs_alloc_ptr_t;
1256
1257/*
1258 * Block numbers in the AG:
1259 * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
1260 */
1261#define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
1262#define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
1263
1264
1265/*
1266 * Inode Allocation Btree format definitions
1267 *
1268 * There is a btree for the inode map per allocation group.
1269 */
1270#define XFS_IBT_MAGIC 0x49414254 /* 'IABT' */
1271#define XFS_IBT_CRC_MAGIC 0x49414233 /* 'IAB3' */
Brian Fosteraafc3c22014-04-24 16:00:52 +10001272#define XFS_FIBT_MAGIC 0x46494254 /* 'FIBT' */
1273#define XFS_FIBT_CRC_MAGIC 0x46494233 /* 'FIB3' */
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11001274
1275typedef __uint64_t xfs_inofree_t;
1276#define XFS_INODES_PER_CHUNK (NBBY * sizeof(xfs_inofree_t))
1277#define XFS_INODES_PER_CHUNK_LOG (XFS_NBBYLOG + 3)
1278#define XFS_INOBT_ALL_FREE ((xfs_inofree_t)-1)
1279#define XFS_INOBT_MASK(i) ((xfs_inofree_t)1 << (i))
1280
1281static inline xfs_inofree_t xfs_inobt_maskn(int i, int n)
1282{
1283 return ((n >= XFS_INODES_PER_CHUNK ? 0 : XFS_INOBT_MASK(n)) - 1) << i;
1284}
1285
1286/*
1287 * Data record structure
1288 */
1289typedef struct xfs_inobt_rec {
1290 __be32 ir_startino; /* starting inode number */
1291 __be32 ir_freecount; /* count of free inodes (set bits) */
1292 __be64 ir_free; /* free inode mask */
1293} xfs_inobt_rec_t;
1294
1295typedef struct xfs_inobt_rec_incore {
1296 xfs_agino_t ir_startino; /* starting inode number */
1297 __int32_t ir_freecount; /* count of free inodes (set bits) */
1298 xfs_inofree_t ir_free; /* free inode mask */
1299} xfs_inobt_rec_incore_t;
1300
1301
1302/*
1303 * Key structure
1304 */
1305typedef struct xfs_inobt_key {
1306 __be32 ir_startino; /* starting inode number */
1307} xfs_inobt_key_t;
1308
1309/* btree pointer type */
1310typedef __be32 xfs_inobt_ptr_t;
1311
1312/*
1313 * block numbers in the AG.
1314 */
1315#define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
Brian Fosteraafc3c22014-04-24 16:00:52 +10001316#define XFS_FIBT_BLOCK(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
1317
1318/*
1319 * The first data block of an AG depends on whether the filesystem was formatted
1320 * with the finobt feature. If so, account for the finobt reserved root btree
1321 * block.
1322 */
1323#define XFS_PREALLOC_BLOCKS(mp) \
1324 (xfs_sb_version_hasfinobt(&((mp)->m_sb)) ? \
1325 XFS_FIBT_BLOCK(mp) + 1 : \
1326 XFS_IBT_BLOCK(mp) + 1)
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11001327
1328
1329
1330/*
1331 * BMAP Btree format definitions
1332 *
1333 * This includes both the root block definition that sits inside an inode fork
1334 * and the record/pointer formats for the leaf/node in the blocks.
1335 */
1336#define XFS_BMAP_MAGIC 0x424d4150 /* 'BMAP' */
1337#define XFS_BMAP_CRC_MAGIC 0x424d4133 /* 'BMA3' */
1338
1339/*
1340 * Bmap root header, on-disk form only.
1341 */
1342typedef struct xfs_bmdr_block {
1343 __be16 bb_level; /* 0 is a leaf */
1344 __be16 bb_numrecs; /* current # of data records */
1345} xfs_bmdr_block_t;
1346
1347/*
1348 * Bmap btree record and extent descriptor.
1349 * l0:63 is an extent flag (value 1 indicates non-normal).
1350 * l0:9-62 are startoff.
1351 * l0:0-8 and l1:21-63 are startblock.
1352 * l1:0-20 are blockcount.
1353 */
1354#define BMBT_EXNTFLAG_BITLEN 1
1355#define BMBT_STARTOFF_BITLEN 54
1356#define BMBT_STARTBLOCK_BITLEN 52
1357#define BMBT_BLOCKCOUNT_BITLEN 21
1358
1359typedef struct xfs_bmbt_rec {
1360 __be64 l0, l1;
1361} xfs_bmbt_rec_t;
1362
1363typedef __uint64_t xfs_bmbt_rec_base_t; /* use this for casts */
1364typedef xfs_bmbt_rec_t xfs_bmdr_rec_t;
1365
1366typedef struct xfs_bmbt_rec_host {
1367 __uint64_t l0, l1;
1368} xfs_bmbt_rec_host_t;
1369
1370/*
1371 * Values and macros for delayed-allocation startblock fields.
1372 */
1373#define STARTBLOCKVALBITS 17
Christoph Hellwigd5cf09b2014-07-30 09:12:05 +10001374#define STARTBLOCKMASKBITS (15 + 20)
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11001375#define STARTBLOCKMASK \
1376 (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11001377
1378static inline int isnullstartblock(xfs_fsblock_t x)
1379{
1380 return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK;
1381}
1382
Dave Chinnera4fbe6a2013-10-23 10:51:50 +11001383static inline xfs_fsblock_t nullstartblock(int k)
1384{
1385 ASSERT(k < (1 << STARTBLOCKVALBITS));
1386 return STARTBLOCKMASK | (k);
1387}
1388
1389static inline xfs_filblks_t startblockval(xfs_fsblock_t x)
1390{
1391 return (xfs_filblks_t)((x) & ~STARTBLOCKMASK);
1392}
1393
1394/*
1395 * Possible extent formats.
1396 */
1397typedef enum {
1398 XFS_EXTFMT_NOSTATE = 0,
1399 XFS_EXTFMT_HASSTATE
1400} xfs_exntfmt_t;
1401
1402/*
1403 * Possible extent states.
1404 */
1405typedef enum {
1406 XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
1407 XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID
1408} xfs_exntst_t;
1409
1410/*
1411 * Incore version of above.
1412 */
1413typedef struct xfs_bmbt_irec
1414{
1415 xfs_fileoff_t br_startoff; /* starting file offset */
1416 xfs_fsblock_t br_startblock; /* starting block number */
1417 xfs_filblks_t br_blockcount; /* number of blocks */
1418 xfs_exntst_t br_state; /* extent state */
1419} xfs_bmbt_irec_t;
1420
1421/*
1422 * Key structure for non-leaf levels of the tree.
1423 */
1424typedef struct xfs_bmbt_key {
1425 __be64 br_startoff; /* starting file offset */
1426} xfs_bmbt_key_t, xfs_bmdr_key_t;
1427
1428/* btree pointer type */
1429typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
1430
1431
1432/*
1433 * Generic Btree block format definitions
1434 *
1435 * This is a combination of the actual format used on disk for short and long
1436 * format btrees. The first three fields are shared by both format, but the
1437 * pointers are different and should be used with care.
1438 *
1439 * To get the size of the actual short or long form headers please use the size
1440 * macros below. Never use sizeof(xfs_btree_block).
1441 *
1442 * The blkno, crc, lsn, owner and uuid fields are only available in filesystems
1443 * with the crc feature bit, and all accesses to them must be conditional on
1444 * that flag.
1445 */
1446struct xfs_btree_block {
1447 __be32 bb_magic; /* magic number for block type */
1448 __be16 bb_level; /* 0 is a leaf */
1449 __be16 bb_numrecs; /* current # of data records */
1450 union {
1451 struct {
1452 __be32 bb_leftsib;
1453 __be32 bb_rightsib;
1454
1455 __be64 bb_blkno;
1456 __be64 bb_lsn;
1457 uuid_t bb_uuid;
1458 __be32 bb_owner;
1459 __le32 bb_crc;
1460 } s; /* short form pointers */
1461 struct {
1462 __be64 bb_leftsib;
1463 __be64 bb_rightsib;
1464
1465 __be64 bb_blkno;
1466 __be64 bb_lsn;
1467 uuid_t bb_uuid;
1468 __be64 bb_owner;
1469 __le32 bb_crc;
1470 __be32 bb_pad; /* padding for alignment */
1471 } l; /* long form pointers */
1472 } bb_u; /* rest */
1473};
1474
1475#define XFS_BTREE_SBLOCK_LEN 16 /* size of a short form block */
1476#define XFS_BTREE_LBLOCK_LEN 24 /* size of a long form block */
1477
1478/* sizes of CRC enabled btree blocks */
1479#define XFS_BTREE_SBLOCK_CRC_LEN (XFS_BTREE_SBLOCK_LEN + 40)
1480#define XFS_BTREE_LBLOCK_CRC_LEN (XFS_BTREE_LBLOCK_LEN + 48)
1481
1482#define XFS_BTREE_SBLOCK_CRC_OFF \
1483 offsetof(struct xfs_btree_block, bb_u.s.bb_crc)
1484#define XFS_BTREE_LBLOCK_CRC_OFF \
1485 offsetof(struct xfs_btree_block, bb_u.l.bb_crc)
1486
Christoph Hellwig5beda582014-11-28 14:24:37 +11001487/*
1488 * On-disk XFS access control list structure.
1489 */
1490struct xfs_acl_entry {
1491 __be32 ae_tag;
1492 __be32 ae_id;
1493 __be16 ae_perm;
1494 __be16 ae_pad; /* fill the implicit hole in the structure */
1495};
1496
1497struct xfs_acl {
1498 __be32 acl_cnt;
1499 struct xfs_acl_entry acl_entry[0];
1500};
1501
1502/*
1503 * The number of ACL entries allowed is defined by the on-disk format.
1504 * For v4 superblocks, that is limited to 25 entries. For v5 superblocks, it is
1505 * limited only by the maximum size of the xattr that stores the information.
1506 */
1507#define XFS_ACL_MAX_ENTRIES(mp) \
1508 (xfs_sb_version_hascrc(&mp->m_sb) \
1509 ? (XATTR_SIZE_MAX - sizeof(struct xfs_acl)) / \
1510 sizeof(struct xfs_acl_entry) \
1511 : 25)
1512
1513#define XFS_ACL_MAX_SIZE(mp) \
1514 (sizeof(struct xfs_acl) + \
1515 sizeof(struct xfs_acl_entry) * XFS_ACL_MAX_ENTRIES((mp)))
1516
1517/* On-disk XFS extended attribute names */
1518#define SGI_ACL_FILE (unsigned char *)"SGI_ACL_FILE"
1519#define SGI_ACL_DEFAULT (unsigned char *)"SGI_ACL_DEFAULT"
1520#define SGI_ACL_FILE_SIZE (sizeof(SGI_ACL_FILE)-1)
1521#define SGI_ACL_DEFAULT_SIZE (sizeof(SGI_ACL_DEFAULT)-1)
1522
Dave Chinner6ca1c902013-08-12 20:49:26 +10001523#endif /* __XFS_FORMAT_H__ */