xfs_dir2_data.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * Copyright (c) 2000,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_DIR2_DATA_H__
  19. #define __XFS_DIR2_DATA_H__
  20. /*
  21. * Directory format 2, data block structures.
  22. *
  23. * A pure data block looks like the following drawing on disk:
  24. *
  25. * +-------------------------------------------------+
  26. * | xfs_dir2_data_hdr_t |
  27. * +-------------------------------------------------+
  28. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
  29. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
  30. * | xfs_dir2_data_entry_t OR xfs_dir2_data_unused_t |
  31. * | ... |
  32. * +-------------------------------------------------+
  33. * | unused space |
  34. * +-------------------------------------------------+
  35. *
  36. * As all the entries are variable size structures the accessors in this
  37. * file should be used to iterate over them.
  38. */
  39. struct xfs_dabuf;
  40. struct xfs_da_args;
  41. struct xfs_inode;
  42. struct xfs_trans;
  43. /*
  44. * Constants.
  45. */
  46. #define XFS_DIR2_DATA_MAGIC 0x58443244 /* XD2D: for multiblock dirs */
  47. #define XFS_DIR2_DATA_ALIGN_LOG 3 /* i.e., 8 bytes */
  48. #define XFS_DIR2_DATA_ALIGN (1 << XFS_DIR2_DATA_ALIGN_LOG)
  49. #define XFS_DIR2_DATA_FREE_TAG 0xffff
  50. #define XFS_DIR2_DATA_FD_COUNT 3
  51. /*
  52. * Directory address space divided into sections,
  53. * spaces separated by 32GB.
  54. */
  55. #define XFS_DIR2_SPACE_SIZE (1ULL << (32 + XFS_DIR2_DATA_ALIGN_LOG))
  56. #define XFS_DIR2_DATA_SPACE 0
  57. #define XFS_DIR2_DATA_OFFSET (XFS_DIR2_DATA_SPACE * XFS_DIR2_SPACE_SIZE)
  58. #define XFS_DIR2_DATA_FIRSTDB(mp) \
  59. xfs_dir2_byte_to_db(mp, XFS_DIR2_DATA_OFFSET)
  60. /*
  61. * Offsets of . and .. in data space (always block 0)
  62. */
  63. #define XFS_DIR2_DATA_DOT_OFFSET \
  64. ((xfs_dir2_data_aoff_t)sizeof(xfs_dir2_data_hdr_t))
  65. #define XFS_DIR2_DATA_DOTDOT_OFFSET \
  66. (XFS_DIR2_DATA_DOT_OFFSET + xfs_dir2_data_entsize(1))
  67. #define XFS_DIR2_DATA_FIRST_OFFSET \
  68. (XFS_DIR2_DATA_DOTDOT_OFFSET + xfs_dir2_data_entsize(2))
  69. /*
  70. * Structures.
  71. */
  72. /*
  73. * Describe a free area in the data block.
  74. * The freespace will be formatted as a xfs_dir2_data_unused_t.
  75. */
  76. typedef struct xfs_dir2_data_free {
  77. __be16 offset; /* start of freespace */
  78. __be16 length; /* length of freespace */
  79. } xfs_dir2_data_free_t;
  80. /*
  81. * Header for the data blocks.
  82. * Always at the beginning of a directory-sized block.
  83. * The code knows that XFS_DIR2_DATA_FD_COUNT is 3.
  84. */
  85. typedef struct xfs_dir2_data_hdr {
  86. __be32 magic; /* XFS_DIR2_DATA_MAGIC */
  87. /* or XFS_DIR2_BLOCK_MAGIC */
  88. xfs_dir2_data_free_t bestfree[XFS_DIR2_DATA_FD_COUNT];
  89. } xfs_dir2_data_hdr_t;
  90. /*
  91. * Active entry in a data block. Aligned to 8 bytes.
  92. *
  93. * After the variable length name field there is a 2 byte tag field, which
  94. * can be accessed using xfs_dir2_data_entry_tag_p.
  95. */
  96. typedef struct xfs_dir2_data_entry {
  97. __be64 inumber; /* inode number */
  98. __u8 namelen; /* name length */
  99. __u8 name[]; /* name bytes, no null */
  100. /* __be16 tag; */ /* starting offset of us */
  101. } xfs_dir2_data_entry_t;
  102. /*
  103. * Unused entry in a data block. Aligned to 8 bytes.
  104. * Tag appears as the last 2 bytes.
  105. */
  106. typedef struct xfs_dir2_data_unused {
  107. __be16 freetag; /* XFS_DIR2_DATA_FREE_TAG */
  108. __be16 length; /* total free length */
  109. /* variable offset */
  110. __be16 tag; /* starting offset of us */
  111. } xfs_dir2_data_unused_t;
  112. /*
  113. * Size of a data entry.
  114. */
  115. static inline int xfs_dir2_data_entsize(int n)
  116. {
  117. return (int)roundup(offsetof(xfs_dir2_data_entry_t, name[0]) + (n) + \
  118. (uint)sizeof(xfs_dir2_data_off_t), XFS_DIR2_DATA_ALIGN);
  119. }
  120. /*
  121. * Pointer to an entry's tag word.
  122. */
  123. static inline __be16 *
  124. xfs_dir2_data_entry_tag_p(xfs_dir2_data_entry_t *dep)
  125. {
  126. return (__be16 *)((char *)dep +
  127. xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16));
  128. }
  129. /*
  130. * Pointer to a freespace's tag word.
  131. */
  132. static inline __be16 *
  133. xfs_dir2_data_unused_tag_p(xfs_dir2_data_unused_t *dup)
  134. {
  135. return (__be16 *)((char *)dup +
  136. be16_to_cpu(dup->length) - sizeof(__be16));
  137. }
  138. /*
  139. * Function declarations.
  140. */
  141. #ifdef DEBUG
  142. extern void xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp);
  143. #else
  144. #define xfs_dir2_data_check(dp,bp)
  145. #endif
  146. extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_hdr_t *hdr,
  147. xfs_dir2_data_unused_t *dup, int *loghead);
  148. extern void xfs_dir2_data_freescan(struct xfs_mount *mp,
  149. xfs_dir2_data_hdr_t *hdr, int *loghead);
  150. extern int xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
  151. struct xfs_dabuf **bpp);
  152. extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp,
  153. xfs_dir2_data_entry_t *dep);
  154. extern void xfs_dir2_data_log_header(struct xfs_trans *tp,
  155. struct xfs_dabuf *bp);
  156. extern void xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_dabuf *bp,
  157. xfs_dir2_data_unused_t *dup);
  158. extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
  159. xfs_dir2_data_aoff_t offset,
  160. xfs_dir2_data_aoff_t len, int *needlogp,
  161. int *needscanp);
  162. extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
  163. xfs_dir2_data_unused_t *dup,
  164. xfs_dir2_data_aoff_t offset,
  165. xfs_dir2_data_aoff_t len, int *needlogp,
  166. int *needscanp);
  167. #endif /* __XFS_DIR2_DATA_H__ */