ntfs_ihash.c revision 71998
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: head/sys/fs/ntfs/ntfs_ihash.c 71998 2001-02-04 12:37:48Z phk $ 37 */ 38 39#include <sys/param.h> 40#include <sys/systm.h> 41#include <sys/kernel.h> 42#include <sys/lock.h> 43#include <sys/vnode.h> 44#include <sys/malloc.h> 45#include <sys/mount.h> 46#include <sys/mutex.h> 47 48#include <ntfs/ntfs.h> 49#include <ntfs/ntfs_inode.h> 50#include <ntfs/ntfs_ihash.h> 51 52MALLOC_DEFINE(M_NTFSNTHASH, "NTFS nthash", "NTFS ntnode hash tables"); 53 54/* 55 * Structures associated with inode cacheing. 56 */ 57static LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl; 58static u_long ntfs_nthash; /* size of hash table - 1 */ 59#define NTNOHASH(device, inum) (&ntfs_nthashtbl[(minor(device) + (inum)) & ntfs_nthash]) 60static struct mtx ntfs_nthash_mtx; 61struct lock ntfs_hashlock; 62 63/* 64 * Initialize inode hash table. 65 */ 66void 67ntfs_nthashinit() 68{ 69 lockinit(&ntfs_hashlock, PINOD, "ntfs_nthashlock", 0, 0); 70 ntfs_nthashtbl = HASHINIT(desiredvnodes, M_NTFSNTHASH, M_WAITOK, 71 &ntfs_nthash); 72 mtx_init(&ntfs_nthash_mtx, "ntfs nthash", MTX_DEF); 73} 74 75/* 76 * Destroy inode hash table. 77 */ 78void 79ntfs_nthashdestroy(void) 80{ 81 lockdestroy(&ntfs_hashlock); 82 mtx_destroy(&ntfs_nthash_mtx); 83} 84 85/* 86 * Use the device/inum pair to find the incore inode, and return a pointer 87 * to it. If it is in core, return it, even if it is locked. 88 */ 89struct ntnode * 90ntfs_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 LIST_FOREACH(ip, NTNOHASH(dev, inum), i_hash) 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