Change the kernel dev_t, representing a pointer to a specinfo structure,
[dragonfly.git] / sys / vfs / ntfs / ntfs_ihash.c
CommitLineData
984263bc
MD
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 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95
36 * $FreeBSD: src/sys/ntfs/ntfs_ihash.c,v 1.7 1999/12/03 20:37:39 semenu Exp $
b13267a5 37 * $DragonFly: src/sys/vfs/ntfs/ntfs_ihash.c,v 1.12 2006/09/10 01:26:41 dillon Exp $
984263bc
MD
38 */
39
40#include <sys/param.h>
41#include <sys/systm.h>
42#include <sys/kernel.h>
43#include <sys/lock.h>
44#include <sys/vnode.h>
45#include <sys/malloc.h>
46#include <sys/proc.h>
47#include <sys/mount.h>
48
1f2de5d4
MD
49#include "ntfs.h"
50#include "ntfs_inode.h"
51#include "ntfs_ihash.h"
984263bc
MD
52
53MALLOC_DEFINE(M_NTFSNTHASH, "NTFS nthash", "NTFS ntnode hash tables");
54
55/*
56 * Structures associated with inode cacheing.
57 */
58static LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl;
59static u_long ntfs_nthash; /* size of hash table - 1 */
60#define NTNOHASH(device, inum) (&ntfs_nthashtbl[(minor(device) + (inum)) & ntfs_nthash])
8a8d5d85 61static struct lwkt_token ntfs_nthash_slock;
984263bc
MD
62struct lock ntfs_hashlock;
63
64/*
65 * Initialize inode hash table.
66 */
67void
cd0a65a2 68ntfs_nthashinit(void)
984263bc 69{
f2770c70 70 lockinit(&ntfs_hashlock, "ntfs_nthashlock", 0, 0);
984263bc
MD
71 ntfs_nthashtbl = HASHINIT(desiredvnodes, M_NTFSNTHASH, M_WAITOK,
72 &ntfs_nthash);
41a01a4d 73 lwkt_token_init(&ntfs_nthash_slock);
984263bc
MD
74}
75
6baa4fd6
HP
76/*
77 * Free the inode hash table.
78 */
79int
80ntfs_nthash_uninit(struct vfsconf *vfc)
81{
41a01a4d
MD
82 lwkt_tokref ilock;
83
84 lwkt_gettoken(&ilock, &ntfs_nthash_slock);
6baa4fd6 85 if (ntfs_nthashtbl)
efda3bd0 86 kfree(ntfs_nthashtbl, M_NTFSNTHASH);
41a01a4d 87 lwkt_reltoken(&ilock);
6baa4fd6
HP
88
89 return 0;
90}
91
984263bc
MD
92/*
93 * Use the device/inum pair to find the incore inode, and return a pointer
94 * to it. If it is in core, return it, even if it is locked.
95 */
96struct ntnode *
b13267a5 97ntfs_nthashlookup(cdev_t dev, ino_t inum)
984263bc
MD
98{
99 struct ntnode *ip;
41a01a4d 100 lwkt_tokref ilock;
984263bc 101
41a01a4d 102 lwkt_gettoken(&ilock, &ntfs_nthash_slock);
34b41b18 103 for (ip = NTNOHASH(dev, inum)->lh_first; ip; ip = ip->i_hash.le_next) {
984263bc
MD
104 if (inum == ip->i_number && dev == ip->i_dev)
105 break;
34b41b18 106 }
41a01a4d 107 lwkt_reltoken(&ilock);
984263bc
MD
108
109 return (ip);
110}
111
112/*
113 * Insert the ntnode into the hash table.
114 */
115void
cd0a65a2 116ntfs_nthashins(struct ntnode *ip)
984263bc
MD
117{
118 struct nthashhead *ipp;
41a01a4d 119 lwkt_tokref ilock;
984263bc 120
41a01a4d 121 lwkt_gettoken(&ilock, &ntfs_nthash_slock);
984263bc
MD
122 ipp = NTNOHASH(ip->i_dev, ip->i_number);
123 LIST_INSERT_HEAD(ipp, ip, i_hash);
124 ip->i_flag |= IN_HASHED;
41a01a4d 125 lwkt_reltoken(&ilock);
984263bc
MD
126}
127
128/*
129 * Remove the inode from the hash table.
130 */
131void
cd0a65a2 132ntfs_nthashrem(struct ntnode *ip)
984263bc 133{
41a01a4d
MD
134 lwkt_tokref ilock;
135
136 lwkt_gettoken(&ilock, &ntfs_nthash_slock);
984263bc
MD
137 if (ip->i_flag & IN_HASHED) {
138 ip->i_flag &= ~IN_HASHED;
139 LIST_REMOVE(ip, i_hash);
140#ifdef DIAGNOSTIC
141 ip->i_hash.le_next = NULL;
142 ip->i_hash.le_prev = NULL;
143#endif
144 }
41a01a4d 145 lwkt_reltoken(&ilock);
984263bc 146}