xfs_dir2_data.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*
  2. * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of version 2 of the GNU General Public License as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it would be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. *
  12. * Further, this software is distributed without any warranty that it is
  13. * free of the rightful claim of any third person regarding infringement
  14. * or the like. Any license provided herein, whether implied or
  15. * otherwise, applies only to this software file. Patent licenses, if
  16. * any, provided herein do not apply to combinations of this program with
  17. * other software, or any other product whatsoever.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write the Free Software Foundation, Inc., 59
  21. * Temple Place - Suite 330, Boston MA 02111-1307, USA.
  22. *
  23. * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  24. * Mountain View, CA 94043, or:
  25. *
  26. * http://www.sgi.com
  27. *
  28. * For further information regarding this notice, see:
  29. *
  30. * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
  31. */
  32. #ifndef __XFS_DIR2_DATA_H__
  33. #define __XFS_DIR2_DATA_H__
  34. /*
  35. * Directory format 2, data block structures.
  36. */
  37. struct xfs_dabuf;
  38. struct xfs_da_args;
  39. struct xfs_inode;
  40. struct xfs_trans;
  41. /*
  42. * Constants.
  43. */
  44. #define XFS_DIR2_DATA_MAGIC 0x58443244 /* XD2D: for multiblock dirs */
  45. #define XFS_DIR2_DATA_ALIGN_LOG 3 /* i.e., 8 bytes */
  46. #define XFS_DIR2_DATA_ALIGN (1 << XFS_DIR2_DATA_ALIGN_LOG)
  47. #define XFS_DIR2_DATA_FREE_TAG 0xffff
  48. #define XFS_DIR2_DATA_FD_COUNT 3
  49. /*
  50. * Directory address space divided into sections,
  51. * spaces separated by 32gb.
  52. */
  53. #define XFS_DIR2_SPACE_SIZE (1ULL << (32 + XFS_DIR2_DATA_ALIGN_LOG))
  54. #define XFS_DIR2_DATA_SPACE 0
  55. #define XFS_DIR2_DATA_OFFSET (XFS_DIR2_DATA_SPACE * XFS_DIR2_SPACE_SIZE)
  56. #define XFS_DIR2_DATA_FIRSTDB(mp) \
  57. XFS_DIR2_BYTE_TO_DB(mp, XFS_DIR2_DATA_OFFSET)
  58. /*
  59. * Offsets of . and .. in data space (always block 0)
  60. */
  61. #define XFS_DIR2_DATA_DOT_OFFSET \
  62. ((xfs_dir2_data_aoff_t)sizeof(xfs_dir2_data_hdr_t))
  63. #define XFS_DIR2_DATA_DOTDOT_OFFSET \
  64. (XFS_DIR2_DATA_DOT_OFFSET + XFS_DIR2_DATA_ENTSIZE(1))
  65. #define XFS_DIR2_DATA_FIRST_OFFSET \
  66. (XFS_DIR2_DATA_DOTDOT_OFFSET + XFS_DIR2_DATA_ENTSIZE(2))
  67. /*
  68. * Structures.
  69. */
  70. /*
  71. * Describe a free area in the data block.
  72. * The freespace will be formatted as a xfs_dir2_data_unused_t.
  73. */
  74. typedef struct xfs_dir2_data_free {
  75. xfs_dir2_data_off_t offset; /* start of freespace */
  76. xfs_dir2_data_off_t length; /* length of freespace */
  77. } xfs_dir2_data_free_t;
  78. /*
  79. * Header for the data blocks.
  80. * Always at the beginning of a directory-sized block.
  81. * The code knows that XFS_DIR2_DATA_FD_COUNT is 3.
  82. */
  83. typedef struct xfs_dir2_data_hdr {
  84. __uint32_t magic; /* XFS_DIR2_DATA_MAGIC */
  85. /* or XFS_DIR2_BLOCK_MAGIC */
  86. xfs_dir2_data_free_t bestfree[XFS_DIR2_DATA_FD_COUNT];
  87. } xfs_dir2_data_hdr_t;
  88. /*
  89. * Active entry in a data block. Aligned to 8 bytes.
  90. * Tag appears as the last 2 bytes.
  91. */
  92. typedef struct xfs_dir2_data_entry {
  93. xfs_ino_t inumber; /* inode number */
  94. __uint8_t namelen; /* name length */
  95. __uint8_t name[1]; /* name bytes, no null */
  96. /* variable offset */
  97. xfs_dir2_data_off_t tag; /* starting offset of us */
  98. } xfs_dir2_data_entry_t;
  99. /*
  100. * Unused entry in a data block. Aligned to 8 bytes.
  101. * Tag appears as the last 2 bytes.
  102. */
  103. typedef struct xfs_dir2_data_unused {
  104. __uint16_t freetag; /* XFS_DIR2_DATA_FREE_TAG */
  105. xfs_dir2_data_off_t length; /* total free length */
  106. /* variable offset */
  107. xfs_dir2_data_off_t tag; /* starting offset of us */
  108. } xfs_dir2_data_unused_t;
  109. typedef union {
  110. xfs_dir2_data_entry_t entry;
  111. xfs_dir2_data_unused_t unused;
  112. } xfs_dir2_data_union_t;
  113. /*
  114. * Generic data block structure, for xfs_db.
  115. */
  116. typedef struct xfs_dir2_data {
  117. xfs_dir2_data_hdr_t hdr; /* magic XFS_DIR2_DATA_MAGIC */
  118. xfs_dir2_data_union_t u[1];
  119. } xfs_dir2_data_t;
  120. /*
  121. * Macros.
  122. */
  123. /*
  124. * Size of a data entry.
  125. */
  126. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATA_ENTSIZE)
  127. int xfs_dir2_data_entsize(int n);
  128. #define XFS_DIR2_DATA_ENTSIZE(n) xfs_dir2_data_entsize(n)
  129. #else
  130. #define XFS_DIR2_DATA_ENTSIZE(n) \
  131. ((int)(roundup(offsetof(xfs_dir2_data_entry_t, name[0]) + (n) + \
  132. (uint)sizeof(xfs_dir2_data_off_t), XFS_DIR2_DATA_ALIGN)))
  133. #endif
  134. /*
  135. * Pointer to an entry's tag word.
  136. */
  137. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATA_ENTRY_TAG_P)
  138. xfs_dir2_data_off_t *xfs_dir2_data_entry_tag_p(xfs_dir2_data_entry_t *dep);
  139. #define XFS_DIR2_DATA_ENTRY_TAG_P(dep) xfs_dir2_data_entry_tag_p(dep)
  140. #else
  141. #define XFS_DIR2_DATA_ENTRY_TAG_P(dep) \
  142. ((xfs_dir2_data_off_t *)\
  143. ((char *)(dep) + XFS_DIR2_DATA_ENTSIZE((dep)->namelen) - \
  144. (uint)sizeof(xfs_dir2_data_off_t)))
  145. #endif
  146. /*
  147. * Pointer to a freespace's tag word.
  148. */
  149. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_DATA_UNUSED_TAG_P)
  150. xfs_dir2_data_off_t *xfs_dir2_data_unused_tag_p(xfs_dir2_data_unused_t *dup);
  151. #define XFS_DIR2_DATA_UNUSED_TAG_P(dup) \
  152. xfs_dir2_data_unused_tag_p(dup)
  153. #else
  154. #define XFS_DIR2_DATA_UNUSED_TAG_P(dup) \
  155. ((xfs_dir2_data_off_t *)\
  156. ((char *)(dup) + INT_GET((dup)->length, ARCH_CONVERT) \
  157. - (uint)sizeof(xfs_dir2_data_off_t)))
  158. #endif
  159. /*
  160. * Function declarations.
  161. */
  162. #ifdef DEBUG
  163. extern void
  164. xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp);
  165. #else
  166. #define xfs_dir2_data_check(dp,bp)
  167. #endif
  168. extern xfs_dir2_data_free_t *
  169. xfs_dir2_data_freefind(xfs_dir2_data_t *d,
  170. xfs_dir2_data_unused_t *dup);
  171. extern xfs_dir2_data_free_t *
  172. xfs_dir2_data_freeinsert(xfs_dir2_data_t *d,
  173. xfs_dir2_data_unused_t *dup, int *loghead);
  174. extern void
  175. xfs_dir2_data_freescan(struct xfs_mount *mp, xfs_dir2_data_t *d,
  176. int *loghead, char *aendp);
  177. extern int
  178. xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
  179. struct xfs_dabuf **bpp);
  180. extern void
  181. xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp,
  182. xfs_dir2_data_entry_t *dep);
  183. extern void
  184. xfs_dir2_data_log_header(struct xfs_trans *tp, struct xfs_dabuf *bp);
  185. extern void
  186. xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_dabuf *bp,
  187. xfs_dir2_data_unused_t *dup);
  188. extern void
  189. xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
  190. xfs_dir2_data_aoff_t offset,
  191. xfs_dir2_data_aoff_t len, int *needlogp,
  192. int *needscanp);
  193. extern void
  194. xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
  195. xfs_dir2_data_unused_t *dup,
  196. xfs_dir2_data_aoff_t offset,
  197. xfs_dir2_data_aoff_t len, int *needlogp,
  198. int *needscanp);
  199. #endif /* __XFS_DIR2_DATA_H__ */