xfs_dir_sf.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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_DIR_SF_H__
  33. #define __XFS_DIR_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. typedef struct { __uint8_t i[sizeof(xfs_ino_t)]; } xfs_dir_ino_t;
  41. /*
  42. * The parent directory has a dedicated field, and the self-pointer must
  43. * be calculated on the fly.
  44. *
  45. * Entries are packed toward the top as tight as possible. The header
  46. * and the elements much be memcpy'd out into a work area to get correct
  47. * alignment for the inode number fields.
  48. */
  49. typedef struct xfs_dir_shortform {
  50. struct xfs_dir_sf_hdr { /* constant-structure header block */
  51. xfs_dir_ino_t parent; /* parent dir inode number */
  52. __uint8_t count; /* count of active entries */
  53. } hdr;
  54. struct xfs_dir_sf_entry {
  55. xfs_dir_ino_t inumber; /* referenced inode number */
  56. __uint8_t namelen; /* actual length of name (no NULL) */
  57. __uint8_t name[1]; /* name */
  58. } list[1]; /* variable sized array */
  59. } xfs_dir_shortform_t;
  60. typedef struct xfs_dir_sf_hdr xfs_dir_sf_hdr_t;
  61. typedef struct xfs_dir_sf_entry xfs_dir_sf_entry_t;
  62. /*
  63. * We generate this then sort it, so that readdirs are returned in
  64. * hash-order. Else seekdir won't work.
  65. */
  66. typedef struct xfs_dir_sf_sort {
  67. __uint8_t entno; /* .=0, ..=1, else entry# + 2 */
  68. __uint8_t seqno; /* sequence # with same hash value */
  69. __uint8_t namelen; /* length of name value (no null) */
  70. xfs_dahash_t hash; /* this entry's hash value */
  71. xfs_intino_t ino; /* this entry's inode number */
  72. char *name; /* name value, pointer into buffer */
  73. } xfs_dir_sf_sort_t;
  74. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_GET_DIRINO)
  75. void xfs_dir_sf_get_dirino(xfs_dir_ino_t *from, xfs_ino_t *to);
  76. #define XFS_DIR_SF_GET_DIRINO(from,to) xfs_dir_sf_get_dirino(from, to)
  77. #else
  78. #define XFS_DIR_SF_GET_DIRINO(from,to) (*(to) = XFS_GET_DIR_INO8(*from))
  79. #endif
  80. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_PUT_DIRINO)
  81. void xfs_dir_sf_put_dirino(xfs_ino_t *from, xfs_dir_ino_t *to);
  82. #define XFS_DIR_SF_PUT_DIRINO(from,to) xfs_dir_sf_put_dirino(from, to)
  83. #else
  84. #define XFS_DIR_SF_PUT_DIRINO(from,to) XFS_PUT_DIR_INO8(*(from), *(to))
  85. #endif
  86. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_ENTSIZE_BYNAME)
  87. int xfs_dir_sf_entsize_byname(int len);
  88. #define XFS_DIR_SF_ENTSIZE_BYNAME(len) xfs_dir_sf_entsize_byname(len)
  89. #else
  90. #define XFS_DIR_SF_ENTSIZE_BYNAME(len) /* space a name uses */ \
  91. ((uint)sizeof(xfs_dir_sf_entry_t)-1 + (len))
  92. #endif
  93. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_ENTSIZE_BYENTRY)
  94. int xfs_dir_sf_entsize_byentry(xfs_dir_sf_entry_t *sfep);
  95. #define XFS_DIR_SF_ENTSIZE_BYENTRY(sfep) xfs_dir_sf_entsize_byentry(sfep)
  96. #else
  97. #define XFS_DIR_SF_ENTSIZE_BYENTRY(sfep) /* space an entry uses */ \
  98. ((uint)sizeof(xfs_dir_sf_entry_t)-1 + (sfep)->namelen)
  99. #endif
  100. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_NEXTENTRY)
  101. xfs_dir_sf_entry_t *xfs_dir_sf_nextentry(xfs_dir_sf_entry_t *sfep);
  102. #define XFS_DIR_SF_NEXTENTRY(sfep) xfs_dir_sf_nextentry(sfep)
  103. #else
  104. #define XFS_DIR_SF_NEXTENTRY(sfep) /* next entry in struct */ \
  105. ((xfs_dir_sf_entry_t *) \
  106. ((char *)(sfep) + XFS_DIR_SF_ENTSIZE_BYENTRY(sfep)))
  107. #endif
  108. #if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR_SF_ALLFIT)
  109. int xfs_dir_sf_allfit(int count, int totallen);
  110. #define XFS_DIR_SF_ALLFIT(count,totallen) \
  111. xfs_dir_sf_allfit(count,totallen)
  112. #else
  113. #define XFS_DIR_SF_ALLFIT(count,totallen) /* will all entries fit? */ \
  114. ((uint)sizeof(xfs_dir_sf_hdr_t) + \
  115. ((uint)sizeof(xfs_dir_sf_entry_t)-1)*(count) + (totallen))
  116. #endif
  117. #if defined(XFS_DIR_TRACE)
  118. /*
  119. * Kernel tracing support for directories.
  120. */
  121. struct uio;
  122. struct xfs_inode;
  123. struct xfs_da_intnode;
  124. struct xfs_dinode;
  125. struct xfs_dir_leafblock;
  126. struct xfs_dir_leaf_entry;
  127. #define XFS_DIR_TRACE_SIZE 4096 /* size of global trace buffer */
  128. extern ktrace_t *xfs_dir_trace_buf;
  129. /*
  130. * Trace record types.
  131. */
  132. #define XFS_DIR_KTRACE_G_DU 1 /* dp, uio */
  133. #define XFS_DIR_KTRACE_G_DUB 2 /* dp, uio, bno */
  134. #define XFS_DIR_KTRACE_G_DUN 3 /* dp, uio, node */
  135. #define XFS_DIR_KTRACE_G_DUL 4 /* dp, uio, leaf */
  136. #define XFS_DIR_KTRACE_G_DUE 5 /* dp, uio, leaf entry */
  137. #define XFS_DIR_KTRACE_G_DUC 6 /* dp, uio, cookie */
  138. void xfs_dir_trace_g_du(char *where, struct xfs_inode *dp, struct uio *uio);
  139. void xfs_dir_trace_g_dub(char *where, struct xfs_inode *dp, struct uio *uio,
  140. xfs_dablk_t bno);
  141. void xfs_dir_trace_g_dun(char *where, struct xfs_inode *dp, struct uio *uio,
  142. struct xfs_da_intnode *node);
  143. void xfs_dir_trace_g_dul(char *where, struct xfs_inode *dp, struct uio *uio,
  144. struct xfs_dir_leafblock *leaf);
  145. void xfs_dir_trace_g_due(char *where, struct xfs_inode *dp, struct uio *uio,
  146. struct xfs_dir_leaf_entry *entry);
  147. void xfs_dir_trace_g_duc(char *where, struct xfs_inode *dp, struct uio *uio,
  148. xfs_off_t cookie);
  149. void xfs_dir_trace_enter(int type, char *where,
  150. void *a0, void *a1, void *a2, void *a3,
  151. void *a4, void *a5, void *a6, void *a7,
  152. void *a8, void *a9, void *a10, void *a11);
  153. #else
  154. #define xfs_dir_trace_g_du(w,d,u)
  155. #define xfs_dir_trace_g_dub(w,d,u,b)
  156. #define xfs_dir_trace_g_dun(w,d,u,n)
  157. #define xfs_dir_trace_g_dul(w,d,u,l)
  158. #define xfs_dir_trace_g_due(w,d,u,e)
  159. #define xfs_dir_trace_g_duc(w,d,u,c)
  160. #endif /* DEBUG */
  161. #endif /* __XFS_DIR_SF_H__ */