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