ccd.c revision 1.64 1 /* $NetBSD: ccd.c,v 1.64 1999/11/03 16:04:03 chs Exp $ */
2
3 /*-
4 * Copyright (c) 1996, 1997, 1998, 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /*
40 * Copyright (c) 1988 University of Utah.
41 * Copyright (c) 1990, 1993
42 * The Regents of the University of California. All rights reserved.
43 *
44 * This code is derived from software contributed to Berkeley by
45 * the Systems Programming Group of the University of Utah Computer
46 * Science Department.
47 *
48 * Redistribution and use in source and binary forms, with or without
49 * modification, are permitted provided that the following conditions
50 * are met:
51 * 1. Redistributions of source code must retain the above copyright
52 * notice, this list of conditions and the following disclaimer.
53 * 2. Redistributions in binary form must reproduce the above copyright
54 * notice, this list of conditions and the following disclaimer in the
55 * documentation and/or other materials provided with the distribution.
56 * 3. All advertising materials mentioning features or use of this software
57 * must display the following acknowledgement:
58 * This product includes software developed by the University of
59 * California, Berkeley and its contributors.
60 * 4. Neither the name of the University nor the names of its contributors
61 * may be used to endorse or promote products derived from this software
62 * without specific prior written permission.
63 *
64 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * SUCH DAMAGE.
75 *
76 * from: Utah $Hdr: cd.c 1.6 90/11/28$
77 *
78 * @(#)cd.c 8.2 (Berkeley) 11/16/93
79 */
80
81 /*
82 * "Concatenated" disk driver.
83 *
84 * Dynamic configuration and disklabel support by:
85 * Jason R. Thorpe <thorpej (at) nas.nasa.gov>
86 * Numerical Aerodynamic Simulation Facility
87 * Mail Stop 258-6
88 * NASA Ames Research Center
89 * Moffett Field, CA 94035
90 */
91
92 #include <sys/param.h>
93 #include <sys/systm.h>
94 #include <sys/proc.h>
95 #include <sys/errno.h>
96 #include <sys/buf.h>
97 #include <sys/malloc.h>
98 #include <sys/pool.h>
99 #include <sys/namei.h>
100 #include <sys/stat.h>
101 #include <sys/ioctl.h>
102 #include <sys/disklabel.h>
103 #include <sys/device.h>
104 #include <sys/disk.h>
105 #include <sys/syslog.h>
106 #include <sys/fcntl.h>
107 #include <sys/vnode.h>
108 #include <sys/conf.h>
109 #include <sys/lock.h>
110 #include <sys/queue.h>
111
112 #include <dev/ccdvar.h>
113
114 #if defined(CCDDEBUG) && !defined(DEBUG)
115 #define DEBUG
116 #endif
117
118 #ifdef DEBUG
119 #define CCDB_FOLLOW 0x01
120 #define CCDB_INIT 0x02
121 #define CCDB_IO 0x04
122 #define CCDB_LABEL 0x08
123 #define CCDB_VNODE 0x10
124 int ccddebug = 0x00;
125 #endif
126
127 #define ccdunit(x) DISKUNIT(x)
128
129 struct ccdbuf {
130 struct buf cb_buf; /* new I/O buf */
131 struct buf *cb_obp; /* ptr. to original I/O buf */
132 struct ccd_softc *cb_sc; /* pointer to ccd softc */
133 int cb_comp; /* target component */
134 SIMPLEQ_ENTRY(ccdbuf) cb_q; /* fifo of component buffers */
135 };
136
137 /* component buffer pool */
138 struct pool ccd_cbufpool;
139
140 #define CCD_GETBUF() pool_get(&ccd_cbufpool, PR_NOWAIT)
141 #define CCD_PUTBUF(cbp) pool_put(&ccd_cbufpool, cbp)
142
143 #define CCDLABELDEV(dev) \
144 (MAKEDISKDEV(major((dev)), ccdunit((dev)), RAW_PART))
145
146 /* called by main() at boot time */
147 void ccdattach __P((int));
148
149 /* called by biodone() at interrupt time */
150 void ccdiodone __P((struct buf *));
151 int ccdsize __P((dev_t));
152
153 static void ccdstart __P((struct ccd_softc *, struct buf *));
154 static void ccdinterleave __P((struct ccd_softc *));
155 static void ccdintr __P((struct ccd_softc *, struct buf *));
156 static int ccdinit __P((struct ccd_softc *, char **, struct vnode **,
157 struct proc *));
158 static int ccdlookup __P((char *, struct proc *p, struct vnode **));
159 static struct ccdbuf *ccdbuffer __P((struct ccd_softc *, struct buf *,
160 daddr_t, caddr_t, long));
161 static void ccdgetdefaultlabel __P((struct ccd_softc *, struct disklabel *));
162 static void ccdgetdisklabel __P((dev_t));
163 static void ccdmakedisklabel __P((struct ccd_softc *));
164
165 #ifdef DEBUG
166 static void printiinfo __P((struct ccdiinfo *));
167 #endif
168
169 /* Non-private for the benefit of libkvm. */
170 struct ccd_softc *ccd_softc;
171 int numccd = 0;
172
173 /*
174 * Called by main() during pseudo-device attachment. All we need
175 * to do is allocate enough space for devices to be configured later.
176 */
177 void
178 ccdattach(num)
179 int num;
180 {
181 struct ccd_softc *cs;
182 int i;
183
184 if (num <= 0) {
185 #ifdef DIAGNOSTIC
186 panic("ccdattach: count <= 0");
187 #endif
188 return;
189 }
190
191 ccd_softc = (struct ccd_softc *)malloc(num * sizeof(struct ccd_softc),
192 M_DEVBUF, M_NOWAIT);
193 if (ccd_softc == NULL) {
194 printf("WARNING: no memory for concatenated disks\n");
195 if (ccd_softc != NULL)
196 free(ccd_softc, M_DEVBUF);
197 return;
198 }
199 numccd = num;
200 bzero(ccd_softc, num * sizeof(struct ccd_softc));
201
202 /* Initialize the component buffer pool. */
203 pool_init(&ccd_cbufpool, sizeof(struct ccdbuf), 0,
204 0, 0, "ccdpl", 0, NULL, NULL, M_DEVBUF);
205
206 /* Initialize per-softc structures. */
207 for (i = 0; i < num; i++) {
208 cs = &ccd_softc[i];
209 sprintf(cs->sc_xname, "ccd%d", i); /* XXX */
210 cs->sc_dkdev.dk_name = cs->sc_xname; /* XXX */
211 lockinit(&cs->sc_lock, PRIBIO, "ccdlk", 0, 0);
212 }
213 }
214
215 static int
216 ccdinit(cs, cpaths, vpp, p)
217 struct ccd_softc *cs;
218 char **cpaths;
219 struct vnode **vpp;
220 struct proc *p;
221 {
222 register struct ccdcinfo *ci = NULL;
223 register size_t size;
224 register int ix;
225 struct vattr va;
226 size_t minsize;
227 int maxsecsize;
228 struct partinfo dpart;
229 struct ccdgeom *ccg = &cs->sc_geom;
230 char tmppath[MAXPATHLEN];
231 int error;
232
233 #ifdef DEBUG
234 if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
235 printf("%s: ccdinit\n", cs->sc_xname);
236 #endif
237
238 /* Allocate space for the component info. */
239 cs->sc_cinfo = malloc(cs->sc_nccdisks * sizeof(struct ccdcinfo),
240 M_DEVBUF, M_WAITOK);
241
242 cs->sc_size = 0;
243
244 /*
245 * Verify that each component piece exists and record
246 * relevant information about it.
247 */
248 maxsecsize = 0;
249 minsize = 0;
250 for (ix = 0; ix < cs->sc_nccdisks; ix++) {
251 ci = &cs->sc_cinfo[ix];
252 ci->ci_vp = vpp[ix];
253
254 /*
255 * Copy in the pathname of the component.
256 */
257 bzero(tmppath, sizeof(tmppath)); /* sanity */
258 error = copyinstr(cpaths[ix], tmppath,
259 MAXPATHLEN, &ci->ci_pathlen);
260 if (error) {
261 #ifdef DEBUG
262 if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
263 printf("%s: can't copy path, error = %d\n",
264 cs->sc_xname, error);
265 #endif
266 free(cs->sc_cinfo, M_DEVBUF);
267 return (error);
268 }
269 ci->ci_path = malloc(ci->ci_pathlen, M_DEVBUF, M_WAITOK);
270 bcopy(tmppath, ci->ci_path, ci->ci_pathlen);
271
272 /*
273 * XXX: Cache the component's dev_t.
274 */
275 if ((error = VOP_GETATTR(vpp[ix], &va, p->p_ucred, p)) != 0) {
276 #ifdef DEBUG
277 if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
278 printf("%s: %s: getattr failed %s = %d\n",
279 cs->sc_xname, ci->ci_path,
280 "error", error);
281 #endif
282 free(ci->ci_path, M_DEVBUF);
283 free(cs->sc_cinfo, M_DEVBUF);
284 return (error);
285 }
286 ci->ci_dev = va.va_rdev;
287
288 /*
289 * Get partition information for the component.
290 */
291 error = VOP_IOCTL(vpp[ix], DIOCGPART, (caddr_t)&dpart,
292 FREAD, p->p_ucred, p);
293 if (error) {
294 #ifdef DEBUG
295 if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
296 printf("%s: %s: ioctl failed, error = %d\n",
297 cs->sc_xname, ci->ci_path, error);
298 #endif
299 free(ci->ci_path, M_DEVBUF);
300 free(cs->sc_cinfo, M_DEVBUF);
301 return (error);
302 }
303
304 /*
305 * Calculate the size, truncating to an interleave
306 * boundary if necessary.
307 */
308 maxsecsize =
309 ((dpart.disklab->d_secsize > maxsecsize) ?
310 dpart.disklab->d_secsize : maxsecsize);
311 size = dpart.part->p_size;
312 if (cs->sc_ileave > 1)
313 size -= size % cs->sc_ileave;
314
315 if (size == 0) {
316 #ifdef DEBUG
317 if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
318 printf("%s: %s: size == 0\n",
319 cs->sc_xname, ci->ci_path);
320 #endif
321 free(ci->ci_path, M_DEVBUF);
322 free(cs->sc_cinfo, M_DEVBUF);
323 return (ENODEV);
324 }
325
326 if (minsize == 0 || size < minsize)
327 minsize = size;
328 ci->ci_size = size;
329 cs->sc_size += size;
330 }
331
332 /*
333 * Don't allow the interleave to be smaller than
334 * the biggest component sector.
335 */
336 if ((cs->sc_ileave > 0) &&
337 (cs->sc_ileave < (maxsecsize / DEV_BSIZE))) {
338 #ifdef DEBUG
339 if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
340 printf("%s: interleave must be at least %d\n",
341 cs->sc_xname, (maxsecsize / DEV_BSIZE));
342 #endif
343 free(ci->ci_path, M_DEVBUF);
344 free(cs->sc_cinfo, M_DEVBUF);
345 return (EINVAL);
346 }
347
348 /*
349 * If uniform interleave is desired set all sizes to that of
350 * the smallest component.
351 */
352 if (cs->sc_flags & CCDF_UNIFORM) {
353 for (ci = cs->sc_cinfo;
354 ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
355 ci->ci_size = minsize;
356
357 cs->sc_size = cs->sc_nccdisks * minsize;
358 }
359
360 /*
361 * Construct the interleave table.
362 */
363 ccdinterleave(cs);
364
365 /*
366 * Create pseudo-geometry based on 1MB cylinders. It's
367 * pretty close.
368 */
369 ccg->ccg_secsize = DEV_BSIZE;
370 ccg->ccg_ntracks = 1;
371 ccg->ccg_nsectors = 1024 * (1024 / ccg->ccg_secsize);
372 ccg->ccg_ncylinders = cs->sc_size / ccg->ccg_nsectors;
373
374 cs->sc_flags |= CCDF_INITED;
375
376 return (0);
377 }
378
379 static void
380 ccdinterleave(cs)
381 register struct ccd_softc *cs;
382 {
383 register struct ccdcinfo *ci, *smallci;
384 register struct ccdiinfo *ii;
385 register daddr_t bn, lbn;
386 register int ix;
387 u_long size;
388
389 #ifdef DEBUG
390 if (ccddebug & CCDB_INIT)
391 printf("ccdinterleave(%p): ileave %d\n", cs, cs->sc_ileave);
392 #endif
393 /*
394 * Allocate an interleave table.
395 * Chances are this is too big, but we don't care.
396 */
397 size = (cs->sc_nccdisks + 1) * sizeof(struct ccdiinfo);
398 cs->sc_itable = (struct ccdiinfo *)malloc(size, M_DEVBUF, M_WAITOK);
399 bzero((caddr_t)cs->sc_itable, size);
400
401 /*
402 * Trivial case: no interleave (actually interleave of disk size).
403 * Each table entry represents a single component in its entirety.
404 */
405 if (cs->sc_ileave == 0) {
406 bn = 0;
407 ii = cs->sc_itable;
408
409 for (ix = 0; ix < cs->sc_nccdisks; ix++) {
410 /* Allocate space for ii_index. */
411 ii->ii_index = malloc(sizeof(int), M_DEVBUF, M_WAITOK);
412 ii->ii_ndisk = 1;
413 ii->ii_startblk = bn;
414 ii->ii_startoff = 0;
415 ii->ii_index[0] = ix;
416 bn += cs->sc_cinfo[ix].ci_size;
417 ii++;
418 }
419 ii->ii_ndisk = 0;
420 #ifdef DEBUG
421 if (ccddebug & CCDB_INIT)
422 printiinfo(cs->sc_itable);
423 #endif
424 return;
425 }
426
427 /*
428 * The following isn't fast or pretty; it doesn't have to be.
429 */
430 size = 0;
431 bn = lbn = 0;
432 for (ii = cs->sc_itable; ; ii++) {
433 /* Allocate space for ii_index. */
434 ii->ii_index = malloc((sizeof(int) * cs->sc_nccdisks),
435 M_DEVBUF, M_WAITOK);
436
437 /*
438 * Locate the smallest of the remaining components
439 */
440 smallci = NULL;
441 for (ci = cs->sc_cinfo;
442 ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
443 if (ci->ci_size > size &&
444 (smallci == NULL ||
445 ci->ci_size < smallci->ci_size))
446 smallci = ci;
447
448 /*
449 * Nobody left, all done
450 */
451 if (smallci == NULL) {
452 ii->ii_ndisk = 0;
453 break;
454 }
455
456 /*
457 * Record starting logical block and component offset
458 */
459 ii->ii_startblk = bn / cs->sc_ileave;
460 ii->ii_startoff = lbn;
461
462 /*
463 * Determine how many disks take part in this interleave
464 * and record their indices.
465 */
466 ix = 0;
467 for (ci = cs->sc_cinfo;
468 ci < &cs->sc_cinfo[cs->sc_nccdisks]; ci++)
469 if (ci->ci_size >= smallci->ci_size)
470 ii->ii_index[ix++] = ci - cs->sc_cinfo;
471 ii->ii_ndisk = ix;
472 bn += ix * (smallci->ci_size - size);
473 lbn = smallci->ci_size / cs->sc_ileave;
474 size = smallci->ci_size;
475 }
476 #ifdef DEBUG
477 if (ccddebug & CCDB_INIT)
478 printiinfo(cs->sc_itable);
479 #endif
480 }
481
482 /* ARGSUSED */
483 int
484 ccdopen(dev, flags, fmt, p)
485 dev_t dev;
486 int flags, fmt;
487 struct proc *p;
488 {
489 int unit = ccdunit(dev);
490 struct ccd_softc *cs;
491 struct disklabel *lp;
492 int error = 0, part, pmask;
493
494 #ifdef DEBUG
495 if (ccddebug & CCDB_FOLLOW)
496 printf("ccdopen(0x%x, 0x%x)\n", dev, flags);
497 #endif
498 if (unit >= numccd)
499 return (ENXIO);
500 cs = &ccd_softc[unit];
501
502 if ((error = lockmgr(&cs->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
503 return (error);
504
505 lp = cs->sc_dkdev.dk_label;
506
507 part = DISKPART(dev);
508 pmask = (1 << part);
509
510 /*
511 * If we're initialized, check to see if there are any other
512 * open partitions. If not, then it's safe to update
513 * the in-core disklabel.
514 */
515 if ((cs->sc_flags & CCDF_INITED) && (cs->sc_dkdev.dk_openmask == 0))
516 ccdgetdisklabel(dev);
517
518 /* Check that the partition exists. */
519 if (part != RAW_PART) {
520 if (((cs->sc_flags & CCDF_INITED) == 0) ||
521 ((part >= lp->d_npartitions) ||
522 (lp->d_partitions[part].p_fstype == FS_UNUSED))) {
523 error = ENXIO;
524 goto done;
525 }
526 }
527
528 /* Prevent our unit from being unconfigured while open. */
529 switch (fmt) {
530 case S_IFCHR:
531 cs->sc_dkdev.dk_copenmask |= pmask;
532 break;
533
534 case S_IFBLK:
535 cs->sc_dkdev.dk_bopenmask |= pmask;
536 break;
537 }
538 cs->sc_dkdev.dk_openmask =
539 cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask;
540
541 done:
542 (void) lockmgr(&cs->sc_lock, LK_RELEASE, NULL);
543 return (error);
544 }
545
546 /* ARGSUSED */
547 int
548 ccdclose(dev, flags, fmt, p)
549 dev_t dev;
550 int flags, fmt;
551 struct proc *p;
552 {
553 int unit = ccdunit(dev);
554 struct ccd_softc *cs;
555 int error = 0, part;
556
557 #ifdef DEBUG
558 if (ccddebug & CCDB_FOLLOW)
559 printf("ccdclose(0x%x, 0x%x)\n", dev, flags);
560 #endif
561
562 if (unit >= numccd)
563 return (ENXIO);
564 cs = &ccd_softc[unit];
565
566 if ((error = lockmgr(&cs->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
567 return (error);
568
569 part = DISKPART(dev);
570
571 /* ...that much closer to allowing unconfiguration... */
572 switch (fmt) {
573 case S_IFCHR:
574 cs->sc_dkdev.dk_copenmask &= ~(1 << part);
575 break;
576
577 case S_IFBLK:
578 cs->sc_dkdev.dk_bopenmask &= ~(1 << part);
579 break;
580 }
581 cs->sc_dkdev.dk_openmask =
582 cs->sc_dkdev.dk_copenmask | cs->sc_dkdev.dk_bopenmask;
583
584 (void) lockmgr(&cs->sc_lock, LK_RELEASE, NULL);
585 return (0);
586 }
587
588 void
589 ccdstrategy(bp)
590 register struct buf *bp;
591 {
592 register int unit = ccdunit(bp->b_dev);
593 register struct ccd_softc *cs = &ccd_softc[unit];
594 register int s;
595 int wlabel;
596 struct disklabel *lp;
597
598 #ifdef DEBUG
599 if (ccddebug & CCDB_FOLLOW)
600 printf("ccdstrategy(%p): unit %d\n", bp, unit);
601 #endif
602 if ((cs->sc_flags & CCDF_INITED) == 0) {
603 #ifdef DEBUG
604 if (ccddebug & CCDB_FOLLOW)
605 printf("ccdstrategy: unit %d: not inited\n", unit);
606 #endif
607 bp->b_error = ENXIO;
608 bp->b_flags |= B_ERROR;
609 goto done;
610 }
611
612 /* If it's a nil transfer, wake up the top half now. */
613 if (bp->b_bcount == 0)
614 goto done;
615
616 lp = cs->sc_dkdev.dk_label;
617
618 /*
619 * Do bounds checking and adjust transfer. If there's an
620 * error, the bounds check will flag that for us.
621 */
622 wlabel = cs->sc_flags & (CCDF_WLABEL|CCDF_LABELLING);
623 if (DISKPART(bp->b_dev) != RAW_PART)
624 if (bounds_check_with_label(bp, lp, wlabel) <= 0)
625 goto done;
626
627 bp->b_resid = bp->b_bcount;
628
629 /*
630 * "Start" the unit.
631 */
632 s = splbio();
633 ccdstart(cs, bp);
634 splx(s);
635 return;
636 done:
637 biodone(bp);
638 }
639
640 static void
641 ccdstart(cs, bp)
642 register struct ccd_softc *cs;
643 register struct buf *bp;
644 {
645 register long bcount, rcount;
646 struct ccdbuf *cbp;
647 caddr_t addr;
648 daddr_t bn;
649 struct partition *pp;
650 SIMPLEQ_HEAD(, ccdbuf) cbufq;
651
652 #ifdef DEBUG
653 if (ccddebug & CCDB_FOLLOW)
654 printf("ccdstart(%p, %p)\n", cs, bp);
655 #endif
656
657 /* Instrumentation. */
658 disk_busy(&cs->sc_dkdev);
659
660 /*
661 * Translate the partition-relative block number to an absolute.
662 */
663 bn = bp->b_blkno;
664 if (DISKPART(bp->b_dev) != RAW_PART) {
665 pp = &cs->sc_dkdev.dk_label->d_partitions[DISKPART(bp->b_dev)];
666 bn += pp->p_offset;
667 }
668
669 /*
670 * Allocate the component buffers.
671 */
672 SIMPLEQ_INIT(&cbufq);
673 addr = bp->b_data;
674 for (bcount = bp->b_bcount; bcount > 0; bcount -= rcount) {
675 cbp = ccdbuffer(cs, bp, bn, addr, bcount);
676 if (cbp == NULL) {
677 /* Free the already allocated component buffers. */
678 while ((cbp = SIMPLEQ_FIRST(&cbufq)) != NULL) {
679 SIMPLEQ_REMOVE_HEAD(&cbufq, cbp, cb_q);
680 CCD_PUTBUF(cbp);
681 }
682
683 /* Notify the upper layer we are out of memory. */
684 bp->b_error = ENOMEM;
685 bp->b_flags |= B_ERROR;
686 biodone(bp);
687 disk_unbusy(&cs->sc_dkdev, 0);
688 return;
689 }
690 SIMPLEQ_INSERT_TAIL(&cbufq, cbp, cb_q);
691 rcount = cbp->cb_buf.b_bcount;
692 bn += btodb(rcount);
693 addr += rcount;
694 }
695
696 /* Now fire off the requests. */
697 while ((cbp = SIMPLEQ_FIRST(&cbufq)) != NULL) {
698 SIMPLEQ_REMOVE_HEAD(&cbufq, cbp, cb_q);
699 if ((cbp->cb_buf.b_flags & B_READ) == 0)
700 cbp->cb_buf.b_vp->v_numoutput++;
701 VOP_STRATEGY(&cbp->cb_buf);
702 }
703 }
704
705 /*
706 * Build a component buffer header.
707 */
708 static struct ccdbuf *
709 ccdbuffer(cs, bp, bn, addr, bcount)
710 register struct ccd_softc *cs;
711 struct buf *bp;
712 daddr_t bn;
713 caddr_t addr;
714 long bcount;
715 {
716 register struct ccdcinfo *ci;
717 register struct ccdbuf *cbp;
718 register daddr_t cbn, cboff;
719 register u_int64_t cbc;
720 int ccdisk;
721
722 #ifdef DEBUG
723 if (ccddebug & CCDB_IO)
724 printf("ccdbuffer(%p, %p, %d, %p, %ld)\n",
725 cs, bp, bn, addr, bcount);
726 #endif
727 /*
728 * Determine which component bn falls in.
729 */
730 cbn = bn;
731 cboff = 0;
732
733 /*
734 * Serially concatenated
735 */
736 if (cs->sc_ileave == 0) {
737 register daddr_t sblk;
738
739 sblk = 0;
740 for (ccdisk = 0, ci = &cs->sc_cinfo[ccdisk];
741 cbn >= sblk + ci->ci_size;
742 ccdisk++, ci = &cs->sc_cinfo[ccdisk])
743 sblk += ci->ci_size;
744 cbn -= sblk;
745 }
746 /*
747 * Interleaved
748 */
749 else {
750 register struct ccdiinfo *ii;
751 int off;
752
753 cboff = cbn % cs->sc_ileave;
754 cbn /= cs->sc_ileave;
755 for (ii = cs->sc_itable; ii->ii_ndisk; ii++)
756 if (ii->ii_startblk > cbn)
757 break;
758 ii--;
759 off = cbn - ii->ii_startblk;
760 if (ii->ii_ndisk == 1) {
761 ccdisk = ii->ii_index[0];
762 cbn = ii->ii_startoff + off;
763 } else {
764 ccdisk = ii->ii_index[off % ii->ii_ndisk];
765 cbn = ii->ii_startoff + off / ii->ii_ndisk;
766 }
767 cbn *= cs->sc_ileave;
768 ci = &cs->sc_cinfo[ccdisk];
769 }
770
771 /*
772 * Fill in the component buf structure.
773 */
774 cbp = CCD_GETBUF();
775 if (cbp == NULL)
776 return (NULL);
777 cbp->cb_buf.b_flags = bp->b_flags | B_CALL;
778 cbp->cb_buf.b_iodone = ccdiodone;
779 cbp->cb_buf.b_proc = bp->b_proc;
780 cbp->cb_buf.b_dev = ci->ci_dev; /* XXX */
781 cbp->cb_buf.b_blkno = cbn + cboff;
782 cbp->cb_buf.b_data = addr;
783 cbp->cb_buf.b_vp = ci->ci_vp;
784 if (cs->sc_ileave == 0)
785 cbc = dbtob((u_int64_t)(ci->ci_size - cbn));
786 else
787 cbc = dbtob((u_int64_t)(cs->sc_ileave - cboff));
788 cbp->cb_buf.b_bcount = cbc < bcount ? cbc : bcount;
789
790 /*
791 * context for ccdiodone
792 */
793 cbp->cb_obp = bp;
794 cbp->cb_sc = cs;
795 cbp->cb_comp = ccdisk;
796
797 #ifdef DEBUG
798 if (ccddebug & CCDB_IO)
799 printf(" dev 0x%x(u%lu): cbp %p bn %d addr %p bcnt %ld\n",
800 ci->ci_dev, (unsigned long) (ci-cs->sc_cinfo), cbp,
801 cbp->cb_buf.b_blkno, cbp->cb_buf.b_data,
802 cbp->cb_buf.b_bcount);
803 #endif
804
805 return (cbp);
806 }
807
808 static void
809 ccdintr(cs, bp)
810 register struct ccd_softc *cs;
811 register struct buf *bp;
812 {
813
814 #ifdef DEBUG
815 if (ccddebug & CCDB_FOLLOW)
816 printf("ccdintr(%p, %p)\n", cs, bp);
817 #endif
818 /*
819 * Request is done for better or worse, wakeup the top half.
820 */
821 if (bp->b_flags & B_ERROR)
822 bp->b_resid = bp->b_bcount;
823 disk_unbusy(&cs->sc_dkdev, (bp->b_bcount - bp->b_resid));
824 biodone(bp);
825 }
826
827 /*
828 * Called at interrupt time.
829 * Mark the component as done and if all components are done,
830 * take a ccd interrupt.
831 */
832 void
833 ccdiodone(vbp)
834 struct buf *vbp;
835 {
836 struct ccdbuf *cbp = (struct ccdbuf *) vbp;
837 struct buf *bp = cbp->cb_obp;
838 struct ccd_softc *cs = cbp->cb_sc;
839 int count, s;
840
841 s = splbio();
842 #ifdef DEBUG
843 if (ccddebug & CCDB_FOLLOW)
844 printf("ccdiodone(%p)\n", cbp);
845 if (ccddebug & CCDB_IO) {
846 printf("ccdiodone: bp %p bcount %ld resid %ld\n",
847 bp, bp->b_bcount, bp->b_resid);
848 printf(" dev 0x%x(u%d), cbp %p bn %d addr %p bcnt %ld\n",
849 cbp->cb_buf.b_dev, cbp->cb_comp, cbp,
850 cbp->cb_buf.b_blkno, cbp->cb_buf.b_data,
851 cbp->cb_buf.b_bcount);
852 }
853 #endif
854
855 if (cbp->cb_buf.b_flags & B_ERROR) {
856 bp->b_flags |= B_ERROR;
857 bp->b_error = cbp->cb_buf.b_error ?
858 cbp->cb_buf.b_error : EIO;
859
860 printf("%s: error %d on component %d\n",
861 cs->sc_xname, bp->b_error, cbp->cb_comp);
862 }
863 count = cbp->cb_buf.b_bcount;
864 CCD_PUTBUF(cbp);
865
866 /*
867 * If all done, "interrupt".
868 */
869 bp->b_resid -= count;
870 if (bp->b_resid < 0)
871 panic("ccdiodone: count");
872 if (bp->b_resid == 0)
873 ccdintr(cs, bp);
874 splx(s);
875 }
876
877 /* ARGSUSED */
878 int
879 ccdread(dev, uio, flags)
880 dev_t dev;
881 struct uio *uio;
882 int flags;
883 {
884 int unit = ccdunit(dev);
885 struct ccd_softc *cs;
886
887 #ifdef DEBUG
888 if (ccddebug & CCDB_FOLLOW)
889 printf("ccdread(0x%x, %p)\n", dev, uio);
890 #endif
891 if (unit >= numccd)
892 return (ENXIO);
893 cs = &ccd_softc[unit];
894
895 if ((cs->sc_flags & CCDF_INITED) == 0)
896 return (ENXIO);
897
898 /*
899 * XXX: It's not clear that using minphys() is completely safe,
900 * in particular, for raw I/O. Underlying devices might have some
901 * non-obvious limits, because of the copy to user-space.
902 */
903 return (physio(ccdstrategy, NULL, dev, B_READ, minphys, uio));
904 }
905
906 /* ARGSUSED */
907 int
908 ccdwrite(dev, uio, flags)
909 dev_t dev;
910 struct uio *uio;
911 int flags;
912 {
913 int unit = ccdunit(dev);
914 struct ccd_softc *cs;
915
916 #ifdef DEBUG
917 if (ccddebug & CCDB_FOLLOW)
918 printf("ccdwrite(0x%x, %p)\n", dev, uio);
919 #endif
920 if (unit >= numccd)
921 return (ENXIO);
922 cs = &ccd_softc[unit];
923
924 if ((cs->sc_flags & CCDF_INITED) == 0)
925 return (ENXIO);
926
927 /*
928 * XXX: It's not clear that using minphys() is completely safe,
929 * in particular, for raw I/O. Underlying devices might have some
930 * non-obvious limits, because of the copy to user-space.
931 */
932 return (physio(ccdstrategy, NULL, dev, B_WRITE, minphys, uio));
933 }
934
935 int
936 ccdioctl(dev, cmd, data, flag, p)
937 dev_t dev;
938 u_long cmd;
939 caddr_t data;
940 int flag;
941 struct proc *p;
942 {
943 int unit = ccdunit(dev);
944 int i, j, lookedup = 0, error;
945 int part, pmask;
946 struct ccd_softc *cs;
947 struct ccd_ioctl *ccio = (struct ccd_ioctl *)data;
948 char **cpp;
949 struct vnode **vpp;
950
951 if (unit >= numccd)
952 return (ENXIO);
953 cs = &ccd_softc[unit];
954
955 /* Must be open for writes for these commands... */
956 switch (cmd) {
957 case CCDIOCSET:
958 case CCDIOCCLR:
959 case DIOCSDINFO:
960 case DIOCWDINFO:
961 case DIOCWLABEL:
962 if ((flag & FWRITE) == 0)
963 return (EBADF);
964 }
965
966 if ((error = lockmgr(&cs->sc_lock, LK_EXCLUSIVE, NULL)) != 0)
967 return (error);
968
969 /* Must be initialized for these... */
970 switch (cmd) {
971 case CCDIOCCLR:
972 case DIOCGDINFO:
973 case DIOCSDINFO:
974 case DIOCWDINFO:
975 case DIOCGPART:
976 case DIOCWLABEL:
977 case DIOCGDEFLABEL:
978 if ((cs->sc_flags & CCDF_INITED) == 0) {
979 error = ENXIO;
980 goto out;
981 }
982 }
983
984 switch (cmd) {
985 case CCDIOCSET:
986 if (cs->sc_flags & CCDF_INITED) {
987 error = EBUSY;
988 goto out;
989 }
990
991 /* Validate the flags. */
992 if ((ccio->ccio_flags & CCDF_USERMASK) != ccio->ccio_flags) {
993 error = EINVAL;
994 goto out;
995 }
996
997 /* Fill in some important bits. */
998 cs->sc_ileave = ccio->ccio_ileave;
999 cs->sc_nccdisks = ccio->ccio_ndisks;
1000 cs->sc_flags = ccio->ccio_flags & CCDF_USERMASK;
1001
1002 /*
1003 * Allocate space for and copy in the array of
1004 * componet pathnames and device numbers.
1005 */
1006 cpp = malloc(ccio->ccio_ndisks * sizeof(char *),
1007 M_DEVBUF, M_WAITOK);
1008 vpp = malloc(ccio->ccio_ndisks * sizeof(struct vnode *),
1009 M_DEVBUF, M_WAITOK);
1010
1011 error = copyin((caddr_t)ccio->ccio_disks, (caddr_t)cpp,
1012 ccio->ccio_ndisks * sizeof(char **));
1013 if (error) {
1014 free(vpp, M_DEVBUF);
1015 free(cpp, M_DEVBUF);
1016 goto out;
1017 }
1018
1019 #ifdef DEBUG
1020 if (ccddebug & CCDB_INIT)
1021 for (i = 0; i < ccio->ccio_ndisks; ++i)
1022 printf("ccdioctl: component %d: 0x%p\n",
1023 i, cpp[i]);
1024 #endif
1025
1026 for (i = 0; i < ccio->ccio_ndisks; ++i) {
1027 #ifdef DEBUG
1028 if (ccddebug & CCDB_INIT)
1029 printf("ccdioctl: lookedup = %d\n", lookedup);
1030 #endif
1031 if ((error = ccdlookup(cpp[i], p, &vpp[i])) != 0) {
1032 for (j = 0; j < lookedup; ++j)
1033 (void)vn_close(vpp[j], FREAD|FWRITE,
1034 p->p_ucred, p);
1035 free(vpp, M_DEVBUF);
1036 free(cpp, M_DEVBUF);
1037 goto out;
1038 }
1039 ++lookedup;
1040 }
1041
1042 /*
1043 * Initialize the ccd. Fills in the softc for us.
1044 */
1045 if ((error = ccdinit(cs, cpp, vpp, p)) != 0) {
1046 for (j = 0; j < lookedup; ++j)
1047 (void)vn_close(vpp[j], FREAD|FWRITE,
1048 p->p_ucred, p);
1049 free(vpp, M_DEVBUF);
1050 free(cpp, M_DEVBUF);
1051 goto out;
1052 }
1053
1054 /* We can free the temporary variables now. */
1055 free(vpp, M_DEVBUF);
1056 free(cpp, M_DEVBUF);
1057
1058 /*
1059 * The ccd has been successfully initialized, so
1060 * we can place it into the array. Don't try to
1061 * read the disklabel until the disk has been attached,
1062 * because space for the disklabel is allocated
1063 * in disk_attach();
1064 */
1065 ccio->ccio_unit = unit;
1066 ccio->ccio_size = cs->sc_size;
1067
1068 /* Attach the disk. */
1069 disk_attach(&cs->sc_dkdev);
1070
1071 /* Try and read the disklabel. */
1072 ccdgetdisklabel(dev);
1073 break;
1074
1075 case CCDIOCCLR:
1076 /*
1077 * Don't unconfigure if any other partitions are open
1078 * or if both the character and block flavors of this
1079 * partition are open.
1080 */
1081 part = DISKPART(dev);
1082 pmask = (1 << part);
1083 if ((cs->sc_dkdev.dk_openmask & ~pmask) ||
1084 ((cs->sc_dkdev.dk_bopenmask & pmask) &&
1085 (cs->sc_dkdev.dk_copenmask & pmask))) {
1086 error = EBUSY;
1087 goto out;
1088 }
1089
1090 /*
1091 * Free ccd_softc information and clear entry.
1092 */
1093
1094 /* Close the components and free their pathnames. */
1095 for (i = 0; i < cs->sc_nccdisks; ++i) {
1096 /*
1097 * XXX: this close could potentially fail and
1098 * cause Bad Things. Maybe we need to force
1099 * the close to happen?
1100 */
1101 #ifdef DEBUG
1102 if (ccddebug & CCDB_VNODE)
1103 vprint("CCDIOCCLR: vnode info",
1104 cs->sc_cinfo[i].ci_vp);
1105 #endif
1106 (void)vn_close(cs->sc_cinfo[i].ci_vp, FREAD|FWRITE,
1107 p->p_ucred, p);
1108 free(cs->sc_cinfo[i].ci_path, M_DEVBUF);
1109 }
1110
1111 /* Free interleave index. */
1112 for (i = 0; cs->sc_itable[i].ii_ndisk; ++i)
1113 free(cs->sc_itable[i].ii_index, M_DEVBUF);
1114
1115 /* Free component info and interleave table. */
1116 free(cs->sc_cinfo, M_DEVBUF);
1117 free(cs->sc_itable, M_DEVBUF);
1118 cs->sc_flags &= ~CCDF_INITED;
1119
1120 /* Detatch the disk. */
1121 disk_detach(&cs->sc_dkdev);
1122 break;
1123
1124 case DIOCGDINFO:
1125 *(struct disklabel *)data = *(cs->sc_dkdev.dk_label);
1126 break;
1127
1128 case DIOCGPART:
1129 ((struct partinfo *)data)->disklab = cs->sc_dkdev.dk_label;
1130 ((struct partinfo *)data)->part =
1131 &cs->sc_dkdev.dk_label->d_partitions[DISKPART(dev)];
1132 break;
1133
1134 case DIOCWDINFO:
1135 case DIOCSDINFO:
1136 cs->sc_flags |= CCDF_LABELLING;
1137
1138 error = setdisklabel(cs->sc_dkdev.dk_label,
1139 (struct disklabel *)data, 0, cs->sc_dkdev.dk_cpulabel);
1140 if (error == 0) {
1141 if (cmd == DIOCWDINFO)
1142 error = writedisklabel(CCDLABELDEV(dev),
1143 ccdstrategy, cs->sc_dkdev.dk_label,
1144 cs->sc_dkdev.dk_cpulabel);
1145 }
1146
1147 cs->sc_flags &= ~CCDF_LABELLING;
1148 break;
1149
1150 case DIOCWLABEL:
1151 if (*(int *)data != 0)
1152 cs->sc_flags |= CCDF_WLABEL;
1153 else
1154 cs->sc_flags &= ~CCDF_WLABEL;
1155 break;
1156
1157 case DIOCGDEFLABEL:
1158 ccdgetdefaultlabel(cs, (struct disklabel *)data);
1159 break;
1160
1161 default:
1162 error = ENOTTY;
1163 }
1164
1165 out:
1166 (void) lockmgr(&cs->sc_lock, LK_RELEASE, NULL);
1167 return (error);
1168 }
1169
1170 int
1171 ccdsize(dev)
1172 dev_t dev;
1173 {
1174 struct ccd_softc *cs;
1175 struct disklabel *lp;
1176 int part, unit, omask, size;
1177
1178 unit = ccdunit(dev);
1179 if (unit >= numccd)
1180 return (-1);
1181 cs = &ccd_softc[unit];
1182
1183 if ((cs->sc_flags & CCDF_INITED) == 0)
1184 return (-1);
1185
1186 part = DISKPART(dev);
1187 omask = cs->sc_dkdev.dk_openmask & (1 << part);
1188 lp = cs->sc_dkdev.dk_label;
1189
1190 if (omask == 0 && ccdopen(dev, 0, S_IFBLK, curproc))
1191 return (-1);
1192
1193 if (lp->d_partitions[part].p_fstype != FS_SWAP)
1194 size = -1;
1195 else
1196 size = lp->d_partitions[part].p_size *
1197 (lp->d_secsize / DEV_BSIZE);
1198
1199 if (omask == 0 && ccdclose(dev, 0, S_IFBLK, curproc))
1200 return (-1);
1201
1202 return (size);
1203 }
1204
1205 int
1206 ccddump(dev, blkno, va, size)
1207 dev_t dev;
1208 daddr_t blkno;
1209 caddr_t va;
1210 size_t size;
1211 {
1212
1213 /* Not implemented. */
1214 return ENXIO;
1215 }
1216
1217 /*
1218 * Lookup the provided name in the filesystem. If the file exists,
1219 * is a valid block device, and isn't being used by anyone else,
1220 * set *vpp to the file's vnode.
1221 */
1222 static int
1223 ccdlookup(path, p, vpp)
1224 char *path;
1225 struct proc *p;
1226 struct vnode **vpp; /* result */
1227 {
1228 struct nameidata nd;
1229 struct vnode *vp;
1230 struct vattr va;
1231 int error;
1232
1233 NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, path, p);
1234 if ((error = vn_open(&nd, FREAD|FWRITE, 0)) != 0) {
1235 #ifdef DEBUG
1236 if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
1237 printf("ccdlookup: vn_open error = %d\n", error);
1238 #endif
1239 return (error);
1240 }
1241 vp = nd.ni_vp;
1242
1243 if (vp->v_usecount > 1) {
1244 VOP_UNLOCK(vp, 0);
1245 (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);
1246 return (EBUSY);
1247 }
1248
1249 if ((error = VOP_GETATTR(vp, &va, p->p_ucred, p)) != 0) {
1250 #ifdef DEBUG
1251 if (ccddebug & (CCDB_FOLLOW|CCDB_INIT))
1252 printf("ccdlookup: getattr error = %d\n", error);
1253 #endif
1254 VOP_UNLOCK(vp, 0);
1255 (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);
1256 return (error);
1257 }
1258
1259 /* XXX: eventually we should handle VREG, too. */
1260 if (va.va_type != VBLK) {
1261 VOP_UNLOCK(vp, 0);
1262 (void)vn_close(vp, FREAD|FWRITE, p->p_ucred, p);
1263 return (ENOTBLK);
1264 }
1265
1266 #ifdef DEBUG
1267 if (ccddebug & CCDB_VNODE)
1268 vprint("ccdlookup: vnode info", vp);
1269 #endif
1270
1271 VOP_UNLOCK(vp, 0);
1272 *vpp = vp;
1273 return (0);
1274 }
1275
1276 static void
1277 ccdgetdefaultlabel(cs, lp)
1278 struct ccd_softc *cs;
1279 struct disklabel *lp;
1280 {
1281 struct ccdgeom *ccg = &cs->sc_geom;
1282
1283 bzero(lp, sizeof(*lp));
1284
1285 lp->d_secperunit = cs->sc_size;
1286 lp->d_secsize = ccg->ccg_secsize;
1287 lp->d_nsectors = ccg->ccg_nsectors;
1288 lp->d_ntracks = ccg->ccg_ntracks;
1289 lp->d_ncylinders = ccg->ccg_ncylinders;
1290 lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
1291
1292 strncpy(lp->d_typename, "ccd", sizeof(lp->d_typename));
1293 lp->d_type = DTYPE_CCD;
1294 strncpy(lp->d_packname, "fictitious", sizeof(lp->d_packname));
1295 lp->d_rpm = 3600;
1296 lp->d_interleave = 1;
1297 lp->d_flags = 0;
1298
1299 lp->d_partitions[RAW_PART].p_offset = 0;
1300 lp->d_partitions[RAW_PART].p_size = cs->sc_size;
1301 lp->d_partitions[RAW_PART].p_fstype = FS_UNUSED;
1302 lp->d_npartitions = RAW_PART + 1;
1303
1304 lp->d_magic = DISKMAGIC;
1305 lp->d_magic2 = DISKMAGIC;
1306 lp->d_checksum = dkcksum(cs->sc_dkdev.dk_label);
1307 }
1308
1309 /*
1310 * Read the disklabel from the ccd. If one is not present, fake one
1311 * up.
1312 */
1313 static void
1314 ccdgetdisklabel(dev)
1315 dev_t dev;
1316 {
1317 int unit = ccdunit(dev);
1318 struct ccd_softc *cs = &ccd_softc[unit];
1319 char *errstring;
1320 struct disklabel *lp = cs->sc_dkdev.dk_label;
1321 struct cpu_disklabel *clp = cs->sc_dkdev.dk_cpulabel;
1322
1323 bzero(clp, sizeof(*clp));
1324
1325 ccdgetdefaultlabel(cs, lp);
1326
1327 /*
1328 * Call the generic disklabel extraction routine.
1329 */
1330 errstring = readdisklabel(CCDLABELDEV(dev), ccdstrategy,
1331 cs->sc_dkdev.dk_label, cs->sc_dkdev.dk_cpulabel);
1332 if (errstring)
1333 ccdmakedisklabel(cs);
1334 else {
1335 int i;
1336 struct partition *pp;
1337
1338 /*
1339 * Sanity check whether the found disklabel is valid.
1340 *
1341 * This is necessary since total size of ccd may vary
1342 * when an interleave is changed even though exactly
1343 * same componets are used, and old disklabel may used
1344 * if that is found.
1345 */
1346 if (lp->d_secperunit != cs->sc_size)
1347 printf("WARNING: %s: "
1348 "total sector size in disklabel (%d) != "
1349 "the size of ccd (%lu)\n", cs->sc_xname,
1350 lp->d_secperunit, (u_long)cs->sc_size);
1351 for (i = 0; i < lp->d_npartitions; i++) {
1352 pp = &lp->d_partitions[i];
1353 if (pp->p_offset + pp->p_size > cs->sc_size)
1354 printf("WARNING: %s: end of partition `%c' "
1355 "exceeds the size of ccd (%lu)\n",
1356 cs->sc_xname, 'a' + i, (u_long)cs->sc_size);
1357 }
1358 }
1359
1360 #ifdef DEBUG
1361 /* It's actually extremely common to have unlabeled ccds. */
1362 if (ccddebug & CCDB_LABEL)
1363 if (errstring != NULL)
1364 printf("%s: %s\n", cs->sc_xname, errstring);
1365 #endif
1366 }
1367
1368 /*
1369 * Take care of things one might want to take care of in the event
1370 * that a disklabel isn't present.
1371 */
1372 static void
1373 ccdmakedisklabel(cs)
1374 struct ccd_softc *cs;
1375 {
1376 struct disklabel *lp = cs->sc_dkdev.dk_label;
1377
1378 /*
1379 * For historical reasons, if there's no disklabel present
1380 * the raw partition must be marked FS_BSDFFS.
1381 */
1382 lp->d_partitions[RAW_PART].p_fstype = FS_BSDFFS;
1383
1384 strncpy(lp->d_packname, "default label", sizeof(lp->d_packname));
1385
1386 lp->d_checksum = dkcksum(lp);
1387 }
1388
1389 #ifdef DEBUG
1390 static void
1391 printiinfo(ii)
1392 struct ccdiinfo *ii;
1393 {
1394 register int ix, i;
1395
1396 for (ix = 0; ii->ii_ndisk; ix++, ii++) {
1397 printf(" itab[%d]: #dk %d sblk %d soff %d",
1398 ix, ii->ii_ndisk, ii->ii_startblk, ii->ii_startoff);
1399 for (i = 0; i < ii->ii_ndisk; i++)
1400 printf(" %d", ii->ii_index[i]);
1401 printf("\n");
1402 }
1403 }
1404 #endif
1405