xfs_dir2_data.h 5.8 KB

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