Deleted Added
full compact
pseudofs_fileno.c (77965) pseudofs_fileno.c (77998)
1/*-
2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
1/*-
2 * Copyright (c) 2001 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/fs/pseudofs/pseudofs_fileno.c 77965 2001-06-10 10:36:16Z des $
28 * $FreeBSD: head/sys/fs/pseudofs/pseudofs_fileno.c 77998 2001-06-10 18:39:21Z des $
29 */
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>
35#include <sys/mount.h>
36#include <sys/mutex.h>
37#include <sys/proc.h>
38#include <sys/sbuf.h>
39#include <sys/sysctl.h>
40
41#include <machine/limits.h>
42
43#include <fs/pseudofs/pseudofs.h>
44#include <fs/pseudofs/pseudofs_internal.h>
45
29 */
30
31#include <sys/param.h>
32#include <sys/kernel.h>
33#include <sys/systm.h>
34#include <sys/malloc.h>
35#include <sys/mount.h>
36#include <sys/mutex.h>
37#include <sys/proc.h>
38#include <sys/sbuf.h>
39#include <sys/sysctl.h>
40
41#include <machine/limits.h>
42
43#include <fs/pseudofs/pseudofs.h>
44#include <fs/pseudofs/pseudofs_internal.h>
45
46static MALLOC_DEFINE(M_PFSFILENO, "pseudofs_fileno", "pseudofs fileno bitmap");
46static MALLOC_DEFINE(M_PFSFILENO, "pfs_fileno", "pseudofs fileno bitmap");
47
48static struct mtx pfs_fileno_mutex;
49
50#define PFS_BITMAP_SIZE 4096
47
48static struct mtx pfs_fileno_mutex;
49
50#define PFS_BITMAP_SIZE 4096
51#define PFS_SLOT_BITS (sizeof(unsigned int) * CHAR_BIT)
51#define PFS_SLOT_BITS (int)(sizeof(unsigned int) * CHAR_BIT)
52#define PFS_BITMAP_BITS (PFS_BITMAP_SIZE * PFS_SLOT_BITS)
53struct pfs_bitmap {
54 u_int32_t pb_offset;
55 int pb_used;
56 unsigned int pb_bitmap[PFS_BITMAP_SIZE];
57 struct pfs_bitmap *pb_next;
58};
59

--- 52 unchanged lines hidden (view full) ---

112
113 mtx_unlock(&pi->pi_mutex);
114
115 for (used = 0; pb; pb = npb) {
116 npb = pb->pb_next;
117 used += pb->pb_used;
118 FREE(pb, M_PFSFILENO);
119 }
52#define PFS_BITMAP_BITS (PFS_BITMAP_SIZE * PFS_SLOT_BITS)
53struct pfs_bitmap {
54 u_int32_t pb_offset;
55 int pb_used;
56 unsigned int pb_bitmap[PFS_BITMAP_SIZE];
57 struct pfs_bitmap *pb_next;
58};
59

--- 52 unchanged lines hidden (view full) ---

