1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __XFS_FORMAT_H__
19#define __XFS_FORMAT_H__
20
21
22
23
24
25
26
27
28
29
30struct xfs_mount;
31struct xfs_trans;
32struct xfs_inode;
33struct xfs_buf;
34struct xfs_ifork;
35
36
37
38
39
40
41#define XFS_MAX_RTEXTSIZE (1024 * 1024 * 1024)
42#define XFS_DFL_RTEXTSIZE (64 * 1024)
43#define XFS_MIN_RTEXTSIZE (4 * 1024)
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
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#if XFS_BIG_BLKNOS
72#define XFS_RTBLOCKLOG(b) xfs_highbit64(b)
73#else
74#define XFS_RTBLOCKLOG(b) xfs_highbit32(b)
75#endif
76
77
78
79
80#define XFS_DQUOT_MAGIC 0x4451
81#define XFS_DQUOT_VERSION (u_int8_t)0x01
82
83
84
85
86
87
88
89typedef struct xfs_disk_dquot {
90 __be16 d_magic;
91 __u8 d_version;
92 __u8 d_flags;
93 __be32 d_id;
94 __be64 d_blk_hardlimit;
95 __be64 d_blk_softlimit;
96 __be64 d_ino_hardlimit;
97 __be64 d_ino_softlimit;
98 __be64 d_bcount;
99 __be64 d_icount;
100 __be32 d_itimer;
101
102 __be32 d_btimer;
103 __be16 d_iwarns;
104 __be16 d_bwarns;
105 __be32 d_pad0;
106 __be64 d_rtb_hardlimit;
107 __be64 d_rtb_softlimit;
108 __be64 d_rtbcount;
109 __be32 d_rtbtimer;
110 __be16 d_rtbwarns;
111 __be16 d_pad;
112} xfs_disk_dquot_t;
113
114
115
116
117
118typedef struct xfs_dqblk {
119 xfs_disk_dquot_t dd_diskdq;
120 char dd_fill[4];
121
122
123
124
125 __be32 dd_crc;
126 __be64 dd_lsn;
127 uuid_t dd_uuid;
128} xfs_dqblk_t;
129
130#define XFS_DQUOT_CRC_OFF offsetof(struct xfs_dqblk, dd_crc)
131
132
133
134
135#define XFS_SYMLINK_MAGIC 0x58534c4d
136
137struct xfs_dsymlink_hdr {
138 __be32 sl_magic;
139 __be32 sl_offset;
140 __be32 sl_bytes;
141 __be32 sl_crc;
142 uuid_t sl_uuid;
143 __be64 sl_owner;
144 __be64 sl_blkno;
145 __be64 sl_lsn;
146};
147
148
149
150
151
152
153#define XFS_SYMLINK_MAPS 3
154
155#define XFS_SYMLINK_BUF_SPACE(mp, bufsize) \
156 ((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
157 sizeof(struct xfs_dsymlink_hdr) : 0))
158
159
160
161
162
163
164
165
166
167#define XFS_ABTB_MAGIC 0x41425442
168#define XFS_ABTB_CRC_MAGIC 0x41423342
169#define XFS_ABTC_MAGIC 0x41425443
170#define XFS_ABTC_CRC_MAGIC 0x41423343
171
172
173
174
175typedef struct xfs_alloc_rec {
176 __be32 ar_startblock;
177 __be32 ar_blockcount;
178} xfs_alloc_rec_t, xfs_alloc_key_t;
179
180typedef struct xfs_alloc_rec_incore {
181 xfs_agblock_t ar_startblock;
182 xfs_extlen_t ar_blockcount;
183} xfs_alloc_rec_incore_t;
184
185
186typedef __be32 xfs_alloc_ptr_t;
187
188
189
190
191
192#define XFS_BNO_BLOCK(mp) ((xfs_agblock_t)(XFS_AGFL_BLOCK(mp) + 1))
193#define XFS_CNT_BLOCK(mp) ((xfs_agblock_t)(XFS_BNO_BLOCK(mp) + 1))
194
195
196
197
198
199
200
201#define XFS_IBT_MAGIC 0x49414254
202#define XFS_IBT_CRC_MAGIC 0x49414233
203
204typedef __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
210static 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
217
218typedef struct xfs_inobt_rec {
219 __be32 ir_startino;
220 __be32 ir_freecount;
221 __be64 ir_free;
222} xfs_inobt_rec_t;
223
224typedef struct xfs_inobt_rec_incore {
225 xfs_agino_t ir_startino;
226 __int32_t ir_freecount;
227 xfs_inofree_t ir_free;
228} xfs_inobt_rec_incore_t;
229
230
231
232
233
234typedef struct xfs_inobt_key {
235 __be32 ir_startino;
236} xfs_inobt_key_t;
237
238
239typedef __be32 xfs_inobt_ptr_t;
240
241
242
243
244#define XFS_IBT_BLOCK(mp) ((xfs_agblock_t)(XFS_CNT_BLOCK(mp) + 1))
245#define XFS_PREALLOC_BLOCKS(mp) ((xfs_agblock_t)(XFS_IBT_BLOCK(mp) + 1))
246
247
248
249
250
251
252
253
254
255#define XFS_BMAP_MAGIC 0x424d4150
256#define XFS_BMAP_CRC_MAGIC 0x424d4133
257
258
259
260
261typedef struct xfs_bmdr_block {
262 __be16 bb_level;
263 __be16 bb_numrecs;
264} xfs_bmdr_block_t;
265
266
267
268
269
270
271
272
273#define BMBT_EXNTFLAG_BITLEN 1
274#define BMBT_STARTOFF_BITLEN 54
275#define BMBT_STARTBLOCK_BITLEN 52
276#define BMBT_BLOCKCOUNT_BITLEN 21
277
278typedef struct xfs_bmbt_rec {
279 __be64 l0, l1;
280} xfs_bmbt_rec_t;
281
282typedef __uint64_t xfs_bmbt_rec_base_t;
283typedef xfs_bmbt_rec_t xfs_bmdr_rec_t;
284
285typedef struct xfs_bmbt_rec_host {
286 __uint64_t l0, l1;
287} xfs_bmbt_rec_host_t;
288
289
290
291
292#define STARTBLOCKVALBITS 17
293#define STARTBLOCKMASKBITS (15 + XFS_BIG_BLKNOS * 20)
294#define DSTARTBLOCKMASKBITS (15 + 20)
295#define STARTBLOCKMASK \
296 (((((xfs_fsblock_t)1) << STARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
297#define DSTARTBLOCKMASK \
298 (((((xfs_dfsbno_t)1) << DSTARTBLOCKMASKBITS) - 1) << STARTBLOCKVALBITS)
299
300static inline int isnullstartblock(xfs_fsblock_t x)
301{
302 return ((x) & STARTBLOCKMASK) == STARTBLOCKMASK;
303}
304
305static inline int isnulldstartblock(xfs_dfsbno_t x)
306{
307 return ((x) & DSTARTBLOCKMASK) == DSTARTBLOCKMASK;
308}
309
310static inline xfs_fsblock_t nullstartblock(int k)
311{
312 ASSERT(k < (1 << STARTBLOCKVALBITS));
313 return STARTBLOCKMASK | (k);
314}
315
316static inline xfs_filblks_t startblockval(xfs_fsblock_t x)
317{
318 return (xfs_filblks_t)((x) & ~STARTBLOCKMASK);
319}
320
321
322
323
324typedef enum {
325 XFS_EXTFMT_NOSTATE = 0,
326 XFS_EXTFMT_HASSTATE
327} xfs_exntfmt_t;
328
329
330
331
332typedef enum {
333 XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
334 XFS_EXT_DMAPI_OFFLINE, XFS_EXT_INVALID
335} xfs_exntst_t;
336
337
338
339
340typedef struct xfs_bmbt_irec
341{
342 xfs_fileoff_t br_startoff;
343 xfs_fsblock_t br_startblock;
344 xfs_filblks_t br_blockcount;
345 xfs_exntst_t br_state;
346} xfs_bmbt_irec_t;
347
348
349
350
351typedef struct xfs_bmbt_key {
352 __be64 br_startoff;
353} xfs_bmbt_key_t, xfs_bmdr_key_t;
354
355
356typedef __be64 xfs_bmbt_ptr_t, xfs_bmdr_ptr_t;
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373struct xfs_btree_block {
374 __be32 bb_magic;
375 __be16 bb_level;
376 __be16 bb_numrecs;
377 union {
378 struct {
379 __be32 bb_leftsib;
380 __be32 bb_rightsib;
381
382 __be64 bb_blkno;
383 __be64 bb_lsn;
384 uuid_t bb_uuid;
385 __be32 bb_owner;
386 __le32 bb_crc;
387 } s;
388 struct {
389 __be64 bb_leftsib;
390 __be64 bb_rightsib;
391
392 __be64 bb_blkno;
393 __be64 bb_lsn;
394 uuid_t bb_uuid;
395 __be64 bb_owner;
396 __le32 bb_crc;
397 __be32 bb_pad;
398 } l;
399 } bb_u;
400};
401
402#define XFS_BTREE_SBLOCK_LEN 16
403#define XFS_BTREE_LBLOCK_LEN 24
404
405
406#define XFS_BTREE_SBLOCK_CRC_LEN (XFS_BTREE_SBLOCK_LEN + 40)
407#define XFS_BTREE_LBLOCK_CRC_LEN (XFS_BTREE_LBLOCK_LEN + 48)
408
409#define XFS_BTREE_SBLOCK_CRC_OFF \
410 offsetof(struct xfs_btree_block, bb_u.s.bb_crc)
411#define XFS_BTREE_LBLOCK_CRC_OFF \
412 offsetof(struct xfs_btree_block, bb_u.l.bb_crc)
413
414#endif
415