]> git.saurik.com Git - apple/hfs.git/blob - core/hfs_lookup.c
hfs-407.30.1.tar.gz
[apple/hfs.git] / core / hfs_lookup.c
1 /*
2 * Copyright (c) 1999-2015 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * Copyright (c) 1989, 1993
30 * The Regents of the University of California. All rights reserved.
31 * (c) UNIX System Laboratories, Inc.
32 * All or some portions of this file are derived from material licensed
33 * to the University of California by American Telephone and Telegraph
34 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
35 * the permission of UNIX System Laboratories, Inc.
36 *
37 * Redistribution and use in source and binary forms, with or without
38 * modification, are permitted provided that the following conditions
39 * are met:
40 * 1. Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * 2. Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in the
44 * documentation and/or other materials provided with the distribution.
45 * 3. All advertising materials mentioning features or use of this software
46 * must display the following acknowledgement:
47 * This product includes software developed by the University of
48 * California, Berkeley and its contributors.
49 * 4. Neither the name of the University nor the names of its contributors
50 * may be used to endorse or promote products derived from this software
51 * without specific prior written permission.
52 *
53 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
54 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
55 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
56 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 *
65 * @(#)hfs_lookup.c 1.0
66 * derived from @(#)ufs_lookup.c 8.15 (Berkeley) 6/16/95
67 *
68 * (c) 1998-1999 Apple Inc. All Rights Reserved
69 * (c) 1990, 1992 NeXT Computer, Inc. All Rights Reserved
70 *
71 *
72 * hfs_lookup.c -- code to handle directory traversal on HFS/HFS+ volume
73 */
74
75 #include <sys/param.h>
76 #include <sys/file.h>
77 #include <sys/mount.h>
78 #include <sys/vnode.h>
79 #include <sys/malloc.h>
80 #include <sys/kdebug.h>
81 #include <sys/kauth.h>
82 #include <sys/namei.h>
83 #include <sys/user.h>
84
85 #include "hfs.h"
86 #include "hfs_catalog.h"
87 #include "hfs_cnode.h"
88
89
90 /*
91 * FROM FREEBSD 3.1
92 * Convert a component of a pathname into a pointer to a locked cnode.
93 * This is a very central and rather complicated routine.
94 * If the file system is not maintained in a strict tree hierarchy,
95 * this can result in a deadlock situation (see comments in code below).
96 *
97 * The cnp->cn_nameiop argument is LOOKUP, CREATE, RENAME, or DELETE depending
98 * on whether the name is to be looked up, created, renamed, or deleted.
99 * When CREATE, RENAME, or DELETE is specified, information usable in
100 * creating, renaming, or deleting a directory entry may be calculated.
101 * Notice that these are the only operations that can affect the directory of the target.
102 *
103 * LOCKPARENT and WANTPARENT actually refer to the parent of the last item,
104 * so if ISLASTCN is not set, they should be ignored. Also they are mutually exclusive, or
105 * WANTPARENT really implies DONTLOCKPARENT. Either of them set means that the calling
106 * routine wants to access the parent of the target, locked or unlocked.
107 *
108 * Keeping the parent locked as long as possible protects from other processes
109 * looking up the same item, so it has to be locked until the cnode is totally finished
110 *
111 * hfs_cache_lookup() performs the following for us:
112 * check that it is a directory
113 * check accessibility of directory
114 * check for modification attempts on read-only mounts
115 * if name found in cache
116 * if at end of path and deleting or creating
117 * drop it
118 * else
119 * return name.
120 * return hfs_lookup()
121 *
122 * Overall outline of hfs_lookup:
123 *
124 * handle simple cases of . and ..
125 * search for name in directory, to found or notfound
126 * notfound:
127 * if creating, return locked directory, leaving info on available slots
128 * else return error
129 * found:
130 * if at end of path and deleting, return information to allow delete
131 * if at end of path and rewriting (RENAME and LOCKPARENT), lock target
132 * cnode and return info to allow rewrite
133 * if not at end, add name to cache; if at end and neither creating
134 * nor deleting, add name to cache
135 */
136
137
138 /*
139 * Lookup *cnp in directory *dvp, return it in *vpp.
140 * **vpp is held on exit.
141 * We create a cnode for the file, but we do NOT open the file here.
142
143 #% lookup dvp L ? ?
144 #% lookup vpp - L -
145
146 IN struct vnode *dvp - Parent node of file;
147 INOUT struct vnode **vpp - node of target file, its a new node if
148 the target vnode did not exist;
149 IN struct componentname *cnp - Name of file;
150
151 * When should we lock parent_hp in here ??
152 */
153 static int
154 hfs_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, int *cnode_locked, int force_casesensitive_lookup)
155 {
156 struct cnode *dcp; /* cnode for directory being searched */
157 struct vnode *tvp; /* target vnode */
158 struct hfsmount *hfsmp;
159 int flags;
160 int nameiop;
161 int retval = 0;
162 int isDot;
163 struct cat_desc desc;
164 struct cat_desc cndesc;
165 struct cat_attr attr;
166 struct cat_fork fork;
167 int lockflags;
168 int newvnode_flags;
169
170 retry:
171 newvnode_flags = 0;
172 dcp = NULL;
173 hfsmp = VTOHFS(dvp);
174 *vpp = NULL;
175 *cnode_locked = 0;
176 isDot = FALSE;
177 tvp = NULL;
178 nameiop = cnp->cn_nameiop;
179 flags = cnp->cn_flags;
180 bzero(&desc, sizeof(desc));
181
182 /*
183 * First check to see if it is a . or .., else look it up.
184 */
185 if (flags & ISDOTDOT) { /* Wanting the parent */
186 cnp->cn_flags &= ~MAKEENTRY;
187 goto found; /* .. is always defined */
188 } else if ((cnp->cn_nameptr[0] == '.') && (cnp->cn_namelen == 1)) {
189 isDot = TRUE;
190 cnp->cn_flags &= ~MAKEENTRY;
191 goto found; /* We always know who we are */
192 } else {
193 if (hfs_lock(VTOC(dvp), HFS_EXCLUSIVE_LOCK, HFS_LOCK_DEFAULT) != 0) {
194 retval = ENOENT; /* The parent no longer exists ? */
195 goto exit;
196 }
197 dcp = VTOC(dvp);
198
199 if (dcp->c_flag & C_DIR_MODIFICATION) {
200 // This needs to be changed to sleep on c_flag using assert_wait.
201 // msleep((caddr_t)&dcp->c_flag, &dcp->c_rwlock, PINOD, "hfs_vnop_lookup", 0);
202 hfs_unlock(dcp);
203 tsleep((caddr_t)dvp, PRIBIO, "hfs_lookup", 1);
204
205 goto retry;
206 }
207
208
209 /*
210 * We shouldn't need to go to the catalog if there are no children.
211 * However, in the face of a minor disk corruption where the valence of
212 * the directory is off, we could infinite loop here if we return ENOENT
213 * even though there are actually items in the directory. (create will
214 * see the ENOENT, try to create something, which will return with
215 * EEXIST over and over again). As a result, always check the catalog.
216 */
217
218 bzero(&cndesc, sizeof(cndesc));
219 cndesc.cd_nameptr = (const u_int8_t *)cnp->cn_nameptr;
220 cndesc.cd_namelen = cnp->cn_namelen;
221 cndesc.cd_parentcnid = dcp->c_fileid;
222 cndesc.cd_hint = dcp->c_childhint;
223
224 lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_SHARED_LOCK);
225
226 retval = cat_lookup(hfsmp, &cndesc, 0, force_casesensitive_lookup, &desc, &attr, &fork, NULL);
227
228 hfs_systemfile_unlock(hfsmp, lockflags);
229
230 if (retval == 0) {
231 dcp->c_childhint = desc.cd_hint;
232 /*
233 * Note: We must drop the parent lock here before calling
234 * hfs_getnewvnode (which takes the child lock).
235 */
236 hfs_unlock(dcp);
237 dcp = NULL;
238
239 /* Verify that the item just looked up isn't one of the hidden directories. */
240 if (desc.cd_cnid == hfsmp->hfs_private_desc[FILE_HARDLINKS].cd_cnid ||
241 desc.cd_cnid == hfsmp->hfs_private_desc[DIR_HARDLINKS].cd_cnid) {
242 retval = ENOENT;
243 goto exit;
244 }
245
246 goto found;
247 }
248
249 if (retval == HFS_ERESERVEDNAME) {
250 /*
251 * We found the name in the catalog, but it is unavailable
252 * to us. The exact error to return to our caller depends
253 * on the operation, and whether we've already reached the
254 * last path component. In all cases, avoid a negative
255 * cache entry, since someone else may be able to access
256 * the name if their lookup is configured differently.
257 */
258
259 cnp->cn_flags &= ~MAKEENTRY;
260
261 if (((flags & ISLASTCN) == 0) || ((nameiop == LOOKUP) || (nameiop == DELETE))) {
262 /* A reserved name for a pure lookup is the same as the path not being present */
263 retval = ENOENT;
264 } else {
265 /* A reserved name with intent to create must be rejected as impossible */
266 retval = EEXIST;
267 }
268 }
269 if (retval != ENOENT)
270 goto exit;
271 /*
272 * This is a non-existing entry
273 *
274 * If creating, and at end of pathname and current
275 * directory has not been removed, then can consider
276 * allowing file to be created.
277 */
278 if ((nameiop == CREATE || nameiop == RENAME) &&
279 (flags & ISLASTCN) &&
280 !(ISSET(dcp->c_flag, C_DELETED | C_NOEXISTS))) {
281 retval = EJUSTRETURN;
282 goto exit;
283 }
284 /*
285 * Insert name into the name cache (as non-existent).
286 */
287 #if CONFIG_HFS_STD
288 if ((hfsmp->hfs_flags & HFS_STANDARD) == 0)
289 #endif
290 {
291 if ((cnp->cn_flags & MAKEENTRY) &&
292 (nameiop != CREATE)) {
293 cache_enter(dvp, NULL, cnp);
294 dcp->c_flag |= C_NEG_ENTRIES;
295 }
296 }
297 goto exit;
298 }
299
300 found:
301 if (flags & ISLASTCN) {
302 switch(nameiop) {
303 case DELETE:
304 cnp->cn_flags &= ~MAKEENTRY;
305 break;
306
307 case RENAME:
308 cnp->cn_flags &= ~MAKEENTRY;
309 if (isDot) {
310 retval = EISDIR;
311 goto exit;
312 }
313 break;
314 }
315 }
316
317 if (isDot) {
318 if ((retval = vnode_get(dvp)))
319 goto exit;
320 *vpp = dvp;
321 } else if (flags & ISDOTDOT) {
322 /*
323 * Directory hard links can have multiple parents so
324 * find the appropriate parent for the current thread.
325 */
326 if ((retval = hfs_vget(hfsmp, hfs_currentparent(VTOC(dvp),
327 /* have_lock: */ false), &tvp, 0, 0))) {
328 goto exit;
329 }
330 *cnode_locked = 1;
331 *vpp = tvp;
332 } else {
333 int type = (attr.ca_mode & S_IFMT);
334
335 if (!(flags & ISLASTCN) && (type != S_IFDIR) && (type != S_IFLNK)) {
336 retval = ENOTDIR;
337 goto exit;
338 }
339 /* Don't cache directory hardlink names. */
340 if (attr.ca_recflags & kHFSHasLinkChainMask) {
341 cnp->cn_flags &= ~MAKEENTRY;
342 }
343 /* Names with composed chars are not cached. */
344 if (cnp->cn_namelen != desc.cd_namelen)
345 cnp->cn_flags &= ~MAKEENTRY;
346
347 retval = hfs_getnewvnode(hfsmp, dvp, cnp, &desc, 0, &attr, &fork, &tvp, &newvnode_flags);
348
349 if (retval) {
350 /*
351 * If this was a create/rename operation lookup, then by this point
352 * we expected to see the item returned from hfs_getnewvnode above.
353 * In the create case, it would probably eventually bubble out an EEXIST
354 * because the item existed when we were trying to create it. In the
355 * rename case, it would let us know that we need to go ahead and
356 * delete it as part of the rename. However, if we hit the condition below
357 * then it means that we found the element during cat_lookup above, but
358 * it is now no longer there. We simply behave as though we never found
359 * the element at all and return EJUSTRETURN.
360 */
361 if ((retval == ENOENT) &&
362 ((cnp->cn_nameiop == CREATE) || (cnp->cn_nameiop == RENAME)) &&
363 (flags & ISLASTCN)) {
364 retval = EJUSTRETURN;
365 }
366
367 /*
368 * If this was a straight lookup operation, we may need to redrive the entire
369 * lookup starting from cat_lookup if the element was deleted as the result of
370 * a rename operation. Since rename is supposed to guarantee atomicity, then
371 * lookups cannot fail because the underlying element is deleted as a result of
372 * the rename call -- either they returned the looked up element prior to rename
373 * or return the newer element. If we are in this region, then all we can do is add
374 * workarounds to guarantee the latter case. The element has already been deleted, so
375 * we just re-try the lookup to ensure the caller gets the most recent element.
376 */
377 if ((retval == ENOENT) && (cnp->cn_nameiop == LOOKUP) &&
378 (newvnode_flags & (GNV_CHASH_RENAMED | GNV_CAT_DELETED))) {
379 if (dcp) {
380 hfs_unlock (dcp);
381 }
382 /* get rid of any name buffers that may have lingered from the cat_lookup call */
383 cat_releasedesc (&desc);
384 goto retry;
385 }
386
387 /* Also, re-drive the lookup if the item we looked up was a hardlink, and the number
388 * or name of hardlinks has changed in the interim between the cat_lookup above, and
389 * our call to hfs_getnewvnode. hfs_getnewvnode will validate the cattr we passed it
390 * against what is actually in the catalog after the cnode is created. If there were
391 * any issues, it will bubble out ERECYCLE, which we need to swallow and use as the
392 * key to redrive as well. We need to special case this below because in this case,
393 * it needs to occur regardless of the type of lookup we're doing here.
394 */
395 if ((retval == ERECYCLE) && (newvnode_flags & GNV_CAT_ATTRCHANGED)) {
396 if (dcp) {
397 hfs_unlock (dcp);
398 }
399 /* get rid of any name buffers that may have lingered from the cat_lookup call */
400 cat_releasedesc (&desc);
401 retval = 0;
402 goto retry;
403 }
404
405 /* skip to the error-handling code if we can't retry */
406 goto exit;
407 }
408
409 /*
410 * Save the origin info for file and directory hardlinks. Directory hardlinks
411 * need the origin for '..' lookups, and file hardlinks need it to ensure that
412 * competing lookups do not cause us to vend different hardlinks than the ones requested.
413 */
414 if (ISSET(VTOC(tvp)->c_flag, C_HARDLINK))
415 hfs_savelinkorigin(VTOC(tvp), VTOC(dvp)->c_fileid);
416 *cnode_locked = 1;
417 *vpp = tvp;
418 }
419 exit:
420 if (dcp) {
421 hfs_unlock(dcp);
422 }
423 cat_releasedesc(&desc);
424 return (retval);
425 }
426
427
428
429 /*
430 * Name caching works as follows:
431 *
432 * Names found by directory scans are retained in a cache
433 * for future reference. It is managed LRU, so frequently
434 * used names will hang around. Cache is indexed by hash value
435 * obtained from (vp, name) where vp refers to the directory
436 * containing name.
437 *
438 * If it is a "negative" entry, (i.e. for a name that is known NOT to
439 * exist) the vnode pointer will be NULL.
440 *
441 * Upon reaching the last segment of a path, if the reference
442 * is for DELETE, or NOCACHE is set (rewrite), and the
443 * name is located in the cache, it will be dropped.
444 *
445 */
446
447 int
448 hfs_vnop_lookup(struct vnop_lookup_args *ap)
449 {
450 struct vnode *dvp = ap->a_dvp;
451 struct vnode *vp;
452 struct cnode *cp;
453 struct cnode *dcp;
454 struct hfsmount *hfsmp;
455 int error;
456 struct vnode **vpp = ap->a_vpp;
457 struct componentname *cnp = ap->a_cnp;
458 int flags = cnp->cn_flags;
459 struct proc *p = vfs_context_proc(ap->a_context);
460 int force_casesensitive_lookup = proc_is_forcing_hfs_case_sensitivity(p);
461 int cnode_locked;
462 int fastdev_candidate = 0;
463 int auto_candidate = 0;
464
465 *vpp = NULL;
466 dcp = VTOC(dvp);
467 hfsmp = VTOHFS(dvp);
468
469 if ((hfsmp->hfs_flags & HFS_CS_HOTFILE_PIN) && (vnode_isfastdevicecandidate(dvp) || (dcp->c_attr.ca_recflags & kHFSFastDevCandidateMask)) ){
470 fastdev_candidate = 1;
471 auto_candidate = (vnode_isautocandidate(dvp) || (dcp->c_attr.ca_recflags & kHFSAutoCandidateMask));
472 }
473
474
475 /*
476 * Lookup an entry in the cache
477 *
478 * If the lookup succeeds, the vnode is returned in *vpp,
479 * and a status of -1 is returned.
480 *
481 * If the lookup determines that the name does not exist
482 * (negative cacheing), a status of ENOENT is returned.
483 *
484 * If the lookup fails, a status of zero is returned.
485 */
486 error = cache_lookup(dvp, vpp, cnp);
487 if (error != -1) {
488 if ((error == ENOENT) && (cnp->cn_nameiop != CREATE))
489 goto exit; /* found a negative cache entry */
490 goto lookup; /* did not find it in the cache */
491 }
492 /*
493 * We have a name that matched
494 * cache_lookup returns the vp with an iocount reference already taken
495 */
496 error = 0;
497 vp = *vpp;
498 cp = VTOC(vp);
499
500 /* We aren't allowed to vend out vp's via lookup to the hidden directory */
501 if (cp->c_cnid == hfsmp->hfs_private_desc[FILE_HARDLINKS].cd_cnid ||
502 cp->c_cnid == hfsmp->hfs_private_desc[DIR_HARDLINKS].cd_cnid) {
503 /* Drop the iocount from cache_lookup */
504 vnode_put (vp);
505 error = ENOENT;
506 goto exit;
507 }
508
509 if (cp->c_attr.ca_recflags & kHFSDoNotFastDevPinMask) {
510 fastdev_candidate = 0;
511 }
512
513 /*
514 * If this is a hard-link vnode then we need to update
515 * the name (of the link), the parent ID, the cnid, the
516 * text encoding and the catalog hint. This enables
517 * getattrlist calls to return the correct link info.
518 */
519
520 /*
521 * Alternatively, if we are forcing a case-sensitive lookup
522 * on a case-insensitive volume, the namecache entry
523 * may have been for an incorrect case. Since we cannot
524 * determine case vs. normalization, redrive the catalog
525 * lookup based on any byte mismatch.
526 */
527 if (((flags & ISLASTCN) && (cp->c_flag & C_HARDLINK))
528 || (force_casesensitive_lookup && !(hfsmp->hfs_flags & HFS_CASE_SENSITIVE))) {
529 int stale_link = 0;
530
531 hfs_lock(cp, HFS_EXCLUSIVE_LOCK, HFS_LOCK_ALLOW_NOEXISTS);
532 if ((cp->c_parentcnid != dcp->c_cnid) ||
533 (cnp->cn_namelen != cp->c_desc.cd_namelen) ||
534 (bcmp(cnp->cn_nameptr, cp->c_desc.cd_nameptr, cp->c_desc.cd_namelen) != 0)) {
535 struct cat_desc desc;
536 struct cat_attr lookup_attr;
537 int lockflags;
538
539 if (force_casesensitive_lookup && !(hfsmp->hfs_flags & HFS_CASE_SENSITIVE)) {
540 /*
541 * Since the name in the cnode doesn't match our lookup
542 * string exactly, do a full lookup.
543 */
544 hfs_unlock (cp);
545
546 vnode_put(vp);
547 goto lookup;
548 }
549
550 /*
551 * Get an updated descriptor
552 */
553 desc.cd_nameptr = (const u_int8_t *)cnp->cn_nameptr;
554 desc.cd_namelen = cnp->cn_namelen;
555 desc.cd_parentcnid = dcp->c_fileid;
556 desc.cd_hint = dcp->c_childhint;
557 desc.cd_encoding = 0;
558 desc.cd_cnid = 0;
559 desc.cd_flags = S_ISDIR(cp->c_mode) ? CD_ISDIR : 0;
560
561 /*
562 * Because lookups call replace_desc to put a new descriptor in
563 * the cnode we are modifying it is possible that this cnode's
564 * descriptor is out of date for the parent ID / name that
565 * we are trying to look up. (It may point to a different hardlink).
566 *
567 * We need to be cautious that when re-supplying the
568 * descriptor below that the results of the catalog lookup
569 * still point to the same raw inode for the hardlink. This would
570 * not be the case if we found something in the cache above but
571 * the vnode it returned no longer has a valid hardlink for the
572 * parent ID/filename combo we are requesting. (This is because
573 * hfs_unlink does not directly trigger namecache removal).
574 *
575 * As a result, before vending out the vnode (and replacing
576 * its descriptor) verify that the fileID is the same by comparing
577 * the in-cnode attributes vs. the one returned from the lookup call
578 * below. If they do not match, treat this lookup as if we never hit
579 * in the cache at all.
580 */
581
582 lockflags = hfs_systemfile_lock(VTOHFS(dvp), SFL_CATALOG, HFS_SHARED_LOCK);
583
584 error = cat_lookup(VTOHFS(vp), &desc, 0, 0, &desc, &lookup_attr, NULL, NULL);
585
586 hfs_systemfile_unlock(VTOHFS(dvp), lockflags);
587
588 /*
589 * Note that cat_lookup may fail to find something with the name provided in the
590 * stack-based descriptor above. In that case, an ENOENT is a legitimate errno
591 * to be placed in error, which will get returned in the fastpath below.
592 */
593 if (error == 0) {
594 if (lookup_attr.ca_fileid == cp->c_attr.ca_fileid) {
595 /* It still points to the right raw inode. Replacing the descriptor is fine */
596 replace_desc (cp, &desc);
597
598 /*
599 * Save the origin info for file and directory hardlinks. Directory hardlinks
600 * need the origin for '..' lookups, and file hardlinks need it to ensure that
601 * competing lookups do not cause us to vend different hardlinks than the ones requested.
602 */
603 hfs_savelinkorigin(cp, dcp->c_fileid);
604 }
605 else {
606 /* If the fileID does not match then do NOT replace the descriptor! */
607 stale_link = 1;
608 }
609 }
610 }
611 hfs_unlock (cp);
612
613 if (stale_link) {
614 /*
615 * If we had a stale_link, then we need to pretend as though
616 * we never found this vnode and force a lookup through the
617 * traditional path. Drop the iocount acquired through
618 * cache_lookup above and force a cat lookup / getnewvnode
619 */
620 vnode_put(vp);
621 goto lookup;
622 }
623
624 if (error) {
625 /*
626 * If the cat_lookup failed then the caller will not expect
627 * a vnode with an iocount on it.
628 */
629 vnode_put(vp);
630 }
631
632 }
633 goto exit;
634
635 lookup:
636 /*
637 * The vnode was not in the name cache or it was stale.
638 *
639 * So we need to do a real lookup.
640 */
641 cnode_locked = 0;
642
643 error = hfs_lookup(dvp, vpp, cnp, &cnode_locked, force_casesensitive_lookup);
644
645 if (*vpp && (VTOC(*vpp)->c_attr.ca_recflags & kHFSDoNotFastDevPinMask)) {
646 fastdev_candidate = 0;
647 }
648
649 if (*vpp && (VTOC(*vpp)->c_attr.ca_recflags & kHFSAutoCandidateMask)) {
650 //printf("vp %s / %d is an auto-candidate\n", (*vpp)->v_name ? (*vpp)->v_name : "no-name", VTOC(*vpp)->c_fileid);
651 auto_candidate = 1;
652 }
653
654 if (cnode_locked)
655 hfs_unlock(VTOC(*vpp));
656 exit:
657 if (*vpp && fastdev_candidate && !vnode_isfastdevicecandidate(*vpp)) {
658 vnode_setfastdevicecandidate(*vpp);
659 if (auto_candidate) {
660 vnode_setautocandidate(*vpp);
661 }
662 }
663
664 /*
665 * check to see if we issued any I/O while completing this lookup and
666 * this thread/task is throttleable... if so, throttle now
667 *
668 * this allows us to throttle in between multiple meta data reads that
669 * might result due to looking up a long pathname (since we'll have to
670 * re-enter hfs_vnop_lookup for each component of the pathnam not in
671 * the VFS cache), instead of waiting until the entire path lookup has
672 * completed and throttling at the systemcall return
673 */
674 if (__builtin_expect(throttle_lowpri_window(), 0))
675 throttle_lowpri_io(1);
676
677 return (error);
678 }
679
680