ntfs_ihash.c revision 47060
122347Spst/* $NetBSD: ntfs_ihash.c,v 1.2 1999/05/06 15:43:19 christos Exp $ */ 222347Spst 329964Sache/* 429964Sache * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995 522347Spst * The Regents of the University of California. All rights reserved. 622347Spst * 722347Spst * Redistribution and use in source and binary forms, with or without 822347Spst * modification, are permitted provided that the following conditions 922347Spst * are met: 1022347Spst * 1. Redistributions of source code must retain the above copyright 1122347Spst * notice, this list of conditions and the following disclaimer. 1222347Spst * 2. Redistributions in binary form must reproduce the above copyright 1322347Spst * notice, this list of conditions and the following disclaimer in the 1422347Spst * documentation and/or other materials provided with the distribution. 1522347Spst * 3. All advertising materials mentioning features or use of this software 1622347Spst * must display the following acknowledgement: 1729964Sache * This product includes software developed by the University of 1829964Sache * California, Berkeley and its contributors. 1929964Sache * 4. Neither the name of the University nor the names of its contributors 2029964Sache * may be used to endorse or promote products derived from this software 2129964Sache * without specific prior written permission. 2229964Sache * 2329964Sache * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2429964Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2522347Spst * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2622347Spst * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2722347Spst * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2822347Spst * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2922347Spst * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3022347Spst * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 3122347Spst * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3222347Spst * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3322347Spst * SUCH DAMAGE. 3422347Spst * 3522347Spst * @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95 3622347Spst * $Id: ntfs_ihash.c,v 1.4 1999/05/11 19:54:50 phk Exp $ 3722347Spst */ 3822347Spst 3922347Spst#include <sys/param.h> 4022347Spst#include <sys/systm.h> 4122347Spst#include <sys/kernel.h> 4222347Spst#include <sys/lock.h> 4322347Spst#include <sys/vnode.h> 4422347Spst#include <sys/malloc.h> 4529964Sache#include <sys/proc.h> 4629964Sache 4729964Sache#include <ntfs/ntfs.h> 4829964Sache#include <ntfs/ntfs_inode.h> 4929964Sache#include <ntfs/ntfs_ihash.h> 5029964Sache 5129964SacheMALLOC_DEFINE(M_NTFSNTHASH, "NTFS nthash", "NTFS ntnode hash tables"); 5229964Sache 5329964Sache/* 5429964Sache * Structures associated with inode cacheing. 5529964Sache */ 5629964Sachestatic LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl; 5729964Sachestatic u_long ntfs_nthash; /* size of hash table - 1 */ 5829964Sache#define NTNOHASH(device, inum) (&ntfs_nthashtbl[(minor(device) + (inum)) & ntfs_nthash]) 5929964Sache#ifndef NULL_SIMPLELOCKS 6029964Sachestatic struct simplelock ntfs_nthash_slock; 6129964Sache#endif 6229964Sache 6329964Sache/* 6429964Sache * Initialize inode hash table. 6529964Sache */ 6629964Sachevoid 6729964Sachentfs_nthashinit() 6829964Sache{ 6929964Sache 7029964Sache ntfs_nthashtbl = HASHINIT(desiredvnodes, M_NTFSNTHASH, M_WAITOK, 7129964Sache &ntfs_nthash); 7229964Sache simple_lock_init(&ntfs_nthash_slock); 7322347Spst} 7429964Sache 7529964Sache/* 7622347Spst * Use the device/inum pair to find the incore inode, and return a pointer 7722347Spst * to it. If it is in core, return it, even if it is locked. 7822347Spst */ 7922347Spststruct ntnode * 8022347Spstntfs_nthashlookup(dev, inum) 8122347Spst dev_t dev; 8222347Spst ino_t inum; 8322347Spst{ 8422347Spst struct ntnode *ip; 8522347Spst 8622347Spst simple_lock(&ntfs_nthash_slock); 8722347Spst for (ip = NTNOHASH(dev, inum)->lh_first; ip; ip = ip->i_hash.le_next) 8822347Spst if (inum == ip->i_number && dev == ip->i_dev) 8922347Spst break; 9022347Spst simple_unlock(&ntfs_nthash_slock); 9122347Spst 9222347Spst return (ip); 9322347Spst} 9422347Spst 9522347Spst/* 9622347Spst * Insert the ntnode into the hash table. 9722347Spst */ 9822347Spstvoid 9922347Spstntfs_nthashins(ip) 10022347Spst struct ntnode *ip; 10122347Spst{ 10222347Spst struct nthashhead *ipp; 10322347Spst 10422347Spst simple_lock(&ntfs_nthash_slock); 10522347Spst ipp = NTNOHASH(ip->i_dev, ip->i_number); 10622347Spst LIST_INSERT_HEAD(ipp, ip, i_hash); 10722347Spst ip->i_flag |= IN_HASHED; 10822347Spst simple_unlock(&ntfs_nthash_slock); 10922347Spst} 11022347Spst 11122347Spst/* 11222347Spst * Remove the inode from the hash table. 11322347Spst */ 11422347Spstvoid 11522347Spstntfs_nthashrem(ip) 11622347Spst struct ntnode *ip; 11722347Spst{ 11822347Spst simple_lock(&ntfs_nthash_slock); 11922347Spst if (ip->i_flag & IN_HASHED) { 12022347Spst ip->i_flag &= ~IN_HASHED; 12122347Spst LIST_REMOVE(ip, i_hash); 12222347Spst#ifdef DIAGNOSTIC 12322347Spst ip->i_hash.le_next = NULL; 12422347Spst ip->i_hash.le_prev = NULL; 12522347Spst#endif 12622347Spst } 12722347Spst simple_unlock(&ntfs_nthash_slock); 12822347Spst} 12922347Spst