• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
30 struct xfs_mount;
31 struct xfs_trans;
32 struct xfs_inode;
33 struct xfs_buf;
34 struct xfs_ifork;
35 
36 /*
37  * RealTime Device format definitions
38  */
39 
40 /* Min and max rt extent sizes, specified in bytes */
41 #define	XFS_MAX_RTEXTSIZE	(1024 * 1024 * 1024)	/* 1GB */
42 #define	XFS_DFL_RTEXTSIZE	(64 * 1024)	        /* 64kB */
43 #define	XFS_MIN_RTEXTSIZE	(4 * 1024)		/* 4kB */
44 
45 #define	XFS_BLOCKSIZE(mp)	((mp)->m_sb.sb_blocksize)
46 #define	XFS_BLOCKMASK(mp)	((mp)->m_blockmask)
47 #define	XFS_BLOCKWSIZE(mp)	((mp)->m_blockwsize)
48 #define	XFS_BLOCKWMASK(mp)	((mp)->m_blockwmask)
49 
50 /*
51  * RT Summary and bit manipulation macros.
52  */
53 #define	XFS_SUMOFFS(mp,ls,bb)	((int)((ls) * (mp)->m_sb.sb_rbmblocks + (bb)))
54 #define	XFS_SUMOFFSTOBLOCK(mp,s)	\
55 	(((s) * (uint)sizeof(xfs_suminfo_t)) >> (mp)->m_sb.sb_blocklog)
56 #define	XFS_SUMPTR(mp,bp,so)	\
57 	((xfs_suminfo_t *)((bp)->b_addr + \
58 		(((so) * (uint)sizeof(xfs_suminfo_t)) & XFS_BLOCKMASK(mp))))
59 
60 #define	XFS_BITTOBLOCK(mp,bi)	((bi) >> (mp)->m_blkbit_log)
61 #define	XFS_BLOCKTOBIT(mp,bb)	((bb) << (mp)->m_blkbit_log)
62 #define	XFS_BITTOWORD(mp,bi)	\
63 	((int)(((bi) >> XFS_NBWORDLOG) & XFS_BLOCKWMASK(mp)))
64 
65 #define	XFS_RTMIN(a,b)	((a) < (b) ? (a) : (b))
66 #define	XFS_RTMAX(a,b)	((a) > (b) ? (a) : (b))
67 
68 #define	XFS_RTLOBIT(w)	xfs_lowbit32(w)
69 #define	XFS_RTHIBIT(w)	xfs_highbit32(w)
70 
71 #define	XFS_RTBLOCKLOG(b)	xfs_highbit64(b)
72 
73 /*
74  * Dquot and dquot block format definitions
75  */
76 #define XFS_DQUOT_MAGIC		0x4451		/* 'DQ' */
77 #define XFS_DQUOT_VERSION	(u_int8_t)0x01	/* latest version number */
78 
79 /*
80  * This is the main portion of the on-disk representation of quota
81  * information for a user. This is the q_core of the xfs_dquot_t that
82  * is kept in kernel memory. We pad this with some more expansion room
83  * to construct the on disk structure.
84  */
85 typedef struct	xfs_disk_dquot {
86 	__be16		d_magic;	/* dquot magic = XFS_DQUOT_MAGIC */
87 	__u8		d_version;	/* dquot version */
88 	__u8		d_flags;	/* XFS_DQ_USER/PROJ/GROUP */
89 	__be32		d_id;		/* user,project,group id */
90 	__be64		d_blk_hardlimit;/* absolute limit on disk blks */
91 	__be64		d_blk_softlimit;/* preferred limit on disk blks */
92 	__be64		d_ino_hardlimit;/* maximum # allocated inodes */
93 	__be64		d_ino_softlimit;/* preferred inode limit */
94 	__be64		d_bcount;	/* disk blocks owned by the user */
95 	__be64		d_icount;	/* inodes owned by the user */
96 	__be32		d_itimer;	/* zero if within inode limits if not,
97 					   this is when we refuse service */
98 	__be32		d_btimer;	/* similar to above; for disk blocks */
99 	__be16		d_iwarns;	/* warnings issued wrt num inodes */
100 	__be16		d_bwarns;	/* warnings issued wrt disk blocks */
101 	__be32		d_pad0;		/* 64 bit align */
102 	__be64		d_rtb_hardlimit;/* absolute limit on realtime blks */
103 	__be64		d_rtb_softlimit;/* preferred limit on RT disk blks */
104 	__be64		d_rtbcount;	/* realtime blocks owned */
105 	__be32		d_rtbtimer;	/* similar to above; for RT disk blocks */
106 	__be16		d_rtbwarns;	/* warnings issued wrt RT disk blocks */
107 	__be16		d_pad;
108 } xfs_disk_dquot_t;
109 
110 /*
111  * This is what goes on disk. This is separated from the xfs_disk_dquot because
112  * carrying the unnecessary padding would be a waste of memory.
113  */
114 typedef struct xfs_dqblk {
115 	xfs_disk_dquot_t  dd_diskdq;	/* portion that lives incore as well */
116 	char		  dd_fill[4];	/* filling for posterity */
117 
118 	/*
119 	 * These two are only present on filesystems with the CRC bits set.
120 	 */
121 	__be32		  dd_crc;	/* checksum */
122 	__be64		  dd_lsn;	/* last modification in log */
123 	uuid_t		  dd_uuid;	/* location information */
124 } xfs_dqblk_t;
125 
126 #define XFS_DQUOT_CRC_OFF	offsetof(struct xfs_dqblk, dd_crc)
127 
128 /*
129  * Remote symlink format and access functions.
130  */
131 #define XFS_SYMLINK_MAGIC	0x58534c4d	/* XSLM */
132 
133 struct xfs_dsymlink_hdr {
134 	__be32	sl_magic;
135 	__be32	sl_offset;
136 	__be32	sl_bytes;
137 	__be32	sl_crc;
138 	uuid_t	sl_uuid;
139 	__be64	sl_owner;
140 	__be64	sl_blkno;
141 	__be64	sl_lsn;
142 };
143 
144 #define XFS_SYMLINK_CRC_OFF	offsetof(struct xfs_dsymlink_hdr, sl_crc)
145 
146 /*
147  * The maximum pathlen is 1024 bytes. Since the minimum file system
148  * blocksize is 512 bytes, we can get a max of 3 extents back from
149  * bmapi when crc headers are taken into account.
150  */
151 #define XFS_SYMLINK_MAPS 3
152 
153 #define XFS_SYMLINK_BUF_SPACE(mp, bufsize)	\
154 	((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
155 			sizeof(struct xfs_dsymlink_hdr) : 0))
156 
157 
158 /*
159  * Allocation Btree format definitions
160  *
161  * There are two on-disk btrees, one sorted by blockno and one sorted
162  * by blockcount and blockno.  All blocks look the same to make the code
163  * simpler; if we have time later, we'll make the optimizations.
164  */
165 #define	XFS_ABTB_MAGIC		0x41425442	/* 'ABTB' for bno tree */
166 #define	XFS_ABTB_CRC_MAGIC	0x41423342	/* 'AB3B' */
167 #define	XFS_ABTC_MAGIC		0x41425443	/* 'ABTC' for cnt tree */
168 #define	XFS_ABTC_CRC_MAGIC	0x41423343	/* 'AB3C' */
169 
170 /*
171  * Data record/key structure
172  */
173 typedef struct xfs_alloc_rec {
174 	__be32		ar_startblock;	/* starting block number */
175 	__be32		ar_blockcount;	/* count of free blocks */
176 } xfs_alloc_rec_t, xfs_alloc_key_t;
177 
178 typedef struct xfs_alloc_rec_incore {
179 	xfs_agblock_t	ar_startblock;	/* starting block number */
180 	xfs_extlen_t	ar_blockcount;	/* count of free blocks */
181 } xfs_alloc_rec_incore_t;
182 
183 /* btree pointer type */
184 typedef __be32 xfs_alloc_ptr_t;
185 
186 /*
187  * Block numbers in the AG:
188  * SB is sector 0, AGF is sector 1, AGI is sector 2, AGFL is sector 3.
189  */
190 #define	XFS_BNO_BLOCK(mp)	((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
191 #define	XFS_CNT_BLOCK(mp)	((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
192 
193 
194 /*
195  * Inode Allocation Btree format definitions
196  *
197  * There is a btree for the inode map per allocation group.
198  */
199 #define	XFS_IBT_MAGIC		0x49414254	/* 'IABT' */
200 #define	XFS_IBT_CRC_MAGIC	0x49414233	/* 'IAB3' */
201 #define	XFS_FIBT_MAGIC		0x46494254	/* 'FIBT' */
202 #define	XFS_FIBT_CRC_MAGIC	0x46494233	/* 'FIB3' */
203 
204 typedef	__uint64_t	xfs_inofree_t;
205 #define	XFS_INODES_PER_CHUNK		(NBBY * sizeof(xfs_inofree_t))
206 #define	XFS_INODES_PER_CHUNK_LOG	(XFS_NBBYLOG + 3)
207 #define	XFS_INOBT_ALL_FREE		((xfs_inofree_t)-1)
208 #define	XFS_INOBT_MASK(i)		((xfs_inofree_t)1 << (i))
209 
xfs_inobt_maskn(int i,int n)210 static inline xfs_inofree_t xfs_inobt_maskn(int i, int n)
211 {
212 	return ((n >= XFS_INODES_PER_CHUNK ? 0 : XFS_INOBT_MASK(n)) - 1) << i;
213 }
214 
215 /*
216  * Data record structure
217  */
218 typedef struct xfs_inobt_rec {
219 	__be32		ir_startino;	/* starting inode number */
220 	__be32		ir_freecount;	/* count of free inodes (set bits) */
221 	__be64		ir_free;	/* free inode mask */
222 } xfs_inobt_rec_t;
223 
224 typedef struct xfs_inobt_rec_incore {
225 	xfs_agino_t	ir_startino;	/* starting inode number */
226 	__int32_t	ir_freecount;	/* count of free inodes (set bits) */
227 	xfs_inofree_t	ir_free;	/* free inode mask */
228 } xfs_inobt_rec_incore_t;
229 
230 
231 /*
232  * Key structure
233  */
234 typedef struct xfs_inobt_key {
235 	__be32		ir_startino;	/* starting inode number */
236 } xfs_inobt_key_t;
237 
238 /* btree pointer type */
239 typedef __be32 xfs_inobt_ptr_t;
240 
241 /*
242  * block numbers in the AG.
243  */
244 #define	XFS_IBT_BLOCK(mp)		((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
245 #define	XFS_FIBT_BLOCK(mp)		((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
246 
247 /*
248  * The first data block of an AG depends on whether the filesystem was formatted
249  * with the finobt feature. If so, account for the finobt reserved root btree
250  * block.
251  */
252 #define XFS_PREALLOC_BLOCKS(mp) \
253 	(xfs_sb_version_hasfinobt(&((mp)->m_sb)) ? \
254 	 XFS_FIBT_BLOCK(mp) + 1 : \
255 	 XFS_IBT_BLOCK(mp) + 1)
256 
257 
258 
259 /*
260  * BMAP Btree format definitions
261  *
262  * This includes both the root block definition that sits inside an inode fork
263  * and the record/pointer formats for the leaf/node in the blocks.
264  */
265 #define XFS_BMAP_MAGIC		0x424d4150	/* 'BMAP' */
266 #define XFS_BMAP_CRC_MAGIC	0x424d4133	/* 'BMA3' */
267 
268 /*
269  * Bmap root header, on-disk form only.
270  */
271 typedef struct xfs_bmdr_block {
272 	__be16		bb_level;	/* 0 is a leaf */
273 	__be16		bb_numrecs;	/* current # of data records */
274 } xfs_bmdr_block_t;
275 
276 /*
277  * Bmap btree record and extent descriptor.
278  *  l0:63 is an extent flag (value 1 indicates non-normal).
279  *  l0:9-62 are startoff.
280  *  l0:0-8 and l1:21-63 are startblock.
281  *  l1:0-20 are blockcount.
282  */
283 #define BMBT_EXNTFLAG_BITLEN	1
284 #define BMBT_STARTOFF_BITLEN	54
285 #define BMBT_STARTBLOCK_BITLEN	52
286 #define BMBT_BLOCKCOUNT_BITLEN	21
287 
288 typedef struct xfs_bmbt_rec {
289 	__be64			l0, l1;
290 } xfs_bmbt_rec_t;
291 
292 typedef __uint64_t	xfs_bmbt_rec_base_t;	/* use this for casts */
293 typedef xfs_bmbt_rec_t xfs_bmdr_rec_t;
294 
295 typedef struct xfs_bmbt_rec_host {
296 	__uint64_t		l0, l1;
297 } xfs_bmbt_rec_host_t;
298 
299 /*
300  * Values and macros for delayed-allocation startblock fields.
301  */
302 #define STARTBLOCKVALBITS	17
303 #define STARTBLOCKMASKBITS	(15 + 20)
304 #define STARTBLOCKMASK		\
305 	(((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
306 
isnullstartblock(xfs_fsblock_t x)307 static inline int isnullstartblock(xfs_fsblock_t x)
308 {
309 	return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK;
310 }
311 
nullstartblock(int k)312 static inline xfs_fsblock_t nullstartblock(int k)
313 {
314 	ASSERT(k < (1 << STARTBLOCKVALBITS));
315 	return STARTBLOCKMASK | (k);
316 }
317 
startblockval(xfs_fsblock_t x)318 static inline xfs_filblks_t startblockval(xfs_fsblock_t x)
319 {
320 	return (xfs_filblks_t)((x) & ~STARTBLOCKMASK);
321 }
322 
323 /*
324  * Possible extent formats.
325  */
326 typedef enum {
327 	XFS_EXTFMT_NOSTATE = 0,
328 	XFS_EXTFMT_HASSTATE
329 } xfs_exntfmt_t;
330 
331 /*
332  * Possible extent states.
333  */
334 typedef enum {
335 	XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
336 	XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID
337 } xfs_exntst_t;
338 
339 /*
340  * Incore version of above.
341  */
342 typedef struct xfs_bmbt_irec
343 {
344 	xfs_fileoff_t	br_startoff;	/* starting file offset */
345 	xfs_fsblock_t	br_startblock;	/* starting block number */
346 	xfs_filblks_t	br_blockcount;	/* number of blocks */
347 	xfs_exntst_t	br_state;	/* extent state */
348 } xfs_bmbt_irec_t;
349 
350 /*
351  * Key structure for non-leaf levels of the tree.
352  */
353 typedef struct xfs_bmbt_key {
354 	__be64		br_startoff;	/* starting file offset */
355 } xfs_bmbt_key_t, xfs_bmdr_key_t;
356 
357 /* btree pointer type */
358 typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
359 
360 
361 /*
362  * Generic Btree block format definitions
363  *
364  * This is a combination of the actual format used on disk for short and long
365  * format btrees.  The first three fields are shared by both format, but the
366  * pointers are different and should be used with care.
367  *
368  * To get the size of the actual short or long form headers please use the size
369  * macros below.  Never use sizeof(xfs_btree_block).
370  *
371  * The blkno, crc, lsn, owner and uuid fields are only available in filesystems
372  * with the crc feature bit, and all accesses to them must be conditional on
373  * that flag.
374  */
375 struct xfs_btree_block {
376 	__be32		bb_magic;	/* magic number for block type */
377 	__be16		bb_level;	/* 0 is a leaf */
378 	__be16		bb_numrecs;	/* current # of data records */
379 	union {
380 		struct {
381 			__be32		bb_leftsib;
382 			__be32		bb_rightsib;
383 
384 			__be64		bb_blkno;
385 			__be64		bb_lsn;
386 			uuid_t		bb_uuid;
387 			__be32		bb_owner;
388 			__le32		bb_crc;
389 		} s;			/* short form pointers */
390 		struct	{
391 			__be64		bb_leftsib;
392 			__be64		bb_rightsib;
393 
394 			__be64		bb_blkno;
395 			__be64		bb_lsn;
396 			uuid_t		bb_uuid;
397 			__be64		bb_owner;
398 			__le32		bb_crc;
399 			__be32		bb_pad; /* padding for alignment */
400 		} l;			/* long form pointers */
401 	} bb_u;				/* rest */
402 };
403 
404 #define XFS_BTREE_SBLOCK_LEN	16	/* size of a short form block */
405 #define XFS_BTREE_LBLOCK_LEN	24	/* size of a long form block */
406 
407 /* sizes of CRC enabled btree blocks */
408 #define XFS_BTREE_SBLOCK_CRC_LEN	(XFS_BTREE_SBLOCK_LEN + 40)
409 #define XFS_BTREE_LBLOCK_CRC_LEN	(XFS_BTREE_LBLOCK_LEN + 48)
410 
411 #define XFS_BTREE_SBLOCK_CRC_OFF \
412 	offsetof(struct xfs_btree_block, bb_u.s.bb_crc)
413 #define XFS_BTREE_LBLOCK_CRC_OFF \
414 	offsetof(struct xfs_btree_block, bb_u.l.bb_crc)
415 
416 #endif /* __XFS_FORMAT_H__ */
417