1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#ifndef __XFS_DIR2_SF_H__
33#define __XFS_DIR2_SF_H__
34
35
36
37
38
39
40
41
42struct uio;
43struct xfs_dabuf;
44struct xfs_da_args;
45struct xfs_dir2_block;
46struct xfs_inode;
47struct xfs_mount;
48struct xfs_trans;
49
50
51
52
53#define XFS_DIR2_SF_MAX_SIZE \
54 (XFS_DINODE_MAX_SIZE - (uint)sizeof(xfs_dinode_core_t) - \
55 (uint)sizeof(xfs_agino_t))
56
57
58
59
60typedef struct { __uint8_t i[8]; } xfs_dir2_ino8_t;
61
62#define XFS_DIR2_SF_GET_INO8_ARCH(di,arch) \
63 (xfs_ino_t)(DIRINO_GET_ARCH(&di,arch))
64#define XFS_DIR2_SF_GET_INO8(di) \
65 XFS_DIR2_SF_GET_INO8_ARCH(di,ARCH_NOCONVERT)
66
67
68
69
70
71
72typedef struct { __uint8_t i[4]; } xfs_dir2_ino4_t;
73#define XFS_DIR2_SF_GET_INO4_ARCH(di,arch) \
74 (xfs_ino_t)(DIRINO4_GET_ARCH(&di,arch))
75#define XFS_DIR2_SF_GET_INO4(di) \
76 XFS_DIR2_SF_GET_INO4_ARCH(di,ARCH_NOCONVERT)
77
78typedef union {
79 xfs_dir2_ino8_t i8;
80 xfs_dir2_ino4_t i4;
81} xfs_dir2_inou_t;
82#define XFS_DIR2_MAX_SHORT_INUM ((xfs_ino_t)0xffffffffULL)
83
84
85
86
87
88typedef struct { __uint8_t i[2]; } xfs_dir2_sf_off_t;
89
90
91
92
93
94
95
96
97
98typedef struct xfs_dir2_sf_hdr {
99 __uint8_t count;
100 __uint8_t i8count;
101 xfs_dir2_inou_t parent;
102} xfs_dir2_sf_hdr_t;
103
104typedef struct xfs_dir2_sf_entry {
105 __uint8_t namelen;
106 xfs_dir2_sf_off_t offset;
107 __uint8_t name[1];
108 xfs_dir2_inou_t inumber;
109} xfs_dir2_sf_entry_t;
110
111typedef struct xfs_dir2_sf {
112 xfs_dir2_sf_hdr_t hdr;
113 xfs_dir2_sf_entry_t list[1];
114} xfs_dir2_sf_t;
115
116#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_HDR_SIZE)
117int xfs_dir2_sf_hdr_size(int i8count);
118#define XFS_DIR2_SF_HDR_SIZE(i8count) xfs_dir2_sf_hdr_size(i8count)
119#else
120#define XFS_DIR2_SF_HDR_SIZE(i8count) \
121 ((uint)sizeof(xfs_dir2_sf_hdr_t) - \
122 ((i8count) == 0) * \
123 ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)))
124#endif
125
126#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_INUMBERP)
127xfs_dir2_inou_t *xfs_dir2_sf_inumberp(xfs_dir2_sf_entry_t *sfep);
128#define XFS_DIR2_SF_INUMBERP(sfep) xfs_dir2_sf_inumberp(sfep)
129#else
130#define XFS_DIR2_SF_INUMBERP(sfep) \
131 ((xfs_dir2_inou_t *)&(sfep)->name[(sfep)->namelen])
132#endif
133
134#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_GET_INUMBER)
135xfs_intino_t xfs_dir2_sf_get_inumber_arch(xfs_dir2_sf_t *sfp, xfs_dir2_inou_t *from,
136 xfs_arch_t arch);
137#define XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, from, arch) \
138 xfs_dir2_sf_get_inumber_arch(sfp, from, arch)
139
140#else
141#define XFS_DIR2_SF_GET_INUMBER_ARCH(sfp, from, arch) \
142 ((sfp)->hdr.i8count == 0 ? \
143 (xfs_intino_t)XFS_DIR2_SF_GET_INO4_ARCH(*(from), arch) : \
144 (xfs_intino_t)XFS_DIR2_SF_GET_INO8_ARCH(*(from), arch))
145#endif
146
147#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_PUT_INUMBER)
148void xfs_dir2_sf_put_inumber_arch(xfs_dir2_sf_t *sfp, xfs_ino_t *from,
149 xfs_dir2_inou_t *to, xfs_arch_t arch);
150#define XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp,from,to,arch) \
151 xfs_dir2_sf_put_inumber_arch(sfp,from,to,arch)
152#else
153#define XFS_DIR2_SF_PUT_INUMBER_ARCH(sfp,from,to,arch) \
154 if ((sfp)->hdr.i8count == 0) { \
155 DIRINO4_COPY_ARCH(from,to,arch); \
156 } else { \
157 DIRINO_COPY_ARCH(from,to,arch); \
158 }
159#endif
160
161#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_GET_OFFSET)
162xfs_dir2_data_aoff_t xfs_dir2_sf_get_offset_arch(xfs_dir2_sf_entry_t *sfep,
163 xfs_arch_t arch);
164xfs_dir2_data_aoff_t xfs_dir2_sf_get_offset(xfs_dir2_sf_entry_t *sfep);
165#define XFS_DIR2_SF_GET_OFFSET_ARCH(sfep,arch) \
166 xfs_dir2_sf_get_offset_arch(sfep,arch)
167#else
168#define XFS_DIR2_SF_GET_OFFSET_ARCH(sfep,arch) \
169 INT_GET_UNALIGNED_16_ARCH(&(sfep)->offset.i,arch)
170#endif
171
172#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_PUT_OFFSET)
173void xfs_dir2_sf_put_offset_arch(xfs_dir2_sf_entry_t *sfep,
174 xfs_dir2_data_aoff_t off, xfs_arch_t arch);
175#define XFS_DIR2_SF_PUT_OFFSET_ARCH(sfep,off,arch) \
176 xfs_dir2_sf_put_offset_arch(sfep,off,arch)
177#else
178#define XFS_DIR2_SF_PUT_OFFSET_ARCH(sfep,off,arch) \
179 INT_SET_UNALIGNED_16_ARCH(&(sfep)->offset.i,off,arch)
180#endif
181
182#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_ENTSIZE_BYNAME)
183int xfs_dir2_sf_entsize_byname(xfs_dir2_sf_t *sfp, int len);
184#define XFS_DIR2_SF_ENTSIZE_BYNAME(sfp,len) \
185 xfs_dir2_sf_entsize_byname(sfp,len)
186#else
187#define XFS_DIR2_SF_ENTSIZE_BYNAME(sfp,len) \
188 ((uint)sizeof(xfs_dir2_sf_entry_t) - 1 + (len) - \
189 ((sfp)->hdr.i8count == 0) * \
190 ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)))
191#endif
192
193#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_ENTSIZE_BYENTRY)
194int xfs_dir2_sf_entsize_byentry(xfs_dir2_sf_t *sfp, xfs_dir2_sf_entry_t *sfep);
195#define XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep) \
196 xfs_dir2_sf_entsize_byentry(sfp,sfep)
197#else
198#define XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep) \
199 ((uint)sizeof(xfs_dir2_sf_entry_t) - 1 + (sfep)->namelen - \
200 ((sfp)->hdr.i8count == 0) * \
201 ((uint)sizeof(xfs_dir2_ino8_t) - (uint)sizeof(xfs_dir2_ino4_t)))
202#endif
203
204#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_FIRSTENTRY)
205xfs_dir2_sf_entry_t *xfs_dir2_sf_firstentry(xfs_dir2_sf_t *sfp);
206#define XFS_DIR2_SF_FIRSTENTRY(sfp) xfs_dir2_sf_firstentry(sfp)
207#else
208#define XFS_DIR2_SF_FIRSTENTRY(sfp) \
209 ((xfs_dir2_sf_entry_t *) \
210 ((char *)(sfp) + XFS_DIR2_SF_HDR_SIZE(sfp->hdr.i8count)))
211#endif
212
213#if XFS_WANT_FUNCS || (XFS_WANT_SPACE && XFSSO_XFS_DIR2_SF_NEXTENTRY)
214xfs_dir2_sf_entry_t *xfs_dir2_sf_nextentry(xfs_dir2_sf_t *sfp,
215 xfs_dir2_sf_entry_t *sfep);
216#define XFS_DIR2_SF_NEXTENTRY(sfp,sfep) xfs_dir2_sf_nextentry(sfp,sfep)
217#else
218#define XFS_DIR2_SF_NEXTENTRY(sfp,sfep) \
219 ((xfs_dir2_sf_entry_t *) \
220 ((char *)(sfep) + XFS_DIR2_SF_ENTSIZE_BYENTRY(sfp,sfep)))
221#endif
222
223
224
225
226
227extern int
228 xfs_dir2_block_sfsize(struct xfs_inode *dp,
229 struct xfs_dir2_block *block,
230 xfs_dir2_sf_hdr_t *sfhp);
231
232extern int
233 xfs_dir2_block_to_sf(struct xfs_da_args *args, struct xfs_dabuf *bp,
234 int size, xfs_dir2_sf_hdr_t *sfhp);
235
236extern int
237 xfs_dir2_sf_addname(struct xfs_da_args *args);
238
239extern int
240 xfs_dir2_sf_create(struct xfs_da_args *args, xfs_ino_t pino);
241
242extern int
243 xfs_dir2_sf_getdents(struct xfs_inode *dp, struct uio *uio, int *eofp,
244 struct xfs_dirent *dbp, xfs_dir2_put_t put);
245
246extern int
247 xfs_dir2_sf_lookup(struct xfs_da_args *args);
248
249extern int
250 xfs_dir2_sf_removename(struct xfs_da_args *args);
251
252extern int
253 xfs_dir2_sf_replace(struct xfs_da_args *args);
254
255#endif
256