]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 1999-2005 Apple Computer, Inc. All rights reserved. |
1c79356b A |
3 | * |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
e5568f75 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
e5568f75 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * Copyright (c) 1989, 1993 | |
24 | * The Regents of the University of California. All rights reserved. | |
25 | * (c) UNIX System Laboratories, Inc. | |
26 | * All or some portions of this file are derived from material licensed | |
27 | * to the University of California by American Telephone and Telegraph | |
28 | * Co. or Unix System Laboratories, Inc. and are reproduced herein with | |
29 | * the permission of UNIX System Laboratories, Inc. | |
30 | * | |
31 | * Redistribution and use in source and binary forms, with or without | |
32 | * modification, are permitted provided that the following conditions | |
33 | * are met: | |
34 | * 1. Redistributions of source code must retain the above copyright | |
35 | * notice, this list of conditions and the following disclaimer. | |
36 | * 2. Redistributions in binary form must reproduce the above copyright | |
37 | * notice, this list of conditions and the following disclaimer in the | |
38 | * documentation and/or other materials provided with the distribution. | |
39 | * 3. All advertising materials mentioning features or use of this software | |
40 | * must display the following acknowledgement: | |
41 | * This product includes software developed by the University of | |
42 | * California, Berkeley and its contributors. | |
43 | * 4. Neither the name of the University nor the names of its contributors | |
44 | * may be used to endorse or promote products derived from this software | |
45 | * without specific prior written permission. | |
46 | * | |
47 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
48 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
49 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
50 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
51 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
52 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
53 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
54 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
55 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
56 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
57 | * SUCH DAMAGE. | |
58 | * | |
59 | * @(#)hfs_lookup.c 1.0 | |
60 | * derived from @(#)ufs_lookup.c 8.15 (Berkeley) 6/16/95 | |
61 | * | |
62 | * (c) 1998-1999 Apple Computer, Inc. All Rights Reserved | |
63 | * (c) 1990, 1992 NeXT Computer, Inc. All Rights Reserved | |
64 | * | |
65 | * | |
66 | * hfs_lookup.c -- code to handle directory traversal on HFS/HFS+ volume | |
1c79356b A |
67 | */ |
68 | ||
69 | #include <sys/param.h> | |
1c79356b A |
70 | #include <sys/file.h> |
71 | #include <sys/mount.h> | |
72 | #include <sys/vnode.h> | |
73 | #include <sys/malloc.h> | |
74 | #include <sys/paths.h> | |
91447636 A |
75 | #include <sys/kdebug.h> |
76 | #include <sys/kauth.h> | |
1c79356b | 77 | |
9bccf70c A |
78 | #include "hfs.h" |
79 | #include "hfs_catalog.h" | |
80 | #include "hfs_cnode.h" | |
1c79356b | 81 | |
91447636 | 82 | #define LEGACY_FORK_NAMES 1 |
1c79356b | 83 | |
9bccf70c | 84 | static int forkcomponent(struct componentname *cnp, int *rsrcfork); |
1c79356b | 85 | |
9bccf70c | 86 | #define _PATH_DATAFORKSPEC "/..namedfork/data" |
1c79356b | 87 | |
91447636 | 88 | #if LEGACY_FORK_NAMES |
9bccf70c | 89 | #define LEGACY_RSRCFORKSPEC "/rsrc" |
1c79356b A |
90 | #endif |
91 | ||
1c79356b A |
92 | /* |
93 | * FROM FREEBSD 3.1 | |
9bccf70c | 94 | * Convert a component of a pathname into a pointer to a locked cnode. |
1c79356b A |
95 | * This is a very central and rather complicated routine. |
96 | * If the file system is not maintained in a strict tree hierarchy, | |
97 | * this can result in a deadlock situation (see comments in code below). | |
98 | * | |
99 | * The cnp->cn_nameiop argument is LOOKUP, CREATE, RENAME, or DELETE depending | |
100 | * on whether the name is to be looked up, created, renamed, or deleted. | |
101 | * When CREATE, RENAME, or DELETE is specified, information usable in | |
102 | * creating, renaming, or deleting a directory entry may be calculated. | |
103 | * Notice that these are the only operations that can affect the directory of the target. | |
104 | * | |
1c79356b A |
105 | * LOCKPARENT and WANTPARENT actually refer to the parent of the last item, |
106 | * so if ISLASTCN is not set, they should be ignored. Also they are mutually exclusive, or | |
107 | * WANTPARENT really implies DONTLOCKPARENT. Either of them set means that the calling | |
108 | * routine wants to access the parent of the target, locked or unlocked. | |
109 | * | |
110 | * Keeping the parent locked as long as possible protects from other processes | |
9bccf70c | 111 | * looking up the same item, so it has to be locked until the cnode is totally finished |
1c79356b | 112 | * |
1c79356b A |
113 | * hfs_cache_lookup() performs the following for us: |
114 | * check that it is a directory | |
115 | * check accessibility of directory | |
116 | * check for modification attempts on read-only mounts | |
117 | * if name found in cache | |
118 | * if at end of path and deleting or creating | |
119 | * drop it | |
120 | * else | |
121 | * return name. | |
91447636 | 122 | * return hfs_lookup() |
1c79356b A |
123 | * |
124 | * Overall outline of hfs_lookup: | |
125 | * | |
126 | * handle simple cases of . and .. | |
127 | * search for name in directory, to found or notfound | |
128 | * notfound: | |
129 | * if creating, return locked directory, leaving info on available slots | |
130 | * else return error | |
131 | * found: | |
132 | * if at end of path and deleting, return information to allow delete | |
133 | * if at end of path and rewriting (RENAME and LOCKPARENT), lock target | |
9bccf70c | 134 | * cnode and return info to allow rewrite |
1c79356b A |
135 | * if not at end, add name to cache; if at end and neither creating |
136 | * nor deleting, add name to cache | |
137 | */ | |
138 | ||
91447636 | 139 | |
1c79356b | 140 | /* |
91447636 A |
141 | * Lookup *cnp in directory *dvp, return it in *vpp. |
142 | * **vpp is held on exit. | |
9bccf70c | 143 | * We create a cnode for the file, but we do NOT open the file here. |
1c79356b A |
144 | |
145 | #% lookup dvp L ? ? | |
146 | #% lookup vpp - L - | |
147 | ||
148 | IN struct vnode *dvp - Parent node of file; | |
9bccf70c A |
149 | INOUT struct vnode **vpp - node of target file, its a new node if |
150 | the target vnode did not exist; | |
1c79356b A |
151 | IN struct componentname *cnp - Name of file; |
152 | ||
153 | * When should we lock parent_hp in here ?? | |
154 | */ | |
91447636 A |
155 | static int |
156 | hfs_lookup(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp, vfs_context_t context, int *cnode_locked) | |
1c79356b | 157 | { |
9bccf70c A |
158 | struct cnode *dcp; /* cnode for directory being searched */ |
159 | struct vnode *tvp; /* target vnode */ | |
160 | struct hfsmount *hfsmp; | |
91447636 | 161 | kauth_cred_t cred; |
9bccf70c A |
162 | struct proc *p; |
163 | int wantrsrc = 0; | |
164 | int forknamelen = 0; | |
165 | int flags; | |
9bccf70c A |
166 | int nameiop; |
167 | int retval = 0; | |
168 | int isDot; | |
91447636 | 169 | struct cat_desc desc; |
9bccf70c A |
170 | struct cat_desc cndesc; |
171 | struct cat_attr attr; | |
172 | struct cat_fork fork; | |
91447636 | 173 | int lockflags; |
9bccf70c | 174 | |
9bccf70c A |
175 | dcp = VTOC(dvp); |
176 | hfsmp = VTOHFS(dvp); | |
177 | *vpp = NULL; | |
91447636 | 178 | *cnode_locked = 0; |
9bccf70c A |
179 | isDot = FALSE; |
180 | tvp = NULL; | |
181 | nameiop = cnp->cn_nameiop; | |
9bccf70c | 182 | flags = cnp->cn_flags; |
91447636 A |
183 | bzero(&desc, sizeof(desc)); |
184 | ||
185 | cred = vfs_context_ucred(context); | |
186 | p = vfs_context_proc(context); | |
1c79356b A |
187 | |
188 | /* | |
189 | * First check to see if it is a . or .., else look it up. | |
190 | */ | |
9bccf70c | 191 | if (flags & ISDOTDOT) { /* Wanting the parent */ |
91447636 | 192 | cnp->cn_flags &= ~MAKEENTRY; |
9bccf70c A |
193 | goto found; /* .. is always defined */ |
194 | } else if ((cnp->cn_nameptr[0] == '.') && (cnp->cn_namelen == 1)) { | |
1c79356b | 195 | isDot = TRUE; |
91447636 | 196 | cnp->cn_flags &= ~MAKEENTRY; |
9bccf70c A |
197 | goto found; /* We always know who we are */ |
198 | } else { | |
199 | /* Check fork suffix to see if we want the resource fork */ | |
200 | forknamelen = forkcomponent(cnp, &wantrsrc); | |
91447636 A |
201 | |
202 | /* Resource fork names are not cached. */ | |
203 | if (wantrsrc) | |
204 | cnp->cn_flags &= ~MAKEENTRY; | |
205 | ||
206 | if (hfs_lock(dcp, HFS_EXCLUSIVE_LOCK) != 0) { | |
207 | goto notfound; | |
208 | } | |
1c79356b | 209 | |
9bccf70c | 210 | /* No need to go to catalog if there are no children */ |
91447636 A |
211 | if (dcp->c_entries == 0) { |
212 | hfs_unlock(dcp); | |
9bccf70c | 213 | goto notfound; |
91447636 | 214 | } |
1c79356b | 215 | |
9bccf70c A |
216 | bzero(&cndesc, sizeof(cndesc)); |
217 | cndesc.cd_nameptr = cnp->cn_nameptr; | |
218 | cndesc.cd_namelen = cnp->cn_namelen; | |
219 | cndesc.cd_parentcnid = dcp->c_cnid; | |
220 | cndesc.cd_hint = dcp->c_childhint; | |
1c79356b | 221 | |
91447636 A |
222 | lockflags = hfs_systemfile_lock(hfsmp, SFL_CATALOG, HFS_SHARED_LOCK); |
223 | ||
224 | retval = cat_lookup(hfsmp, &cndesc, wantrsrc, &desc, &attr, &fork, NULL); | |
9bccf70c | 225 | |
91447636 A |
226 | hfs_systemfile_unlock(hfsmp, lockflags); |
227 | ||
9bccf70c A |
228 | if (retval == 0) { |
229 | dcp->c_childhint = desc.cd_hint; | |
91447636 | 230 | hfs_unlock(dcp); |
9bccf70c A |
231 | goto found; |
232 | } | |
91447636 | 233 | hfs_unlock(dcp); |
9bccf70c | 234 | notfound: |
91447636 A |
235 | /* ENAMETOOLONG supersedes other errors */ |
236 | if (((nameiop != CREATE) && (nameiop != RENAME)) && | |
237 | (retval != ENAMETOOLONG) && | |
238 | (cnp->cn_namelen > kHFSPlusMaxFileNameChars)) { | |
239 | retval = ENAMETOOLONG; | |
240 | } else if (retval == 0) { | |
241 | retval = ENOENT; | |
242 | } | |
9bccf70c A |
243 | /* |
244 | * This is a non-existing entry | |
245 | * | |
246 | * If creating, and at end of pathname and current | |
247 | * directory has not been removed, then can consider | |
248 | * allowing file to be created. | |
249 | */ | |
250 | if ((nameiop == CREATE || nameiop == RENAME || | |
251 | (nameiop == DELETE && | |
91447636 A |
252 | (cnp->cn_flags & DOWHITEOUT) && |
253 | (cnp->cn_flags & ISWHITEOUT))) && | |
254 | (flags & ISLASTCN) && | |
255 | (retval == ENOENT)) { | |
9bccf70c A |
256 | retval = EJUSTRETURN; |
257 | goto exit; | |
1c79356b | 258 | } |
1c79356b A |
259 | /* |
260 | * Insert name into cache (as non-existent) if appropriate. | |
9bccf70c | 261 | * |
55e303ae | 262 | * Only done for case-sensitive HFS+ volumes. |
1c79356b | 263 | */ |
91447636 A |
264 | if ((retval == ENOENT) && |
265 | (hfsmp->hfs_flags & HFS_CASE_SENSITIVE) && | |
266 | (cnp->cn_flags & MAKEENTRY) && nameiop != CREATE) { | |
267 | cache_enter(dvp, NULL, cnp); | |
268 | } | |
9bccf70c | 269 | goto exit; |
1c79356b | 270 | } |
1c79356b | 271 | |
9bccf70c A |
272 | found: |
273 | /* | |
274 | * Process any fork specifiers | |
275 | */ | |
276 | if (forknamelen && S_ISREG(attr.ca_mode)) { | |
277 | /* fork names are only for lookups */ | |
278 | if ((nameiop != LOOKUP) && (nameiop != CREATE)) { | |
279 | retval = EPERM; | |
280 | goto exit; | |
281 | } | |
282 | cnp->cn_consume = forknamelen; | |
283 | flags |= ISLASTCN; | |
284 | } else { | |
285 | wantrsrc = 0; | |
286 | forknamelen = 0; | |
287 | } | |
91447636 A |
288 | if (flags & ISLASTCN) { |
289 | switch(nameiop) { | |
290 | case DELETE: | |
291 | cnp->cn_flags &= ~MAKEENTRY; | |
292 | break; | |
293 | ||
294 | case RENAME: | |
295 | cnp->cn_flags &= ~MAKEENTRY; | |
296 | if (isDot) { | |
297 | retval = EISDIR; | |
9bccf70c | 298 | goto exit; |
91447636 A |
299 | } |
300 | break; | |
1c79356b | 301 | } |
91447636 | 302 | } |
9bccf70c | 303 | |
91447636 A |
304 | if (isDot) { |
305 | if ((retval = vnode_get(dvp))) | |
9bccf70c | 306 | goto exit; |
91447636 A |
307 | *vpp = dvp; |
308 | } else if (flags & ISDOTDOT) { | |
309 | if ((retval = hfs_vget(hfsmp, dcp->c_parentcnid, &tvp, 0))) | |
9bccf70c | 310 | goto exit; |
91447636 | 311 | *cnode_locked = 1; |
9bccf70c | 312 | *vpp = tvp; |
9bccf70c A |
313 | } else { |
314 | int type = (attr.ca_mode & S_IFMT); | |
1c79356b | 315 | |
91447636 | 316 | if (!(flags & ISLASTCN) && (type != S_IFDIR) && (type != S_IFLNK)) { |
9bccf70c A |
317 | retval = ENOTDIR; |
318 | goto exit; | |
1c79356b | 319 | } |
1c79356b | 320 | |
91447636 A |
321 | /* Names with composed chars are not cached. */ |
322 | if (cnp->cn_namelen != desc.cd_namelen) | |
323 | cnp->cn_flags &= ~MAKEENTRY; | |
1c79356b | 324 | |
91447636 A |
325 | /* Resource fork vnode names include the fork specifier. */ |
326 | if (wantrsrc && (flags & ISLASTCN)) | |
327 | cnp->cn_namelen += forknamelen; | |
1c79356b | 328 | |
91447636 | 329 | retval = hfs_getnewvnode(hfsmp, dvp, cnp, &desc, wantrsrc, &attr, &fork, &tvp); |
1c79356b | 330 | |
91447636 A |
331 | if (wantrsrc && (flags & ISLASTCN)) |
332 | cnp->cn_namelen -= forknamelen; | |
55e303ae | 333 | |
91447636 A |
334 | if (retval) |
335 | goto exit; | |
336 | *cnode_locked = 1; | |
337 | *vpp = tvp; | |
55e303ae | 338 | } |
9bccf70c A |
339 | exit: |
340 | cat_releasedesc(&desc); | |
1c79356b A |
341 | return (retval); |
342 | } | |
343 | ||
344 | ||
345 | ||
346 | /* | |
1c79356b A |
347 | * Name caching works as follows: |
348 | * | |
349 | * Names found by directory scans are retained in a cache | |
350 | * for future reference. It is managed LRU, so frequently | |
351 | * used names will hang around. Cache is indexed by hash value | |
352 | * obtained from (vp, name) where vp refers to the directory | |
353 | * containing name. | |
354 | * | |
355 | * If it is a "negative" entry, (i.e. for a name that is known NOT to | |
356 | * exist) the vnode pointer will be NULL. | |
357 | * | |
358 | * Upon reaching the last segment of a path, if the reference | |
359 | * is for DELETE, or NOCACHE is set (rewrite), and the | |
360 | * name is located in the cache, it will be dropped. | |
361 | * | |
1c79356b A |
362 | */ |
363 | ||
55e303ae A |
364 | #define S_IXALL 0000111 |
365 | ||
9bccf70c | 366 | __private_extern__ |
1c79356b | 367 | int |
91447636 | 368 | hfs_vnop_lookup(struct vnop_lookup_args *ap) |
1c79356b | 369 | { |
91447636 | 370 | struct vnode *dvp = ap->a_dvp; |
9bccf70c A |
371 | struct vnode *vp; |
372 | struct cnode *cp; | |
55e303ae | 373 | struct cnode *dcp; |
1c79356b A |
374 | int error; |
375 | struct vnode **vpp = ap->a_vpp; | |
9bccf70c | 376 | struct componentname *cnp = ap->a_cnp; |
1c79356b | 377 | int flags = cnp->cn_flags; |
91447636 | 378 | int cnode_locked; |
1c79356b | 379 | |
91447636 | 380 | *vpp = NULL; |
55e303ae | 381 | dcp = VTOC(dvp); |
1c79356b A |
382 | |
383 | /* | |
384 | * Lookup an entry in the cache | |
91447636 A |
385 | * |
386 | * If the lookup succeeds, the vnode is returned in *vpp, | |
387 | * and a status of -1 is returned. | |
388 | * | |
389 | * If the lookup determines that the name does not exist | |
390 | * (negative cacheing), a status of ENOENT is returned. | |
391 | * | |
392 | * If the lookup fails, a status of zero is returned. | |
1c79356b | 393 | */ |
9bccf70c | 394 | error = cache_lookup(dvp, vpp, cnp); |
55e303ae | 395 | if (error != -1) { |
91447636 A |
396 | if (error == ENOENT) /* found a negative cache entry */ |
397 | goto exit; | |
398 | goto lookup; /* did not find it in the cache */ | |
9bccf70c | 399 | } |
91447636 A |
400 | /* |
401 | * We have a name that matched | |
402 | * cache_lookup returns the vp with an iocount reference already taken | |
403 | */ | |
404 | error = 0; | |
9bccf70c | 405 | vp = *vpp; |
9bccf70c | 406 | |
1c79356b A |
407 | /* |
408 | * If this is a hard-link vnode then we need to update | |
9bccf70c A |
409 | * the name (of the link), the parent ID, the cnid, the |
410 | * text encoding and the catalog hint. This enables | |
411 | * getattrlist calls to return the correct link info. | |
1c79356b | 412 | */ |
9bccf70c | 413 | cp = VTOC(vp); |
9bccf70c | 414 | |
91447636 A |
415 | if ((flags & ISLASTCN) && (cp->c_flag & C_HARDLINK)) { |
416 | hfs_lock(cp, HFS_FORCE_LOCK); | |
417 | if ((cp->c_parentcnid != VTOC(dvp)->c_cnid) || | |
418 | (bcmp(cnp->cn_nameptr, cp->c_desc.cd_nameptr, cp->c_desc.cd_namelen) != 0)) { | |
419 | struct cat_desc desc; | |
420 | int lockflags; | |
1c79356b | 421 | |
91447636 A |
422 | /* |
423 | * Get an updated descriptor | |
424 | */ | |
425 | bzero(&desc, sizeof(desc)); | |
426 | desc.cd_nameptr = cnp->cn_nameptr; | |
427 | desc.cd_namelen = cnp->cn_namelen; | |
428 | desc.cd_parentcnid = VTOC(dvp)->c_cnid; | |
429 | desc.cd_hint = VTOC(dvp)->c_childhint; | |
430 | ||
431 | lockflags = hfs_systemfile_lock(VTOHFS(dvp), SFL_CATALOG, HFS_SHARED_LOCK); | |
432 | if (cat_lookup(VTOHFS(vp), &desc, 0, &desc, NULL, NULL, NULL) == 0) | |
433 | replace_desc(cp, &desc); | |
434 | hfs_systemfile_unlock(VTOHFS(dvp), lockflags); | |
435 | } | |
436 | hfs_unlock(cp); | |
437 | } | |
438 | if (dvp != vp && !(flags & ISDOTDOT)) { | |
439 | if ((flags & ISLASTCN) == 0 && vnode_isreg(vp)) { | |
9bccf70c A |
440 | int wantrsrc = 0; |
441 | ||
442 | cnp->cn_consume = forkcomponent(cnp, &wantrsrc); | |
55e303ae A |
443 | if (cnp->cn_consume) { |
444 | flags |= ISLASTCN; | |
445 | /* Fork names are only for lookups */ | |
446 | if (cnp->cn_nameiop != LOOKUP && | |
447 | cnp->cn_nameiop != CREATE) { | |
91447636 | 448 | vnode_put(vp); |
55e303ae | 449 | error = EPERM; |
91447636 | 450 | goto exit; |
55e303ae A |
451 | } |
452 | } | |
91447636 A |
453 | /* |
454 | * Use cnode's rsrcfork vnode if possible. | |
455 | */ | |
55e303ae | 456 | if (wantrsrc) { |
91447636 A |
457 | int vid; |
458 | ||
459 | *vpp = NULL; | |
460 | ||
461 | if (cp->c_rsrc_vp == NULL) { | |
462 | vnode_put(vp); | |
463 | goto lookup; | |
55e303ae | 464 | } |
91447636 A |
465 | vid = vnode_vid(cp->c_rsrc_vp); |
466 | ||
467 | error = vnode_getwithvid(cp->c_rsrc_vp, vid); | |
468 | if (error) { | |
469 | vnode_put(vp); | |
470 | goto lookup; | |
471 | } | |
472 | *vpp = cp->c_rsrc_vp; | |
473 | vnode_put(vp); | |
474 | vp = *vpp; | |
55e303ae A |
475 | } |
476 | } | |
0b4e3aa0 | 477 | } |
91447636 A |
478 | return (error); |
479 | ||
480 | lookup: | |
1c79356b | 481 | /* |
91447636 A |
482 | * The vnode was not in the name cache or it was stale. |
483 | * | |
484 | * So we need to do a real lookup. | |
1c79356b | 485 | */ |
91447636 | 486 | cnode_locked = 0; |
55e303ae | 487 | |
91447636 A |
488 | error = hfs_lookup(dvp, vpp, cnp, ap->a_context, &cnode_locked); |
489 | ||
490 | if (cnode_locked) | |
491 | hfs_unlock(VTOC(*vpp)); | |
492 | exit: | |
55e303ae | 493 | return (error); |
1c79356b A |
494 | } |
495 | ||
9bccf70c | 496 | |
1c79356b | 497 | /* |
9bccf70c A |
498 | * forkcomponent - look for a fork suffix in the component name |
499 | * | |
1c79356b | 500 | */ |
9bccf70c A |
501 | static int |
502 | forkcomponent(struct componentname *cnp, int *rsrcfork) | |
1c79356b | 503 | { |
9bccf70c A |
504 | char *suffix = cnp->cn_nameptr + cnp->cn_namelen; |
505 | int consume = 0; | |
1c79356b | 506 | |
9bccf70c A |
507 | *rsrcfork = 0; |
508 | if (*suffix == '\0') | |
509 | return (0); | |
510 | /* | |
511 | * There are only 3 valid fork suffixes: | |
512 | * "/..namedfork/rsrc" | |
513 | * "/..namedfork/data" | |
514 | * "/rsrc" (legacy) | |
515 | */ | |
516 | if (bcmp(suffix, _PATH_RSRCFORKSPEC, sizeof(_PATH_RSRCFORKSPEC)) == 0) { | |
517 | consume = sizeof(_PATH_RSRCFORKSPEC) - 1; | |
518 | *rsrcfork = 1; | |
519 | } else if (bcmp(suffix, _PATH_DATAFORKSPEC, sizeof(_PATH_DATAFORKSPEC)) == 0) { | |
520 | consume = sizeof(_PATH_DATAFORKSPEC) - 1; | |
1c79356b A |
521 | } |
522 | ||
91447636 | 523 | #if LEGACY_FORK_NAMES |
9bccf70c A |
524 | else if (bcmp(suffix, LEGACY_RSRCFORKSPEC, sizeof(LEGACY_RSRCFORKSPEC)) == 0) { |
525 | consume = sizeof(LEGACY_RSRCFORKSPEC) - 1; | |
526 | *rsrcfork = 1; | |
91447636 | 527 | printf("HFS: /rsrc paths are deprecated (%s)\n", cnp->cn_nameptr); |
1c79356b | 528 | } |
9bccf70c A |
529 | #endif |
530 | return (consume); | |
1c79356b A |
531 | } |
532 |