xfs_dir2_data.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. #define XFS_DIR2_DATA_ENTSIZE(n) xfs_dir2_data_entsize(n)
  127. static inline int xfs_dir2_data_entsize(int n)
  128. {
  129. return (int)roundup(offsetof(xfs_dir2_data_entry_t, name[0]) + (n) + \
  130. (uint)sizeof(xfs_dir2_data_off_t), XFS_DIR2_DATA_ALIGN);
  131. }
  132. /*
  133. * Pointer to an entry's tag word.
  134. */
  135. #define XFS_DIR2_DATA_ENTRY_TAG_P(dep) xfs_dir2_data_entry_tag_p(dep)
  136. static inline xfs_dir2_data_off_t *
  137. xfs_dir2_data_entry_tag_p(xfs_dir2_data_entry_t *dep)
  138. {
  139. return (xfs_dir2_data_off_t *) \
  140. ((char *)(dep) + XFS_DIR2_DATA_ENTSIZE((dep)->namelen) - \
  141. (uint)sizeof(xfs_dir2_data_off_t));
  142. }
  143. /*
  144. * Pointer to a freespace's tag word.
  145. */
  146. #define XFS_DIR2_DATA_UNUSED_TAG_P(dup) \
  147. xfs_dir2_data_unused_tag_p(dup)
  148. static inline xfs_dir2_data_off_t *
  149. xfs_dir2_data_unused_tag_p(xfs_dir2_data_unused_t *dup)
  150. {
  151. return (xfs_dir2_data_off_t *) \
  152. ((char *)(dup) + INT_GET((dup)->length, ARCH_CONVERT) \
  153. - (uint)sizeof(xfs_dir2_data_off_t));
  154. }
  155. /*
  156. * Function declarations.
  157. */
  158. #ifdef DEBUG
  159. extern void xfs_dir2_data_check(struct xfs_inode *dp, struct xfs_dabuf *bp);
  160. #else
  161. #define xfs_dir2_data_check(dp,bp)
  162. #endif
  163. extern xfs_dir2_data_free_t *xfs_dir2_data_freefind(xfs_dir2_data_t *d,
  164. xfs_dir2_data_unused_t *dup);
  165. extern xfs_dir2_data_free_t *xfs_dir2_data_freeinsert(xfs_dir2_data_t *d,
  166. xfs_dir2_data_unused_t *dup, int *loghead);
  167. extern void xfs_dir2_data_freescan(struct xfs_mount *mp, xfs_dir2_data_t *d,
  168. int *loghead, char *aendp);
  169. extern int xfs_dir2_data_init(struct xfs_da_args *args, xfs_dir2_db_t blkno,
  170. struct xfs_dabuf **bpp);
  171. extern void xfs_dir2_data_log_entry(struct xfs_trans *tp, struct xfs_dabuf *bp,
  172. xfs_dir2_data_entry_t *dep);
  173. extern void xfs_dir2_data_log_header(struct xfs_trans *tp,
  174. struct xfs_dabuf *bp);
  175. extern void xfs_dir2_data_log_unused(struct xfs_trans *tp, struct xfs_dabuf *bp,
  176. xfs_dir2_data_unused_t *dup);
  177. extern void xfs_dir2_data_make_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
  178. xfs_dir2_data_aoff_t offset,
  179. xfs_dir2_data_aoff_t len, int *needlogp,
  180. int *needscanp);
  181. extern void xfs_dir2_data_use_free(struct xfs_trans *tp, struct xfs_dabuf *bp,
  182. xfs_dir2_data_unused_t *dup,
  183. xfs_dir2_data_aoff_t offset,
  184. xfs_dir2_data_aoff_t len, int *needlogp,
  185. int *needscanp);
  186. #endif /* __XFS_DIR2_DATA_H__ */