xfs_dir.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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_H__
  19. #define __XFS_DIR_H__
  20. /*
  21. * Large directories are structured around Btrees where all the data
  22. * elements are in the leaf nodes. Filenames are hashed into an int,
  23. * then that int is used as the index into the Btree. Since the hashval
  24. * of a filename may not be unique, we may have duplicate keys. The
  25. * internal links in the Btree are logical block offsets into the file.
  26. *
  27. * Small directories use a different format and are packed as tightly
  28. * as possible so as to fit into the literal area of the inode.
  29. */
  30. /*========================================================================
  31. * Function prototypes for the kernel.
  32. *========================================================================*/
  33. struct uio;
  34. struct xfs_bmap_free;
  35. struct xfs_da_args;
  36. struct xfs_dinode;
  37. struct xfs_inode;
  38. struct xfs_mount;
  39. struct xfs_trans;
  40. /*
  41. * Directory function types.
  42. * Put in structures (xfs_dirops_t) for v1 and v2 directories.
  43. */
  44. typedef void (*xfs_dir_mount_t)(struct xfs_mount *mp);
  45. typedef int (*xfs_dir_isempty_t)(struct xfs_inode *dp);
  46. typedef int (*xfs_dir_init_t)(struct xfs_trans *tp,
  47. struct xfs_inode *dp,
  48. struct xfs_inode *pdp);
  49. typedef int (*xfs_dir_createname_t)(struct xfs_trans *tp,
  50. struct xfs_inode *dp,
  51. char *name,
  52. int namelen,
  53. xfs_ino_t inum,
  54. xfs_fsblock_t *first,
  55. struct xfs_bmap_free *flist,
  56. xfs_extlen_t total);
  57. typedef int (*xfs_dir_lookup_t)(struct xfs_trans *tp,
  58. struct xfs_inode *dp,
  59. char *name,
  60. int namelen,
  61. xfs_ino_t *inum);
  62. typedef int (*xfs_dir_removename_t)(struct xfs_trans *tp,
  63. struct xfs_inode *dp,
  64. char *name,
  65. int namelen,
  66. xfs_ino_t ino,
  67. xfs_fsblock_t *first,
  68. struct xfs_bmap_free *flist,
  69. xfs_extlen_t total);
  70. typedef int (*xfs_dir_getdents_t)(struct xfs_trans *tp,
  71. struct xfs_inode *dp,
  72. struct uio *uio,
  73. int *eofp);
  74. typedef int (*xfs_dir_replace_t)(struct xfs_trans *tp,
  75. struct xfs_inode *dp,
  76. char *name,
  77. int namelen,
  78. xfs_ino_t inum,
  79. xfs_fsblock_t *first,
  80. struct xfs_bmap_free *flist,
  81. xfs_extlen_t total);
  82. typedef int (*xfs_dir_canenter_t)(struct xfs_trans *tp,
  83. struct xfs_inode *dp,
  84. char *name,
  85. int namelen);
  86. typedef int (*xfs_dir_shortform_validate_ondisk_t)(struct xfs_mount *mp,
  87. struct xfs_dinode *dip);
  88. typedef int (*xfs_dir_shortform_to_single_t)(struct xfs_da_args *args);
  89. typedef struct xfs_dirops {
  90. xfs_dir_mount_t xd_mount;
  91. xfs_dir_isempty_t xd_isempty;
  92. xfs_dir_init_t xd_init;
  93. xfs_dir_createname_t xd_createname;
  94. xfs_dir_lookup_t xd_lookup;
  95. xfs_dir_removename_t xd_removename;
  96. xfs_dir_getdents_t xd_getdents;
  97. xfs_dir_replace_t xd_replace;
  98. xfs_dir_canenter_t xd_canenter;
  99. xfs_dir_shortform_validate_ondisk_t xd_shortform_validate_ondisk;
  100. xfs_dir_shortform_to_single_t xd_shortform_to_single;
  101. } xfs_dirops_t;
  102. /*
  103. * Overall external interface routines.
  104. */
  105. void xfs_dir_startup(void); /* called exactly once */
  106. #define XFS_DIR_MOUNT(mp) \
  107. ((mp)->m_dirops.xd_mount(mp))
  108. #define XFS_DIR_ISEMPTY(mp,dp) \
  109. ((mp)->m_dirops.xd_isempty(dp))
  110. #define XFS_DIR_INIT(mp,tp,dp,pdp) \
  111. ((mp)->m_dirops.xd_init(tp,dp,pdp))
  112. #define XFS_DIR_CREATENAME(mp,tp,dp,name,namelen,inum,first,flist,total) \
  113. ((mp)->m_dirops.xd_createname(tp,dp,name,namelen,inum,first,flist,\
  114. total))
  115. #define XFS_DIR_LOOKUP(mp,tp,dp,name,namelen,inum) \
  116. ((mp)->m_dirops.xd_lookup(tp,dp,name,namelen,inum))
  117. #define XFS_DIR_REMOVENAME(mp,tp,dp,name,namelen,ino,first,flist,total) \
  118. ((mp)->m_dirops.xd_removename(tp,dp,name,namelen,ino,first,flist,total))
  119. #define XFS_DIR_GETDENTS(mp,tp,dp,uio,eofp) \
  120. ((mp)->m_dirops.xd_getdents(tp,dp,uio,eofp))
  121. #define XFS_DIR_REPLACE(mp,tp,dp,name,namelen,inum,first,flist,total) \
  122. ((mp)->m_dirops.xd_replace(tp,dp,name,namelen,inum,first,flist,total))
  123. #define XFS_DIR_CANENTER(mp,tp,dp,name,namelen) \
  124. ((mp)->m_dirops.xd_canenter(tp,dp,name,namelen))
  125. #define XFS_DIR_SHORTFORM_VALIDATE_ONDISK(mp,dip) \
  126. ((mp)->m_dirops.xd_shortform_validate_ondisk(mp,dip))
  127. #define XFS_DIR_SHORTFORM_TO_SINGLE(mp,args) \
  128. ((mp)->m_dirops.xd_shortform_to_single(args))
  129. #define XFS_DIR_IS_V1(mp) ((mp)->m_dirversion == 1)
  130. #define XFS_DIR_IS_V2(mp) ((mp)->m_dirversion == 2)
  131. extern xfs_dirops_t xfsv1_dirops;
  132. extern xfs_dirops_t xfsv2_dirops;
  133. #endif /* __XFS_DIR_H__ */