1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#ifndef __XFS_LOG_FORMAT_H__
19#define __XFS_LOG_FORMAT_H__
20
21struct xfs_mount;
22struct xfs_trans_res;
23
24
25
26
27
28
29
30
31
32
33
34typedef __uint32_t xlog_tid_t;
35
36#define XLOG_MIN_ICLOGS 2
37#define XLOG_MAX_ICLOGS 8
38#define XLOG_HEADER_MAGIC_NUM 0xFEEDbabe
39#define XLOG_VERSION_1 1
40#define XLOG_VERSION_2 2
41#define XLOG_VERSION_OKBITS (XLOG_VERSION_1 | XLOG_VERSION_2)
42#define XLOG_MIN_RECORD_BSIZE (16*1024)
43#define XLOG_BIG_RECORD_BSIZE (32*1024)
44#define XLOG_MAX_RECORD_BSIZE (256*1024)
45#define XLOG_HEADER_CYCLE_SIZE (32*1024)
46#define XLOG_MIN_RECORD_BSHIFT 14
47#define XLOG_BIG_RECORD_BSHIFT 15
48#define XLOG_MAX_RECORD_BSHIFT 18
49#define XLOG_BTOLSUNIT(log, b) (((b)+(log)->l_mp->m_sb.sb_logsunit-1) / \
50 (log)->l_mp->m_sb.sb_logsunit)
51#define XLOG_LSUNITTOB(log, su) ((su) * (log)->l_mp->m_sb.sb_logsunit)
52
53#define XLOG_HEADER_SIZE 512
54
55
56#define XFS_MIN_LOG_FACTOR 3
57
58#define XLOG_REC_SHIFT(log) \
59 BTOBB(1 << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
60 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
61#define XLOG_TOTAL_REC_SHIFT(log) \
62 BTOBB(XLOG_MAX_ICLOGS << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
63 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
64
65
66#define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
67#define BLOCK_LSN(lsn) ((uint)(lsn))
68
69
70#define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
71
72static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
73{
74 return ((xfs_lsn_t)cycle << 32) | block;
75}
76
77static inline uint xlog_get_cycle(char *ptr)
78{
79 if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
80 return be32_to_cpu(*((__be32 *)ptr + 1));
81 else
82 return be32_to_cpu(*(__be32 *)ptr);
83}
84
85
86#define XFS_TRANSACTION 0x69
87#define XFS_VOLUME 0x2
88#define XFS_LOG 0xaa
89
90#define XLOG_UNMOUNT_TYPE 0x556e
91
92
93#define XLOG_REG_TYPE_BFORMAT 1
94#define XLOG_REG_TYPE_BCHUNK 2
95#define XLOG_REG_TYPE_EFI_FORMAT 3
96#define XLOG_REG_TYPE_EFD_FORMAT 4
97#define XLOG_REG_TYPE_IFORMAT 5
98#define XLOG_REG_TYPE_ICORE 6
99#define XLOG_REG_TYPE_IEXT 7
100#define XLOG_REG_TYPE_IBROOT 8
101#define XLOG_REG_TYPE_ILOCAL 9
102#define XLOG_REG_TYPE_IATTR_EXT 10
103#define XLOG_REG_TYPE_IATTR_BROOT 11
104#define XLOG_REG_TYPE_IATTR_LOCAL 12
105#define XLOG_REG_TYPE_QFORMAT 13
106#define XLOG_REG_TYPE_DQUOT 14
107#define XLOG_REG_TYPE_QUOTAOFF 15
108#define XLOG_REG_TYPE_LRHEADER 16
109#define XLOG_REG_TYPE_UNMOUNT 17
110#define XLOG_REG_TYPE_COMMIT 18
111#define XLOG_REG_TYPE_TRANSHDR 19
112#define XLOG_REG_TYPE_ICREATE 20
113#define XLOG_REG_TYPE_MAX 20
114
115
116
117
118
119
120
121
122
123
124
125
126#define XLOG_START_TRANS 0x01
127#define XLOG_COMMIT_TRANS 0x02
128#define XLOG_CONTINUE_TRANS 0x04
129#define XLOG_WAS_CONT_TRANS 0x08
130#define XLOG_END_TRANS 0x10
131#define XLOG_UNMOUNT_TRANS 0x20
132
133
134typedef struct xlog_op_header {
135 __be32 oh_tid;
136 __be32 oh_len;
137 __u8 oh_clientid;
138 __u8 oh_flags;
139 __u16 oh_res2;
140} xlog_op_header_t;
141
142
143#define XLOG_FMT_UNKNOWN 0
144#define XLOG_FMT_LINUX_LE 1
145#define XLOG_FMT_LINUX_BE 2
146#define XLOG_FMT_IRIX_BE 3
147
148
149#ifdef XFS_NATIVE_HOST
150#define XLOG_FMT XLOG_FMT_LINUX_BE
151#else
152#define XLOG_FMT XLOG_FMT_LINUX_LE
153#endif
154
155typedef struct xlog_rec_header {
156 __be32 h_magicno;
157 __be32 h_cycle;
158 __be32 h_version;
159 __be32 h_len;
160 __be64 h_lsn;
161 __be64 h_tail_lsn;
162 __le32 h_crc;
163 __be32 h_prev_block;
164 __be32 h_num_logops;
165 __be32 h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
166
167 __be32 h_fmt;
168 uuid_t h_fs_uuid;
169 __be32 h_size;
170} xlog_rec_header_t;
171
172typedef struct xlog_rec_ext_header {
173 __be32 xh_cycle;
174 __be32 xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
175} xlog_rec_ext_header_t;
176
177
178
179
180typedef union xlog_in_core2 {
181 xlog_rec_header_t hic_header;
182 xlog_rec_ext_header_t hic_xheader;
183 char hic_sector[XLOG_HEADER_SIZE];
184} xlog_in_core_2_t;
185
186
187typedef struct xfs_log_iovec {
188 void *i_addr;
189 int i_len;
190 uint i_type;
191} xfs_log_iovec_t;
192
193
194
195
196
197
198
199
200
201
202
203
204
205typedef struct xfs_trans_header {
206 uint th_magic;
207 uint th_type;
208 __int32_t th_tid;
209 uint th_num_items;
210} xfs_trans_header_t;
211
212#define XFS_TRANS_HEADER_MAGIC 0x5452414e
213
214
215
216
217#define XFS_TRANS_CHECKPOINT 40
218
219
220
221
222#define XFS_LI_EFI 0x1236
223#define XFS_LI_EFD 0x1237
224#define XFS_LI_IUNLINK 0x1238
225#define XFS_LI_INODE 0x123b
226#define XFS_LI_BUF 0x123c
227#define XFS_LI_DQUOT 0x123d
228#define XFS_LI_QUOTAOFF 0x123e
229#define XFS_LI_ICREATE 0x123f
230
231#define XFS_LI_TYPE_DESC \
232 { XFS_LI_EFI, "XFS_LI_EFI" }, \
233 { XFS_LI_EFD, "XFS_LI_EFD" }, \
234 { XFS_LI_IUNLINK, "XFS_LI_IUNLINK" }, \
235 { XFS_LI_INODE, "XFS_LI_INODE" }, \
236 { XFS_LI_BUF, "XFS_LI_BUF" }, \
237 { XFS_LI_DQUOT, "XFS_LI_DQUOT" }, \
238 { XFS_LI_QUOTAOFF, "XFS_LI_QUOTAOFF" }, \
239 { XFS_LI_ICREATE, "XFS_LI_ICREATE" }
240
241
242
243
244
245
246
247
248
249typedef struct xfs_inode_log_format {
250 __uint16_t ilf_type;
251 __uint16_t ilf_size;
252 __uint32_t ilf_fields;
253 __uint16_t ilf_asize;
254 __uint16_t ilf_dsize;
255 __uint64_t ilf_ino;
256 union {
257 __uint32_t ilfu_rdev;
258 uuid_t ilfu_uuid;
259 } ilf_u;
260 __int64_t ilf_blkno;
261 __int32_t ilf_len;
262 __int32_t ilf_boffset;
263} xfs_inode_log_format_t;
264
265typedef struct xfs_inode_log_format_32 {
266 __uint16_t ilf_type;
267 __uint16_t ilf_size;
268 __uint32_t ilf_fields;
269 __uint16_t ilf_asize;
270 __uint16_t ilf_dsize;
271 __uint64_t ilf_ino;
272 union {
273 __uint32_t ilfu_rdev;
274 uuid_t ilfu_uuid;
275 } ilf_u;
276 __int64_t ilf_blkno;
277 __int32_t ilf_len;
278 __int32_t ilf_boffset;
279} __attribute__((packed)) xfs_inode_log_format_32_t;
280
281typedef struct xfs_inode_log_format_64 {
282 __uint16_t ilf_type;
283 __uint16_t ilf_size;
284 __uint32_t ilf_fields;
285 __uint16_t ilf_asize;
286 __uint16_t ilf_dsize;
287 __uint32_t ilf_pad;
288 __uint64_t ilf_ino;
289 union {
290 __uint32_t ilfu_rdev;
291 uuid_t ilfu_uuid;
292 } ilf_u;
293 __int64_t ilf_blkno;
294 __int32_t ilf_len;
295 __int32_t ilf_boffset;
296} xfs_inode_log_format_64_t;
297
298
299
300
301
302#define XFS_ILOG_CORE 0x001
303#define XFS_ILOG_DDATA 0x002
304#define XFS_ILOG_DEXT 0x004
305#define XFS_ILOG_DBROOT 0x008
306#define XFS_ILOG_DEV 0x010
307#define XFS_ILOG_UUID 0x020
308#define XFS_ILOG_ADATA 0x040
309#define XFS_ILOG_AEXT 0x080
310#define XFS_ILOG_ABROOT 0x100
311#define XFS_ILOG_DOWNER 0x200
312#define XFS_ILOG_AOWNER 0x400
313
314
315
316
317
318
319
320
321#define XFS_ILOG_TIMESTAMP 0x4000
322
323#define XFS_ILOG_NONCORE (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
324 XFS_ILOG_DBROOT | XFS_ILOG_DEV | \
325 XFS_ILOG_UUID | XFS_ILOG_ADATA | \
326 XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \
327 XFS_ILOG_DOWNER | XFS_ILOG_AOWNER)
328
329#define XFS_ILOG_DFORK (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
330 XFS_ILOG_DBROOT)
331
332#define XFS_ILOG_AFORK (XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
333 XFS_ILOG_ABROOT)
334
335#define XFS_ILOG_ALL (XFS_ILOG_CORE | XFS_ILOG_DDATA | \
336 XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \
337 XFS_ILOG_DEV | XFS_ILOG_UUID | \
338 XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
339 XFS_ILOG_ABROOT | XFS_ILOG_TIMESTAMP | \
340 XFS_ILOG_DOWNER | XFS_ILOG_AOWNER)
341
342static inline int xfs_ilog_fbroot(int w)
343{
344 return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
345}
346
347static inline int xfs_ilog_fext(int w)
348{
349 return (w == XFS_DATA_FORK ? XFS_ILOG_DEXT : XFS_ILOG_AEXT);
350}
351
352static inline int xfs_ilog_fdata(int w)
353{
354 return (w == XFS_DATA_FORK ? XFS_ILOG_DDATA : XFS_ILOG_ADATA);
355}
356
357
358
359
360
361
362
363typedef struct xfs_ictimestamp {
364 __int32_t t_sec;
365 __int32_t t_nsec;
366} xfs_ictimestamp_t;
367
368
369
370
371
372struct xfs_log_dinode {
373 __uint16_t di_magic;
374 __uint16_t di_mode;
375 __int8_t di_version;
376 __int8_t di_format;
377 __uint8_t di_pad3[2];
378 __uint32_t di_uid;
379 __uint32_t di_gid;
380 __uint32_t di_nlink;
381 __uint16_t di_projid_lo;
382 __uint16_t di_projid_hi;
383 __uint8_t di_pad[6];
384 __uint16_t di_flushiter;
385 xfs_ictimestamp_t di_atime;
386 xfs_ictimestamp_t di_mtime;
387 xfs_ictimestamp_t di_ctime;
388 xfs_fsize_t di_size;
389 xfs_rfsblock_t di_nblocks;
390 xfs_extlen_t di_extsize;
391 xfs_extnum_t di_nextents;
392 xfs_aextnum_t di_anextents;
393 __uint8_t di_forkoff;
394 __int8_t di_aformat;
395 __uint32_t di_dmevmask;
396 __uint16_t di_dmstate;
397 __uint16_t di_flags;
398 __uint32_t di_gen;
399
400
401 xfs_agino_t di_next_unlinked;
402
403
404 __uint32_t di_crc;
405 __uint64_t di_changecount;
406 xfs_lsn_t di_lsn;
407 __uint64_t di_flags2;
408 __uint8_t di_pad2[16];
409
410
411 xfs_ictimestamp_t di_crtime;
412 xfs_ino_t di_ino;
413 uuid_t di_uuid;
414
415
416};
417
418static inline uint xfs_log_dinode_size(int version)
419{
420 if (version == 3)
421 return sizeof(struct xfs_log_dinode);
422 return offsetof(struct xfs_log_dinode, di_next_unlinked);
423}
424
425
426
427
428
429
430#define XFS_BLF_CHUNK 128
431#define XFS_BLF_SHIFT 7
432#define BIT_TO_WORD_SHIFT 5
433#define NBWORD (NBBY * sizeof(unsigned int))
434
435
436
437
438
439#define XFS_BLF_INODE_BUF (1<<0)
440
441
442
443
444
445#define XFS_BLF_CANCEL (1<<1)
446
447
448
449
450
451#define XFS_BLF_UDQUOT_BUF (1<<2)
452#define XFS_BLF_PDQUOT_BUF (1<<3)
453#define XFS_BLF_GDQUOT_BUF (1<<4)
454
455
456
457
458
459
460#define XFS_BLF_DATAMAP_SIZE ((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
461
462typedef struct xfs_buf_log_format {
463 unsigned short blf_type;
464 unsigned short blf_size;
465 ushort blf_flags;
466 ushort blf_len;
467 __int64_t blf_blkno;
468 unsigned int blf_map_size;
469 unsigned int blf_data_map[XFS_BLF_DATAMAP_SIZE];
470} xfs_buf_log_format_t;
471
472
473
474
475
476
477
478
479
480#define XFS_BLFT_BITS 5
481#define XFS_BLFT_SHIFT 11
482#define XFS_BLFT_MASK (((1 << XFS_BLFT_BITS) - 1) << XFS_BLFT_SHIFT)
483
484enum xfs_blft {
485 XFS_BLFT_UNKNOWN_BUF = 0,
486 XFS_BLFT_UDQUOT_BUF,
487 XFS_BLFT_PDQUOT_BUF,
488 XFS_BLFT_GDQUOT_BUF,
489 XFS_BLFT_BTREE_BUF,
490 XFS_BLFT_AGF_BUF,
491 XFS_BLFT_AGFL_BUF,
492 XFS_BLFT_AGI_BUF,
493 XFS_BLFT_DINO_BUF,
494 XFS_BLFT_SYMLINK_BUF,
495 XFS_BLFT_DIR_BLOCK_BUF,
496 XFS_BLFT_DIR_DATA_BUF,
497 XFS_BLFT_DIR_FREE_BUF,
498 XFS_BLFT_DIR_LEAF1_BUF,
499 XFS_BLFT_DIR_LEAFN_BUF,
500 XFS_BLFT_DA_NODE_BUF,
501 XFS_BLFT_ATTR_LEAF_BUF,
502 XFS_BLFT_ATTR_RMT_BUF,
503 XFS_BLFT_SB_BUF,
504 XFS_BLFT_RTBITMAP_BUF,
505 XFS_BLFT_RTSUMMARY_BUF,
506 XFS_BLFT_MAX_BUF = (1 << XFS_BLFT_BITS),
507};
508
509static inline void
510xfs_blft_to_flags(struct xfs_buf_log_format *blf, enum xfs_blft type)
511{
512 ASSERT(type > XFS_BLFT_UNKNOWN_BUF && type < XFS_BLFT_MAX_BUF);
513 blf->blf_flags &= ~XFS_BLFT_MASK;
514 blf->blf_flags |= ((type << XFS_BLFT_SHIFT) & XFS_BLFT_MASK);
515}
516
517static inline __uint16_t
518xfs_blft_from_flags(struct xfs_buf_log_format *blf)
519{
520 return (blf->blf_flags & XFS_BLFT_MASK) >> XFS_BLFT_SHIFT;
521}
522
523
524
525
526typedef struct xfs_extent {
527 xfs_fsblock_t ext_start;
528 xfs_extlen_t ext_len;
529} xfs_extent_t;
530
531
532
533
534
535
536
537typedef struct xfs_extent_32 {
538 __uint64_t ext_start;
539 __uint32_t ext_len;
540} __attribute__((packed)) xfs_extent_32_t;
541
542typedef struct xfs_extent_64 {
543 __uint64_t ext_start;
544 __uint32_t ext_len;
545 __uint32_t ext_pad;
546} xfs_extent_64_t;
547
548
549
550
551
552
553typedef struct xfs_efi_log_format {
554 __uint16_t efi_type;
555 __uint16_t efi_size;
556 __uint32_t efi_nextents;
557 __uint64_t efi_id;
558 xfs_extent_t efi_extents[1];
559} xfs_efi_log_format_t;
560
561typedef struct xfs_efi_log_format_32 {
562 __uint16_t efi_type;
563 __uint16_t efi_size;
564 __uint32_t efi_nextents;
565 __uint64_t efi_id;
566 xfs_extent_32_t efi_extents[1];
567} __attribute__((packed)) xfs_efi_log_format_32_t;
568
569typedef struct xfs_efi_log_format_64 {
570 __uint16_t efi_type;
571 __uint16_t efi_size;
572 __uint32_t efi_nextents;
573 __uint64_t efi_id;
574 xfs_extent_64_t efi_extents[1];
575} xfs_efi_log_format_64_t;
576
577
578
579
580
581
582typedef struct xfs_efd_log_format {
583 __uint16_t efd_type;
584 __uint16_t efd_size;
585 __uint32_t efd_nextents;
586 __uint64_t efd_efi_id;
587 xfs_extent_t efd_extents[1];
588} xfs_efd_log_format_t;
589
590typedef struct xfs_efd_log_format_32 {
591 __uint16_t efd_type;
592 __uint16_t efd_size;
593 __uint32_t efd_nextents;
594 __uint64_t efd_efi_id;
595 xfs_extent_32_t efd_extents[1];
596} __attribute__((packed)) xfs_efd_log_format_32_t;
597
598typedef struct xfs_efd_log_format_64 {
599 __uint16_t efd_type;
600 __uint16_t efd_size;
601 __uint32_t efd_nextents;
602 __uint64_t efd_efi_id;
603 xfs_extent_64_t efd_extents[1];
604} xfs_efd_log_format_64_t;
605
606
607
608
609
610
611
612typedef struct xfs_dq_logformat {
613 __uint16_t qlf_type;
614 __uint16_t qlf_size;
615 xfs_dqid_t qlf_id;
616 __int64_t qlf_blkno;
617 __int32_t qlf_len;
618 __uint32_t qlf_boffset;
619} xfs_dq_logformat_t;
620
621
622
623
624
625
626
627
628
629typedef struct xfs_qoff_logformat {
630 unsigned short qf_type;
631 unsigned short qf_size;
632 unsigned int qf_flags;
633 char qf_pad[12];
634} xfs_qoff_logformat_t;
635
636
637
638
639#define XFS_UQUOTA_ACCT 0x0001
640#define XFS_UQUOTA_ENFD 0x0002
641#define XFS_UQUOTA_CHKD 0x0004
642#define XFS_PQUOTA_ACCT 0x0008
643#define XFS_OQUOTA_ENFD 0x0010
644#define XFS_OQUOTA_CHKD 0x0020
645#define XFS_GQUOTA_ACCT 0x0040
646
647
648
649
650
651#define XFS_GQUOTA_ENFD 0x0080
652#define XFS_GQUOTA_CHKD 0x0100
653#define XFS_PQUOTA_ENFD 0x0200
654#define XFS_PQUOTA_CHKD 0x0400
655
656#define XFS_ALL_QUOTA_ACCT \
657 (XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
658#define XFS_ALL_QUOTA_ENFD \
659 (XFS_UQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_ENFD)
660#define XFS_ALL_QUOTA_CHKD \
661 (XFS_UQUOTA_CHKD | XFS_GQUOTA_CHKD | XFS_PQUOTA_CHKD)
662
663#define XFS_MOUNT_QUOTA_ALL (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
664 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
665 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD|\
666 XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD|\
667 XFS_PQUOTA_CHKD)
668
669
670
671
672
673
674
675
676struct xfs_icreate_log {
677 __uint16_t icl_type;
678 __uint16_t icl_size;
679 __be32 icl_ag;
680 __be32 icl_agbno;
681 __be32 icl_count;
682 __be32 icl_isize;
683 __be32 icl_length;
684 __be32 icl_gen;
685};
686
687#endif
688