ntfs_ihash.c revision 71993
150276Speter/* $NetBSD: ntfs_ihash.c,v 1.5 1999/09/30 16:56:40 jdolecek Exp $ */ 250276Speter 3166124Srafan/* 450276Speter * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995 550276Speter * The Regents of the University of California. All rights reserved. 650276Speter * 750276Speter * Redistribution and use in source and binary forms, with or without 850276Speter * modification, are permitted provided that the following conditions 950276Speter * are met: 1050276Speter * 1. Redistributions of source code must retain the above copyright 1150276Speter * notice, this list of conditions and the following disclaimer. 1250276Speter * 2. Redistributions in binary form must reproduce the above copyright 1350276Speter * notice, this list of conditions and the following disclaimer in the 1450276Speter * documentation and/or other materials provided with the distribution. 1550276Speter * 3. All advertising materials mentioning features or use of this software 1650276Speter * must display the following acknowledgement: 1750276Speter * This product includes software developed by the University of 1850276Speter * California, Berkeley and its contributors. 1950276Speter * 4. Neither the name of the University nor the names of its contributors 2050276Speter * may be used to endorse or promote products derived from this software 2150276Speter * without specific prior written permission. 2250276Speter * 2350276Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2450276Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2550276Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2650276Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2750276Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2850276Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2950276Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30166124Srafan * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3150276Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3250276Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3350276Speter * SUCH DAMAGE. 3450276Speter * 3550276Speter * @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95 3650276Speter * $FreeBSD: head/sys/fs/ntfs/ntfs_ihash.c 71993 2001-02-04 11:53:51Z phk $ 3750276Speter */ 3850276Speter 3950276Speter#include <sys/param.h> 4050276Speter#include <sys/systm.h> 4150276Speter#include <sys/kernel.h> 4250276Speter#include <sys/lock.h> 4350276Speter#include <sys/vnode.h> 4450276Speter#include <sys/malloc.h> 45166124Srafan#include <sys/mount.h> 4650276Speter#include <sys/mutex.h> 4750276Speter 4850276Speter#include <ntfs/ntfs.h> 4950276Speter#include <ntfs/ntfs_inode.h> 5050276Speter#include <ntfs/ntfs_ihash.h> 5150276Speter 5250276SpeterMALLOC_DEFINE(M_NTFSNTHASH, "NTFS nthash", "NTFS ntnode hash tables"); 53166124Srafan 54166124Srafan/* 55166124Srafan * Structures associated with inode cacheing. 56166124Srafan */ 57166124Srafanstatic LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl; 58166124Srafanstatic u_long ntfs_nthash; /* size of hash table - 1 */ 59166124Srafan#define NTNOHASH(device, inum) (&ntfs_nthashtbl[(minor(device) + (inum)) & ntfs_nthash]) 60166124Srafanstatic struct mtx ntfs_nthash_mtx; 6150276Speterstruct lock ntfs_hashlock; 6250276Speter 63166124Srafan/* 6450276Speter * Initialize inode hash table. 6550276Speter */ 66166124Srafanvoid 6750276Speterntfs_nthashinit() 6850276Speter{ 69166124Srafan lockinit(&ntfs_hashlock, PINOD, "ntfs_nthashlock", 0, 0); 7050276Speter ntfs_nthashtbl = HASHINIT(desiredvnodes, M_NTFSNTHASH, M_WAITOK, 71166124Srafan &ntfs_nthash); 72166124Srafan mtx_init(&ntfs_nthash_mtx, "ntfs nthash", MTX_DEF); 73166124Srafan} 7450276Speter 7550276Speter/* 7650276Speter * Destroy inode hash table. 7750276Speter */ 7850276Spetervoid 7950276Speterntfs_nthashdestroy(void) 8050276Speter{ 8150276Speter lockdestroy(&ntfs_hashlock); 8250276Speter mtx_destroy(&ntfs_nthash_mtx); 8350276Speter} 8450276Speter 8550276Speter/* 8650276Speter * Use the device/inum pair to find the incore inode, and return a pointer 8750276Speter * to it. If it is in core, return it, even if it is locked. 8850276Speter */ 8950276Speterstruct ntnode * 9050276Speterntfs_nthashlookup(dev, inum) 91 dev_t dev; 92 ino_t inum; 93{ 94 struct ntnode *ip; 95 96 mtx_enter(&ntfs_nthash_mtx, MTX_DEF); 97 for (ip = NTNOHASH(dev, inum)->lh_first; ip; ip = ip->i_hash.le_next) 98 if (inum == ip->i_number && dev == ip->i_dev) 99 break; 100 mtx_exit(&ntfs_nthash_mtx, MTX_DEF); 101 102 return (ip); 103} 104 105/* 106 * Insert the ntnode into the hash table. 107 */ 108void 109ntfs_nthashins(ip) 110 struct ntnode *ip; 111{ 112 struct nthashhead *ipp; 113 114 mtx_enter(&ntfs_nthash_mtx, MTX_DEF); 115 ipp = NTNOHASH(ip->i_dev, ip->i_number); 116 LIST_INSERT_HEAD(ipp, ip, i_hash); 117 ip->i_flag |= IN_HASHED; 118 mtx_exit(&ntfs_nthash_mtx, MTX_DEF); 119} 120 121/* 122 * Remove the inode from the hash table. 123 */ 124void 125ntfs_nthashrem(ip) 126 struct ntnode *ip; 127{ 128 mtx_enter(&ntfs_nthash_mtx, MTX_DEF); 129 if (ip->i_flag & IN_HASHED) { 130 ip->i_flag &= ~IN_HASHED; 131 LIST_REMOVE(ip, i_hash); 132 } 133 mtx_exit(&ntfs_nthash_mtx, MTX_DEF); 134} 135