xfs_log_format.h 29 KB

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