xfs_dir2_sf.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright (c) 2000-2001 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_SF_H__
  33. #define __XFS_DIR2_SF_H__
  34. /*
  35. * Directory layout when stored internal to an inode.
  36. *
  37. * Small directories are packed as tightly as possible so as to
  38. * fit into the literal area of the inode.
  39. */
  40. struct uio;
  41. struct xfs_dabuf;
  42. struct xfs_da_args;
  43. struct xfs_dir2_block;
  44. struct xfs_inode;
  45. struct xfs_mount;
  46. struct xfs_trans;
  47. /*
  48. * Maximum size of a shortform directory.
  49. */
  50. #define XFS_DIR2_SF_MAX_SIZE \
  51. (XFS_DINODE_MAX_SIZE - (uint)sizeof(xfs_dinode_core_t) - \
  52. (uint)sizeof(xfs_agino_t))
  53. /*
  54. * Inode number stored as 8 8-bit values.
  55. */
  56. typedef struct { __uint8_t i[8]; } xfs_dir2_ino8_t;
  57. /*
  58. * Inode number stored as 4 8-bit values.
  59. * Works a lot of the time, when all the inode numbers in a directory
  60. * fit in 32 bits.
  61. */
  62. typedef struct { __uint8_t i[4]; } xfs_dir2_ino4_t;
  63. typedef union {
  64. xfs_dir2_ino8_t i8;
  65. xfs_dir2_ino4_t i4;
  66. } xfs_dir2_inou_t;
  67. #define XFS_DIR2_MAX_SHORT_INUM ((xfs_ino_t)0xffffffffULL)
  68. /*
  69. * Normalized offset (in a data block) of the entry, really xfs_dir2_data_off_t.
  70. * Only need 16 bits, this is the byte offset into the single block form.
  71. */
  72. typedef struct { __uint8_t i[2]; } xfs_dir2_sf_off_t;
  73. /*
  74. * The parent directory has a dedicated field, and the self-pointer must
  75. * be calculated on the fly.
  76. *
  77. * Entries are packed toward the top as tightly as possible. The header
  78. * and the elements must be memcpy'd out into a work area to get correct
  79. * alignment for the inode number fields.
  80. */
  81. typedef struct xfs_dir2_sf_hdr {
  82. __uint8_t count; /* count of entries */
  83. __uint8_t i8count; /* count of 8-byte inode #s */
  84. xfs_dir2_inou_t parent; /* parent dir inode number */
  85. } xfs_dir2_sf_hdr_t;
  86. typedef struct xfs_dir2_sf_entry {
  87. __uint8_t namelen; /* actual name length */
  88. xfs_dir2_sf_off_t offset; /* saved offset */
  89. __uint8_t name[1]; /* name, variable size */
  90. xfs_dir2_inou_t inumber; /* inode number, var. offset */
  91. } xfs_dir2_sf_entry_t;
  92. typedef struct xfs_dir2_sf {
  93. xfs_dir2_sf_hdr_t hdr; /* shortform header */
  94. xfs_dir2_sf_entry_t list[1]; /* shortform entries */
  95. } xfs_dir2_sf_t;
  96. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_HDR_SIZE)
  97. int xfs_dir2_sf_hdr_size(int i8count);
  98. #define XFS_DIR2_SF_HDR_SIZE(i8count) xfs_dir2_sf_hdr_size(i8count)
  99. #else
  100. #define XFS_DIR2_SF_HDR_SIZE(i8count) \
  101. ((uint)sizeof(xfs_dir2_sf_hdr_t) - \
  102. ((i8count) == 0) * \
  103. ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)))
  104. #endif
  105. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_INUMBERP)
  106. xfs_dir2_inou_t *xfs_dir2_sf_inumberp(xfs_dir2_sf_entry_t *sfep);
  107. #define XFS_DIR2_SF_INUMBERP(sfep) xfs_dir2_sf_inumberp(sfep)
  108. #else
  109. #define XFS_DIR2_SF_INUMBERP(sfep) \
  110. ((xfs_dir2_inou_t *)&(sfep)->name[(sfep)->namelen])
  111. #endif
  112. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_GET_INUMBER)
  113. xfs_intino_t xfs_dir2_sf_get_inumber(xfs_dir2_sf_t *sfp, xfs_dir2_inou_t *from);
  114. #define XFS_DIR2_SF_GET_INUMBER(sfp, from) \
  115. xfs_dir2_sf_get_inumber(sfp, from)
  116. #else
  117. #define XFS_DIR2_SF_GET_INUMBER(sfp, from) \
  118. ((sfp)->hdr.i8count == 0 ? \
  119. (xfs_intino_t)XFS_GET_DIR_INO4((from)->i4) : \
  120. (xfs_intino_t)XFS_GET_DIR_INO8((from)->i8))
  121. #endif
  122. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_PUT_INUMBER)
  123. void xfs_dir2_sf_put_inumber(xfs_dir2_sf_t *sfp, xfs_ino_t *from,
  124. xfs_dir2_inou_t *to);
  125. #define XFS_DIR2_SF_PUT_INUMBER(sfp,from,to) \
  126. xfs_dir2_sf_put_inumber(sfp,from,to)
  127. #else
  128. #define XFS_DIR2_SF_PUT_INUMBER(sfp,from,to) \
  129. if ((sfp)->hdr.i8count == 0) { \
  130. XFS_PUT_DIR_INO4(*(from), (to)->i4); \
  131. } else { \
  132. XFS_PUT_DIR_INO8(*(from), (to)->i8); \
  133. }
  134. #endif
  135. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_GET_OFFSET)
  136. xfs_dir2_data_aoff_t xfs_dir2_sf_get_offset(xfs_dir2_sf_entry_t *sfep);
  137. #define XFS_DIR2_SF_GET_OFFSET(sfep) \
  138. xfs_dir2_sf_get_offset(sfep)
  139. #else
  140. #define XFS_DIR2_SF_GET_OFFSET(sfep) \
  141. INT_GET_UNALIGNED_16_BE(&(sfep)->offset.i)
  142. #endif
  143. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_PUT_OFFSET)
  144. void xfs_dir2_sf_put_offset(xfs_dir2_sf_entry_t *sfep,
  145. xfs_dir2_data_aoff_t off);
  146. #define XFS_DIR2_SF_PUT_OFFSET(sfep,off) \
  147. xfs_dir2_sf_put_offset(sfep,off)
  148. #else
  149. #define XFS_DIR2_SF_PUT_OFFSET(sfep,off) \
  150. INT_SET_UNALIGNED_16_BE(&(sfep)->offset.i,off)
  151. #endif
  152. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_ENTSIZE_BYNAME)
  153. int xfs_dir2_sf_entsize_byname(xfs_dir2_sf_t *sfp, int len);
  154. #define XFS_DIR2_SF_ENTSIZE_BYNAME(sfp,len) \
  155. xfs_dir2_sf_entsize_byname(sfp,len)
  156. #else
  157. #define XFS_DIR2_SF_ENTSIZE_BYNAME(sfp,len) /* space a name uses */ \
  158. ((uint)sizeof(xfs_dir2_sf_entry_t) - 1 + (len) - \
  159. ((sfp)->hdr.i8count == 0) * \
  160. ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)))
  161. #endif
  162. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_ENTSIZE_BYENTRY)
  163. int xfs_dir2_sf_entsize_byentry(xfs_dir2_sf_t *sfp, xfs_dir2_sf_entry_t *sfep);
  164. #define XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep) \
  165. xfs_dir2_sf_entsize_byentry(sfp,sfep)
  166. #else
  167. #define XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep) /* space an entry uses */ \
  168. ((uint)sizeof(xfs_dir2_sf_entry_t) - 1 + (sfep)->namelen - \
  169. ((sfp)->hdr.i8count == 0) * \
  170. ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)))
  171. #endif
  172. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_FIRSTENTRY)
  173. xfs_dir2_sf_entry_t *xfs_dir2_sf_firstentry(xfs_dir2_sf_t *sfp);
  174. #define XFS_DIR2_SF_FIRSTENTRY(sfp) xfs_dir2_sf_firstentry(sfp)
  175. #else
  176. #define XFS_DIR2_SF_FIRSTENTRY(sfp) /* first entry in struct */ \
  177. ((xfs_dir2_sf_entry_t *) \
  178. ((char *)(sfp) + XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count)))
  179. #endif
  180. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_NEXTENTRY)
  181. xfs_dir2_sf_entry_t *xfs_dir2_sf_nextentry(xfs_dir2_sf_t *sfp,
  182. xfs_dir2_sf_entry_t *sfep);
  183. #define XFS_DIR2_SF_NEXTENTRY(sfp,sfep) xfs_dir2_sf_nextentry(sfp,sfep)
  184. #else
  185. #define XFS_DIR2_SF_NEXTENTRY(sfp,sfep) /* next entry in struct */ \
  186. ((xfs_dir2_sf_entry_t *) \
  187. ((char *)(sfep) + XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep)))
  188. #endif
  189. /*
  190. * Functions.
  191. */
  192. extern int
  193. xfs_dir2_block_sfsize(struct xfs_inode *dp,
  194. struct xfs_dir2_block *block,
  195. xfs_dir2_sf_hdr_t *sfhp);
  196. extern int
  197. xfs_dir2_block_to_sf(struct xfs_da_args *args, struct xfs_dabuf *bp,
  198. int size, xfs_dir2_sf_hdr_t *sfhp);
  199. extern int
  200. xfs_dir2_sf_addname(struct xfs_da_args *args);
  201. extern int
  202. xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);
  203. extern int
  204. xfs_dir2_sf_getdents(struct xfs_inode *dp, struct uio *uio, int *eofp,
  205. struct xfs_dirent *dbp, xfs_dir2_put_t put);
  206. extern int
  207. xfs_dir2_sf_lookup(struct xfs_da_args *args);
  208. extern int
  209. xfs_dir2_sf_removename(struct xfs_da_args *args);
  210. extern int
  211. xfs_dir2_sf_replace(struct xfs_da_args *args);
  212. #endif /* __XFS_DIR2_SF_H__ */