Deleted Added
full compact
pseudofs_fileno.c (168637) pseudofs_fileno.c (168720)
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

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

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
29#include <sys/cdefs.h>
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

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

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
29#include <sys/cdefs.h>
30__FBSDID("$FreeBSD: head/sys/fs/pseudofs/pseudofs_fileno.c 168637 2007-04-11 22:40:57Z des $");
30__FBSDID("$FreeBSD: head/sys/fs/pseudofs/pseudofs_fileno.c 168720 2007-04-14 14:08:30Z des $");
31
32#include "opt_pseudofs.h"
33
34#include <sys/param.h>
35#include <sys/kernel.h>
36#include <sys/systm.h>
37#include <sys/limits.h>
38#include <sys/lock.h>
39#include <sys/malloc.h>
40#include <sys/mutex.h>
31
32#include "opt_pseudofs.h"
33
34#include <sys/param.h>
35#include <sys/kernel.h>
36#include <sys/systm.h>
37#include <sys/limits.h>
38#include <sys/lock.h>
39#include <sys/malloc.h>
40#include <sys/mutex.h>
41#include <sys/proc.h>
41#include <sys/sysctl.h>
42#include <sys/systm.h>
43
44#include <fs/pseudofs/pseudofs.h>
45#include <fs/pseudofs/pseudofs_internal.h>
46
47/*
48 * Initialize fileno bitmap
49 */
50void
51pfs_fileno_init(struct pfs_info *pi)
52{
42#include <sys/sysctl.h>
43#include <sys/systm.h>
44
45#include <fs/pseudofs/pseudofs.h>
46#include <fs/pseudofs/pseudofs_internal.h>
47
48/*
49 * Initialize fileno bitmap
50 */
51void
52pfs_fileno_init(struct pfs_info *pi)
53{
53 struct unrhdr *up;
54
54
55 up = new_unrhdr(3, INT_MAX, &pi->pi_mutex);
56 mtx_lock(&pi->pi_mutex);
57 pi->pi_unrhdr = up;
58 mtx_unlock(&pi->pi_mutex);
55 mtx_assert(&Giant, MA_OWNED);
56 mtx_init(&pi->pi_mutex, "pfs_fileno", NULL, MTX_DEF);
57 pi->pi_unrhdr = new_unrhdr(3, INT_MAX / NO_PID, &pi->pi_mutex);
59}
60
61/*
62 * Tear down fileno bitmap
63 */
64void
65pfs_fileno_uninit(struct pfs_info *pi)
66{
58}
59
60/*
61 * Tear down fileno bitmap
62 */
63void
64pfs_fileno_uninit(struct pfs_info *pi)
65{
67 struct unrhdr *up;
68
66
69 mtx_lock(&pi->pi_mutex);
70
71 up = pi->pi_unrhdr;
67 mtx_assert(&Giant, MA_OWNED);
68 delete_unrhdr(pi->pi_unrhdr);
72 pi->pi_unrhdr = NULL;
69 pi->pi_unrhdr = NULL;
73
74 mtx_unlock(&pi->pi_mutex);
75
76 delete_unrhdr(up);
70 mtx_destroy(&pi->pi_mutex);
77}
78
79/*
80 * Allocate a file number
81 */
82void
71}
72
73/*
74 * Allocate a file number
75 */
76void
83pfs_fileno_alloc(struct pfs_info *pi, struct pfs_node *pn)
77pfs_fileno_alloc(struct pfs_node *pn)
84{
78{
85 /* pi is not really necessary as it can be derived */
86 KASSERT(pi == pn->pn_info, ("pn / pi mismatch"));
87
88 /* make sure our parent has a file number */
89 if (pn->pn_parent && !pn->pn_parent->pn_fileno)
79
80 /* make sure our parent has a file number */
81 if (pn->pn_parent && !pn->pn_parent->pn_fileno)
90 pfs_fileno_alloc(pi, pn->pn_parent);
82 pfs_fileno_alloc(pn->pn_parent);
91
92 switch (pn->pn_type) {
93 case pfstype_root:
94 /* root must always be 2 */
95 pn->pn_fileno = 2;
96 break;
97 case pfstype_dir:
98 case pfstype_file:
99 case pfstype_symlink:
100 case pfstype_procdir:
83
84 switch (pn->pn_type) {
85 case pfstype_root:
86 /* root must always be 2 */
87 pn->pn_fileno = 2;
88 break;
89 case pfstype_dir:
90 case pfstype_file:
91 case pfstype_symlink:
92 case pfstype_procdir:
101 pn->pn_fileno = alloc_unr(pi->pi_unrhdr);
93 pn->pn_fileno = alloc_unr(pn->pn_info->pi_unrhdr);
102 break;
103 case pfstype_this:
104 KASSERT(pn->pn_parent != NULL,
105 ("pfstype_this node has no parent"));
106 pn->pn_fileno = pn->pn_parent->pn_fileno;
107 break;
108 case pfstype_parent:
109 KASSERT(pn->pn_parent != NULL,
110 ("pfstype_parent node has no parent"));
94 break;
95 case pfstype_this:
96 KASSERT(pn->pn_parent != NULL,
97 ("pfstype_this node has no parent"));
98 pn->pn_fileno = pn->pn_parent->pn_fileno;
99 break;
100 case pfstype_parent:
101 KASSERT(pn->pn_parent != NULL,
102 ("pfstype_parent node has no parent"));
111 if (pn->pn_parent == pi->pi_root) {
103 if (pn->pn_parent == pn->pn_info->pi_root) {
112 pn->pn_fileno = pn->pn_parent->pn_fileno;
113 break;
114 }
115 KASSERT(pn->pn_parent->pn_parent != NULL,
116 ("pfstype_parent node has no grandparent"));
117 pn->pn_fileno = pn->pn_parent->pn_parent->pn_fileno;
118 break;
119 case pfstype_none:
120 KASSERT(0,
121 ("pfs_fileno_alloc() called for pfstype_none node"));
122 break;
123 }
124
125#if 0
104 pn->pn_fileno = pn->pn_parent->pn_fileno;
105 break;
106 }
107 KASSERT(pn->pn_parent->pn_parent != NULL,
108 ("pfstype_parent node has no grandparent"));
109 pn->pn_fileno = pn->pn_parent->pn_parent->pn_fileno;
110 break;
111 case pfstype_none:
112 KASSERT(0,
113 ("pfs_fileno_alloc() called for pfstype_none node"));
114 break;
115 }
116
117#if 0
126 printf("pfs_fileno_alloc(): %s: ", pi->pi_name);
118 printf("pfs_fileno_alloc(): %s: ", pn->pn_info->pi_name);
127 if (pn->pn_parent) {
128 if (pn->pn_parent->pn_parent) {
129 printf("%s/", pn->pn_parent->pn_parent->pn_name);
130 }
131 printf("%s/", pn->pn_parent->pn_name);
132 }
133 printf("%s -> %d\n", pn->pn_name, pn->pn_fileno);
134#endif
135}
136
137/*
138 * Release a file number
139 */
140void
119 if (pn->pn_parent) {
120 if (pn->pn_parent->pn_parent) {
121 printf("%s/", pn->pn_parent->pn_parent->pn_name);
122 }
123 printf("%s/", pn->pn_parent->pn_name);
124 }
125 printf("%s -> %d\n", pn->pn_name, pn->pn_fileno);
126#endif
127}
128
129/*
130 * Release a file number
131 */
132void
141pfs_fileno_free(struct pfs_info *pi, struct pfs_node *pn)
133pfs_fileno_free(struct pfs_node *pn)
142{
134{
143 /* pi is not really necessary as it can be derived */
144 KASSERT(pi == pn->pn_info, ("pn / pi mismatch"));
145
146 switch (pn->pn_type) {
147 case pfstype_root:
148 /* not allocated from unrhdr */
149 return;
150 case pfstype_dir:
151 case pfstype_file:
152 case pfstype_symlink:
153 case pfstype_procdir:
135
136 switch (pn->pn_type) {
137 case pfstype_root:
138 /* not allocated from unrhdr */
139 return;
140 case pfstype_dir:
141 case pfstype_file:
142 case pfstype_symlink:
143 case pfstype_procdir:
154 free_unr(pi->pi_unrhdr, pn->pn_fileno);
144 free_unr(pn->pn_info->pi_unrhdr, pn->pn_fileno);
155 break;
156 case pfstype_this:
157 case pfstype_parent:
158 /* ignore these, as they don't "own" their file number */
159 break;
160 case pfstype_none:
161 KASSERT(0,
162 ("pfs_fileno_free() called for pfstype_none node"));
163 break;
164 }
165}
145 break;
146 case pfstype_this:
147 case pfstype_parent:
148 /* ignore these, as they don't "own" their file number */
149 break;
150 case pfstype_none:
151 KASSERT(0,
152 ("pfs_fileno_free() called for pfstype_none node"));
153 break;
154 }
155}