1 /* $NetBSD: ntfs_ihash.c,v 1.5 1999/09/30 16:56:40 jdolecek Exp $ */
4 * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95
32 * $FreeBSD: src/sys/ntfs/ntfs_ihash.c,v 1.7 1999/12/03 20:37:39 semenu Exp $
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
39 #include <sys/vnode.h>
40 #include <sys/malloc.h>
42 #include <sys/mount.h>
45 #include "ntfs_inode.h"
46 #include "ntfs_ihash.h"
48 MALLOC_DEFINE(M_NTFSNTHASH, "NTFS nthash", "NTFS ntnode hash tables");
51 * Structures associated with inode cacheing.
53 static LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl;
54 static u_long ntfs_nthash; /* size of hash table - 1 */
55 #define NTNOHASH(device, inum) (&ntfs_nthashtbl[(minor(device) + (inum)) & ntfs_nthash])
56 static struct lwkt_token ntfs_nthash_slock;
57 struct lock ntfs_hashlock;
60 * Initialize inode hash table.
65 lockinit(&ntfs_hashlock, "ntfs_nthashlock", 0, 0);
66 ntfs_nthashtbl = hashinit(desiredvnodes, M_NTFSNTHASH, &ntfs_nthash);
67 lwkt_token_init(&ntfs_nthash_slock, "ntfsihash");
71 * Free the inode hash table.
74 ntfs_nthash_uninit(struct vfsconf *vfc)
76 lwkt_gettoken(&ntfs_nthash_slock);
78 hashdestroy(ntfs_nthashtbl, M_NTFSNTHASH, ntfs_nthash);
79 lwkt_reltoken(&ntfs_nthash_slock);
85 * Use the device/inum pair to find the incore inode, and return a pointer
86 * to it. If it is in core, return it, even if it is locked.
89 ntfs_nthashlookup(cdev_t dev, ino_t inum)
93 lwkt_gettoken(&ntfs_nthash_slock);
94 for (ip = NTNOHASH(dev, inum)->lh_first; ip; ip = ip->i_hash.le_next) {
95 if (inum == ip->i_number && dev == ip->i_dev)
98 lwkt_reltoken(&ntfs_nthash_slock);
104 * Insert the ntnode into the hash table.
107 ntfs_nthashins(struct ntnode *ip)
109 struct nthashhead *ipp;
111 lwkt_gettoken(&ntfs_nthash_slock);
112 ipp = NTNOHASH(ip->i_dev, ip->i_number);
113 LIST_INSERT_HEAD(ipp, ip, i_hash);
114 ip->i_flag |= IN_HASHED;
115 lwkt_reltoken(&ntfs_nthash_slock);
119 * Remove the inode from the hash table.
122 ntfs_nthashrem(struct ntnode *ip)
124 lwkt_gettoken(&ntfs_nthash_slock);
125 if (ip->i_flag & IN_HASHED) {
126 ip->i_flag &= ~IN_HASHED;
127 LIST_REMOVE(ip, i_hash);
129 ip->i_hash.le_next = NULL;
130 ip->i_hash.le_prev = NULL;
133 lwkt_reltoken(&ntfs_nthash_slock);