lfs_rename.c revision 1.7.6.2 1 1.7.6.2 tls /* $NetBSD: lfs_rename.c,v 1.7.6.2 2014/08/20 00:04:44 tls Exp $ */
2 1.7.6.2 tls /* from NetBSD: ufs_rename.c,v 1.6 2013/01/22 09:39:18 dholland Exp */
3 1.7.6.2 tls
4 1.7.6.2 tls /*-
5 1.7.6.2 tls * Copyright (c) 2012 The NetBSD Foundation, Inc.
6 1.7.6.2 tls * All rights reserved.
7 1.7.6.2 tls *
8 1.7.6.2 tls * This code is derived from software contributed to The NetBSD Foundation
9 1.7.6.2 tls * by Taylor R Campbell.
10 1.7.6.2 tls *
11 1.7.6.2 tls * Redistribution and use in source and binary forms, with or without
12 1.7.6.2 tls * modification, are permitted provided that the following conditions
13 1.7.6.2 tls * are met:
14 1.7.6.2 tls * 1. Redistributions of source code must retain the above copyright
15 1.7.6.2 tls * notice, this list of conditions and the following disclaimer.
16 1.7.6.2 tls * 2. Redistributions in binary form must reproduce the above copyright
17 1.7.6.2 tls * notice, this list of conditions and the following disclaimer in the
18 1.7.6.2 tls * documentation and/or other materials provided with the distribution.
19 1.7.6.2 tls *
20 1.7.6.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.7.6.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.7.6.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.7.6.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.7.6.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.7.6.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.7.6.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.7.6.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.7.6.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.7.6.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.7.6.2 tls * POSSIBILITY OF SUCH DAMAGE.
31 1.7.6.2 tls */
32 1.7.6.2 tls /*-
33 1.7.6.2 tls * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
34 1.7.6.2 tls * All rights reserved.
35 1.7.6.2 tls *
36 1.7.6.2 tls * This code is derived from software contributed to The NetBSD Foundation
37 1.7.6.2 tls * by Konrad E. Schroder <perseant (at) hhhh.org>.
38 1.7.6.2 tls *
39 1.7.6.2 tls * Redistribution and use in source and binary forms, with or without
40 1.7.6.2 tls * modification, are permitted provided that the following conditions
41 1.7.6.2 tls * are met:
42 1.7.6.2 tls * 1. Redistributions of source code must retain the above copyright
43 1.7.6.2 tls * notice, this list of conditions and the following disclaimer.
44 1.7.6.2 tls * 2. Redistributions in binary form must reproduce the above copyright
45 1.7.6.2 tls * notice, this list of conditions and the following disclaimer in the
46 1.7.6.2 tls * documentation and/or other materials provided with the distribution.
47 1.7.6.2 tls *
48 1.7.6.2 tls * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
49 1.7.6.2 tls * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
50 1.7.6.2 tls * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
51 1.7.6.2 tls * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
52 1.7.6.2 tls * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
53 1.7.6.2 tls * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 1.7.6.2 tls * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 1.7.6.2 tls * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
56 1.7.6.2 tls * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 1.7.6.2 tls * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
58 1.7.6.2 tls * POSSIBILITY OF SUCH DAMAGE.
59 1.7.6.2 tls */
60 1.7.6.2 tls /*
61 1.7.6.2 tls * Copyright (c) 1986, 1989, 1991, 1993, 1995
62 1.7.6.2 tls * The Regents of the University of California. All rights reserved.
63 1.7.6.2 tls *
64 1.7.6.2 tls * Redistribution and use in source and binary forms, with or without
65 1.7.6.2 tls * modification, are permitted provided that the following conditions
66 1.7.6.2 tls * are met:
67 1.7.6.2 tls * 1. Redistributions of source code must retain the above copyright
68 1.7.6.2 tls * notice, this list of conditions and the following disclaimer.
69 1.7.6.2 tls * 2. Redistributions in binary form must reproduce the above copyright
70 1.7.6.2 tls * notice, this list of conditions and the following disclaimer in the
71 1.7.6.2 tls * documentation and/or other materials provided with the distribution.
72 1.7.6.2 tls * 3. Neither the name of the University nor the names of its contributors
73 1.7.6.2 tls * may be used to endorse or promote products derived from this software
74 1.7.6.2 tls * without specific prior written permission.
75 1.7.6.2 tls *
76 1.7.6.2 tls * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
77 1.7.6.2 tls * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
78 1.7.6.2 tls * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
79 1.7.6.2 tls * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
80 1.7.6.2 tls * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
81 1.7.6.2 tls * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
82 1.7.6.2 tls * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
83 1.7.6.2 tls * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
84 1.7.6.2 tls * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
85 1.7.6.2 tls * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
86 1.7.6.2 tls * SUCH DAMAGE.
87 1.7.6.2 tls *
88 1.7.6.2 tls * @(#)lfs_vnops.c 8.13 (Berkeley) 6/10/95
89 1.7.6.2 tls */
90 1.7.6.2 tls
91 1.7.6.2 tls #include <sys/cdefs.h>
92 1.7.6.2 tls __KERNEL_RCSID(0, "$NetBSD: lfs_rename.c,v 1.7.6.2 2014/08/20 00:04:44 tls Exp $");
93 1.7.6.2 tls
94 1.7.6.2 tls #include <sys/param.h>
95 1.7.6.2 tls #include <sys/systm.h>
96 1.7.6.2 tls #include <sys/errno.h>
97 1.7.6.2 tls #include <sys/namei.h>
98 1.7.6.2 tls #include <sys/resourcevar.h>
99 1.7.6.2 tls #include <sys/kernel.h>
100 1.7.6.2 tls #include <sys/file.h>
101 1.7.6.2 tls #include <sys/stat.h>
102 1.7.6.2 tls #include <sys/buf.h>
103 1.7.6.2 tls #include <sys/proc.h>
104 1.7.6.2 tls #include <sys/mount.h>
105 1.7.6.2 tls #include <sys/vnode.h>
106 1.7.6.2 tls #include <sys/vnode_if.h>
107 1.7.6.2 tls #include <sys/pool.h>
108 1.7.6.2 tls #include <sys/signalvar.h>
109 1.7.6.2 tls #include <sys/kauth.h>
110 1.7.6.2 tls #include <sys/syslog.h>
111 1.7.6.2 tls
112 1.7.6.2 tls #include <uvm/uvm.h>
113 1.7.6.2 tls #include <uvm/uvm_pmap.h>
114 1.7.6.2 tls #include <uvm/uvm_stat.h>
115 1.7.6.2 tls #include <uvm/uvm_pager.h>
116 1.7.6.2 tls
117 1.7.6.2 tls #include <miscfs/fifofs/fifo.h>
118 1.7.6.2 tls #include <miscfs/genfs/genfs.h>
119 1.7.6.2 tls #include <miscfs/specfs/specdev.h>
120 1.7.6.2 tls
121 1.7.6.2 tls #include <ufs/lfs/ulfs_inode.h>
122 1.7.6.2 tls #include <ufs/lfs/ulfsmount.h>
123 1.7.6.2 tls #include <ufs/lfs/ulfs_bswap.h>
124 1.7.6.2 tls #include <ufs/lfs/ulfs_extern.h>
125 1.7.6.2 tls
126 1.7.6.2 tls #include <ufs/lfs/lfs.h>
127 1.7.6.2 tls #include <ufs/lfs/lfs_extern.h>
128 1.7.6.2 tls
129 1.7.6.2 tls /*
130 1.7.6.2 tls * A virgin directory (no blushing please).
131 1.7.6.2 tls *
132 1.7.6.2 tls * XXX Copypasta from ulfs_vnops.c. Kill!
133 1.7.6.2 tls */
134 1.7.6.2 tls static const struct lfs_dirtemplate mastertemplate = {
135 1.7.6.2 tls 0, 12, LFS_DT_DIR, 1, ".",
136 1.7.6.2 tls 0, LFS_DIRBLKSIZ - 12, LFS_DT_DIR, 2, ".."
137 1.7.6.2 tls };
138 1.7.6.2 tls
139 1.7.6.2 tls /*
140 1.7.6.2 tls * ulfs_gro_directory_empty_p: Return true if the directory vp is
141 1.7.6.2 tls * empty. dvp is its parent.
142 1.7.6.2 tls *
143 1.7.6.2 tls * vp and dvp must be locked and referenced.
144 1.7.6.2 tls */
145 1.7.6.2 tls static bool
146 1.7.6.2 tls ulfs_gro_directory_empty_p(struct mount *mp, kauth_cred_t cred,
147 1.7.6.2 tls struct vnode *vp, struct vnode *dvp)
148 1.7.6.2 tls {
149 1.7.6.2 tls
150 1.7.6.2 tls (void)mp;
151 1.7.6.2 tls KASSERT(mp != NULL);
152 1.7.6.2 tls KASSERT(vp != NULL);
153 1.7.6.2 tls KASSERT(dvp != NULL);
154 1.7.6.2 tls KASSERT(vp != dvp);
155 1.7.6.2 tls KASSERT(vp->v_mount == mp);
156 1.7.6.2 tls KASSERT(dvp->v_mount == mp);
157 1.7.6.2 tls KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
158 1.7.6.2 tls KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
159 1.7.6.2 tls
160 1.7.6.2 tls return ulfs_dirempty(VTOI(vp), VTOI(dvp)->i_number, cred);
161 1.7.6.2 tls }
162 1.7.6.2 tls
163 1.7.6.2 tls /*
164 1.7.6.2 tls * ulfs_gro_rename_check_possible: Check whether a rename is possible
165 1.7.6.2 tls * independent of credentials.
166 1.7.6.2 tls */
167 1.7.6.2 tls static int
168 1.7.6.2 tls ulfs_gro_rename_check_possible(struct mount *mp,
169 1.7.6.2 tls struct vnode *fdvp, struct vnode *fvp,
170 1.7.6.2 tls struct vnode *tdvp, struct vnode *tvp)
171 1.7.6.2 tls {
172 1.7.6.2 tls
173 1.7.6.2 tls (void)mp;
174 1.7.6.2 tls KASSERT(mp != NULL);
175 1.7.6.2 tls KASSERT(fdvp != NULL);
176 1.7.6.2 tls KASSERT(fvp != NULL);
177 1.7.6.2 tls KASSERT(tdvp != NULL);
178 1.7.6.2 tls KASSERT(fdvp != fvp);
179 1.7.6.2 tls KASSERT(fdvp != tvp);
180 1.7.6.2 tls KASSERT(tdvp != fvp);
181 1.7.6.2 tls KASSERT(tdvp != tvp);
182 1.7.6.2 tls KASSERT(fvp != tvp);
183 1.7.6.2 tls KASSERT(fdvp->v_type == VDIR);
184 1.7.6.2 tls KASSERT(tdvp->v_type == VDIR);
185 1.7.6.2 tls KASSERT(fdvp->v_mount == mp);
186 1.7.6.2 tls KASSERT(fvp->v_mount == mp);
187 1.7.6.2 tls KASSERT(tdvp->v_mount == mp);
188 1.7.6.2 tls KASSERT((tvp == NULL) || (tvp->v_mount == mp));
189 1.7.6.2 tls KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
190 1.7.6.2 tls KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
191 1.7.6.2 tls KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
192 1.7.6.2 tls KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
193 1.7.6.2 tls
194 1.7.6.2 tls return genfs_ufslike_rename_check_possible(
195 1.7.6.2 tls VTOI(fdvp)->i_flags, VTOI(fvp)->i_flags,
196 1.7.6.2 tls VTOI(tdvp)->i_flags, (tvp? VTOI(tvp)->i_flags : 0),
197 1.7.6.2 tls (tvp != NULL),
198 1.7.6.2 tls IMMUTABLE, APPEND);
199 1.7.6.2 tls }
200 1.7.6.2 tls
201 1.7.6.2 tls /*
202 1.7.6.2 tls * ulfs_gro_rename_check_permitted: Check whether a rename is permitted
203 1.7.6.2 tls * given our credentials.
204 1.7.6.2 tls */
205 1.7.6.2 tls static int
206 1.7.6.2 tls ulfs_gro_rename_check_permitted(struct mount *mp, kauth_cred_t cred,
207 1.7.6.2 tls struct vnode *fdvp, struct vnode *fvp,
208 1.7.6.2 tls struct vnode *tdvp, struct vnode *tvp)
209 1.7.6.2 tls {
210 1.7.6.2 tls
211 1.7.6.2 tls (void)mp;
212 1.7.6.2 tls KASSERT(mp != NULL);
213 1.7.6.2 tls KASSERT(fdvp != NULL);
214 1.7.6.2 tls KASSERT(fvp != NULL);
215 1.7.6.2 tls KASSERT(tdvp != NULL);
216 1.7.6.2 tls KASSERT(fdvp != fvp);
217 1.7.6.2 tls KASSERT(fdvp != tvp);
218 1.7.6.2 tls KASSERT(tdvp != fvp);
219 1.7.6.2 tls KASSERT(tdvp != tvp);
220 1.7.6.2 tls KASSERT(fvp != tvp);
221 1.7.6.2 tls KASSERT(fdvp->v_type == VDIR);
222 1.7.6.2 tls KASSERT(tdvp->v_type == VDIR);
223 1.7.6.2 tls KASSERT(fdvp->v_mount == mp);
224 1.7.6.2 tls KASSERT(fvp->v_mount == mp);
225 1.7.6.2 tls KASSERT(tdvp->v_mount == mp);
226 1.7.6.2 tls KASSERT((tvp == NULL) || (tvp->v_mount == mp));
227 1.7.6.2 tls KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
228 1.7.6.2 tls KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
229 1.7.6.2 tls KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
230 1.7.6.2 tls KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
231 1.7.6.2 tls
232 1.7.6.2 tls return genfs_ufslike_rename_check_permitted(cred,
233 1.7.6.2 tls fdvp, VTOI(fdvp)->i_mode, VTOI(fdvp)->i_uid,
234 1.7.6.2 tls fvp, VTOI(fvp)->i_uid,
235 1.7.6.2 tls tdvp, VTOI(tdvp)->i_mode, VTOI(tdvp)->i_uid,
236 1.7.6.2 tls tvp, (tvp? VTOI(tvp)->i_uid : 0));
237 1.7.6.2 tls }
238 1.7.6.2 tls
239 1.7.6.2 tls /*
240 1.7.6.2 tls * ulfs_gro_remove_check_possible: Check whether a remove is possible
241 1.7.6.2 tls * independent of credentials.
242 1.7.6.2 tls */
243 1.7.6.2 tls static int
244 1.7.6.2 tls ulfs_gro_remove_check_possible(struct mount *mp,
245 1.7.6.2 tls struct vnode *dvp, struct vnode *vp)
246 1.7.6.2 tls {
247 1.7.6.2 tls
248 1.7.6.2 tls (void)mp;
249 1.7.6.2 tls KASSERT(mp != NULL);
250 1.7.6.2 tls KASSERT(dvp != NULL);
251 1.7.6.2 tls KASSERT(vp != NULL);
252 1.7.6.2 tls KASSERT(dvp != vp);
253 1.7.6.2 tls KASSERT(dvp->v_type == VDIR);
254 1.7.6.2 tls KASSERT(vp->v_type != VDIR);
255 1.7.6.2 tls KASSERT(dvp->v_mount == mp);
256 1.7.6.2 tls KASSERT(vp->v_mount == mp);
257 1.7.6.2 tls KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
258 1.7.6.2 tls KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
259 1.7.6.2 tls
260 1.7.6.2 tls return genfs_ufslike_remove_check_possible(
261 1.7.6.2 tls VTOI(dvp)->i_flags, VTOI(vp)->i_flags,
262 1.7.6.2 tls IMMUTABLE, APPEND);
263 1.7.6.2 tls }
264 1.7.6.2 tls
265 1.7.6.2 tls /*
266 1.7.6.2 tls * ulfs_gro_remove_check_permitted: Check whether a remove is permitted
267 1.7.6.2 tls * given our credentials.
268 1.7.6.2 tls */
269 1.7.6.2 tls static int
270 1.7.6.2 tls ulfs_gro_remove_check_permitted(struct mount *mp, kauth_cred_t cred,
271 1.7.6.2 tls struct vnode *dvp, struct vnode *vp)
272 1.7.6.2 tls {
273 1.7.6.2 tls
274 1.7.6.2 tls (void)mp;
275 1.7.6.2 tls KASSERT(mp != NULL);
276 1.7.6.2 tls KASSERT(dvp != NULL);
277 1.7.6.2 tls KASSERT(vp != NULL);
278 1.7.6.2 tls KASSERT(dvp != vp);
279 1.7.6.2 tls KASSERT(dvp->v_type == VDIR);
280 1.7.6.2 tls KASSERT(vp->v_type != VDIR);
281 1.7.6.2 tls KASSERT(dvp->v_mount == mp);
282 1.7.6.2 tls KASSERT(vp->v_mount == mp);
283 1.7.6.2 tls KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
284 1.7.6.2 tls KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
285 1.7.6.2 tls
286 1.7.6.2 tls return genfs_ufslike_remove_check_permitted(cred,
287 1.7.6.2 tls dvp, VTOI(dvp)->i_mode, VTOI(dvp)->i_uid, vp, VTOI(vp)->i_uid);
288 1.7.6.2 tls }
289 1.7.6.2 tls
290 1.7.6.2 tls /*
291 1.7.6.2 tls * ulfs_rename_ulr_overlap_p: True iff tulr overlaps with fulr so that
292 1.7.6.2 tls * entering a directory entry at tulr may move fulr.
293 1.7.6.2 tls */
294 1.7.6.2 tls static bool
295 1.7.6.2 tls ulfs_rename_ulr_overlap_p(const struct ulfs_lookup_results *fulr,
296 1.7.6.2 tls const struct ulfs_lookup_results *tulr)
297 1.7.6.2 tls {
298 1.7.6.2 tls doff_t from_prev_start, from_prev_end, to_start, to_end;
299 1.7.6.2 tls
300 1.7.6.2 tls KASSERT(fulr != NULL);
301 1.7.6.2 tls KASSERT(tulr != NULL);
302 1.7.6.2 tls KASSERT(fulr != tulr);
303 1.7.6.2 tls
304 1.7.6.2 tls /*
305 1.7.6.2 tls * fulr is from a DELETE lookup, so fulr->ulr_count is the size
306 1.7.6.2 tls * of the preceding entry (d_reclen).
307 1.7.6.2 tls */
308 1.7.6.2 tls from_prev_end = fulr->ulr_offset;
309 1.7.6.2 tls KASSERT(fulr->ulr_count <= from_prev_end);
310 1.7.6.2 tls from_prev_start = (from_prev_end - fulr->ulr_count);
311 1.7.6.2 tls
312 1.7.6.2 tls /*
313 1.7.6.2 tls * tulr is from a RENAME lookup, so tulr->ulr_count is the size
314 1.7.6.2 tls * of the free space for an entry that we are about to fill.
315 1.7.6.2 tls */
316 1.7.6.2 tls to_start = tulr->ulr_offset;
317 1.7.6.2 tls KASSERT(tulr->ulr_count < (LFS_MAXDIRSIZE - to_start));
318 1.7.6.2 tls to_end = (to_start + tulr->ulr_count);
319 1.7.6.2 tls
320 1.7.6.2 tls return
321 1.7.6.2 tls (((to_start <= from_prev_start) && (from_prev_start < to_end)) ||
322 1.7.6.2 tls ((to_start <= from_prev_end) && (from_prev_end < to_end)));
323 1.7.6.2 tls }
324 1.7.6.2 tls
325 1.7.6.2 tls /*
326 1.7.6.2 tls * ulfs_direct_namlen: Return the namlen of the directory entry ep from
327 1.7.6.2 tls * the directory vp.
328 1.7.6.2 tls */
329 1.7.6.2 tls static int /* XXX int? uint8_t? */
330 1.7.6.2 tls ulfs_direct_namlen(const struct lfs_direct *ep, const struct vnode *vp)
331 1.7.6.2 tls {
332 1.7.6.2 tls bool swap;
333 1.7.6.2 tls
334 1.7.6.2 tls KASSERT(ep != NULL);
335 1.7.6.2 tls KASSERT(vp != NULL);
336 1.7.6.2 tls KASSERT(VTOI(vp) != NULL);
337 1.7.6.2 tls KASSERT(VTOI(vp)->i_ump != NULL);
338 1.7.6.2 tls
339 1.7.6.2 tls #if (BYTE_ORDER == LITTLE_ENDIAN)
340 1.7.6.2 tls swap = (ULFS_IPNEEDSWAP(VTOI(vp)) == 0);
341 1.7.6.2 tls #else
342 1.7.6.2 tls swap = (ULFS_IPNEEDSWAP(VTOI(vp)) != 0);
343 1.7.6.2 tls #endif
344 1.7.6.2 tls
345 1.7.6.2 tls return ((FSFMT(vp) && swap)? ep->d_type : ep->d_namlen);
346 1.7.6.2 tls }
347 1.7.6.2 tls
348 1.7.6.2 tls /*
349 1.7.6.2 tls * ulfs_rename_recalculate_fulr: If we have just entered a directory into
350 1.7.6.2 tls * dvp at tulr, and we were about to remove one at fulr for an entry
351 1.7.6.2 tls * named fcnp, fulr may be invalid. So, if necessary, recalculate it.
352 1.7.6.2 tls */
353 1.7.6.2 tls static int
354 1.7.6.2 tls ulfs_rename_recalculate_fulr(struct vnode *dvp,
355 1.7.6.2 tls struct ulfs_lookup_results *fulr, const struct ulfs_lookup_results *tulr,
356 1.7.6.2 tls const struct componentname *fcnp)
357 1.7.6.2 tls {
358 1.7.6.2 tls struct mount *mp;
359 1.7.6.2 tls struct lfs *fs;
360 1.7.6.2 tls struct ulfsmount *ump;
361 1.7.6.2 tls int needswap;
362 1.7.6.2 tls /* XXX int is a silly type for this; blame ulfsmount::um_dirblksiz. */
363 1.7.6.2 tls int dirblksiz;
364 1.7.6.2 tls doff_t search_start, search_end;
365 1.7.6.2 tls doff_t offset; /* Offset of entry we're examining. */
366 1.7.6.2 tls struct buf *bp; /* I/O block we're examining. */
367 1.7.6.2 tls char *dirbuf; /* Pointer into directory at search_start. */
368 1.7.6.2 tls struct lfs_direct *ep; /* Pointer to the entry we're examining. */
369 1.7.6.2 tls /* XXX direct::d_reclen is 16-bit;
370 1.7.6.2 tls * ulfs_lookup_results::ulr_reclen is 32-bit. Blah. */
371 1.7.6.2 tls uint32_t reclen; /* Length of the entry we're examining. */
372 1.7.6.2 tls uint32_t prev_reclen; /* Length of the preceding entry. */
373 1.7.6.2 tls int error;
374 1.7.6.2 tls
375 1.7.6.2 tls KASSERT(dvp != NULL);
376 1.7.6.2 tls KASSERT(dvp->v_mount != NULL);
377 1.7.6.2 tls KASSERT(VTOI(dvp) != NULL);
378 1.7.6.2 tls KASSERT(fulr != NULL);
379 1.7.6.2 tls KASSERT(tulr != NULL);
380 1.7.6.2 tls KASSERT(fulr != tulr);
381 1.7.6.2 tls KASSERT(ulfs_rename_ulr_overlap_p(fulr, tulr));
382 1.7.6.2 tls
383 1.7.6.2 tls mp = dvp->v_mount;
384 1.7.6.2 tls ump = VFSTOULFS(mp);
385 1.7.6.2 tls fs = ump->um_lfs;
386 1.7.6.2 tls KASSERT(ump != NULL);
387 1.7.6.2 tls KASSERT(ump == VTOI(dvp)->i_ump);
388 1.7.6.2 tls KASSERT(fs == VTOI(dvp)->i_lfs);
389 1.7.6.2 tls
390 1.7.6.2 tls needswap = ULFS_MPNEEDSWAP(fs);
391 1.7.6.2 tls
392 1.7.6.2 tls dirblksiz = fs->um_dirblksiz;
393 1.7.6.2 tls KASSERT(0 < dirblksiz);
394 1.7.6.2 tls KASSERT((dirblksiz & (dirblksiz - 1)) == 0);
395 1.7.6.2 tls
396 1.7.6.2 tls /* A directory block may not span across multiple I/O blocks. */
397 1.7.6.2 tls KASSERT(dirblksiz <= mp->mnt_stat.f_iosize);
398 1.7.6.2 tls
399 1.7.6.2 tls /* Find the bounds of the search. */
400 1.7.6.2 tls search_start = tulr->ulr_offset;
401 1.7.6.2 tls KASSERT(fulr->ulr_reclen < (LFS_MAXDIRSIZE - fulr->ulr_offset));
402 1.7.6.2 tls search_end = (fulr->ulr_offset + fulr->ulr_reclen);
403 1.7.6.2 tls
404 1.7.6.2 tls /* Compaction must happen only within a directory block. (*) */
405 1.7.6.2 tls KASSERT(search_start <= search_end);
406 1.7.6.2 tls KASSERT((search_end - (search_start &~ (dirblksiz - 1))) <= dirblksiz);
407 1.7.6.2 tls
408 1.7.6.2 tls dirbuf = NULL;
409 1.7.6.2 tls bp = NULL;
410 1.7.6.2 tls error = ulfs_blkatoff(dvp, (off_t)search_start, &dirbuf, &bp, false);
411 1.7.6.2 tls if (error)
412 1.7.6.2 tls return error;
413 1.7.6.2 tls KASSERT(dirbuf != NULL);
414 1.7.6.2 tls KASSERT(bp != NULL);
415 1.7.6.2 tls
416 1.7.6.2 tls /*
417 1.7.6.2 tls * Guarantee we sha'n't go past the end of the buffer we got.
418 1.7.6.2 tls * dirbuf is bp->b_data + (search_start & (iosize - 1)), and
419 1.7.6.2 tls * the valid range is [bp->b_data, bp->b_data + bp->b_bcount).
420 1.7.6.2 tls */
421 1.7.6.2 tls KASSERT((search_end - search_start) <=
422 1.7.6.2 tls (bp->b_bcount - (search_start & (mp->mnt_stat.f_iosize - 1))));
423 1.7.6.2 tls
424 1.7.6.2 tls prev_reclen = fulr->ulr_count;
425 1.7.6.2 tls offset = search_start;
426 1.7.6.2 tls
427 1.7.6.2 tls /*
428 1.7.6.2 tls * Search from search_start to search_end for the entry matching
429 1.7.6.2 tls * fcnp, which must be there because we found it before and it
430 1.7.6.2 tls * should only at most have moved earlier.
431 1.7.6.2 tls */
432 1.7.6.2 tls for (;;) {
433 1.7.6.2 tls KASSERT(search_start <= offset);
434 1.7.6.2 tls KASSERT(offset < search_end);
435 1.7.6.2 tls
436 1.7.6.2 tls /*
437 1.7.6.2 tls * Examine the directory entry at offset.
438 1.7.6.2 tls */
439 1.7.6.2 tls ep = (struct lfs_direct *)(dirbuf + (offset - search_start));
440 1.7.6.2 tls reclen = ulfs_rw16(ep->d_reclen, needswap);
441 1.7.6.2 tls
442 1.7.6.2 tls if (ep->d_ino == 0)
443 1.7.6.2 tls goto next; /* Entry is unused. */
444 1.7.6.2 tls
445 1.7.6.2 tls if (ulfs_rw32(ep->d_ino, needswap) == ULFS_WINO)
446 1.7.6.2 tls goto next; /* Entry is whiteout. */
447 1.7.6.2 tls
448 1.7.6.2 tls if (fcnp->cn_namelen != ulfs_direct_namlen(ep, dvp))
449 1.7.6.2 tls goto next; /* Wrong name length. */
450 1.7.6.2 tls
451 1.7.6.2 tls if (memcmp(ep->d_name, fcnp->cn_nameptr, fcnp->cn_namelen))
452 1.7.6.2 tls goto next; /* Wrong name. */
453 1.7.6.2 tls
454 1.7.6.2 tls /* Got it! */
455 1.7.6.2 tls break;
456 1.7.6.2 tls
457 1.7.6.2 tls next:
458 1.7.6.2 tls if (! ((reclen < search_end) &&
459 1.7.6.2 tls (offset < (search_end - reclen)))) {
460 1.7.6.2 tls brelse(bp, 0);
461 1.7.6.2 tls return EIO; /* XXX Panic? What? */
462 1.7.6.2 tls }
463 1.7.6.2 tls
464 1.7.6.2 tls /* We may not move past the search end. */
465 1.7.6.2 tls KASSERT(reclen < search_end);
466 1.7.6.2 tls KASSERT(offset < (search_end - reclen));
467 1.7.6.2 tls
468 1.7.6.2 tls /*
469 1.7.6.2 tls * We may not move across a directory block boundary;
470 1.7.6.2 tls * see (*) above.
471 1.7.6.2 tls */
472 1.7.6.2 tls KASSERT((offset &~ (dirblksiz - 1)) ==
473 1.7.6.2 tls ((offset + reclen) &~ (dirblksiz - 1)));
474 1.7.6.2 tls
475 1.7.6.2 tls prev_reclen = reclen;
476 1.7.6.2 tls offset += reclen;
477 1.7.6.2 tls }
478 1.7.6.2 tls
479 1.7.6.2 tls /*
480 1.7.6.2 tls * Found the entry. Record where.
481 1.7.6.2 tls */
482 1.7.6.2 tls fulr->ulr_offset = offset;
483 1.7.6.2 tls fulr->ulr_reclen = reclen;
484 1.7.6.2 tls
485 1.7.6.2 tls /*
486 1.7.6.2 tls * Record the preceding record length, but not if we're at the
487 1.7.6.2 tls * start of a directory block.
488 1.7.6.2 tls */
489 1.7.6.2 tls fulr->ulr_count = ((offset & (dirblksiz - 1))? prev_reclen : 0);
490 1.7.6.2 tls
491 1.7.6.2 tls brelse(bp, 0);
492 1.7.6.2 tls return 0;
493 1.7.6.2 tls }
494 1.7.6.2 tls
495 1.7.6.2 tls /*
496 1.7.6.2 tls * ulfs_gro_remove: Rename an object over another link to itself,
497 1.7.6.2 tls * effectively removing just the original link.
498 1.7.6.2 tls */
499 1.7.6.2 tls static int
500 1.7.6.2 tls ulfs_gro_remove(struct mount *mp, kauth_cred_t cred,
501 1.7.6.2 tls struct vnode *dvp, struct componentname *cnp, void *de, struct vnode *vp)
502 1.7.6.2 tls {
503 1.7.6.2 tls struct ulfs_lookup_results *ulr = de;
504 1.7.6.2 tls int error;
505 1.7.6.2 tls
506 1.7.6.2 tls KASSERT(mp != NULL);
507 1.7.6.2 tls KASSERT(dvp != NULL);
508 1.7.6.2 tls KASSERT(cnp != NULL);
509 1.7.6.2 tls KASSERT(ulr != NULL);
510 1.7.6.2 tls KASSERT(vp != NULL);
511 1.7.6.2 tls KASSERT(dvp != vp);
512 1.7.6.2 tls KASSERT(dvp->v_mount == mp);
513 1.7.6.2 tls KASSERT(vp->v_mount == mp);
514 1.7.6.2 tls KASSERT(dvp->v_type == VDIR);
515 1.7.6.2 tls KASSERT(vp->v_type != VDIR);
516 1.7.6.2 tls KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
517 1.7.6.2 tls KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
518 1.7.6.2 tls KASSERT(cnp->cn_nameiop == DELETE);
519 1.7.6.2 tls
520 1.7.6.2 tls /* XXX ulfs_dirremove decrements vp's link count for us. */
521 1.7.6.2 tls error = ulfs_dirremove(dvp, ulr, VTOI(vp), cnp->cn_flags, 0);
522 1.7.6.2 tls if (error)
523 1.7.6.2 tls goto out1;
524 1.7.6.2 tls
525 1.7.6.2 tls VN_KNOTE(dvp, NOTE_WRITE);
526 1.7.6.2 tls VN_KNOTE(vp, (VTOI(vp)->i_nlink? NOTE_LINK : NOTE_DELETE));
527 1.7.6.2 tls
528 1.7.6.2 tls out1:
529 1.7.6.2 tls return error;
530 1.7.6.2 tls }
531 1.7.6.2 tls
532 1.7.6.2 tls /*
533 1.7.6.2 tls * ulfs_gro_lookup: Look up and save the lookup results.
534 1.7.6.2 tls */
535 1.7.6.2 tls static int
536 1.7.6.2 tls ulfs_gro_lookup(struct mount *mp, struct vnode *dvp,
537 1.7.6.2 tls struct componentname *cnp, void *de_ret, struct vnode **vp_ret)
538 1.7.6.2 tls {
539 1.7.6.2 tls struct ulfs_lookup_results *ulr_ret = de_ret;
540 1.7.6.2 tls struct vnode *vp = NULL;
541 1.7.6.2 tls int error;
542 1.7.6.2 tls
543 1.7.6.2 tls (void)mp;
544 1.7.6.2 tls KASSERT(mp != NULL);
545 1.7.6.2 tls KASSERT(dvp != NULL);
546 1.7.6.2 tls KASSERT(cnp != NULL);
547 1.7.6.2 tls KASSERT(ulr_ret != NULL);
548 1.7.6.2 tls KASSERT(vp_ret != NULL);
549 1.7.6.2 tls KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
550 1.7.6.2 tls
551 1.7.6.2 tls /* Kludge cargo-culted from dholland's ulfs_rename. */
552 1.7.6.2 tls cnp->cn_flags &=~ MODMASK;
553 1.7.6.2 tls cnp->cn_flags |= (LOCKPARENT | LOCKLEAF);
554 1.7.6.2 tls
555 1.7.6.2 tls error = relookup(dvp, &vp, cnp, 0 /* dummy */);
556 1.7.6.2 tls if ((error == 0) && (vp == NULL)) {
557 1.7.6.2 tls error = ENOENT;
558 1.7.6.2 tls goto out;
559 1.7.6.2 tls } else if (error) {
560 1.7.6.2 tls return error;
561 1.7.6.2 tls }
562 1.7.6.2 tls
563 1.7.6.2 tls /*
564 1.7.6.2 tls * Thanks to VFS insanity, relookup locks vp, which screws us
565 1.7.6.2 tls * in various ways.
566 1.7.6.2 tls */
567 1.7.6.2 tls KASSERT(vp != NULL);
568 1.7.6.2 tls VOP_UNLOCK(vp);
569 1.7.6.2 tls
570 1.7.6.2 tls out: *ulr_ret = VTOI(dvp)->i_crap;
571 1.7.6.2 tls *vp_ret = vp;
572 1.7.6.2 tls return error;
573 1.7.6.2 tls }
574 1.7.6.2 tls
575 1.7.6.2 tls /*
576 1.7.6.2 tls * ulfs_rmdired_p: Check whether the directory vp has been rmdired.
577 1.7.6.2 tls *
578 1.7.6.2 tls * vp must be locked and referenced.
579 1.7.6.2 tls */
580 1.7.6.2 tls static bool
581 1.7.6.2 tls ulfs_rmdired_p(struct vnode *vp)
582 1.7.6.2 tls {
583 1.7.6.2 tls
584 1.7.6.2 tls KASSERT(vp != NULL);
585 1.7.6.2 tls KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
586 1.7.6.2 tls KASSERT(vp->v_type == VDIR);
587 1.7.6.2 tls
588 1.7.6.2 tls /* XXX Is this correct? */
589 1.7.6.2 tls return (VTOI(vp)->i_size == 0);
590 1.7.6.2 tls }
591 1.7.6.2 tls
592 1.7.6.2 tls /*
593 1.7.6.2 tls * ulfs_dirbuf_dotdot_namlen: Return the namlen of the directory buffer
594 1.7.6.2 tls * dirbuf that came from the directory vp. Swap byte order if
595 1.7.6.2 tls * necessary.
596 1.7.6.2 tls */
597 1.7.6.2 tls static int /* XXX int? uint8_t? */
598 1.7.6.2 tls ulfs_dirbuf_dotdot_namlen(const struct lfs_dirtemplate *dirbuf,
599 1.7.6.2 tls const struct vnode *vp)
600 1.7.6.2 tls {
601 1.7.6.2 tls bool swap;
602 1.7.6.2 tls
603 1.7.6.2 tls KASSERT(dirbuf != NULL);
604 1.7.6.2 tls KASSERT(vp != NULL);
605 1.7.6.2 tls KASSERT(VTOI(vp) != NULL);
606 1.7.6.2 tls KASSERT(VTOI(vp)->i_ump != NULL);
607 1.7.6.2 tls
608 1.7.6.2 tls #if (BYTE_ORDER == LITTLE_ENDIAN)
609 1.7.6.2 tls swap = (ULFS_IPNEEDSWAP(VTOI(vp)) == 0);
610 1.7.6.2 tls #else
611 1.7.6.2 tls swap = (ULFS_IPNEEDSWAP(VTOI(vp)) != 0);
612 1.7.6.2 tls #endif
613 1.7.6.2 tls
614 1.7.6.2 tls return ((FSFMT(vp) && swap)?
615 1.7.6.2 tls dirbuf->dotdot_type : dirbuf->dotdot_namlen);
616 1.7.6.2 tls }
617 1.7.6.2 tls
618 1.7.6.2 tls /*
619 1.7.6.2 tls * ulfs_read_dotdot: Store in *ino_ret the inode number of the parent
620 1.7.6.2 tls * of the directory vp.
621 1.7.6.2 tls */
622 1.7.6.2 tls static int
623 1.7.6.2 tls ulfs_read_dotdot(struct vnode *vp, kauth_cred_t cred, ino_t *ino_ret)
624 1.7.6.2 tls {
625 1.7.6.2 tls struct lfs_dirtemplate dirbuf;
626 1.7.6.2 tls int error;
627 1.7.6.2 tls
628 1.7.6.2 tls KASSERT(vp != NULL);
629 1.7.6.2 tls KASSERT(ino_ret != NULL);
630 1.7.6.2 tls KASSERT(vp->v_type == VDIR);
631 1.7.6.2 tls
632 1.7.6.2 tls error = vn_rdwr(UIO_READ, vp, &dirbuf, sizeof dirbuf, (off_t)0,
633 1.7.6.2 tls UIO_SYSSPACE, IO_NODELOCKED, cred, NULL, NULL);
634 1.7.6.2 tls if (error)
635 1.7.6.2 tls return error;
636 1.7.6.2 tls
637 1.7.6.2 tls if (ulfs_dirbuf_dotdot_namlen(&dirbuf, vp) != 2 ||
638 1.7.6.2 tls dirbuf.dotdot_name[0] != '.' ||
639 1.7.6.2 tls dirbuf.dotdot_name[1] != '.')
640 1.7.6.2 tls /* XXX Panic? Print warning? */
641 1.7.6.2 tls return ENOTDIR;
642 1.7.6.2 tls
643 1.7.6.2 tls *ino_ret = ulfs_rw32(dirbuf.dotdot_ino,
644 1.7.6.2 tls ULFS_IPNEEDSWAP(VTOI(vp)));
645 1.7.6.2 tls return 0;
646 1.7.6.2 tls }
647 1.7.6.2 tls
648 1.7.6.2 tls /*
649 1.7.6.2 tls * ulfs_gro_lock_directory: Lock the directory vp, but fail if it has
650 1.7.6.2 tls * been rmdir'd.
651 1.7.6.2 tls */
652 1.7.6.2 tls static int
653 1.7.6.2 tls ulfs_gro_lock_directory(struct mount *mp, struct vnode *vp)
654 1.7.6.2 tls {
655 1.7.6.2 tls
656 1.7.6.2 tls (void)mp;
657 1.7.6.2 tls KASSERT(mp != NULL);
658 1.7.6.2 tls KASSERT(vp != NULL);
659 1.7.6.2 tls KASSERT(vp->v_mount == mp);
660 1.7.6.2 tls
661 1.7.6.2 tls vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
662 1.7.6.2 tls
663 1.7.6.2 tls if (ulfs_rmdired_p(vp)) {
664 1.7.6.2 tls VOP_UNLOCK(vp);
665 1.7.6.2 tls return ENOENT;
666 1.7.6.2 tls }
667 1.7.6.2 tls
668 1.7.6.2 tls return 0;
669 1.7.6.2 tls }
670 1.7.6.2 tls
671 1.7.6.2 tls /*
672 1.7.6.2 tls * ulfs_gro_genealogy: Analyze the genealogy of the source and target
673 1.7.6.2 tls * directories.
674 1.7.6.2 tls */
675 1.7.6.2 tls static int
676 1.7.6.2 tls ulfs_gro_genealogy(struct mount *mp, kauth_cred_t cred,
677 1.7.6.2 tls struct vnode *fdvp, struct vnode *tdvp,
678 1.7.6.2 tls struct vnode **intermediate_node_ret)
679 1.7.6.2 tls {
680 1.7.6.2 tls struct vnode *vp, *dvp;
681 1.7.6.2 tls ino_t dotdot_ino = -1; /* XXX gcc 4.8: maybe-uninitialized */
682 1.7.6.2 tls int error;
683 1.7.6.2 tls
684 1.7.6.2 tls KASSERT(mp != NULL);
685 1.7.6.2 tls KASSERT(fdvp != NULL);
686 1.7.6.2 tls KASSERT(tdvp != NULL);
687 1.7.6.2 tls KASSERT(fdvp != tdvp);
688 1.7.6.2 tls KASSERT(intermediate_node_ret != NULL);
689 1.7.6.2 tls KASSERT(fdvp->v_mount == mp);
690 1.7.6.2 tls KASSERT(tdvp->v_mount == mp);
691 1.7.6.2 tls KASSERT(fdvp->v_type == VDIR);
692 1.7.6.2 tls KASSERT(tdvp->v_type == VDIR);
693 1.7.6.2 tls
694 1.7.6.2 tls /*
695 1.7.6.2 tls * We need to provisionally lock tdvp to keep rmdir from
696 1.7.6.2 tls * deleting it -- or any ancestor -- at an inopportune moment.
697 1.7.6.2 tls */
698 1.7.6.2 tls error = ulfs_gro_lock_directory(mp, tdvp);
699 1.7.6.2 tls if (error)
700 1.7.6.2 tls return error;
701 1.7.6.2 tls
702 1.7.6.2 tls vp = tdvp;
703 1.7.6.2 tls vref(vp);
704 1.7.6.2 tls
705 1.7.6.2 tls for (;;) {
706 1.7.6.2 tls KASSERT(vp != NULL);
707 1.7.6.2 tls KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
708 1.7.6.2 tls KASSERT(vp->v_mount == mp);
709 1.7.6.2 tls KASSERT(vp->v_type == VDIR);
710 1.7.6.2 tls KASSERT(!ulfs_rmdired_p(vp));
711 1.7.6.2 tls
712 1.7.6.2 tls /* Did we hit the root without finding fdvp? */
713 1.7.6.2 tls if (VTOI(vp)->i_number == ULFS_ROOTINO) {
714 1.7.6.2 tls vput(vp);
715 1.7.6.2 tls *intermediate_node_ret = NULL;
716 1.7.6.2 tls return 0;
717 1.7.6.2 tls }
718 1.7.6.2 tls
719 1.7.6.2 tls error = ulfs_read_dotdot(vp, cred, &dotdot_ino);
720 1.7.6.2 tls if (error) {
721 1.7.6.2 tls vput(vp);
722 1.7.6.2 tls return error;
723 1.7.6.2 tls }
724 1.7.6.2 tls
725 1.7.6.2 tls /* Did we find that fdvp is an ancestor of tdvp? */
726 1.7.6.2 tls if (VTOI(fdvp)->i_number == dotdot_ino) {
727 1.7.6.2 tls /* Unlock vp, but keep it referenced. */
728 1.7.6.2 tls VOP_UNLOCK(vp);
729 1.7.6.2 tls *intermediate_node_ret = vp;
730 1.7.6.2 tls return 0;
731 1.7.6.2 tls }
732 1.7.6.2 tls
733 1.7.6.2 tls /* Neither -- keep ascending the family tree. */
734 1.7.6.2 tls
735 1.7.6.2 tls /*
736 1.7.6.2 tls * Unlock vp so that we can lock the parent, but keep
737 1.7.6.2 tls * vp referenced until after we have found the parent,
738 1.7.6.2 tls * so that dotdot_ino will not be recycled.
739 1.7.6.2 tls *
740 1.7.6.2 tls * XXX This guarantees that vp's inode number will not
741 1.7.6.2 tls * be recycled, but why can't dotdot_ino be recycled?
742 1.7.6.2 tls */
743 1.7.6.2 tls VOP_UNLOCK(vp);
744 1.7.6.2 tls error = VFS_VGET(mp, dotdot_ino, &dvp);
745 1.7.6.2 tls vrele(vp);
746 1.7.6.2 tls if (error)
747 1.7.6.2 tls return error;
748 1.7.6.2 tls
749 1.7.6.2 tls KASSERT(dvp != NULL);
750 1.7.6.2 tls KASSERT(VOP_ISLOCKED(dvp) == LK_EXCLUSIVE);
751 1.7.6.2 tls vp = dvp;
752 1.7.6.2 tls
753 1.7.6.2 tls if (vp->v_type != VDIR) {
754 1.7.6.2 tls /*
755 1.7.6.2 tls * XXX Panic? Print a warning? Can this
756 1.7.6.2 tls * happen if we lose the race I suspect to
757 1.7.6.2 tls * exist above, and the `..' inode number has
758 1.7.6.2 tls * been recycled?
759 1.7.6.2 tls */
760 1.7.6.2 tls vput(vp);
761 1.7.6.2 tls return ENOTDIR;
762 1.7.6.2 tls }
763 1.7.6.2 tls
764 1.7.6.2 tls if (ulfs_rmdired_p(vp)) {
765 1.7.6.2 tls vput(vp);
766 1.7.6.2 tls return ENOENT;
767 1.7.6.2 tls }
768 1.7.6.2 tls }
769 1.7.6.2 tls }
770 1.7.6.2 tls
771 1.7.6.2 tls /*
772 1.7.6.2 tls * ulfs_gro_rename: Actually perform the rename operation.
773 1.7.6.2 tls */
774 1.7.6.2 tls static int
775 1.7.6.2 tls ulfs_gro_rename(struct mount *mp, kauth_cred_t cred,
776 1.7.6.2 tls struct vnode *fdvp, struct componentname *fcnp,
777 1.7.6.2 tls void *fde, struct vnode *fvp,
778 1.7.6.2 tls struct vnode *tdvp, struct componentname *tcnp,
779 1.7.6.2 tls void *tde, struct vnode *tvp)
780 1.7.6.2 tls {
781 1.7.6.2 tls struct ulfs_lookup_results *fulr = fde;
782 1.7.6.2 tls struct ulfs_lookup_results *tulr = tde;
783 1.7.6.2 tls bool directory_p, reparent_p;
784 1.7.6.2 tls struct lfs_direct *newdir;
785 1.7.6.2 tls int error;
786 1.7.6.2 tls
787 1.7.6.2 tls KASSERT(mp != NULL);
788 1.7.6.2 tls KASSERT(fdvp != NULL);
789 1.7.6.2 tls KASSERT(fcnp != NULL);
790 1.7.6.2 tls KASSERT(fulr != NULL);
791 1.7.6.2 tls KASSERT(fvp != NULL);
792 1.7.6.2 tls KASSERT(tdvp != NULL);
793 1.7.6.2 tls KASSERT(tcnp != NULL);
794 1.7.6.2 tls KASSERT(tulr != NULL);
795 1.7.6.2 tls KASSERT(fulr != tulr);
796 1.7.6.2 tls KASSERT(fdvp != fvp);
797 1.7.6.2 tls KASSERT(fdvp != tvp);
798 1.7.6.2 tls KASSERT(tdvp != fvp);
799 1.7.6.2 tls KASSERT(tdvp != tvp);
800 1.7.6.2 tls KASSERT(fvp != tvp);
801 1.7.6.2 tls KASSERT(fdvp->v_mount == mp);
802 1.7.6.2 tls KASSERT(fvp->v_mount == mp);
803 1.7.6.2 tls KASSERT(tdvp->v_mount == mp);
804 1.7.6.2 tls KASSERT((tvp == NULL) || (tvp->v_mount == mp));
805 1.7.6.2 tls KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
806 1.7.6.2 tls KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
807 1.7.6.2 tls KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
808 1.7.6.2 tls KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
809 1.7.6.2 tls
810 1.7.6.2 tls /*
811 1.7.6.2 tls * We shall need to temporarily bump the link count, so make
812 1.7.6.2 tls * sure there is room to do so.
813 1.7.6.2 tls */
814 1.7.6.2 tls if ((nlink_t)VTOI(fvp)->i_nlink >= LINK_MAX)
815 1.7.6.2 tls return EMLINK;
816 1.7.6.2 tls
817 1.7.6.2 tls directory_p = (fvp->v_type == VDIR);
818 1.7.6.2 tls KASSERT(directory_p == ((VTOI(fvp)->i_mode & LFS_IFMT) == LFS_IFDIR));
819 1.7.6.2 tls KASSERT((tvp == NULL) || (directory_p == (tvp->v_type == VDIR)));
820 1.7.6.2 tls KASSERT((tvp == NULL) || (directory_p ==
821 1.7.6.2 tls ((VTOI(tvp)->i_mode & LFS_IFMT) == LFS_IFDIR)));
822 1.7.6.2 tls
823 1.7.6.2 tls reparent_p = (fdvp != tdvp);
824 1.7.6.2 tls KASSERT(reparent_p == (VTOI(fdvp)->i_number != VTOI(tdvp)->i_number));
825 1.7.6.2 tls
826 1.7.6.2 tls /*
827 1.7.6.2 tls * Commence hacking of the data on disk.
828 1.7.6.2 tls */
829 1.7.6.2 tls
830 1.7.6.2 tls error = 0;
831 1.7.6.2 tls
832 1.7.6.2 tls /*
833 1.7.6.2 tls * 1) Bump link count while we're moving stuff
834 1.7.6.2 tls * around. If we crash somewhere before
835 1.7.6.2 tls * completing our work, the link count
836 1.7.6.2 tls * may be wrong, but correctable.
837 1.7.6.2 tls */
838 1.7.6.2 tls
839 1.7.6.2 tls KASSERT((nlink_t)VTOI(fvp)->i_nlink < LINK_MAX);
840 1.7.6.2 tls VTOI(fvp)->i_nlink++;
841 1.7.6.2 tls DIP_ASSIGN(VTOI(fvp), nlink, VTOI(fvp)->i_nlink);
842 1.7.6.2 tls VTOI(fvp)->i_flag |= IN_CHANGE;
843 1.7.6.2 tls error = lfs_update(fvp, NULL, NULL, UPDATE_DIROP);
844 1.7.6.2 tls if (error)
845 1.7.6.2 tls goto whymustithurtsomuch;
846 1.7.6.2 tls
847 1.7.6.2 tls /*
848 1.7.6.2 tls * 2) If target doesn't exist, link the target
849 1.7.6.2 tls * to the source and unlink the source.
850 1.7.6.2 tls * Otherwise, rewrite the target directory
851 1.7.6.2 tls * entry to reference the source inode and
852 1.7.6.2 tls * expunge the original entry's existence.
853 1.7.6.2 tls */
854 1.7.6.2 tls
855 1.7.6.2 tls if (tvp == NULL) {
856 1.7.6.2 tls /*
857 1.7.6.2 tls * Account for ".." in new directory.
858 1.7.6.2 tls * When source and destination have the same
859 1.7.6.2 tls * parent we don't fool with the link count.
860 1.7.6.2 tls */
861 1.7.6.2 tls if (directory_p && reparent_p) {
862 1.7.6.2 tls if ((nlink_t)VTOI(tdvp)->i_nlink >= LINK_MAX) {
863 1.7.6.2 tls error = EMLINK;
864 1.7.6.2 tls goto whymustithurtsomuch;
865 1.7.6.2 tls }
866 1.7.6.2 tls KASSERT((nlink_t)VTOI(tdvp)->i_nlink < LINK_MAX);
867 1.7.6.2 tls VTOI(tdvp)->i_nlink++;
868 1.7.6.2 tls DIP_ASSIGN(VTOI(tdvp), nlink, VTOI(tdvp)->i_nlink);
869 1.7.6.2 tls VTOI(tdvp)->i_flag |= IN_CHANGE;
870 1.7.6.2 tls error = lfs_update(tdvp, NULL, NULL, UPDATE_DIROP);
871 1.7.6.2 tls if (error) {
872 1.7.6.2 tls /*
873 1.7.6.2 tls * Link count update didn't take --
874 1.7.6.2 tls * back out the in-memory link count.
875 1.7.6.2 tls */
876 1.7.6.2 tls KASSERT(0 < VTOI(tdvp)->i_nlink);
877 1.7.6.2 tls VTOI(tdvp)->i_nlink--;
878 1.7.6.2 tls DIP_ASSIGN(VTOI(tdvp), nlink,
879 1.7.6.2 tls VTOI(tdvp)->i_nlink);
880 1.7.6.2 tls VTOI(tdvp)->i_flag |= IN_CHANGE;
881 1.7.6.2 tls goto whymustithurtsomuch;
882 1.7.6.2 tls }
883 1.7.6.2 tls }
884 1.7.6.2 tls
885 1.7.6.2 tls newdir = pool_cache_get(ulfs_direct_cache, PR_WAITOK);
886 1.7.6.2 tls ulfs_makedirentry(VTOI(fvp), tcnp, newdir);
887 1.7.6.2 tls error = ulfs_direnter(tdvp, tulr, NULL, newdir, tcnp, NULL);
888 1.7.6.2 tls pool_cache_put(ulfs_direct_cache, newdir);
889 1.7.6.2 tls if (error) {
890 1.7.6.2 tls if (directory_p && reparent_p) {
891 1.7.6.2 tls /*
892 1.7.6.2 tls * Directory update didn't take, but
893 1.7.6.2 tls * the link count update did -- back
894 1.7.6.2 tls * out the in-memory link count and the
895 1.7.6.2 tls * on-disk link count.
896 1.7.6.2 tls */
897 1.7.6.2 tls KASSERT(0 < VTOI(tdvp)->i_nlink);
898 1.7.6.2 tls VTOI(tdvp)->i_nlink--;
899 1.7.6.2 tls DIP_ASSIGN(VTOI(tdvp), nlink,
900 1.7.6.2 tls VTOI(tdvp)->i_nlink);
901 1.7.6.2 tls VTOI(tdvp)->i_flag |= IN_CHANGE;
902 1.7.6.2 tls (void)lfs_update(tdvp, NULL, NULL,
903 1.7.6.2 tls UPDATE_WAIT | UPDATE_DIROP);
904 1.7.6.2 tls }
905 1.7.6.2 tls goto whymustithurtsomuch;
906 1.7.6.2 tls }
907 1.7.6.2 tls } else {
908 1.7.6.2 tls if (directory_p)
909 1.7.6.2 tls /* XXX WTF? Why purge here? Why not purge others? */
910 1.7.6.2 tls cache_purge(tdvp);
911 1.7.6.2 tls
912 1.7.6.2 tls /*
913 1.7.6.2 tls * Make the target directory's entry for tcnp point at
914 1.7.6.2 tls * the source node.
915 1.7.6.2 tls *
916 1.7.6.2 tls * XXX ulfs_dirrewrite decrements tvp's link count, but
917 1.7.6.2 tls * doesn't touch the link count of the new inode. Go
918 1.7.6.2 tls * figure.
919 1.7.6.2 tls */
920 1.7.6.2 tls error = ulfs_dirrewrite(VTOI(tdvp), tulr->ulr_offset,
921 1.7.6.2 tls VTOI(tvp), VTOI(fvp)->i_number, LFS_IFTODT(VTOI(fvp)->i_mode),
922 1.7.6.2 tls ((directory_p && reparent_p) ? reparent_p : directory_p),
923 1.7.6.2 tls IN_CHANGE | IN_UPDATE);
924 1.7.6.2 tls if (error)
925 1.7.6.2 tls goto whymustithurtsomuch;
926 1.7.6.2 tls
927 1.7.6.2 tls /*
928 1.7.6.2 tls * If the source and target are directories, and the
929 1.7.6.2 tls * target is in the same directory as the source,
930 1.7.6.2 tls * decrement the link count of the common parent
931 1.7.6.2 tls * directory, since we are removing the target from
932 1.7.6.2 tls * that directory.
933 1.7.6.2 tls */
934 1.7.6.2 tls if (directory_p && !reparent_p) {
935 1.7.6.2 tls KASSERT(fdvp == tdvp);
936 1.7.6.2 tls /* XXX check, don't kassert */
937 1.7.6.2 tls KASSERT(0 < VTOI(tdvp)->i_nlink);
938 1.7.6.2 tls VTOI(tdvp)->i_nlink--;
939 1.7.6.2 tls DIP_ASSIGN(VTOI(tdvp), nlink, VTOI(tdvp)->i_nlink);
940 1.7.6.2 tls VTOI(tdvp)->i_flag |= IN_CHANGE;
941 1.7.6.2 tls }
942 1.7.6.2 tls
943 1.7.6.2 tls if (directory_p) {
944 1.7.6.2 tls /*
945 1.7.6.2 tls * XXX I don't understand the following comment
946 1.7.6.2 tls * from ulfs_rename -- in particular, the part
947 1.7.6.2 tls * about `there may be other hard links'.
948 1.7.6.2 tls *
949 1.7.6.2 tls * Truncate inode. The only stuff left in the directory
950 1.7.6.2 tls * is "." and "..". The "." reference is inconsequential
951 1.7.6.2 tls * since we are quashing it. We have removed the "."
952 1.7.6.2 tls * reference and the reference in the parent directory,
953 1.7.6.2 tls * but there may be other hard links.
954 1.7.6.2 tls *
955 1.7.6.2 tls * XXX The ulfs_dirempty call earlier does
956 1.7.6.2 tls * not guarantee anything about nlink.
957 1.7.6.2 tls */
958 1.7.6.2 tls if (VTOI(tvp)->i_nlink != 1)
959 1.7.6.2 tls ulfs_dirbad(VTOI(tvp), (doff_t)0,
960 1.7.6.2 tls "hard-linked directory");
961 1.7.6.2 tls VTOI(tvp)->i_nlink = 0;
962 1.7.6.2 tls DIP_ASSIGN(VTOI(tvp), nlink, 0);
963 1.7.6.2 tls error = lfs_truncate(tvp, (off_t)0, IO_SYNC, cred);
964 1.7.6.2 tls if (error)
965 1.7.6.2 tls goto whymustithurtsomuch;
966 1.7.6.2 tls }
967 1.7.6.2 tls }
968 1.7.6.2 tls
969 1.7.6.2 tls /*
970 1.7.6.2 tls * If the source is a directory with a new parent, the link
971 1.7.6.2 tls * count of the old parent directory must be decremented and
972 1.7.6.2 tls * ".." set to point to the new parent.
973 1.7.6.2 tls *
974 1.7.6.2 tls * XXX ulfs_dirrewrite updates the link count of fdvp, but not
975 1.7.6.2 tls * the link count of fvp or the link count of tdvp. Go figure.
976 1.7.6.2 tls */
977 1.7.6.2 tls if (directory_p && reparent_p) {
978 1.7.6.2 tls error = ulfs_dirrewrite(VTOI(fvp), mastertemplate.dot_reclen,
979 1.7.6.2 tls VTOI(fdvp), VTOI(tdvp)->i_number, LFS_DT_DIR, 0, IN_CHANGE);
980 1.7.6.2 tls #if 0 /* XXX This branch was not in ulfs_rename! */
981 1.7.6.2 tls if (error)
982 1.7.6.2 tls goto whymustithurtsomuch;
983 1.7.6.2 tls #endif
984 1.7.6.2 tls
985 1.7.6.2 tls /* XXX WTF? Why purge here? Why not purge others? */
986 1.7.6.2 tls cache_purge(fdvp);
987 1.7.6.2 tls }
988 1.7.6.2 tls
989 1.7.6.2 tls /*
990 1.7.6.2 tls * 3) Unlink the source.
991 1.7.6.2 tls */
992 1.7.6.2 tls
993 1.7.6.2 tls /*
994 1.7.6.2 tls * ulfs_direnter may compact the directory in the process of
995 1.7.6.2 tls * inserting a new entry. That may invalidate fulr, which we
996 1.7.6.2 tls * need in order to remove the old entry. In that case, we
997 1.7.6.2 tls * need to recalculate what fulr should be.
998 1.7.6.2 tls */
999 1.7.6.2 tls if (!reparent_p && (tvp == NULL) &&
1000 1.7.6.2 tls ulfs_rename_ulr_overlap_p(fulr, tulr)) {
1001 1.7.6.2 tls error = ulfs_rename_recalculate_fulr(fdvp, fulr, tulr, fcnp);
1002 1.7.6.2 tls #if 0 /* XXX */
1003 1.7.6.2 tls if (error) /* XXX Try to back out changes? */
1004 1.7.6.2 tls goto whymustithurtsomuch;
1005 1.7.6.2 tls #endif
1006 1.7.6.2 tls }
1007 1.7.6.2 tls
1008 1.7.6.2 tls /*
1009 1.7.6.2 tls * XXX 0 means !isrmdir. But can't this be an rmdir?
1010 1.7.6.2 tls * XXX Well, turns out that argument to ulfs_dirremove is ignored...
1011 1.7.6.2 tls * XXX And it turns out ulfs_dirremove updates the link count of fvp.
1012 1.7.6.2 tls * XXX But it doesn't update the link count of fdvp. Go figure.
1013 1.7.6.2 tls * XXX fdvp's link count is updated in ulfs_dirrewrite instead.
1014 1.7.6.2 tls * XXX Actually, sometimes it doesn't update fvp's link count.
1015 1.7.6.2 tls * XXX I hate the world.
1016 1.7.6.2 tls */
1017 1.7.6.2 tls error = ulfs_dirremove(fdvp, fulr, VTOI(fvp), fcnp->cn_flags, 0);
1018 1.7.6.2 tls if (error)
1019 1.7.6.2 tls #if 0 /* XXX */
1020 1.7.6.2 tls goto whymustithurtsomuch;
1021 1.7.6.2 tls #endif
1022 1.7.6.2 tls goto arghmybrainhurts;
1023 1.7.6.2 tls
1024 1.7.6.2 tls /*
1025 1.7.6.2 tls * XXX Perhaps this should go at the top, in case the file
1026 1.7.6.2 tls * system is modified but incompletely so because of an
1027 1.7.6.2 tls * intermediate error.
1028 1.7.6.2 tls */
1029 1.7.6.2 tls genfs_rename_knote(fdvp, fvp, tdvp, tvp,
1030 1.7.6.2 tls ((tvp != NULL) && (VTOI(tvp)->i_nlink == 0)));
1031 1.7.6.2 tls #if 0 /* XXX */
1032 1.7.6.2 tls genfs_rename_cache_purge(fdvp, fvp, tdvp, tvp);
1033 1.7.6.2 tls #endif
1034 1.7.6.2 tls goto arghmybrainhurts;
1035 1.7.6.2 tls
1036 1.7.6.2 tls whymustithurtsomuch:
1037 1.7.6.2 tls KASSERT(0 < VTOI(fvp)->i_nlink);
1038 1.7.6.2 tls VTOI(fvp)->i_nlink--;
1039 1.7.6.2 tls DIP_ASSIGN(VTOI(fvp), nlink, VTOI(fvp)->i_nlink);
1040 1.7.6.2 tls VTOI(fvp)->i_flag |= IN_CHANGE;
1041 1.7.6.2 tls
1042 1.7.6.2 tls arghmybrainhurts:
1043 1.7.6.2 tls /*ihateyou:*/
1044 1.7.6.2 tls return error;
1045 1.7.6.2 tls }
1046 1.7.6.2 tls
1047 1.7.6.2 tls /*
1048 1.7.6.2 tls * lfs_gro_rename: Actually perform the rename operation. Do a little
1049 1.7.6.2 tls * LFS bookkeeping and then defer to ulfs_gro_rename.
1050 1.7.6.2 tls */
1051 1.7.6.2 tls static int
1052 1.7.6.2 tls lfs_gro_rename(struct mount *mp, kauth_cred_t cred,
1053 1.7.6.2 tls struct vnode *fdvp, struct componentname *fcnp,
1054 1.7.6.2 tls void *fde, struct vnode *fvp,
1055 1.7.6.2 tls struct vnode *tdvp, struct componentname *tcnp,
1056 1.7.6.2 tls void *tde, struct vnode *tvp)
1057 1.7.6.2 tls {
1058 1.7.6.2 tls int error;
1059 1.7.6.2 tls
1060 1.7.6.2 tls KASSERT(mp != NULL);
1061 1.7.6.2 tls KASSERT(fdvp != NULL);
1062 1.7.6.2 tls KASSERT(fcnp != NULL);
1063 1.7.6.2 tls KASSERT(fde != NULL);
1064 1.7.6.2 tls KASSERT(fvp != NULL);
1065 1.7.6.2 tls KASSERT(tdvp != NULL);
1066 1.7.6.2 tls KASSERT(tcnp != NULL);
1067 1.7.6.2 tls KASSERT(tde != NULL);
1068 1.7.6.2 tls KASSERT(fdvp != fvp);
1069 1.7.6.2 tls KASSERT(fdvp != tvp);
1070 1.7.6.2 tls KASSERT(tdvp != fvp);
1071 1.7.6.2 tls KASSERT(tdvp != tvp);
1072 1.7.6.2 tls KASSERT(fvp != tvp);
1073 1.7.6.2 tls KASSERT(fdvp->v_mount == mp);
1074 1.7.6.2 tls KASSERT(fvp->v_mount == mp);
1075 1.7.6.2 tls KASSERT(tdvp->v_mount == mp);
1076 1.7.6.2 tls KASSERT((tvp == NULL) || (tvp->v_mount == mp));
1077 1.7.6.2 tls KASSERT(VOP_ISLOCKED(fdvp) == LK_EXCLUSIVE);
1078 1.7.6.2 tls KASSERT(VOP_ISLOCKED(fvp) == LK_EXCLUSIVE);
1079 1.7.6.2 tls KASSERT(VOP_ISLOCKED(tdvp) == LK_EXCLUSIVE);
1080 1.7.6.2 tls KASSERT((tvp == NULL) || (VOP_ISLOCKED(tvp) == LK_EXCLUSIVE));
1081 1.7.6.2 tls
1082 1.7.6.2 tls error = lfs_set_dirop(tdvp, tvp);
1083 1.7.6.2 tls if (error != 0)
1084 1.7.6.2 tls return error;
1085 1.7.6.2 tls
1086 1.7.6.2 tls MARK_VNODE(fdvp);
1087 1.7.6.2 tls MARK_VNODE(fvp);
1088 1.7.6.2 tls
1089 1.7.6.2 tls error = ulfs_gro_rename(mp, cred,
1090 1.7.6.2 tls fdvp, fcnp, fde, fvp,
1091 1.7.6.2 tls tdvp, tcnp, tde, tvp);
1092 1.7.6.2 tls
1093 1.7.6.2 tls UNMARK_VNODE(fdvp);
1094 1.7.6.2 tls UNMARK_VNODE(fvp);
1095 1.7.6.2 tls UNMARK_VNODE(tdvp);
1096 1.7.6.2 tls if (tvp) {
1097 1.7.6.2 tls UNMARK_VNODE(tvp);
1098 1.7.6.2 tls }
1099 1.7.6.2 tls lfs_unset_dirop(VFSTOULFS(mp)->um_lfs, tdvp, "rename");
1100 1.7.6.2 tls vrele(tdvp);
1101 1.7.6.2 tls if (tvp) {
1102 1.7.6.2 tls vrele(tvp);
1103 1.7.6.2 tls }
1104 1.7.6.2 tls
1105 1.7.6.2 tls return error;
1106 1.7.6.2 tls }
1107 1.7.6.2 tls
1108 1.7.6.2 tls static const struct genfs_rename_ops lfs_genfs_rename_ops = {
1109 1.7.6.2 tls .gro_directory_empty_p = ulfs_gro_directory_empty_p,
1110 1.7.6.2 tls .gro_rename_check_possible = ulfs_gro_rename_check_possible,
1111 1.7.6.2 tls .gro_rename_check_permitted = ulfs_gro_rename_check_permitted,
1112 1.7.6.2 tls .gro_remove_check_possible = ulfs_gro_remove_check_possible,
1113 1.7.6.2 tls .gro_remove_check_permitted = ulfs_gro_remove_check_permitted,
1114 1.7.6.2 tls .gro_rename = lfs_gro_rename,
1115 1.7.6.2 tls .gro_remove = ulfs_gro_remove,
1116 1.7.6.2 tls .gro_lookup = ulfs_gro_lookup,
1117 1.7.6.2 tls .gro_genealogy = ulfs_gro_genealogy,
1118 1.7.6.2 tls .gro_lock_directory = ulfs_gro_lock_directory,
1119 1.7.6.2 tls };
1120 1.7.6.2 tls
1121 1.7.6.2 tls /*
1122 1.7.6.2 tls * lfs_sane_rename: The hairiest vop, with the saner API.
1123 1.7.6.2 tls *
1124 1.7.6.2 tls * Arguments:
1125 1.7.6.2 tls *
1126 1.7.6.2 tls * . fdvp (from directory vnode),
1127 1.7.6.2 tls * . fcnp (from component name),
1128 1.7.6.2 tls * . tdvp (to directory vnode),
1129 1.7.6.2 tls * . tcnp (to component name),
1130 1.7.6.2 tls * . cred (credentials structure), and
1131 1.7.6.2 tls * . posixly_correct (flag for behaviour if target & source link same file).
1132 1.7.6.2 tls *
1133 1.7.6.2 tls * fdvp and tdvp may be the same, and must be referenced and unlocked.
1134 1.7.6.2 tls */
1135 1.7.6.2 tls static int
1136 1.7.6.2 tls lfs_sane_rename(
1137 1.7.6.2 tls struct vnode *fdvp, struct componentname *fcnp,
1138 1.7.6.2 tls struct vnode *tdvp, struct componentname *tcnp,
1139 1.7.6.2 tls kauth_cred_t cred, bool posixly_correct)
1140 1.7.6.2 tls {
1141 1.7.6.2 tls struct ulfs_lookup_results fulr, tulr;
1142 1.7.6.2 tls
1143 1.7.6.2 tls /*
1144 1.7.6.2 tls * XXX Provisional kludge -- ulfs_lookup does not reject rename
1145 1.7.6.2 tls * of . or .. (from or to), so we hack it here. This is not
1146 1.7.6.2 tls * the right place: it should be caller's responsibility to
1147 1.7.6.2 tls * reject this case.
1148 1.7.6.2 tls */
1149 1.7.6.2 tls KASSERT(fcnp != NULL);
1150 1.7.6.2 tls KASSERT(tcnp != NULL);
1151 1.7.6.2 tls KASSERT(fcnp != tcnp);
1152 1.7.6.2 tls KASSERT(fcnp->cn_nameptr != NULL);
1153 1.7.6.2 tls KASSERT(tcnp->cn_nameptr != NULL);
1154 1.7.6.2 tls
1155 1.7.6.2 tls if ((fcnp->cn_flags | tcnp->cn_flags) & ISDOTDOT)
1156 1.7.6.2 tls return EINVAL; /* XXX EISDIR? */
1157 1.7.6.2 tls if ((fcnp->cn_namelen == 1) && (fcnp->cn_nameptr[0] == '.'))
1158 1.7.6.2 tls return EINVAL;
1159 1.7.6.2 tls if ((tcnp->cn_namelen == 1) && (tcnp->cn_nameptr[0] == '.'))
1160 1.7.6.2 tls return EINVAL;
1161 1.7.6.2 tls
1162 1.7.6.2 tls return genfs_sane_rename(&lfs_genfs_rename_ops,
1163 1.7.6.2 tls fdvp, fcnp, &fulr, tdvp, tcnp, &tulr,
1164 1.7.6.2 tls cred, posixly_correct);
1165 1.7.6.2 tls }
1166 1.7.6.2 tls
1167 1.7.6.2 tls /*
1168 1.7.6.2 tls * lfs_rename: The hairiest vop, with the insanest API. Defer to
1169 1.7.6.2 tls * genfs_insane_rename immediately.
1170 1.7.6.2 tls */
1171 1.7.6.2 tls int
1172 1.7.6.2 tls lfs_rename(void *v)
1173 1.7.6.2 tls {
1174 1.7.6.2 tls
1175 1.7.6.2 tls return genfs_insane_rename(v, &lfs_sane_rename);
1176 1.7.6.2 tls }
1177