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_disk.c 109623 2003-01-21 08:56:16Z alfred $
36 */
37
38#include "opt_geom.h"
39#ifndef NO_GEOM
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/kernel.h>
44#include <sys/sysctl.h>
45#include <sys/bio.h>
46#include <sys/conf.h>
47#include <sys/disk.h>
--- 14 unchanged lines hidden (view full) ---
62 "DISK",
63 NULL,
64 NULL,
65 G_CLASS_INITIALIZER
66};
67
68DECLARE_GEOM_CLASS(g_disk_class, g_disk);
69
70static int
71g_disk_access(struct g_provider *pp, int r, int w, int e)
72{
73 struct disk *dp;
74 dev_t dev;
75 int error;
76
77 g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)",
78 pp->name, r, w, e);
79 g_topology_assert();
80 r += pp->acr;
81 w += pp->acw;
82 e += pp->ace;
83 dp = pp->geom->softc;
84 dev = dp->d_dev;
85 if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) {
86 mtx_lock(&Giant);
87 error = devsw(dev)->d_open(dev, 3, 0, NULL);
88 if (error != 0)
89 printf("Opened disk %s -> %d\n", pp->name, error);
90 mtx_unlock(&Giant);
91 pp->mediasize = dp->d_mediasize;
92 pp->sectorsize = dp->d_sectorsize;
93 } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) {
94 mtx_lock(&Giant);
95 error = devsw(dev)->d_close(dev, 3, 0, NULL);
96 if (error != 0)
97 printf("Closed disk %s -> %d\n", pp->name, error);
98 mtx_unlock(&Giant);
99 } else {
100 error = 0;
101 }
102 return (error);
103}
104
105static void
106g_disk_kerneldump(struct bio *bp, struct disk *dp)
--- 14 unchanged lines hidden (view full) ---
121 di.mediasize = gkd->length;
122 error = set_dumper(&di);
123 g_io_deliver(bp, error);
124}
125
126static void
127g_disk_done(struct bio *bp)
128{
129
130 mtx_unlock(&Giant);
131 bp->bio_completed = bp->bio_length - bp->bio_resid;
132 g_std_done(bp);
133 mtx_lock(&Giant);
134}
135
136static void
137g_disk_start(struct bio *bp)
138{
139 struct bio *bp2;
140 dev_t dev;
141 struct disk *dp;
--- 13 unchanged lines hidden (view full) ---
155 case BIO_READ:
156 case BIO_WRITE:
157 bp2 = g_clone_bio(bp);
158 bp2->bio_done = g_disk_done;
159 bp2->bio_blkno = bp2->bio_offset >> DEV_BSHIFT;
160 bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize;
161 bp2->bio_bcount = bp2->bio_length;
162 bp2->bio_dev = dev;
163 mtx_lock(&Giant);
164 devsw(dev)->d_strategy(bp2);
165 mtx_unlock(&Giant);
166 break;
167 case BIO_GETATTR:
168 if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors))
169 break;
170 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads))
171 break;
172 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0))
173 break;
--- 138 unchanged lines hidden (view full) ---
312 error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1);
313 sbuf_delete(sb);
314 return error;
315}
316
317SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0,
318 sysctl_disks, "A", "names of available disks");
319
320#endif
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_disk.c 109623 2003-01-21 08:56:16Z alfred $
36 */
37
38#include "opt_geom.h"
39#ifndef NO_GEOM
40
41#include <sys/param.h>
42#include <sys/systm.h>
43#include <sys/kernel.h>
44#include <sys/sysctl.h>
45#include <sys/bio.h>
46#include <sys/conf.h>
47#include <sys/disk.h>
--- 14 unchanged lines hidden (view full) ---
62 "DISK",
63 NULL,
64 NULL,
65 G_CLASS_INITIALIZER
66};
67
68DECLARE_GEOM_CLASS(g_disk_class, g_disk);
69
70static int
71g_disk_access(struct g_provider *pp, int r, int w, int e)
72{
73 struct disk *dp;
74 dev_t dev;
75 int error;
76
77 g_trace(G_T_ACCESS, "g_disk_access(%s, %d, %d, %d)",
78 pp->name, r, w, e);
79 g_topology_assert();
80 r += pp->acr;
81 w += pp->acw;
82 e += pp->ace;
83 dp = pp->geom->softc;
84 dev = dp->d_dev;
85 if ((pp->acr + pp->acw + pp->ace) == 0 && (r + w + e) > 0) {
86 mtx_lock(&Giant);
87 error = devsw(dev)->d_open(dev, 3, 0, NULL);
88 if (error != 0)
89 printf("Opened disk %s -> %d\n", pp->name, error);
90 mtx_unlock(&Giant);
91 pp->mediasize = dp->d_mediasize;
92 pp->sectorsize = dp->d_sectorsize;
93 } else if ((pp->acr + pp->acw + pp->ace) > 0 && (r + w + e) == 0) {
94 mtx_lock(&Giant);
95 error = devsw(dev)->d_close(dev, 3, 0, NULL);
96 if (error != 0)
97 printf("Closed disk %s -> %d\n", pp->name, error);
98 mtx_unlock(&Giant);
99 } else {
100 error = 0;
101 }
102 return (error);
103}
104
105static void
106g_disk_kerneldump(struct bio *bp, struct disk *dp)
--- 14 unchanged lines hidden (view full) ---
121 di.mediasize = gkd->length;
122 error = set_dumper(&di);
123 g_io_deliver(bp, error);
124}
125
126static void
127g_disk_done(struct bio *bp)
128{
129
130 mtx_unlock(&Giant);
131 bp->bio_completed = bp->bio_length - bp->bio_resid;
132 g_std_done(bp);
133 mtx_lock(&Giant);
134}
135
136static void
137g_disk_start(struct bio *bp)
138{
139 struct bio *bp2;
140 dev_t dev;
141 struct disk *dp;
--- 13 unchanged lines hidden (view full) ---
155 case BIO_READ:
156 case BIO_WRITE:
157 bp2 = g_clone_bio(bp);
158 bp2->bio_done = g_disk_done;
159 bp2->bio_blkno = bp2->bio_offset >> DEV_BSHIFT;
160 bp2->bio_pblkno = bp2->bio_offset / dp->d_sectorsize;
161 bp2->bio_bcount = bp2->bio_length;
162 bp2->bio_dev = dev;
163 mtx_lock(&Giant);
164 devsw(dev)->d_strategy(bp2);
165 mtx_unlock(&Giant);
166 break;
167 case BIO_GETATTR:
168 if (g_handleattr_int(bp, "GEOM::fwsectors", dp->d_fwsectors))
169 break;
170 else if (g_handleattr_int(bp, "GEOM::fwheads", dp->d_fwheads))
171 break;
172 else if (g_handleattr_off_t(bp, "GEOM::frontstuff", 0))
173 break;
--- 138 unchanged lines hidden (view full) ---
312 error = SYSCTL_OUT(req, sbuf_data(sb), sbuf_len(sb) + 1);
313 sbuf_delete(sb);
314 return error;
315}
316
317SYSCTL_PROC(_kern, OID_AUTO, disks, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NOLOCK, 0, 0,
318 sysctl_disks, "A", "names of available disks");
319
320#endif