The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/fs/ntfs/ntfs_ihash.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: ntfs_ihash.c,v 1.7 2008/05/05 17:11:16 ad 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. Neither the name of the University nor the names of its contributors
   16  *    may be used to endorse or promote products derived from this software
   17  *    without specific prior written permission.
   18  *
   19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
   20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
   23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29  * SUCH DAMAGE.
   30  *
   31  *      @(#)ufs_ihash.c 8.7 (Berkeley) 5/17/95
   32  * Id: ntfs_ihash.c,v 1.5 1999/05/12 09:42:58 semenu Exp
   33  */
   34 
   35 #include <sys/cdefs.h>
   36 __KERNEL_RCSID(0, "$NetBSD: ntfs_ihash.c,v 1.7 2008/05/05 17:11:16 ad Exp $");
   37 
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/kernel.h>
   41 #include <sys/lock.h>
   42 #include <sys/vnode.h>
   43 #include <sys/proc.h>
   44 #include <sys/mount.h>
   45 
   46 #include <fs/ntfs/ntfs.h>
   47 #include <fs/ntfs/ntfs_inode.h>
   48 #include <fs/ntfs/ntfs_ihash.h>
   49 
   50 /*
   51  * Structures associated with inode cacheing.
   52  */
   53 static LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl;
   54 static u_long   ntfs_nthash;            /* size of hash table - 1 */
   55 #define NTNOHASH(device, inum)  ((minor(device) + (inum)) & ntfs_nthash)
   56 static kmutex_t ntfs_nthash_lock;
   57 kmutex_t ntfs_hashlock;
   58 
   59 /*
   60  * Initialize inode hash table.
   61  */
   62 void
   63 ntfs_nthashinit()
   64 {
   65         mutex_init(&ntfs_hashlock, MUTEX_DEFAULT, IPL_NONE);
   66         mutex_init(&ntfs_nthash_lock, MUTEX_DEFAULT, IPL_NONE);
   67         ntfs_nthashtbl = hashinit(desiredvnodes, HASH_LIST, true, &ntfs_nthash);
   68 }
   69 
   70 /*
   71  * Reinitialize inode hash table.
   72  */
   73 
   74 void
   75 ntfs_nthashreinit()
   76 {
   77         struct ntnode *ip;
   78         struct nthashhead *oldhash, *hash;
   79         u_long oldmask, mask, val;
   80         int i;
   81 
   82         hash = hashinit(desiredvnodes, HASH_LIST, true, &mask);
   83 
   84         mutex_enter(&ntfs_nthash_lock);
   85         oldhash = ntfs_nthashtbl;
   86         oldmask = ntfs_nthash;
   87         ntfs_nthashtbl = hash;
   88         ntfs_nthash = mask;
   89         for (i = 0; i <= oldmask; i++) {
   90                 while ((ip = LIST_FIRST(&oldhash[i])) != NULL) {
   91                         LIST_REMOVE(ip, i_hash);
   92                         val = NTNOHASH(ip->i_dev, ip->i_number);
   93                         LIST_INSERT_HEAD(&hash[val], ip, i_hash);
   94                 }
   95         }
   96         mutex_exit(&ntfs_nthash_lock);
   97         hashdone(oldhash, HASH_LIST, oldmask);
   98 }
   99 
  100 /*
  101  * Free the inode hash table. Called from ntfs_done(), only needed
  102  * on NetBSD.
  103  */
  104 void
  105 ntfs_nthashdone()
  106 {
  107         hashdone(ntfs_nthashtbl, HASH_LIST, ntfs_nthash);
  108         mutex_destroy(&ntfs_hashlock);
  109         mutex_destroy(&ntfs_nthash_lock);
  110 }
  111 
  112 /*
  113  * Use the device/inum pair to find the incore inode, and return a pointer
  114  * to it. If it is in core, return it, even if it is locked.
  115  */
  116 struct ntnode *
  117 ntfs_nthashlookup(dev, inum)
  118         dev_t dev;
  119         ino_t inum;
  120 {
  121         struct ntnode *ip;
  122         struct nthashhead *ipp;
  123 
  124         mutex_enter(&ntfs_nthash_lock);
  125         ipp = &ntfs_nthashtbl[NTNOHASH(dev, inum)];
  126         LIST_FOREACH(ip, ipp, i_hash) {
  127                 if (inum == ip->i_number && dev == ip->i_dev)
  128                         break;
  129         }
  130         mutex_exit(&ntfs_nthash_lock);
  131 
  132         return (ip);
  133 }
  134 
  135 /*
  136  * Insert the ntnode into the hash table.
  137  */
  138 void
  139 ntfs_nthashins(ip)
  140         struct ntnode *ip;
  141 {
  142         struct nthashhead *ipp;
  143 
  144         mutex_enter(&ntfs_nthash_lock);
  145         ipp = &ntfs_nthashtbl[NTNOHASH(ip->i_dev, ip->i_number)];
  146         LIST_INSERT_HEAD(ipp, ip, i_hash);
  147         ip->i_flag |= IN_HASHED;
  148         mutex_exit(&ntfs_nthash_lock);
  149 }
  150 
  151 /*
  152  * Remove the inode from the hash table.
  153  */
  154 void
  155 ntfs_nthashrem(ip)
  156         struct ntnode *ip;
  157 {
  158         mutex_enter(&ntfs_nthash_lock);
  159         if (ip->i_flag & IN_HASHED) {
  160                 ip->i_flag &= ~IN_HASHED;
  161                 LIST_REMOVE(ip, i_hash);
  162         }
  163         mutex_exit(&ntfs_nthash_lock);
  164 }

Cache object: ebd23ccdb0e14766db99015cffe67c81


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.