Annotation of sys/arch/mvme88k/mvme88k/disksubr.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: disksubr.c,v 1.56 2007/06/20 18:15:46 deraadt Exp $ */
2: /*
3: * Copyright (c) 1998 Steve Murphree, Jr.
4: * Copyright (c) 1995 Dale Rahn.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. The name of the author may not be used to endorse or promote products
16: * derived from this software without specific prior written permission.
17: *
18: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28: */
29:
30: #include <sys/param.h>
31: #include <sys/systm.h>
32: #include <sys/buf.h>
33: #include <sys/disklabel.h>
34: #include <sys/disk.h>
35:
36: void bsdtocpulabel(struct disklabel *, struct mvmedisklabel *);
37: void cputobsdlabel(struct disklabel *, struct mvmedisklabel *);
38:
39: /*
40: * Attempt to read a disk label from a device
41: * using the indicated strategy routine.
42: * The label must be partly set up before this:
43: * secpercyl and anything required in the strategy routine
44: * (e.g., sector size) must be filled in before calling us.
45: * Returns NULL on success and an error string on failure.
46: */
47:
48: char *
49: readdisklabel(dev_t dev, void (*strat)(struct buf *),
50: struct disklabel *lp, int spoofonly)
51: {
52: struct buf *bp = NULL;
53: struct mvmedisklabel *mlp;
54: int error;
55: char *msg;
56:
57: if ((msg = initdisklabel(lp)))
58: goto done;
59:
60: /* get a buffer and initialize it */
61: bp = geteblk((int)lp->d_secsize);
62: bp->b_dev = dev;
63:
64: /* don't read the on-disk label if we are in spoofed-only mode */
65: if (spoofonly)
66: goto done;
67:
68: bp->b_blkno = LABELSECTOR;
69: bp->b_bcount = lp->d_secsize;
70: bp->b_flags = B_BUSY | B_READ;
71: (*strat)(bp);
72: error = biowait(bp);
73: if (error) {
74: msg = "disk label read error";
75: goto done;
76: }
77:
78: mlp = (struct mvmedisklabel *)bp->b_data;
79: if (mlp->magic1 != DISKMAGIC || mlp->magic2 != DISKMAGIC) {
80: msg = "no disk label";
81: goto done;
82: }
83:
84: cputobsdlabel(lp, mlp);
85: if (dkcksum(lp) == 0)
86: goto done;
87: msg = "disk label corrupted";
88:
89: #if defined(CD9660)
90: if (iso_disklabelspoof(dev, strat, lp) == 0) {
91: msg = NULL;
92: goto done;
93: }
94: #endif
95: #if defined(UDF)
96: if (udf_disklabelspoof(dev, strat, lp) == 0) {
97: msg = NULL;
98: goto done;
99: }
100: #endif
101:
102: done:
103: if (bp) {
104: bp->b_flags |= B_INVAL;
105: brelse(bp);
106: }
107: return (msg);
108: }
109:
110: /*
111: * Write disk label back to device after modification.
112: */
113: int
114: writedisklabel(dev_t dev, void (*strat)(struct buf *), struct disklabel *lp)
115: {
116: struct buf *bp = NULL;
117: int error;
118:
119: /* get a buffer and initialize it */
120: bp = geteblk((int)lp->d_secsize);
121: bp->b_dev = dev;
122:
123: /* Read it in, slap the new label in, and write it back out */
124: bp->b_blkno = LABELSECTOR;
125: bp->b_bcount = lp->d_secsize;
126: bp->b_flags = B_BUSY | B_READ;
127: (*strat)(bp);
128: if ((error = biowait(bp)) != 0)
129: goto done;
130:
131: bsdtocpulabel(lp, (struct mvmedisklabel *)bp->b_data);
132:
133: bp->b_flags = B_BUSY | B_WRITE;
134: (*strat)(bp);
135: error = biowait(bp);
136:
137: done:
138: if (bp) {
139: bp->b_flags |= B_INVAL;
140: brelse(bp);
141: }
142: return (error);
143: }
144:
145: void
146: bsdtocpulabel(struct disklabel *lp, struct mvmedisklabel *clp)
147: {
148: char *tmot = "MOTOROLA", *id = "M88K", *mot;
149: int i;
150:
151: clp->magic1 = lp->d_magic;
152: clp->type = lp->d_type;
153: clp->subtype = lp->d_subtype;
154: strncpy(clp->vid_vd, lp->d_typename, 16);
155: strncpy(clp->packname, lp->d_packname, 16);
156: clp->cfg_psm = lp->d_secsize;
157: clp->cfg_spt = lp->d_nsectors;
158: clp->cfg_trk = lp->d_ncylinders; /* trk is really num of cyl! */
159: clp->cfg_hds = lp->d_ntracks;
160:
161: clp->secpercyl = lp->d_secpercyl;
162: clp->secperunit = DL_GETDSIZE(lp);
163: clp->sparespertrack = lp->d_sparespertrack;
164: clp->sparespercyl = lp->d_sparespercyl;
165: clp->acylinders = lp->d_acylinders;
166: clp->rpm = lp->d_rpm;
167:
168: clp->cfg_ilv = lp->d_interleave;
169: clp->cfg_sof = lp->d_trackskew;
170: clp->cylskew = lp->d_cylskew;
171: clp->headswitch = lp->d_headswitch;
172:
173: /* this silly table is for winchester drives */
174: if (lp->d_trkseek < 6)
175: clp->cfg_ssr = 0;
176: else if (lp->d_trkseek < 10)
177: clp->cfg_ssr = 1;
178: else if (lp->d_trkseek < 15)
179: clp->cfg_ssr = 2;
180: else if (lp->d_trkseek < 20)
181: clp->cfg_ssr = 3;
182: else
183: clp->cfg_ssr = 4;
184:
185: clp->flags = lp->d_flags;
186: for (i = 0; i < NDDATA; i++)
187: clp->drivedata[i] = lp->d_drivedata[i];
188: for (i = 0; i < NSPARE; i++)
189: clp->spare[i] = lp->d_spare[i];
190:
191: clp->magic2 = lp->d_magic2;
192: clp->checksum = lp->d_checksum;
193: clp->partitions = lp->d_npartitions;
194: clp->bbsize = lp->d_bbsize;
195: clp->sbsize = lp->d_sbsize;
196: clp->checksum = lp->d_checksum;
197: bcopy(&lp->d_partitions[0], clp->vid_4, sizeof(struct partition) * 4);
198: bcopy(&lp->d_partitions[4], clp->cfg_4, sizeof(struct partition) * 12);
199: clp->version = 2;
200:
201: /* Put "MOTOROLA" in the VID. This makes it a valid boot disk. */
202: for (mot = clp->vid_mot, i = 0; i < 8; i++)
203: *mot++ = *tmot++;
204:
205: /* put volume id in the VID */
206: for (mot = clp->vid_id, i = 0; i < 4; i++)
207: *mot++ = *id++;
208: }
209:
210: void
211: cputobsdlabel(struct disklabel *lp, struct mvmedisklabel *clp)
212: {
213: int i;
214:
215: lp->d_magic = clp->magic1;
216: lp->d_type = clp->type;
217: lp->d_subtype = clp->subtype;
218: strncpy(lp->d_typename, clp->vid_vd, sizeof lp->d_typename);
219: strncpy(lp->d_packname, clp->packname, sizeof lp->d_packname);
220: lp->d_secsize = clp->cfg_psm;
221: lp->d_nsectors = clp->cfg_spt;
222: lp->d_ncylinders = clp->cfg_trk; /* trk is really num of cyl! */
223: lp->d_ntracks = clp->cfg_hds;
224:
225: lp->d_secpercyl = clp->secpercyl;
226: if (DL_GETDSIZE(lp) == 0)
227: DL_SETDSIZE(lp, clp->secperunit);
228: lp->d_sparespertrack = clp->sparespertrack;
229: lp->d_sparespercyl = clp->sparespercyl;
230: lp->d_acylinders = clp->acylinders;
231: lp->d_rpm = clp->rpm;
232: lp->d_interleave = clp->cfg_ilv;
233: lp->d_trackskew = clp->cfg_sof;
234: lp->d_cylskew = clp->cylskew;
235: lp->d_headswitch = clp->headswitch;
236:
237: /* this silly table is for winchester drives */
238: switch (clp->cfg_ssr) {
239: case 1:
240: lp->d_trkseek = 6;
241: break;
242: case 2:
243: lp->d_trkseek = 10;
244: break;
245: case 3:
246: lp->d_trkseek = 15;
247: break;
248: case 4:
249: lp->d_trkseek = 20;
250: break;
251: default:
252: lp->d_trkseek = 0;
253: }
254:
255: lp->d_flags = clp->flags;
256: for (i = 0; i < NDDATA; i++)
257: lp->d_drivedata[i] = clp->drivedata[i];
258: for (i = 0; i < NSPARE; i++)
259: lp->d_spare[i] = clp->spare[i];
260:
261: lp->d_magic2 = clp->magic2;
262: lp->d_npartitions = clp->partitions;
263: lp->d_bbsize = clp->bbsize;
264: lp->d_sbsize = clp->sbsize;
265:
266: bcopy(clp->vid_4, &lp->d_partitions[0], sizeof(struct partition) * 4);
267: bcopy(clp->cfg_4, &lp->d_partitions[4], sizeof(struct partition) * 12);
268:
269: if (clp->version < 2) {
270: struct __partitionv0 *v0pp = (struct __partitionv0 *)lp->d_partitions;
271: struct partition *pp = lp->d_partitions;
272:
273: for (i = 0; i < lp->d_npartitions; i++, pp++, v0pp++) {
274: pp->p_fragblock = DISKLABELV1_FFS_FRAGBLOCK(v0pp->
275: p_fsize, v0pp->p_frag);
276: pp->p_offseth = 0;
277: pp->p_sizeh = 0;
278: }
279: }
280:
281: lp->d_version = 1;
282: lp->d_checksum = 0;
283: lp->d_checksum = dkcksum(lp);
284: }
CVSweb