Deleted Added
full compact
geom_dev.c (92108) geom_dev.c (92403)
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the

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

27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
1/*-
2 * Copyright (c) 2002 Poul-Henning Kamp
3 * Copyright (c) 2002 Networks Associates Technology, Inc.
4 * All rights reserved.
5 *
6 * This software was developed for the FreeBSD Project by Poul-Henning Kamp
7 * and NAI Labs, the Security Research Division of Network Associates, Inc.
8 * under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as part of the

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

27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 * $FreeBSD: head/sys/geom/geom_dev.c 92108 2002-03-11 21:42:35Z phk $
35 * $FreeBSD: head/sys/geom/geom_dev.c 92403 2002-03-16 09:24:19Z phk $
36 */
37
36 */
37
38
39#include <sys/param.h>
40#include <sys/systm.h>
41#include <sys/malloc.h>
42#include <sys/kernel.h>
43#include <sys/conf.h>
44#include <sys/bio.h>
45#include <sys/lock.h>
46#include <sys/mutex.h>
47#include <sys/errno.h>
48#include <sys/time.h>
49#include <sys/disk.h>
50#include <sys/fcntl.h>
51#include <geom/geom.h>
52
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/malloc.h>
41#include <sys/kernel.h>
42#include <sys/conf.h>
43#include <sys/bio.h>
44#include <sys/lock.h>
45#include <sys/mutex.h>
46#include <sys/errno.h>
47#include <sys/time.h>
48#include <sys/disk.h>
49#include <sys/fcntl.h>
50#include <geom/geom.h>
51
53
54#define CDEV_MAJOR 4
55
56static d_open_t g_dev_open;
57static d_close_t g_dev_close;
58static d_strategy_t g_dev_strategy;
59static d_ioctl_t g_dev_ioctl;
60static d_psize_t g_dev_psize;
61

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

