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