xref: /OK3568_Linux_fs/kernel/fs/xfs/libxfs/xfs_log_format.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
4*4882a593Smuzhiyun  * All Rights Reserved.
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun #ifndef	__XFS_LOG_FORMAT_H__
7*4882a593Smuzhiyun #define __XFS_LOG_FORMAT_H__
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun struct xfs_mount;
10*4882a593Smuzhiyun struct xfs_trans_res;
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun /*
13*4882a593Smuzhiyun  * On-disk Log Format definitions.
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * This file contains all the on-disk format definitions used within the log. It
16*4882a593Smuzhiyun  * includes the physical log structure itself, as well as all the log item
17*4882a593Smuzhiyun  * format structures that are written into the log and intepreted by log
18*4882a593Smuzhiyun  * recovery. We start with the physical log format definitions, and then work
19*4882a593Smuzhiyun  * through all the log items definitions and everything they encode into the
20*4882a593Smuzhiyun  * log.
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun typedef uint32_t xlog_tid_t;
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #define XLOG_MIN_ICLOGS		2
25*4882a593Smuzhiyun #define XLOG_MAX_ICLOGS		8
26*4882a593Smuzhiyun #define XLOG_HEADER_MAGIC_NUM	0xFEEDbabe	/* Invalid cycle number */
27*4882a593Smuzhiyun #define XLOG_VERSION_1		1
28*4882a593Smuzhiyun #define XLOG_VERSION_2		2		/* Large IClogs, Log sunit */
29*4882a593Smuzhiyun #define XLOG_VERSION_OKBITS	(XLOG_VERSION_1 | XLOG_VERSION_2)
30*4882a593Smuzhiyun #define XLOG_MIN_RECORD_BSIZE	(16*1024)	/* eventually 32k */
31*4882a593Smuzhiyun #define XLOG_BIG_RECORD_BSIZE	(32*1024)	/* 32k buffers */
32*4882a593Smuzhiyun #define XLOG_MAX_RECORD_BSIZE	(256*1024)
33*4882a593Smuzhiyun #define XLOG_HEADER_CYCLE_SIZE	(32*1024)	/* cycle data in header */
34*4882a593Smuzhiyun #define XLOG_MIN_RECORD_BSHIFT	14		/* 16384 == 1 << 14 */
35*4882a593Smuzhiyun #define XLOG_BIG_RECORD_BSHIFT	15		/* 32k == 1 << 15 */
36*4882a593Smuzhiyun #define XLOG_MAX_RECORD_BSHIFT	18		/* 256k == 1 << 18 */
37*4882a593Smuzhiyun #define XLOG_BTOLSUNIT(log, b)  (((b)+(log)->l_mp->m_sb.sb_logsunit-1) / \
38*4882a593Smuzhiyun                                  (log)->l_mp->m_sb.sb_logsunit)
39*4882a593Smuzhiyun #define XLOG_LSUNITTOB(log, su) ((su) * (log)->l_mp->m_sb.sb_logsunit)
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun #define XLOG_HEADER_SIZE	512
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun /* Minimum number of transactions that must fit in the log (defined by mkfs) */
44*4882a593Smuzhiyun #define XFS_MIN_LOG_FACTOR	3
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun #define XLOG_REC_SHIFT(log) \
47*4882a593Smuzhiyun 	BTOBB(1 << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
48*4882a593Smuzhiyun 	 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
49*4882a593Smuzhiyun #define XLOG_TOTAL_REC_SHIFT(log) \
50*4882a593Smuzhiyun 	BTOBB(XLOG_MAX_ICLOGS << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
51*4882a593Smuzhiyun 	 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /* get lsn fields */
54*4882a593Smuzhiyun #define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
55*4882a593Smuzhiyun #define BLOCK_LSN(lsn) ((uint)(lsn))
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun /* this is used in a spot where we might otherwise double-endian-flip */
58*4882a593Smuzhiyun #define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
59*4882a593Smuzhiyun 
xlog_assign_lsn(uint cycle,uint block)60*4882a593Smuzhiyun static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
61*4882a593Smuzhiyun {
62*4882a593Smuzhiyun 	return ((xfs_lsn_t)cycle << 32) | block;
63*4882a593Smuzhiyun }
64*4882a593Smuzhiyun 
xlog_get_cycle(char * ptr)65*4882a593Smuzhiyun static inline uint xlog_get_cycle(char *ptr)
66*4882a593Smuzhiyun {
67*4882a593Smuzhiyun 	if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
68*4882a593Smuzhiyun 		return be32_to_cpu(*((__be32 *)ptr + 1));
69*4882a593Smuzhiyun 	else
70*4882a593Smuzhiyun 		return be32_to_cpu(*(__be32 *)ptr);
71*4882a593Smuzhiyun }
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun /* Log Clients */
74*4882a593Smuzhiyun #define XFS_TRANSACTION		0x69
75*4882a593Smuzhiyun #define XFS_VOLUME		0x2
76*4882a593Smuzhiyun #define XFS_LOG			0xaa
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun #define XLOG_UNMOUNT_TYPE	0x556e	/* Un for Unmount */
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun /*
81*4882a593Smuzhiyun  * Log item for unmount records.
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  * The unmount record used to have a string "Unmount filesystem--" in the
84*4882a593Smuzhiyun  * data section where the "Un" was really a magic number (XLOG_UNMOUNT_TYPE).
85*4882a593Smuzhiyun  * We just write the magic number now; see xfs_log_unmount_write.
86*4882a593Smuzhiyun  */
87*4882a593Smuzhiyun struct xfs_unmount_log_format {
88*4882a593Smuzhiyun 	uint16_t	magic;	/* XLOG_UNMOUNT_TYPE */
89*4882a593Smuzhiyun 	uint16_t	pad1;
90*4882a593Smuzhiyun 	uint32_t	pad2;	/* may as well make it 64 bits */
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun /* Region types for iovec's i_type */
94*4882a593Smuzhiyun #define XLOG_REG_TYPE_BFORMAT		1
95*4882a593Smuzhiyun #define XLOG_REG_TYPE_BCHUNK		2
96*4882a593Smuzhiyun #define XLOG_REG_TYPE_EFI_FORMAT	3
97*4882a593Smuzhiyun #define XLOG_REG_TYPE_EFD_FORMAT	4
98*4882a593Smuzhiyun #define XLOG_REG_TYPE_IFORMAT		5
99*4882a593Smuzhiyun #define XLOG_REG_TYPE_ICORE		6
100*4882a593Smuzhiyun #define XLOG_REG_TYPE_IEXT		7
101*4882a593Smuzhiyun #define XLOG_REG_TYPE_IBROOT		8
102*4882a593Smuzhiyun #define XLOG_REG_TYPE_ILOCAL		9
103*4882a593Smuzhiyun #define XLOG_REG_TYPE_IATTR_EXT		10
104*4882a593Smuzhiyun #define XLOG_REG_TYPE_IATTR_BROOT	11
105*4882a593Smuzhiyun #define XLOG_REG_TYPE_IATTR_LOCAL	12
106*4882a593Smuzhiyun #define XLOG_REG_TYPE_QFORMAT		13
107*4882a593Smuzhiyun #define XLOG_REG_TYPE_DQUOT		14
108*4882a593Smuzhiyun #define XLOG_REG_TYPE_QUOTAOFF		15
109*4882a593Smuzhiyun #define XLOG_REG_TYPE_LRHEADER		16
110*4882a593Smuzhiyun #define XLOG_REG_TYPE_UNMOUNT		17
111*4882a593Smuzhiyun #define XLOG_REG_TYPE_COMMIT		18
112*4882a593Smuzhiyun #define XLOG_REG_TYPE_TRANSHDR		19
113*4882a593Smuzhiyun #define XLOG_REG_TYPE_ICREATE		20
114*4882a593Smuzhiyun #define XLOG_REG_TYPE_RUI_FORMAT	21
115*4882a593Smuzhiyun #define XLOG_REG_TYPE_RUD_FORMAT	22
116*4882a593Smuzhiyun #define XLOG_REG_TYPE_CUI_FORMAT	23
117*4882a593Smuzhiyun #define XLOG_REG_TYPE_CUD_FORMAT	24
118*4882a593Smuzhiyun #define XLOG_REG_TYPE_BUI_FORMAT	25
119*4882a593Smuzhiyun #define XLOG_REG_TYPE_BUD_FORMAT	26
120*4882a593Smuzhiyun #define XLOG_REG_TYPE_MAX		26
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun /*
123*4882a593Smuzhiyun  * Flags to log operation header
124*4882a593Smuzhiyun  *
125*4882a593Smuzhiyun  * The first write of a new transaction will be preceded with a start
126*4882a593Smuzhiyun  * record, XLOG_START_TRANS.  Once a transaction is committed, a commit
127*4882a593Smuzhiyun  * record is written, XLOG_COMMIT_TRANS.  If a single region can not fit into
128*4882a593Smuzhiyun  * the remainder of the current active in-core log, it is split up into
129*4882a593Smuzhiyun  * multiple regions.  Each partial region will be marked with a
130*4882a593Smuzhiyun  * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
131*4882a593Smuzhiyun  *
132*4882a593Smuzhiyun  */
133*4882a593Smuzhiyun #define XLOG_START_TRANS	0x01	/* Start a new transaction */
134*4882a593Smuzhiyun #define XLOG_COMMIT_TRANS	0x02	/* Commit this transaction */
135*4882a593Smuzhiyun #define XLOG_CONTINUE_TRANS	0x04	/* Cont this trans into new region */
136*4882a593Smuzhiyun #define XLOG_WAS_CONT_TRANS	0x08	/* Cont this trans into new region */
137*4882a593Smuzhiyun #define XLOG_END_TRANS		0x10	/* End a continued transaction */
138*4882a593Smuzhiyun #define XLOG_UNMOUNT_TRANS	0x20	/* Unmount a filesystem transaction */
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 
141*4882a593Smuzhiyun typedef struct xlog_op_header {
142*4882a593Smuzhiyun 	__be32	   oh_tid;	/* transaction id of operation	:  4 b */
143*4882a593Smuzhiyun 	__be32	   oh_len;	/* bytes in data region		:  4 b */
144*4882a593Smuzhiyun 	__u8	   oh_clientid;	/* who sent me this		:  1 b */
145*4882a593Smuzhiyun 	__u8	   oh_flags;	/*				:  1 b */
146*4882a593Smuzhiyun 	__u16	   oh_res2;	/* 32 bit align			:  2 b */
147*4882a593Smuzhiyun } xlog_op_header_t;
148*4882a593Smuzhiyun 
149*4882a593Smuzhiyun /* valid values for h_fmt */
150*4882a593Smuzhiyun #define XLOG_FMT_UNKNOWN  0
151*4882a593Smuzhiyun #define XLOG_FMT_LINUX_LE 1
152*4882a593Smuzhiyun #define XLOG_FMT_LINUX_BE 2
153*4882a593Smuzhiyun #define XLOG_FMT_IRIX_BE  3
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun /* our fmt */
156*4882a593Smuzhiyun #ifdef XFS_NATIVE_HOST
157*4882a593Smuzhiyun #define XLOG_FMT XLOG_FMT_LINUX_BE
158*4882a593Smuzhiyun #else
159*4882a593Smuzhiyun #define XLOG_FMT XLOG_FMT_LINUX_LE
160*4882a593Smuzhiyun #endif
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun typedef struct xlog_rec_header {
163*4882a593Smuzhiyun 	__be32	  h_magicno;	/* log record (LR) identifier		:  4 */
164*4882a593Smuzhiyun 	__be32	  h_cycle;	/* write cycle of log			:  4 */
165*4882a593Smuzhiyun 	__be32	  h_version;	/* LR version				:  4 */
166*4882a593Smuzhiyun 	__be32	  h_len;	/* len in bytes; should be 64-bit aligned: 4 */
167*4882a593Smuzhiyun 	__be64	  h_lsn;	/* lsn of this LR			:  8 */
168*4882a593Smuzhiyun 	__be64	  h_tail_lsn;	/* lsn of 1st LR w/ buffers not committed: 8 */
169*4882a593Smuzhiyun 	__le32	  h_crc;	/* crc of log record                    :  4 */
170*4882a593Smuzhiyun 	__be32	  h_prev_block; /* block number to previous LR		:  4 */
171*4882a593Smuzhiyun 	__be32	  h_num_logops;	/* number of log operations in this LR	:  4 */
172*4882a593Smuzhiyun 	__be32	  h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
173*4882a593Smuzhiyun 	/* new fields */
174*4882a593Smuzhiyun 	__be32    h_fmt;        /* format of log record                 :  4 */
175*4882a593Smuzhiyun 	uuid_t	  h_fs_uuid;    /* uuid of FS                           : 16 */
176*4882a593Smuzhiyun 	__be32	  h_size;	/* iclog size				:  4 */
177*4882a593Smuzhiyun } xlog_rec_header_t;
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun typedef struct xlog_rec_ext_header {
180*4882a593Smuzhiyun 	__be32	  xh_cycle;	/* write cycle of log			: 4 */
181*4882a593Smuzhiyun 	__be32	  xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /*	: 256 */
182*4882a593Smuzhiyun } xlog_rec_ext_header_t;
183*4882a593Smuzhiyun 
184*4882a593Smuzhiyun /*
185*4882a593Smuzhiyun  * Quite misnamed, because this union lays out the actual on-disk log buffer.
186*4882a593Smuzhiyun  */
187*4882a593Smuzhiyun typedef union xlog_in_core2 {
188*4882a593Smuzhiyun 	xlog_rec_header_t	hic_header;
189*4882a593Smuzhiyun 	xlog_rec_ext_header_t	hic_xheader;
190*4882a593Smuzhiyun 	char			hic_sector[XLOG_HEADER_SIZE];
191*4882a593Smuzhiyun } xlog_in_core_2_t;
192*4882a593Smuzhiyun 
193*4882a593Smuzhiyun /* not an on-disk structure, but needed by log recovery in userspace */
194*4882a593Smuzhiyun typedef struct xfs_log_iovec {
195*4882a593Smuzhiyun 	void		*i_addr;	/* beginning address of region */
196*4882a593Smuzhiyun 	int		i_len;		/* length in bytes of region */
197*4882a593Smuzhiyun 	uint		i_type;		/* type of region */
198*4882a593Smuzhiyun } xfs_log_iovec_t;
199*4882a593Smuzhiyun 
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun /*
202*4882a593Smuzhiyun  * Transaction Header definitions.
203*4882a593Smuzhiyun  *
204*4882a593Smuzhiyun  * This is the structure written in the log at the head of every transaction. It
205*4882a593Smuzhiyun  * identifies the type and id of the transaction, and contains the number of
206*4882a593Smuzhiyun  * items logged by the transaction so we know how many to expect during
207*4882a593Smuzhiyun  * recovery.
208*4882a593Smuzhiyun  *
209*4882a593Smuzhiyun  * Do not change the below structure without redoing the code in
210*4882a593Smuzhiyun  * xlog_recover_add_to_trans() and xlog_recover_add_to_cont_trans().
211*4882a593Smuzhiyun  */
212*4882a593Smuzhiyun typedef struct xfs_trans_header {
213*4882a593Smuzhiyun 	uint		th_magic;		/* magic number */
214*4882a593Smuzhiyun 	uint		th_type;		/* transaction type */
215*4882a593Smuzhiyun 	int32_t		th_tid;			/* transaction id (unused) */
216*4882a593Smuzhiyun 	uint		th_num_items;		/* num items logged by trans */
217*4882a593Smuzhiyun } xfs_trans_header_t;
218*4882a593Smuzhiyun 
219*4882a593Smuzhiyun #define	XFS_TRANS_HEADER_MAGIC	0x5452414e	/* TRAN */
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun /*
222*4882a593Smuzhiyun  * The only type valid for th_type in CIL-enabled file system logs:
223*4882a593Smuzhiyun  */
224*4882a593Smuzhiyun #define XFS_TRANS_CHECKPOINT	40
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun /*
227*4882a593Smuzhiyun  * Log item types.
228*4882a593Smuzhiyun  */
229*4882a593Smuzhiyun #define	XFS_LI_EFI		0x1236
230*4882a593Smuzhiyun #define	XFS_LI_EFD		0x1237
231*4882a593Smuzhiyun #define	XFS_LI_IUNLINK		0x1238
232*4882a593Smuzhiyun #define	XFS_LI_INODE		0x123b	/* aligned ino chunks, var-size ibufs */
233*4882a593Smuzhiyun #define	XFS_LI_BUF		0x123c	/* v2 bufs, variable sized inode bufs */
234*4882a593Smuzhiyun #define	XFS_LI_DQUOT		0x123d
235*4882a593Smuzhiyun #define	XFS_LI_QUOTAOFF		0x123e
236*4882a593Smuzhiyun #define	XFS_LI_ICREATE		0x123f
237*4882a593Smuzhiyun #define	XFS_LI_RUI		0x1240	/* rmap update intent */
238*4882a593Smuzhiyun #define	XFS_LI_RUD		0x1241
239*4882a593Smuzhiyun #define	XFS_LI_CUI		0x1242	/* refcount update intent */
240*4882a593Smuzhiyun #define	XFS_LI_CUD		0x1243
241*4882a593Smuzhiyun #define	XFS_LI_BUI		0x1244	/* bmbt update intent */
242*4882a593Smuzhiyun #define	XFS_LI_BUD		0x1245
243*4882a593Smuzhiyun 
244*4882a593Smuzhiyun #define XFS_LI_TYPE_DESC \
245*4882a593Smuzhiyun 	{ XFS_LI_EFI,		"XFS_LI_EFI" }, \
246*4882a593Smuzhiyun 	{ XFS_LI_EFD,		"XFS_LI_EFD" }, \
247*4882a593Smuzhiyun 	{ XFS_LI_IUNLINK,	"XFS_LI_IUNLINK" }, \
248*4882a593Smuzhiyun 	{ XFS_LI_INODE,		"XFS_LI_INODE" }, \
249*4882a593Smuzhiyun 	{ XFS_LI_BUF,		"XFS_LI_BUF" }, \
250*4882a593Smuzhiyun 	{ XFS_LI_DQUOT,		"XFS_LI_DQUOT" }, \
251*4882a593Smuzhiyun 	{ XFS_LI_QUOTAOFF,	"XFS_LI_QUOTAOFF" }, \
252*4882a593Smuzhiyun 	{ XFS_LI_ICREATE,	"XFS_LI_ICREATE" }, \
253*4882a593Smuzhiyun 	{ XFS_LI_RUI,		"XFS_LI_RUI" }, \
254*4882a593Smuzhiyun 	{ XFS_LI_RUD,		"XFS_LI_RUD" }, \
255*4882a593Smuzhiyun 	{ XFS_LI_CUI,		"XFS_LI_CUI" }, \
256*4882a593Smuzhiyun 	{ XFS_LI_CUD,		"XFS_LI_CUD" }, \
257*4882a593Smuzhiyun 	{ XFS_LI_BUI,		"XFS_LI_BUI" }, \
258*4882a593Smuzhiyun 	{ XFS_LI_BUD,		"XFS_LI_BUD" }
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun /*
261*4882a593Smuzhiyun  * Inode Log Item Format definitions.
262*4882a593Smuzhiyun  *
263*4882a593Smuzhiyun  * This is the structure used to lay out an inode log item in the
264*4882a593Smuzhiyun  * log.  The size of the inline data/extents/b-tree root to be logged
265*4882a593Smuzhiyun  * (if any) is indicated in the ilf_dsize field.  Changes to this structure
266*4882a593Smuzhiyun  * must be added on to the end.
267*4882a593Smuzhiyun  */
268*4882a593Smuzhiyun struct xfs_inode_log_format {
269*4882a593Smuzhiyun 	uint16_t		ilf_type;	/* inode log item type */
270*4882a593Smuzhiyun 	uint16_t		ilf_size;	/* size of this item */
271*4882a593Smuzhiyun 	uint32_t		ilf_fields;	/* flags for fields logged */
272*4882a593Smuzhiyun 	uint16_t		ilf_asize;	/* size of attr d/ext/root */
273*4882a593Smuzhiyun 	uint16_t		ilf_dsize;	/* size of data/ext/root */
274*4882a593Smuzhiyun 	uint32_t		ilf_pad;	/* pad for 64 bit boundary */
275*4882a593Smuzhiyun 	uint64_t		ilf_ino;	/* inode number */
276*4882a593Smuzhiyun 	union {
277*4882a593Smuzhiyun 		uint32_t	ilfu_rdev;	/* rdev value for dev inode*/
278*4882a593Smuzhiyun 		uint8_t		__pad[16];	/* unused */
279*4882a593Smuzhiyun 	} ilf_u;
280*4882a593Smuzhiyun 	int64_t			ilf_blkno;	/* blkno of inode buffer */
281*4882a593Smuzhiyun 	int32_t			ilf_len;	/* len of inode buffer */
282*4882a593Smuzhiyun 	int32_t			ilf_boffset;	/* off of inode in buffer */
283*4882a593Smuzhiyun };
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun /*
286*4882a593Smuzhiyun  * Old 32 bit systems will log in this format without the 64 bit
287*4882a593Smuzhiyun  * alignment padding. Recovery will detect this and convert it to the
288*4882a593Smuzhiyun  * correct format.
289*4882a593Smuzhiyun  */
290*4882a593Smuzhiyun struct xfs_inode_log_format_32 {
291*4882a593Smuzhiyun 	uint16_t		ilf_type;	/* inode log item type */
292*4882a593Smuzhiyun 	uint16_t		ilf_size;	/* size of this item */
293*4882a593Smuzhiyun 	uint32_t		ilf_fields;	/* flags for fields logged */
294*4882a593Smuzhiyun 	uint16_t		ilf_asize;	/* size of attr d/ext/root */
295*4882a593Smuzhiyun 	uint16_t		ilf_dsize;	/* size of data/ext/root */
296*4882a593Smuzhiyun 	uint64_t		ilf_ino;	/* inode number */
297*4882a593Smuzhiyun 	union {
298*4882a593Smuzhiyun 		uint32_t	ilfu_rdev;	/* rdev value for dev inode*/
299*4882a593Smuzhiyun 		uint8_t		__pad[16];	/* unused */
300*4882a593Smuzhiyun 	} ilf_u;
301*4882a593Smuzhiyun 	int64_t			ilf_blkno;	/* blkno of inode buffer */
302*4882a593Smuzhiyun 	int32_t			ilf_len;	/* len of inode buffer */
303*4882a593Smuzhiyun 	int32_t			ilf_boffset;	/* off of inode in buffer */
304*4882a593Smuzhiyun } __attribute__((packed));
305*4882a593Smuzhiyun 
306*4882a593Smuzhiyun 
307*4882a593Smuzhiyun /*
308*4882a593Smuzhiyun  * Flags for xfs_trans_log_inode flags field.
309*4882a593Smuzhiyun  */
310*4882a593Smuzhiyun #define	XFS_ILOG_CORE	0x001	/* log standard inode fields */
311*4882a593Smuzhiyun #define	XFS_ILOG_DDATA	0x002	/* log i_df.if_data */
312*4882a593Smuzhiyun #define	XFS_ILOG_DEXT	0x004	/* log i_df.if_extents */
313*4882a593Smuzhiyun #define	XFS_ILOG_DBROOT	0x008	/* log i_df.i_broot */
314*4882a593Smuzhiyun #define	XFS_ILOG_DEV	0x010	/* log the dev field */
315*4882a593Smuzhiyun #define	XFS_ILOG_UUID	0x020	/* added long ago, but never used */
316*4882a593Smuzhiyun #define	XFS_ILOG_ADATA	0x040	/* log i_af.if_data */
317*4882a593Smuzhiyun #define	XFS_ILOG_AEXT	0x080	/* log i_af.if_extents */
318*4882a593Smuzhiyun #define	XFS_ILOG_ABROOT	0x100	/* log i_af.i_broot */
319*4882a593Smuzhiyun #define XFS_ILOG_DOWNER	0x200	/* change the data fork owner on replay */
320*4882a593Smuzhiyun #define XFS_ILOG_AOWNER	0x400	/* change the attr fork owner on replay */
321*4882a593Smuzhiyun 
322*4882a593Smuzhiyun 
323*4882a593Smuzhiyun /*
324*4882a593Smuzhiyun  * The timestamps are dirty, but not necessarily anything else in the inode
325*4882a593Smuzhiyun  * core.  Unlike the other fields above this one must never make it to disk
326*4882a593Smuzhiyun  * in the ilf_fields of the inode_log_format, but is purely store in-memory in
327*4882a593Smuzhiyun  * ili_fields in the inode_log_item.
328*4882a593Smuzhiyun  */
329*4882a593Smuzhiyun #define XFS_ILOG_TIMESTAMP	0x4000
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun #define	XFS_ILOG_NONCORE	(XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
332*4882a593Smuzhiyun 				 XFS_ILOG_DBROOT | XFS_ILOG_DEV | \
333*4882a593Smuzhiyun 				 XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
334*4882a593Smuzhiyun 				 XFS_ILOG_ABROOT | XFS_ILOG_DOWNER | \
335*4882a593Smuzhiyun 				 XFS_ILOG_AOWNER)
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun #define	XFS_ILOG_DFORK		(XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
338*4882a593Smuzhiyun 				 XFS_ILOG_DBROOT)
339*4882a593Smuzhiyun 
340*4882a593Smuzhiyun #define	XFS_ILOG_AFORK		(XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
341*4882a593Smuzhiyun 				 XFS_ILOG_ABROOT)
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun #define	XFS_ILOG_ALL		(XFS_ILOG_CORE | XFS_ILOG_DDATA | \
344*4882a593Smuzhiyun 				 XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \
345*4882a593Smuzhiyun 				 XFS_ILOG_DEV | XFS_ILOG_ADATA | \
346*4882a593Smuzhiyun 				 XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \
347*4882a593Smuzhiyun 				 XFS_ILOG_TIMESTAMP | XFS_ILOG_DOWNER | \
348*4882a593Smuzhiyun 				 XFS_ILOG_AOWNER)
349*4882a593Smuzhiyun 
xfs_ilog_fbroot(int w)350*4882a593Smuzhiyun static inline int xfs_ilog_fbroot(int w)
351*4882a593Smuzhiyun {
352*4882a593Smuzhiyun 	return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
353*4882a593Smuzhiyun }
354*4882a593Smuzhiyun 
xfs_ilog_fext(int w)355*4882a593Smuzhiyun static inline int xfs_ilog_fext(int w)
356*4882a593Smuzhiyun {
357*4882a593Smuzhiyun 	return (w == XFS_DATA_FORK ? XFS_ILOG_DEXT : XFS_ILOG_AEXT);
358*4882a593Smuzhiyun }
359*4882a593Smuzhiyun 
xfs_ilog_fdata(int w)360*4882a593Smuzhiyun static inline int xfs_ilog_fdata(int w)
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun 	return (w == XFS_DATA_FORK ? XFS_ILOG_DDATA : XFS_ILOG_ADATA);
363*4882a593Smuzhiyun }
364*4882a593Smuzhiyun 
365*4882a593Smuzhiyun /*
366*4882a593Smuzhiyun  * Incore version of the on-disk inode core structures. We log this directly
367*4882a593Smuzhiyun  * into the journal in host CPU format (for better or worse) and as such
368*4882a593Smuzhiyun  * directly mirrors the xfs_dinode structure as it must contain all the same
369*4882a593Smuzhiyun  * information.
370*4882a593Smuzhiyun  */
371*4882a593Smuzhiyun typedef uint64_t xfs_ictimestamp_t;
372*4882a593Smuzhiyun 
373*4882a593Smuzhiyun /* Legacy timestamp encoding format. */
374*4882a593Smuzhiyun struct xfs_legacy_ictimestamp {
375*4882a593Smuzhiyun 	int32_t		t_sec;		/* timestamp seconds */
376*4882a593Smuzhiyun 	int32_t		t_nsec;		/* timestamp nanoseconds */
377*4882a593Smuzhiyun };
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun /*
380*4882a593Smuzhiyun  * Define the format of the inode core that is logged. This structure must be
381*4882a593Smuzhiyun  * kept identical to struct xfs_dinode except for the endianness annotations.
382*4882a593Smuzhiyun  */
383*4882a593Smuzhiyun struct xfs_log_dinode {
384*4882a593Smuzhiyun 	uint16_t	di_magic;	/* inode magic # = XFS_DINODE_MAGIC */
385*4882a593Smuzhiyun 	uint16_t	di_mode;	/* mode and type of file */
386*4882a593Smuzhiyun 	int8_t		di_version;	/* inode version */
387*4882a593Smuzhiyun 	int8_t		di_format;	/* format of di_c data */
388*4882a593Smuzhiyun 	uint8_t		di_pad3[2];	/* unused in v2/3 inodes */
389*4882a593Smuzhiyun 	uint32_t	di_uid;		/* owner's user id */
390*4882a593Smuzhiyun 	uint32_t	di_gid;		/* owner's group id */
391*4882a593Smuzhiyun 	uint32_t	di_nlink;	/* number of links to file */
392*4882a593Smuzhiyun 	uint16_t	di_projid_lo;	/* lower part of owner's project id */
393*4882a593Smuzhiyun 	uint16_t	di_projid_hi;	/* higher part of owner's project id */
394*4882a593Smuzhiyun 	uint8_t		di_pad[6];	/* unused, zeroed space */
395*4882a593Smuzhiyun 	uint16_t	di_flushiter;	/* incremented on flush */
396*4882a593Smuzhiyun 	xfs_ictimestamp_t di_atime;	/* time last accessed */
397*4882a593Smuzhiyun 	xfs_ictimestamp_t di_mtime;	/* time last modified */
398*4882a593Smuzhiyun 	xfs_ictimestamp_t di_ctime;	/* time created/inode modified */
399*4882a593Smuzhiyun 	xfs_fsize_t	di_size;	/* number of bytes in file */
400*4882a593Smuzhiyun 	xfs_rfsblock_t	di_nblocks;	/* # of direct & btree blocks used */
401*4882a593Smuzhiyun 	xfs_extlen_t	di_extsize;	/* basic/minimum extent size for file */
402*4882a593Smuzhiyun 	xfs_extnum_t	di_nextents;	/* number of extents in data fork */
403*4882a593Smuzhiyun 	xfs_aextnum_t	di_anextents;	/* number of extents in attribute fork*/
404*4882a593Smuzhiyun 	uint8_t		di_forkoff;	/* attr fork offs, <<3 for 64b align */
405*4882a593Smuzhiyun 	int8_t		di_aformat;	/* format of attr fork's data */
406*4882a593Smuzhiyun 	uint32_t	di_dmevmask;	/* DMIG event mask */
407*4882a593Smuzhiyun 	uint16_t	di_dmstate;	/* DMIG state info */
408*4882a593Smuzhiyun 	uint16_t	di_flags;	/* random flags, XFS_DIFLAG_... */
409*4882a593Smuzhiyun 	uint32_t	di_gen;		/* generation number */
410*4882a593Smuzhiyun 
411*4882a593Smuzhiyun 	/* di_next_unlinked is the only non-core field in the old dinode */
412*4882a593Smuzhiyun 	xfs_agino_t	di_next_unlinked;/* agi unlinked list ptr */
413*4882a593Smuzhiyun 
414*4882a593Smuzhiyun 	/* start of the extended dinode, writable fields */
415*4882a593Smuzhiyun 	uint32_t	di_crc;		/* CRC of the inode */
416*4882a593Smuzhiyun 	uint64_t	di_changecount;	/* number of attribute changes */
417*4882a593Smuzhiyun 
418*4882a593Smuzhiyun 	/*
419*4882a593Smuzhiyun 	 * The LSN we write to this field during formatting is not a reflection
420*4882a593Smuzhiyun 	 * of the current on-disk LSN. It should never be used for recovery
421*4882a593Smuzhiyun 	 * sequencing, nor should it be recovered into the on-disk inode at all.
422*4882a593Smuzhiyun 	 * See xlog_recover_inode_commit_pass2() and xfs_log_dinode_to_disk()
423*4882a593Smuzhiyun 	 * for details.
424*4882a593Smuzhiyun 	 */
425*4882a593Smuzhiyun 	xfs_lsn_t	di_lsn;
426*4882a593Smuzhiyun 
427*4882a593Smuzhiyun 	uint64_t	di_flags2;	/* more random flags */
428*4882a593Smuzhiyun 	uint32_t	di_cowextsize;	/* basic cow extent size for file */
429*4882a593Smuzhiyun 	uint8_t		di_pad2[12];	/* more padding for future expansion */
430*4882a593Smuzhiyun 
431*4882a593Smuzhiyun 	/* fields only written to during inode creation */
432*4882a593Smuzhiyun 	xfs_ictimestamp_t di_crtime;	/* time created */
433*4882a593Smuzhiyun 	xfs_ino_t	di_ino;		/* inode number */
434*4882a593Smuzhiyun 	uuid_t		di_uuid;	/* UUID of the filesystem */
435*4882a593Smuzhiyun 
436*4882a593Smuzhiyun 	/* structure must be padded to 64 bit alignment */
437*4882a593Smuzhiyun };
438*4882a593Smuzhiyun 
439*4882a593Smuzhiyun #define xfs_log_dinode_size(mp)						\
440*4882a593Smuzhiyun 	(xfs_sb_version_has_v3inode(&(mp)->m_sb) ?			\
441*4882a593Smuzhiyun 		sizeof(struct xfs_log_dinode) :				\
442*4882a593Smuzhiyun 		offsetof(struct xfs_log_dinode, di_next_unlinked))
443*4882a593Smuzhiyun 
444*4882a593Smuzhiyun /*
445*4882a593Smuzhiyun  * Buffer Log Format definitions
446*4882a593Smuzhiyun  *
447*4882a593Smuzhiyun  * These are the physical dirty bitmap definitions for the log format structure.
448*4882a593Smuzhiyun  */
449*4882a593Smuzhiyun #define	XFS_BLF_CHUNK		128
450*4882a593Smuzhiyun #define	XFS_BLF_SHIFT		7
451*4882a593Smuzhiyun #define	BIT_TO_WORD_SHIFT	5
452*4882a593Smuzhiyun #define	NBWORD			(NBBY * sizeof(unsigned int))
453*4882a593Smuzhiyun 
454*4882a593Smuzhiyun /*
455*4882a593Smuzhiyun  * This flag indicates that the buffer contains on disk inodes
456*4882a593Smuzhiyun  * and requires special recovery handling.
457*4882a593Smuzhiyun  */
458*4882a593Smuzhiyun #define	XFS_BLF_INODE_BUF	(1<<0)
459*4882a593Smuzhiyun 
460*4882a593Smuzhiyun /*
461*4882a593Smuzhiyun  * This flag indicates that the buffer should not be replayed
462*4882a593Smuzhiyun  * during recovery because its blocks are being freed.
463*4882a593Smuzhiyun  */
464*4882a593Smuzhiyun #define	XFS_BLF_CANCEL		(1<<1)
465*4882a593Smuzhiyun 
466*4882a593Smuzhiyun /*
467*4882a593Smuzhiyun  * This flag indicates that the buffer contains on disk
468*4882a593Smuzhiyun  * user or group dquots and may require special recovery handling.
469*4882a593Smuzhiyun  */
470*4882a593Smuzhiyun #define	XFS_BLF_UDQUOT_BUF	(1<<2)
471*4882a593Smuzhiyun #define XFS_BLF_PDQUOT_BUF	(1<<3)
472*4882a593Smuzhiyun #define	XFS_BLF_GDQUOT_BUF	(1<<4)
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun /*
475*4882a593Smuzhiyun  * This is the structure used to lay out a buf log item in the log.  The data
476*4882a593Smuzhiyun  * map describes which 128 byte chunks of the buffer have been logged.
477*4882a593Smuzhiyun  *
478*4882a593Smuzhiyun  * The placement of blf_map_size causes blf_data_map to start at an odd
479*4882a593Smuzhiyun  * multiple of sizeof(unsigned int) offset within the struct.  Because the data
480*4882a593Smuzhiyun  * bitmap size will always be an even number, the end of the data_map (and
481*4882a593Smuzhiyun  * therefore the structure) will also be at an odd multiple of sizeof(unsigned
482*4882a593Smuzhiyun  * int).  Some 64-bit compilers will insert padding at the end of the struct to
483*4882a593Smuzhiyun  * ensure 64-bit alignment of blf_blkno, but 32-bit ones will not.  Therefore,
484*4882a593Smuzhiyun  * XFS_BLF_DATAMAP_SIZE must be an odd number to make the padding explicit and
485*4882a593Smuzhiyun  * keep the structure size consistent between 32-bit and 64-bit platforms.
486*4882a593Smuzhiyun  */
487*4882a593Smuzhiyun #define __XFS_BLF_DATAMAP_SIZE	((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
488*4882a593Smuzhiyun #define XFS_BLF_DATAMAP_SIZE	(__XFS_BLF_DATAMAP_SIZE + 1)
489*4882a593Smuzhiyun 
490*4882a593Smuzhiyun typedef struct xfs_buf_log_format {
491*4882a593Smuzhiyun 	unsigned short	blf_type;	/* buf log item type indicator */
492*4882a593Smuzhiyun 	unsigned short	blf_size;	/* size of this item */
493*4882a593Smuzhiyun 	unsigned short	blf_flags;	/* misc state */
494*4882a593Smuzhiyun 	unsigned short	blf_len;	/* number of blocks in this buf */
495*4882a593Smuzhiyun 	int64_t		blf_blkno;	/* starting blkno of this buf */
496*4882a593Smuzhiyun 	unsigned int	blf_map_size;	/* used size of data bitmap in words */
497*4882a593Smuzhiyun 	unsigned int	blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
498*4882a593Smuzhiyun } xfs_buf_log_format_t;
499*4882a593Smuzhiyun 
500*4882a593Smuzhiyun /*
501*4882a593Smuzhiyun  * All buffers now need to tell recovery where the magic number
502*4882a593Smuzhiyun  * is so that it can verify and calculate the CRCs on the buffer correctly
503*4882a593Smuzhiyun  * once the changes have been replayed into the buffer.
504*4882a593Smuzhiyun  *
505*4882a593Smuzhiyun  * The type value is held in the upper 5 bits of the blf_flags field, which is
506*4882a593Smuzhiyun  * an unsigned 16 bit field. Hence we need to shift it 11 bits up and down.
507*4882a593Smuzhiyun  */
508*4882a593Smuzhiyun #define XFS_BLFT_BITS	5
509*4882a593Smuzhiyun #define XFS_BLFT_SHIFT	11
510*4882a593Smuzhiyun #define XFS_BLFT_MASK	(((1 << XFS_BLFT_BITS) - 1) << XFS_BLFT_SHIFT)
511*4882a593Smuzhiyun 
512*4882a593Smuzhiyun enum xfs_blft {
513*4882a593Smuzhiyun 	XFS_BLFT_UNKNOWN_BUF = 0,
514*4882a593Smuzhiyun 	XFS_BLFT_UDQUOT_BUF,
515*4882a593Smuzhiyun 	XFS_BLFT_PDQUOT_BUF,
516*4882a593Smuzhiyun 	XFS_BLFT_GDQUOT_BUF,
517*4882a593Smuzhiyun 	XFS_BLFT_BTREE_BUF,
518*4882a593Smuzhiyun 	XFS_BLFT_AGF_BUF,
519*4882a593Smuzhiyun 	XFS_BLFT_AGFL_BUF,
520*4882a593Smuzhiyun 	XFS_BLFT_AGI_BUF,
521*4882a593Smuzhiyun 	XFS_BLFT_DINO_BUF,
522*4882a593Smuzhiyun 	XFS_BLFT_SYMLINK_BUF,
523*4882a593Smuzhiyun 	XFS_BLFT_DIR_BLOCK_BUF,
524*4882a593Smuzhiyun 	XFS_BLFT_DIR_DATA_BUF,
525*4882a593Smuzhiyun 	XFS_BLFT_DIR_FREE_BUF,
526*4882a593Smuzhiyun 	XFS_BLFT_DIR_LEAF1_BUF,
527*4882a593Smuzhiyun 	XFS_BLFT_DIR_LEAFN_BUF,
528*4882a593Smuzhiyun 	XFS_BLFT_DA_NODE_BUF,
529*4882a593Smuzhiyun 	XFS_BLFT_ATTR_LEAF_BUF,
530*4882a593Smuzhiyun 	XFS_BLFT_ATTR_RMT_BUF,
531*4882a593Smuzhiyun 	XFS_BLFT_SB_BUF,
532*4882a593Smuzhiyun 	XFS_BLFT_RTBITMAP_BUF,
533*4882a593Smuzhiyun 	XFS_BLFT_RTSUMMARY_BUF,
534*4882a593Smuzhiyun 	XFS_BLFT_MAX_BUF = (1 << XFS_BLFT_BITS),
535*4882a593Smuzhiyun };
536*4882a593Smuzhiyun 
537*4882a593Smuzhiyun static inline void
xfs_blft_to_flags(struct xfs_buf_log_format * blf,enum xfs_blft type)538*4882a593Smuzhiyun xfs_blft_to_flags(struct xfs_buf_log_format *blf, enum xfs_blft type)
539*4882a593Smuzhiyun {
540*4882a593Smuzhiyun 	ASSERT(type > XFS_BLFT_UNKNOWN_BUF && type < XFS_BLFT_MAX_BUF);
541*4882a593Smuzhiyun 	blf->blf_flags &= ~XFS_BLFT_MASK;
542*4882a593Smuzhiyun 	blf->blf_flags |= ((type << XFS_BLFT_SHIFT) & XFS_BLFT_MASK);
543*4882a593Smuzhiyun }
544*4882a593Smuzhiyun 
545*4882a593Smuzhiyun static inline uint16_t
xfs_blft_from_flags(struct xfs_buf_log_format * blf)546*4882a593Smuzhiyun xfs_blft_from_flags(struct xfs_buf_log_format *blf)
547*4882a593Smuzhiyun {
548*4882a593Smuzhiyun 	return (blf->blf_flags & XFS_BLFT_MASK) >> XFS_BLFT_SHIFT;
549*4882a593Smuzhiyun }
550*4882a593Smuzhiyun 
551*4882a593Smuzhiyun /*
552*4882a593Smuzhiyun  * EFI/EFD log format definitions
553*4882a593Smuzhiyun  */
554*4882a593Smuzhiyun typedef struct xfs_extent {
555*4882a593Smuzhiyun 	xfs_fsblock_t	ext_start;
556*4882a593Smuzhiyun 	xfs_extlen_t	ext_len;
557*4882a593Smuzhiyun } xfs_extent_t;
558*4882a593Smuzhiyun 
559*4882a593Smuzhiyun /*
560*4882a593Smuzhiyun  * Since an xfs_extent_t has types (start:64, len: 32)
561*4882a593Smuzhiyun  * there are different alignments on 32 bit and 64 bit kernels.
562*4882a593Smuzhiyun  * So we provide the different variants for use by a
563*4882a593Smuzhiyun  * conversion routine.
564*4882a593Smuzhiyun  */
565*4882a593Smuzhiyun typedef struct xfs_extent_32 {
566*4882a593Smuzhiyun 	uint64_t	ext_start;
567*4882a593Smuzhiyun 	uint32_t	ext_len;
568*4882a593Smuzhiyun } __attribute__((packed)) xfs_extent_32_t;
569*4882a593Smuzhiyun 
570*4882a593Smuzhiyun typedef struct xfs_extent_64 {
571*4882a593Smuzhiyun 	uint64_t	ext_start;
572*4882a593Smuzhiyun 	uint32_t	ext_len;
573*4882a593Smuzhiyun 	uint32_t	ext_pad;
574*4882a593Smuzhiyun } xfs_extent_64_t;
575*4882a593Smuzhiyun 
576*4882a593Smuzhiyun /*
577*4882a593Smuzhiyun  * This is the structure used to lay out an efi log item in the
578*4882a593Smuzhiyun  * log.  The efi_extents field is a variable size array whose
579*4882a593Smuzhiyun  * size is given by efi_nextents.
580*4882a593Smuzhiyun  */
581*4882a593Smuzhiyun typedef struct xfs_efi_log_format {
582*4882a593Smuzhiyun 	uint16_t		efi_type;	/* efi log item type */
583*4882a593Smuzhiyun 	uint16_t		efi_size;	/* size of this item */
584*4882a593Smuzhiyun 	uint32_t		efi_nextents;	/* # extents to free */
585*4882a593Smuzhiyun 	uint64_t		efi_id;		/* efi identifier */
586*4882a593Smuzhiyun 	xfs_extent_t		efi_extents[1];	/* array of extents to free */
587*4882a593Smuzhiyun } xfs_efi_log_format_t;
588*4882a593Smuzhiyun 
589*4882a593Smuzhiyun typedef struct xfs_efi_log_format_32 {
590*4882a593Smuzhiyun 	uint16_t		efi_type;	/* efi log item type */
591*4882a593Smuzhiyun 	uint16_t		efi_size;	/* size of this item */
592*4882a593Smuzhiyun 	uint32_t		efi_nextents;	/* # extents to free */
593*4882a593Smuzhiyun 	uint64_t		efi_id;		/* efi identifier */
594*4882a593Smuzhiyun 	xfs_extent_32_t		efi_extents[1];	/* array of extents to free */
595*4882a593Smuzhiyun } __attribute__((packed)) xfs_efi_log_format_32_t;
596*4882a593Smuzhiyun 
597*4882a593Smuzhiyun typedef struct xfs_efi_log_format_64 {
598*4882a593Smuzhiyun 	uint16_t		efi_type;	/* efi log item type */
599*4882a593Smuzhiyun 	uint16_t		efi_size;	/* size of this item */
600*4882a593Smuzhiyun 	uint32_t		efi_nextents;	/* # extents to free */
601*4882a593Smuzhiyun 	uint64_t		efi_id;		/* efi identifier */
602*4882a593Smuzhiyun 	xfs_extent_64_t		efi_extents[1];	/* array of extents to free */
603*4882a593Smuzhiyun } xfs_efi_log_format_64_t;
604*4882a593Smuzhiyun 
605*4882a593Smuzhiyun /*
606*4882a593Smuzhiyun  * This is the structure used to lay out an efd log item in the
607*4882a593Smuzhiyun  * log.  The efd_extents array is a variable size array whose
608*4882a593Smuzhiyun  * size is given by efd_nextents;
609*4882a593Smuzhiyun  */
610*4882a593Smuzhiyun typedef struct xfs_efd_log_format {
611*4882a593Smuzhiyun 	uint16_t		efd_type;	/* efd log item type */
612*4882a593Smuzhiyun 	uint16_t		efd_size;	/* size of this item */
613*4882a593Smuzhiyun 	uint32_t		efd_nextents;	/* # of extents freed */
614*4882a593Smuzhiyun 	uint64_t		efd_efi_id;	/* id of corresponding efi */
615*4882a593Smuzhiyun 	xfs_extent_t		efd_extents[1];	/* array of extents freed */
616*4882a593Smuzhiyun } xfs_efd_log_format_t;
617*4882a593Smuzhiyun 
618*4882a593Smuzhiyun typedef struct xfs_efd_log_format_32 {
619*4882a593Smuzhiyun 	uint16_t		efd_type;	/* efd log item type */
620*4882a593Smuzhiyun 	uint16_t		efd_size;	/* size of this item */
621*4882a593Smuzhiyun 	uint32_t		efd_nextents;	/* # of extents freed */
622*4882a593Smuzhiyun 	uint64_t		efd_efi_id;	/* id of corresponding efi */
623*4882a593Smuzhiyun 	xfs_extent_32_t		efd_extents[1];	/* array of extents freed */
624*4882a593Smuzhiyun } __attribute__((packed)) xfs_efd_log_format_32_t;
625*4882a593Smuzhiyun 
626*4882a593Smuzhiyun typedef struct xfs_efd_log_format_64 {
627*4882a593Smuzhiyun 	uint16_t		efd_type;	/* efd log item type */
628*4882a593Smuzhiyun 	uint16_t		efd_size;	/* size of this item */
629*4882a593Smuzhiyun 	uint32_t		efd_nextents;	/* # of extents freed */
630*4882a593Smuzhiyun 	uint64_t		efd_efi_id;	/* id of corresponding efi */
631*4882a593Smuzhiyun 	xfs_extent_64_t		efd_extents[1];	/* array of extents freed */
632*4882a593Smuzhiyun } xfs_efd_log_format_64_t;
633*4882a593Smuzhiyun 
634*4882a593Smuzhiyun /*
635*4882a593Smuzhiyun  * RUI/RUD (reverse mapping) log format definitions
636*4882a593Smuzhiyun  */
637*4882a593Smuzhiyun struct xfs_map_extent {
638*4882a593Smuzhiyun 	uint64_t		me_owner;
639*4882a593Smuzhiyun 	uint64_t		me_startblock;
640*4882a593Smuzhiyun 	uint64_t		me_startoff;
641*4882a593Smuzhiyun 	uint32_t		me_len;
642*4882a593Smuzhiyun 	uint32_t		me_flags;
643*4882a593Smuzhiyun };
644*4882a593Smuzhiyun 
645*4882a593Smuzhiyun /* rmap me_flags: upper bits are flags, lower byte is type code */
646*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_MAP		1
647*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_MAP_SHARED	2
648*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_UNMAP		3
649*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_UNMAP_SHARED	4
650*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_CONVERT		5
651*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_CONVERT_SHARED	6
652*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_ALLOC		7
653*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_FREE		8
654*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_TYPE_MASK	0xFF
655*4882a593Smuzhiyun 
656*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_ATTR_FORK	(1U << 31)
657*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_BMBT_BLOCK	(1U << 30)
658*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_UNWRITTEN	(1U << 29)
659*4882a593Smuzhiyun 
660*4882a593Smuzhiyun #define XFS_RMAP_EXTENT_FLAGS		(XFS_RMAP_EXTENT_TYPE_MASK | \
661*4882a593Smuzhiyun 					 XFS_RMAP_EXTENT_ATTR_FORK | \
662*4882a593Smuzhiyun 					 XFS_RMAP_EXTENT_BMBT_BLOCK | \
663*4882a593Smuzhiyun 					 XFS_RMAP_EXTENT_UNWRITTEN)
664*4882a593Smuzhiyun 
665*4882a593Smuzhiyun /*
666*4882a593Smuzhiyun  * This is the structure used to lay out an rui log item in the
667*4882a593Smuzhiyun  * log.  The rui_extents field is a variable size array whose
668*4882a593Smuzhiyun  * size is given by rui_nextents.
669*4882a593Smuzhiyun  */
670*4882a593Smuzhiyun struct xfs_rui_log_format {
671*4882a593Smuzhiyun 	uint16_t		rui_type;	/* rui log item type */
672*4882a593Smuzhiyun 	uint16_t		rui_size;	/* size of this item */
673*4882a593Smuzhiyun 	uint32_t		rui_nextents;	/* # extents to free */
674*4882a593Smuzhiyun 	uint64_t		rui_id;		/* rui identifier */
675*4882a593Smuzhiyun 	struct xfs_map_extent	rui_extents[];	/* array of extents to rmap */
676*4882a593Smuzhiyun };
677*4882a593Smuzhiyun 
678*4882a593Smuzhiyun static inline size_t
xfs_rui_log_format_sizeof(unsigned int nr)679*4882a593Smuzhiyun xfs_rui_log_format_sizeof(
680*4882a593Smuzhiyun 	unsigned int		nr)
681*4882a593Smuzhiyun {
682*4882a593Smuzhiyun 	return sizeof(struct xfs_rui_log_format) +
683*4882a593Smuzhiyun 			nr * sizeof(struct xfs_map_extent);
684*4882a593Smuzhiyun }
685*4882a593Smuzhiyun 
686*4882a593Smuzhiyun /*
687*4882a593Smuzhiyun  * This is the structure used to lay out an rud log item in the
688*4882a593Smuzhiyun  * log.  The rud_extents array is a variable size array whose
689*4882a593Smuzhiyun  * size is given by rud_nextents;
690*4882a593Smuzhiyun  */
691*4882a593Smuzhiyun struct xfs_rud_log_format {
692*4882a593Smuzhiyun 	uint16_t		rud_type;	/* rud log item type */
693*4882a593Smuzhiyun 	uint16_t		rud_size;	/* size of this item */
694*4882a593Smuzhiyun 	uint32_t		__pad;
695*4882a593Smuzhiyun 	uint64_t		rud_rui_id;	/* id of corresponding rui */
696*4882a593Smuzhiyun };
697*4882a593Smuzhiyun 
698*4882a593Smuzhiyun /*
699*4882a593Smuzhiyun  * CUI/CUD (refcount update) log format definitions
700*4882a593Smuzhiyun  */
701*4882a593Smuzhiyun struct xfs_phys_extent {
702*4882a593Smuzhiyun 	uint64_t		pe_startblock;
703*4882a593Smuzhiyun 	uint32_t		pe_len;
704*4882a593Smuzhiyun 	uint32_t		pe_flags;
705*4882a593Smuzhiyun };
706*4882a593Smuzhiyun 
707*4882a593Smuzhiyun /* refcount pe_flags: upper bits are flags, lower byte is type code */
708*4882a593Smuzhiyun /* Type codes are taken directly from enum xfs_refcount_intent_type. */
709*4882a593Smuzhiyun #define XFS_REFCOUNT_EXTENT_TYPE_MASK	0xFF
710*4882a593Smuzhiyun 
711*4882a593Smuzhiyun #define XFS_REFCOUNT_EXTENT_FLAGS	(XFS_REFCOUNT_EXTENT_TYPE_MASK)
712*4882a593Smuzhiyun 
713*4882a593Smuzhiyun /*
714*4882a593Smuzhiyun  * This is the structure used to lay out a cui log item in the
715*4882a593Smuzhiyun  * log.  The cui_extents field is a variable size array whose
716*4882a593Smuzhiyun  * size is given by cui_nextents.
717*4882a593Smuzhiyun  */
718*4882a593Smuzhiyun struct xfs_cui_log_format {
719*4882a593Smuzhiyun 	uint16_t		cui_type;	/* cui log item type */
720*4882a593Smuzhiyun 	uint16_t		cui_size;	/* size of this item */
721*4882a593Smuzhiyun 	uint32_t		cui_nextents;	/* # extents to free */
722*4882a593Smuzhiyun 	uint64_t		cui_id;		/* cui identifier */
723*4882a593Smuzhiyun 	struct xfs_phys_extent	cui_extents[];	/* array of extents */
724*4882a593Smuzhiyun };
725*4882a593Smuzhiyun 
726*4882a593Smuzhiyun static inline size_t
xfs_cui_log_format_sizeof(unsigned int nr)727*4882a593Smuzhiyun xfs_cui_log_format_sizeof(
728*4882a593Smuzhiyun 	unsigned int		nr)
729*4882a593Smuzhiyun {
730*4882a593Smuzhiyun 	return sizeof(struct xfs_cui_log_format) +
731*4882a593Smuzhiyun 			nr * sizeof(struct xfs_phys_extent);
732*4882a593Smuzhiyun }
733*4882a593Smuzhiyun 
734*4882a593Smuzhiyun /*
735*4882a593Smuzhiyun  * This is the structure used to lay out a cud log item in the
736*4882a593Smuzhiyun  * log.  The cud_extents array is a variable size array whose
737*4882a593Smuzhiyun  * size is given by cud_nextents;
738*4882a593Smuzhiyun  */
739*4882a593Smuzhiyun struct xfs_cud_log_format {
740*4882a593Smuzhiyun 	uint16_t		cud_type;	/* cud log item type */
741*4882a593Smuzhiyun 	uint16_t		cud_size;	/* size of this item */
742*4882a593Smuzhiyun 	uint32_t		__pad;
743*4882a593Smuzhiyun 	uint64_t		cud_cui_id;	/* id of corresponding cui */
744*4882a593Smuzhiyun };
745*4882a593Smuzhiyun 
746*4882a593Smuzhiyun /*
747*4882a593Smuzhiyun  * BUI/BUD (inode block mapping) log format definitions
748*4882a593Smuzhiyun  */
749*4882a593Smuzhiyun 
750*4882a593Smuzhiyun /* bmbt me_flags: upper bits are flags, lower byte is type code */
751*4882a593Smuzhiyun /* Type codes are taken directly from enum xfs_bmap_intent_type. */
752*4882a593Smuzhiyun #define XFS_BMAP_EXTENT_TYPE_MASK	0xFF
753*4882a593Smuzhiyun 
754*4882a593Smuzhiyun #define XFS_BMAP_EXTENT_ATTR_FORK	(1U << 31)
755*4882a593Smuzhiyun #define XFS_BMAP_EXTENT_UNWRITTEN	(1U << 30)
756*4882a593Smuzhiyun 
757*4882a593Smuzhiyun #define XFS_BMAP_EXTENT_FLAGS		(XFS_BMAP_EXTENT_TYPE_MASK | \
758*4882a593Smuzhiyun 					 XFS_BMAP_EXTENT_ATTR_FORK | \
759*4882a593Smuzhiyun 					 XFS_BMAP_EXTENT_UNWRITTEN)
760*4882a593Smuzhiyun 
761*4882a593Smuzhiyun /*
762*4882a593Smuzhiyun  * This is the structure used to lay out an bui log item in the
763*4882a593Smuzhiyun  * log.  The bui_extents field is a variable size array whose
764*4882a593Smuzhiyun  * size is given by bui_nextents.
765*4882a593Smuzhiyun  */
766*4882a593Smuzhiyun struct xfs_bui_log_format {
767*4882a593Smuzhiyun 	uint16_t		bui_type;	/* bui log item type */
768*4882a593Smuzhiyun 	uint16_t		bui_size;	/* size of this item */
769*4882a593Smuzhiyun 	uint32_t		bui_nextents;	/* # extents to free */
770*4882a593Smuzhiyun 	uint64_t		bui_id;		/* bui identifier */
771*4882a593Smuzhiyun 	struct xfs_map_extent	bui_extents[];	/* array of extents to bmap */
772*4882a593Smuzhiyun };
773*4882a593Smuzhiyun 
774*4882a593Smuzhiyun static inline size_t
xfs_bui_log_format_sizeof(unsigned int nr)775*4882a593Smuzhiyun xfs_bui_log_format_sizeof(
776*4882a593Smuzhiyun 	unsigned int		nr)
777*4882a593Smuzhiyun {
778*4882a593Smuzhiyun 	return sizeof(struct xfs_bui_log_format) +
779*4882a593Smuzhiyun 			nr * sizeof(struct xfs_map_extent);
780*4882a593Smuzhiyun }
781*4882a593Smuzhiyun 
782*4882a593Smuzhiyun /*
783*4882a593Smuzhiyun  * This is the structure used to lay out an bud log item in the
784*4882a593Smuzhiyun  * log.  The bud_extents array is a variable size array whose
785*4882a593Smuzhiyun  * size is given by bud_nextents;
786*4882a593Smuzhiyun  */
787*4882a593Smuzhiyun struct xfs_bud_log_format {
788*4882a593Smuzhiyun 	uint16_t		bud_type;	/* bud log item type */
789*4882a593Smuzhiyun 	uint16_t		bud_size;	/* size of this item */
790*4882a593Smuzhiyun 	uint32_t		__pad;
791*4882a593Smuzhiyun 	uint64_t		bud_bui_id;	/* id of corresponding bui */
792*4882a593Smuzhiyun };
793*4882a593Smuzhiyun 
794*4882a593Smuzhiyun /*
795*4882a593Smuzhiyun  * Dquot Log format definitions.
796*4882a593Smuzhiyun  *
797*4882a593Smuzhiyun  * The first two fields must be the type and size fitting into
798*4882a593Smuzhiyun  * 32 bits : log_recovery code assumes that.
799*4882a593Smuzhiyun  */
800*4882a593Smuzhiyun typedef struct xfs_dq_logformat {
801*4882a593Smuzhiyun 	uint16_t		qlf_type;      /* dquot log item type */
802*4882a593Smuzhiyun 	uint16_t		qlf_size;      /* size of this item */
803*4882a593Smuzhiyun 	xfs_dqid_t		qlf_id;	       /* usr/grp/proj id : 32 bits */
804*4882a593Smuzhiyun 	int64_t			qlf_blkno;     /* blkno of dquot buffer */
805*4882a593Smuzhiyun 	int32_t			qlf_len;       /* len of dquot buffer */
806*4882a593Smuzhiyun 	uint32_t		qlf_boffset;   /* off of dquot in buffer */
807*4882a593Smuzhiyun } xfs_dq_logformat_t;
808*4882a593Smuzhiyun 
809*4882a593Smuzhiyun /*
810*4882a593Smuzhiyun  * log format struct for QUOTAOFF records.
811*4882a593Smuzhiyun  * The first two fields must be the type and size fitting into
812*4882a593Smuzhiyun  * 32 bits : log_recovery code assumes that.
813*4882a593Smuzhiyun  * We write two LI_QUOTAOFF logitems per quotaoff, the last one keeps a pointer
814*4882a593Smuzhiyun  * to the first and ensures that the first logitem is taken out of the AIL
815*4882a593Smuzhiyun  * only when the last one is securely committed.
816*4882a593Smuzhiyun  */
817*4882a593Smuzhiyun typedef struct xfs_qoff_logformat {
818*4882a593Smuzhiyun 	unsigned short		qf_type;	/* quotaoff log item type */
819*4882a593Smuzhiyun 	unsigned short		qf_size;	/* size of this item */
820*4882a593Smuzhiyun 	unsigned int		qf_flags;	/* USR and/or GRP */
821*4882a593Smuzhiyun 	char			qf_pad[12];	/* padding for future */
822*4882a593Smuzhiyun } xfs_qoff_logformat_t;
823*4882a593Smuzhiyun 
824*4882a593Smuzhiyun /*
825*4882a593Smuzhiyun  * Disk quotas status in m_qflags, and also sb_qflags. 16 bits.
826*4882a593Smuzhiyun  */
827*4882a593Smuzhiyun #define XFS_UQUOTA_ACCT	0x0001  /* user quota accounting ON */
828*4882a593Smuzhiyun #define XFS_UQUOTA_ENFD	0x0002  /* user quota limits enforced */
829*4882a593Smuzhiyun #define XFS_UQUOTA_CHKD	0x0004  /* quotacheck run on usr quotas */
830*4882a593Smuzhiyun #define XFS_PQUOTA_ACCT	0x0008  /* project quota accounting ON */
831*4882a593Smuzhiyun #define XFS_OQUOTA_ENFD	0x0010  /* other (grp/prj) quota limits enforced */
832*4882a593Smuzhiyun #define XFS_OQUOTA_CHKD	0x0020  /* quotacheck run on other (grp/prj) quotas */
833*4882a593Smuzhiyun #define XFS_GQUOTA_ACCT	0x0040  /* group quota accounting ON */
834*4882a593Smuzhiyun 
835*4882a593Smuzhiyun /*
836*4882a593Smuzhiyun  * Conversion to and from the combined OQUOTA flag (if necessary)
837*4882a593Smuzhiyun  * is done only in xfs_sb_qflags_to_disk() and xfs_sb_qflags_from_disk()
838*4882a593Smuzhiyun  */
839*4882a593Smuzhiyun #define XFS_GQUOTA_ENFD	0x0080  /* group quota limits enforced */
840*4882a593Smuzhiyun #define XFS_GQUOTA_CHKD	0x0100  /* quotacheck run on group quotas */
841*4882a593Smuzhiyun #define XFS_PQUOTA_ENFD	0x0200  /* project quota limits enforced */
842*4882a593Smuzhiyun #define XFS_PQUOTA_CHKD	0x0400  /* quotacheck run on project quotas */
843*4882a593Smuzhiyun 
844*4882a593Smuzhiyun #define XFS_ALL_QUOTA_ACCT	\
845*4882a593Smuzhiyun 		(XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
846*4882a593Smuzhiyun #define XFS_ALL_QUOTA_ENFD	\
847*4882a593Smuzhiyun 		(XFS_UQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_ENFD)
848*4882a593Smuzhiyun #define XFS_ALL_QUOTA_CHKD	\
849*4882a593Smuzhiyun 		(XFS_UQUOTA_CHKD | XFS_GQUOTA_CHKD | XFS_PQUOTA_CHKD)
850*4882a593Smuzhiyun 
851*4882a593Smuzhiyun #define XFS_MOUNT_QUOTA_ALL	(XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
852*4882a593Smuzhiyun 				 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
853*4882a593Smuzhiyun 				 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD|\
854*4882a593Smuzhiyun 				 XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD|\
855*4882a593Smuzhiyun 				 XFS_PQUOTA_CHKD)
856*4882a593Smuzhiyun 
857*4882a593Smuzhiyun /*
858*4882a593Smuzhiyun  * Inode create log item structure
859*4882a593Smuzhiyun  *
860*4882a593Smuzhiyun  * Log recovery assumes the first two entries are the type and size and they fit
861*4882a593Smuzhiyun  * in 32 bits. Also in host order (ugh) so they have to be 32 bit aligned so
862*4882a593Smuzhiyun  * decoding can be done correctly.
863*4882a593Smuzhiyun  */
864*4882a593Smuzhiyun struct xfs_icreate_log {
865*4882a593Smuzhiyun 	uint16_t	icl_type;	/* type of log format structure */
866*4882a593Smuzhiyun 	uint16_t	icl_size;	/* size of log format structure */
867*4882a593Smuzhiyun 	__be32		icl_ag;		/* ag being allocated in */
868*4882a593Smuzhiyun 	__be32		icl_agbno;	/* start block of inode range */
869*4882a593Smuzhiyun 	__be32		icl_count;	/* number of inodes to initialise */
870*4882a593Smuzhiyun 	__be32		icl_isize;	/* size of inodes */
871*4882a593Smuzhiyun 	__be32		icl_length;	/* length of extent to initialise */
872*4882a593Smuzhiyun 	__be32		icl_gen;	/* inode generation number to use */
873*4882a593Smuzhiyun };
874*4882a593Smuzhiyun 
875*4882a593Smuzhiyun #endif /* __XFS_LOG_FORMAT_H__ */
876