112
113 mtx_unlock(&pi->pi_mutex);
114
115 for (used = 0; pb; pb = npb) {
116 npb = pb->pb_next;
117 used += pb->pb_used;
118 FREE(pb, M_PFSFILENO);
119 }
120#if 0
121 /* we currently don't reclaim filenos */
120 if (used > 2)
121 printf("WARNING: %d file numbers still in use\n", used);
122 if (used > 2)
123 printf("WARNING: %d file numbers still in use\n", used);
124#endif
122}
123
124/*
125 * Get the next available file number
126 */
127static u_int32_t
128pfs_get_fileno(struct pfs_info *pi)
129{

--- 67 unchanged lines hidden (view full) ---

197 p = &pb->pb_bitmap[fileno / PFS_SLOT_BITS];
198 i = fileno % PFS_SLOT_BITS;
199 KASSERT(*p & (unsigned int)(1 << i),
200 ("fileno is already free"));
201 *p &= ~((unsigned int)(1 << i));
202 --pb->pb_used;
203
204 mtx_unlock(&pi->pi_mutex);
125}
126
127/*
128 * Get the next available file number
129 */
130static u_int32_t
131pfs_get_fileno(struct pfs_info *pi)
132{

--- 67 unchanged lines hidden (view full) ---

200 p = &pb->pb_bitmap[fileno / PFS_SLOT_BITS];
201 i = fileno % PFS_SLOT_BITS;
202 KASSERT(*p & (unsigned int)(1 << i),
203 ("fileno is already free"));
204 *p &= ~((unsigned int)(1 << i));
205 --pb->pb_used;
206
207 mtx_unlock(&pi->pi_mutex);
208 printf("pfs_free_fileno(): reclaimed %d\n", fileno);
205}
206
207/*
208 * Allocate a file number
209 */
210void
211pfs_fileno_alloc(struct pfs_info *pi, struct pfs_node *pn)
212{
213 /* make sure our parent has a file number */
214 if (pn->pn_parent && !pn->pn_parent->pn_fileno)
215 pfs_fileno_alloc(pi, pn->pn_parent);
216
217 switch (pn->pn_type) {
218 case pfstype_root:
219 case pfstype_dir:
220 case pfstype_file:
221 case pfstype_symlink:
209}
210
211/*
212 * Allocate a file number
213 */
214void
215pfs_fileno_alloc(struct pfs_info *pi, struct pfs_node *pn)
216{
217 /* make sure our parent has a file number */
218 if (pn->pn_parent && !pn->pn_parent->pn_fileno)
219 pfs_fileno_alloc(pi, pn->pn_parent);
220
221 switch (pn->pn_type) {
222 case pfstype_root:
223 case pfstype_dir:
224 case pfstype_file:
225 case pfstype_symlink:
226 case pfstype_procdir:
222 pn->pn_fileno = pfs_get_fileno(pi);
223 break;
224 case pfstype_this:
225 KASSERT(pn->pn_parent != NULL,
226 ("pfstype_this node has no parent"));
227 pn->pn_fileno = pn->pn_parent->pn_fileno;
228 break;
229 case pfstype_parent:
230 KASSERT(pn->pn_parent != NULL,
231 ("pfstype_parent node has no parent"));
232 if (pn->pn_parent == pi->pi_root) {
233 pn->pn_fileno = pn->pn_parent->pn_fileno;
234 break;
235 }
236 KASSERT(pn->pn_parent->pn_parent != NULL,
237 ("pfstype_parent node has no grandparent"));
238 pn->pn_fileno = pn->pn_parent->pn_parent->pn_fileno;
239 break;
227 pn->pn_fileno = pfs_get_fileno(pi);
228 break;
229 case pfstype_this:
230 KASSERT(pn->pn_parent != NULL,
231 ("pfstype_this node has no parent"));
232 pn->pn_fileno = pn->pn_parent->pn_fileno;
233 break;
234 case pfstype_parent:
235 KASSERT(pn->pn_parent != NULL,
236 ("pfstype_parent node has no parent"));
237 if (pn->pn_parent == pi->pi_root) {
238 pn->pn_fileno = pn->pn_parent->pn_fileno;
239 break;
240 }
241 KASSERT(pn->pn_parent->pn_parent != NULL,
242 ("pfstype_parent node has no grandparent"));
243 pn->pn_fileno = pn->pn_parent->pn_parent->pn_fileno;
244 break;
240 case pfstype_procdep:
241 KASSERT(1,
242 ("pfs_fileno_alloc() called for pfstype_procdep node"));
243 break;
244 case pfstype_none:
245 case pfstype_none:
245 KASSERT(1,
246 KASSERT(0,
246 ("pfs_fileno_alloc() called for pfstype_none node"));
247 break;
248 }
247 ("pfs_fileno_alloc() called for pfstype_none node"));
248 break;
249 }
249
250
251#if 0
250 printf("pfs_fileno_alloc(): %s: ", pi->pi_name);
251 if (pn->pn_parent) {
252 if (pn->pn_parent->pn_parent) {
253 printf("%s/", pn->pn_parent->pn_parent->pn_name);
254 }
255 printf("%s/", pn->pn_parent->pn_name);
256 }
257 printf("%s -> %d\n", pn->pn_name, pn->pn_fileno);
252 printf("pfs_fileno_alloc(): %s: ", pi->pi_name);
253 if (pn->pn_parent) {
254 if (pn->pn_parent->pn_parent) {
255 printf("%s/", pn->pn_parent->pn_parent->pn_name);
256 }
257 printf("%s/", pn->pn_parent->pn_name);
258 }
259 printf("%s -> %d\n", pn->pn_name, pn->pn_fileno);
260#endif
258}
259
260/*
261 * Release a file number
262 */
263void
264pfs_fileno_free(struct pfs_info *pi, struct pfs_node *pn)
265{
266 switch (pn->pn_type) {
267 case pfstype_root:
268 case pfstype_dir:
269 case pfstype_file:
270 case pfstype_symlink:
261}
262
263/*
264 * Release a file number
265 */
266void
267pfs_fileno_free(struct pfs_info *pi, struct pfs_node *pn)
268{
269 switch (pn->pn_type) {
270 case pfstype_root:
271 case pfstype_dir:
272 case pfstype_file:
273 case pfstype_symlink:
274 case pfstype_procdir:
271 pfs_free_fileno(pi, pn->pn_fileno);
272 break;
273 case pfstype_this:
274 case pfstype_parent:
275 /* ignore these, as they don't "own" their file number */
276 break;
275 pfs_free_fileno(pi, pn->pn_fileno);
276 break;
277 case pfstype_this:
278 case pfstype_parent:
279 /* ignore these, as they don't "own" their file number */
280 break;
277 case pfstype_procdep:
278 KASSERT(1,
279 ("pfs_fileno_free() called for pfstype_procdep node"));
280 break;
281 case pfstype_none:
281 case pfstype_none:
282 KASSERT(1,
282 KASSERT(0,
283 ("pfs_fileno_free() called for pfstype_none node"));
284 break;
285 }
286}
283 ("pfs_fileno_free() called for pfstype_none node"));
284 break;
285 }
286}