|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24:
25: /* Copyright (c) 1998 Apple Computer, Inc. All Rights Reserved */
26: /*
27: * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995
28: * The Regents of the University of California. All rights reserved.
29: *
30: * Redistribution and use in source and binary forms, with or without
31: * modification, are permitted provided that the following conditions
32: * are met:
33: * 1. Redistributions of source code must retain the above copyright
34: * notice, this list of conditions and the following disclaimer.
35: * 2. Redistributions in binary form must reproduce the above copyright
36: * notice, this list of conditions and the following disclaimer in the
37: * documentation and/or other materials provided with the distribution.
38: * 3. All advertising materials mentioning features or use of this software
39: * must display the following acknowledgement:
40: * This product includes software developed by the University of
41: * California, Berkeley and its contributors.
42: * 4. Neither the name of the University nor the names of its contributors
43: * may be used to endorse or promote products derived from this software
44: * without specific prior written permission.
45: *
46: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56: * SUCH DAMAGE.
57: *
58: * @(#)hfs_vhash.c
59: * derived from @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95
60: */
61:
62: #include <sys/param.h>
63: #include <mach/machine/vm_types.h>
64: #include <sys/vnode.h>
65: #include <sys/malloc.h>
66: #include <sys/proc.h>
67: #include <sys/systm.h>
68:
69: #include "hfs.h"
70:
71: #include <libkern/libkern.h>
72: #include <mach/machine/simple_lock.h>
73:
74: /*
75: * Structures associated with hfsnode cacheing.
76: */
77: LIST_HEAD(vhashhead, hfsnode) *vhashtbl;
78: u_long vhash; /* size of hash table - 1 */
79: #define HFSNODEHASH(device, nodeID, forkType) (&vhashtbl[((device) + ((nodeID)<<2) + (forkType)) & vhash])
80: struct slock hfs_vhash_slock;
81:
82: /*
83: * Initialize hfsnode hash table.
84: */
85: void
86: hfs_vhashinit()
87: {
88:
89: vhashtbl = hashinit(desiredvnodes, M_HFSMNT, &vhash);
90: simple_lock_init(&hfs_vhash_slock);
91: }
92:
93: /*
94: * Use the device/dirID pair to find the incore hfsnode, and return a pointer
95: * to it. If it is in core, return it, even if it is locked.
96: */
97: struct vnode *
98: hfs_vhashlookup(dev, nodeID, forkType)
99: dev_t dev;
100: UInt32 nodeID;
101: UInt8 forkType;
102: {
103: struct hfsnode *hp;
104:
105: simple_lock(&hfs_vhash_slock);
106: for (hp = HFSNODEHASH(dev, nodeID, forkType)->lh_first; hp; hp = hp->h_hash.le_next)
107: if ((H_FILEID(hp) == nodeID) && (hp->h_dev == dev) && (H_FORKTYPE(hp) == forkType))
108: break;
109: simple_unlock(&hfs_vhash_slock);
110:
111: if (hp)
112: return (HTOV(hp));
113: return (NULLVP);
114: }
115:
116: /*
117: * Use the device/dirID pair to find the incore hfsnode, and return a pointer
118: * to it. If it is in core, but locked, wait for it.
119: */
120: struct vnode *
121: hfs_vhashget(dev, nodeID, forkType)
122: dev_t dev;
123: UInt32 nodeID;
124: UInt8 forkType;
125: {
126: struct proc *p = CURRENT_PROC; /* XXX */
127: struct hfsnode *hp;
128: struct vnode *vp;
129:
130: loop:
131: simple_lock(&hfs_vhash_slock);
132: for (hp = HFSNODEHASH(dev, nodeID, forkType)->lh_first; hp; hp = hp->h_hash.le_next) {
133: if ((H_FILEID(hp) == nodeID) && (hp->h_dev == dev) && (H_FORKTYPE(hp) == forkType)) {
134: vp = HTOV(hp);
135: simple_lock(&vp->v_interlock);
136: simple_unlock(&hfs_vhash_slock);
137: if (vget(vp, LK_EXCLUSIVE | LK_INTERLOCK, p))
138: goto loop;
139: return (vp);
140: }
141: }
142: simple_unlock(&hfs_vhash_slock);
143: return (NULL);
144: }
145:
146: /*
147: * Lock the hfsnode and insert the hfsnode into the hash table, and return it locked.
148: */
149: void
150: hfs_vhashins(hp)
151: struct hfsnode *hp;
152: {
153: struct vhashhead *ipp;
154:
155: lockmgr(&hp->h_lock, LK_EXCLUSIVE, (struct slock *)0, CURRENT_PROC);
156:
157: simple_lock(&hfs_vhash_slock);
158: ipp = HFSNODEHASH(hp->h_dev, H_FILEID(hp), H_FORKTYPE(hp));
159: LIST_INSERT_HEAD(ipp, hp, h_hash);
160: simple_unlock(&hfs_vhash_slock);
161: }
162:
163: /*
164: * Insert a locked hfsnode into the hash table.
165: */
166: void
167: hfs_vhashinslocked(hp)
168: struct hfsnode *hp;
169: {
170: struct vhashhead *ipp;
171:
172: simple_lock(&hfs_vhash_slock);
173: ipp = HFSNODEHASH(hp->h_dev, H_FILEID(hp), H_FORKTYPE(hp));
174: LIST_INSERT_HEAD(ipp, hp, h_hash);
175: simple_unlock(&hfs_vhash_slock);
176: }
177:
178: /*
179: * Remove the hfsnode from the hash table.
180: */
181: void
182: hfs_vhashrem(hp)
183: struct hfsnode *hp;
184: {
185:
186: simple_lock(&hfs_vhash_slock);
187: LIST_REMOVE(hp, h_hash);
188: #if DIAGNOSTIC
189: hp->h_hash.le_next = NULL;
190: hp->h_hash.le_prev = NULL;
191: #endif
192: simple_unlock(&hfs_vhash_slock);
193: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.