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