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