xfs_da_format.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  1. /*
  2. * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  3. * Copyright (c) 2013 Red Hat, Inc.
  4. * All Rights Reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it would be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write the Free Software Foundation,
  17. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. #ifndef __XFS_DA_FORMAT_H__
  20. #define __XFS_DA_FORMAT_H__
  21. /*========================================================================
  22. * Directory Structure when greater than XFS_LBSIZE(mp) bytes.
  23. *========================================================================*/
  24. /*
  25. * This structure is common to both leaf nodes and non-leaf nodes in the Btree.
  26. *
  27. * It is used to manage a doubly linked list of all blocks at the same
  28. * level in the Btree, and to identify which type of block this is.
  29. */
  30. #define XFS_DA_NODE_MAGIC 0xfebe /* magic number: non-leaf blocks */
  31. #define XFS_ATTR_LEAF_MAGIC 0xfbee /* magic number: attribute leaf blks */
  32. #define XFS_DIR2_LEAF1_MAGIC 0xd2f1 /* magic number: v2 dirlf single blks */
  33. #define XFS_DIR2_LEAFN_MAGIC 0xd2ff /* magic number: v2 dirlf multi blks */
  34. typedef struct xfs_da_blkinfo {
  35. __be32 forw; /* previous block in list */
  36. __be32 back; /* following block in list */
  37. __be16 magic; /* validity check on block */
  38. __be16 pad; /* unused */
  39. } xfs_da_blkinfo_t;
  40. /*
  41. * CRC enabled directory structure types
  42. *
  43. * The headers change size for the additional verification information, but
  44. * otherwise the tree layouts and contents are unchanged. Hence the da btree
  45. * code can use the struct xfs_da_blkinfo for manipulating the tree links and
  46. * magic numbers without modification for both v2 and v3 nodes.
  47. */
  48. #define XFS_DA3_NODE_MAGIC 0x3ebe /* magic number: non-leaf blocks */
  49. #define XFS_ATTR3_LEAF_MAGIC 0x3bee /* magic number: attribute leaf blks */
  50. #define XFS_DIR3_LEAF1_MAGIC 0x3df1 /* magic number: v2 dirlf single blks */
  51. #define XFS_DIR3_LEAFN_MAGIC 0x3dff /* magic number: v2 dirlf multi blks */
  52. struct xfs_da3_blkinfo {
  53. /*
  54. * the node link manipulation code relies on the fact that the first
  55. * element of this structure is the struct xfs_da_blkinfo so it can
  56. * ignore the differences in the rest of the structures.
  57. */
  58. struct xfs_da_blkinfo hdr;
  59. __be32 crc; /* CRC of block */
  60. __be64 blkno; /* first block of the buffer */
  61. __be64 lsn; /* sequence number of last write */
  62. uuid_t uuid; /* filesystem we belong to */
  63. __be64 owner; /* inode that owns the block */
  64. };
  65. /*
  66. * This is the structure of the root and intermediate nodes in the Btree.
  67. * The leaf nodes are defined above.
  68. *
  69. * Entries are not packed.
  70. *
  71. * Since we have duplicate keys, use a binary search but always follow
  72. * all match in the block, not just the first match found.
  73. */
  74. #define XFS_DA_NODE_MAXDEPTH 5 /* max depth of Btree */
  75. typedef struct xfs_da_node_hdr {
  76. struct xfs_da_blkinfo info; /* block type, links, etc. */
  77. __be16 __count; /* count of active entries */
  78. __be16 __level; /* level above leaves (leaf == 0) */
  79. } xfs_da_node_hdr_t;
  80. struct xfs_da3_node_hdr {
  81. struct xfs_da3_blkinfo info; /* block type, links, etc. */
  82. __be16 __count; /* count of active entries */
  83. __be16 __level; /* level above leaves (leaf == 0) */
  84. __be32 __pad32;
  85. };
  86. #define XFS_DA3_NODE_CRC_OFF (offsetof(struct xfs_da3_node_hdr, info.crc))
  87. typedef struct xfs_da_node_entry {
  88. __be32 hashval; /* hash value for this descendant */
  89. __be32 before; /* Btree block before this key */
  90. } xfs_da_node_entry_t;
  91. typedef struct xfs_da_intnode {
  92. struct xfs_da_node_hdr hdr;
  93. struct xfs_da_node_entry __btree[];
  94. } xfs_da_intnode_t;
  95. struct xfs_da3_intnode {
  96. struct xfs_da3_node_hdr hdr;
  97. struct xfs_da_node_entry __btree[];
  98. };
  99. /*
  100. * In-core version of the node header to abstract the differences in the v2 and
  101. * v3 disk format of the headers. Callers need to convert to/from disk format as
  102. * appropriate.
  103. */
  104. struct xfs_da3_icnode_hdr {
  105. __uint32_t forw;
  106. __uint32_t back;
  107. __uint16_t magic;
  108. __uint16_t count;
  109. __uint16_t level;
  110. };
  111. extern void xfs_da3_node_hdr_from_disk(struct xfs_da3_icnode_hdr *to,
  112. struct xfs_da_intnode *from);
  113. extern void xfs_da3_node_hdr_to_disk(struct xfs_da_intnode *to,
  114. struct xfs_da3_icnode_hdr *from);
  115. static inline int
  116. __xfs_da3_node_hdr_size(bool v3)
  117. {
  118. if (v3)
  119. return sizeof(struct xfs_da3_node_hdr);
  120. return sizeof(struct xfs_da_node_hdr);
  121. }
  122. static inline int
  123. xfs_da3_node_hdr_size(struct xfs_da_intnode *dap)
  124. {
  125. bool v3 = dap->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC);
  126. return __xfs_da3_node_hdr_size(v3);
  127. }
  128. static inline struct xfs_da_node_entry *
  129. xfs_da3_node_tree_p(struct xfs_da_intnode *dap)
  130. {
  131. if (dap->hdr.info.magic == cpu_to_be16(XFS_DA3_NODE_MAGIC)) {
  132. struct xfs_da3_intnode *dap3 = (struct xfs_da3_intnode *)dap;
  133. return dap3->__btree;
  134. }
  135. return dap->__btree;
  136. }
  137. extern void xfs_da3_intnode_from_disk(struct xfs_da3_icnode_hdr *to,
  138. struct xfs_da_intnode *from);
  139. extern void xfs_da3_intnode_to_disk(struct xfs_da_intnode *to,
  140. struct xfs_da3_icnode_hdr *from);
  141. #define XFS_LBSIZE(mp) (mp)->m_sb.sb_blocksize
  142. /*
  143. * Directory version 2.
  144. *
  145. * There are 4 possible formats:
  146. * - shortform - embedded into the inode
  147. * - single block - data with embedded leaf at the end
  148. * - multiple data blocks, single leaf+freeindex block
  149. * - data blocks, node and leaf blocks (btree), freeindex blocks
  150. *
  151. * Note: many node blocks structures and constants are shared with the attr
  152. * code and defined in xfs_da_btree.h.
  153. */
  154. #define XFS_DIR2_BLOCK_MAGIC 0x58443242 /* XD2B: single block dirs */
  155. #define XFS_DIR2_DATA_MAGIC 0x58443244 /* XD2D: multiblock dirs */
  156. #define XFS_DIR2_FREE_MAGIC 0x58443246 /* XD2F: free index blocks */
  157. /*
  158. * Directory Version 3 With CRCs.
  159. *
  160. * The tree formats are the same as for version 2 directories. The difference
  161. * is in the block header and dirent formats. In many cases the v3 structures
  162. * use v2 definitions as they are no different and this makes code sharing much
  163. * easier.
  164. *
  165. * Also, the xfs_dir3_*() functions handle both v2 and v3 formats - if the
  166. * format is v2 then they switch to the existing v2 code, or the format is v3
  167. * they implement the v3 functionality. This means the existing dir2 is a mix of
  168. * xfs_dir2/xfs_dir3 calls and functions. The xfs_dir3 functions are called
  169. * where there is a difference in the formats, otherwise the code is unchanged.
  170. *
  171. * Where it is possible, the code decides what to do based on the magic numbers
  172. * in the blocks rather than feature bits in the superblock. This means the code
  173. * is as independent of the external XFS code as possible as doesn't require
  174. * passing struct xfs_mount pointers into places where it isn't really
  175. * necessary.
  176. *
  177. * Version 3 includes:
  178. *
  179. * - a larger block header for CRC and identification purposes and so the
  180. * offsets of all the structures inside the blocks are different.
  181. *
  182. * - new magic numbers to be able to detect the v2/v3 types on the fly.
  183. */
  184. #define XFS_DIR3_BLOCK_MAGIC 0x58444233 /* XDB3: single block dirs */
  185. #define XFS_DIR3_DATA_MAGIC 0x58444433 /* XDD3: multiblock dirs */
  186. #define XFS_DIR3_FREE_MAGIC 0x58444633 /* XDF3: free index blocks */
  187. /*
  188. * Dirents in version 3 directories have a file type field. Additions to this
  189. * list are an on-disk format change, requiring feature bits. Valid values
  190. * are as follows:
  191. */
  192. #define XFS_DIR3_FT_UNKNOWN 0
  193. #define XFS_DIR3_FT_REG_FILE 1
  194. #define XFS_DIR3_FT_DIR 2
  195. #define XFS_DIR3_FT_CHRDEV 3
  196. #define XFS_DIR3_FT_BLKDEV 4
  197. #define XFS_DIR3_FT_FIFO 5
  198. #define XFS_DIR3_FT_SOCK 6
  199. #define XFS_DIR3_FT_SYMLINK 7
  200. #define XFS_DIR3_FT_WHT 8
  201. #define XFS_DIR3_FT_MAX 9
  202. /*
  203. * Byte offset in data block and shortform entry.
  204. */
  205. typedef __uint16_t xfs_dir2_data_off_t;
  206. #define NULLDATAOFF 0xffffU
  207. typedef uint xfs_dir2_data_aoff_t; /* argument form */
  208. /*
  209. * Normalized offset (in a data block) of the entry, really xfs_dir2_data_off_t.
  210. * Only need 16 bits, this is the byte offset into the single block form.
  211. */
  212. typedef struct { __uint8_t i[2]; } __arch_pack xfs_dir2_sf_off_t;
  213. /*
  214. * Offset in data space of a data entry.
  215. */
  216. typedef __uint32_t xfs_dir2_dataptr_t;
  217. #define XFS_DIR2_MAX_DATAPTR ((xfs_dir2_dataptr_t)0xffffffff)
  218. #define XFS_DIR2_NULL_DATAPTR ((xfs_dir2_dataptr_t)0)
  219. /*
  220. * Byte offset in a directory.
  221. */
  222. typedef xfs_off_t xfs_dir2_off_t;
  223. /*
  224. * Directory block number (logical dirblk in file)
  225. */
  226. typedef __uint32_t xfs_dir2_db_t;
  227. /*
  228. * Inode number stored as 8 8-bit values.
  229. */
  230. typedef struct { __uint8_t i[8]; } xfs_dir2_ino8_t;
  231. /*
  232. * Inode number stored as 4 8-bit values.
  233. * Works a lot of the time, when all the inode numbers in a directory
  234. * fit in 32 bits.
  235. */
  236. typedef struct { __uint8_t i[4]; } xfs_dir2_ino4_t;
  237. typedef union {
  238. xfs_dir2_ino8_t i8;
  239. xfs_dir2_ino4_t i4;
  240. } xfs_dir2_inou_t;
  241. #define XFS_DIR2_MAX_SHORT_INUM ((xfs_ino_t)0xffffffffULL)
  242. /*
  243. * Directory layout when stored internal to an inode.
  244. *
  245. * Small directories are packed as tightly as possible so as to fit into the
  246. * literal area of the inode. These "shortform" directories consist of a
  247. * single xfs_dir2_sf_hdr header followed by zero or more xfs_dir2_sf_entry
  248. * structures. Due the different inode number storage size and the variable
  249. * length name field in the xfs_dir2_sf_entry all these structure are
  250. * variable length, and the accessors in this file should be used to iterate
  251. * over them.
  252. */
  253. typedef struct xfs_dir2_sf_hdr {
  254. __uint8_t count; /* count of entries */
  255. __uint8_t i8count; /* count of 8-byte inode #s */
  256. xfs_dir2_inou_t parent; /* parent dir inode number */
  257. } __arch_pack xfs_dir2_sf_hdr_t;
  258. typedef struct xfs_dir2_sf_entry {
  259. __u8 namelen; /* actual name length */
  260. xfs_dir2_sf_off_t offset; /* saved offset */
  261. __u8 name[]; /* name, variable size */
  262. /*
  263. * A single byte containing the file type field follows the inode
  264. * number for version 3 directory entries.
  265. *
  266. * A xfs_dir2_ino8_t or xfs_dir2_ino4_t follows here, at a
  267. * variable offset after the name.
  268. */
  269. } __arch_pack xfs_dir2_sf_entry_t;
  270. static inline int xfs_dir2_sf_hdr_size(int i8count)
  271. {
  272. return sizeof(struct xfs_dir2_sf_hdr) -
  273. (i8count == 0) *
  274. (sizeof(xfs_dir2_ino8_t) - sizeof(xfs_dir2_ino4_t));
  275. }
  276. static inline xfs_dir2_data_aoff_t
  277. xfs_dir2_sf_get_offset(xfs_dir2_sf_entry_t *sfep)
  278. {
  279. return get_unaligned_be16(&sfep->offset.i);
  280. }
  281. static inline void
  282. xfs_dir2_sf_put_offset(xfs_dir2_sf_entry_t *sfep, xfs_dir2_data_aoff_t off)
  283. {
  284. put_unaligned_be16(off, &sfep->offset.i);
  285. }
  286. static inline struct xfs_dir2_sf_entry *
  287. xfs_dir2_sf_firstentry(struct xfs_dir2_sf_hdr *hdr)
  288. {
  289. return (struct xfs_dir2_sf_entry *)
  290. ((char *)hdr + xfs_dir2_sf_hdr_size(hdr->i8count));
  291. }
  292. /*
  293. * Data block structures.
  294. *
  295. * A pure data block looks like the following drawing on disk:
  296. *
  297. * +-------------------------------------------------+
  298. * | xfs_dir2_data_hdr_t |
  299. * +-------------------------------------------------+
  300. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
  301. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
  302. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
  303. * | ... |
  304. * +-------------------------------------------------+
  305. * | unused space |
  306. * +-------------------------------------------------+
  307. *
  308. * As all the entries are variable size structures the accessors below should
  309. * be used to iterate over them.
  310. *
  311. * In addition to the pure data blocks for the data and node formats,
  312. * most structures are also used for the combined data/freespace "block"
  313. * format below.
  314. */
  315. #define XFS_DIR2_DATA_ALIGN_LOG 3 /* i.e., 8 bytes */
  316. #define XFS_DIR2_DATA_ALIGN (1 << XFS_DIR2_DATA_ALIGN_LOG)
  317. #define XFS_DIR2_DATA_FREE_TAG 0xffff
  318. #define XFS_DIR2_DATA_FD_COUNT 3
  319. /*
  320. * Directory address space divided into sections,
  321. * spaces separated by 32GB.
  322. */
  323. #define XFS_DIR2_SPACE_SIZE (1ULL << (32 + XFS_DIR2_DATA_ALIGN_LOG))
  324. #define XFS_DIR2_DATA_SPACE 0
  325. #define XFS_DIR2_DATA_OFFSET (XFS_DIR2_DATA_SPACE * XFS_DIR2_SPACE_SIZE)
  326. #define XFS_DIR2_DATA_FIRSTDB(mp) \
  327. xfs_dir2_byte_to_db(mp, XFS_DIR2_DATA_OFFSET)
  328. /*
  329. * Describe a free area in the data block.
  330. *
  331. * The freespace will be formatted as a xfs_dir2_data_unused_t.
  332. */
  333. typedef struct xfs_dir2_data_free {
  334. __be16 offset; /* start of freespace */
  335. __be16 length; /* length of freespace */
  336. } xfs_dir2_data_free_t;
  337. /*
  338. * Header for the data blocks.
  339. *
  340. * The code knows that XFS_DIR2_DATA_FD_COUNT is 3.
  341. */
  342. typedef struct xfs_dir2_data_hdr {
  343. __be32 magic; /* XFS_DIR2_DATA_MAGIC or */
  344. /* XFS_DIR2_BLOCK_MAGIC */
  345. xfs_dir2_data_free_t bestfree[XFS_DIR2_DATA_FD_COUNT];
  346. } xfs_dir2_data_hdr_t;
  347. /*
  348. * define a structure for all the verification fields we are adding to the
  349. * directory block structures. This will be used in several structures.
  350. * The magic number must be the first entry to align with all the dir2
  351. * structures so we determine how to decode them just by the magic number.
  352. */
  353. struct xfs_dir3_blk_hdr {
  354. __be32 magic; /* magic number */
  355. __be32 crc; /* CRC of block */
  356. __be64 blkno; /* first block of the buffer */
  357. __be64 lsn; /* sequence number of last write */
  358. uuid_t uuid; /* filesystem we belong to */
  359. __be64 owner; /* inode that owns the block */
  360. };
  361. struct xfs_dir3_data_hdr {
  362. struct xfs_dir3_blk_hdr hdr;
  363. xfs_dir2_data_free_t best_free[XFS_DIR2_DATA_FD_COUNT];
  364. __be32 pad; /* 64 bit alignment */
  365. };
  366. #define XFS_DIR3_DATA_CRC_OFF offsetof(struct xfs_dir3_data_hdr, hdr.crc)
  367. /*
  368. * Active entry in a data block.
  369. *
  370. * Aligned to 8 bytes. After the variable length name field there is a
  371. * 2 byte tag field, which can be accessed using xfs_dir3_data_entry_tag_p.
  372. *
  373. * For dir3 structures, there is file type field between the name and the tag.
  374. * This can only be manipulated by helper functions. It is packed hard against
  375. * the end of the name so any padding for rounding is between the file type and
  376. * the tag.
  377. */
  378. typedef struct xfs_dir2_data_entry {
  379. __be64 inumber; /* inode number */
  380. __u8 namelen; /* name length */
  381. __u8 name[]; /* name bytes, no null */
  382. /* __u8 filetype; */ /* type of inode we point to */
  383. /* __be16 tag; */ /* starting offset of us */
  384. } xfs_dir2_data_entry_t;
  385. /*
  386. * Unused entry in a data block.
  387. *
  388. * Aligned to 8 bytes. Tag appears as the last 2 bytes and must be accessed
  389. * using xfs_dir2_data_unused_tag_p.
  390. */
  391. typedef struct xfs_dir2_data_unused {
  392. __be16 freetag; /* XFS_DIR2_DATA_FREE_TAG */
  393. __be16 length; /* total free length */
  394. /* variable offset */
  395. __be16 tag; /* starting offset of us */
  396. } xfs_dir2_data_unused_t;
  397. /*
  398. * Pointer to a freespace's tag word.
  399. */
  400. static inline __be16 *
  401. xfs_dir2_data_unused_tag_p(struct xfs_dir2_data_unused *dup)
  402. {
  403. return (__be16 *)((char *)dup +
  404. be16_to_cpu(dup->length) - sizeof(__be16));
  405. }
  406. /*
  407. * Leaf block structures.
  408. *
  409. * A pure leaf block looks like the following drawing on disk:
  410. *
  411. * +---------------------------+
  412. * | xfs_dir2_leaf_hdr_t |
  413. * +---------------------------+
  414. * | xfs_dir2_leaf_entry_t |
  415. * | xfs_dir2_leaf_entry_t |
  416. * | xfs_dir2_leaf_entry_t |
  417. * | xfs_dir2_leaf_entry_t |
  418. * | ... |
  419. * +---------------------------+
  420. * | xfs_dir2_data_off_t |
  421. * | xfs_dir2_data_off_t |
  422. * | xfs_dir2_data_off_t |
  423. * | ... |
  424. * +---------------------------+
  425. * | xfs_dir2_leaf_tail_t |
  426. * +---------------------------+
  427. *
  428. * The xfs_dir2_data_off_t members (bests) and tail are at the end of the block
  429. * for single-leaf (magic = XFS_DIR2_LEAF1_MAGIC) blocks only, but not present
  430. * for directories with separate leaf nodes and free space blocks
  431. * (magic = XFS_DIR2_LEAFN_MAGIC).
  432. *
  433. * As all the entries are variable size structures the accessors below should
  434. * be used to iterate over them.
  435. */
  436. /*
  437. * Offset of the leaf/node space. First block in this space
  438. * is the btree root.
  439. */
  440. #define XFS_DIR2_LEAF_SPACE 1
  441. #define XFS_DIR2_LEAF_OFFSET (XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE)
  442. #define XFS_DIR2_LEAF_FIRSTDB(mp) \
  443. xfs_dir2_byte_to_db(mp, XFS_DIR2_LEAF_OFFSET)
  444. /*
  445. * Leaf block header.
  446. */
  447. typedef struct xfs_dir2_leaf_hdr {
  448. xfs_da_blkinfo_t info; /* header for da routines */
  449. __be16 count; /* count of entries */
  450. __be16 stale; /* count of stale entries */
  451. } xfs_dir2_leaf_hdr_t;
  452. struct xfs_dir3_leaf_hdr {
  453. struct xfs_da3_blkinfo info; /* header for da routines */
  454. __be16 count; /* count of entries */
  455. __be16 stale; /* count of stale entries */
  456. __be32 pad; /* 64 bit alignment */
  457. };
  458. struct xfs_dir3_icleaf_hdr {
  459. __uint32_t forw;
  460. __uint32_t back;
  461. __uint16_t magic;
  462. __uint16_t count;
  463. __uint16_t stale;
  464. };
  465. /*
  466. * Leaf block entry.
  467. */
  468. typedef struct xfs_dir2_leaf_entry {
  469. __be32 hashval; /* hash value of name */
  470. __be32 address; /* address of data entry */
  471. } xfs_dir2_leaf_entry_t;
  472. /*
  473. * Leaf block tail.
  474. */
  475. typedef struct xfs_dir2_leaf_tail {
  476. __be32 bestcount;
  477. } xfs_dir2_leaf_tail_t;
  478. /*
  479. * Leaf block.
  480. */
  481. typedef struct xfs_dir2_leaf {
  482. xfs_dir2_leaf_hdr_t hdr; /* leaf header */
  483. xfs_dir2_leaf_entry_t __ents[]; /* entries */
  484. } xfs_dir2_leaf_t;
  485. struct xfs_dir3_leaf {
  486. struct xfs_dir3_leaf_hdr hdr; /* leaf header */
  487. struct xfs_dir2_leaf_entry __ents[]; /* entries */
  488. };
  489. #define XFS_DIR3_LEAF_CRC_OFF offsetof(struct xfs_dir3_leaf_hdr, info.crc)
  490. extern void xfs_dir3_leaf_hdr_from_disk(struct xfs_dir3_icleaf_hdr *to,
  491. struct xfs_dir2_leaf *from);
  492. /*
  493. * Get address of the bestcount field in the single-leaf block.
  494. */
  495. static inline struct xfs_dir2_leaf_tail *
  496. xfs_dir2_leaf_tail_p(struct xfs_mount *mp, struct xfs_dir2_leaf *lp)
  497. {
  498. return (struct xfs_dir2_leaf_tail *)
  499. ((char *)lp + mp->m_dirblksize -
  500. sizeof(struct xfs_dir2_leaf_tail));
  501. }
  502. /*
  503. * Get address of the bests array in the single-leaf block.
  504. */
  505. static inline __be16 *
  506. xfs_dir2_leaf_bests_p(struct xfs_dir2_leaf_tail *ltp)
  507. {
  508. return (__be16 *)ltp - be32_to_cpu(ltp->bestcount);
  509. }
  510. /*
  511. * DB blocks here are logical directory block numbers, not filesystem blocks.
  512. */
  513. /*
  514. * Convert dataptr to byte in file space
  515. */
  516. static inline xfs_dir2_off_t
  517. xfs_dir2_dataptr_to_byte(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  518. {
  519. return (xfs_dir2_off_t)dp << XFS_DIR2_DATA_ALIGN_LOG;
  520. }
  521. /*
  522. * Convert byte in file space to dataptr. It had better be aligned.
  523. */
  524. static inline xfs_dir2_dataptr_t
  525. xfs_dir2_byte_to_dataptr(struct xfs_mount *mp, xfs_dir2_off_t by)
  526. {
  527. return (xfs_dir2_dataptr_t)(by >> XFS_DIR2_DATA_ALIGN_LOG);
  528. }
  529. /*
  530. * Convert byte in space to (DB) block
  531. */
  532. static inline xfs_dir2_db_t
  533. xfs_dir2_byte_to_db(struct xfs_mount *mp, xfs_dir2_off_t by)
  534. {
  535. return (xfs_dir2_db_t)
  536. (by >> (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog));
  537. }
  538. /*
  539. * Convert dataptr to a block number
  540. */
  541. static inline xfs_dir2_db_t
  542. xfs_dir2_dataptr_to_db(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  543. {
  544. return xfs_dir2_byte_to_db(mp, xfs_dir2_dataptr_to_byte(mp, dp));
  545. }
  546. /*
  547. * Convert byte in space to offset in a block
  548. */
  549. static inline xfs_dir2_data_aoff_t
  550. xfs_dir2_byte_to_off(struct xfs_mount *mp, xfs_dir2_off_t by)
  551. {
  552. return (xfs_dir2_data_aoff_t)(by &
  553. ((1 << (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog)) - 1));
  554. }
  555. /*
  556. * Convert dataptr to a byte offset in a block
  557. */
  558. static inline xfs_dir2_data_aoff_t
  559. xfs_dir2_dataptr_to_off(struct xfs_mount *mp, xfs_dir2_dataptr_t dp)
  560. {
  561. return xfs_dir2_byte_to_off(mp, xfs_dir2_dataptr_to_byte(mp, dp));
  562. }
  563. /*
  564. * Convert block and offset to byte in space
  565. */
  566. static inline xfs_dir2_off_t
  567. xfs_dir2_db_off_to_byte(struct xfs_mount *mp, xfs_dir2_db_t db,
  568. xfs_dir2_data_aoff_t o)
  569. {
  570. return ((xfs_dir2_off_t)db <<
  571. (mp->m_sb.sb_blocklog + mp->m_sb.sb_dirblklog)) + o;
  572. }
  573. /*
  574. * Convert block (DB) to block (dablk)
  575. */
  576. static inline xfs_dablk_t
  577. xfs_dir2_db_to_da(struct xfs_mount *mp, xfs_dir2_db_t db)
  578. {
  579. return (xfs_dablk_t)(db << mp->m_sb.sb_dirblklog);
  580. }
  581. /*
  582. * Convert byte in space to (DA) block
  583. */
  584. static inline xfs_dablk_t
  585. xfs_dir2_byte_to_da(struct xfs_mount *mp, xfs_dir2_off_t by)
  586. {
  587. return xfs_dir2_db_to_da(mp, xfs_dir2_byte_to_db(mp, by));
  588. }
  589. /*
  590. * Convert block and offset to dataptr
  591. */
  592. static inline xfs_dir2_dataptr_t
  593. xfs_dir2_db_off_to_dataptr(struct xfs_mount *mp, xfs_dir2_db_t db,
  594. xfs_dir2_data_aoff_t o)
  595. {
  596. return xfs_dir2_byte_to_dataptr(mp, xfs_dir2_db_off_to_byte(mp, db, o));
  597. }
  598. /*
  599. * Convert block (dablk) to block (DB)
  600. */
  601. static inline xfs_dir2_db_t
  602. xfs_dir2_da_to_db(struct xfs_mount *mp, xfs_dablk_t da)
  603. {
  604. return (xfs_dir2_db_t)(da >> mp->m_sb.sb_dirblklog);
  605. }
  606. /*
  607. * Convert block (dablk) to byte offset in space
  608. */
  609. static inline xfs_dir2_off_t
  610. xfs_dir2_da_to_byte(struct xfs_mount *mp, xfs_dablk_t da)
  611. {
  612. return xfs_dir2_db_off_to_byte(mp, xfs_dir2_da_to_db(mp, da), 0);
  613. }
  614. /*
  615. * Free space block defintions for the node format.
  616. */
  617. /*
  618. * Offset of the freespace index.
  619. */
  620. #define XFS_DIR2_FREE_SPACE 2
  621. #define XFS_DIR2_FREE_OFFSET (XFS_DIR2_FREE_SPACE * XFS_DIR2_SPACE_SIZE)
  622. #define XFS_DIR2_FREE_FIRSTDB(mp) \
  623. xfs_dir2_byte_to_db(mp, XFS_DIR2_FREE_OFFSET)
  624. typedef struct xfs_dir2_free_hdr {
  625. __be32 magic; /* XFS_DIR2_FREE_MAGIC */
  626. __be32 firstdb; /* db of first entry */
  627. __be32 nvalid; /* count of valid entries */
  628. __be32 nused; /* count of used entries */
  629. } xfs_dir2_free_hdr_t;
  630. typedef struct xfs_dir2_free {
  631. xfs_dir2_free_hdr_t hdr; /* block header */
  632. __be16 bests[]; /* best free counts */
  633. /* unused entries are -1 */
  634. } xfs_dir2_free_t;
  635. struct xfs_dir3_free_hdr {
  636. struct xfs_dir3_blk_hdr hdr;
  637. __be32 firstdb; /* db of first entry */
  638. __be32 nvalid; /* count of valid entries */
  639. __be32 nused; /* count of used entries */
  640. __be32 pad; /* 64 bit alignment */
  641. };
  642. struct xfs_dir3_free {
  643. struct xfs_dir3_free_hdr hdr;
  644. __be16 bests[]; /* best free counts */
  645. /* unused entries are -1 */
  646. };
  647. #define XFS_DIR3_FREE_CRC_OFF offsetof(struct xfs_dir3_free, hdr.hdr.crc)
  648. /*
  649. * In core version of the free block header, abstracted away from on-disk format
  650. * differences. Use this in the code, and convert to/from the disk version using
  651. * xfs_dir3_free_hdr_from_disk/xfs_dir3_free_hdr_to_disk.
  652. */
  653. struct xfs_dir3_icfree_hdr {
  654. __uint32_t magic;
  655. __uint32_t firstdb;
  656. __uint32_t nvalid;
  657. __uint32_t nused;
  658. };
  659. void xfs_dir3_free_hdr_from_disk(struct xfs_dir3_icfree_hdr *to,
  660. struct xfs_dir2_free *from);
  661. static inline int
  662. xfs_dir3_free_hdr_size(struct xfs_mount *mp)
  663. {
  664. if (xfs_sb_version_hascrc(&mp->m_sb))
  665. return sizeof(struct xfs_dir3_free_hdr);
  666. return sizeof(struct xfs_dir2_free_hdr);
  667. }
  668. static inline int
  669. xfs_dir3_free_max_bests(struct xfs_mount *mp)
  670. {
  671. return (mp->m_dirblksize - xfs_dir3_free_hdr_size(mp)) /
  672. sizeof(xfs_dir2_data_off_t);
  673. }
  674. static inline __be16 *
  675. xfs_dir3_free_bests_p(struct xfs_mount *mp, struct xfs_dir2_free *free)
  676. {
  677. return (__be16 *)((char *)free + xfs_dir3_free_hdr_size(mp));
  678. }
  679. /*
  680. * Convert data space db to the corresponding free db.
  681. */
  682. static inline xfs_dir2_db_t
  683. xfs_dir2_db_to_fdb(struct xfs_mount *mp, xfs_dir2_db_t db)
  684. {
  685. return XFS_DIR2_FREE_FIRSTDB(mp) + db / xfs_dir3_free_max_bests(mp);
  686. }
  687. /*
  688. * Convert data space db to the corresponding index in a free db.
  689. */
  690. static inline int
  691. xfs_dir2_db_to_fdindex(struct xfs_mount *mp, xfs_dir2_db_t db)
  692. {
  693. return db % xfs_dir3_free_max_bests(mp);
  694. }
  695. /*
  696. * Single block format.
  697. *
  698. * The single block format looks like the following drawing on disk:
  699. *
  700. * +-------------------------------------------------+
  701. * | xfs_dir2_data_hdr_t |
  702. * +-------------------------------------------------+
  703. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
  704. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
  705. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t :
  706. * | ... |
  707. * +-------------------------------------------------+
  708. * | unused space |
  709. * +-------------------------------------------------+
  710. * | ... |
  711. * | xfs_dir2_leaf_entry_t |
  712. * | xfs_dir2_leaf_entry_t |
  713. * +-------------------------------------------------+
  714. * | xfs_dir2_block_tail_t |
  715. * +-------------------------------------------------+
  716. *
  717. * As all the entries are variable size structures the accessors below should
  718. * be used to iterate over them.
  719. */
  720. typedef struct xfs_dir2_block_tail {
  721. __be32 count; /* count of leaf entries */
  722. __be32 stale; /* count of stale lf entries */
  723. } xfs_dir2_block_tail_t;
  724. /*
  725. * Pointer to the leaf header embedded in a data block (1-block format)
  726. */
  727. static inline struct xfs_dir2_block_tail *
  728. xfs_dir2_block_tail_p(struct xfs_mount *mp, struct xfs_dir2_data_hdr *hdr)
  729. {
  730. return ((struct xfs_dir2_block_tail *)
  731. ((char *)hdr + mp->m_dirblksize)) - 1;
  732. }
  733. /*
  734. * Pointer to the leaf entries embedded in a data block (1-block format)
  735. */
  736. static inline struct xfs_dir2_leaf_entry *
  737. xfs_dir2_block_leaf_p(struct xfs_dir2_block_tail *btp)
  738. {
  739. return ((struct xfs_dir2_leaf_entry *)btp) - be32_to_cpu(btp->count);
  740. }
  741. /*
  742. * Attribute storage layout
  743. *
  744. * Attribute lists are structured around Btrees where all the data
  745. * elements are in the leaf nodes. Attribute names are hashed into an int,
  746. * then that int is used as the index into the Btree. Since the hashval
  747. * of an attribute name may not be unique, we may have duplicate keys. The
  748. * internal links in the Btree are logical block offsets into the file.
  749. *
  750. *========================================================================
  751. * Attribute structure when equal to XFS_LBSIZE(mp) bytes.
  752. *========================================================================
  753. *
  754. * Struct leaf_entry's are packed from the top. Name/values grow from the
  755. * bottom but are not packed. The freemap contains run-length-encoded entries
  756. * for the free bytes after the leaf_entry's, but only the N largest such,
  757. * smaller runs are dropped. When the freemap doesn't show enough space
  758. * for an allocation, we compact the name/value area and try again. If we
  759. * still don't have enough space, then we have to split the block. The
  760. * name/value structs (both local and remote versions) must be 32bit aligned.
  761. *
  762. * Since we have duplicate hash keys, for each key that matches, compare
  763. * the actual name string. The root and intermediate node search always
  764. * takes the first-in-the-block key match found, so we should only have
  765. * to work "forw"ard. If none matches, continue with the "forw"ard leaf
  766. * nodes until the hash key changes or the attribute name is found.
  767. *
  768. * We store the fact that an attribute is a ROOT/USER/SECURE attribute in
  769. * the leaf_entry. The namespaces are independent only because we also look
  770. * at the namespace bit when we are looking for a matching attribute name.
  771. *
  772. * We also store an "incomplete" bit in the leaf_entry. It shows that an
  773. * attribute is in the middle of being created and should not be shown to
  774. * the user if we crash during the time that the bit is set. We clear the
  775. * bit when we have finished setting up the attribute. We do this because
  776. * we cannot create some large attributes inside a single transaction, and we
  777. * need some indication that we weren't finished if we crash in the middle.
  778. */
  779. #define XFS_ATTR_LEAF_MAPSIZE 3 /* how many freespace slots */
  780. typedef struct xfs_attr_leaf_map { /* RLE map of free bytes */
  781. __be16 base; /* base of free region */
  782. __be16 size; /* length of free region */
  783. } xfs_attr_leaf_map_t;
  784. typedef struct xfs_attr_leaf_hdr { /* constant-structure header block */
  785. xfs_da_blkinfo_t info; /* block type, links, etc. */
  786. __be16 count; /* count of active leaf_entry's */
  787. __be16 usedbytes; /* num bytes of names/values stored */
  788. __be16 firstused; /* first used byte in name area */
  789. __u8 holes; /* != 0 if blk needs compaction */
  790. __u8 pad1;
  791. xfs_attr_leaf_map_t freemap[XFS_ATTR_LEAF_MAPSIZE];
  792. /* N largest free regions */
  793. } xfs_attr_leaf_hdr_t;
  794. typedef struct xfs_attr_leaf_entry { /* sorted on key, not name */
  795. __be32 hashval; /* hash value of name */
  796. __be16 nameidx; /* index into buffer of name/value */
  797. __u8 flags; /* LOCAL/ROOT/SECURE/INCOMPLETE flag */
  798. __u8 pad2; /* unused pad byte */
  799. } xfs_attr_leaf_entry_t;
  800. typedef struct xfs_attr_leaf_name_local {
  801. __be16 valuelen; /* number of bytes in value */
  802. __u8 namelen; /* length of name bytes */
  803. __u8 nameval[1]; /* name/value bytes */
  804. } xfs_attr_leaf_name_local_t;
  805. typedef struct xfs_attr_leaf_name_remote {
  806. __be32 valueblk; /* block number of value bytes */
  807. __be32 valuelen; /* number of bytes in value */
  808. __u8 namelen; /* length of name bytes */
  809. __u8 name[1]; /* name bytes */
  810. } xfs_attr_leaf_name_remote_t;
  811. typedef struct xfs_attr_leafblock {
  812. xfs_attr_leaf_hdr_t hdr; /* constant-structure header block */
  813. xfs_attr_leaf_entry_t entries[1]; /* sorted on key, not name */
  814. xfs_attr_leaf_name_local_t namelist; /* grows from bottom of buf */
  815. xfs_attr_leaf_name_remote_t valuelist; /* grows from bottom of buf */
  816. } xfs_attr_leafblock_t;
  817. /*
  818. * CRC enabled leaf structures. Called "version 3" structures to match the
  819. * version number of the directory and dablk structures for this feature, and
  820. * attr2 is already taken by the variable inode attribute fork size feature.
  821. */
  822. struct xfs_attr3_leaf_hdr {
  823. struct xfs_da3_blkinfo info;
  824. __be16 count;
  825. __be16 usedbytes;
  826. __be16 firstused;
  827. __u8 holes;
  828. __u8 pad1;
  829. struct xfs_attr_leaf_map freemap[XFS_ATTR_LEAF_MAPSIZE];
  830. __be32 pad2; /* 64 bit alignment */
  831. };
  832. #define XFS_ATTR3_LEAF_CRC_OFF (offsetof(struct xfs_attr3_leaf_hdr, info.crc))
  833. struct xfs_attr3_leafblock {
  834. struct xfs_attr3_leaf_hdr hdr;
  835. struct xfs_attr_leaf_entry entries[1];
  836. /*
  837. * The rest of the block contains the following structures after the
  838. * leaf entries, growing from the bottom up. The variables are never
  839. * referenced, the locations accessed purely from helper functions.
  840. *
  841. * struct xfs_attr_leaf_name_local
  842. * struct xfs_attr_leaf_name_remote
  843. */
  844. };
  845. /*
  846. * incore, neutral version of the attribute leaf header
  847. */
  848. struct xfs_attr3_icleaf_hdr {
  849. __uint32_t forw;
  850. __uint32_t back;
  851. __uint16_t magic;
  852. __uint16_t count;
  853. __uint16_t usedbytes;
  854. __uint16_t firstused;
  855. __u8 holes;
  856. struct {
  857. __uint16_t base;
  858. __uint16_t size;
  859. } freemap[XFS_ATTR_LEAF_MAPSIZE];
  860. };
  861. /*
  862. * Flags used in the leaf_entry[i].flags field.
  863. * NOTE: the INCOMPLETE bit must not collide with the flags bits specified
  864. * on the system call, they are "or"ed together for various operations.
  865. */
  866. #define XFS_ATTR_LOCAL_BIT 0 /* attr is stored locally */
  867. #define XFS_ATTR_ROOT_BIT 1 /* limit access to trusted attrs */
  868. #define XFS_ATTR_SECURE_BIT 2 /* limit access to secure attrs */
  869. #define XFS_ATTR_INCOMPLETE_BIT 7 /* attr in middle of create/delete */
  870. #define XFS_ATTR_LOCAL (1 << XFS_ATTR_LOCAL_BIT)
  871. #define XFS_ATTR_ROOT (1 << XFS_ATTR_ROOT_BIT)
  872. #define XFS_ATTR_SECURE (1 << XFS_ATTR_SECURE_BIT)
  873. #define XFS_ATTR_INCOMPLETE (1 << XFS_ATTR_INCOMPLETE_BIT)
  874. /*
  875. * Conversion macros for converting namespace bits from argument flags
  876. * to ondisk flags.
  877. */
  878. #define XFS_ATTR_NSP_ARGS_MASK (ATTR_ROOT | ATTR_SECURE)
  879. #define XFS_ATTR_NSP_ONDISK_MASK (XFS_ATTR_ROOT | XFS_ATTR_SECURE)
  880. #define XFS_ATTR_NSP_ONDISK(flags) ((flags) & XFS_ATTR_NSP_ONDISK_MASK)
  881. #define XFS_ATTR_NSP_ARGS(flags) ((flags) & XFS_ATTR_NSP_ARGS_MASK)
  882. #define XFS_ATTR_NSP_ARGS_TO_ONDISK(x) (((x) & ATTR_ROOT ? XFS_ATTR_ROOT : 0) |\
  883. ((x) & ATTR_SECURE ? XFS_ATTR_SECURE : 0))
  884. #define XFS_ATTR_NSP_ONDISK_TO_ARGS(x) (((x) & XFS_ATTR_ROOT ? ATTR_ROOT : 0) |\
  885. ((x) & XFS_ATTR_SECURE ? ATTR_SECURE : 0))
  886. /*
  887. * Alignment for namelist and valuelist entries (since they are mixed
  888. * there can be only one alignment value)
  889. */
  890. #define XFS_ATTR_LEAF_NAME_ALIGN ((uint)sizeof(xfs_dablk_t))
  891. static inline int
  892. xfs_attr3_leaf_hdr_size(struct xfs_attr_leafblock *leafp)
  893. {
  894. if (leafp->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
  895. return sizeof(struct xfs_attr3_leaf_hdr);
  896. return sizeof(struct xfs_attr_leaf_hdr);
  897. }
  898. static inline struct xfs_attr_leaf_entry *
  899. xfs_attr3_leaf_entryp(xfs_attr_leafblock_t *leafp)
  900. {
  901. if (leafp->hdr.info.magic == cpu_to_be16(XFS_ATTR3_LEAF_MAGIC))
  902. return &((struct xfs_attr3_leafblock *)leafp)->entries[0];
  903. return &leafp->entries[0];
  904. }
  905. /*
  906. * Cast typed pointers for "local" and "remote" name/value structs.
  907. */
  908. static inline char *
  909. xfs_attr3_leaf_name(xfs_attr_leafblock_t *leafp, int idx)
  910. {
  911. struct xfs_attr_leaf_entry *entries = xfs_attr3_leaf_entryp(leafp);
  912. return &((char *)leafp)[be16_to_cpu(entries[idx].nameidx)];
  913. }
  914. static inline xfs_attr_leaf_name_remote_t *
  915. xfs_attr3_leaf_name_remote(xfs_attr_leafblock_t *leafp, int idx)
  916. {
  917. return (xfs_attr_leaf_name_remote_t *)xfs_attr3_leaf_name(leafp, idx);
  918. }
  919. static inline xfs_attr_leaf_name_local_t *
  920. xfs_attr3_leaf_name_local(xfs_attr_leafblock_t *leafp, int idx)
  921. {
  922. return (xfs_attr_leaf_name_local_t *)xfs_attr3_leaf_name(leafp, idx);
  923. }
  924. /*
  925. * Calculate total bytes used (including trailing pad for alignment) for
  926. * a "local" name/value structure, a "remote" name/value structure, and
  927. * a pointer which might be either.
  928. */
  929. static inline int xfs_attr_leaf_entsize_remote(int nlen)
  930. {
  931. return ((uint)sizeof(xfs_attr_leaf_name_remote_t) - 1 + (nlen) + \
  932. XFS_ATTR_LEAF_NAME_ALIGN - 1) & ~(XFS_ATTR_LEAF_NAME_ALIGN - 1);
  933. }
  934. static inline int xfs_attr_leaf_entsize_local(int nlen, int vlen)
  935. {
  936. return ((uint)sizeof(xfs_attr_leaf_name_local_t) - 1 + (nlen) + (vlen) +
  937. XFS_ATTR_LEAF_NAME_ALIGN - 1) & ~(XFS_ATTR_LEAF_NAME_ALIGN - 1);
  938. }
  939. static inline int xfs_attr_leaf_entsize_local_max(int bsize)
  940. {
  941. return (((bsize) >> 1) + ((bsize) >> 2));
  942. }
  943. /*
  944. * Remote attribute block format definition
  945. *
  946. * There is one of these headers per filesystem block in a remote attribute.
  947. * This is done to ensure there is a 1:1 mapping between the attribute value
  948. * length and the number of blocks needed to store the attribute. This makes the
  949. * verification of a buffer a little more complex, but greatly simplifies the
  950. * allocation, reading and writing of these attributes as we don't have to guess
  951. * the number of blocks needed to store the attribute data.
  952. */
  953. #define XFS_ATTR3_RMT_MAGIC 0x5841524d /* XARM */
  954. struct xfs_attr3_rmt_hdr {
  955. __be32 rm_magic;
  956. __be32 rm_offset;
  957. __be32 rm_bytes;
  958. __be32 rm_crc;
  959. uuid_t rm_uuid;
  960. __be64 rm_owner;
  961. __be64 rm_blkno;
  962. __be64 rm_lsn;
  963. };
  964. #define XFS_ATTR3_RMT_CRC_OFF offsetof(struct xfs_attr3_rmt_hdr, rm_crc)
  965. #define XFS_ATTR3_RMT_BUF_SPACE(mp, bufsize) \
  966. ((bufsize) - (xfs_sb_version_hascrc(&(mp)->m_sb) ? \
  967. sizeof(struct xfs_attr3_rmt_hdr) : 0))
  968. #endif /* __XFS_DA_FORMAT_H__ */