This source file includes following definitions.
- LIST_HEAD
- ntfs_nthashreinit
- ntfs_nthashdone
- ntfs_nthashlookup
- ntfs_nthashins
- ntfs_nthashrem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #include <sys/cdefs.h>
37 #ifdef __KERNEL_RCSID
38 __KERNEL_RCSID(0, "$NetBSD: ntfs_ihash.c,v 1.1 2002/12/23 17:38:32 jdolecek Exp $");
39 #endif
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/lock.h>
45 #include <sys/vnode.h>
46 #include <sys/malloc.h>
47 #include <sys/proc.h>
48 #include <sys/mount.h>
49
50 #if defined(__FreeBSD__) || defined(__NetBSD__)
51 #include <fs/ntfs/ntfs.h>
52 #include <fs/ntfs/ntfs_inode.h>
53 #include <fs/ntfs/ntfs_ihash.h>
54 #else
55 #include <ntfs/ntfs.h>
56 #include <ntfs/ntfs_inode.h>
57 #include <ntfs/ntfs_ihash.h>
58 #endif
59
60 #ifdef MALLOC_DEFINE
61 MALLOC_DEFINE(M_NTFSNTHASH, "NTFS nthash", "NTFS ntnode hash tables");
62 #endif
63
64
65
66
67 static LIST_HEAD(nthashhead, ntnode) *ntfs_nthashtbl;
68 static u_long ntfs_nthash;
69 #define NTNOHASH(device, inum) ((minor(device) + (inum)) & ntfs_nthash)
70 #ifndef NULL_SIMPLELOCKS
71 static struct simplelock ntfs_nthash_slock;
72 #endif
73 struct lock ntfs_hashlock;
74
75
76
77
78 void
79 ntfs_nthashinit()
80 {
81 lockinit(&ntfs_hashlock, PINOD, "ntfs_nthashlock", 0, 0);
82 ntfs_nthashtbl = HASHINIT(desiredvnodes, M_NTFSNTHASH, M_WAITOK,
83 &ntfs_nthash);
84 simple_lock_init(&ntfs_nthash_slock);
85 }
86
87 #ifdef __NetBSD__
88
89
90
91
92 void
93 ntfs_nthashreinit()
94 {
95 struct ntnode *ip;
96 struct nthashhead *oldhash, *hash;
97 u_long oldmask, mask, val;
98 int i;
99
100 hash = HASHINIT(desiredvnodes, M_NTFSNTHASH, M_WAITOK, &mask);
101
102 simple_lock(&ntfs_nthash_slock);
103 oldhash = ntfs_nthashtbl;
104 oldmask = ntfs_nthash;
105 ntfs_nthashtbl = hash;
106 ntfs_nthash = mask;
107 for (i = 0; i <= oldmask; i++) {
108 while ((ip = LIST_FIRST(&oldhash[i])) != NULL) {
109 LIST_REMOVE(ip, i_hash);
110 val = NTNOHASH(ip->i_dev, ip->i_number);
111 LIST_INSERT_HEAD(&hash[val], ip, i_hash);
112 }
113 }
114 simple_unlock(&ntfs_nthash_slock);
115 hashdone(oldhash, M_NTFSNTHASH);
116 }
117
118
119
120
121
122 void
123 ntfs_nthashdone()
124 {
125 hashdone(ntfs_nthashtbl, M_NTFSNTHASH);
126 }
127 #endif
128
129
130
131
132
133 struct ntnode *
134 ntfs_nthashlookup(dev, inum)
135 dev_t dev;
136 ino_t inum;
137 {
138 struct ntnode *ip;
139 struct nthashhead *ipp;
140
141 simple_lock(&ntfs_nthash_slock);
142 ipp = &ntfs_nthashtbl[NTNOHASH(dev, inum)];
143 LIST_FOREACH(ip, ipp, i_hash) {
144 if (inum == ip->i_number && dev == ip->i_dev)
145 break;
146 }
147 simple_unlock(&ntfs_nthash_slock);
148
149 return (ip);
150 }
151
152
153
154
155 void
156 ntfs_nthashins(ip)
157 struct ntnode *ip;
158 {
159 struct nthashhead *ipp;
160
161 simple_lock(&ntfs_nthash_slock);
162 ipp = &ntfs_nthashtbl[NTNOHASH(ip->i_dev, ip->i_number)];
163 LIST_INSERT_HEAD(ipp, ip, i_hash);
164 ip->i_flag |= IN_HASHED;
165 simple_unlock(&ntfs_nthash_slock);
166 }
167
168
169
170
171 void
172 ntfs_nthashrem(ip)
173 struct ntnode *ip;
174 {
175 simple_lock(&ntfs_nthash_slock);
176 if (ip->i_flag & IN_HASHED) {
177 ip->i_flag &= ~IN_HASHED;
178 LIST_REMOVE(ip, i_hash);
179 }
180 simple_unlock(&ntfs_nthash_slock);
181 }