xfs_dir2_data.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. __be16 offset; /* start of freespace */
  62. __be16 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. __be32 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. __be64 inumber; /* inode number */
  80. __u8 namelen; /* name length */
  81. __u8 name[1]; /* name bytes, no null */
  82. /* variable offset */
  83. __be16 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. __be16 freetag; /* XFS_DIR2_DATA_FREE_TAG */
  91. __be16 length; /* total free length */
  92. /* variable offset */
  93. __be16 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 __be16 *
  123. xfs_dir2_data_entry_tag_p(xfs_dir2_data_entry_t *dep)
  124. {
  125. return (__be16 *)((char *)dep +
  126. XFS_DIR2_DATA_ENTSIZE(dep->namelen) - sizeof(__be16));
  127. }
  128. /*
  129. * Pointer to a freespace's tag word.
  130. */
  131. #define XFS_DIR2_DATA_UNUSED_TAG_P(dup) \
  132. xfs_dir2_data_unused_tag_p(dup)
  133. static inline __be16 *
  134. xfs_dir2_data_unused_tag_p(xfs_dir2_data_unused_t *dup)
  135. {
  136. return (__be16 *)((char *)dup +
  137. be16_to_cpu(dup->length) - sizeof(__be16));
  138. }
  139. /*
  140. * Function declarations.
  141. */
  142. #ifdef DEBUG
  143. extern void xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp);
  144. #else
  145. #define xfs_dir2_data_check(dp,bp)
  146. #endif
  147. extern xfs_dir2_data_free_t *xfs_dir2_data_freefind(xfs_dir2_data_t *d,
  148. xfs_dir2_data_unused_t *dup);
  149. extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_t *d,
  150. xfs_dir2_data_unused_t *dup, int *loghead);
  151. extern void xfs_dir2_data_freescan(struct xfs_mount *mp, xfs_dir2_data_t *d,
  152. int *loghead, char *aendp);
  153. extern int xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
  154. struct xfs_dabuf **bpp);
  155. extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp,
  156. xfs_dir2_data_entry_t *dep);
  157. extern void xfs_dir2_data_log_header(struct xfs_trans *tp,
  158. struct xfs_dabuf *bp);
  159. extern void xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_dabuf *bp,
  160. xfs_dir2_data_unused_t *dup);
  161. extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
  162. xfs_dir2_data_aoff_t offset,
  163. xfs_dir2_data_aoff_t len, int *needlogp,
  164. int *needscanp);
  165. extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
  166. xfs_dir2_data_unused_t *dup,
  167. xfs_dir2_data_aoff_t offset,
  168. xfs_dir2_data_aoff_t len, int *needlogp,
  169. int *needscanp);
  170. #endif /* __XFS_DIR2_DATA_H__ */