Annotation of sys/arch/hppa/stand/libsa/dk.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: dk.c,v 1.13 2004/11/22 18:41:41 mickey Exp $ */
2:
3: /*
4: * Copyright 1996 1995 by Open Software Foundation, Inc.
5: * All Rights Reserved
6: *
7: * Permission to use, copy, modify, and distribute this software and
8: * its documentation for any purpose and without fee is hereby granted,
9: * provided that the above copyright notice appears in all copies and
10: * that both the copyright notice and this permission notice appear in
11: * supporting documentation.
12: *
13: * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
14: * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
15: * FOR A PARTICULAR PURPOSE.
16: *
17: * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
18: * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
19: * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
20: * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
21: * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22: *
23: */
24:
25: #include "libsa.h"
26:
27: #include <sys/param.h>
28: #include <sys/disklabel.h>
29: #include <sys/reboot.h>
30: #include <machine/pdc.h>
31: #include <machine/iomod.h>
32:
33: #include "dev_hppa.h"
34:
35: const char *
36: dk_disklabel(struct hppa_dev *dp, struct disklabel *label)
37: {
38: char buf[DEV_BSIZE];
39: size_t ret;
40:
41: if (iodcstrategy(dp, F_READ, LABELSECTOR, DEV_BSIZE, buf, &ret))
42: if (ret != DEV_BSIZE)
43: return "cannot read disklabel";
44:
45: return (getdisklabel(buf, label));
46: }
47:
48: int
49: dkopen(struct open_file *f, ...)
50: {
51: struct disklabel *lp;
52: struct hppa_dev *dp = f->f_devdata;
53: const char *st;
54:
55: #ifdef DEBUG
56: if (debug)
57: printf("dkopen(%p)\n", f);
58: #endif
59:
60: if (!(dp->pz_dev = pdc_findev(-1, PCL_RANDOM)))
61: return ENXIO;
62:
63: lp = dp->label;
64: st = NULL;
65:
66: #ifdef DEBUG
67: if (debug)
68: printf ("disklabel\n");
69: #endif
70:
71: if ((st = dk_disklabel(dp, lp)) != NULL) {
72: #ifdef DEBUG
73: if (debug)
74: printf ("dkopen: %s\n", st);
75: #endif
76: /* we do not know if it's a disk or net, but do not fail */
77: } else {
78: u_int i;
79:
80: i = B_PARTITION(dp->bootdev);
81: if (i >= lp->d_npartitions || !lp->d_partitions[i].p_size)
82: return (EPART);
83:
84: dp->fsoff = lp->d_partitions[i].p_offset;
85: }
86:
87: #ifdef DEBUGBUG
88: if (debug)
89: printf ("dkopen() ret\n");
90: #endif
91: return (0);
92: }
93:
94: int
95: dkclose(f)
96: struct open_file *f;
97: {
98: free (f->f_devdata, sizeof(struct hppa_dev));
99: f->f_devdata = NULL;
100: return 0;
101: }
CVSweb