1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4 * All Rights Reserved.
5 */
6#ifndef __XFS_LOG_FORMAT_H__
7#define __XFS_LOG_FORMAT_H__
8
9struct xfs_mount;
10struct xfs_trans_res;
11
12/*
13 * On-disk Log Format definitions.
14 *
15 * This file contains all the on-disk format definitions used within the log. It
16 * includes the physical log structure itself, as well as all the log item
17 * format structures that are written into the log and intepreted by log
18 * recovery. We start with the physical log format definitions, and then work
19 * through all the log items definitions and everything they encode into the
20 * log.
21 */
22typedef uint32_t xlog_tid_t;
23
24#define XLOG_MIN_ICLOGS 2
25#define XLOG_MAX_ICLOGS 8
26#define XLOG_HEADER_MAGIC_NUM 0xFEEDbabe /* Invalid cycle number */
27#define XLOG_VERSION_1 1
28#define XLOG_VERSION_2 2 /* Large IClogs, Log sunit */
29#define XLOG_VERSION_OKBITS (XLOG_VERSION_1 | XLOG_VERSION_2)
30#define XLOG_MIN_RECORD_BSIZE (16*1024) /* eventually 32k */
31#define XLOG_BIG_RECORD_BSIZE (32*1024) /* 32k buffers */
32#define XLOG_MAX_RECORD_BSIZE (256*1024)
33#define XLOG_HEADER_CYCLE_SIZE (32*1024) /* cycle data in header */
34#define XLOG_CYCLE_DATA_SIZE (XLOG_HEADER_CYCLE_SIZE / BBSIZE)
35#define XLOG_MIN_RECORD_BSHIFT 14 /* 16384 == 1 << 14 */
36#define XLOG_BIG_RECORD_BSHIFT 15 /* 32k == 1 << 15 */
37#define XLOG_MAX_RECORD_BSHIFT 18 /* 256k == 1 << 18 */
38
39#define XLOG_HEADER_SIZE 512
40
41/* Minimum number of transactions that must fit in the log (defined by mkfs) */
42#define XFS_MIN_LOG_FACTOR 3
43
44#define XLOG_REC_SHIFT(log) \
45 BTOBB(1 << (xfs_has_logv2(log->l_mp) ? \
46 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
47#define XLOG_TOTAL_REC_SHIFT(log) \
48 BTOBB(XLOG_MAX_ICLOGS << (xfs_has_logv2(log->l_mp) ? \
49 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
50
51/* get lsn fields */
52#define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
53#define BLOCK_LSN(lsn) ((uint)(lsn))
54
55/* this is used in a spot where we might otherwise double-endian-flip */
56#define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
57
58static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
59{
60 return ((xfs_lsn_t)cycle << 32) | block;
61}
62
63static inline uint xlog_get_cycle(char *ptr)
64{
65 if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
66 return be32_to_cpu(*((__be32 *)ptr + 1));
67 else
68 return be32_to_cpu(*(__be32 *)ptr);
69}
70
71/* Log Clients */
72#define XFS_TRANSACTION 0x69
73#define XFS_LOG 0xaa
74
75#define XLOG_UNMOUNT_TYPE 0x556e /* Un for Unmount */
76
77/*
78 * Log item for unmount records.
79 *
80 * The unmount record used to have a string "Unmount filesystem--" in the
81 * data section where the "Un" was really a magic number (XLOG_UNMOUNT_TYPE).
82 * We just write the magic number now; see xfs_log_unmount_write.
83 */
84struct xfs_unmount_log_format {
85 uint16_t magic; /* XLOG_UNMOUNT_TYPE */
86 uint16_t pad1;
87 uint32_t pad2; /* may as well make it 64 bits */
88};
89
90/*
91 * Flags to log operation header
92 *
93 * The first write of a new transaction will be preceded with a start
94 * record, XLOG_START_TRANS. Once a transaction is committed, a commit
95 * record is written, XLOG_COMMIT_TRANS. If a single region can not fit into
96 * the remainder of the current active in-core log, it is split up into
97 * multiple regions. Each partial region will be marked with a
98 * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
99 *
100 */
101#define XLOG_START_TRANS 0x01 /* Start a new transaction */
102#define XLOG_COMMIT_TRANS 0x02 /* Commit this transaction */
103#define XLOG_CONTINUE_TRANS 0x04 /* Cont this trans into new region */
104#define XLOG_WAS_CONT_TRANS 0x08 /* Cont this trans into new region */
105#define XLOG_END_TRANS 0x10 /* End a continued transaction */
106#define XLOG_UNMOUNT_TRANS 0x20 /* Unmount a filesystem transaction */
107
108struct xlog_op_header {
109 __be32 oh_tid; /* transaction id of operation : 4 b */
110 __be32 oh_len; /* bytes in data region : 4 b */
111 __u8 oh_clientid; /* who sent me this : 1 b */
112 __u8 oh_flags; /* : 1 b */
113 __u16 oh_res2; /* 32 bit align : 2 b */
114};
115
116/* valid values for h_fmt */
117#define XLOG_FMT_UNKNOWN 0
118#define XLOG_FMT_LINUX_LE 1
119#define XLOG_FMT_LINUX_BE 2
120#define XLOG_FMT_IRIX_BE 3
121
122/* our fmt */
123#ifdef XFS_NATIVE_HOST
124#define XLOG_FMT XLOG_FMT_LINUX_BE
125#else
126#define XLOG_FMT XLOG_FMT_LINUX_LE
127#endif
128
129struct xlog_rec_ext_header {
130 __be32 xh_cycle; /* write cycle of log */
131 __be32 xh_cycle_data[XLOG_CYCLE_DATA_SIZE];
132 __u8 xh_reserved[252];
133};
134
135/* actual ext header payload size for checksumming */
136#define XLOG_REC_EXT_SIZE \
137 offsetofend(struct xlog_rec_ext_header, xh_cycle_data)
138
139struct xlog_rec_header {
140 __be32 h_magicno; /* log record (LR) identifier : 4 */
141 __be32 h_cycle; /* write cycle of log : 4 */
142 __be32 h_version; /* LR version : 4 */
143 __be32 h_len; /* len in bytes; should be 64-bit aligned: 4 */
144 __be64 h_lsn; /* lsn of this LR : 8 */
145 __be64 h_tail_lsn; /* lsn of 1st LR w/ buffers not committed: 8 */
146 __le32 h_crc; /* crc of log record : 4 */
147 __be32 h_prev_block; /* block number to previous LR : 4 */
148 __be32 h_num_logops; /* number of log operations in this LR : 4 */
149 __be32 h_cycle_data[XLOG_CYCLE_DATA_SIZE];
150
151 /* fields added by the Linux port: */
152 __be32 h_fmt; /* format of log record : 4 */
153 uuid_t h_fs_uuid; /* uuid of FS : 16 */
154
155 /* fields added for log v2: */
156 __be32 h_size; /* iclog size : 4 */
157
158 /*
159 * When h_size added for log v2 support, it caused structure to have
160 * a different size on i386 vs all other architectures because the
161 * sum of the size ofthe member is not aligned by that of the largest
162 * __be64-sized member, and i386 has really odd struct alignment rules.
163 *
164 * Due to the way the log headers are placed out on-disk that alone is
165 * not a problem becaue the xlog_rec_header always sits alone in a
166 * BBSIZEs area, and the rest of that area is padded with zeroes.
167 * But xlog_cksum used to calculate the checksum based on the structure
168 * size, and thus gives different checksums for i386 vs the rest.
169 * We now do two checksum validation passes for both sizes to allow
170 * moving v5 file systems with unclean logs between i386 and other
171 * (little-endian) architectures.
172 */
173 __u32 h_pad0;
174
175 __u8 h_reserved[184];
176 struct xlog_rec_ext_header h_ext[];
177};
178
179#ifdef __i386__
180#define XLOG_REC_SIZE offsetofend(struct xlog_rec_header, h_size)
181#define XLOG_REC_SIZE_OTHER offsetofend(struct xlog_rec_header, h_pad0)
182#else
183#define XLOG_REC_SIZE offsetofend(struct xlog_rec_header, h_pad0)
184#define XLOG_REC_SIZE_OTHER offsetofend(struct xlog_rec_header, h_size)
185#endif /* __i386__ */
186
187/* not an on-disk structure, but needed by log recovery in userspace */
188struct xfs_log_iovec {
189 void *i_addr; /* beginning address of region */
190 int i_len; /* length in bytes of region */
191 uint i_type; /* type of region */
192};
193
194/*
195 * Transaction Header definitions.
196 *
197 * This is the structure written in the log at the head of every transaction. It
198 * identifies the type and id of the transaction, and contains the number of
199 * items logged by the transaction so we know how many to expect during
200 * recovery.
201 *
202 * Do not change the below structure without redoing the code in
203 * xlog_recover_add_to_trans() and xlog_recover_add_to_cont_trans().
204 */
205struct xfs_trans_header {
206 uint th_magic; /* magic number */
207 uint th_type; /* transaction type */
208 int32_t th_tid; /* transaction id (unused) */
209 uint th_num_items; /* num items logged by trans */
210};
211
212#define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */
213
214/*
215 * The only type valid for th_type in CIL-enabled file system logs:
216 */
217#define XFS_TRANS_CHECKPOINT 40
218
219/*
220 * Log item types.
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 /* aligned ino chunks, var-size ibufs */
226#define XFS_LI_BUF 0x123c /* v2 bufs, variable sized inode bufs */
227#define XFS_LI_DQUOT 0x123d
228#define XFS_LI_QUOTAOFF 0x123e
229#define XFS_LI_ICREATE 0x123f
230#define XFS_LI_RUI 0x1240 /* rmap update intent */
231#define XFS_LI_RUD 0x1241
232#define XFS_LI_CUI 0x1242 /* refcount update intent */
233#define XFS_LI_CUD 0x1243
234#define XFS_LI_BUI 0x1244 /* bmbt update intent */
235#define XFS_LI_BUD 0x1245
236#define XFS_LI_ATTRI 0x1246 /* attr set/remove intent*/
237#define XFS_LI_ATTRD 0x1247 /* attr set/remove done */
238#define XFS_LI_XMI 0x1248 /* mapping exchange intent */
239#define XFS_LI_XMD 0x1249 /* mapping exchange done */
240#define XFS_LI_EFI_RT 0x124a /* realtime extent free intent */
241#define XFS_LI_EFD_RT 0x124b /* realtime extent free done */
242#define XFS_LI_RUI_RT 0x124c /* realtime rmap update intent */
243#define XFS_LI_RUD_RT 0x124d /* realtime rmap update done */
244#define XFS_LI_CUI_RT 0x124e /* realtime refcount update intent */
245#define XFS_LI_CUD_RT 0x124f /* realtime refcount update done */
246
247#define XFS_LI_TYPE_DESC \
248 { XFS_LI_EFI, "XFS_LI_EFI" }, \
249 { XFS_LI_EFD, "XFS_LI_EFD" }, \
250 { XFS_LI_IUNLINK, "XFS_LI_IUNLINK" }, \
251 { XFS_LI_INODE, "XFS_LI_INODE" }, \
252 { XFS_LI_BUF, "XFS_LI_BUF" }, \
253 { XFS_LI_DQUOT, "XFS_LI_DQUOT" }, \
254 { XFS_LI_QUOTAOFF, "XFS_LI_QUOTAOFF" }, \
255 { XFS_LI_ICREATE, "XFS_LI_ICREATE" }, \
256 { XFS_LI_RUI, "XFS_LI_RUI" }, \
257 { XFS_LI_RUD, "XFS_LI_RUD" }, \
258 { XFS_LI_CUI, "XFS_LI_CUI" }, \
259 { XFS_LI_CUD, "XFS_LI_CUD" }, \
260 { XFS_LI_BUI, "XFS_LI_BUI" }, \
261 { XFS_LI_BUD, "XFS_LI_BUD" }, \
262 { XFS_LI_ATTRI, "XFS_LI_ATTRI" }, \
263 { XFS_LI_ATTRD, "XFS_LI_ATTRD" }, \
264 { XFS_LI_XMI, "XFS_LI_XMI" }, \
265 { XFS_LI_XMD, "XFS_LI_XMD" }, \
266 { XFS_LI_EFI_RT, "XFS_LI_EFI_RT" }, \
267 { XFS_LI_EFD_RT, "XFS_LI_EFD_RT" }, \
268 { XFS_LI_RUI_RT, "XFS_LI_RUI_RT" }, \
269 { XFS_LI_RUD_RT, "XFS_LI_RUD_RT" }, \
270 { XFS_LI_CUI_RT, "XFS_LI_CUI_RT" }, \
271 { XFS_LI_CUD_RT, "XFS_LI_CUD_RT" }
272
273/*
274 * Inode Log Item Format definitions.
275 *
276 * This is the structure used to lay out an inode log item in the
277 * log. The size of the inline data/extents/b-tree root to be logged
278 * (if any) is indicated in the ilf_dsize field. Changes to this structure
279 * must be added on to the end.
280 */
281struct xfs_inode_log_format {
282 uint16_t ilf_type; /* inode log item type */
283 uint16_t ilf_size; /* size of this item */
284 uint32_t ilf_fields; /* flags for fields logged */
285 uint16_t ilf_asize; /* size of attr d/ext/root */
286 uint16_t ilf_dsize; /* size of data/ext/root */
287 uint32_t ilf_pad; /* pad for 64 bit boundary */
288 uint64_t ilf_ino; /* inode number */
289 union {
290 uint32_t ilfu_rdev; /* rdev value for dev inode*/
291 uint8_t __pad[16]; /* unused */
292 } ilf_u;
293 int64_t ilf_blkno; /* blkno of inode buffer */
294 int32_t ilf_len; /* len of inode buffer */
295 int32_t ilf_boffset; /* off of inode in buffer */
296};
297
298/*
299 * Old 32 bit systems will log in this format without the 64 bit
300 * alignment padding. Recovery will detect this and convert it to the
301 * correct format.
302 */
303struct xfs_inode_log_format_32 {
304 uint16_t ilf_type; /* inode log item type */
305 uint16_t ilf_size; /* size of this item */
306 uint32_t ilf_fields; /* flags for fields logged */
307 uint16_t ilf_asize; /* size of attr d/ext/root */
308 uint16_t ilf_dsize; /* size of data/ext/root */
309 uint64_t ilf_ino; /* inode number */
310 union {
311 uint32_t ilfu_rdev; /* rdev value for dev inode*/
312 uint8_t __pad[16]; /* unused */
313 } ilf_u;
314 int64_t ilf_blkno; /* blkno of inode buffer */
315 int32_t ilf_len; /* len of inode buffer */
316 int32_t ilf_boffset; /* off of inode in buffer */
317} __attribute__((packed));
318
319
320/*
321 * Flags for xfs_trans_log_inode flags field.
322 */
323#define XFS_ILOG_CORE 0x001 /* log standard inode fields */
324#define XFS_ILOG_DDATA 0x002 /* log i_df.if_data */
325#define XFS_ILOG_DEXT 0x004 /* log i_df.if_extents */
326#define XFS_ILOG_DBROOT 0x008 /* log i_df.i_broot */
327#define XFS_ILOG_DEV 0x010 /* log the dev field */
328#define XFS_ILOG_UUID 0x020 /* added long ago, but never used */
329#define XFS_ILOG_ADATA 0x040 /* log i_af.if_data */
330#define XFS_ILOG_AEXT 0x080 /* log i_af.if_extents */
331#define XFS_ILOG_ABROOT 0x100 /* log i_af.i_broot */
332#define XFS_ILOG_DOWNER 0x200 /* change the data fork owner on replay */
333#define XFS_ILOG_AOWNER 0x400 /* change the attr fork owner on replay */
334
335/*
336 * The timestamps are dirty, but not necessarily anything else in the inode
337 * core. Unlike the other fields above this one must never make it to disk
338 * in the ilf_fields of the inode_log_format, but is purely store in-memory in
339 * ili_fields in the inode_log_item.
340 */
341#define XFS_ILOG_TIMESTAMP 0x4000
342
343/*
344 * The version field has been changed, but not necessarily anything else of
345 * interest. This must never make it to disk - it is used purely to ensure that
346 * the inode item ->precommit operation can update the fsync flag triggers
347 * in the inode item correctly.
348 */
349#define XFS_ILOG_IVERSION 0x8000
350
351#define XFS_ILOG_DFORK (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
352 XFS_ILOG_DBROOT)
353
354#define XFS_ILOG_AFORK (XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
355 XFS_ILOG_ABROOT)
356
357#define XFS_ILOG_ALL (XFS_ILOG_CORE | XFS_ILOG_DDATA | \
358 XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \
359 XFS_ILOG_DEV | XFS_ILOG_ADATA | \
360 XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \
361 XFS_ILOG_TIMESTAMP | XFS_ILOG_DOWNER | \
362 XFS_ILOG_AOWNER)
363
364static inline int xfs_ilog_fbroot(int w)
365{
366 return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
367}
368
369static inline int xfs_ilog_fext(int w)
370{
371 return (w == XFS_DATA_FORK ? XFS_ILOG_DEXT : XFS_ILOG_AEXT);
372}
373
374static inline int xfs_ilog_fdata(int w)
375{
376 return (w == XFS_DATA_FORK ? XFS_ILOG_DDATA : XFS_ILOG_ADATA);
377}
378
379/*
380 * Incore version of the on-disk inode core structures. We log this directly
381 * into the journal in host CPU format (for better or worse) and as such
382 * directly mirrors the xfs_dinode structure as it must contain all the same
383 * information.
384 */
385typedef uint64_t xfs_log_timestamp_t;
386
387/* Legacy timestamp encoding format. */
388struct xfs_log_legacy_timestamp {
389 int32_t t_sec; /* timestamp seconds */
390 int32_t t_nsec; /* timestamp nanoseconds */
391};
392
393/*
394 * Define the format of the inode core that is logged. This structure must be
395 * kept identical to struct xfs_dinode except for the endianness annotations.
396 */
397struct xfs_log_dinode {
398 uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */
399 uint16_t di_mode; /* mode and type of file */
400 int8_t di_version; /* inode version */
401 int8_t di_format; /* format of di_c data */
402 uint16_t di_metatype; /* metadata type, if DIFLAG2_METADATA */
403 uint32_t di_uid; /* owner's user id */
404 uint32_t di_gid; /* owner's group id */
405 uint32_t di_nlink; /* number of links to file */
406 uint16_t di_projid_lo; /* lower part of owner's project id */
407 uint16_t di_projid_hi; /* higher part of owner's project id */
408 union {
409 /* Number of data fork extents if NREXT64 is set */
410 uint64_t di_big_nextents;
411
412 /* Padding for V3 inodes without NREXT64 set. */
413 uint64_t di_v3_pad;
414
415 /* Padding and inode flush counter for V2 inodes. */
416 struct {
417 uint8_t di_v2_pad[6]; /* V2 inode zeroed space */
418 uint16_t di_flushiter; /* V2 inode incremented on flush */
419 };
420 };
421 xfs_log_timestamp_t di_atime; /* time last accessed */
422 xfs_log_timestamp_t di_mtime; /* time last modified */
423 xfs_log_timestamp_t di_ctime; /* time created/inode modified */
424 xfs_fsize_t di_size; /* number of bytes in file */
425 xfs_rfsblock_t di_nblocks; /* # of direct & btree blocks used */
426 xfs_extlen_t di_extsize; /* basic/minimum extent size for file */
427 union {
428 /*
429 * For V2 inodes and V3 inodes without NREXT64 set, this
430 * is the number of data and attr fork extents.
431 */
432 struct {
433 uint32_t di_nextents;
434 uint16_t di_anextents;
435 } __packed;
436
437 /* Number of attr fork extents if NREXT64 is set. */
438 struct {
439 uint32_t di_big_anextents;
440 uint16_t di_nrext64_pad;
441 } __packed;
442 } __packed;
443 uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */
444 int8_t di_aformat; /* format of attr fork's data */
445 uint32_t di_dmevmask; /* DMIG event mask */
446 uint16_t di_dmstate; /* DMIG state info */
447 uint16_t di_flags; /* random flags, XFS_DIFLAG_... */
448 uint32_t di_gen; /* generation number */
449
450 /* di_next_unlinked is the only non-core field in the old dinode */
451 xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */
452
453 /* start of the extended dinode, writable fields */
454 uint32_t di_crc; /* CRC of the inode */
455 uint64_t di_changecount; /* number of attribute changes */
456
457 /*
458 * The LSN we write to this field during formatting is not a reflection
459 * of the current on-disk LSN. It should never be used for recovery
460 * sequencing, nor should it be recovered into the on-disk inode at all.
461 * See xlog_recover_inode_commit_pass2() and xfs_log_dinode_to_disk()
462 * for details.
463 */
464 xfs_lsn_t di_lsn;
465
466 uint64_t di_flags2; /* more random flags */
467 union {
468 /* basic cow extent size for (regular) file */
469 uint32_t di_cowextsize;
470 /* used blocks in RTG for (zoned) rtrmap inode */
471 uint32_t di_used_blocks;
472 };
473 uint8_t di_pad2[12]; /* more padding for future expansion */
474
475 /* fields only written to during inode creation */
476 xfs_log_timestamp_t di_crtime; /* time created */
477 xfs_ino_t di_ino; /* inode number */
478 uuid_t di_uuid; /* UUID of the filesystem */
479
480 /* structure must be padded to 64 bit alignment */
481};
482
483#define xfs_log_dinode_size(mp) \
484 (xfs_has_v3inodes((mp)) ? \
485 sizeof(struct xfs_log_dinode) : \
486 offsetof(struct xfs_log_dinode, di_next_unlinked))
487
488/*
489 * Buffer Log Format definitions
490 *
491 * These are the physical dirty bitmap definitions for the log format structure.
492 */
493#define XFS_BLF_CHUNK 128
494#define XFS_BLF_SHIFT 7
495#define BIT_TO_WORD_SHIFT 5
496#define NBWORD (NBBY * sizeof(unsigned int))
497
498/*
499 * This flag indicates that the buffer contains on disk inodes
500 * and requires special recovery handling.
501 */
502#define XFS_BLF_INODE_BUF (1<<0)
503
504/*
505 * This flag indicates that the buffer should not be replayed
506 * during recovery because its blocks are being freed.
507 */
508#define XFS_BLF_CANCEL (1<<1)
509
510/*
511 * This flag indicates that the buffer contains on disk
512 * user or group dquots and may require special recovery handling.
513 */
514#define XFS_BLF_UDQUOT_BUF (1<<2)
515#define XFS_BLF_PDQUOT_BUF (1<<3)
516#define XFS_BLF_GDQUOT_BUF (1<<4)
517
518/*
519 * This is the structure used to lay out a buf log item in the log. The data
520 * map describes which 128 byte chunks of the buffer have been logged.
521 *
522 * The placement of blf_map_size causes blf_data_map to start at an odd
523 * multiple of sizeof(unsigned int) offset within the struct. Because the data
524 * bitmap size will always be an even number, the end of the data_map (and
525 * therefore the structure) will also be at an odd multiple of sizeof(unsigned
526 * int). Some 64-bit compilers will insert padding at the end of the struct to
527 * ensure 64-bit alignment of blf_blkno, but 32-bit ones will not. Therefore,
528 * XFS_BLF_DATAMAP_SIZE must be an odd number to make the padding explicit and
529 * keep the structure size consistent between 32-bit and 64-bit platforms.
530 */
531#define __XFS_BLF_DATAMAP_SIZE ((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
532#define XFS_BLF_DATAMAP_SIZE (__XFS_BLF_DATAMAP_SIZE + 1)
533
534struct xfs_buf_log_format {
535 unsigned short blf_type; /* buf log item type indicator */
536 unsigned short blf_size; /* size of this item */
537 unsigned short blf_flags; /* misc state */
538 unsigned short blf_len; /* number of blocks in this buf */
539 int64_t blf_blkno; /* starting blkno of this buf */
540 unsigned int blf_map_size; /* used size of data bitmap in words */
541 unsigned int blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
542};
543
544/*
545 * All buffers now need to tell recovery where the magic number
546 * is so that it can verify and calculate the CRCs on the buffer correctly
547 * once the changes have been replayed into the buffer.
548 *
549 * The type value is held in the upper 5 bits of the blf_flags field, which is
550 * an unsigned 16 bit field. Hence we need to shift it 11 bits up and down.
551 */
552#define XFS_BLFT_BITS 5
553#define XFS_BLFT_SHIFT 11
554#define XFS_BLFT_MASK (((1 << XFS_BLFT_BITS) - 1) << XFS_BLFT_SHIFT)
555
556enum xfs_blft {
557 XFS_BLFT_UNKNOWN_BUF = 0,
558 XFS_BLFT_UDQUOT_BUF,
559 XFS_BLFT_PDQUOT_BUF,
560 XFS_BLFT_GDQUOT_BUF,
561 XFS_BLFT_BTREE_BUF,
562 XFS_BLFT_AGF_BUF,
563 XFS_BLFT_AGFL_BUF,
564 XFS_BLFT_AGI_BUF,
565 XFS_BLFT_DINO_BUF,
566 XFS_BLFT_SYMLINK_BUF,
567 XFS_BLFT_DIR_BLOCK_BUF,
568 XFS_BLFT_DIR_DATA_BUF,
569 XFS_BLFT_DIR_FREE_BUF,
570 XFS_BLFT_DIR_LEAF1_BUF,
571 XFS_BLFT_DIR_LEAFN_BUF,
572 XFS_BLFT_DA_NODE_BUF,
573 XFS_BLFT_ATTR_LEAF_BUF,
574 XFS_BLFT_ATTR_RMT_BUF,
575 XFS_BLFT_SB_BUF,
576 XFS_BLFT_RTBITMAP_BUF,
577 XFS_BLFT_RTSUMMARY_BUF,
578 XFS_BLFT_MAX_BUF = (1 << XFS_BLFT_BITS),
579};
580
581static inline void
582xfs_blft_to_flags(struct xfs_buf_log_format *blf, enum xfs_blft type)
583{
584 ASSERT(type > XFS_BLFT_UNKNOWN_BUF && type < XFS_BLFT_MAX_BUF);
585 blf->blf_flags &= ~XFS_BLFT_MASK;
586 blf->blf_flags |= ((type << XFS_BLFT_SHIFT) & XFS_BLFT_MASK);
587}
588
589static inline uint16_t
590xfs_blft_from_flags(struct xfs_buf_log_format *blf)
591{
592 return (blf->blf_flags & XFS_BLFT_MASK) >> XFS_BLFT_SHIFT;
593}
594
595/*
596 * EFI/EFD log format definitions
597 */
598struct xfs_extent {
599 xfs_fsblock_t ext_start;
600 xfs_extlen_t ext_len;
601};
602
603/*
604 * Since the structures in struct xfs_extent add up to 96 bytes, it has
605 * different alignments on i386 vs all other architectures, because i386
606 * does not pad structures to their natural alignment.
607 *
608 * Provide the different variants for use by a conversion routine.
609 */
610struct xfs_extent_32 {
611 uint64_t ext_start;
612 uint32_t ext_len;
613} __attribute__((packed));
614
615struct xfs_extent_64 {
616 uint64_t ext_start;
617 uint32_t ext_len;
618 uint32_t ext_pad;
619};
620
621/*
622 * This is the structure used to lay out an efi log item in the
623 * log. The efi_extents field is a variable size array whose
624 * size is given by efi_nextents.
625 */
626struct xfs_efi_log_format {
627 uint16_t efi_type; /* efi log item type */
628 uint16_t efi_size; /* size of this item */
629 uint32_t efi_nextents; /* # extents to free */
630 uint64_t efi_id; /* efi identifier */
631 struct xfs_extent efi_extents[]; /* array of extents to free */
632};
633
634static inline size_t
635xfs_efi_log_format_sizeof(
636 unsigned int nr)
637{
638 return sizeof(struct xfs_efi_log_format) +
639 nr * sizeof(struct xfs_extent);
640}
641
642struct xfs_efi_log_format_32 {
643 uint16_t efi_type; /* efi log item type */
644 uint16_t efi_size; /* size of this item */
645 uint32_t efi_nextents; /* # extents to free */
646 uint64_t efi_id; /* efi identifier */
647 struct xfs_extent_32 efi_extents[]; /* array of extents to free */
648} __attribute__((packed));
649
650static inline size_t
651xfs_efi_log_format32_sizeof(
652 unsigned int nr)
653{
654 return sizeof(struct xfs_efi_log_format_32) +
655 nr * sizeof(struct xfs_extent_32);
656}
657
658struct xfs_efi_log_format_64 {
659 uint16_t efi_type; /* efi log item type */
660 uint16_t efi_size; /* size of this item */
661 uint32_t efi_nextents; /* # extents to free */
662 uint64_t efi_id; /* efi identifier */
663 struct xfs_extent_64 efi_extents[]; /* array of extents to free */
664};
665
666static inline size_t
667xfs_efi_log_format64_sizeof(
668 unsigned int nr)
669{
670 return sizeof(struct xfs_efi_log_format_64) +
671 nr * sizeof(struct xfs_extent_64);
672}
673
674/*
675 * This is the structure used to lay out an efd log item in the
676 * log. The efd_extents array is a variable size array whose
677 * size is given by efd_nextents;
678 */
679struct xfs_efd_log_format {
680 uint16_t efd_type; /* efd log item type */
681 uint16_t efd_size; /* size of this item */
682 uint32_t efd_nextents; /* # of extents freed */
683 uint64_t efd_efi_id; /* id of corresponding efi */
684 struct xfs_extent efd_extents[]; /* array of extents freed */
685};
686
687static inline size_t
688xfs_efd_log_format_sizeof(
689 unsigned int nr)
690{
691 return sizeof(struct xfs_efd_log_format) +
692 nr * sizeof(struct xfs_extent);
693}
694
695struct xfs_efd_log_format_32 {
696 uint16_t efd_type; /* efd log item type */
697 uint16_t efd_size; /* size of this item */
698 uint32_t efd_nextents; /* # of extents freed */
699 uint64_t efd_efi_id; /* id of corresponding efi */
700 struct xfs_extent_32 efd_extents[]; /* array of extents freed */
701} __attribute__((packed));
702
703static inline size_t
704xfs_efd_log_format32_sizeof(
705 unsigned int nr)
706{
707 return sizeof(struct xfs_efd_log_format_32) +
708 nr * sizeof(struct xfs_extent_32);
709}
710
711struct xfs_efd_log_format_64 {
712 uint16_t efd_type; /* efd log item type */
713 uint16_t efd_size; /* size of this item */
714 uint32_t efd_nextents; /* # of extents freed */
715 uint64_t efd_efi_id; /* id of corresponding efi */
716 struct xfs_extent_64 efd_extents[]; /* array of extents freed */
717};
718
719static inline size_t
720xfs_efd_log_format64_sizeof(
721 unsigned int nr)
722{
723 return sizeof(struct xfs_efd_log_format_64) +
724 nr * sizeof(struct xfs_extent_64);
725}
726
727/*
728 * RUI/RUD (reverse mapping) log format definitions
729 */
730struct xfs_map_extent {
731 uint64_t me_owner;
732 uint64_t me_startblock;
733 uint64_t me_startoff;
734 uint32_t me_len;
735 uint32_t me_flags;
736};
737
738/* rmap me_flags: upper bits are flags, lower byte is type code */
739#define XFS_RMAP_EXTENT_MAP 1
740#define XFS_RMAP_EXTENT_MAP_SHARED 2
741#define XFS_RMAP_EXTENT_UNMAP 3
742#define XFS_RMAP_EXTENT_UNMAP_SHARED 4
743#define XFS_RMAP_EXTENT_CONVERT 5
744#define XFS_RMAP_EXTENT_CONVERT_SHARED 6
745#define XFS_RMAP_EXTENT_ALLOC 7
746#define XFS_RMAP_EXTENT_FREE 8
747#define XFS_RMAP_EXTENT_TYPE_MASK 0xFF
748
749#define XFS_RMAP_EXTENT_ATTR_FORK (1U << 31)
750#define XFS_RMAP_EXTENT_BMBT_BLOCK (1U << 30)
751#define XFS_RMAP_EXTENT_UNWRITTEN (1U << 29)
752
753#define XFS_RMAP_EXTENT_FLAGS (XFS_RMAP_EXTENT_TYPE_MASK | \
754 XFS_RMAP_EXTENT_ATTR_FORK | \
755 XFS_RMAP_EXTENT_BMBT_BLOCK | \
756 XFS_RMAP_EXTENT_UNWRITTEN)
757
758/*
759 * This is the structure used to lay out an rui log item in the
760 * log. The rui_extents field is a variable size array whose
761 * size is given by rui_nextents.
762 */
763struct xfs_rui_log_format {
764 uint16_t rui_type; /* rui log item type */
765 uint16_t rui_size; /* size of this item */
766 uint32_t rui_nextents; /* # extents to free */
767 uint64_t rui_id; /* rui identifier */
768 struct xfs_map_extent rui_extents[]; /* array of extents to rmap */
769};
770
771static inline size_t
772xfs_rui_log_format_sizeof(
773 unsigned int nr)
774{
775 return sizeof(struct xfs_rui_log_format) +
776 nr * sizeof(struct xfs_map_extent);
777}
778
779/*
780 * This is the structure used to lay out an rud log item in the
781 * log. The rud_extents array is a variable size array whose
782 * size is given by rud_nextents;
783 */
784struct xfs_rud_log_format {
785 uint16_t rud_type; /* rud log item type */
786 uint16_t rud_size; /* size of this item */
787 uint32_t __pad;
788 uint64_t rud_rui_id; /* id of corresponding rui */
789};
790
791/*
792 * CUI/CUD (refcount update) log format definitions
793 */
794struct xfs_phys_extent {
795 uint64_t pe_startblock;
796 uint32_t pe_len;
797 uint32_t pe_flags;
798};
799
800/* refcount pe_flags: upper bits are flags, lower byte is type code */
801/* Type codes are taken directly from enum xfs_refcount_intent_type. */
802#define XFS_REFCOUNT_EXTENT_TYPE_MASK 0xFF
803
804#define XFS_REFCOUNT_EXTENT_FLAGS (XFS_REFCOUNT_EXTENT_TYPE_MASK)
805
806/*
807 * This is the structure used to lay out a cui log item in the
808 * log. The cui_extents field is a variable size array whose
809 * size is given by cui_nextents.
810 */
811struct xfs_cui_log_format {
812 uint16_t cui_type; /* cui log item type */
813 uint16_t cui_size; /* size of this item */
814 uint32_t cui_nextents; /* # extents to free */
815 uint64_t cui_id; /* cui identifier */
816 struct xfs_phys_extent cui_extents[]; /* array of extents */
817};
818
819static inline size_t
820xfs_cui_log_format_sizeof(
821 unsigned int nr)
822{
823 return sizeof(struct xfs_cui_log_format) +
824 nr * sizeof(struct xfs_phys_extent);
825}
826
827/*
828 * This is the structure used to lay out a cud log item in the
829 * log. The cud_extents array is a variable size array whose
830 * size is given by cud_nextents;
831 */
832struct xfs_cud_log_format {
833 uint16_t cud_type; /* cud log item type */
834 uint16_t cud_size; /* size of this item */
835 uint32_t __pad;
836 uint64_t cud_cui_id; /* id of corresponding cui */
837};
838
839/*
840 * BUI/BUD (inode block mapping) log format definitions
841 */
842
843/* bmbt me_flags: upper bits are flags, lower byte is type code */
844/* Type codes are taken directly from enum xfs_bmap_intent_type. */
845#define XFS_BMAP_EXTENT_TYPE_MASK 0xFF
846
847#define XFS_BMAP_EXTENT_ATTR_FORK (1U << 31)
848#define XFS_BMAP_EXTENT_UNWRITTEN (1U << 30)
849#define XFS_BMAP_EXTENT_REALTIME (1U << 29)
850
851#define XFS_BMAP_EXTENT_FLAGS (XFS_BMAP_EXTENT_TYPE_MASK | \
852 XFS_BMAP_EXTENT_ATTR_FORK | \
853 XFS_BMAP_EXTENT_UNWRITTEN | \
854 XFS_BMAP_EXTENT_REALTIME)
855
856/*
857 * This is the structure used to lay out an bui log item in the
858 * log. The bui_extents field is a variable size array whose
859 * size is given by bui_nextents.
860 */
861struct xfs_bui_log_format {
862 uint16_t bui_type; /* bui log item type */
863 uint16_t bui_size; /* size of this item */
864 uint32_t bui_nextents; /* # extents to free */
865 uint64_t bui_id; /* bui identifier */
866 struct xfs_map_extent bui_extents[]; /* array of extents to bmap */
867};
868
869static inline size_t
870xfs_bui_log_format_sizeof(
871 unsigned int nr)
872{
873 return sizeof(struct xfs_bui_log_format) +
874 nr * sizeof(struct xfs_map_extent);
875}
876
877/*
878 * This is the structure used to lay out an bud log item in the
879 * log. The bud_extents array is a variable size array whose
880 * size is given by bud_nextents;
881 */
882struct xfs_bud_log_format {
883 uint16_t bud_type; /* bud log item type */
884 uint16_t bud_size; /* size of this item */
885 uint32_t __pad;
886 uint64_t bud_bui_id; /* id of corresponding bui */
887};
888
889/*
890 * XMI/XMD (file mapping exchange) log format definitions
891 */
892
893/* This is the structure used to lay out an mapping exchange log item. */
894struct xfs_xmi_log_format {
895 uint16_t xmi_type; /* xmi log item type */
896 uint16_t xmi_size; /* size of this item */
897 uint32_t __pad; /* must be zero */
898 uint64_t xmi_id; /* xmi identifier */
899
900 uint64_t xmi_inode1; /* inumber of first file */
901 uint64_t xmi_inode2; /* inumber of second file */
902 uint32_t xmi_igen1; /* generation of first file */
903 uint32_t xmi_igen2; /* generation of second file */
904 uint64_t xmi_startoff1; /* block offset into file1 */
905 uint64_t xmi_startoff2; /* block offset into file2 */
906 uint64_t xmi_blockcount; /* number of blocks */
907 uint64_t xmi_flags; /* XFS_EXCHMAPS_* */
908 uint64_t xmi_isize1; /* intended file1 size */
909 uint64_t xmi_isize2; /* intended file2 size */
910};
911
912/* Exchange mappings between extended attribute forks instead of data forks. */
913#define XFS_EXCHMAPS_ATTR_FORK (1ULL << 0)
914
915/* Set the file sizes when finished. */
916#define XFS_EXCHMAPS_SET_SIZES (1ULL << 1)
917
918/*
919 * Exchange the mappings of the two files only if the file allocation units
920 * mapped to file1's range have been written.
921 */
922#define XFS_EXCHMAPS_INO1_WRITTEN (1ULL << 2)
923
924/* Clear the reflink flag from inode1 after the operation. */
925#define XFS_EXCHMAPS_CLEAR_INO1_REFLINK (1ULL << 3)
926
927/* Clear the reflink flag from inode2 after the operation. */
928#define XFS_EXCHMAPS_CLEAR_INO2_REFLINK (1ULL << 4)
929
930#define XFS_EXCHMAPS_LOGGED_FLAGS (XFS_EXCHMAPS_ATTR_FORK | \
931 XFS_EXCHMAPS_SET_SIZES | \
932 XFS_EXCHMAPS_INO1_WRITTEN | \
933 XFS_EXCHMAPS_CLEAR_INO1_REFLINK | \
934 XFS_EXCHMAPS_CLEAR_INO2_REFLINK)
935
936/* This is the structure used to lay out an mapping exchange done log item. */
937struct xfs_xmd_log_format {
938 uint16_t xmd_type; /* xmd log item type */
939 uint16_t xmd_size; /* size of this item */
940 uint32_t __pad;
941 uint64_t xmd_xmi_id; /* id of corresponding xmi */
942};
943
944/*
945 * Dquot Log format definitions.
946 *
947 * The first two fields must be the type and size fitting into
948 * 32 bits : log_recovery code assumes that.
949 */
950struct xfs_dq_logformat {
951 uint16_t qlf_type; /* dquot log item type */
952 uint16_t qlf_size; /* size of this item */
953 xfs_dqid_t qlf_id; /* usr/grp/proj id : 32 bits */
954 int64_t qlf_blkno; /* blkno of dquot buffer */
955 int32_t qlf_len; /* len of dquot buffer */
956 uint32_t qlf_boffset; /* off of dquot in buffer */
957};
958
959/*
960 * log format struct for QUOTAOFF records.
961 * The first two fields must be the type and size fitting into
962 * 32 bits : log_recovery code assumes that.
963 * We write two LI_QUOTAOFF logitems per quotaoff, the last one keeps a pointer
964 * to the first and ensures that the first logitem is taken out of the AIL
965 * only when the last one is securely committed.
966 */
967struct xfs_qoff_logformat {
968 unsigned short qf_type; /* quotaoff log item type */
969 unsigned short qf_size; /* size of this item */
970 unsigned int qf_flags; /* USR and/or GRP */
971 char qf_pad[12]; /* padding for future */
972};
973
974/*
975 * Disk quotas status in m_qflags, and also sb_qflags. 16 bits.
976 */
977#define XFS_UQUOTA_ACCT 0x0001 /* user quota accounting ON */
978#define XFS_UQUOTA_ENFD 0x0002 /* user quota limits enforced */
979#define XFS_UQUOTA_CHKD 0x0004 /* quotacheck run on usr quotas */
980#define XFS_PQUOTA_ACCT 0x0008 /* project quota accounting ON */
981#define XFS_OQUOTA_ENFD 0x0010 /* other (grp/prj) quota limits enforced */
982#define XFS_OQUOTA_CHKD 0x0020 /* quotacheck run on other (grp/prj) quotas */
983#define XFS_GQUOTA_ACCT 0x0040 /* group quota accounting ON */
984
985/*
986 * Conversion to and from the combined OQUOTA flag (if necessary)
987 * is done only in xfs_sb_qflags_to_disk() and xfs_sb_qflags_from_disk()
988 */
989#define XFS_GQUOTA_ENFD 0x0080 /* group quota limits enforced */
990#define XFS_GQUOTA_CHKD 0x0100 /* quotacheck run on group quotas */
991#define XFS_PQUOTA_ENFD 0x0200 /* project quota limits enforced */
992#define XFS_PQUOTA_CHKD 0x0400 /* quotacheck run on project quotas */
993
994#define XFS_ALL_QUOTA_ACCT \
995 (XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
996#define XFS_ALL_QUOTA_ENFD \
997 (XFS_UQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_ENFD)
998#define XFS_ALL_QUOTA_CHKD \
999 (XFS_UQUOTA_CHKD | XFS_GQUOTA_CHKD | XFS_PQUOTA_CHKD)
1000
1001#define XFS_MOUNT_QUOTA_ALL (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
1002 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
1003 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD|\
1004 XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD|\
1005 XFS_PQUOTA_CHKD)
1006
1007/*
1008 * Inode create log item structure
1009 *
1010 * Log recovery assumes the first two entries are the type and size and they fit
1011 * in 32 bits. Also in host order (ugh) so they have to be 32 bit aligned so
1012 * decoding can be done correctly.
1013 */
1014struct xfs_icreate_log {
1015 uint16_t icl_type; /* type of log format structure */
1016 uint16_t icl_size; /* size of log format structure */
1017 __be32 icl_ag; /* ag being allocated in */
1018 __be32 icl_agbno; /* start block of inode range */
1019 __be32 icl_count; /* number of inodes to initialise */
1020 __be32 icl_isize; /* size of inodes */
1021 __be32 icl_length; /* length of extent to initialise */
1022 __be32 icl_gen; /* inode generation number to use */
1023};
1024
1025/*
1026 * Flags for deferred attribute operations.
1027 * Upper bits are flags, lower byte is type code
1028 */
1029#define XFS_ATTRI_OP_FLAGS_SET 1 /* Set the attribute */
1030#define XFS_ATTRI_OP_FLAGS_REMOVE 2 /* Remove the attribute */
1031#define XFS_ATTRI_OP_FLAGS_REPLACE 3 /* Replace the attribute */
1032#define XFS_ATTRI_OP_FLAGS_PPTR_SET 4 /* Set parent pointer */
1033#define XFS_ATTRI_OP_FLAGS_PPTR_REMOVE 5 /* Remove parent pointer */
1034#define XFS_ATTRI_OP_FLAGS_PPTR_REPLACE 6 /* Replace parent pointer */
1035#define XFS_ATTRI_OP_FLAGS_TYPE_MASK 0xFF /* Flags type mask */
1036
1037/*
1038 * alfi_attr_filter captures the state of xfs_da_args.attr_filter, so it should
1039 * never have any other bits set.
1040 */
1041#define XFS_ATTRI_FILTER_MASK (XFS_ATTR_ROOT | \
1042 XFS_ATTR_SECURE | \
1043 XFS_ATTR_PARENT | \
1044 XFS_ATTR_INCOMPLETE)
1045
1046/*
1047 * This is the structure used to lay out an attr log item in the
1048 * log.
1049 */
1050struct xfs_attri_log_format {
1051 uint16_t alfi_type; /* attri log item type */
1052 uint16_t alfi_size; /* size of this item */
1053 uint32_t alfi_igen; /* generation of alfi_ino for pptr ops */
1054 uint64_t alfi_id; /* attri identifier */
1055 uint64_t alfi_ino; /* the inode for this attr operation */
1056 uint32_t alfi_op_flags; /* marks the op as a set or remove */
1057 union {
1058 uint32_t alfi_name_len; /* attr name length */
1059 struct {
1060 /*
1061 * For PPTR_REPLACE, these are the lengths of the old
1062 * and new attr names. The new and old values must
1063 * have the same length.
1064 */
1065 uint16_t alfi_old_name_len;
1066 uint16_t alfi_new_name_len;
1067 };
1068 };
1069 uint32_t alfi_value_len; /* attr value length */
1070 uint32_t alfi_attr_filter;/* attr filter flags */
1071};
1072
1073struct xfs_attrd_log_format {
1074 uint16_t alfd_type; /* attrd log item type */
1075 uint16_t alfd_size; /* size of this item */
1076 uint32_t __pad; /* pad to 64 bit aligned */
1077 uint64_t alfd_alf_id; /* id of corresponding attri */
1078};
1079
1080#endif /* __XFS_LOG_FORMAT_H__ */
1081

source code of linux/fs/xfs/libxfs/xfs_log_format.h