]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/xfs_log_format.h
96c701070292335ff937a5d5ba3f6d6feaa54dfb
[thirdparty/xfsprogs-dev.git] / libxfs / 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
21 struct xfs_mount;
22 struct 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 */
34 typedef __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
72 static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
73 {
74 return ((xfs_lsn_t)cycle << 32) | block;
75 }
76
77 static 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_MAX 22
116
117 /*
118 * Flags to log operation header
119 *
120 * The first write of a new transaction will be preceded with a start
121 * record, XLOG_START_TRANS. Once a transaction is committed, a commit
122 * record is written, XLOG_COMMIT_TRANS. If a single region can not fit into
123 * the remainder of the current active in-core log, it is split up into
124 * multiple regions. Each partial region will be marked with a
125 * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
126 *
127 */
128 #define XLOG_START_TRANS 0x01 /* Start a new transaction */
129 #define XLOG_COMMIT_TRANS 0x02 /* Commit this transaction */
130 #define XLOG_CONTINUE_TRANS 0x04 /* Cont this trans into new region */
131 #define XLOG_WAS_CONT_TRANS 0x08 /* Cont this trans into new region */
132 #define XLOG_END_TRANS 0x10 /* End a continued transaction */
133 #define XLOG_UNMOUNT_TRANS 0x20 /* Unmount a filesystem transaction */
134
135
136 typedef struct xlog_op_header {
137 __be32 oh_tid; /* transaction id of operation : 4 b */
138 __be32 oh_len; /* bytes in data region : 4 b */
139 __u8 oh_clientid; /* who sent me this : 1 b */
140 __u8 oh_flags; /* : 1 b */
141 __u16 oh_res2; /* 32 bit align : 2 b */
142 } xlog_op_header_t;
143
144 /* valid values for h_fmt */
145 #define XLOG_FMT_UNKNOWN 0
146 #define XLOG_FMT_LINUX_LE 1
147 #define XLOG_FMT_LINUX_BE 2
148 #define XLOG_FMT_IRIX_BE 3
149
150 /* our fmt */
151 #ifdef XFS_NATIVE_HOST
152 #define XLOG_FMT XLOG_FMT_LINUX_BE
153 #else
154 #define XLOG_FMT XLOG_FMT_LINUX_LE
155 #endif
156
157 typedef struct xlog_rec_header {
158 __be32 h_magicno; /* log record (LR) identifier : 4 */
159 __be32 h_cycle; /* write cycle of log : 4 */
160 __be32 h_version; /* LR version : 4 */
161 __be32 h_len; /* len in bytes; should be 64-bit aligned: 4 */
162 __be64 h_lsn; /* lsn of this LR : 8 */
163 __be64 h_tail_lsn; /* lsn of 1st LR w/ buffers not committed: 8 */
164 __le32 h_crc; /* crc of log record : 4 */
165 __be32 h_prev_block; /* block number to previous LR : 4 */
166 __be32 h_num_logops; /* number of log operations in this LR : 4 */
167 __be32 h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
168 /* new fields */
169 __be32 h_fmt; /* format of log record : 4 */
170 uuid_t h_fs_uuid; /* uuid of FS : 16 */
171 __be32 h_size; /* iclog size : 4 */
172 } xlog_rec_header_t;
173
174 typedef struct xlog_rec_ext_header {
175 __be32 xh_cycle; /* write cycle of log : 4 */
176 __be32 xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /* : 256 */
177 } xlog_rec_ext_header_t;
178
179 /*
180 * Quite misnamed, because this union lays out the actual on-disk log buffer.
181 */
182 typedef union xlog_in_core2 {
183 xlog_rec_header_t hic_header;
184 xlog_rec_ext_header_t hic_xheader;
185 char hic_sector[XLOG_HEADER_SIZE];
186 } xlog_in_core_2_t;
187
188 /* not an on-disk structure, but needed by log recovery in userspace */
189 typedef struct xfs_log_iovec {
190 void *i_addr; /* beginning address of region */
191 int i_len; /* length in bytes of region */
192 uint i_type; /* type of region */
193 } xfs_log_iovec_t;
194
195
196 /*
197 * Transaction Header definitions.
198 *
199 * This is the structure written in the log at the head of every transaction. It
200 * identifies the type and id of the transaction, and contains the number of
201 * items logged by the transaction so we know how many to expect during
202 * recovery.
203 *
204 * Do not change the below structure without redoing the code in
205 * xlog_recover_add_to_trans() and xlog_recover_add_to_cont_trans().
206 */
207 typedef struct xfs_trans_header {
208 uint th_magic; /* magic number */
209 uint th_type; /* transaction type */
210 __int32_t th_tid; /* transaction id (unused) */
211 uint th_num_items; /* num items logged by trans */
212 } xfs_trans_header_t;
213
214 #define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */
215
216 /*
217 * The only type valid for th_type in CIL-enabled file system logs:
218 */
219 #define XFS_TRANS_CHECKPOINT 40
220
221 /*
222 * Log item types.
223 */
224 #define XFS_LI_EFI 0x1236
225 #define XFS_LI_EFD 0x1237
226 #define XFS_LI_IUNLINK 0x1238
227 #define XFS_LI_INODE 0x123b /* aligned ino chunks, var-size ibufs */
228 #define XFS_LI_BUF 0x123c /* v2 bufs, variable sized inode bufs */
229 #define XFS_LI_DQUOT 0x123d
230 #define XFS_LI_QUOTAOFF 0x123e
231 #define XFS_LI_ICREATE 0x123f
232 #define XFS_LI_RUI 0x1240 /* rmap update intent */
233 #define XFS_LI_RUD 0x1241
234
235 #define XFS_LI_TYPE_DESC \
236 { XFS_LI_EFI, "XFS_LI_EFI" }, \
237 { XFS_LI_EFD, "XFS_LI_EFD" }, \
238 { XFS_LI_IUNLINK, "XFS_LI_IUNLINK" }, \
239 { XFS_LI_INODE, "XFS_LI_INODE" }, \
240 { XFS_LI_BUF, "XFS_LI_BUF" }, \
241 { XFS_LI_DQUOT, "XFS_LI_DQUOT" }, \
242 { XFS_LI_QUOTAOFF, "XFS_LI_QUOTAOFF" }, \
243 { XFS_LI_ICREATE, "XFS_LI_ICREATE" }, \
244 { XFS_LI_RUI, "XFS_LI_RUI" }, \
245 { XFS_LI_RUD, "XFS_LI_RUD" }
246
247 /*
248 * Inode Log Item Format definitions.
249 *
250 * This is the structure used to lay out an inode log item in the
251 * log. The size of the inline data/extents/b-tree root to be logged
252 * (if any) is indicated in the ilf_dsize field. Changes to this structure
253 * must be added on to the end.
254 */
255 typedef struct xfs_inode_log_format {
256 __uint16_t ilf_type; /* inode log item type */
257 __uint16_t ilf_size; /* size of this item */
258 __uint32_t ilf_fields; /* flags for fields logged */
259 __uint16_t ilf_asize; /* size of attr d/ext/root */
260 __uint16_t ilf_dsize; /* size of data/ext/root */
261 __uint64_t ilf_ino; /* inode number */
262 union {
263 __uint32_t ilfu_rdev; /* rdev value for dev inode*/
264 uuid_t ilfu_uuid; /* mount point value */
265 } ilf_u;
266 __int64_t ilf_blkno; /* blkno of inode buffer */
267 __int32_t ilf_len; /* len of inode buffer */
268 __int32_t ilf_boffset; /* off of inode in buffer */
269 } xfs_inode_log_format_t;
270
271 typedef struct xfs_inode_log_format_32 {
272 __uint16_t ilf_type; /* inode log item type */
273 __uint16_t ilf_size; /* size of this item */
274 __uint32_t ilf_fields; /* flags for fields logged */
275 __uint16_t ilf_asize; /* size of attr d/ext/root */
276 __uint16_t ilf_dsize; /* size of data/ext/root */
277 __uint64_t ilf_ino; /* inode number */
278 union {
279 __uint32_t ilfu_rdev; /* rdev value for dev inode*/
280 uuid_t ilfu_uuid; /* mount point value */
281 } ilf_u;
282 __int64_t ilf_blkno; /* blkno of inode buffer */
283 __int32_t ilf_len; /* len of inode buffer */
284 __int32_t ilf_boffset; /* off of inode in buffer */
285 } __attribute__((packed)) xfs_inode_log_format_32_t;
286
287 typedef struct xfs_inode_log_format_64 {
288 __uint16_t ilf_type; /* inode log item type */
289 __uint16_t ilf_size; /* size of this item */
290 __uint32_t ilf_fields; /* flags for fields logged */
291 __uint16_t ilf_asize; /* size of attr d/ext/root */
292 __uint16_t ilf_dsize; /* size of data/ext/root */
293 __uint32_t ilf_pad; /* pad for 64 bit boundary */
294 __uint64_t ilf_ino; /* inode number */
295 union {
296 __uint32_t ilfu_rdev; /* rdev value for dev inode*/
297 uuid_t ilfu_uuid; /* mount point value */
298 } ilf_u;
299 __int64_t ilf_blkno; /* blkno of inode buffer */
300 __int32_t ilf_len; /* len of inode buffer */
301 __int32_t ilf_boffset; /* off of inode in buffer */
302 } xfs_inode_log_format_64_t;
303
304
305 /*
306 * Flags for xfs_trans_log_inode flags field.
307 */
308 #define XFS_ILOG_CORE 0x001 /* log standard inode fields */
309 #define XFS_ILOG_DDATA 0x002 /* log i_df.if_data */
310 #define XFS_ILOG_DEXT 0x004 /* log i_df.if_extents */
311 #define XFS_ILOG_DBROOT 0x008 /* log i_df.i_broot */
312 #define XFS_ILOG_DEV 0x010 /* log the dev field */
313 #define XFS_ILOG_UUID 0x020 /* log the uuid field */
314 #define XFS_ILOG_ADATA 0x040 /* log i_af.if_data */
315 #define XFS_ILOG_AEXT 0x080 /* log i_af.if_extents */
316 #define XFS_ILOG_ABROOT 0x100 /* log i_af.i_broot */
317 #define XFS_ILOG_DOWNER 0x200 /* change the data fork owner on replay */
318 #define XFS_ILOG_AOWNER 0x400 /* change the attr fork owner on replay */
319
320
321 /*
322 * The timestamps are dirty, but not necessarily anything else in the inode
323 * core. Unlike the other fields above this one must never make it to disk
324 * in the ilf_fields of the inode_log_format, but is purely store in-memory in
325 * ili_fields in the inode_log_item.
326 */
327 #define XFS_ILOG_TIMESTAMP 0x4000
328
329 #define XFS_ILOG_NONCORE (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
330 XFS_ILOG_DBROOT | XFS_ILOG_DEV | \
331 XFS_ILOG_UUID | XFS_ILOG_ADATA | \
332 XFS_ILOG_AEXT | XFS_ILOG_ABROOT | \
333 XFS_ILOG_DOWNER | XFS_ILOG_AOWNER)
334
335 #define XFS_ILOG_DFORK (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
336 XFS_ILOG_DBROOT)
337
338 #define XFS_ILOG_AFORK (XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
339 XFS_ILOG_ABROOT)
340
341 #define XFS_ILOG_ALL (XFS_ILOG_CORE | XFS_ILOG_DDATA | \
342 XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \
343 XFS_ILOG_DEV | XFS_ILOG_UUID | \
344 XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
345 XFS_ILOG_ABROOT | XFS_ILOG_TIMESTAMP | \
346 XFS_ILOG_DOWNER | XFS_ILOG_AOWNER)
347
348 static inline int xfs_ilog_fbroot(int w)
349 {
350 return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
351 }
352
353 static inline int xfs_ilog_fext(int w)
354 {
355 return (w == XFS_DATA_FORK ? XFS_ILOG_DEXT : XFS_ILOG_AEXT);
356 }
357
358 static inline int xfs_ilog_fdata(int w)
359 {
360 return (w == XFS_DATA_FORK ? XFS_ILOG_DDATA : XFS_ILOG_ADATA);
361 }
362
363 /*
364 * Incore version of the on-disk inode core structures. We log this directly
365 * into the journal in host CPU format (for better or worse) and as such
366 * directly mirrors the xfs_dinode structure as it must contain all the same
367 * information.
368 */
369 typedef struct xfs_ictimestamp {
370 __int32_t t_sec; /* timestamp seconds */
371 __int32_t t_nsec; /* timestamp nanoseconds */
372 } xfs_ictimestamp_t;
373
374 /*
375 * Define the format of the inode core that is logged. This structure must be
376 * kept identical to struct xfs_dinode except for the endianness annotations.
377 */
378 struct xfs_log_dinode {
379 __uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */
380 __uint16_t di_mode; /* mode and type of file */
381 __int8_t di_version; /* inode version */
382 __int8_t di_format; /* format of di_c data */
383 __uint8_t di_pad3[2]; /* unused in v2/3 inodes */
384 __uint32_t di_uid; /* owner's user id */
385 __uint32_t di_gid; /* owner's group id */
386 __uint32_t di_nlink; /* number of links to file */
387 __uint16_t di_projid_lo; /* lower part of owner's project id */
388 __uint16_t di_projid_hi; /* higher part of owner's project id */
389 __uint8_t di_pad[6]; /* unused, zeroed space */
390 __uint16_t di_flushiter; /* incremented on flush */
391 xfs_ictimestamp_t di_atime; /* time last accessed */
392 xfs_ictimestamp_t di_mtime; /* time last modified */
393 xfs_ictimestamp_t di_ctime; /* time created/inode modified */
394 xfs_fsize_t di_size; /* number of bytes in file */
395 xfs_rfsblock_t di_nblocks; /* # of direct & btree blocks used */
396 xfs_extlen_t di_extsize; /* basic/minimum extent size for file */
397 xfs_extnum_t di_nextents; /* number of extents in data fork */
398 xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/
399 __uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */
400 __int8_t di_aformat; /* format of attr fork's data */
401 __uint32_t di_dmevmask; /* DMIG event mask */
402 __uint16_t di_dmstate; /* DMIG state info */
403 __uint16_t di_flags; /* random flags, XFS_DIFLAG_... */
404 __uint32_t di_gen; /* generation number */
405
406 /* di_next_unlinked is the only non-core field in the old dinode */
407 xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */
408
409 /* start of the extended dinode, writable fields */
410 __uint32_t di_crc; /* CRC of the inode */
411 __uint64_t di_changecount; /* number of attribute changes */
412 xfs_lsn_t di_lsn; /* flush sequence */
413 __uint64_t di_flags2; /* more random flags */
414 __uint8_t di_pad2[16]; /* more padding for future expansion */
415
416 /* fields only written to during inode creation */
417 xfs_ictimestamp_t di_crtime; /* time created */
418 xfs_ino_t di_ino; /* inode number */
419 uuid_t di_uuid; /* UUID of the filesystem */
420
421 /* structure must be padded to 64 bit alignment */
422 };
423
424 static inline uint xfs_log_dinode_size(int version)
425 {
426 if (version == 3)
427 return sizeof(struct xfs_log_dinode);
428 return offsetof(struct xfs_log_dinode, di_next_unlinked);
429 }
430
431 /*
432 * Buffer Log Format defintions
433 *
434 * These are the physical dirty bitmap defintions for the log format structure.
435 */
436 #define XFS_BLF_CHUNK 128
437 #define XFS_BLF_SHIFT 7
438 #define BIT_TO_WORD_SHIFT 5
439 #define NBWORD (NBBY * sizeof(unsigned int))
440
441 /*
442 * This flag indicates that the buffer contains on disk inodes
443 * and requires special recovery handling.
444 */
445 #define XFS_BLF_INODE_BUF (1<<0)
446
447 /*
448 * This flag indicates that the buffer should not be replayed
449 * during recovery because its blocks are being freed.
450 */
451 #define XFS_BLF_CANCEL (1<<1)
452
453 /*
454 * This flag indicates that the buffer contains on disk
455 * user or group dquots and may require special recovery handling.
456 */
457 #define XFS_BLF_UDQUOT_BUF (1<<2)
458 #define XFS_BLF_PDQUOT_BUF (1<<3)
459 #define XFS_BLF_GDQUOT_BUF (1<<4)
460
461 /*
462 * This is the structure used to lay out a buf log item in the
463 * log. The data map describes which 128 byte chunks of the buffer
464 * have been logged.
465 */
466 #define XFS_BLF_DATAMAP_SIZE ((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
467
468 typedef struct xfs_buf_log_format {
469 unsigned short blf_type; /* buf log item type indicator */
470 unsigned short blf_size; /* size of this item */
471 unsigned short blf_flags; /* misc state */
472 unsigned short blf_len; /* number of blocks in this buf */
473 __int64_t blf_blkno; /* starting blkno of this buf */
474 unsigned int blf_map_size; /* used size of data bitmap in words */
475 unsigned int blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
476 } xfs_buf_log_format_t;
477
478 /*
479 * All buffers now need to tell recovery where the magic number
480 * is so that it can verify and calculate the CRCs on the buffer correctly
481 * once the changes have been replayed into the buffer.
482 *
483 * The type value is held in the upper 5 bits of the blf_flags field, which is
484 * an unsigned 16 bit field. Hence we need to shift it 11 bits up and down.
485 */
486 #define XFS_BLFT_BITS 5
487 #define XFS_BLFT_SHIFT 11
488 #define XFS_BLFT_MASK (((1 << XFS_BLFT_BITS) - 1) << XFS_BLFT_SHIFT)
489
490 enum xfs_blft {
491 XFS_BLFT_UNKNOWN_BUF = 0,
492 XFS_BLFT_UDQUOT_BUF,
493 XFS_BLFT_PDQUOT_BUF,
494 XFS_BLFT_GDQUOT_BUF,
495 XFS_BLFT_BTREE_BUF,
496 XFS_BLFT_AGF_BUF,
497 XFS_BLFT_AGFL_BUF,
498 XFS_BLFT_AGI_BUF,
499 XFS_BLFT_DINO_BUF,
500 XFS_BLFT_SYMLINK_BUF,
501 XFS_BLFT_DIR_BLOCK_BUF,
502 XFS_BLFT_DIR_DATA_BUF,
503 XFS_BLFT_DIR_FREE_BUF,
504 XFS_BLFT_DIR_LEAF1_BUF,
505 XFS_BLFT_DIR_LEAFN_BUF,
506 XFS_BLFT_DA_NODE_BUF,
507 XFS_BLFT_ATTR_LEAF_BUF,
508 XFS_BLFT_ATTR_RMT_BUF,
509 XFS_BLFT_SB_BUF,
510 XFS_BLFT_RTBITMAP_BUF,
511 XFS_BLFT_RTSUMMARY_BUF,
512 XFS_BLFT_MAX_BUF = (1 << XFS_BLFT_BITS),
513 };
514
515 static inline void
516 xfs_blft_to_flags(struct xfs_buf_log_format *blf, enum xfs_blft type)
517 {
518 ASSERT(type > XFS_BLFT_UNKNOWN_BUF && type < XFS_BLFT_MAX_BUF);
519 blf->blf_flags &= ~XFS_BLFT_MASK;
520 blf->blf_flags |= ((type << XFS_BLFT_SHIFT) & XFS_BLFT_MASK);
521 }
522
523 static inline __uint16_t
524 xfs_blft_from_flags(struct xfs_buf_log_format *blf)
525 {
526 return (blf->blf_flags & XFS_BLFT_MASK) >> XFS_BLFT_SHIFT;
527 }
528
529 /*
530 * EFI/EFD log format definitions
531 */
532 typedef struct xfs_extent {
533 xfs_fsblock_t ext_start;
534 xfs_extlen_t ext_len;
535 } xfs_extent_t;
536
537 /*
538 * Since an xfs_extent_t has types (start:64, len: 32)
539 * there are different alignments on 32 bit and 64 bit kernels.
540 * So we provide the different variants for use by a
541 * conversion routine.
542 */
543 typedef struct xfs_extent_32 {
544 __uint64_t ext_start;
545 __uint32_t ext_len;
546 } __attribute__((packed)) xfs_extent_32_t;
547
548 typedef struct xfs_extent_64 {
549 __uint64_t ext_start;
550 __uint32_t ext_len;
551 __uint32_t ext_pad;
552 } xfs_extent_64_t;
553
554 /*
555 * This is the structure used to lay out an efi log item in the
556 * log. The efi_extents field is a variable size array whose
557 * size is given by efi_nextents.
558 */
559 typedef struct xfs_efi_log_format {
560 __uint16_t efi_type; /* efi log item type */
561 __uint16_t efi_size; /* size of this item */
562 __uint32_t efi_nextents; /* # extents to free */
563 __uint64_t efi_id; /* efi identifier */
564 xfs_extent_t efi_extents[1]; /* array of extents to free */
565 } xfs_efi_log_format_t;
566
567 typedef struct xfs_efi_log_format_32 {
568 __uint16_t efi_type; /* efi log item type */
569 __uint16_t efi_size; /* size of this item */
570 __uint32_t efi_nextents; /* # extents to free */
571 __uint64_t efi_id; /* efi identifier */
572 xfs_extent_32_t efi_extents[1]; /* array of extents to free */
573 } __attribute__((packed)) xfs_efi_log_format_32_t;
574
575 typedef struct xfs_efi_log_format_64 {
576 __uint16_t efi_type; /* efi log item type */
577 __uint16_t efi_size; /* size of this item */
578 __uint32_t efi_nextents; /* # extents to free */
579 __uint64_t efi_id; /* efi identifier */
580 xfs_extent_64_t efi_extents[1]; /* array of extents to free */
581 } xfs_efi_log_format_64_t;
582
583 /*
584 * This is the structure used to lay out an efd log item in the
585 * log. The efd_extents array is a variable size array whose
586 * size is given by efd_nextents;
587 */
588 typedef struct xfs_efd_log_format {
589 __uint16_t efd_type; /* efd log item type */
590 __uint16_t efd_size; /* size of this item */
591 __uint32_t efd_nextents; /* # of extents freed */
592 __uint64_t efd_efi_id; /* id of corresponding efi */
593 xfs_extent_t efd_extents[1]; /* array of extents freed */
594 } xfs_efd_log_format_t;
595
596 typedef struct xfs_efd_log_format_32 {
597 __uint16_t efd_type; /* efd log item type */
598 __uint16_t efd_size; /* size of this item */
599 __uint32_t efd_nextents; /* # of extents freed */
600 __uint64_t efd_efi_id; /* id of corresponding efi */
601 xfs_extent_32_t efd_extents[1]; /* array of extents freed */
602 } __attribute__((packed)) xfs_efd_log_format_32_t;
603
604 typedef struct xfs_efd_log_format_64 {
605 __uint16_t efd_type; /* efd log item type */
606 __uint16_t efd_size; /* size of this item */
607 __uint32_t efd_nextents; /* # of extents freed */
608 __uint64_t efd_efi_id; /* id of corresponding efi */
609 xfs_extent_64_t efd_extents[1]; /* array of extents freed */
610 } xfs_efd_log_format_64_t;
611
612 /*
613 * RUI/RUD (reverse mapping) log format definitions
614 */
615 struct xfs_map_extent {
616 __uint64_t me_owner;
617 __uint64_t me_startblock;
618 __uint64_t me_startoff;
619 __uint32_t me_len;
620 __uint32_t me_flags;
621 };
622
623 /* rmap me_flags: upper bits are flags, lower byte is type code */
624 #define XFS_RMAP_EXTENT_MAP 1
625 #define XFS_RMAP_EXTENT_UNMAP 3
626 #define XFS_RMAP_EXTENT_CONVERT 5
627 #define XFS_RMAP_EXTENT_ALLOC 7
628 #define XFS_RMAP_EXTENT_FREE 8
629 #define XFS_RMAP_EXTENT_TYPE_MASK 0xFF
630
631 #define XFS_RMAP_EXTENT_ATTR_FORK (1U << 31)
632 #define XFS_RMAP_EXTENT_BMBT_BLOCK (1U << 30)
633 #define XFS_RMAP_EXTENT_UNWRITTEN (1U << 29)
634
635 #define XFS_RMAP_EXTENT_FLAGS (XFS_RMAP_EXTENT_TYPE_MASK | \
636 XFS_RMAP_EXTENT_ATTR_FORK | \
637 XFS_RMAP_EXTENT_BMBT_BLOCK | \
638 XFS_RMAP_EXTENT_UNWRITTEN)
639
640 /*
641 * This is the structure used to lay out an rui log item in the
642 * log. The rui_extents field is a variable size array whose
643 * size is given by rui_nextents.
644 */
645 struct xfs_rui_log_format {
646 __uint16_t rui_type; /* rui log item type */
647 __uint16_t rui_size; /* size of this item */
648 __uint32_t rui_nextents; /* # extents to free */
649 __uint64_t rui_id; /* rui identifier */
650 struct xfs_map_extent rui_extents[1]; /* array of extents to rmap */
651 };
652
653 /*
654 * This is the structure used to lay out an rud log item in the
655 * log. The rud_extents array is a variable size array whose
656 * size is given by rud_nextents;
657 */
658 struct xfs_rud_log_format {
659 __uint16_t rud_type; /* rud log item type */
660 __uint16_t rud_size; /* size of this item */
661 __uint32_t __pad;
662 __uint64_t rud_rui_id; /* id of corresponding rui */
663 };
664
665 /*
666 * Dquot Log format definitions.
667 *
668 * The first two fields must be the type and size fitting into
669 * 32 bits : log_recovery code assumes that.
670 */
671 typedef struct xfs_dq_logformat {
672 __uint16_t qlf_type; /* dquot log item type */
673 __uint16_t qlf_size; /* size of this item */
674 xfs_dqid_t qlf_id; /* usr/grp/proj id : 32 bits */
675 __int64_t qlf_blkno; /* blkno of dquot buffer */
676 __int32_t qlf_len; /* len of dquot buffer */
677 __uint32_t qlf_boffset; /* off of dquot in buffer */
678 } xfs_dq_logformat_t;
679
680 /*
681 * log format struct for QUOTAOFF records.
682 * The first two fields must be the type and size fitting into
683 * 32 bits : log_recovery code assumes that.
684 * We write two LI_QUOTAOFF logitems per quotaoff, the last one keeps a pointer
685 * to the first and ensures that the first logitem is taken out of the AIL
686 * only when the last one is securely committed.
687 */
688 typedef struct xfs_qoff_logformat {
689 unsigned short qf_type; /* quotaoff log item type */
690 unsigned short qf_size; /* size of this item */
691 unsigned int qf_flags; /* USR and/or GRP */
692 char qf_pad[12]; /* padding for future */
693 } xfs_qoff_logformat_t;
694
695 /*
696 * Disk quotas status in m_qflags, and also sb_qflags. 16 bits.
697 */
698 #define XFS_UQUOTA_ACCT 0x0001 /* user quota accounting ON */
699 #define XFS_UQUOTA_ENFD 0x0002 /* user quota limits enforced */
700 #define XFS_UQUOTA_CHKD 0x0004 /* quotacheck run on usr quotas */
701 #define XFS_PQUOTA_ACCT 0x0008 /* project quota accounting ON */
702 #define XFS_OQUOTA_ENFD 0x0010 /* other (grp/prj) quota limits enforced */
703 #define XFS_OQUOTA_CHKD 0x0020 /* quotacheck run on other (grp/prj) quotas */
704 #define XFS_GQUOTA_ACCT 0x0040 /* group quota accounting ON */
705
706 /*
707 * Conversion to and from the combined OQUOTA flag (if necessary)
708 * is done only in xfs_sb_qflags_to_disk() and xfs_sb_qflags_from_disk()
709 */
710 #define XFS_GQUOTA_ENFD 0x0080 /* group quota limits enforced */
711 #define XFS_GQUOTA_CHKD 0x0100 /* quotacheck run on group quotas */
712 #define XFS_PQUOTA_ENFD 0x0200 /* project quota limits enforced */
713 #define XFS_PQUOTA_CHKD 0x0400 /* quotacheck run on project quotas */
714
715 #define XFS_ALL_QUOTA_ACCT \
716 (XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
717 #define XFS_ALL_QUOTA_ENFD \
718 (XFS_UQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_ENFD)
719 #define XFS_ALL_QUOTA_CHKD \
720 (XFS_UQUOTA_CHKD | XFS_GQUOTA_CHKD | XFS_PQUOTA_CHKD)
721
722 #define XFS_MOUNT_QUOTA_ALL (XFS_UQUOTA_ACCT|XFS_UQUOTA_ENFD|\
723 XFS_UQUOTA_CHKD|XFS_GQUOTA_ACCT|\
724 XFS_GQUOTA_ENFD|XFS_GQUOTA_CHKD|\
725 XFS_PQUOTA_ACCT|XFS_PQUOTA_ENFD|\
726 XFS_PQUOTA_CHKD)
727
728 /*
729 * Inode create log item structure
730 *
731 * Log recovery assumes the first two entries are the type and size and they fit
732 * in 32 bits. Also in host order (ugh) so they have to be 32 bit aligned so
733 * decoding can be done correctly.
734 */
735 struct xfs_icreate_log {
736 __uint16_t icl_type; /* type of log format structure */
737 __uint16_t icl_size; /* size of log format structure */
738 __be32 icl_ag; /* ag being allocated in */
739 __be32 icl_agbno; /* start block of inode range */
740 __be32 icl_count; /* number of inodes to initialise */
741 __be32 icl_isize; /* size of inodes */
742 __be32 icl_length; /* length of extent to initialise */
743 __be32 icl_gen; /* inode generation number to use */
744 };
745
746 #endif /* __XFS_LOG_FORMAT_H__ */