126SYSINIT(geomdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,g_dev_register_cloner,NULL);
127
128static struct g_geom *
129g_dev_taste(struct g_method *mp, struct g_provider *pp, struct thread *tp __unused, int insist __unused)
130{
131 struct g_geom *gp;
132 struct g_consumer *cp;
133 static int unit;
52#define CDEV_MAJOR 4
53
54static d_open_t g_dev_open;
55static d_close_t g_dev_close;
56static d_strategy_t g_dev_strategy;
57static d_ioctl_t g_dev_ioctl;
58static d_psize_t g_dev_psize;
59

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

124SYSINIT(geomdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE,g_dev_register_cloner,NULL);
125
126static struct g_geom *
127g_dev_taste(struct g_method *mp, struct g_provider *pp, struct thread *tp __unused, int insist __unused)
128{
129 struct g_geom *gp;
130 struct g_consumer *cp;
131 static int unit;
134#if 1
135 u_int secsize;
136 off_t mediasize;
137 int error, j;
132 u_int secsize;
133 off_t mediasize;
134 int error, j;
138#endif
139 dev_t dev;
140
141 g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name);
142 g_topology_assert();
143 LIST_FOREACH(cp, &pp->consumers, consumers)
144 if (cp->geom->method == mp)
145 return (NULL);
146 gp = g_new_geomf(mp, pp->name);
147 cp = g_new_consumer(gp);
148 g_attach(cp, pp);
135 dev_t dev;
136
137 g_trace(G_T_TOPOLOGY, "dev_taste(%s,%s)", mp->name, pp->name);
138 g_topology_assert();
139 LIST_FOREACH(cp, &pp->consumers, consumers)
140 if (cp->geom->method == mp)
141 return (NULL);
142 gp = g_new_geomf(mp, pp->name);
143 cp = g_new_consumer(gp);
144 g_attach(cp, pp);
149#if 1
150 error = g_access_rel(cp, 1, 0, 0);
151 g_topology_unlock();
152 if (!error) {
153 j = sizeof secsize;
154 error = g_io_getattr("GEOM::sectorsize", cp, &j, &secsize, tp);
155 if (error) {
156 secsize = 512;
157 printf("g_bsd_taste: error %d Sectors are %d bytes\n",

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

166 }
167 g_topology_lock();
168 g_access_rel(cp, -1, 0, 0);
169 g_topology_unlock();
170 } else {
171 secsize = 512;
172 mediasize = 0;
173 }
145 error = g_access_rel(cp, 1, 0, 0);
146 g_topology_unlock();
147 if (!error) {
148 j = sizeof secsize;
149 error = g_io_getattr("GEOM::sectorsize", cp, &j, &secsize, tp);
150 if (error) {
151 secsize = 512;
152 printf("g_bsd_taste: error %d Sectors are %d bytes\n",

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

161 }
162 g_topology_lock();
163 g_access_rel(cp, -1, 0, 0);
164 g_topology_unlock();
165 } else {
166 secsize = 512;
167 mediasize = 0;
168 }
174#else
175 g_topology_unlock();
176#endif
177 mtx_lock(&Giant);
169 mtx_lock(&Giant);
178#if 1
179 if (mediasize != 0)
180 printf("GEOM: \"%s\" %lld bytes in %lld sectors of %u bytes\n",
181 pp->name, mediasize, mediasize / secsize, secsize);
182 else
183 printf("GEOM: \"%s\" (size unavailable)\n", pp->name);
170 if (mediasize != 0)
171 printf("GEOM: \"%s\" %lld bytes in %lld sectors of %u bytes\n",
172 pp->name, mediasize, mediasize / secsize, secsize);
173 else
174 printf("GEOM: \"%s\" (size unavailable)\n", pp->name);
184#endif
185 dev = make_dev(&g_dev_cdevsw, unit++,
186 UID_ROOT, GID_WHEEL, 0600, gp->name);
187 gp->softc = dev;
188 dev->si_drv1 = gp;
189 dev->si_drv2 = cp;
190 mtx_unlock(&Giant);
191 g_topology_lock();
192 return (gp);

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

244 return (error);
245}
246
247static int
248g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
249{
250 struct g_geom *gp;
251 struct g_consumer *cp;
175 dev = make_dev(&g_dev_cdevsw, unit++,
176 UID_ROOT, GID_WHEEL, 0600, gp->name);
177 gp->softc = dev;
178 dev->si_drv1 = gp;
179 dev->si_drv2 = cp;
180 mtx_unlock(&Giant);
181 g_topology_lock();
182 return (gp);

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

234 return (error);
235}
236
237static int
238g_dev_ioctl(dev_t dev, u_long cmd, caddr_t data, int fflag, struct thread *td)
239{
240 struct g_geom *gp;
241 struct g_consumer *cp;
252 char *nm;
253 int i, error;
242 int i, error;
243 struct g_ioctl *gio;
254
255 gp = dev->si_drv1;
256 cp = dev->si_drv2;
257
258 error = 0;
259 mtx_unlock(&Giant);
244
245 gp = dev->si_drv1;
246 cp = dev->si_drv2;
247
248 error = 0;
249 mtx_unlock(&Giant);
260 switch (cmd) {
261 case DIOCGDINFO: nm = "IOCTL::DIOCGDINFO"; break;
262 case DIOCGDVIRGIN: nm = "IOCTL::DIOCGDVIRGIN"; break;
263 case DIOCGPART: nm = "IOCTL::DIOCGPART"; break;
264 default: nm = "?"; break;
250
251 gio = g_malloc(sizeof *gio, M_WAITOK);
252 gio->cmd = cmd;
253 gio->data = data;
254 gio->fflag = fflag;
255 gio->td = td;
256 i = sizeof *gio;
257 if (cmd & IOC_IN)
258 error = g_io_setattr("GEOM::ioctl", cp, i, gio, td);
259 else
260 error = g_io_getattr("GEOM::ioctl", cp, &i, gio, td);
261 g_free(gio);
262
263 if (error == 0) {
264 if (error != 0 && cmd == DIOCGDVIRGIN) {
265 g_topology_lock();
266 gp = g_create_geomf("BSD-method", cp->provider, NULL);
267 g_topology_unlock();
268 }
265 }
269 }
266 i = IOCGROUP(cmd);
267 if (*nm == '?') {
270 mtx_lock(&Giant);
271 g_rattle();
272 if (error == ENOIOCTL) {
273 i = IOCGROUP(cmd);
268 printf("IOCTL(0x%lx) \"%s\"", cmd, gp->name);
269 if (i > ' ' && i <= '~')
270 printf(" '%c'", (int)IOCGROUP(cmd));
271 else
272 printf(" 0x%lx", IOCGROUP(cmd));
273 printf("/%ld ", cmd & 0xff);
274 if (cmd & IOC_IN)
275 printf("I");
276 if (cmd & IOC_OUT)
277 printf("O");
274 printf("IOCTL(0x%lx) \"%s\"", cmd, gp->name);
275 if (i > ' ' && i <= '~')
276 printf(" '%c'", (int)IOCGROUP(cmd));
277 else
278 printf(" 0x%lx", IOCGROUP(cmd));
279 printf("/%ld ", cmd & 0xff);
280 if (cmd & IOC_IN)
281 printf("I");
282 if (cmd & IOC_OUT)
283 printf("O");
278 printf("(%ld)", IOCPARM_LEN(cmd));
279 printf(" \"%s\"\n", nm);
280 error = ENOIOCTL;
281 }
282 if (error == 0) {
283 i = IOCPARM_LEN(cmd);
284 error = g_io_getattr(nm, cp, &i, data, td);
285 if (error != 0 && cmd == DIOCGDVIRGIN) {
286 g_topology_lock();
287 gp = g_create_geomf("BSD-method", cp->provider, NULL);
288 g_topology_unlock();
289 }
290 }
291 mtx_lock(&Giant);
292 g_rattle();
293 if (error == ENOIOCTL)
284 printf("(%ld) = ENOIOCTL\n", IOCPARM_LEN(cmd));
294 error = ENOTTY;
285 error = ENOTTY;
286 }
295 return (error);
296}
297
298static int
299g_dev_psize(dev_t dev)
300{
301 struct g_consumer *cp;
302 int i, error;

--- 80 unchanged lines hidden ---
287 return (error);
288}
289
290static int
291g_dev_psize(dev_t dev)
292{
293 struct g_consumer *cp;
294 int i, error;

--- 80 unchanged lines hidden ---