]> git.saurik.com Git - apple/xnu.git/blob - bsd/hfs/hfs_lookup.c
xnu-344.21.73.tar.gz
[apple/xnu.git] / bsd / hfs / hfs_lookup.c
1 /*
2 * Copyright (c) 1999-2002 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * Copyright (c) 1989, 1993
27 * The Regents of the University of California. All rights reserved.
28 * (c) UNIX System Laboratories, Inc.
29 * All or some portions of this file are derived from material licensed
30 * to the University of California by American Telephone and Telegraph
31 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
32 * the permission of UNIX System Laboratories, Inc.
33 *
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
36 * are met:
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
42 * 3. All advertising materials mentioning features or use of this software
43 * must display the following acknowledgement:
44 * This product includes software developed by the University of
45 * California, Berkeley and its contributors.
46 * 4. Neither the name of the University nor the names of its contributors
47 * may be used to endorse or promote products derived from this software
48 * without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * SUCH DAMAGE.
61 *
62 * @(#)hfs_lookup.c 1.0
63 * derived from @(#)ufs_lookup.c 8.15 (Berkeley) 6/16/95
64 *
65 * (c) 1998-1999 Apple Computer, Inc. All Rights Reserved
66 * (c) 1990, 1992 NeXT Computer, Inc. All Rights Reserved
67 *
68 *
69 * hfs_lookup.c -- code to handle directory traversal on HFS/HFS+ volume
70 */
71 #define LEGACY_FORK_NAMES 0
72
73 #include <sys/param.h>
74 #include <sys/buf.h>
75 #include <sys/file.h>
76 #include <sys/mount.h>
77 #include <sys/vnode.h>
78 #include <sys/namei.h>
79 #include <sys/malloc.h>
80 #include <sys/paths.h>
81
82 #include "hfs.h"
83 #include "hfs_catalog.h"
84 #include "hfs_cnode.h"
85
86
87 static int forkcomponent(struct componentname *cnp, int *rsrcfork);
88
89 #define _PATH_DATAFORKSPEC "/..namedfork/data"
90
91 #ifdef LEGACY_FORK_NAMES
92 #define LEGACY_RSRCFORKSPEC "/rsrc"
93 #endif
94
95 /*
96 * FROM FREEBSD 3.1
97 * Convert a component of a pathname into a pointer to a locked cnode.
98 * This is a very central and rather complicated routine.
99 * If the file system is not maintained in a strict tree hierarchy,
100 * this can result in a deadlock situation (see comments in code below).
101 *
102 * The cnp->cn_nameiop argument is LOOKUP, CREATE, RENAME, or DELETE depending
103 * on whether the name is to be looked up, created, renamed, or deleted.
104 * When CREATE, RENAME, or DELETE is specified, information usable in
105 * creating, renaming, or deleting a directory entry may be calculated.
106 * Notice that these are the only operations that can affect the directory of the target.
107 *
108 * If flag has LOCKPARENT or'ed into it and the target of the pathname
109 * exists, lookup returns both the target and its parent directory locked.
110 * When creating or renaming and LOCKPARENT is specified, the target may
111 * not be ".". When deleting and LOCKPARENT is specified, the target may
112 * be "."., but the caller must check to ensure it does an vrele and vput
113 * instead of two vputs.
114 *
115 * LOCKPARENT and WANTPARENT actually refer to the parent of the last item,
116 * so if ISLASTCN is not set, they should be ignored. Also they are mutually exclusive, or
117 * WANTPARENT really implies DONTLOCKPARENT. Either of them set means that the calling
118 * routine wants to access the parent of the target, locked or unlocked.
119 *
120 * Keeping the parent locked as long as possible protects from other processes
121 * looking up the same item, so it has to be locked until the cnode is totally finished
122 *
123 * This routine is actually used as VOP_CACHEDLOOKUP method, and the
124 * filesystem employs the generic hfs_cache_lookup() as VOP_LOOKUP
125 * method.
126 *
127 * hfs_cache_lookup() performs the following for us:
128 * check that it is a directory
129 * check accessibility of directory
130 * check for modification attempts on read-only mounts
131 * if name found in cache
132 * if at end of path and deleting or creating
133 * drop it
134 * else
135 * return name.
136 * return VOP_CACHEDLOOKUP()
137 *
138 * Overall outline of hfs_lookup:
139 *
140 * handle simple cases of . and ..
141 * search for name in directory, to found or notfound
142 * notfound:
143 * if creating, return locked directory, leaving info on available slots
144 * else return error
145 * found:
146 * if at end of path and deleting, return information to allow delete
147 * if at end of path and rewriting (RENAME and LOCKPARENT), lock target
148 * cnode and return info to allow rewrite
149 * if not at end, add name to cache; if at end and neither creating
150 * nor deleting, add name to cache
151 */
152
153 /*
154 * Lookup *nm in directory *pvp, return it in *a_vpp.
155 * **a_vpp is held on exit.
156 * We create a cnode for the file, but we do NOT open the file here.
157
158 #% lookup dvp L ? ?
159 #% lookup vpp - L -
160
161 IN struct vnode *dvp - Parent node of file;
162 INOUT struct vnode **vpp - node of target file, its a new node if
163 the target vnode did not exist;
164 IN struct componentname *cnp - Name of file;
165
166 * When should we lock parent_hp in here ??
167 */
168
169 __private_extern__
170 int
171 hfs_lookup(ap)
172 struct vop_cachedlookup_args /* {
173 struct vnode *a_dvp;
174 struct vnode **a_vpp;
175 struct componentname *a_cnp;
176 } */ *ap;
177 {
178 struct vnode *dvp; /* vnode for directory being searched */
179 struct cnode *dcp; /* cnode for directory being searched */
180 struct vnode *tvp; /* target vnode */
181 struct hfsmount *hfsmp;
182 struct componentname *cnp;
183 struct ucred *cred;
184 struct proc *p;
185 int wantrsrc = 0;
186 int forknamelen = 0;
187 int flags;
188 int wantparent;
189 int nameiop;
190 int retval = 0;
191 int isDot;
192 struct cat_desc desc = {0};
193 struct cat_desc cndesc;
194 struct cat_attr attr;
195 struct cat_fork fork;
196 struct vnode **vpp;
197
198 vpp = ap->a_vpp;
199 cnp = ap->a_cnp;
200 dvp = ap->a_dvp;
201 dcp = VTOC(dvp);
202 hfsmp = VTOHFS(dvp);
203 *vpp = NULL;
204 isDot = FALSE;
205 tvp = NULL;
206 nameiop = cnp->cn_nameiop;
207 cred = cnp->cn_cred;
208 p = cnp->cn_proc;
209 flags = cnp->cn_flags;
210 wantparent = flags & (LOCKPARENT|WANTPARENT);
211
212 /*
213 * First check to see if it is a . or .., else look it up.
214 */
215 if (flags & ISDOTDOT) { /* Wanting the parent */
216 goto found; /* .. is always defined */
217 } else if ((cnp->cn_nameptr[0] == '.') && (cnp->cn_namelen == 1)) {
218 isDot = TRUE;
219 goto found; /* We always know who we are */
220 } else {
221 /* Check fork suffix to see if we want the resource fork */
222 forknamelen = forkcomponent(cnp, &wantrsrc);
223
224 /* No need to go to catalog if there are no children */
225 if (dcp->c_entries == 0)
226 goto notfound;
227
228 bzero(&cndesc, sizeof(cndesc));
229 cndesc.cd_nameptr = cnp->cn_nameptr;
230 cndesc.cd_namelen = cnp->cn_namelen;
231 cndesc.cd_parentcnid = dcp->c_cnid;
232 cndesc.cd_hint = dcp->c_childhint;
233
234 /* Lock catalog b-tree */
235 retval = hfs_metafilelocking(hfsmp, kHFSCatalogFileID, LK_SHARED, p);
236 if (retval)
237 goto exit;
238 retval = cat_lookup(hfsmp, &cndesc, wantrsrc, &desc, &attr, &fork);
239
240 if (retval == 0 && S_ISREG(attr.ca_mode) && attr.ca_blocks < fork.cf_blocks)
241 panic("hfs_lookup: bad ca_blocks (too small)");
242
243 /* Unlock catalog b-tree */
244 (void) hfs_metafilelocking(hfsmp, kHFSCatalogFileID, LK_RELEASE, p);
245 if (retval == 0) {
246 dcp->c_childhint = desc.cd_hint;
247 goto found;
248 }
249 notfound:
250 /*
251 * This is a non-existing entry
252 *
253 * If creating, and at end of pathname and current
254 * directory has not been removed, then can consider
255 * allowing file to be created.
256 */
257 if ((nameiop == CREATE || nameiop == RENAME ||
258 (nameiop == DELETE &&
259 (ap->a_cnp->cn_flags & DOWHITEOUT) &&
260 (ap->a_cnp->cn_flags & ISWHITEOUT))) &&
261 (flags & ISLASTCN)) {
262 /*
263 * Access for write is interpreted as allowing
264 * creation of files in the directory.
265 */
266 retval = VOP_ACCESS(dvp, VWRITE, cred, cnp->cn_proc);
267 if (retval) {
268 goto exit;
269 }
270
271 cnp->cn_flags |= SAVENAME;
272 if (!(flags & LOCKPARENT))
273 VOP_UNLOCK(dvp, 0, p);
274 retval = EJUSTRETURN;
275 goto exit;
276 }
277
278 /*
279 * Insert name into cache (as non-existent) if appropriate.
280 *
281 * Disable negative caching since HFS is case-insensitive.
282 */
283 #if 0
284 if ((cnp->cn_flags & MAKEENTRY) && nameiop != CREATE)
285 cache_enter(dvp, *vpp, cnp);
286 #endif
287 retval = ENOENT;
288 goto exit;
289 }
290
291 found:
292 /*
293 * Process any fork specifiers
294 */
295 if (forknamelen && S_ISREG(attr.ca_mode)) {
296 /* fork names are only for lookups */
297 if ((nameiop != LOOKUP) && (nameiop != CREATE)) {
298 retval = EPERM;
299 goto exit;
300 }
301 cnp->cn_consume = forknamelen;
302 flags |= ISLASTCN;
303 } else {
304 wantrsrc = 0;
305 forknamelen = 0;
306 }
307
308 /*
309 * If deleting, and at end of pathname, return
310 * parameters which can be used to remove file.
311 */
312 if (nameiop == DELETE && (flags & ISLASTCN)) {
313 /*
314 * Write access to directory required to delete files.
315 */
316 if ((retval = VOP_ACCESS(dvp, VWRITE, cred, cnp->cn_proc)))
317 goto exit;
318
319 if (isDot) { /* Want to return ourselves */
320 VREF(dvp);
321 *vpp = dvp;
322 goto exit;
323 } else if (flags & ISDOTDOT) {
324 retval = hfs_getcnode(hfsmp, dcp->c_parentcnid,
325 NULL, 0, NULL, NULL, &tvp);
326 if (retval)
327 goto exit;
328 } else {
329 retval = hfs_getcnode(hfsmp, attr.ca_fileid,
330 &desc, wantrsrc, &attr, &fork, &tvp);
331 if (retval)
332 goto exit;
333 }
334
335 /*
336 * If directory is "sticky", then user must own
337 * the directory, or the file in it, else she
338 * may not delete it (unless she's root). This
339 * implements append-only directories.
340 */
341 if ((dcp->c_mode & S_ISTXT) &&
342 (cred->cr_uid != 0) &&
343 (cred->cr_uid != dcp->c_uid) &&
344 (tvp->v_type != VLNK) &&
345 (hfs_owner_rights(hfsmp, VTOC(tvp)->c_uid, cred, p, false))) {
346 vput(tvp);
347 retval = EPERM;
348 goto exit;
349 }
350
351 /*
352 * If this is a link node then we need to save the name
353 * (of the link) so we can delete it from the catalog b-tree.
354 * In this case, hfs_remove will then free the component name.
355 *
356 * DJB - IS THIS STILL NEEDED????
357 */
358 if (tvp && (VTOC(tvp)->c_flag & C_HARDLINK))
359 cnp->cn_flags |= SAVENAME;
360
361 if (!(flags & LOCKPARENT))
362 VOP_UNLOCK(dvp, 0, p);
363 *vpp = tvp;
364 goto exit;
365 }
366
367 /*
368 * If renaming, return the cnode and save the current name.
369 */
370 if (nameiop == RENAME && wantparent && (flags & ISLASTCN)) {
371 if ((retval = VOP_ACCESS(dvp, VWRITE, cred, cnp->cn_proc)) != 0)
372 goto exit;
373 /*
374 * Careful about locking second cnode.
375 */
376 if (isDot) {
377 retval = EISDIR;
378 goto exit;
379 } else if (flags & ISDOTDOT) {
380 retval = hfs_getcnode(hfsmp, dcp->c_parentcnid,
381 NULL, 0, NULL, NULL, &tvp);
382 if (retval)
383 goto exit;
384 } else {
385 retval = hfs_getcnode(hfsmp, attr.ca_fileid,
386 &desc, wantrsrc, &attr, &fork, &tvp);
387 if (retval)
388 goto exit;
389 }
390 cnp->cn_flags |= SAVENAME;
391 if (!(flags & LOCKPARENT))
392 VOP_UNLOCK(dvp, 0, p);
393 *vpp = tvp;
394 goto exit;
395 }
396
397 /*
398 * We must get the target cnode before unlocking
399 * the directory to insure that the cnode will not be removed
400 * before we get it. We prevent deadlock by always fetching
401 * cnodes from the root, moving down the directory tree. Thus
402 * when following backward pointers ".." we must unlock the
403 * parent directory before getting the requested directory.
404 * There is a potential race condition here if both the current
405 * and parent directories are removed before the VFS_VGET for the
406 * cnode associated with ".." returns. We hope that this occurs
407 * infrequently since we cannot avoid this race condition without
408 * implementing a sophisticated deadlock detection algorithm.
409 */
410 if (flags & ISDOTDOT) {
411 VOP_UNLOCK(dvp, 0, p); /* race to get the cnode */
412 retval = hfs_getcnode(hfsmp, dcp->c_parentcnid,
413 NULL, 0, NULL, NULL, &tvp);
414 if (retval) {
415 vn_lock(dvp, LK_EXCLUSIVE | LK_RETRY, p);
416 goto exit;
417 }
418 if ((flags & LOCKPARENT) && (flags & ISLASTCN) && (dvp != tvp) &&
419 (retval = vn_lock(dvp, LK_EXCLUSIVE, p))) {
420 vput(tvp);
421 goto exit;
422 }
423 *vpp = tvp;
424 } else if (isDot) {
425 VREF(dvp); /* we want ourself, ie "." */
426 *vpp = dvp;
427 } else {
428 int type = (attr.ca_mode & S_IFMT);
429
430 if (!(flags & ISLASTCN) && type != S_IFDIR && type != S_IFLNK) {
431 retval = ENOTDIR;
432 goto exit;
433 }
434
435 retval = hfs_getcnode(hfsmp, attr.ca_fileid,
436 &desc, wantrsrc, &attr, &fork, &tvp);
437 if (retval)
438 goto exit;
439
440 if (!(flags & LOCKPARENT) || !(flags & ISLASTCN))
441 VOP_UNLOCK(dvp, 0, p);
442 *vpp = tvp;
443 }
444
445 /*
446 * Insert name in cache if appropriate.
447 * - "." and ".." are not cached.
448 * - Resource fork names are not cached.
449 * - Names with composed chars are not cached.
450 */
451 if ((cnp->cn_flags & MAKEENTRY)
452 && !isDot
453 && !(flags & ISDOTDOT)
454 && !wantrsrc
455 && (cnp->cn_namelen == VTOC(*vpp)->c_desc.cd_namelen)) {
456 cache_enter(dvp, *vpp, cnp);
457 }
458
459 exit:
460 cat_releasedesc(&desc);
461 return (retval);
462 }
463
464
465
466 /*
467 * Based on vn_cache_lookup (which is vfs_cache_lookup in FreeBSD 3.1)
468 *
469 * Name caching works as follows:
470 *
471 * Names found by directory scans are retained in a cache
472 * for future reference. It is managed LRU, so frequently
473 * used names will hang around. Cache is indexed by hash value
474 * obtained from (vp, name) where vp refers to the directory
475 * containing name.
476 *
477 * If it is a "negative" entry, (i.e. for a name that is known NOT to
478 * exist) the vnode pointer will be NULL.
479 *
480 * Upon reaching the last segment of a path, if the reference
481 * is for DELETE, or NOCACHE is set (rewrite), and the
482 * name is located in the cache, it will be dropped.
483 *
484 */
485
486 __private_extern__
487 int
488 hfs_cache_lookup(ap)
489 struct vop_lookup_args /* {
490 struct vnode *a_dvp;
491 struct vnode **a_vpp;
492 struct componentname *a_cnp;
493 } */ *ap;
494 {
495 struct vnode *dvp;
496 struct vnode *vp;
497 struct cnode *cp;
498 int lockparent;
499 int error;
500 struct vnode **vpp = ap->a_vpp;
501 struct componentname *cnp = ap->a_cnp;
502 struct ucred *cred = cnp->cn_cred;
503 int flags = cnp->cn_flags;
504 struct proc *p = cnp->cn_proc;
505 u_long vpid; /* capability number of vnode */
506
507 *vpp = NULL;
508 dvp = ap->a_dvp;
509 lockparent = flags & LOCKPARENT;
510
511 /*
512 * Check accessiblity of directory.
513 */
514 if (dvp->v_type != VDIR)
515 return (ENOTDIR);
516 if ((flags & ISLASTCN) && (dvp->v_mount->mnt_flag & MNT_RDONLY) &&
517 (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
518 return (EROFS);
519 if ((error = VOP_ACCESS(dvp, VEXEC, cred, cnp->cn_proc)))
520 return (error);
521
522 /*
523 * Lookup an entry in the cache
524 * If the lookup succeeds, the vnode is returned in *vpp, and a status of -1 is
525 * returned. If the lookup determines that the name does not exist
526 * (negative cacheing), a status of ENOENT is returned. If the lookup
527 * fails, a status of zero is returned.
528 */
529 error = cache_lookup(dvp, vpp, cnp);
530 if (error == 0) { /* Unsuccessfull */
531 error = hfs_lookup(ap);
532 return (error);
533 }
534
535 if (error == ENOENT)
536 return (error);
537
538 /* We have a name that matched */
539 vp = *vpp;
540 vpid = vp->v_id;
541
542 /*
543 * If this is a hard-link vnode then we need to update
544 * the name (of the link), the parent ID, the cnid, the
545 * text encoding and the catalog hint. This enables
546 * getattrlist calls to return the correct link info.
547 */
548 cp = VTOC(vp);
549 if ((flags & ISLASTCN) && (cp->c_flag & C_HARDLINK) &&
550 ((cp->c_parentcnid != VTOC(ap->a_dvp)->c_cnid) ||
551 (bcmp(cnp->cn_nameptr, cp->c_desc.cd_nameptr, cp->c_desc.cd_namelen) != 0))) {
552
553 struct cat_desc desc;
554
555 /*
556 * Get an updated descriptor
557 */
558 bzero(&desc, sizeof(desc));
559 desc.cd_nameptr = cnp->cn_nameptr;
560 desc.cd_namelen = cnp->cn_namelen;
561 desc.cd_parentcnid = VTOC(ap->a_dvp)->c_cnid;
562 desc.cd_hint = VTOC(ap->a_dvp)->c_childhint;
563 if (cat_lookup(VTOHFS(vp), &desc, 0, &desc, NULL, NULL) == 0)
564 replace_desc(cp, &desc);
565 }
566
567 if (dvp == vp) { /* lookup on "." */
568 VREF(vp);
569 error = 0;
570 } else if (flags & ISDOTDOT) {
571 /*
572 * Carefull on the locking policy,
573 * remember we always lock from parent to child, so have
574 * to release lock on child before trying to lock parent
575 * then regain lock if needed
576 */
577 VOP_UNLOCK(dvp, 0, p);
578 error = vget(vp, LK_EXCLUSIVE, p);
579 if (!error && lockparent && (flags & ISLASTCN))
580 error = vn_lock(dvp, LK_EXCLUSIVE, p);
581 } else {
582 if ((flags & ISLASTCN) == 0 && vp->v_type == VREG) {
583 int wantrsrc = 0;
584
585 cnp->cn_consume = forkcomponent(cnp, &wantrsrc);
586
587 /* Fork names are only for lookups */
588 if (cnp->cn_consume &&
589 (cnp->cn_nameiop != LOOKUP && cnp->cn_nameiop != CREATE))
590 return (EPERM);
591 /*
592 * We only store data forks in the name cache.
593 */
594 if (wantrsrc)
595 return (hfs_lookup(ap));
596 }
597 error = vget(vp, LK_EXCLUSIVE, p);
598 if (!lockparent || error || !(flags & ISLASTCN))
599 VOP_UNLOCK(dvp, 0, p);
600 }
601 /*
602 * Check that the capability number did not change
603 * while we were waiting for the lock.
604 */
605 if (!error) {
606 if (vpid == vp->v_id)
607 return (0);
608 /*
609 * The above is the NORMAL exit, after this point is an error
610 * condition.
611 */
612 vput(vp);
613 if (lockparent && (dvp != vp) && (flags & ISLASTCN))
614 VOP_UNLOCK(dvp, 0, p);
615 }
616
617 if ((error = vn_lock(dvp, LK_EXCLUSIVE, p)))
618 return (error);
619
620 return (hfs_lookup(ap));
621 }
622
623
624 /*
625 * forkcomponent - look for a fork suffix in the component name
626 *
627 */
628 static int
629 forkcomponent(struct componentname *cnp, int *rsrcfork)
630 {
631 char *suffix = cnp->cn_nameptr + cnp->cn_namelen;
632 int consume = 0;
633
634 *rsrcfork = 0;
635 if (*suffix == '\0')
636 return (0);
637 /*
638 * There are only 3 valid fork suffixes:
639 * "/..namedfork/rsrc"
640 * "/..namedfork/data"
641 * "/rsrc" (legacy)
642 */
643 if (bcmp(suffix, _PATH_RSRCFORKSPEC, sizeof(_PATH_RSRCFORKSPEC)) == 0) {
644 consume = sizeof(_PATH_RSRCFORKSPEC) - 1;
645 *rsrcfork = 1;
646 } else if (bcmp(suffix, _PATH_DATAFORKSPEC, sizeof(_PATH_DATAFORKSPEC)) == 0) {
647 consume = sizeof(_PATH_DATAFORKSPEC) - 1;
648 }
649
650 #ifdef LEGACY_FORK_NAMES
651 else if (bcmp(suffix, LEGACY_RSRCFORKSPEC, sizeof(LEGACY_RSRCFORKSPEC)) == 0) {
652 consume = sizeof(LEGACY_RSRCFORKSPEC) - 1;
653 *rsrcfork = 1;
654 }
655 #endif
656 return (consume);
657 }
658