1 /* $OpenBSD: ntfs_ihash.c,v 1.10 2010/09/04 21:35:58 tedu Exp $ */ 2 /* $NetBSD: ntfs_ihash.c,v 1.1 2002/12/23 17:38:32 jdolecek Exp $ */ 3 4 /* 5 * Copyright (c) 1982, 1986, 1989, 1991, 1993, 1995 6 * The Regents of the University of California. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. Neither the name of the University nor the names of its contributors 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95 33 * Id: ntfs_ihash.c,v 1.5 1999/05/12 09:42:58 semenu Exp 34 */ 35 36 #include <sys/param.h> 37 #include <sys/systm.h> 38 #include <sys/kernel.h> 39 #include <sys/rwlock.h> 40 #include <sys/vnode.h> 41 #include <sys/malloc.h> 42 #include <sys/proc.h> 43 #include <sys/mount.h> 44 45 #include <ntfs/ntfs.h> 46 #include <ntfs/ntfs_inode.h> 47 #include <ntfs/ntfs_ihash.h> 48 49 #ifdef MALLOC_DEFINE 50 MALLOC_DEFINE(M_NTFSNTHASH, "NTFS nthash", "NTFS ntnode hash tables"); 51 #endif 52 53 /* 54 * Structures associated with inode cacheing. 55 */ 56 static LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl; 57 static u_long ntfs_nthash; /* size of hash table - 1 */ 58 #define NTNOHASH(device, inum) ((minor(device) + (inum)) & ntfs_nthash) 59 struct rwlock ntfs_hashlock = RWLOCK_INITIALIZER("ntfs_nthashlock"); 60 61 /* 62 * Initialize inode hash table. 63 */ 64 void 65 ntfs_nthashinit() 66 { 67 ntfs_nthashtbl = hashinit(desiredvnodes, M_NTFSNTHASH, M_WAITOK, 68 &ntfs_nthash); 69 } 70 71 /* 72 * Use the device/inum pair to find the incore inode, and return a pointer 73 * to it. If it is in core, return it, even if it is locked. 74 */ 75 struct ntnode * 76 ntfs_nthashlookup(dev, inum) 77 dev_t dev; 78 ino_t inum; 79 { 80 struct ntnode *ip; 81 struct nthashhead *ipp; 82 83 /* XXXLOCKING lock hash list? */ 84 ipp = &ntfs_nthashtbl[NTNOHASH(dev, inum)]; 85 LIST_FOREACH(ip, ipp, i_hash) { 86 if (inum == ip->i_number && dev == ip->i_dev) 87 break; 88 } 89 /* XXXLOCKING unlock hash list? */ 90 91 return (ip); 92 } 93 94 /* 95 * Insert the ntnode into the hash table. 96 */ 97 void 98 ntfs_nthashins(ip) 99 struct ntnode *ip; 100 { 101 struct nthashhead *ipp; 102 103 /* XXXLOCKING lock hash list? */ 104 ipp = &ntfs_nthashtbl[NTNOHASH(ip->i_dev, ip->i_number)]; 105 LIST_INSERT_HEAD(ipp, ip, i_hash); 106 ip->i_flag |= IN_HASHED; 107 /* XXXLOCKING unlock hash list? */ 108 } 109 110 /* 111 * Remove the inode from the hash table. 112 */ 113 void 114 ntfs_nthashrem(ip) 115 struct ntnode *ip; 116 { 117 /* XXXLOCKING lock hash list? */ 118 if (ip->i_flag & IN_HASHED) { 119 ip->i_flag &= ~IN_HASHED; 120 LIST_REMOVE(ip, i_hash); 121 } 122 /* XXXLOCKING unlock hash list? */ 123 } 124