2 * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
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.
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.
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
18 #ifndef __XFS_LOG_FORMAT_H__
19 #define __XFS_LOG_FORMAT_H__
24 * On-disk Log Format definitions.
26 * This file contains all the on-disk format definitions used within the log. It
27 * includes the physical log structure itself, as well as all the log item
28 * format structures that are written into the log and intepreted by log
29 * recovery. We start with the physical log format definitions, and then work
30 * through all the log items definitions and everything they encode into the
33 typedef __uint32_t xlog_tid_t;
35 #define XLOG_MIN_ICLOGS 2
36 #define XLOG_MAX_ICLOGS 8
37 #define XLOG_HEADER_MAGIC_NUM 0xFEEDbabe /* Invalid cycle number */
38 #define XLOG_VERSION_1 1
39 #define XLOG_VERSION_2 2 /* Large IClogs, Log sunit */
40 #define XLOG_VERSION_OKBITS (XLOG_VERSION_1 | XLOG_VERSION_2)
41 #define XLOG_MIN_RECORD_BSIZE (16*1024) /* eventually 32k */
42 #define XLOG_BIG_RECORD_BSIZE (32*1024) /* 32k buffers */
43 #define XLOG_MAX_RECORD_BSIZE (256*1024)
44 #define XLOG_HEADER_CYCLE_SIZE (32*1024) /* cycle data in header */
45 #define XLOG_MIN_RECORD_BSHIFT 14 /* 16384 == 1 << 14 */
46 #define XLOG_BIG_RECORD_BSHIFT 15 /* 32k == 1 << 15 */
47 #define XLOG_MAX_RECORD_BSHIFT 18 /* 256k == 1 << 18 */
48 #define XLOG_BTOLSUNIT(log, b) (((b)+(log)->l_mp->m_sb.sb_logsunit-1) / \
49 (log)->l_mp->m_sb.sb_logsunit)
50 #define XLOG_LSUNITTOB(log, su) ((su) * (log)->l_mp->m_sb.sb_logsunit)
52 #define XLOG_HEADER_SIZE 512
54 #define XLOG_REC_SHIFT(log) \
55 BTOBB(1 << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
56 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
57 #define XLOG_TOTAL_REC_SHIFT(log) \
58 BTOBB(XLOG_MAX_ICLOGS << (xfs_sb_version_haslogv2(&log->l_mp->m_sb) ? \
59 XLOG_MAX_RECORD_BSHIFT : XLOG_BIG_RECORD_BSHIFT))
62 #define CYCLE_LSN(lsn) ((uint)((lsn)>>32))
63 #define BLOCK_LSN(lsn) ((uint)(lsn))
65 /* this is used in a spot where we might otherwise double-endian-flip */
66 #define CYCLE_LSN_DISK(lsn) (((__be32 *)&(lsn))[0])
68 static inline xfs_lsn_t xlog_assign_lsn(uint cycle, uint block)
70 return ((xfs_lsn_t)cycle << 32) | block;
73 static inline uint xlog_get_cycle(char *ptr)
75 if (be32_to_cpu(*(__be32 *)ptr) == XLOG_HEADER_MAGIC_NUM)
76 return be32_to_cpu(*((__be32 *)ptr + 1));
78 return be32_to_cpu(*(__be32 *)ptr);
82 #define XFS_TRANSACTION 0x69
83 #define XFS_VOLUME 0x2
86 #define XLOG_UNMOUNT_TYPE 0x556e /* Un for Unmount */
88 /* Region types for iovec's i_type */
89 #define XLOG_REG_TYPE_BFORMAT 1
90 #define XLOG_REG_TYPE_BCHUNK 2
91 #define XLOG_REG_TYPE_EFI_FORMAT 3
92 #define XLOG_REG_TYPE_EFD_FORMAT 4
93 #define XLOG_REG_TYPE_IFORMAT 5
94 #define XLOG_REG_TYPE_ICORE 6
95 #define XLOG_REG_TYPE_IEXT 7
96 #define XLOG_REG_TYPE_IBROOT 8
97 #define XLOG_REG_TYPE_ILOCAL 9
98 #define XLOG_REG_TYPE_IATTR_EXT 10
99 #define XLOG_REG_TYPE_IATTR_BROOT 11
100 #define XLOG_REG_TYPE_IATTR_LOCAL 12
101 #define XLOG_REG_TYPE_QFORMAT 13
102 #define XLOG_REG_TYPE_DQUOT 14
103 #define XLOG_REG_TYPE_QUOTAOFF 15
104 #define XLOG_REG_TYPE_LRHEADER 16
105 #define XLOG_REG_TYPE_UNMOUNT 17
106 #define XLOG_REG_TYPE_COMMIT 18
107 #define XLOG_REG_TYPE_TRANSHDR 19
108 #define XLOG_REG_TYPE_ICREATE 20
109 #define XLOG_REG_TYPE_MAX 20
112 * Flags to log operation header
114 * The first write of a new transaction will be preceded with a start
115 * record, XLOG_START_TRANS. Once a transaction is committed, a commit
116 * record is written, XLOG_COMMIT_TRANS. If a single region can not fit into
117 * the remainder of the current active in-core log, it is split up into
118 * multiple regions. Each partial region will be marked with a
119 * XLOG_CONTINUE_TRANS until the last one, which gets marked with XLOG_END_TRANS.
122 #define XLOG_START_TRANS 0x01 /* Start a new transaction */
123 #define XLOG_COMMIT_TRANS 0x02 /* Commit this transaction */
124 #define XLOG_CONTINUE_TRANS 0x04 /* Cont this trans into new region */
125 #define XLOG_WAS_CONT_TRANS 0x08 /* Cont this trans into new region */
126 #define XLOG_END_TRANS 0x10 /* End a continued transaction */
127 #define XLOG_UNMOUNT_TRANS 0x20 /* Unmount a filesystem transaction */
130 typedef struct xlog_op_header {
131 __be32 oh_tid; /* transaction id of operation : 4 b */
132 __be32 oh_len; /* bytes in data region : 4 b */
133 __u8 oh_clientid; /* who sent me this : 1 b */
134 __u8 oh_flags; /* : 1 b */
135 __u16 oh_res2; /* 32 bit align : 2 b */
139 /* valid values for h_fmt */
140 #define XLOG_FMT_UNKNOWN 0
141 #define XLOG_FMT_LINUX_LE 1
142 #define XLOG_FMT_LINUX_BE 2
143 #define XLOG_FMT_IRIX_BE 3
146 #ifdef XFS_NATIVE_HOST
147 #define XLOG_FMT XLOG_FMT_LINUX_BE
149 #define XLOG_FMT XLOG_FMT_LINUX_LE
152 typedef struct xlog_rec_header {
153 __be32 h_magicno; /* log record (LR) identifier : 4 */
154 __be32 h_cycle; /* write cycle of log : 4 */
155 __be32 h_version; /* LR version : 4 */
156 __be32 h_len; /* len in bytes; should be 64-bit aligned: 4 */
157 __be64 h_lsn; /* lsn of this LR : 8 */
158 __be64 h_tail_lsn; /* lsn of 1st LR w/ buffers not committed: 8 */
159 __le32 h_crc; /* crc of log record : 4 */
160 __be32 h_prev_block; /* block number to previous LR : 4 */
161 __be32 h_num_logops; /* number of log operations in this LR : 4 */
162 __be32 h_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE];
164 __be32 h_fmt; /* format of log record : 4 */
165 uuid_t h_fs_uuid; /* uuid of FS : 16 */
166 __be32 h_size; /* iclog size : 4 */
169 typedef struct xlog_rec_ext_header {
170 __be32 xh_cycle; /* write cycle of log : 4 */
171 __be32 xh_cycle_data[XLOG_HEADER_CYCLE_SIZE / BBSIZE]; /* : 256 */
172 } xlog_rec_ext_header_t;
175 * Quite misnamed, because this union lays out the actual on-disk log buffer.
177 typedef union xlog_in_core2 {
178 xlog_rec_header_t hic_header;
179 xlog_rec_ext_header_t hic_xheader;
180 char hic_sector[XLOG_HEADER_SIZE];
183 /* not an on-disk structure, but needed by log recovery in userspace */
184 typedef struct xfs_log_iovec {
185 void *i_addr; /* beginning address of region */
186 int i_len; /* length in bytes of region */
187 uint i_type; /* type of region */
192 * Transaction Header definitions.
194 * This is the structure written in the log at the head of every transaction. It
195 * identifies the type and id of the transaction, and contains the number of
196 * items logged by the transaction so we know how many to expect during
199 * Do not change the below structure without redoing the code in
200 * xlog_recover_add_to_trans() and xlog_recover_add_to_cont_trans().
202 typedef struct xfs_trans_header {
203 uint th_magic; /* magic number */
204 uint th_type; /* transaction type */
205 __int32_t th_tid; /* transaction id (unused) */
206 uint th_num_items; /* num items logged by trans */
207 } xfs_trans_header_t;
209 #define XFS_TRANS_HEADER_MAGIC 0x5452414e /* TRAN */
214 #define XFS_LI_EFI 0x1236
215 #define XFS_LI_EFD 0x1237
216 #define XFS_LI_IUNLINK 0x1238
217 #define XFS_LI_INODE 0x123b /* aligned ino chunks, var-size ibufs */
218 #define XFS_LI_BUF 0x123c /* v2 bufs, variable sized inode bufs */
219 #define XFS_LI_DQUOT 0x123d
220 #define XFS_LI_QUOTAOFF 0x123e
221 #define XFS_LI_ICREATE 0x123f
223 #define XFS_LI_TYPE_DESC \
224 { XFS_LI_EFI, "XFS_LI_EFI" }, \
225 { XFS_LI_EFD, "XFS_LI_EFD" }, \
226 { XFS_LI_IUNLINK, "XFS_LI_IUNLINK" }, \
227 { XFS_LI_INODE, "XFS_LI_INODE" }, \
228 { XFS_LI_BUF, "XFS_LI_BUF" }, \
229 { XFS_LI_DQUOT, "XFS_LI_DQUOT" }, \
230 { XFS_LI_QUOTAOFF, "XFS_LI_QUOTAOFF" }, \
231 { XFS_LI_ICREATE, "XFS_LI_ICREATE" }
234 * Transaction types. Used to distinguish types of buffers.
236 #define XFS_TRANS_SETATTR_NOT_SIZE 1
237 #define XFS_TRANS_SETATTR_SIZE 2
238 #define XFS_TRANS_INACTIVE 3
239 #define XFS_TRANS_CREATE 4
240 #define XFS_TRANS_CREATE_TRUNC 5
241 #define XFS_TRANS_TRUNCATE_FILE 6
242 #define XFS_TRANS_REMOVE 7
243 #define XFS_TRANS_LINK 8
244 #define XFS_TRANS_RENAME 9
245 #define XFS_TRANS_MKDIR 10
246 #define XFS_TRANS_RMDIR 11
247 #define XFS_TRANS_SYMLINK 12
248 #define XFS_TRANS_SET_DMATTRS 13
249 #define XFS_TRANS_GROWFS 14
250 #define XFS_TRANS_STRAT_WRITE 15
251 #define XFS_TRANS_DIOSTRAT 16
252 /* 17 was XFS_TRANS_WRITE_SYNC */
253 #define XFS_TRANS_WRITEID 18
254 #define XFS_TRANS_ADDAFORK 19
255 #define XFS_TRANS_ATTRINVAL 20
256 #define XFS_TRANS_ATRUNCATE 21
257 #define XFS_TRANS_ATTR_SET 22
258 #define XFS_TRANS_ATTR_RM 23
259 #define XFS_TRANS_ATTR_FLAG 24
260 #define XFS_TRANS_CLEAR_AGI_BUCKET 25
261 #define XFS_TRANS_QM_SBCHANGE 26
263 * Dummy entries since we use the transaction type to index into the
264 * trans_type[] in xlog_recover_print_trans_head()
266 #define XFS_TRANS_DUMMY1 27
267 #define XFS_TRANS_DUMMY2 28
268 #define XFS_TRANS_QM_QUOTAOFF 29
269 #define XFS_TRANS_QM_DQALLOC 30
270 #define XFS_TRANS_QM_SETQLIM 31
271 #define XFS_TRANS_QM_DQCLUSTER 32
272 #define XFS_TRANS_QM_QINOCREATE 33
273 #define XFS_TRANS_QM_QUOTAOFF_END 34
274 #define XFS_TRANS_SB_UNIT 35
275 #define XFS_TRANS_FSYNC_TS 36
276 #define XFS_TRANS_GROWFSRT_ALLOC 37
277 #define XFS_TRANS_GROWFSRT_ZERO 38
278 #define XFS_TRANS_GROWFSRT_FREE 39
279 #define XFS_TRANS_SWAPEXT 40
280 #define XFS_TRANS_SB_COUNT 41
281 #define XFS_TRANS_CHECKPOINT 42
282 #define XFS_TRANS_ICREATE 43
283 #define XFS_TRANS_TYPE_MAX 43
284 /* new transaction types need to be reflected in xfs_logprint(8) */
286 #define XFS_TRANS_TYPES \
287 { XFS_TRANS_SETATTR_NOT_SIZE, "SETATTR_NOT_SIZE" }, \
288 { XFS_TRANS_SETATTR_SIZE, "SETATTR_SIZE" }, \
289 { XFS_TRANS_INACTIVE, "INACTIVE" }, \
290 { XFS_TRANS_CREATE, "CREATE" }, \
291 { XFS_TRANS_CREATE_TRUNC, "CREATE_TRUNC" }, \
292 { XFS_TRANS_TRUNCATE_FILE, "TRUNCATE_FILE" }, \
293 { XFS_TRANS_REMOVE, "REMOVE" }, \
294 { XFS_TRANS_LINK, "LINK" }, \
295 { XFS_TRANS_RENAME, "RENAME" }, \
296 { XFS_TRANS_MKDIR, "MKDIR" }, \
297 { XFS_TRANS_RMDIR, "RMDIR" }, \
298 { XFS_TRANS_SYMLINK, "SYMLINK" }, \
299 { XFS_TRANS_SET_DMATTRS, "SET_DMATTRS" }, \
300 { XFS_TRANS_GROWFS, "GROWFS" }, \
301 { XFS_TRANS_STRAT_WRITE, "STRAT_WRITE" }, \
302 { XFS_TRANS_DIOSTRAT, "DIOSTRAT" }, \
303 { XFS_TRANS_WRITEID, "WRITEID" }, \
304 { XFS_TRANS_ADDAFORK, "ADDAFORK" }, \
305 { XFS_TRANS_ATTRINVAL, "ATTRINVAL" }, \
306 { XFS_TRANS_ATRUNCATE, "ATRUNCATE" }, \
307 { XFS_TRANS_ATTR_SET, "ATTR_SET" }, \
308 { XFS_TRANS_ATTR_RM, "ATTR_RM" }, \
309 { XFS_TRANS_ATTR_FLAG, "ATTR_FLAG" }, \
310 { XFS_TRANS_CLEAR_AGI_BUCKET, "CLEAR_AGI_BUCKET" }, \
311 { XFS_TRANS_QM_SBCHANGE, "QM_SBCHANGE" }, \
312 { XFS_TRANS_QM_QUOTAOFF, "QM_QUOTAOFF" }, \
313 { XFS_TRANS_QM_DQALLOC, "QM_DQALLOC" }, \
314 { XFS_TRANS_QM_SETQLIM, "QM_SETQLIM" }, \
315 { XFS_TRANS_QM_DQCLUSTER, "QM_DQCLUSTER" }, \
316 { XFS_TRANS_QM_QINOCREATE, "QM_QINOCREATE" }, \
317 { XFS_TRANS_QM_QUOTAOFF_END, "QM_QOFF_END" }, \
318 { XFS_TRANS_SB_UNIT, "SB_UNIT" }, \
319 { XFS_TRANS_FSYNC_TS, "FSYNC_TS" }, \
320 { XFS_TRANS_GROWFSRT_ALLOC, "GROWFSRT_ALLOC" }, \
321 { XFS_TRANS_GROWFSRT_ZERO, "GROWFSRT_ZERO" }, \
322 { XFS_TRANS_GROWFSRT_FREE, "GROWFSRT_FREE" }, \
323 { XFS_TRANS_SWAPEXT, "SWAPEXT" }, \
324 { XFS_TRANS_SB_COUNT, "SB_COUNT" }, \
325 { XFS_TRANS_CHECKPOINT, "CHECKPOINT" }, \
326 { XFS_TRANS_DUMMY1, "DUMMY1" }, \
327 { XFS_TRANS_DUMMY2, "DUMMY2" }, \
328 { XLOG_UNMOUNT_REC_TYPE, "UNMOUNT" }
331 * This structure is used to track log items associated with
332 * a transaction. It points to the log item and keeps some
333 * flags to track the state of the log item. It also tracks
334 * the amount of space needed to log the item it describes
335 * once we get to commit processing (see xfs_trans_commit()).
337 struct xfs_log_item_desc {
338 struct xfs_log_item *lid_item;
339 struct list_head lid_trans;
340 unsigned char lid_flags;
343 #define XFS_LID_DIRTY 0x1
346 * Values for t_flags.
348 #define XFS_TRANS_DIRTY 0x01 /* something needs to be logged */
349 #define XFS_TRANS_SB_DIRTY 0x02 /* superblock is modified */
350 #define XFS_TRANS_PERM_LOG_RES 0x04 /* xact took a permanent log res */
351 #define XFS_TRANS_SYNC 0x08 /* make commit synchronous */
352 #define XFS_TRANS_DQ_DIRTY 0x10 /* at least one dquot in trx dirty */
353 #define XFS_TRANS_RESERVE 0x20 /* OK to use reserved data blocks */
354 #define XFS_TRANS_FREEZE_PROT 0x40 /* Transaction has elevated writer
355 count in superblock */
358 * Values for call flags parameter.
360 #define XFS_TRANS_RELEASE_LOG_RES 0x4
361 #define XFS_TRANS_ABORT 0x8
364 * Field values for xfs_trans_mod_sb.
366 #define XFS_TRANS_SB_ICOUNT 0x00000001
367 #define XFS_TRANS_SB_IFREE 0x00000002
368 #define XFS_TRANS_SB_FDBLOCKS 0x00000004
369 #define XFS_TRANS_SB_RES_FDBLOCKS 0x00000008
370 #define XFS_TRANS_SB_FREXTENTS 0x00000010
371 #define XFS_TRANS_SB_RES_FREXTENTS 0x00000020
372 #define XFS_TRANS_SB_DBLOCKS 0x00000040
373 #define XFS_TRANS_SB_AGCOUNT 0x00000080
374 #define XFS_TRANS_SB_IMAXPCT 0x00000100
375 #define XFS_TRANS_SB_REXTSIZE 0x00000200
376 #define XFS_TRANS_SB_RBMBLOCKS 0x00000400
377 #define XFS_TRANS_SB_RBLOCKS 0x00000800
378 #define XFS_TRANS_SB_REXTENTS 0x00001000
379 #define XFS_TRANS_SB_REXTSLOG 0x00002000
382 * Here we centralize the specification of XFS meta-data buffer
383 * reference count values. This determine how hard the buffer
384 * cache tries to hold onto the buffer.
386 #define XFS_AGF_REF 4
387 #define XFS_AGI_REF 4
388 #define XFS_AGFL_REF 3
389 #define XFS_INO_BTREE_REF 3
390 #define XFS_ALLOC_BTREE_REF 2
391 #define XFS_BMAP_BTREE_REF 2
392 #define XFS_DIR_BTREE_REF 2
393 #define XFS_INO_REF 2
394 #define XFS_ATTR_BTREE_REF 1
395 #define XFS_DQUOT_REF 1
398 * Flags for xfs_trans_ichgtime().
400 #define XFS_ICHGTIME_MOD 0x1 /* data fork modification timestamp */
401 #define XFS_ICHGTIME_CHG 0x2 /* inode field change timestamp */
402 #define XFS_ICHGTIME_CREATE 0x4 /* inode create timestamp */
406 * Inode Log Item Format definitions.
408 * This is the structure used to lay out an inode log item in the
409 * log. The size of the inline data/extents/b-tree root to be logged
410 * (if any) is indicated in the ilf_dsize field. Changes to this structure
411 * must be added on to the end.
413 typedef struct xfs_inode_log_format {
414 __uint16_t ilf_type; /* inode log item type */
415 __uint16_t ilf_size; /* size of this item */
416 __uint32_t ilf_fields; /* flags for fields logged */
417 __uint16_t ilf_asize; /* size of attr d/ext/root */
418 __uint16_t ilf_dsize; /* size of data/ext/root */
419 __uint64_t ilf_ino; /* inode number */
421 __uint32_t ilfu_rdev; /* rdev value for dev inode*/
422 uuid_t ilfu_uuid; /* mount point value */
424 __int64_t ilf_blkno; /* blkno of inode buffer */
425 __int32_t ilf_len; /* len of inode buffer */
426 __int32_t ilf_boffset; /* off of inode in buffer */
427 } xfs_inode_log_format_t;
429 typedef struct xfs_inode_log_format_32 {
430 __uint16_t ilf_type; /* inode log item type */
431 __uint16_t ilf_size; /* size of this item */
432 __uint32_t ilf_fields; /* flags for fields logged */
433 __uint16_t ilf_asize; /* size of attr d/ext/root */
434 __uint16_t ilf_dsize; /* size of data/ext/root */
435 __uint64_t ilf_ino; /* inode number */
437 __uint32_t ilfu_rdev; /* rdev value for dev inode*/
438 uuid_t ilfu_uuid; /* mount point value */
440 __int64_t ilf_blkno; /* blkno of inode buffer */
441 __int32_t ilf_len; /* len of inode buffer */
442 __int32_t ilf_boffset; /* off of inode in buffer */
443 } __attribute__((packed)) xfs_inode_log_format_32_t;
445 typedef struct xfs_inode_log_format_64 {
446 __uint16_t ilf_type; /* inode log item type */
447 __uint16_t ilf_size; /* size of this item */
448 __uint32_t ilf_fields; /* flags for fields logged */
449 __uint16_t ilf_asize; /* size of attr d/ext/root */
450 __uint16_t ilf_dsize; /* size of data/ext/root */
451 __uint32_t ilf_pad; /* pad for 64 bit boundary */
452 __uint64_t ilf_ino; /* inode number */
454 __uint32_t ilfu_rdev; /* rdev value for dev inode*/
455 uuid_t ilfu_uuid; /* mount point value */
457 __int64_t ilf_blkno; /* blkno of inode buffer */
458 __int32_t ilf_len; /* len of inode buffer */
459 __int32_t ilf_boffset; /* off of inode in buffer */
460 } xfs_inode_log_format_64_t;
463 * Flags for xfs_trans_log_inode flags field.
465 #define XFS_ILOG_CORE 0x001 /* log standard inode fields */
466 #define XFS_ILOG_DDATA 0x002 /* log i_df.if_data */
467 #define XFS_ILOG_DEXT 0x004 /* log i_df.if_extents */
468 #define XFS_ILOG_DBROOT 0x008 /* log i_df.i_broot */
469 #define XFS_ILOG_DEV 0x010 /* log the dev field */
470 #define XFS_ILOG_UUID 0x020 /* log the uuid field */
471 #define XFS_ILOG_ADATA 0x040 /* log i_af.if_data */
472 #define XFS_ILOG_AEXT 0x080 /* log i_af.if_extents */
473 #define XFS_ILOG_ABROOT 0x100 /* log i_af.i_broot */
477 * The timestamps are dirty, but not necessarily anything else in the inode
478 * core. Unlike the other fields above this one must never make it to disk
479 * in the ilf_fields of the inode_log_format, but is purely store in-memory in
480 * ili_fields in the inode_log_item.
482 #define XFS_ILOG_TIMESTAMP 0x4000
484 #define XFS_ILOG_NONCORE (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
485 XFS_ILOG_DBROOT | XFS_ILOG_DEV | \
486 XFS_ILOG_UUID | XFS_ILOG_ADATA | \
487 XFS_ILOG_AEXT | XFS_ILOG_ABROOT)
489 #define XFS_ILOG_DFORK (XFS_ILOG_DDATA | XFS_ILOG_DEXT | \
492 #define XFS_ILOG_AFORK (XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
495 #define XFS_ILOG_ALL (XFS_ILOG_CORE | XFS_ILOG_DDATA | \
496 XFS_ILOG_DEXT | XFS_ILOG_DBROOT | \
497 XFS_ILOG_DEV | XFS_ILOG_UUID | \
498 XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
499 XFS_ILOG_ABROOT | XFS_ILOG_TIMESTAMP)
501 static inline int xfs_ilog_fbroot(int w)
503 return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
506 static inline int xfs_ilog_fext(int w)
508 return (w == XFS_DATA_FORK ? XFS_ILOG_DEXT : XFS_ILOG_AEXT);
511 static inline int xfs_ilog_fdata(int w)
513 return (w == XFS_DATA_FORK ? XFS_ILOG_DDATA : XFS_ILOG_ADATA);
517 * Incore version of the on-disk inode core structures. We log this directly
518 * into the journal in host CPU format (for better or worse) and as such
519 * directly mirrors the xfs_dinode structure as it must contain all the same
522 typedef struct xfs_ictimestamp {
523 __int32_t t_sec; /* timestamp seconds */
524 __int32_t t_nsec; /* timestamp nanoseconds */
528 * NOTE: This structure must be kept identical to struct xfs_dinode
529 * in xfs_dinode.h except for the endianness annotations.
531 typedef struct xfs_icdinode {
532 __uint16_t di_magic; /* inode magic # = XFS_DINODE_MAGIC */
533 __uint16_t di_mode; /* mode and type of file */
534 __int8_t di_version; /* inode version */
535 __int8_t di_format; /* format of di_c data */
536 __uint16_t di_onlink; /* old number of links to file */
537 __uint32_t di_uid; /* owner's user id */
538 __uint32_t di_gid; /* owner's group id */
539 __uint32_t di_nlink; /* number of links to file */
540 __uint16_t di_projid_lo; /* lower part of owner's project id */
541 __uint16_t di_projid_hi; /* higher part of owner's project id */
542 __uint8_t di_pad[6]; /* unused, zeroed space */
543 __uint16_t di_flushiter; /* incremented on flush */
544 xfs_ictimestamp_t di_atime; /* time last accessed */
545 xfs_ictimestamp_t di_mtime; /* time last modified */
546 xfs_ictimestamp_t di_ctime; /* time created/inode modified */
547 xfs_fsize_t di_size; /* number of bytes in file */
548 xfs_drfsbno_t di_nblocks; /* # of direct & btree blocks used */
549 xfs_extlen_t di_extsize; /* basic/minimum extent size for file */
550 xfs_extnum_t di_nextents; /* number of extents in data fork */
551 xfs_aextnum_t di_anextents; /* number of extents in attribute fork*/
552 __uint8_t di_forkoff; /* attr fork offs, <<3 for 64b align */
553 __int8_t di_aformat; /* format of attr fork's data */
554 __uint32_t di_dmevmask; /* DMIG event mask */
555 __uint16_t di_dmstate; /* DMIG state info */
556 __uint16_t di_flags; /* random flags, XFS_DIFLAG_... */
557 __uint32_t di_gen; /* generation number */
559 /* di_next_unlinked is the only non-core field in the old dinode */
560 xfs_agino_t di_next_unlinked;/* agi unlinked list ptr */
562 /* start of the extended dinode, writable fields */
563 __uint32_t di_crc; /* CRC of the inode */
564 __uint64_t di_changecount; /* number of attribute changes */
565 xfs_lsn_t di_lsn; /* flush sequence */
566 __uint64_t di_flags2; /* more random flags */
567 __uint8_t di_pad2[16]; /* more padding for future expansion */
569 /* fields only written to during inode creation */
570 xfs_ictimestamp_t di_crtime; /* time created */
571 xfs_ino_t di_ino; /* inode number */
572 uuid_t di_uuid; /* UUID of the filesystem */
574 /* structure must be padded to 64 bit alignment */
577 static inline uint xfs_icdinode_size(int version)
580 return sizeof(struct xfs_icdinode);
581 return offsetof(struct xfs_icdinode, di_next_unlinked);
585 * Buffer Log Format defintions
587 * These are the physical dirty bitmap defintions for the log format structure.
589 #define XFS_BLF_CHUNK 128
590 #define XFS_BLF_SHIFT 7
591 #define BIT_TO_WORD_SHIFT 5
592 #define NBWORD (NBBY * sizeof(unsigned int))
595 * This flag indicates that the buffer contains on disk inodes
596 * and requires special recovery handling.
598 #define XFS_BLF_INODE_BUF (1<<0)
601 * This flag indicates that the buffer should not be replayed
602 * during recovery because its blocks are being freed.
604 #define XFS_BLF_CANCEL (1<<1)
607 * This flag indicates that the buffer contains on disk
608 * user or group dquots and may require special recovery handling.
610 #define XFS_BLF_UDQUOT_BUF (1<<2)
611 #define XFS_BLF_PDQUOT_BUF (1<<3)
612 #define XFS_BLF_GDQUOT_BUF (1<<4)
615 * This is the structure used to lay out a buf log item in the
616 * log. The data map describes which 128 byte chunks of the buffer
619 #define XFS_BLF_DATAMAP_SIZE ((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) / NBWORD)
621 typedef struct xfs_buf_log_format {
622 unsigned short blf_type; /* buf log item type indicator */
623 unsigned short blf_size; /* size of this item */
624 ushort blf_flags; /* misc state */
625 ushort blf_len; /* number of blocks in this buf */
626 __int64_t blf_blkno; /* starting blkno of this buf */
627 unsigned int blf_map_size; /* used size of data bitmap in words */
628 unsigned int blf_data_map[XFS_BLF_DATAMAP_SIZE]; /* dirty bitmap */
629 } xfs_buf_log_format_t;
632 * All buffers now need to tell recovery where the magic number
633 * is so that it can verify and calculate the CRCs on the buffer correctly
634 * once the changes have been replayed into the buffer.
636 * The type value is held in the upper 5 bits of the blf_flags field, which is
637 * an unsigned 16 bit field. Hence we need to shift it 11 bits up and down.
639 #define XFS_BLFT_BITS 5
640 #define XFS_BLFT_SHIFT 11
641 #define XFS_BLFT_MASK (((1 << XFS_BLFT_BITS) - 1) << XFS_BLFT_SHIFT)
644 XFS_BLFT_UNKNOWN_BUF = 0,
653 XFS_BLFT_SYMLINK_BUF,
654 XFS_BLFT_DIR_BLOCK_BUF,
655 XFS_BLFT_DIR_DATA_BUF,
656 XFS_BLFT_DIR_FREE_BUF,
657 XFS_BLFT_DIR_LEAF1_BUF,
658 XFS_BLFT_DIR_LEAFN_BUF,
659 XFS_BLFT_DA_NODE_BUF,
660 XFS_BLFT_ATTR_LEAF_BUF,
661 XFS_BLFT_ATTR_RMT_BUF,
663 XFS_BLFT_MAX_BUF = (1 << XFS_BLFT_BITS),
667 xfs_blft_to_flags(struct xfs_buf_log_format *blf, enum xfs_blft type)
669 ASSERT(type > XFS_BLFT_UNKNOWN_BUF && type < XFS_BLFT_MAX_BUF);
670 blf->blf_flags &= ~XFS_BLFT_MASK;
671 blf->blf_flags |= ((type << XFS_BLFT_SHIFT) & XFS_BLFT_MASK);
674 static inline __uint16_t
675 xfs_blft_from_flags(struct xfs_buf_log_format *blf)
677 return (blf->blf_flags & XFS_BLFT_MASK) >> XFS_BLFT_SHIFT;
681 * EFI/EFD log format definitions
683 typedef struct xfs_extent {
684 xfs_dfsbno_t ext_start;
685 xfs_extlen_t ext_len;
689 * Since an xfs_extent_t has types (start:64, len: 32)
690 * there are different alignments on 32 bit and 64 bit kernels.
691 * So we provide the different variants for use by a
692 * conversion routine.
694 typedef struct xfs_extent_32 {
695 __uint64_t ext_start;
697 } __attribute__((packed)) xfs_extent_32_t;
699 typedef struct xfs_extent_64 {
700 __uint64_t ext_start;
706 * This is the structure used to lay out an efi log item in the
707 * log. The efi_extents field is a variable size array whose
708 * size is given by efi_nextents.
710 typedef struct xfs_efi_log_format {
711 __uint16_t efi_type; /* efi log item type */
712 __uint16_t efi_size; /* size of this item */
713 __uint32_t efi_nextents; /* # extents to free */
714 __uint64_t efi_id; /* efi identifier */
715 xfs_extent_t efi_extents[1]; /* array of extents to free */
716 } xfs_efi_log_format_t;
718 typedef struct xfs_efi_log_format_32 {
719 __uint16_t efi_type; /* efi log item type */
720 __uint16_t efi_size; /* size of this item */
721 __uint32_t efi_nextents; /* # extents to free */
722 __uint64_t efi_id; /* efi identifier */
723 xfs_extent_32_t efi_extents[1]; /* array of extents to free */
724 } __attribute__((packed)) xfs_efi_log_format_32_t;
726 typedef struct xfs_efi_log_format_64 {
727 __uint16_t efi_type; /* efi log item type */
728 __uint16_t efi_size; /* size of this item */
729 __uint32_t efi_nextents; /* # extents to free */
730 __uint64_t efi_id; /* efi identifier */
731 xfs_extent_64_t efi_extents[1]; /* array of extents to free */
732 } xfs_efi_log_format_64_t;
735 * This is the structure used to lay out an efd log item in the
736 * log. The efd_extents array is a variable size array whose
737 * size is given by efd_nextents;
739 typedef struct xfs_efd_log_format {
740 __uint16_t efd_type; /* efd log item type */
741 __uint16_t efd_size; /* size of this item */
742 __uint32_t efd_nextents; /* # of extents freed */
743 __uint64_t efd_efi_id; /* id of corresponding efi */
744 xfs_extent_t efd_extents[1]; /* array of extents freed */
745 } xfs_efd_log_format_t;
747 typedef struct xfs_efd_log_format_32 {
748 __uint16_t efd_type; /* efd log item type */
749 __uint16_t efd_size; /* size of this item */
750 __uint32_t efd_nextents; /* # of extents freed */
751 __uint64_t efd_efi_id; /* id of corresponding efi */
752 xfs_extent_32_t efd_extents[1]; /* array of extents freed */
753 } __attribute__((packed)) xfs_efd_log_format_32_t;
755 typedef struct xfs_efd_log_format_64 {
756 __uint16_t efd_type; /* efd log item type */
757 __uint16_t efd_size; /* size of this item */
758 __uint32_t efd_nextents; /* # of extents freed */
759 __uint64_t efd_efi_id; /* id of corresponding efi */
760 xfs_extent_64_t efd_extents[1]; /* array of extents freed */
761 } xfs_efd_log_format_64_t;
764 * Dquot Log format definitions.
766 * The first two fields must be the type and size fitting into
767 * 32 bits : log_recovery code assumes that.
769 typedef struct xfs_dq_logformat {
770 __uint16_t qlf_type; /* dquot log item type */
771 __uint16_t qlf_size; /* size of this item */
772 xfs_dqid_t qlf_id; /* usr/grp/proj id : 32 bits */
773 __int64_t qlf_blkno; /* blkno of dquot buffer */
774 __int32_t qlf_len; /* len of dquot buffer */
775 __uint32_t qlf_boffset; /* off of dquot in buffer */
776 } xfs_dq_logformat_t;
779 * log format struct for QUOTAOFF records.
780 * The first two fields must be the type and size fitting into
781 * 32 bits : log_recovery code assumes that.
782 * We write two LI_QUOTAOFF logitems per quotaoff, the last one keeps a pointer
783 * to the first and ensures that the first logitem is taken out of the AIL
784 * only when the last one is securely committed.
786 typedef struct xfs_qoff_logformat {
787 unsigned short qf_type; /* quotaoff log item type */
788 unsigned short qf_size; /* size of this item */
789 unsigned int qf_flags; /* USR and/or GRP */
790 char qf_pad[12]; /* padding for future */
791 } xfs_qoff_logformat_t;
795 * Disk quotas status in m_qflags, and also sb_qflags. 16 bits.
797 #define XFS_UQUOTA_ACCT 0x0001 /* user quota accounting ON */
798 #define XFS_UQUOTA_ENFD 0x0002 /* user quota limits enforced */
799 #define XFS_UQUOTA_CHKD 0x0004 /* quotacheck run on usr quotas */
800 #define XFS_PQUOTA_ACCT 0x0008 /* project quota accounting ON */
801 #define XFS_OQUOTA_ENFD 0x0010 /* other (grp/prj) quota limits enforced */
802 #define XFS_OQUOTA_CHKD 0x0020 /* quotacheck run on other (grp/prj) quotas */
803 #define XFS_GQUOTA_ACCT 0x0040 /* group quota accounting ON */
806 * Conversion to and from the combined OQUOTA flag (if necessary)
807 * is done only in xfs_sb_qflags_to_disk() and xfs_sb_qflags_from_disk()
809 #define XFS_GQUOTA_ENFD 0x0080 /* group quota limits enforced */
810 #define XFS_GQUOTA_CHKD 0x0100 /* quotacheck run on group quotas */
811 #define XFS_PQUOTA_ENFD 0x0200 /* project quota limits enforced */
812 #define XFS_PQUOTA_CHKD 0x0400 /* quotacheck run on project quotas */
814 #define XFS_ALL_QUOTA_ACCT \
815 (XFS_UQUOTA_ACCT | XFS_GQUOTA_ACCT | XFS_PQUOTA_ACCT)
816 #define XFS_ALL_QUOTA_ENFD \
817 (XFS_UQUOTA_ENFD | XFS_GQUOTA_ENFD | XFS_PQUOTA_ENFD)
818 #define XFS_ALL_QUOTA_CHKD \
819 (XFS_UQUOTA_CHKD | XFS_GQUOTA_CHKD | XFS_PQUOTA_CHKD)
822 * Inode create log item structure
824 * Log recovery assumes the first two entries are the type and size and they fit
825 * in 32 bits. Also in host order (ugh) so they have to be 32 bit aligned so
826 * decoding can be done correctly.
828 struct xfs_icreate_log {
829 __uint16_t icl_type; /* type of log format structure */
830 __uint16_t icl_size; /* size of log format structure */
831 __be32 icl_ag; /* ag being allocated in */
832 __be32 icl_agbno; /* start block of inode range */
833 __be32 icl_count; /* number of inodes to initialise */
834 __be32 icl_isize; /* size of inodes */
835 __be32 icl_length; /* length of extent to initialise */
836 __be32 icl_gen; /* inode generation number to use */
839 int xfs_log_calc_unit_res(struct xfs_mount *mp, int unit_bytes);
841 #endif /* __XFS_LOG_FORMAT_H__ */