sd.c revision 1.2 1 1.2 tsutsui /* $NetBSD: sd.c,v 1.2 2013/01/13 04:39:28 tsutsui Exp $ */
2 1.1 tsutsui
3 1.1 tsutsui /*
4 1.1 tsutsui * Copyright (c) 1992 OMRON Corporation.
5 1.1 tsutsui *
6 1.1 tsutsui * This code is derived from software contributed to Berkeley by
7 1.1 tsutsui * OMRON Corporation.
8 1.1 tsutsui *
9 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
10 1.1 tsutsui * modification, are permitted provided that the following conditions
11 1.1 tsutsui * are met:
12 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
13 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
14 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
16 1.1 tsutsui * documentation and/or other materials provided with the distribution.
17 1.1 tsutsui * 3. All advertising materials mentioning features or use of this software
18 1.1 tsutsui * must display the following acknowledgement:
19 1.1 tsutsui * This product includes software developed by the University of
20 1.1 tsutsui * California, Berkeley and its contributors.
21 1.1 tsutsui * 4. Neither the name of the University nor the names of its contributors
22 1.1 tsutsui * may be used to endorse or promote products derived from this software
23 1.1 tsutsui * without specific prior written permission.
24 1.1 tsutsui *
25 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.1 tsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.1 tsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.1 tsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.1 tsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.1 tsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.1 tsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.1 tsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.1 tsutsui * SUCH DAMAGE.
36 1.1 tsutsui *
37 1.1 tsutsui * @(#)sd.c 8.1 (Berkeley) 6/10/93
38 1.1 tsutsui */
39 1.1 tsutsui /*
40 1.1 tsutsui * Copyright (c) 1992, 1993
41 1.1 tsutsui * The Regents of the University of California. All rights reserved.
42 1.1 tsutsui *
43 1.1 tsutsui * This code is derived from software contributed to Berkeley by
44 1.1 tsutsui * OMRON Corporation.
45 1.1 tsutsui *
46 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
47 1.1 tsutsui * modification, are permitted provided that the following conditions
48 1.1 tsutsui * are met:
49 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
50 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
51 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
52 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
53 1.1 tsutsui * documentation and/or other materials provided with the distribution.
54 1.1 tsutsui * 3. Neither the name of the University nor the names of its contributors
55 1.1 tsutsui * may be used to endorse or promote products derived from this software
56 1.1 tsutsui * without specific prior written permission.
57 1.1 tsutsui *
58 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.1 tsutsui * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.1 tsutsui * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.1 tsutsui * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.1 tsutsui * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.1 tsutsui * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.1 tsutsui * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.1 tsutsui * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.1 tsutsui * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.1 tsutsui * SUCH DAMAGE.
69 1.1 tsutsui *
70 1.1 tsutsui * @(#)sd.c 8.1 (Berkeley) 6/10/93
71 1.1 tsutsui */
72 1.1 tsutsui
73 1.1 tsutsui /*
74 1.1 tsutsui * sd.c -- SCSI DISK device driver
75 1.1 tsutsui * by A.Fujita, FEB-26-1992
76 1.1 tsutsui */
77 1.1 tsutsui
78 1.1 tsutsui
79 1.1 tsutsui /*
80 1.1 tsutsui * SCSI CCS (Command Command Set) disk driver.
81 1.1 tsutsui */
82 1.1 tsutsui #include <sys/param.h>
83 1.1 tsutsui #include <sys/disklabel.h>
84 1.1 tsutsui #include <luna68k/stand/boot/samachdep.h>
85 1.1 tsutsui #include <luna68k/stand/boot/scsireg.h>
86 1.1 tsutsui #include <luna68k/stand/boot/device.h>
87 1.1 tsutsui
88 1.1 tsutsui struct disklabel sdlabel[NSD];
89 1.1 tsutsui
90 1.1 tsutsui struct sd_softc {
91 1.1 tsutsui struct hp_device *sc_hd;
92 1.1 tsutsui struct devqueue sc_dq;
93 1.1 tsutsui int sc_format_pid; /* process using "format" mode */
94 1.1 tsutsui short sc_flags;
95 1.1 tsutsui short sc_type; /* drive type */
96 1.1 tsutsui short sc_punit; /* physical unit (scsi lun) */
97 1.1 tsutsui u_short sc_bshift; /* convert device blocks to DEV_BSIZE blks */
98 1.1 tsutsui u_int sc_blks; /* number of blocks on device */
99 1.1 tsutsui int sc_blksize; /* device block size in bytes */
100 1.1 tsutsui u_int sc_wpms; /* average xfer rate in 16 bit wds/sec. */
101 1.1 tsutsui };
102 1.1 tsutsui
103 1.1 tsutsui struct sd_devdata {
104 1.1 tsutsui int unit; /* drive number */
105 1.1 tsutsui int part; /* partition */
106 1.1 tsutsui };
107 1.1 tsutsui
108 1.1 tsutsui static int sdinit(void *);
109 1.1 tsutsui static int sdident(struct sd_softc *, struct hp_device *);
110 1.1 tsutsui
111 1.1 tsutsui struct driver sddriver = {
112 1.2 tsutsui sdinit, "sd", NULL,
113 1.1 tsutsui };
114 1.1 tsutsui
115 1.1 tsutsui struct sd_softc sd_softc[NSD];
116 1.1 tsutsui struct sd_devdata sd_devdata[NSD];
117 1.1 tsutsui
118 1.1 tsutsui /* sc_flags values */
119 1.1 tsutsui #define SDF_ALIVE 0x1
120 1.1 tsutsui
121 1.1 tsutsui #define sdunit(x) ((minor(x) >> 3) & 0x7)
122 1.1 tsutsui #define sdpart(x) (minor(x) & 0x7)
123 1.1 tsutsui #define sdpunit(x) ((x) & 7)
124 1.1 tsutsui
125 1.1 tsutsui static struct scsi_inquiry inqbuf;
126 1.1 tsutsui static struct scsi_fmt_cdb inq = {
127 1.1 tsutsui 6,
128 1.1 tsutsui { CMD_INQUIRY, 0, 0, 0, sizeof(inqbuf), 0 }
129 1.1 tsutsui };
130 1.1 tsutsui
131 1.1 tsutsui static u_long capbuf[2];
132 1.1 tsutsui struct scsi_fmt_cdb cap = {
133 1.1 tsutsui 10,
134 1.1 tsutsui { CMD_READ_CAPACITY, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
135 1.1 tsutsui };
136 1.1 tsutsui
137 1.1 tsutsui int
138 1.1 tsutsui sdident(struct sd_softc *sc, struct hp_device *hd)
139 1.1 tsutsui {
140 1.1 tsutsui char idstr[32];
141 1.1 tsutsui int unit;
142 1.1 tsutsui int ctlr, slave;
143 1.1 tsutsui int i;
144 1.1 tsutsui int tries = 10;
145 1.1 tsutsui
146 1.1 tsutsui ctlr = hd->hp_ctlr;
147 1.1 tsutsui slave = hd->hp_slave;
148 1.1 tsutsui unit = sc->sc_punit;
149 1.1 tsutsui
150 1.1 tsutsui /*
151 1.1 tsutsui * See if unit exists and is a disk then read block size & nblocks.
152 1.1 tsutsui */
153 1.1 tsutsui while ((i = scsi_test_unit_rdy(ctlr, slave, unit)) != 0) {
154 1.1 tsutsui if (i < 0 || --tries < 0)
155 1.1 tsutsui return (-1);
156 1.1 tsutsui if (i == STS_CHECKCOND) {
157 1.1 tsutsui u_char sensebuf[8];
158 1.1 tsutsui struct scsi_xsense *sp = (struct scsi_xsense *)sensebuf;
159 1.1 tsutsui
160 1.1 tsutsui scsi_request_sense(ctlr, slave, unit, sensebuf, 8);
161 1.1 tsutsui if (sp->class == 7 && sp->key == 6)
162 1.1 tsutsui /* drive doing an RTZ -- give it a while */
163 1.1 tsutsui DELAY(1000000);
164 1.1 tsutsui }
165 1.1 tsutsui DELAY(1000);
166 1.1 tsutsui }
167 1.1 tsutsui if (scsi_immed_command(ctlr, slave, unit, &inq, (u_char *)&inqbuf,
168 1.1 tsutsui sizeof(inqbuf)) ||
169 1.1 tsutsui scsi_immed_command(ctlr, slave, unit, &cap, (u_char *)&capbuf,
170 1.1 tsutsui sizeof(capbuf)))
171 1.1 tsutsui /* doesn't exist or not a CCS device */
172 1.1 tsutsui return (-1);
173 1.1 tsutsui
174 1.1 tsutsui switch (inqbuf.type) {
175 1.1 tsutsui case 0: /* disk */
176 1.1 tsutsui case 4: /* WORM */
177 1.1 tsutsui case 5: /* CD-ROM */
178 1.1 tsutsui case 7: /* Magneto-optical */
179 1.1 tsutsui break;
180 1.1 tsutsui default: /* not a disk */
181 1.1 tsutsui return (-1);
182 1.1 tsutsui }
183 1.1 tsutsui sc->sc_blks = capbuf[0];
184 1.1 tsutsui sc->sc_blksize = capbuf[1];
185 1.1 tsutsui
186 1.1 tsutsui memcpy(idstr, &inqbuf.vendor_id, 28);
187 1.1 tsutsui for (i = 27; i > 23; --i)
188 1.1 tsutsui if (idstr[i] != ' ')
189 1.1 tsutsui break;
190 1.1 tsutsui idstr[i+1] = 0;
191 1.1 tsutsui for (i = 23; i > 7; --i)
192 1.1 tsutsui if (idstr[i] != ' ')
193 1.1 tsutsui break;
194 1.1 tsutsui idstr[i+1] = 0;
195 1.1 tsutsui for (i = 7; i >= 0; --i)
196 1.1 tsutsui if (idstr[i] != ' ')
197 1.1 tsutsui break;
198 1.1 tsutsui idstr[i+1] = 0;
199 1.1 tsutsui printf("sd%d: %s %s rev %s", hd->hp_unit, idstr, &idstr[8],
200 1.1 tsutsui &idstr[24]);
201 1.1 tsutsui
202 1.1 tsutsui printf(", %d %d byte blocks\n", sc->sc_blks, sc->sc_blksize);
203 1.1 tsutsui if (sc->sc_blksize != DEV_BSIZE) {
204 1.1 tsutsui if (sc->sc_blksize < DEV_BSIZE) {
205 1.1 tsutsui printf("sd%d: need %d byte blocks - drive ignored\n",
206 1.1 tsutsui unit, DEV_BSIZE);
207 1.1 tsutsui return (-1);
208 1.1 tsutsui }
209 1.1 tsutsui for (i = sc->sc_blksize; i > DEV_BSIZE; i >>= 1)
210 1.1 tsutsui ++sc->sc_bshift;
211 1.1 tsutsui sc->sc_blks <<= sc->sc_bshift;
212 1.1 tsutsui }
213 1.1 tsutsui sc->sc_wpms = 32 * (60 * DEV_BSIZE / 2); /* XXX */
214 1.1 tsutsui return(inqbuf.type);
215 1.1 tsutsui }
216 1.1 tsutsui
217 1.1 tsutsui int
218 1.1 tsutsui sdinit(void *arg)
219 1.1 tsutsui {
220 1.1 tsutsui struct hp_device *hd = arg;
221 1.1 tsutsui struct sd_softc *sc = &sd_softc[hd->hp_unit];
222 1.1 tsutsui struct disklabel *lp;
223 1.1 tsutsui char *msg;
224 1.1 tsutsui
225 1.1 tsutsui #ifdef DEBUG
226 1.1 tsutsui printf("sdinit: hd->hp_unit = %d\n", hd->hp_unit);
227 1.1 tsutsui printf("sdinit: hd->hp_ctlr = %d, hd->hp_slave = %d\n",
228 1.1 tsutsui hd->hp_ctlr, hd->hp_slave);
229 1.1 tsutsui #endif
230 1.1 tsutsui sc->sc_hd = hd;
231 1.1 tsutsui sc->sc_punit = sdpunit(hd->hp_flags);
232 1.1 tsutsui sc->sc_type = sdident(sc, hd);
233 1.1 tsutsui if (sc->sc_type < 0)
234 1.1 tsutsui return(0);
235 1.1 tsutsui
236 1.1 tsutsui /*
237 1.1 tsutsui * Use the default sizes until we've read the label,
238 1.1 tsutsui * or longer if there isn't one there.
239 1.1 tsutsui */
240 1.1 tsutsui lp = &sdlabel[hd->hp_unit];
241 1.1 tsutsui
242 1.1 tsutsui if (lp->d_secpercyl == 0) {
243 1.1 tsutsui lp->d_secsize = DEV_BSIZE;
244 1.1 tsutsui lp->d_nsectors = 32;
245 1.1 tsutsui lp->d_ntracks = 20;
246 1.1 tsutsui lp->d_secpercyl = 32*20;
247 1.1 tsutsui lp->d_npartitions = 1;
248 1.1 tsutsui lp->d_partitions[0].p_offset = 0;
249 1.1 tsutsui lp->d_partitions[0].p_size = LABELSECTOR + 1;
250 1.1 tsutsui }
251 1.1 tsutsui
252 1.1 tsutsui /*
253 1.1 tsutsui * read disklabel
254 1.1 tsutsui */
255 1.1 tsutsui msg = readdisklabel(hd->hp_slave, sdstrategy, lp);
256 1.1 tsutsui if (msg != NULL)
257 1.1 tsutsui printf("sd%d: %s\n", hd->hp_unit, msg);
258 1.1 tsutsui
259 1.1 tsutsui sc->sc_flags = SDF_ALIVE;
260 1.1 tsutsui return(1);
261 1.1 tsutsui }
262 1.1 tsutsui
263 1.1 tsutsui int
264 1.1 tsutsui sdopen(struct open_file *f, ...)
265 1.1 tsutsui {
266 1.1 tsutsui va_list ap;
267 1.1 tsutsui struct sd_devdata *sd;
268 1.1 tsutsui int unit, part;
269 1.1 tsutsui
270 1.1 tsutsui va_start(ap, f);
271 1.1 tsutsui unit = va_arg(ap, int);
272 1.1 tsutsui part = va_arg(ap, int);
273 1.1 tsutsui va_end(ap);
274 1.1 tsutsui
275 1.1 tsutsui if (unit < 0 || unit >= NSD)
276 1.1 tsutsui return(-1);
277 1.1 tsutsui if (part < 0 || part >= 8)
278 1.1 tsutsui return(-1);
279 1.1 tsutsui
280 1.1 tsutsui sd = &sd_devdata[unit];
281 1.1 tsutsui sd->unit = unit;
282 1.1 tsutsui sd->part = part;
283 1.1 tsutsui f->f_devdata = (void *)sd;
284 1.1 tsutsui
285 1.1 tsutsui return 0;
286 1.1 tsutsui }
287 1.1 tsutsui
288 1.1 tsutsui int
289 1.1 tsutsui sdclose(struct open_file *f)
290 1.1 tsutsui {
291 1.1 tsutsui struct sd_devdata *sd = f->f_devdata;
292 1.1 tsutsui
293 1.1 tsutsui sd->unit = -1;
294 1.1 tsutsui sd->part = -1;
295 1.1 tsutsui f->f_devdata = NULL;
296 1.1 tsutsui
297 1.1 tsutsui return 0;
298 1.1 tsutsui }
299 1.1 tsutsui
300 1.1 tsutsui static struct scsi_fmt_cdb cdb_read = {
301 1.1 tsutsui 10,
302 1.1 tsutsui { CMD_READ_EXT, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
303 1.1 tsutsui };
304 1.1 tsutsui
305 1.1 tsutsui static struct scsi_fmt_cdb cdb_write = {
306 1.1 tsutsui 6,
307 1.1 tsutsui { CMD_WRITE_EXT, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
308 1.1 tsutsui };
309 1.1 tsutsui
310 1.1 tsutsui int
311 1.1 tsutsui sdstrategy(void *devdata, int func, daddr_t dblk, size_t size, void *v_buf,
312 1.1 tsutsui size_t *rsize)
313 1.1 tsutsui {
314 1.1 tsutsui struct sd_devdata *sd = devdata;
315 1.1 tsutsui struct disklabel *lp;
316 1.1 tsutsui uint8_t *buf = v_buf;
317 1.1 tsutsui int unit = sd->unit;
318 1.1 tsutsui int part = sd->part;
319 1.1 tsutsui struct sd_softc *sc = &sd_softc[unit];
320 1.1 tsutsui struct scsi_fmt_cdb *cdb;
321 1.1 tsutsui daddr_t blk;
322 1.1 tsutsui u_int nblk = size >> sc->sc_bshift;
323 1.1 tsutsui int stat, ctlr, slave;
324 1.1 tsutsui #ifdef DEBUG
325 1.1 tsutsui int i;
326 1.1 tsutsui #endif
327 1.1 tsutsui
328 1.1 tsutsui if (unit < 0 || unit >= NSD)
329 1.1 tsutsui return(-1);
330 1.1 tsutsui
331 1.1 tsutsui ctlr = sc->sc_hd->hp_ctlr;
332 1.1 tsutsui slave = sc->sc_hd->hp_slave;
333 1.1 tsutsui
334 1.1 tsutsui lp = &sdlabel[unit];
335 1.1 tsutsui blk = dblk + (lp->d_partitions[part].p_offset >> sc->sc_bshift);
336 1.1 tsutsui
337 1.1 tsutsui if (func == F_READ)
338 1.1 tsutsui cdb = &cdb_read;
339 1.1 tsutsui else
340 1.1 tsutsui cdb = &cdb_write;
341 1.1 tsutsui
342 1.1 tsutsui cdb->cdb[2] = (blk & 0xff000000) >> 24;
343 1.1 tsutsui cdb->cdb[3] = (blk & 0x00ff0000) >> 16;
344 1.1 tsutsui cdb->cdb[4] = (blk & 0x0000ff00) >> 8;
345 1.1 tsutsui cdb->cdb[5] = (blk & 0x000000ff);
346 1.1 tsutsui
347 1.1 tsutsui cdb->cdb[7] = ((nblk >> DEV_BSHIFT) & 0xff00) >> 8;
348 1.1 tsutsui cdb->cdb[8] = ((nblk >> DEV_BSHIFT) & 0x00ff);
349 1.1 tsutsui
350 1.1 tsutsui #ifdef DEBUG
351 1.1 tsutsui printf("sdstrategy: unit = %d\n", unit);
352 1.1 tsutsui printf("sdstrategy: blk = %lu (0x%lx), nblk = %u (0x%x)\n", (u_long)blk, (long)blk, nblk, nblk);
353 1.1 tsutsui for (i = 0; i < 10; i++)
354 1.1 tsutsui printf("sdstrategy: cdb[%d] = 0x%x\n", i, cdb->cdb[i]);
355 1.1 tsutsui printf("sdstrategy: ctlr = %d, slave = %d\n", ctlr, slave);
356 1.1 tsutsui #endif
357 1.1 tsutsui stat = scsi_immed_command(ctlr, slave, sc->sc_punit, cdb, buf, size);
358 1.1 tsutsui if (rsize)
359 1.1 tsutsui *rsize = size;
360 1.1 tsutsui
361 1.1 tsutsui return 0;
362 1.1 tsutsui }
363 1.1 tsutsui
364 1.1 tsutsui #if 0
365 1.1 tsutsui int
366 1.1 tsutsui sdread(dev_t dev, u_int blk, u_int nblk, u_char *buff, u_int len)
367 1.1 tsutsui {
368 1.1 tsutsui int unit = sdunit(dev);
369 1.1 tsutsui int part = sdpart(dev);
370 1.1 tsutsui struct sd_softc *sc = &sd_softc[unit];
371 1.1 tsutsui struct scsi_fmt_cdb *cdb;
372 1.1 tsutsui int stat, ctlr, slave;
373 1.1 tsutsui
374 1.1 tsutsui ctlr = sc->sc_hd->hp_ctlr;
375 1.1 tsutsui slave = sc->sc_hd->hp_slave;
376 1.1 tsutsui
377 1.1 tsutsui cdb = &cdb_read;
378 1.1 tsutsui
379 1.1 tsutsui cdb->cdb[2] = (blk & 0xff000000) >> 24;
380 1.1 tsutsui cdb->cdb[3] = (blk & 0x00ff0000) >> 16;
381 1.1 tsutsui cdb->cdb[4] = (blk & 0x0000ff00) >> 8;
382 1.1 tsutsui cdb->cdb[5] = (blk & 0x000000ff);
383 1.1 tsutsui
384 1.1 tsutsui cdb->cdb[7] = (nblk & 0xff00) >> 8;
385 1.1 tsutsui cdb->cdb[8] = (nblk & 0x00ff);
386 1.1 tsutsui
387 1.1 tsutsui stat = scsi_immed_command(ctlr, slave, sc->sc_punit, cdb, buff, len);
388 1.1 tsutsui
389 1.1 tsutsui if (stat == 0)
390 1.1 tsutsui return(1);
391 1.1 tsutsui else
392 1.1 tsutsui return(0);
393 1.1 tsutsui }
394 1.1 tsutsui
395 1.1 tsutsui int
396 1.1 tsutsui sdioctl(dev_t dev, u_long data[])
397 1.1 tsutsui {
398 1.1 tsutsui int unit = sdunit(dev);
399 1.1 tsutsui int part = sdpart(dev);
400 1.1 tsutsui struct disklabel *lp;
401 1.1 tsutsui
402 1.1 tsutsui if (unit < 0 || unit >= NSD)
403 1.1 tsutsui return(0);
404 1.1 tsutsui
405 1.1 tsutsui if (part < 0 || part >= MAXPARTITIONS)
406 1.1 tsutsui return(0);
407 1.1 tsutsui
408 1.1 tsutsui lp = &sdlabel[unit];
409 1.1 tsutsui data[0] = lp->d_partitions[part].p_offset;
410 1.1 tsutsui data[1] = lp->d_partitions[part].p_size;
411 1.1 tsutsui
412 1.1 tsutsui return(1);
413 1.1 tsutsui }
414 1.1 tsutsui #endif
415