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