xfs_dir_sf.h 5.2 KB

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