]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/fs/ntfs/ntfs_ihash.c
This commit was generated by cvs2svn to compensate for changes in r165538,
[FreeBSD/FreeBSD.git] / sys / fs / ntfs / ntfs_ihash.c
1 /*      $NetBSD: ntfs_ihash.c,v 1.5 1999/09/30 16:56:40 jdolecek Exp $  */
2
3 /*-
4  * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
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  * 4. 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.
18  *
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
29  * SUCH DAMAGE.
30  *
31  *      @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95
32  * $FreeBSD$
33  */
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/kernel.h>
38 #include <sys/lock.h>
39 #include <sys/vnode.h>
40 #include <sys/malloc.h>
41 #include <sys/mount.h>
42 #include <sys/mutex.h>
43
44 #include <fs/ntfs/ntfs.h>
45 #include <fs/ntfs/ntfs_inode.h>
46 #include <fs/ntfs/ntfs_ihash.h>
47
48 MALLOC_DEFINE(M_NTFSNTHASH, "ntfs_nthash", "NTFS ntnode hash tables");
49
50 /*
51  * Structures associated with inode cacheing.
52  */
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 mtx ntfs_nthash_mtx;
57 struct lock ntfs_hashlock;
58
59 /*
60  * Initialize inode hash table.
61  */
62 void
63 ntfs_nthashinit()
64 {
65         lockinit(&ntfs_hashlock, PINOD, "ntfs_nthashlock", 0, 0);
66         ntfs_nthashtbl = hashinit(desiredvnodes, M_NTFSNTHASH, &ntfs_nthash);
67         mtx_init(&ntfs_nthash_mtx, "ntfs nthash", NULL, MTX_DEF);
68 }
69
70 /*
71  * Destroy inode hash table.
72  */
73 void
74 ntfs_nthashdestroy(void)
75 {
76         lockdestroy(&ntfs_hashlock);
77         mtx_destroy(&ntfs_nthash_mtx);
78 }
79
80 /*
81  * Use the device/inum pair to find the incore inode, and return a pointer
82  * to it. If it is in core, return it, even if it is locked.
83  */
84 struct ntnode *
85 ntfs_nthashlookup(dev, inum)
86         struct cdev *dev;
87         ino_t inum;
88 {
89         struct ntnode *ip;
90
91         mtx_lock(&ntfs_nthash_mtx);
92         LIST_FOREACH(ip, NTNOHASH(dev, inum), i_hash)
93                 if (inum == ip->i_number && dev == ip->i_dev)
94                         break;
95         mtx_unlock(&ntfs_nthash_mtx);
96
97         return (ip);
98 }
99
100 /*
101  * Insert the ntnode into the hash table.
102  */
103 void
104 ntfs_nthashins(ip)
105         struct ntnode *ip;
106 {
107         struct nthashhead *ipp;
108
109         mtx_lock(&ntfs_nthash_mtx);
110         ipp = NTNOHASH(ip->i_dev, ip->i_number);
111         LIST_INSERT_HEAD(ipp, ip, i_hash);
112         ip->i_flag |= IN_HASHED;
113         mtx_unlock(&ntfs_nthash_mtx);
114 }
115
116 /*
117  * Remove the inode from the hash table.
118  */
119 void
120 ntfs_nthashrem(ip)
121         struct ntnode *ip;
122 {
123         mtx_lock(&ntfs_nthash_mtx);
124         if (ip->i_flag & IN_HASHED) {
125                 ip->i_flag &= ~IN_HASHED;
126                 LIST_REMOVE(ip, i_hash);
127         }
128         mtx_unlock(&ntfs_nthash_mtx);
129 }